all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#55343] Add support for 32bit UEFI
@ 2022-05-09 23:18 Denis 'GNUtoo' Carikli
  2022-05-09 23:24 ` [bug#55343] [PATCH 1/2] utils: Define 'target-x86?' predicate Denis 'GNUtoo' Carikli
  0 siblings, 1 reply; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-05-09 23:18 UTC (permalink / raw)
  To: 55343


[-- Attachment #1.1: Type: text/plain, Size: 3703 bytes --]

Hi,

I was lent a tablet with an x86_64 CPU and a 32bit UEFI. As I wanted
to test Guix on it, I ended up making patches to add support for 32bit
UEFI. This also enabled me to learn more about UEFI in the process.

In these patches (that will be sent right after this mail), I added a
grub-efi32 package that makes sure it is compiled for 32bit, even on
64bit systems, and to use it, I added and a new 'efi32-raw' image type.

I've copied (with dd) a system image that I made with this command on a
x86_64 Guix:
> guix system image -t efi32-raw system.scm
to an USB key that I then booted on a Dell Venue Pro 8.

I've attached the system.scm used for the tests (it's based on the
desktop.tmpl in the Guix source code).

I validated that the device booted fine up to gdm.

I also validated that the grub image generated with this package was
32bit with the following commands (on both i686 and x86_64 computers):
> /gnu/store/[...]-grub-efi32-2.06/bin/grub-mkimage \
> -O i386-efi -p / -o /tmp/grub.img
> $ file /tmp/grub.img 
> /tmp/grub.img: PE32 executable (EFI application) Intel 80386 (stripped
> to external PDB), for MS Windows

I've not yet tried to create an image with grub-efi32 on i686 but I
assume that it's not necessarily an issue since grub system image also
has targets like novena-raw that don't work for x86.

I also don't have ARM UEFI machines so I still added support for that
but I could not test it.

Also, for some reasons guix lint fails on i686 while it works fine for
x86_64:
> $ ./pre-inst-env guix lint grub-efi32
> gnu/packages/bootloaders.scm:337:2: grub-efi32@2.06: label
> 'ld-wrapper' does not match package name 'ld-wrapper-i386'
> gnu/packages/bootloaders.scm:337:2: grub-efi32@2.06: label 'binutils'
> does not match package name 'binutils-i386'
> gnu/packages/bootloaders.scm:337:2: grub-efi32@2.06: label 'qemu'
> does not match package name 'qemu-minimal'
> gnu/packages/bootloaders.scm:337:2: grub-efi32@2.06: label 'gettext'
> does not match package name 'gettext-minimal'
> gnu/packages/bootloaders.scm:337:2: grub-efi32@2.06: file names of
> patches should start with the package name Backtrace:rub-efi32@2.06
> [gnu-description]... In ice-9/boot-9.scm: 1752:10 17
> (with-exception-handler _ _ #:unwind? _ # _) In unknown file: 16
> (apply-smob/0 #<thunk 919b010>) In ice-9/boot-9.scm: 724:2 15
> (call-with-prompt _ _ #<procedure default-prompt-handle…>) In
> ice-9/eval.scm: 619:8 14 (_ #(#(#<directory (guile-user) 9192690>)))
> In guix/ui.scm: 2230:7 13 (run-guix . _)
>   2193:10 12 (run-guix-command _ . _)
> In ice-9/boot-9.scm:
>   1752:10 11 (with-exception-handler _ _ #:unwind? _ # _)
>   1752:10 10 (with-exception-handler _ _ #:unwind? _ # _)
> In guix/store.scm:
>    658:37  9 (thunk)
> In srfi/srfi-1.scm:
>     634:9  8 (for-each #<procedure 9265740 at guix/scripts/lint.scm…>
> …) In guix/scripts/lint.scm:
>      65:4  7 (run-checkers _ _ #:store _)
> In srfi/srfi-1.scm:
>     634:9  6 (for-each #<procedure b0bd948 at guix/scripts/lint.scm…>
> …) In guix/scripts/lint.scm:
>     74:21  5 (_ _)
> In guix/lint.scm:
>    1093:2  4 (check-gnu-synopsis+description #<package
> grub-efi32@2.…>) In srfi/srfi-1.scm:
>    730:15  3 (find #<procedure b8d71d0 at guix/lint.scm:1093:15 (de…>
> …) In guix/gnu-maintenance.scm:
>    100:21  2 (_ #<<gnu-package-descriptor> name: "3dldf"
> mundane-nam…>) In ice-9/boot-9.scm:
>   1685:16  1 (raise-exception _ #:continuable? _)
>   1685:16  0 (raise-exception _ #:continuable? _)
> 
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> error: <gnu-package-descriptor>: unbound variable

Denis.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: system.scm --]
[-- Type: text/x-scheme, Size: 3406 bytes --]

(use-modules (gnu) (gnu system nss) (guix utils))
(use-service-modules desktop sddm xorg)
(use-package-modules certs gnome)

(operating-system
  (host-name "dell-venue-8-pro")
  (timezone "Europe/Paris")
  (locale "en_US.utf8")

  (keyboard-layout (keyboard-layout "us" "altgr-intl"))

  ;; This device has a 32bit UEFI
  (bootloader (bootloader-configuration
	       (bootloader grub-efi32-bootloader)
               (targets '("/boot/efi"))
               (keyboard-layout keyboard-layout)))

  ;; Specify a mapped device for the encrypted root partition.
  ;; The UUID is that returned by 'cryptsetup luksUUID'.
  (mapped-devices
   (list (mapped-device
          (source (uuid "12345678-1234-1234-1234-123456789abc"))
          (target "my-root")
          (type luks-device-mapping))))

  (file-systems (append
                 (list (file-system
                         (device (file-system-label "my-root"))
                         (mount-point "/")
                         (type "ext4")
                         (dependencies mapped-devices))
                       (file-system
                         (device (uuid "1234-ABCD" 'fat))
                         (mount-point "/boot/efi")
                         (type "vfat")))
                 %base-file-systems))

  ;; Specify a swap file for the system, which resides on the
  ;; root file system.
  (swap-devices (list (swap-space
                       (target "/swapfile"))))

  (users (cons (user-account
                (name "parinux")
                (comment "Parinux")
		(group "parinux"))
               %base-user-accounts))

  (groups (cons* (user-group
                  (name "parinux"))
                 %base-groups))



  ;; This is where we specify system-wide packages.
  (packages (append (list
                     ;; for HTTPS access
                     nss-certs
                     ;; for user mounts
                     gvfs)
                    %base-packages))

  ;; Add GNOME and Xfce---we can choose at the log-in screen
  ;; by clicking the gear.  Use the "desktop" services, which
  ;; include the X11 log-in service, networking with
  ;; NetworkManager, and more.
  (services (if (target-x86-64?)
                (append (list (service gnome-desktop-service-type)
                              (service xfce-desktop-service-type)
                              (set-xorg-configuration
                               (xorg-configuration
                                (keyboard-layout keyboard-layout))))
                        %desktop-services)

                ;; FIXME: Since GDM depends on Rust (gdm -> gnome-shell -> gjs
                ;; -> mozjs -> rust) and Rust is currently unavailable on
                ;; non-x86_64 platforms, we use SDDM and Mate here instead of
                ;; GNOME and GDM.
                (append (list (service mate-desktop-service-type)
                              (service xfce-desktop-service-type)
                              (set-xorg-configuration
                               (xorg-configuration
                                (keyboard-layout keyboard-layout))
                               sddm-service-type))
                        %desktop-services)))

  ;; Allow resolution of '.local' host names with mDNS.
  (name-service-switch %mdns-host-lookup-nss))

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [bug#55343] [PATCH 1/2] utils: Define 'target-x86?' predicate.
  2022-05-09 23:18 [bug#55343] Add support for 32bit UEFI Denis 'GNUtoo' Carikli
@ 2022-05-09 23:24 ` Denis 'GNUtoo' Carikli
  2022-05-09 23:24   ` [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems Denis 'GNUtoo' Carikli
  0 siblings, 1 reply; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-05-09 23:24 UTC (permalink / raw)
  To: 55343; +Cc: Denis 'GNUtoo' Carikli

* guix/utils.scm (target-x86?): New predicate.
---
 guix/utils.scm | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/guix/utils.scm b/guix/utils.scm
index 44c46cb4a9..a9d8819770 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -14,6 +14,7 @@
 ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
 ;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -91,6 +92,7 @@ (define-module (guix utils)
             target-mingw?
             target-x86-32?
             target-x86-64?
+            target-x86?
             target-arm32?
             target-aarch64?
             target-arm?
@@ -683,6 +685,10 @@ (define* (target-x86-64? #:optional (target (or (%current-target-system)
 architecture (x86_64)?"
   (string-prefix? "x86_64-" target))
 
+(define* (target-x86? #:optional (target (or (%current-target-system)
+                                             (%current-system))))
+  (or (target-x86-32? target) (target-x86-64? target)))
+
 (define* (target-arm32? #:optional (target (or (%current-target-system)
                                                (%current-system))))
   (string-prefix? "arm" target))

base-commit: 37e44d48baf976f6bfcd885b2e10da4ab7be4af9
-- 
2.36.0





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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-09 23:24 ` [bug#55343] [PATCH 1/2] utils: Define 'target-x86?' predicate Denis 'GNUtoo' Carikli
@ 2022-05-09 23:24   ` Denis 'GNUtoo' Carikli
  2022-05-10  9:32     ` Maxime Devos
  0 siblings, 1 reply; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-05-09 23:24 UTC (permalink / raw)
  To: 55343; +Cc: Denis 'GNUtoo' Carikli

* gnu/bootloader/grub.scm (grub-efi32-bootloader): New variable.
  (install-grub-efi32): New variable
* gnu/build/bootloader.scm (install-efi32-loader): New variable.
  (install-efi32-loader): New variable.
* gnu/build/image.scm (initialize-efi32-partition): New variable
* gnu/packages/bootloaders.scm (grub-efi32): New variable.
* gnu/system/image.scm (esp32-partition): New variable
  (efi32-disk-image): New variable
  (efi32-raw-image-type): New variable.
  (partition-image): Add partition-image keyword
---
 gnu/bootloader/grub.scm      | 32 +++++++++++++++++++++++++
 gnu/build/bootloader.scm     | 46 +++++++++++++++++++++++++++++++++++-
 gnu/build/image.scm          |  9 +++++++
 gnu/packages/bootloaders.scm | 13 ++++++++++
 gnu/system/image.scm         | 19 +++++++++++++++
 5 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 120cd55012..1ea356030f 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2019, 2020 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -54,6 +55,7 @@ (define-module (gnu bootloader grub)
 
             grub-bootloader
             grub-efi-bootloader
+            grub-efi32-bootloader
             grub-efi-netboot-bootloader
             grub-mkrescue-bootloader
             grub-minimal-bootloader
@@ -608,6 +610,29 @@ (define install-grub-efi
                         "--bootloader-id=Guix"
                         "--efi-directory" target-esp)))))
 
