diff options
Diffstat (limited to 'gnu/bootloader')
-rw-r--r-- | gnu/bootloader/grub.scm | 102 | ||||
-rw-r--r-- | gnu/bootloader/u-boot.scm | 47 |
2 files changed, 63 insertions, 86 deletions
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index 2723eda5f4..c2462d5d03 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm @@ -3,13 +3,14 @@ ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com> ;;; Copyright © 2017 Leo Famulari <leo@famulari.name> ;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com> -;;; Copyright © 2019, 2020, 2023 Janneke Nieuwenhuizen <janneke@gnu.org> +;;; Copyright © 2019, 2020, 2023, 2024 Janneke Nieuwenhuizen <janneke@gnu.org> ;;; 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 Karl Hallsby <karl@hallsby.com> ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> ;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz> +;;; Copyright © 2024 Herman Rimm <herman@rimm.ee> ;;; ;;; This file is part of GNU Guix. ;;; @@ -28,12 +29,14 @@ (define-module (gnu bootloader grub) #:use-module (guix build union) + #:use-module (guix deprecation) #:use-module (guix records) #:use-module (guix store) #:use-module (guix utils) #:use-module (guix gexp) #:use-module (gnu artwork) #:use-module (gnu bootloader) + #:use-module (gnu build file-systems) #:use-module (gnu system uuid) #:use-module (gnu system file-systems) #:use-module (gnu system keyboard) @@ -45,6 +48,7 @@ #:use-module (ice-9 regex) #:use-module (srfi srfi-1) #:use-module (srfi srfi-2) + #:use-module (srfi srfi-26) #:export (grub-theme grub-theme? grub-theme-image @@ -54,6 +58,7 @@ grub-theme-gfxmode install-grub-efi-removable + make-grub-efi-installer make-grub-efi-netboot-installer grub-bootloader @@ -355,6 +360,11 @@ code." ((or #f (? string?)) #~(format #f "search --file --set ~a" #$file))))) +(define* (device->hurd-device-name device-spec #:key (disk "w")) + "Return DEVICE as a Hurd name spec: part:PART-NUMBER:device:DISKdDISK-INDEX." + (let ((device-name (canonicalize-device-spec device-spec))) + (device-name->hurd-device-name device-name #:disk disk))) + (define* (make-grub-configuration grub config entries #:key (locale #f) @@ -413,16 +423,16 @@ when booting a root file system on a Btrfs subvolume." ;; IDE driver ("hdX") and those understood by rumpdisk ("wdX" ;; in the "noide" case). (disk (if (member "noide" arguments) "w" "h")) - (modules (menu-entry-multiboot-modules entry)) - (root-index 1)) ; XXX EFI will need root-index 2 + (device-spec (and=> device file-system-device->string)) + (device-name (and=> device-spec device-spec->device-name)) + (modules (menu-entry-multiboot-modules entry))) #~(format port " menuentry ~s { - multiboot ~a root=part:~a:device:~ad0~a~a + multiboot ~a root=~a~a~a }~%" #$label #$kernel - #$root-index - #$disk + #$(device-name->hurd-device-name device-name #:disk disk) (string-join (list #$@arguments) " " 'prefix) (string-join (map string-join '#$modules) "\n module " 'prefix)))) @@ -621,53 +631,16 @@ fi~%")))) "-d" "." image)))) -(define install-grub-efi - #~(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" - "--efi-directory" target-esp))))) - -(define install-grub-efi-removable - #~(lambda (bootloader efi-dir mount-point) - ;; NOTE: mount-point is /mnt in guix system init /etc/config.scm /mnt/point - ;; NOTE: efi-dir comes from target list of booloader configuration - ;; 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 - "--removable" - ;; "--no-nvram" - "--bootloader-id=Guix" - "--efi-directory" target-esp))))) - -(define install-grub-efi32 +(define* (make-grub-efi-installer #:key efi32? removable?) + "Return a G-expression of a procedure for installing GRUB on a UEFI +system. If EFI32? is #t, then a 32-bit target will be used. If +REMOVABLE? is #t, GRUB will be installed for Removable Media Boot." + (define extra-args + (list (and efi32? + #~(cond ((target-x86?) "--target=i386-efi") + ((target-arm?) "--target=arm-efi"))) + ;; This does not update UEFI boot entries, like --no-nvram. + (and removable? "--removable"))) #~(lambda (bootloader efi-dir mount-point) ;; There is nothing useful to do when called in the context of a disk ;; image generation. @@ -684,11 +657,10 @@ fi~%")))) ;; 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))))) + (invoke/quiet grub-install "--bootloader-id=Guix" + "--boot-directory" install-dir + "--efi-directory" target-esp + #$@(filter identity extra-args)))))) (define* (make-grub-efi-netboot-installer grub-efi grub-cfg subdir) "Make a bootloader-installer for a grub-efi-netboot bootloader, which expects @@ -849,7 +821,7 @@ symlink to the store is not needed in this case." (bootloader (name 'grub-efi) (package grub-efi) - (installer install-grub-efi) + (installer (make-grub-efi-installer)) (disk-image-installer #f) (configuration-file grub-cfg) (configuration-file-generator grub-configuration-file))) @@ -858,12 +830,12 @@ symlink to the store is not needed in this case." (bootloader (inherit grub-efi-bootloader) (name 'grub-efi-removable-bootloader) - (installer install-grub-efi-removable))) + (installer (make-grub-efi-installer #:removable? #t)))) (define grub-efi32-bootloader (bootloader (inherit grub-efi-bootloader) - (installer install-grub-efi32) + (installer (make-grub-efi-installer #:efi32? #t)) (name 'grub-efi32) (package grub-efi32))) @@ -909,4 +881,12 @@ symlink to the store is not needed in this case." (bootloader grub-bootloader) fields ...)))) + +;;; +;;; Deprecated bootloader and installer variables. +;;; + +(define-deprecated/alias install-grub-efi-removable + (make-grub-efi-installer #:removable? #t)) + ;;; grub.scm ends here diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm index c5437a7b63..5e149eaea0 100644 --- a/gnu/bootloader/u-boot.scm +++ b/gnu/bootloader/u-boot.scm @@ -5,7 +5,7 @@ ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il> -;;; Copyright © 2023 Herman Rimm <herman_rimm@protonmail.com> +;;; Copyright © 2023-2024 Herman Rimm <herman@rimm.ee> ;;; Copyright © 2024 Zheng Junjie <873216071@qq.com> ;;; ;;; This file is part of GNU Guix. @@ -28,6 +28,7 @@ #:use-module (gnu bootloader) #:use-module (gnu packages bootloaders) #:use-module (guix gexp) + #:use-module (ice-9 match) #:export (u-boot-bootloader u-boot-a20-olinuxino-lime-bootloader u-boot-a20-olinuxino-lime2-bootloader @@ -53,6 +54,18 @@ u-boot-ts7970-q-2g-1000mhz-c-bootloader u-boot-wandboard-bootloader)) +(define (make-u-boot-installer file) + (let ((file + (match file + ((? string?) + (list #~(install-file (string-append bootloader #$file) + install-dir))) + ((? file-like?) (list #~(install-file #$file install-dir))) + (#f '())))) + #~(lambda (bootloader device mount-point) + (let ((install-dir (string-append mount-point "/boot"))) + #$@file)))) + (define install-u-boot #~(lambda (bootloader root-index image) (if bootloader @@ -145,12 +158,6 @@ (define install-pinebook-pro-rk3399-u-boot install-rockpro64-rk3399-u-boot) -(define install-u-boot-ts7970-q-2g-1000mhz-c-u-boot - #~(lambda (bootloader device mount-point) - (let ((u-boot.imx (string-append bootloader "/libexec/u-boot.imx")) - (install-dir (string-append mount-point "/boot"))) - (install-file u-boot.imx install-dir)))) - (define install-sifive-unmatched-u-boot #~(lambda (bootloader root-index image) (let ((spl (string-append bootloader "/libexec/spl/u-boot-spl.bin")) @@ -171,24 +178,14 @@ image (* 2082 512))))) (define install-starfive-visionfive2-uEnv.txt - #~(lambda (bootloader device mount-point) - (mkdir-p (string-append mount-point "/boot")) - (call-with-output-file (string-append mount-point "/boot/uEnv.txt") - (lambda (port) - (format port - ;; if board SPI use vender's u-boot, will find - ;; ""starfive/starfive_visionfive2.dtb"", We cannot guarantee - ;; that users will update this u-boot, so set it. - "fdtfile=starfive/jh7110-starfive-visionfive-2-v1.3b.dtb~%"))))) - -(define install-qemu-riscv64-u-boot - #~(lambda (bootloader device mount-point) - (let ((u-boot.bin (string-append bootloader "/libexec/u-boot.bin")) - (install-dir (string-append mount-point "/boot"))) - (install-file u-boot.bin install-dir)))) + (make-u-boot-installer + ;; If the board SPI uses the vendor's U-Boot, it will find starfive/ + ;; starfive_visionfive2.dtb. We cannot guarantee that users will + ;; update this U-Boot, so set the FDT explicitly. + (plain-file "uEnv.txt" + "fdtfile=starfive/jh7110-starfive-visionfive-2-v1.3b.dtb~%"))) - ;;; ;;; Bootloader definitions. ;;; @@ -329,7 +326,7 @@ (bootloader (inherit u-boot-bootloader) (package u-boot-ts7970-q-2g-1000mhz-c) - (installer install-u-boot-ts7970-q-2g-1000mhz-c-u-boot) + (installer (make-u-boot-installer "libexec/u-boot.imx")) (disk-image-installer #f))) (define u-boot-sifive-unmatched-bootloader @@ -349,5 +346,5 @@ (bootloader (inherit u-boot-bootloader) (package u-boot-qemu-riscv64) - (installer install-qemu-riscv64-u-boot) + (installer (make-u-boot-installer "libexec/u-boot.bin")) (disk-image-installer #f))) |