treewide: use architecture-specific UEFI boot path

The default UEFI boot path depends on the architecture. This change is
needed for aarch64 support.

Change-Id: I69916ac5063e963b67ecdcdd814b0678c61da9fb
Reviewed-on: https://review.monogon.dev/c/monogon/+/4195
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/node/core/update/e2e/BUILD.bazel b/metropolis/node/core/update/e2e/BUILD.bazel
index a5dcc5e..19738eb 100644
--- a/metropolis/node/core/update/e2e/BUILD.bazel
+++ b/metropolis/node/core/update/e2e/BUILD.bazel
@@ -28,6 +28,7 @@
         "//osbase/blockdev",
         "//osbase/build/mkimage/osimage",
         "//osbase/oci",
+        "//osbase/oci/osimage",
         "//osbase/oci/registry",
         "//osbase/structfs",
         "@io_bazel_rules_go//go/runfiles",
diff --git a/metropolis/node/core/update/e2e/e2e_test.go b/metropolis/node/core/update/e2e/e2e_test.go
index ec51281..8bc2bb9 100644
--- a/metropolis/node/core/update/e2e/e2e_test.go
+++ b/metropolis/node/core/update/e2e/e2e_test.go
@@ -23,6 +23,7 @@
 	"source.monogon.dev/osbase/blockdev"
 	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/oci"
+	ociosimage "source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/oci/registry"
 	"source.monogon.dev/osbase/structfs"
 )
@@ -149,6 +150,11 @@
 		t.Fatal(err)
 	}
 
+	osImageY, err := ociosimage.Read(imageY)
+	if err != nil {
+		t.Fatal(err)
+	}
+
 	registryServer := registry.NewServer()
 	registryServer.AddImage("testos", "y", imageY)
 	registryServer.AddImage("testos", "z", imageZ)
@@ -184,10 +190,11 @@
 	}
 
 	if _, err := osimage.Write(&osimage.Params{
-		Output:      rootDisk,
-		ABLoader:    loader,
-		EFIPayload:  boot,
-		SystemImage: system,
+		Output:       rootDisk,
+		Architecture: osImageY.Config.ProductInfo.Architecture(),
+		ABLoader:     loader,
+		EFIPayload:   boot,
+		SystemImage:  system,
 		PartitionSize: osimage.PartitionSizeInfo{
 			ESP:    128,
 			System: 256,
diff --git a/metropolis/node/core/update/update.go b/metropolis/node/core/update/update.go
index d620677..ee53f90 100644
--- a/metropolis/node/core/update/update.go
+++ b/metropolis/node/core/update/update.go
@@ -428,7 +428,12 @@
 var abloader []byte
 
 func (s *Service) fixupPreloader() error {
-	abLoaderFile, err := os.Open(filepath.Join(s.ESPPath, osimage.EFIPayloadPath))
+	efiBootPath, err := osimage.EFIBootPath(productinfo.Get().Info.Architecture())
+	if err != nil {
+		return err
+	}
+	efiBootFilePath := filepath.Join(s.ESPPath, efiBootPath)
+	abLoaderFile, err := os.Open(efiBootFilePath)
 	if err != nil {
 		s.Logger.Warningf("A/B preloader not available, attempting to restore: %v", err)
 	} else {
@@ -458,7 +463,7 @@
 		return fmt.Errorf("while sync'ing preloader swap file: %w", err)
 	}
 	preloader.Close()
-	if err := os.Rename(filepath.Join(s.ESPPath, "preloader.swp"), filepath.Join(s.ESPPath, osimage.EFIPayloadPath)); err != nil {
+	if err := os.Rename(filepath.Join(s.ESPPath, "preloader.swp"), efiBootFilePath); err != nil {
 		return fmt.Errorf("while swapping preloader: %w", err)
 	}
 	s.Logger.Info("Successfully wrote current preloader")
@@ -468,6 +473,11 @@
 // fixupEFI checks for the existence and correctness of the EFI boot entry
 // repairs/recreates it if needed.
 func (s *Service) fixupEFI() error {
+	efiBootPath, err := osimage.EFIBootPath(productinfo.Get().Info.Architecture())
+	if err != nil {
+		return err
+	}
+	efiBootVarPath := "/" + efiBootPath
 	varNames, err := efivarfs.List(efivarfs.ScopeGlobal)
 	if err != nil {
 		return fmt.Errorf("failed to list EFI variables: %w", err)
@@ -504,7 +514,7 @@
 		}
 		switch p := e.FilePath[1].(type) {
 		case efivarfs.FilePath:
-			if string(p) == "/"+osimage.EFIPayloadPath {
+			if string(p) == efiBootVarPath {
 				if validBootEntryIdx == -1 {
 					validBootEntryIdx = int(idx)
 				} else {
@@ -540,7 +550,7 @@
 						PartitionUUID: s.ESPPart.ID,
 					},
 				},
-				efivarfs.FilePath("/" + osimage.EFIPayloadPath),
+				efivarfs.FilePath(efiBootVarPath),
 			},
 		})
 		if err == nil {