+(define install-grub-efi32
+  #~(lambda (bootloader efi-dir mount-point)
+      ;; There is nothing useful to do when called in the context of a disk
+      ;; image generation.
+      (when efi-dir
+        ;; Install GRUB onto the EFI partition mounted at EFI-DIR, for the
+        ;; system whose root is mounted at MOUNT-POINT.
+        (let ((grub-install (string-append bootloader "/sbin/grub-install"))
+              (install-dir (string-append mount-point "/boot"))
+              ;; When installing Guix, it's common to mount EFI-DIR below
+              ;; MOUNT-POINT rather than /boot/efi on the live image.
+              (target-esp (if (file-exists? (string-append mount-point efi-dir))
+                              (string-append mount-point efi-dir)
+                              efi-dir)))
+          ;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
+          ;; root partition.
+          (setenv "GRUB_ENABLE_CRYPTODISK" "y")
+          (invoke/quiet grub-install "--boot-directory" install-dir
+                        "--bootloader-id=Guix"
+			(cond ((target-x86?) "--target=i386-efi")
+                              ((target-arm?) "--target=arm-efi"))
+                        "--efi-directory" target-esp)))))
+
 (define (install-grub-efi-netboot subdir)
   "Define a grub-efi-netboot bootloader installer for installation in SUBDIR,
 which is usually efi/Guix or efi/boot."
@@ -734,6 +759,13 @@ (define grub-efi-bootloader
    (name 'grub-efi)
    (package grub-efi)))
 
+(define grub-efi32-bootloader
+  (bootloader
+   (inherit grub-efi-bootloader)
+   (installer install-grub-efi32)
+   (name 'grub-efi32)
+   (package grub-efi32)))
+
 (define grub-efi-netboot-bootloader
   (bootloader
    (inherit grub-efi-bootloader)
diff --git a/gnu/build/bootloader.scm b/gnu/build/bootloader.scm
index 9a89fe55cb..d41143d98e 100644
--- a/gnu/build/bootloader.scm
+++ b/gnu/build/bootloader.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -25,7 +26,8 @@ (define-module (gnu build bootloader)
   #:use-module (rnrs io ports)
   #:use-module (rnrs io simple)
   #:export (write-file-on-device
-            install-efi-loader))
+            install-efi-loader
+            install-efi32-loader))
 
 \f
 ;;;
@@ -81,6 +83,29 @@ (define (install-efi grub grub-config esp)
             ;; Graft the configuration file onto the image.
             (string-append "boot/grub/grub.cfg=" grub-config))))
 
