patches and low-level development discussion
 help / color / mirror / code / Atom feed
* [PATCH] EFI Loader: use correct arch suffix
@ 2022-09-27 10:56 Ivan Nikolaenko
  2022-09-27 11:17 ` Alyssa Ross
  0 siblings, 1 reply; 3+ messages in thread
From: Ivan Nikolaenko @ 2022-09-27 10:56 UTC (permalink / raw)
  To: devel; +Cc: Ivan Nikolaenko

Previously there were hardcoded "x64" in EFI loaders' filenames.

Signed-off-by: Ivan Nikolaenko <ivan.nikolaenko@unikie.com>
---
 img/combined/default.nix |  5 +++--
 img/live/Makefile        |  2 +-
 img/live/default.nix     |  5 +++--
 nix/eval-config.nix      | 11 ++++++++++-
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/img/combined/default.nix b/img/combined/default.nix
index 3989d55..2086973 100644
--- a/img/combined/default.nix
+++ b/img/combined/default.nix
@@ -7,6 +7,7 @@
 let
   inherit (builtins) storeDir;
   inherit (pkgs.lib) removePrefix;
+  inherit (config) archSuffix;
 
   eosimages = import ./eosimages.nix { inherit config; };
 
@@ -74,8 +75,8 @@ let
     done
     mcopy -i $out ${grub}/share/grub/unicode.pf2 ::/grub/fonts
 
-    grub-mkimage -o grubx64.efi -p "(hd0,gpt1)/grub" -O ${grub.grubTarget} part_gpt fat
-    mcopy -i $out grubx64.efi ::/EFI/BOOT/BOOTX64.EFI
+    grub-mkimage -o grub${archSuffix}.efi -p "(hd0,gpt1)/grub" -O ${grub.grubTarget} part_gpt fat
+    mcopy -i $out grub${archSuffix}.efi ::/EFI/BOOT/BOOT${lib.toUpper archSuffix}.EFI
 
     fsck.vfat -n $out
   '';
diff --git a/img/live/Makefile b/img/live/Makefile
index 9815c88..e63c598 100644
--- a/img/live/Makefile
+++ b/img/live/Makefile
@@ -36,7 +36,7 @@ build/boot.fat: $(KERNEL) $(INITRAMFS) $(SYSTEMD_BOOT_EFI) build/spectrum.conf
 	$(MCOPY) -i $@ build/spectrum.conf ::/loader/entries
 	$(MCOPY) -i $@ $(KERNEL) ::/spectrum/linux
 	$(MCOPY) -i $@ $(INITRAMFS) ::/spectrum/initrd
-	$(MCOPY) -i $@ $(SYSTEMD_BOOT_EFI) ::/EFI/BOOT/BOOTX64.EFI
+	$(MCOPY) -i $@ $(SYSTEMD_BOOT_EFI) ::/EFI/BOOT/$(EFINAME)
 
 # veritysetup format produces two files, but Make only (portably)
 # supports one output per rule, so we combine the two outputs then
diff --git a/img/live/default.nix b/img/live/default.nix
index 65ad058..7be55ac 100644
--- a/img/live/default.nix
+++ b/img/live/default.nix
@@ -4,7 +4,7 @@
 { config ? import ../../nix/eval-config.nix {} }:
 
 let
-  inherit (config) pkgs;
+  inherit (config) pkgs archSuffix;
   inherit (pkgs.lib) cleanSource cleanSourceWith hasSuffix;
 
   extfs = pkgs.pkgsStatic.callPackage ../../host/initramfs/extfs.nix {
@@ -33,7 +33,8 @@ stdenvNoCC.mkDerivation {
   INITRAMFS = initramfs;
   KERNEL = "${rootfs.kernel}/${stdenv.hostPlatform.linux-kernel.target}";
   ROOT_FS = rootfs;
-  SYSTEMD_BOOT_EFI = "${systemd}/lib/systemd/boot/efi/systemd-bootx64.efi";
+  SYSTEMD_BOOT_EFI = "${systemd}/lib/systemd/boot/efi/systemd-boot${archSuffix}.efi";
+  EFINAME = "BOOT${lib.toUpper archSuffix}.EFI";
 
   buildFlags = [ "build/live.img" ];
   makeFlags = [ "SCRIPTS=${scripts}" ];
diff --git a/nix/eval-config.nix b/nix/eval-config.nix
index 467f877..4234321 100644
--- a/nix/eval-config.nix
+++ b/nix/eval-config.nix
@@ -8,6 +8,15 @@
   else {}
 }:
 
-({ pkgs ? import <nixpkgs> {} }: {
+({ pkgs ? import <nixpkgs> {} }: with pkgs; {
   inherit pkgs;
+
+  archSuffix =
+    if pkgs.stdenv.isx86_64 then
+      "x64"
+    else if pkgs.stdenv.isAarch64 then
+      "aa64"
+    else
+      throw "Unsupported architecture";
+
 }) config
-- 
2.25.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] EFI Loader: use correct arch suffix
  2022-09-27 10:56 [PATCH] EFI Loader: use correct arch suffix Ivan Nikolaenko
@ 2022-09-27 11:17 ` Alyssa Ross
  2022-09-29  8:44   ` Alyssa Ross
  0 siblings, 1 reply; 3+ messages in thread
From: Alyssa Ross @ 2022-09-27 11:17 UTC (permalink / raw)
  To: Ivan Nikolaenko; +Cc: devel

[-- Attachment #1: Type: text/plain, Size: 2025 bytes --]

Ivan Nikolaenko <ivan.nikolaenko@unikie.com> writes:

> Previously there were hardcoded "x64" in EFI loaders' filenames.
>
> Signed-off-by: Ivan Nikolaenko <ivan.nikolaenko@unikie.com>
> ---
>  img/combined/default.nix |  5 +++--
>  img/live/Makefile        |  2 +-
>  img/live/default.nix     |  5 +++--
>  nix/eval-config.nix      | 11 ++++++++++-
>  4 files changed, 17 insertions(+), 6 deletions(-)

Thanks for looking at this.  I knew this would come up at some point!

Your patch looks good, except:

> diff --git a/nix/eval-config.nix b/nix/eval-config.nix
> index 467f877..4234321 100644
> --- a/nix/eval-config.nix
> +++ b/nix/eval-config.nix
> @@ -8,6 +8,15 @@
>    else {}
>  }:
>  
> -({ pkgs ? import <nixpkgs> {} }: {
> +({ pkgs ? import <nixpkgs> {} }: with pkgs; {
>    inherit pkgs;
> +
> +  archSuffix =
> +    if pkgs.stdenv.isx86_64 then
> +      "x64"
> +    else if pkgs.stdenv.isAarch64 then
> +      "aa64"
> +    else
> +      throw "Unsupported architecture";
> +
>  }) config
> -- 
> 2.25.1

I don't really want this file to turn into an unstructured list of
global constants, but I think there might be a better way:

Nixpkgs already has an unexposed mapping of Nixpkgs platforms to EFI
architecture names[1], so it would be a shame to have to duplicate it
ourselves.  What if instead, we moved that list somewhere accessible in
Nixpkgs, like how Nixpkgs already exposes the Linux and QEMU names for
architectures[2]?  Then we could just access stdenv.hostPlatform.efiArch
or whatever in our Nix expressions, and so could Nixpkgs.

I imagine that'd be a welcome (and small) Nixpkgs refactoring, and I'd
gladly backport it to Spectrum's Nixpkgs immediately after it was
accepted upstream.

[1]: https://github.com/NixOS/nixpkgs/blob/68770d269df8d7d8c7deba87156f66b0f997c071/nixos/modules/installer/cd-dvd/iso-image.nix#L434-L445
[2]: https://github.com/NixOS/nixpkgs/blob/68770d269df8d7d8c7deba87156f66b0f997c071/lib/systems/default.nix#L118

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] EFI Loader: use correct arch suffix
  2022-09-27 11:17 ` Alyssa Ross
