summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-06-17 23:18:35 -0600
committerMathieu Othacehe <othacehe@gnu.org>2022-06-24 10:21:06 +0200
commit62c86c8391ceb8953ca972498fd75ea9298b85ff (patch)
treef4ddcdf3749219c0fd36b92d0c2ba52b73566a07
parent242fad357e969da3b1f80b7e4360b54d99ee03f3 (diff)
image: Add support for 32bit UEFI.
* 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. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
-rw-r--r--gnu/bootloader/grub.scm32
-rw-r--r--gnu/build/bootloader.scm37
-rw-r--r--gnu/build/image.scm14
-rw-r--r--gnu/packages/bootloaders.scm13
-rw-r--r--gnu/system/image.scm19
5 files changed, 102 insertions, 13 deletions
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 65d7171432c..4f18c9b5183 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -8,6 +8,7 @@
8;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> 8;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
9;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de> 9;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
10;;; Copyright © 2022 Karl Hallsby <karl@hallsby.com> 10;;; Copyright © 2022 Karl Hallsby <karl@hallsby.com>
11;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
11;;; 12;;;
12;;; This file is part of GNU Guix. 13;;; This file is part of GNU Guix.
13;;; 14;;;
@@ -57,6 +58,7 @@
57 grub-bootloader 58 grub-bootloader
58 grub-efi-bootloader 59 grub-efi-bootloader
59 grub-efi-removable-bootloader 60 grub-efi-removable-bootloader
61 grub-efi32-bootloader
60 grub-efi-netboot-bootloader 62 grub-efi-netboot-bootloader
61 grub-mkrescue-bootloader 63 grub-mkrescue-bootloader
62 grub-minimal-bootloader 64 grub-minimal-bootloader
@@ -636,6 +638,29 @@ fi~%"))))
636 "--bootloader-id=Guix" 638 "--bootloader-id=Guix"
637 "--efi-directory" target-esp))))) 639 "--efi-directory" target-esp)))))
638 640
641(define install-grub-efi32
642 #~(lambda (bootloader efi-dir mount-point)
643 ;; There is nothing useful to do when called in the context of a disk
644 ;; image generation.
645 (when efi-dir
646 ;; Install GRUB onto the EFI partition mounted at EFI-DIR, for the
647 ;; system whose root is mounted at MOUNT-POINT.
648 (let ((grub-install (string-append bootloader "/sbin/grub-install"))
649 (install-dir (string-append mount-point "/boot"))
650 ;; When installing Guix, it's common to mount EFI-DIR below
651 ;; MOUNT-POINT rather than /boot/efi on the live image.
652 (target-esp (if (file-exists? (string-append mount-point efi-dir))
653 (string-append mount-point efi-dir)
654 efi-dir)))
655 ;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
656 ;; root partition.
657 (setenv "GRUB_ENABLE_CRYPTODISK" "y")
658 (invoke/quiet grub-install "--boot-directory" install-dir
659 "--bootloader-id=Guix"
660 (cond ((target-x86?) "--target=i386-efi")
661 ((target-arm?) "--target=arm-efi"))
662 "--efi-directory" target-esp)))))
663
639(define (install-grub-efi-netboot subdir) 664(define (install-grub-efi-netboot subdir)
640 "Define a grub-efi-netboot bootloader installer for installation in SUBDIR, 665 "Define a grub-efi-netboot bootloader installer for installation in SUBDIR,
641which is usually efi/Guix or efi/boot." 666which is usually efi/Guix or efi/boot."
@@ -768,6 +793,13 @@ considered for security aspects."
768 (name 'grub-efi-removable-bootloader) 793 (name 'grub-efi-removable-bootloader)
769 (installer install-grub-efi-removable))) 794 (installer install-grub-efi-removable)))
770 795
796(define grub-efi32-bootloader
797 (bootloader
798 (inherit grub-efi-bootloader)
799 (installer install-grub-efi32)
800 (name 'grub-efi32)
801 (package grub-efi32)))
802
771(define grub-efi-netboot-bootloader 803(define grub-efi-netboot-bootloader
772 (bootloader 804 (bootloader
773 (inherit grub-efi-bootloader) 805 (inherit grub-efi-bootloader)
diff --git a/gnu/build/bootloader.scm b/gnu/build/bootloader.scm
index 9a89fe55cbe..af6063a884a 100644
--- a/gnu/build/bootloader.scm
+++ b/gnu/build/bootloader.scm
@@ -1,6 +1,8 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com> 2;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
3;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org> 3;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
5;;; Copyright © 2022 Timothy Sample <samplet@ngyro.com>
4;;; 6;;;
5;;; This file is part of GNU Guix. 7;;; This file is part of GNU Guix.
6;;; 8;;;
@@ -54,8 +56,12 @@
54;;; EFI bootloader. 56;;; EFI bootloader.
55;;; 57;;;
56 58
57(define (install-efi grub grub-config esp) 59(define* (install-efi grub grub-config esp #:key targets)
58 "Write a self-contained GRUB EFI loader to the mounted ESP using GRUB-CONFIG." 60 "Write a self-contained GRUB EFI loader to the mounted ESP using
61GRUB-CONFIG.
62
63If TARGETS is set, use its car as the GRUB image format and its cdr as
64the output filename. Otherwise, use defaults for the host platform."
59 (let* ((system %host-type) 65 (let* ((system %host-type)
60 ;; Hard code the output location to a well-known path recognized by 66 ;; Hard code the output location to a well-known path recognized by
61 ;; compliant firmware. See "3.5.1.1 Removable Media Boot Behaviour": 67 ;; compliant firmware. See "3.5.1.1 Removable Media Boot Behaviour":
@@ -63,14 +69,15 @@
63 (grub-mkstandalone (string-append grub "/bin/grub-mkstandalone")) 69 (grub-mkstandalone (string-append grub "/bin/grub-mkstandalone"))
64 (efi-directory (string-append esp "/EFI/BOOT")) 70 (efi-directory (string-append esp "/EFI/BOOT"))
65 ;; Map grub target names to boot file names. 71 ;; Map grub target names to boot file names.
66 (efi-targets (cond ((string-prefix? "x86_64" system) 72 (efi-targets (or targets
67 '("x86_64-efi" . "BOOTX64.EFI")) 73 (cond ((string-prefix? "x86_64" system)
68 ((string-prefix? "i686" system) 74 '("x86_64-efi" . "BOOTX64.EFI"))
69 '("i386-efi" . "BOOTIA32.EFI")) 75 ((string-prefix? "i686" system)
70 ((string-prefix? "armhf" system) 76 '("i386-efi" . "BOOTIA32.EFI"))
71 '("arm-efi" . "BOOTARM.EFI")) 77 ((string-prefix? "armhf" system)
72 ((string-prefix? "aarch64" system) 78 '("arm-efi" . "BOOTARM.EFI"))
73 '("arm64-efi" . "BOOTAA64.EFI"))))) 79 ((string-prefix? "aarch64" system)
80 '("arm64-efi" . "BOOTAA64.EFI"))))))
74 ;; grub-mkstandalone requires a TMPDIR to prepare the firmware image. 81 ;; grub-mkstandalone requires a TMPDIR to prepare the firmware image.
75 (setenv "TMPDIR" esp) 82 (setenv "TMPDIR" esp)
76 83
@@ -81,9 +88,12 @@
81 ;; Graft the configuration file onto the image. 88 ;; Graft the configuration file onto the image.
82 (string-append "boot/grub/grub.cfg=" grub-config)))) 89 (string-append "boot/grub/grub.cfg=" grub-config))))
83 90
84(define (install-efi-loader grub-efi esp) 91(define* (install-efi-loader grub-efi esp #:key targets)
85 "Install in ESP directory the given GRUB-EFI bootloader. Configure it to 92 "Install in ESP directory the given GRUB-EFI bootloader. Configure it to
86load the Grub bootloader located in the 'Guix_image' root partition." 93load the Grub bootloader located in the 'Guix_image' root partition.
94
95If TARGETS is set, use its car as the GRUB image format and its cdr as
96the output filename. Otherwise, use defaults for the host platform."
87 (let ((grub-config "grub.cfg")) 97 (let ((grub-config "grub.cfg"))
88 (call-with-output-file grub-config 98 (call-with-output-file grub-config
89 (lambda (port) 99 (lambda (port)
@@ -97,5 +107,6 @@ load the Grub bootloader located in the 'Guix_image' root partition."
97 insmod part_gpt~@ 107 insmod part_gpt~@
98 search --set=root --label Guix_image~@ 108 search --set=root --label Guix_image~@
99 configfile /boot/grub/grub.cfg~%"))) 109 configfile /boot/grub/grub.cfg~%")))
100 (install-efi grub-efi grub-config esp) 110 (install-efi grub-efi grub-config esp #:targets targets)
101 (delete-file grub-config))) 111 (delete-file grub-config)))
112
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index ddfd34c111a..321be8e4b1a 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -6,6 +6,7 @@
6;;; Copyright © 2020, 2022 Tobias Geerinckx-Rice <me@tobias.gr> 6;;; Copyright © 2020, 2022 Tobias Geerinckx-Rice <me@tobias.gr>
7;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> 7;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
8;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org> 8;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org>
9;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
9;;; 10;;;
10;;; This file is part of GNU Guix. 11;;; This file is part of GNU Guix.
11;;; 12;;;
@@ -27,6 +28,7 @@
27 #:use-module (guix build syscalls) 28 #:use-module (guix build syscalls)
28 #:use-module (guix build utils) 29 #:use-module (guix build utils)
29 #:use-module (guix store database) 30 #:use-module (guix store database)
31 #:use-module (guix utils)
30 #:use-module (gnu build bootloader) 32 #:use-module (gnu build bootloader)
31 #:use-module (gnu build install) 33 #:use-module (gnu build install)
32 #:use-module (gnu build linux-boot) 34 #:use-module (gnu build linux-boot)
@@ -41,6 +43,7 @@
41 convert-disk-image 43 convert-disk-image
42 genimage 44 genimage
43 initialize-efi-partition 45 initialize-efi-partition
46 initialize-efi32-partition
44 initialize-root-partition 47 initialize-root-partition
45 48
46 make-iso9660-image)) 49 make-iso9660-image))
@@ -169,6 +172,17 @@ produced by #:references-graphs. Pass WAL-MODE? to call-with-database."
169 "Install in ROOT directory, an EFI loader using GRUB-EFI." 172 "Install in ROOT directory, an EFI loader using GRUB-EFI."
170 (install-efi-loader grub-efi root)) 173 (install-efi-loader grub-efi root))
171 174
175(define* (initialize-efi32-partition root
176 #:key
177 grub-efi32
178 #:allow-other-keys)
179 "Install in ROOT directory, an EFI 32bit loader using GRUB-EFI32."
180 (install-efi-loader grub-efi32 root
181 #:targets (cond ((target-x86?)
182 '("i386-efi" . "BOOTIA32.EFI"))
183 ((target-arm?)
184 '("arm-efi" . "BOOTARM.EFI")))))
185
172(define* (initialize-root-partition root 186(define* (initialize-root-partition root
173 #:key 187 #:key
174 bootcfg 188 bootcfg
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 91d259475a4..71a10f54d54 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -15,6 +15,7 @@
15;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com> 15;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com>
16;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com> 16;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
17;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re> 17;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
18;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
18;;; 19;;;
19;;; This file is part of GNU Guix. 20;;; This file is part of GNU Guix.
20;;; 21;;;
@@ -332,6 +333,18 @@ menu to select one of the installed operating systems.")
332 "/bin/mcopy\""))) 333 "/bin/mcopy\"")))
333 #t)))))))))) 334 #t))))))))))
334 335
336(define-public grub-efi32
337 (package
338 (inherit grub-efi)
339 (name "grub-efi32")
340 (synopsis "GRand Unified Boot loader (UEFI 32bit version)")
341 (arguments
342 `(,@(substitute-keyword-arguments (package-arguments grub-efi)
343 ((#:configure-flags flags
344 ''()) `(cons* ,(cond ((target-x86?) "--target=i386")
345 ((target-arm?) "--target=arm"))
346 ,flags)))))))
347
335;; Because grub searches hardcoded paths it's easiest to just build grub 348;; Because grub searches hardcoded paths it's easiest to just build grub
336;; again to make it find both grub-pc and grub-efi. There is a command 349;; again to make it find both grub-pc and grub-efi. There is a command
337;; line argument which allows you to specify ONE platform - but 350;; line argument which allows you to specify ONE platform - but
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index f02f6e0b8c2..5972a944d7b 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -2,6 +2,7 @@
2;;; Copyright © 2020, 2021 Mathieu Othacehe <m.othacehe@gmail.com> 2;;; Copyright © 2020, 2021 Mathieu Othacehe <m.othacehe@gmail.com>
3;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> 3;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
4;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org> 4;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org>
5;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
5;;; 6;;;
6;;; This file is part of GNU Guix. 7;;; This file is part of GNU Guix.
7;;; 8;;;
@@ -66,6 +67,7 @@
66 root-label 67 root-label
67 68
68 esp-partition 69 esp-partition
70 esp32-partition
69 root-partition 71 root-partition
70 72
71 efi-disk-image 73 efi-disk-image
@@ -75,6 +77,7 @@
75 77
76 image-with-os 78 image-with-os
77 efi-raw-image-type 79 efi-raw-image-type
80 efi32-raw-image-type
78 qcow2-image-type 81 qcow2-image-type
79 iso-image-type 82 iso-image-type
80 uncompressed-iso-image-type 83 uncompressed-iso-image-type
@@ -110,6 +113,11 @@
110 (flags '(esp)) 113 (flags '(esp))
111 (initializer (gexp initialize-efi-partition)))) 114 (initializer (gexp initialize-efi-partition))))
112 115
116(define esp32-partition
117 (partition
118 (inherit esp-partition)
119 (initializer (gexp initialize-efi32-partition))))
120
113(define root-partition 121(define root-partition
114 (partition 122 (partition
115 (size 'guess) 123 (size 'guess)
@@ -123,6 +131,11 @@
123 (format 'disk-image) 131 (format 'disk-image)
124 (partitions (list esp-partition root-partition)))) 132 (partitions (list esp-partition root-partition))))
125 133
134(define efi32-disk-image
135 (image
136 (format 'disk-image)
137 (partitions (list esp32-partition root-partition))))
138
126(define iso9660-image 139(define iso9660-image
127 (image 140 (image
128 (format 'iso9660) 141 (format 'iso9660)
@@ -164,6 +177,11 @@ set to the given OS."
164 (name 'efi-raw) 177 (name 'efi-raw)
165 (constructor (cut image-with-os efi-disk-image <>)))) 178 (constructor (cut image-with-os efi-disk-image <>))))
166 179
180(define efi32-raw-image-type
181 (image-type
182 (name 'efi32-raw)
183 (constructor (cut image-with-os efi32-disk-image <>))))
184
167(define qcow2-image-type 185(define qcow2-image-type
168 (image-type 186 (image-type
169 (name 'qcow2) 187 (name 'qcow2)
@@ -376,6 +394,7 @@ used in the image."
376 #$(image-shared-store? image)) 394 #$(image-shared-store? image))
377 #:system-directory #$os 395 #:system-directory #$os
378 #:grub-efi #+grub-efi 396 #:grub-efi #+grub-efi
397 #:grub-efi32 #+grub-efi32
379 #:bootloader-package 398 #:bootloader-package
380 #+(bootloader-package bootloader) 399 #+(bootloader-package bootloader)
381 #:bootloader-installer 400 #:bootloader-installer