+(define (install-efi32 grub grub-config esp)
+  "Write a self-contained GRUB EFI 32bit loader to the mounted ESP using GRUB-CONFIG."
+  (let* ((system %host-type)
+         ;; Hard code the output location to a well-known path recognized by
+         ;; compliant firmware. See "3.5.1.1 Removable Media Boot Behaviour":
+         ;; http://www.uefi.org/sites/default/files/resources/UEFI%20Spec%202_6.pdf
+         (grub-mkstandalone (string-append grub "/bin/grub-mkstandalone"))
+         (efi-directory (string-append esp "/EFI/BOOT"))
+         ;; Map grub target names to boot file names.
+         (efi-targets (cond ((target-x86?)
+                             '("i386-efi" . "BOOTIA32.EFI"))
+                            ((target-arm?)
+                             '("arm-efi" . "BOOTARM.EFI")))))
+    ;; grub-mkstandalone requires a TMPDIR to prepare the firmware image.
+    (setenv "TMPDIR" esp)
+
+    (mkdir-p efi-directory)
+    (invoke grub-mkstandalone "-O" (car efi-targets)
+            "-o" (string-append efi-directory "/"
+                                (cdr efi-targets))
+            ;; Graft the configuration file onto the image.
+            (string-append "boot/grub/grub.cfg=" grub-config))))
+
 (define (install-efi-loader grub-efi esp)
   "Install in ESP directory the given GRUB-EFI bootloader.  Configure it to
 load the Grub bootloader located in the 'Guix_image' root partition."
@@ -99,3 +124,22 @@ (define (install-efi-loader grub-efi esp)
                configfile /boot/grub/grub.cfg~%")))
     (install-efi grub-efi grub-config esp)
     (delete-file grub-config)))
+
+(define (install-efi32-loader grub-efi32 esp)
+  "Install in ESP directory the given GRUB-EFI 32bit bootloader.  Configure it
+to load the Grub bootloader located in the 'Guix_image' root partition."
+  (let ((grub-config "grub.cfg"))
+    (call-with-output-file grub-config
+      (lambda (port)
+        ;; Create a tiny configuration file telling the embedded grub where to
+        ;; load the real thing.  XXX This is quite fragile, and can prevent
+        ;; the image from booting when there's more than one volume with this
+        ;; label present.  Reproducible almost-UUIDs could reduce the risk
+        ;; (not eliminate it).
+        (format port
+                "insmod part_msdos~@
+               insmod part_gpt~@
+               search --set=root --label Guix_image~@
+               configfile /boot/grub/grub.cfg~%")))
+    (install-efi32 grub-efi32 grub-config esp)
+    (delete-file grub-config)))
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index 81caa424f8..bae747494f 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
 ;;; Copyright © 2020, 2022 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -40,6 +41,7 @@ (define-module (gnu build image)
             convert-disk-image
             genimage
             initialize-efi-partition
+            initialize-efi32-partition
             initialize-root-partition
 
             make-iso9660-image))
@@ -162,6 +164,13 @@ (define* (initialize-efi-partition root
   "Install in ROOT directory, an EFI loader using GRUB-EFI."
   (install-efi-loader grub-efi root))
 
+(define* (initialize-efi32-partition root
+                                     #:key
+                                     grub-efi32
+                                     #:allow-other-keys)
+  "Install in ROOT directory, an EFI 32bit loader using GRUB-EFI32."
+  (install-efi32-loader grub-efi32 root))
+
 (define* (initialize-root-partition root
                                     #:key
                                     bootcfg
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 7ea6f5a647..f133d9f604 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -15,6 +15,7 @@
 ;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com>
 ;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
 ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -332,6 +333,18 @@ (define-public grub-efi
                                        "/bin/mcopy\"")))
                      #t))))))))))
 
+(define-public grub-efi32
+  (package
+    (inherit grub-efi)
+    (name "grub-efi32")
+    (synopsis "GRand Unified Boot loader (UEFI 32bit version)")
+    (arguments
+     `(,@(substitute-keyword-arguments (package-arguments grub-efi)
+           ((#:configure-flags flags
+             ''()) `(cons* ,(cond ((target-x86?) "--target=i386")
+                                  ((target-arm?) "--target=arm"))
+                           ,flags)))))))
+
 ;; Because grub searches hardcoded paths it's easiest to just build grub
 ;; again to make it find both grub-pc and grub-efi.  There is a command
 ;; line argument which allows you to specify ONE platform - but
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index 42e215f614..e35c54ca50 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2020, 2021 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -65,6 +66,7 @@ (define-module (gnu system image)
             root-label
 
             esp-partition
+            esp32-partition
             root-partition
 
             efi-disk-image
@@ -74,6 +76,7 @@ (define-module (gnu system image)
 
             image-with-os
             efi-raw-image-type
+            efi32-raw-image-type
             qcow2-image-type
             iso-image-type
             uncompressed-iso-image-type
@@ -109,6 +112,11 @@ (define esp-partition
    (flags '(esp))
    (initializer (gexp initialize-efi-partition))))
 
+(define esp32-partition
+  (partition
+   (inherit esp-partition)
+   (initializer (gexp initialize-efi32-partition))))
+
 (define root-partition
   (partition
    (size 'guess)
@@ -122,6 +130,11 @@ (define efi-disk-image
    (format 'disk-image)
    (partitions (list esp-partition root-partition))))
 
+(define efi32-disk-image
+  (image
+   (format 'disk-image)
+   (partitions (list esp32-partition root-partition))))
+
 (define iso9660-image
   (image
    (format 'iso9660)
@@ -163,6 +176,11 @@ (define efi-raw-image-type
    (name 'efi-raw)
    (constructor (cut image-with-os efi-disk-image <>))))
 
+(define efi32-raw-image-type
+  (image-type
+   (name 'efi32-raw)
+   (constructor (cut image-with-os efi32-disk-image <>))))
+
 (define qcow2-image-type
   (image-type
    (name 'qcow2)
@@ -352,6 +370,7 @@ (define (partition-image partition)
                                                 #$(image-shared-store? image))
                               #:system-directory #$os
                               #:grub-efi #+grub-efi
+                              #:grub-efi32 #+grub-efi32
                               #:bootloader-package
                               #+(bootloader-package bootloader)
                               #:bootloader-installer
-- 
2.36.0





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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-09 23:24   ` [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems Denis 'GNUtoo' Carikli
@ 2022-05-10  9:32     ` Maxime Devos
  2022-05-10 21:39       ` Denis 'GNUtoo' Carikli
  2022-05-11 17:00       ` Denis 'GNUtoo' Carikli
  0 siblings, 2 replies; 17+ messages in thread
From: Maxime Devos @ 2022-05-10  9:32 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli, 55343

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

Denis 'GNUtoo' Carikli schreef op di 10-05-2022 om 01:24 [+0200]:
> +           ((#:configure-flags flags
> +             ''()) `(cons* ,(cond ((target-x86?) "--target=i386")
> +                                  ((target-arm?) "--target=arm"))
> +                           ,flags)))))))

Isn't this just grub but compiled for the 32-bit variant of the system?
If so, can we reuse Guix built-in cross-compilation and native
compilation mechanisms here?  Maybe

  (list #:target "i386")

or

  (list #:target "i686-linux-gnu") ; if i386 is invalid

or

  (list #:system "i686-linux)

or

  (list #:system "i586-gnu")


Or do you mean to use 'grub' as a cross-compiler here (instead of
something that is being cross-compiled), like 'gcc'?

Greetings,
Maxime

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-10  9:32     ` Maxime Devos
@ 2022-05-10 21:39       ` Denis 'GNUtoo' Carikli
  2022-05-11  9:07         ` Maxime Devos
  2022-05-11 17:00       ` Denis 'GNUtoo' Carikli
  1 sibling, 1 reply; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-05-10 21:39 UTC (permalink / raw)
  To: Maxime Devos; +Cc: 55343

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

On Tue, 10 May 2022 11:32:52 +0200
Maxime Devos <maximedevos@telenet.be> wrote:

> Denis 'GNUtoo' Carikli schreef op di 10-05-2022 om 01:24 [+0200]:
> > +           ((#:configure-flags flags
> > +             ''()) `(cons* ,(cond ((target-x86?) "--target=i386")
> > +                                  ((target-arm?) "--target=arm"))
> > +                           ,flags)))))))
> 
> Isn't this just grub but compiled for the 32-bit variant of the
> system?

> Or do you mean to use 'grub' as a cross-compiler here (instead of
> something that is being cross-compiled), like 'gcc'?
Apparently the modification I did (passing --target=i386) results in a
64bit grub-mkimage and 32bit modules in lib/grub/i386-efi so I think
it's more like a cross-compiler. I verified that by installing
grub-efi32 and using file on the mentioned files.

It's also possible to have something like multiple target/architectures
with GRUB by compiling it for each target/architecture and then
shipping the modules in lib/grub/* but that would require way more
work, so it would make more sense to do that as a separate patch set if
needed.

Though for now I'm just interested in adding 32bit UEFI support because
I did the work for testing/learning, and I would prefer if that work
results in Guix supporting 32bit UEFI somehow.

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-10 21:39       ` Denis 'GNUtoo' Carikli
@ 2022-05-11  9:07         ` Maxime Devos
  2022-05-11 17:35           ` Denis 'GNUtoo' Carikli
  0 siblings, 1 reply; 17+ messages in thread
From: Maxime Devos @ 2022-05-11  9:07 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli; +Cc: 55343

Denis 'GNUtoo' Carikli schreef op di 10-05-2022 om 23:39 [+0200]:
> On Tue, 10 May 2022 11:32:52 +0200
> Maxime Devos <maximedevos@telenet.be> wrote:
> 
> > Denis 'GNUtoo' Carikli schreef op di 10-05-2022 om 01:24 [+0200]:
> > > +           ((#:configure-flags flags
> > > +             ''()) `(cons* ,(cond ((target-x86?) "--
> target=i386")
> > > +                                  ((target-arm?) "--
> target=arm"))
> > > +                           ,flags)))))))
> > 
> > Isn't this just grub but compiled for the 32-bit variant of the
> > system?
> 
> > Or do you mean to use 'grub' as a cross-compiler here (instead of
> > something that is being cross-compiled), like 'gcc'?
> Apparently the modification I did (passing --target=i386) results in
> a
> 64bit grub-mkimage and 32bit modules in lib/grub/i386-efi so I think
> it's more like a cross-compiler. I verified that by installing
> grub-efi32 and using file on the mentioned files.
> [...]

Ok, --target looks like a better fit in this case.  Though now I'm
wondering if on i686-linux we might need a grub-efi64 variant on some
setups ...

Greetings,
Maxime






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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-10  9:32     ` Maxime Devos
  2022-05-10 21:39       ` Denis 'GNUtoo' Carikli
@ 2022-05-11 17:00       ` Denis 'GNUtoo' Carikli
  2022-05-11 17:19         ` Maxime Devos
  2022-05-11 17:25         ` Maxime Devos
  1 sibling, 2 replies; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-05-11 17:00 UTC (permalink / raw)
  To: Maxime Devos; +Cc: 55343


[-- Attachment #1.1: Type: text/plain, Size: 2982 bytes --]

Hi,

On Tue, 10 May 2022 11:32:52 +0200
Maxime Devos <maximedevos@telenet.be> wrote:
>   (list #:target "i386")

I've tried that I get the following error:
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> dynamic linker name not known for this system "i386"

This means that I have to use "i686-linux" because only "i686-linux" is
in the list of allowed values.

I've tried and this adds a cross toolchain to the list of
dependencies[1] and this doesn't work because efibootmgr which is a
dependency doesn't compile anymore as it doesn't find some of the
headers like efivar.h and efiboot.h. This could probably be fixed
somehow though.

In addition I've found the following issues with that approach:
- It hardcode the kernel (Linux or HURD) so we'd probably
  need extra logic to handle it well. With --target=i386 that is
  transparent. Note that I didn't test grub-efi32 with HURD in either
  cases.

- It doesn't support "canadian" cross compilation where the builder
  (for instance x86) builds a cross compiler to run on another
  architecture (for instance ARM) to then compile programs for another
  architecture (for instance riscv). With --target=i386 we can in
  theory do that (though I've not tested it).

And with it, I see the following advantage: since it's wrapped somehow
Guix can probably do things automatically (like checks or change
things) on all the packages that are cross compiled.

What approach do you think is best (I don't know the implementation of
(list #:target "i686-linux") so you probably know way better than me
which one is the best) ?.

If (list #:target "i686-linux") is the way to go, do you have any
pointers to make it find the headers it needs? I've attached its build
log in case it is useful.

References:
-----------
[1] Here's the output when trying to build grub-efi32 with
    (list #:target "i686-linux"):
> $ ./pre-inst-env guix package -i grub-efi32
> The following package will be upgraded:
>    grub-efi32 (dependencies or package changed)
> 
> The following derivations will be built:
>   /gnu/store/j4divh7pf1bxr11ivzddqhsihan6ij4p-util-linux-2.37.2.drv
>   /gnu/store/h86glf6qlyfmf214qj6xsqbj8vmrfss9-zlib-1.2.11.drv
>   /gnu/store/hy4x62rrx3gqdnn476dja6im74pxzkpk-glibc-cross-i686-linux-2.33.drv
>   /gnu/store/1qynvffnfnf7dlzmrkrkx7nzxq6mkz1k-gcc-cross-sans-libc-i686-linux-10.3.0.drv
>   /gnu/store/kyr74wyvikyldkx9a0zd55fmxjs6862c-binutils-cross-i686-linux-2.37.drv
>   /gnu/store/wc7zhlgnzrg9z5w5wqyvkwlg0ninavs1-ld-wrapper-i686-linux-0.drv
>   /gnu/store/i4h82qxwyaj3i97rgcvh6khfibbj4x3p-linux-libre-headers-cross-i686-linux-5.10.35.drv
>   /gnu/store/j4w5c2iqvm9ylfnc2gsadipngl00labp-gcc-cross-i686-linux-10.3.0.drv
>   /gnu/store/y15y0pici7yhgycjv13a4hm9jjshdzzm-ncurses-6.2.20210619.drv
>   /gnu/store/l5jdw7k9mdm0af4gyklhixw447fgsnxn-pkg-config-i686-linux-0.29.2.drv
>   /gnu/store/zg2fyiwc4i4vwarbk8imi9wsgzp8z90h-file-5.39.drv

Denis.

[-- Attachment #1.2: s1q7llv6m4nn8256hjcjx997rjf0vm-efibootmgr-17.drv.xz --]
[-- Type: application/x-xz, Size: 2864 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-11 17:00       ` Denis 'GNUtoo' Carikli
@ 2022-05-11 17:19         ` Maxime Devos
  2022-05-11 17:25         ` Maxime Devos
  1 sibling, 0 replies; 17+ messages in thread
From: Maxime Devos @ 2022-05-11 17:19 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli; +Cc: 55343

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

Denis 'GNUtoo' Carikli schreef op wo 11-05-2022 om 19:00 [+0200]:
> What approach do you think is best (I don't know the implementation
> of
> (list #:target "i686-linux") so you probably know way better than me
> which one is the best) ?.

#:target determines for which architecture the grub binaries
('bin/install-grub' or something like that?  I forgot the name ...),
whereas (IIUC) what we need is to compile the _bootloader_ itself (and
its modules) for "i[36]86-SOMETHING" (*).  So since #:target isn't
appropriate here, and what you originally sent presumably works, so
let's go for the original "--target=..."?

(*) in practice, I don't think the SOMETHING or 386/686 matters here,
I'd expect the grub makefile/configure to set the -nostdlib and -
march=... bits appropriately?

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-11 17:00       ` Denis 'GNUtoo' Carikli
  2022-05-11 17:19         ` Maxime Devos
@ 2022-05-11 17:25         ` Maxime Devos
  2022-05-18 13:50           ` Denis 'GNUtoo' Carikli
  1 sibling, 1 reply; 17+ messages in thread
From: Maxime Devos @ 2022-05-11 17:25 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli; +Cc: 55343

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

Denis 'GNUtoo' Carikli schreef op wo 11-05-2022 om 19:00 [+0200]:
> [1] Here's the output when trying to build grub-efi32 with
>     (list #:target "i686-linux"):

I don't think it will be relevant to grub-efi32, at least for now, but
I have opened an issue for this at <https://issues.guix.gnu.org/55373>.

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-11  9:07         ` Maxime Devos
@ 2022-05-11 17:35           ` Denis 'GNUtoo' Carikli
  0 siblings, 0 replies; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-05-11 17:35 UTC (permalink / raw)
  To: Maxime Devos; +Cc: 55343

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

On Wed, 11 May 2022 11:07:22 +0200
Maxime Devos <maximedevos@telenet.be> wrote:

> Ok, --target looks like a better fit in this case.
Sorry for the previous mail, I saw this one after finishing sending the
one with a report on tests with (list #:target "i686-linux").

> Though now I'm wondering if on i686-linux we might need a grub-efi64
> variant on some setups ...
Good question.

It would require to have a computer where the UEFI implementation is
only able to launch 64bit PE files on computers with a CPU that also
support 32bit OS.

For ARM I'm not sure if we can boot 32bit kernels on 64bit CPUs: In
theory many ARM computers hardware is capable of that. However in
practice we'd need to make that kernel configurations works for that,
and platform drivers that only work for aarch64 are probably required
anyway. Maybe in case of emulation that doesn't apply though.

For x86 I didn't ear of 64bit-only UEFI with CPUs that still
support 32bit OS, but it could exist.

And according to the official GRUB documentation, it is possible to
boot 32bit OS when the UEFI is 64bit and vice versa[1]:
|                                | ia32 EFI | amd64 EFI |
| BIOS chainloading              | no (1)   | no (1)    |
| [...]                          | [...]    | [...]     |
| FreeDOS                        | no (1)   | no (1)    |
| Multiboot                      | yes      | yes       |
| Multiboot2                     | yes      | yes       |
| 32-bit Linux (legacy protocol) | no (1)   | no (1)    |
| 64-bit Linux (legacy protocol) | no (1)   | no (1)    |
| 32-bit Linux (modern protocol) | yes      | yes       |
| 64-bit Linux (modern protocol) | yes      | yes       |
| [...]                          | [...]    | [...]     |
| 32-bit EFI chainloader         | yes      | no (3)    |
| 64-bit EFI chainloader         | no (3)   | yes       |
| [...]                          | [...]    | [...]     |
1. Requires BIOS 

So there might be a use case here if such machines exist. I'll try to
look for infos on that.

References:
[1]https://www.gnu.org/software/grub/manual/grub/grub.html#Supported-boot-targets

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-11 17:25         ` Maxime Devos
@ 2022-05-18 13:50           ` Denis 'GNUtoo' Carikli
  2022-06-11 16:41             ` Denis 'GNUtoo' Carikli
  2022-06-11 19:52             ` [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems Maxime Devos
  0 siblings, 2 replies; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-05-18 13:50 UTC (permalink / raw)
  To: Maxime Devos; +Cc: 55343

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

On Wed, 11 May 2022 19:25:10 +0200
Maxime Devos <maximedevos@telenet.be> wrote:

> Denis 'GNUtoo' Carikli schreef op wo 11-05-2022 om 19:00 [+0200]:
> > [1] Here's the output when trying to build grub-efi32 with
> >     (list #:target "i686-linux"):  
> 
> I don't think it will be relevant to grub-efi32, at least for now, but
> I have opened an issue for this at
> <https://issues.guix.gnu.org/55373>.
Thanks.

Do I still need to do something with the patch serie adding support for
32bit UEFI or is everything OK?

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-18 13:50           ` Denis 'GNUtoo' Carikli
@ 2022-06-11 16:41             ` Denis 'GNUtoo' Carikli
  2022-06-17 20:36               ` [bug#55343] Add support for 32bit UEFI Ludovic Courtès
  2022-06-11 19:52             ` [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems Maxime Devos
  1 sibling, 1 reply; 17+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2022-06-11 16:41 UTC (permalink / raw)
  To: Maxime Devos; +Cc: 55343

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

On Wed, 18 May 2022 15:50:03 +0200
Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> wrote:

> On Wed, 11 May 2022 19:25:10 +0200
> Maxime Devos <maximedevos@telenet.be> wrote:
> 
> > Denis 'GNUtoo' Carikli schreef op wo 11-05-2022 om 19:00 [+0200]:
> > > [1] Here's the output when trying to build grub-efi32 with
> > >     (list #:target "i686-linux"):  
> > 
> > I don't think it will be relevant to grub-efi32, at least for now,
> > but I have opened an issue for this at
> > <https://issues.guix.gnu.org/55373>.
> Thanks.
> 
> Do I still need to do something with the patch serie adding support
> for 32bit UEFI or is everything OK?
As I understood that serie was ready to be merged or is there something
I still need to do on my side?

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems
  2022-05-18 13:50           ` Denis 'GNUtoo' Carikli
  2022-06-11 16:41             ` Denis 'GNUtoo' Carikli
@ 2022-06-11 19:52             ` Maxime Devos
  1 sibling, 0 replies; 17+ messages in thread
From: Maxime Devos @ 2022-06-11 19:52 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli; +Cc: 55343

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

Denis 'GNUtoo' Carikli schreef op wo 18-05-2022 om 15:50 [+0200]:
> [...]
> Do I still need to do something with the patch serie adding support for
> 32bit UEFI or is everything OK?

I'm not familiar enough with grub etc. to tell.

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

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

* [bug#55343] Add support for 32bit UEFI
  2022-06-11 16:41             ` Denis 'GNUtoo' Carikli
@ 2022-06-17 20:36               ` Ludovic Courtès
  2022-06-18  5:18                 ` Timothy Sample
  0 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2022-06-17 20:36 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli, Mathieu Othacehe; +Cc: Maxime Devos, 55343

Hi Denis,

Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> skribis:

> On Wed, 18 May 2022 15:50:03 +0200
> Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> wrote:
>
>> On Wed, 11 May 2022 19:25:10 +0200
>> Maxime Devos <maximedevos@telenet.be> wrote:
>> 
>> > Denis 'GNUtoo' Carikli schreef op wo 11-05-2022 om 19:00 [+0200]:
>> > > [1] Here's the output when trying to build grub-efi32 with
>> > >     (list #:target "i686-linux"):  
>> > 
>> > I don't think it will be relevant to grub-efi32, at least for now,
>> > but I have opened an issue for this at
>> > <https://issues.guix.gnu.org/55373>.
>> Thanks.
>> 
>> Do I still need to do something with the patch serie adding support
>> for 32bit UEFI or is everything OK?
> As I understood that serie was ready to be merged or is there something
> I still need to do on my side?

Sorry for the delay; Mathieu, this is more your area of expertise: WDYT?

  https://issues.guix.gnu.org/55343

Ludo’.




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

* [bug#55343] Add support for 32bit UEFI
  2022-06-17 20:36               ` [bug#55343] Add support for 32bit UEFI Ludovic Courtès
@ 2022-06-18  5:18                 ` Timothy Sample
  2022-06-19 19:02                   ` Mathieu Othacehe
  0 siblings, 1 reply; 17+ messages in thread
From: Timothy Sample @ 2022-06-18  5:18 UTC (permalink / raw)
  To: Ludovic Courtès
  Cc: Mathieu Othacehe, Maxime Devos, 55343,
	Denis 'GNUtoo' Carikli

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

Hi all,

Ludovic Courtès <ludo@gnu.org> writes:

> Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> skribis:
>
>> As I understood that serie was ready to be merged or is there something
>> I still need to do on my side?
>
> Sorry for the delay; Mathieu, this is more your area of expertise: WDYT?

I’m not Mathieu, but I wanted to chime in anyway.  :)

I have an old Mac Mini with the same setup: it’s a 64bit system with a
32bit UEFI.  I’ve been using the same GRUB package and bootloader
modifications from this patch for years and it works great.  I also just
tested the image generation code.  I built an image, wrote it to a USB
storage device, and booted the machine from it.  That’s pretty handy!

I’ve attached a slightly modified version of the second patch.  It
removes some duplication.  Essentially, I added a keyword to the
‘install-efi’ procedure so that callers can override the GRUB image type
and output file.  There’s lots of duplication in the patch, but that
seems to be largely due to the structure of the existing code, so I
wouldn’t worry about it.

So, barring any comments from Mathieu, these patches LGTM.


-- Tim


[-- Attachment #2: 0001-image-Support-32bit-UEFI-on-64bit-systems.patch --]
[-- Type: text/x-patch, Size: 13502 bytes --]

From 4be147b1c8fdef014ba06fd92e701753148d58c6 Mon Sep 17 00:00:00 2001
From: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Date: Tue, 10 May 2022 01:24:51 +0200
Subject: [PATCH] image: Support 32bit UEFI on 64bit systems.

* gnu/bootloader/grub.scm (grub-efi32-bootloader): New variable.
(install-grub-efi32): New variable.
* gnu/build/bootloader.scm (install-efi): Add a 'targets' keyword
argument.
(install-efi-loader): Likewise.
* gnu/build/image.scm (initialize-efi32-partition): New procedure.
* gnu/packages/bootloaders.scm (grub-efi32): New variable.
* gnu/system/image.scm (esp32-partition): New variable
(efi32-disk-image): New variable.
(efi32-raw-image-type): New variable.
(system-disk-image)[partition-image]: Set '#:grub-efi32' when
calling the partition initializer.
---
 gnu/bootloader/grub.scm      | 32 +++++++++++++++++++++++++++++++
 gnu/build/bootloader.scm     | 37 +++++++++++++++++++++++-------------
 gnu/build/image.scm          | 14 ++++++++++++++
 gnu/packages/bootloaders.scm | 13 +++++++++++++
 gnu/system/image.scm         | 19 ++++++++++++++++++
 5 files changed, 102 insertions(+), 13 deletions(-)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 65d7171432..4f18c9b518 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -8,6 +8,7 @@
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
 ;;; Copyright © 2022 Karl Hallsby <karl@hallsby.com>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -57,6 +58,7 @@ (define-module (gnu bootloader grub)
             grub-bootloader
             grub-efi-bootloader
             grub-efi-removable-bootloader
+            grub-efi32-bootloader
             grub-efi-netboot-bootloader
             grub-mkrescue-bootloader
             grub-minimal-bootloader
@@ -636,6 +638,29 @@ (define install-grub-efi-removable
                         "--bootloader-id=Guix"
                         "--efi-directory" target-esp)))))
 
+(define install-grub-efi32
+  #~(lambda (bootloader efi-dir mount-point)
+      ;; There is nothing useful to do when called in the context of a disk
+      ;; image generation.
+      (when efi-dir
+        ;; Install GRUB onto the EFI partition mounted at EFI-DIR, for the
+        ;; system whose root is mounted at MOUNT-POINT.
+        (let ((grub-install (string-append bootloader "/sbin/grub-install"))
+              (install-dir (string-append mount-point "/boot"))
+              ;; When installing Guix, it's common to mount EFI-DIR below
+              ;; MOUNT-POINT rather than /boot/efi on the live image.
+              (target-esp (if (file-exists? (string-append mount-point efi-dir))
+                              (string-append mount-point efi-dir)
+                              efi-dir)))
+          ;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
+          ;; root partition.
+          (setenv "GRUB_ENABLE_CRYPTODISK" "y")
+          (invoke/quiet grub-install "--boot-directory" install-dir
+                        "--bootloader-id=Guix"
+			(cond ((target-x86?) "--target=i386-efi")
+                              ((target-arm?) "--target=arm-efi"))
+                        "--efi-directory" target-esp)))))
+
 (define (install-grub-efi-netboot subdir)
   "Define a grub-efi-netboot bootloader installer for installation in SUBDIR,
 which is usually efi/Guix or efi/boot."
@@ -768,6 +793,13 @@ (define grub-efi-removable-bootloader
    (name 'grub-efi-removable-bootloader)
    (installer install-grub-efi-removable)))
 
+(define grub-efi32-bootloader
+  (bootloader
+   (inherit grub-efi-bootloader)
+   (installer install-grub-efi32)
+   (name 'grub-efi32)
+   (package grub-efi32)))
+
 (define grub-efi-netboot-bootloader
   (bootloader
    (inherit grub-efi-bootloader)
diff --git a/gnu/build/bootloader.scm b/gnu/build/bootloader.scm
index 9a89fe55cb..af6063a884 100644
--- a/gnu/build/bootloader.scm
+++ b/gnu/build/bootloader.scm
@@ -1,6 +1,8 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
+;;; Copyright © 2022 Timothy Sample <samplet@ngyro.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -54,8 +56,12 @@ (define (write-file-on-device file size device offset)
 ;;; EFI bootloader.
 ;;;
 
-(define (install-efi grub grub-config esp)
-  "Write a self-contained GRUB EFI loader to the mounted ESP using GRUB-CONFIG."
+(define* (install-efi grub grub-config esp #:key targets)
+  "Write a self-contained GRUB EFI loader to the mounted ESP using
+GRUB-CONFIG.
+
+If TARGETS is set, use its car as the GRUB image format and its cdr as
+the output filename.  Otherwise, use defaults for the host platform."
   (let* ((system %host-type)
          ;; Hard code the output location to a well-known path recognized by
          ;; compliant firmware. See "3.5.1.1 Removable Media Boot Behaviour":
@@ -63,14 +69,15 @@ (define (install-efi grub grub-config esp)
          (grub-mkstandalone (string-append grub "/bin/grub-mkstandalone"))
          (efi-directory (string-append esp "/EFI/BOOT"))
          ;; Map grub target names to boot file names.
-         (efi-targets (cond ((string-prefix? "x86_64" system)
-                             '("x86_64-efi" . "BOOTX64.EFI"))
-                            ((string-prefix? "i686" system)
-                             '("i386-efi" . "BOOTIA32.EFI"))
-                            ((string-prefix? "armhf" system)
-                             '("arm-efi" . "BOOTARM.EFI"))
-                            ((string-prefix? "aarch64" system)
-                             '("arm64-efi" . "BOOTAA64.EFI")))))
+         (efi-targets (or targets
+                          (cond ((string-prefix? "x86_64" system)
+                                 '("x86_64-efi" . "BOOTX64.EFI"))
+                                ((string-prefix? "i686" system)
+                                 '("i386-efi" . "BOOTIA32.EFI"))
+                                ((string-prefix? "armhf" system)
+                                 '("arm-efi" . "BOOTARM.EFI"))
+                                ((string-prefix? "aarch64" system)
+                                 '("arm64-efi" . "BOOTAA64.EFI"))))))
     ;; grub-mkstandalone requires a TMPDIR to prepare the firmware image.
     (setenv "TMPDIR" esp)
 
@@ -81,9 +88,12 @@ (define (install-efi grub grub-config esp)
             ;; Graft the configuration file onto the image.
             (string-append "boot/grub/grub.cfg=" grub-config))))
 
-(define (install-efi-loader grub-efi esp)
+(define* (install-efi-loader grub-efi esp #:key targets)
   "Install in ESP directory the given GRUB-EFI bootloader.  Configure it to
-load the Grub bootloader located in the 'Guix_image' root partition."
+load the Grub bootloader located in the 'Guix_image' root partition.
+
+If TARGETS is set, use its car as the GRUB image format and its cdr as
+the output filename.  Otherwise, use defaults for the host platform."
   (let ((grub-config "grub.cfg"))
     (call-with-output-file grub-config
       (lambda (port)
@@ -97,5 +107,6 @@ (define (install-efi-loader grub-efi esp)
                insmod part_gpt~@
                search --set=root --label Guix_image~@
                configfile /boot/grub/grub.cfg~%")))
-    (install-efi grub-efi grub-config esp)
+    (install-efi grub-efi grub-config esp #:targets targets)
     (delete-file grub-config)))
+
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index ddfd34c111..321be8e4b1 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2020, 2022 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -27,6 +28,7 @@ (define-module (gnu build image)
   #:use-module (guix build syscalls)
   #:use-module (guix build utils)
   #:use-module (guix store database)
+  #:use-module (guix utils)
   #:use-module (gnu build bootloader)
   #:use-module (gnu build install)
   #:use-module (gnu build linux-boot)
@@ -41,6 +43,7 @@ (define-module (gnu build image)
             convert-disk-image
             genimage
             initialize-efi-partition
+            initialize-efi32-partition
             initialize-root-partition
 
             make-iso9660-image))
@@ -169,6 +172,17 @@ (define* (initialize-efi-partition root
   "Install in ROOT directory, an EFI loader using GRUB-EFI."
   (install-efi-loader grub-efi root))
 
+(define* (initialize-efi32-partition root
+                                     #:key
+                                     grub-efi32
+                                     #:allow-other-keys)
+  "Install in ROOT directory, an EFI 32bit loader using GRUB-EFI32."
+  (install-efi-loader grub-efi32 root
+                      #:targets (cond ((target-x86?)
+                                       '("i386-efi" . "BOOTIA32.EFI"))
+                                      ((target-arm?)
+                                       '("arm-efi" . "BOOTARM.EFI")))))
+
 (define* (initialize-root-partition root
                                     #:key
                                     bootcfg
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 91d259475a..71a10f54d5 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -15,6 +15,7 @@
 ;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com>
 ;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
 ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -332,6 +333,18 @@ (define-public grub-efi
                                        "/bin/mcopy\"")))
                      #t))))))))))
 
+(define-public grub-efi32
+  (package
+    (inherit grub-efi)
+    (name "grub-efi32")
+    (synopsis "GRand Unified Boot loader (UEFI 32bit version)")
+    (arguments
+     `(,@(substitute-keyword-arguments (package-arguments grub-efi)
+           ((#:configure-flags flags
+             ''()) `(cons* ,(cond ((target-x86?) "--target=i386")
+                                  ((target-arm?) "--target=arm"))
+                           ,flags)))))))
+
 ;; Because grub searches hardcoded paths it's easiest to just build grub
 ;; again to make it find both grub-pc and grub-efi.  There is a command
 ;; line argument which allows you to specify ONE platform - but
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index f02f6e0b8c..5972a944d7 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2020, 2021 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
 ;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org>
+;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -66,6 +67,7 @@ (define-module (gnu system image)
             root-label
 
             esp-partition
+            esp32-partition
             root-partition
 
             efi-disk-image
@@ -75,6 +77,7 @@ (define-module (gnu system image)
 
             image-with-os
             efi-raw-image-type
+            efi32-raw-image-type
             qcow2-image-type
             iso-image-type
             uncompressed-iso-image-type
@@ -110,6 +113,11 @@ (define esp-partition
    (flags '(esp))
    (initializer (gexp initialize-efi-partition))))
 
+(define esp32-partition
+  (partition
+   (inherit esp-partition)
+   (initializer (gexp initialize-efi32-partition))))
+
 (define root-partition
   (partition
    (size 'guess)
@@ -123,6 +131,11 @@ (define efi-disk-image
    (format 'disk-image)
    (partitions (list esp-partition root-partition))))
 
+(define efi32-disk-image
+  (image
+   (format 'disk-image)
+   (partitions (list esp32-partition root-partition))))
+
 (define iso9660-image
   (image
    (format 'iso9660)
@@ -164,6 +177,11 @@ (define efi-raw-image-type
    (name 'efi-raw)
    (constructor (cut image-with-os efi-disk-image <>))))
 
+(define efi32-raw-image-type
+  (image-type
+   (name 'efi32-raw)
+   (constructor (cut image-with-os efi32-disk-image <>))))
+
 (define qcow2-image-type
   (image-type
    (name 'qcow2)
@@ -376,6 +394,7 @@ (define* (system-disk-image image
                                                 #$(image-shared-store? image))
                               #:system-directory #$os
                               #:grub-efi #+grub-efi
+                              #:grub-efi32 #+grub-efi32
                               #:bootloader-package
                               #+(bootloader-package bootloader)
                               #:bootloader-installer
-- 
2.36.1


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

* [bug#55343] Add support for 32bit UEFI
  2022-06-18  5:18                 ` Timothy Sample
@ 2022-06-19 19:02                   ` Mathieu Othacehe
  2022-06-24  8:23                     ` bug#55343: " Mathieu Othacehe
  0 siblings, 1 reply; 17+ messages in thread
From: Mathieu Othacehe @ 2022-06-19 19:02 UTC (permalink / raw)
  To: Timothy Sample
  Cc: Ludovic Courtès, Maxime Devos, 55343,
	Denis 'GNUtoo' Carikli


Hey,

This seems good to me! There are two things that we could maybe improve
before pushing or later on:

- We could tweak the "grub" package so that the x86_64-linux package
  contains the i386-efi and x86_64-efi modules. That's the
  case for the Archlinux package for instance:
  https://archlinux.org/packages/core/x86_64/grub/.

  This way we could get rid of the grub-efi32 package and rely only on
  the grub-efi package. We would need to come up with something
  similar for the aarch64-linux Grub package I guess.

- The install-grub-efi, install-grub-efi-removable and
  install-grub-efi32 procedures share some bits. It could be nice to
  factorize them if possible.

As everything else is ready to go, I'm fine to proceed here anyway.

WDYT?

Thanks,

Mathieu




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

* bug#55343: Add support for 32bit UEFI
  2022-06-19 19:02                   ` Mathieu Othacehe
@ 2022-06-24  8:23                     ` Mathieu Othacehe
  0 siblings, 0 replies; 17+ messages in thread
From: Mathieu Othacehe @ 2022-06-24  8:23 UTC (permalink / raw)
  To: Timothy Sample
  Cc: Ludovic Courtès, Maxime Devos,
	Denis 'GNUtoo' Carikli, 55343-done


Hey,

>   This way we could get rid of the grub-efi32 package and rely only on
>   the grub-efi package. We would need to come up with something
>   similar for the aarch64-linux Grub package I guess.

I tried to do that, turns out Grub doesn't have support for building
modules for multiple architectures in a single pass. You need to call
configure and make for each architecture. Having a dedicated grub-efi32
doesn't seem so bad after all.

I pushed the patchset, thanks!

Mathieu




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

end of thread, other threads:[~2022-06-24  8:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-09 23:18 [bug#55343] Add support for 32bit UEFI Denis 'GNUtoo' Carikli
2022-05-09 23:24 ` [bug#55343] [PATCH 1/2] utils: Define 'target-x86?' predicate Denis 'GNUtoo' Carikli
2022-05-09 23:24   ` [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems Denis 'GNUtoo' Carikli
2022-05-10  9:32     ` Maxime Devos
2022-05-10 21:39       ` Denis 'GNUtoo' Carikli
2022-05-11  9:07         ` Maxime Devos
2022-05-11 17:35           ` Denis 'GNUtoo' Carikli
2022-05-11 17:00       ` Denis 'GNUtoo' Carikli
2022-05-11 17:19         ` Maxime Devos
2022-05-11 17:25         ` Maxime Devos
2022-05-18 13:50           ` Denis 'GNUtoo' Carikli
2022-06-11 16:41             ` Denis 'GNUtoo' Carikli
2022-06-17 20:36               ` [bug#55343] Add support for 32bit UEFI Ludovic Courtès
2022-06-18  5:18                 ` Timothy Sample
2022-06-19 19:02                   ` Mathieu Othacehe
2022-06-24  8:23                     ` bug#55343: " Mathieu Othacehe
2022-06-11 19:52             ` [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems Maxime Devos

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.