@ 2022-09-29  8:44   ` Alyssa Ross
  0 siblings, 0 replies; 3+ messages in thread
From: Alyssa Ross @ 2022-09-29  8:44 UTC (permalink / raw)
  To: Ivan Nikolaenko; +Cc: devel

[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]

Alyssa Ross <alyssa.ross@unikie.com> writes:

> Nixpkgs already has an unexposed mapping of Nixpkgs platforms to EFI
> architecture names[1], so it would be a shame to have to duplicate it
> ourselves.  What if instead, we moved that list somewhere accessible in
> Nixpkgs, like how Nixpkgs already exposes the Linux and QEMU names for
> architectures[2]?  Then we could just access stdenv.hostPlatform.efiArch
> or whatever in our Nix expressions, and so could Nixpkgs.
>
> I imagine that'd be a welcome (and small) Nixpkgs refactoring, and I'd
> gladly backport it to Spectrum's Nixpkgs immediately after it was
> accepted upstream.
>
> [1]: https://github.com/NixOS/nixpkgs/blob/68770d269df8d7d8c7deba87156f66b0f997c071/nixos/modules/installer/cd-dvd/iso-image.nix#L434-L445
> [2]: https://github.com/NixOS/nixpkgs/blob/68770d269df8d7d8c7deba87156f66b0f997c071/lib/systems/default.nix#L118

I've merged your Nixpkgs PR (#193175 for anybody following along at
home), and backported it to Spectrum's Nixpkgs as commit
5e6b4a3127b59be1c10e8e1ccf4b57db7ff3cca0.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-29  8:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 10:56 [PATCH] EFI Loader: use correct arch suffix Ivan Nikolaenko
2022-09-27 11:17 ` Alyssa Ross
2022-09-29  8:44   ` Alyssa Ross

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).