From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id mNVmA5uieWLsgwEAbAwnHQ (envelope-from ) for ; Tue, 10 May 2022 01:24:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id MARpA5uieWLXHwEA9RJhRA (envelope-from ) for ; Tue, 10 May 2022 01:24:11 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 07EEE16B24 for ; Tue, 10 May 2022 01:24:10 +0200 (CEST) Received: from localhost ([::1]:42608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1noCjZ-0005Bl-41 for larch@yhetil.org; Mon, 09 May 2022 19:24:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noCjU-0005BF-Jz for guix-patches@gnu.org; Mon, 09 May 2022 19:24:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1noCjU-0008Fj-Bh for guix-patches@gnu.org; Mon, 09 May 2022 19:24:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1noCjU-0003bP-6s for guix-patches@gnu.org; Mon, 09 May 2022 19:24:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55343] [PATCH 2/2] image: Add new efi32-raw format for 32bit UEFI on 64bit systems Resent-From: Denis 'GNUtoo' Carikli Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 09 May 2022 23:24:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55343 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 55343@debbugs.gnu.org Cc: Denis 'GNUtoo' Carikli Received: via spool by 55343-submit@debbugs.gnu.org id=B55343.165213862013804 (code B ref 55343); Mon, 09 May 2022 23:24:04 +0000 Received: (at 55343) by debbugs.gnu.org; 9 May 2022 23:23:40 +0000 Received: from localhost ([127.0.0.1]:59721 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1noCiu-0003aK-TB for submit@debbugs.gnu.org; Mon, 09 May 2022 19:23:40 -0400 Received: from cyberdimension.org ([80.67.179.20]:35764 helo=gnutoo.cyberdimension.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1noCis-0003Zw-KF for 55343@debbugs.gnu.org; Mon, 09 May 2022 19:23:27 -0400 Received: from gnutoo.cyberdimension.org (localhost [127.0.0.1]) by cyberdimension.org (OpenSMTPD) with ESMTP id b62f8160; Mon, 9 May 2022 23:22:37 +0000 (UTC) Received: from primarylaptop.localdomain (localhost [::1]) by gnutoo.cyberdimension.org (OpenSMTPD) with ESMTP id 4f30fcfb; Mon, 9 May 2022 23:22:37 +0000 (UTC) From: Denis 'GNUtoo' Carikli Date: Tue, 10 May 2022 01:24:51 +0200 Message-Id: <20220509232451.30605-2-GNUtoo@cyberdimension.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220509232451.30605-1-GNUtoo@cyberdimension.org> References: <20220510011812.15710e0b@primarylaptop.localdomain> <20220509232451.30605-1-GNUtoo@cyberdimension.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1652138650; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=VzgKt/loWOv8xpfkq06Ghoh29MCBmqIFfoCMuH9Ksc0=; b=Dp2NqkEubEkiXHDgMSibZUrNA7Ls4qCwDkFndhJyFozwOBtWiYjUM8R/UF1FiweM+1esir Zo3mEu65zU1cy5e9lB7gEO8PuyTxZt6rO0pNln4yquFbbX/yo/DR3tcw8D9M5nV+261eTw ozlvNEAHiXIEgFBh0nLUkT5Rpf3Z864Ks5V3AtjBYESKgBN9iAUVRri7SDq0pP5ARZKE8a YgGv1E/FKerXtRLz6GLmNKpey81pP8T1NGPXmFkCNLCpJQJHdofjPfZ9wqGHqtU2D2+h5C fEsR8kXNm/WObLE9KW8uq8jdvJ+cagIfXE+8+JjGwubVCcmDr6Z0dbBWy6nSHA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652138650; a=rsa-sha256; cv=none; b=K2ThECH0bEImE7xXAsILsRTzkwTAMg+L6hECVDVsRQUPFkVOJKsscmsCIK5ItD0ShtOBBu WT15TDyXFGhIqVdT0WhYDR91v7dcihpOqQAxUBUCb5GLZTOOJmzBJZWPLvsgJvuq9Vv7ud oF7DoIQFbQMN/Dz7ku3w4MO513Byyphu7KY0xlIE7Wzpw67jJulSHgbHkbxpHDVpYtTayH tOBzHA4AupnfH32qf8/rdq+AOzi8SaoS3Q9OBEdSBAYrkaX5pwBggSKlvJVKRE5tZNOzlB oruLXKfd/Oc51y5P/bv66P7fMamHwQ49DD+ippEh3dq/z5I+h3Is4jkygAVW3A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.60 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 07EEE16B24 X-Spam-Score: -2.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: HzLReSAjAObn * 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 ;;; Copyright © 2020 Maxim Cournoyer ;;; Copyright © 2020 Stefan +;;; Copyright © 2022 Denis 'GNUtoo' Carikli ;;; ;;; 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 ;;; Copyright © 2019 Ludovic Courtès +;;; Copyright © 2022 Denis 'GNUtoo' Carikli ;;; ;;; 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)) ;;; @@ -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 ;;; Copyright © 2020, 2022 Tobias Geerinckx-Rice ;;; Copyright © 2020 Mathieu Othacehe +;;; Copyright © 2022 Denis 'GNUtoo' Carikli ;;; ;;; 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 ;;; Copyright © 2021 Vincent Legoll ;;; Copyright © 2021 Brice Waegeneire +;;; Copyright © 2022 Denis 'GNUtoo' Carikli ;;; ;;; 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 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2022 Denis 'GNUtoo' Carikli ;;; ;;; 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