From 969bfda3c725fb75cc7abe6085aded3ea72b0954 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Thu, 24 Aug 2023 00:26:18 +0200 Subject: [PATCH] Use Guix for GRUB and flashrom. TODO: - check clean script - Add Guix dependency and update Guix - Take care of updating Guix if the revision isn't found. - cache guix paths and use that with guix gc -D in clean Signed-off-by: Denis 'GNUtoo' Carikli --- ...missing-characters-for-borders-arrow.patch | 90 ---------- ...pecifically-use-python3-in-gentpl.py.patch | 22 --- ...ay-the-name-gnuboot-in-the-grub-menu.patch | 25 --- resources/guix/packages/grub-coreboot.scm | 92 ++++++++++ resources/packages/grub/clean | 9 +- resources/packages/grub/download | 78 +-------- resources/packages/grub/module | 160 +++++++++++++++--- resources/packages/grub/payload | 17 +- 8 files changed, 241 insertions(+), 252 deletions(-) delete mode 100644 resources/grub/patches/0001-mitigate-grub-s-missing-characters-for-borders-arrow.patch delete mode 100644 resources/grub/patches/0002-specifically-use-python3-in-gentpl.py.patch delete mode 100644 resources/grub/patches/0003-say-the-name-gnuboot-in-the-grub-menu.patch create mode 100644 resources/guix/packages/grub-coreboot.scm mode change 100755 => 120000 resources/packages/grub/download diff --git a/resources/grub/patches/0001-mitigate-grub-s-missing-characters-for-borders-arrow.patch b/resources/grub/patches/0001-mitigate-grub-s-missing-characters-for-borders-arrow.patch deleted file mode 100644 index 0f97666..0000000 --- a/resources/grub/patches/0001-mitigate-grub-s-missing-characters-for-borders-arrow.patch +++ /dev/null @@ -1,90 +0,0 @@ -From 2ca3c327501c482ba34af977cd1a7ccac20a35bf Mon Sep 17 00:00:00 2001 -From: Leah Rowe -Date: Sun, 31 Oct 2021 03:47:05 +0000 -Subject: [PATCH 1/3] mitigate grub's missing characters for borders/arrow - characters - -This cleans up the display on the main screen in GRUB. - -Just don't draw a border, at all. ---- - grub-core/normal/menu_text.c | 49 ++---------------------------------- - 1 file changed, 2 insertions(+), 47 deletions(-) - -diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c -index 18240e76c..4d6282b43 100644 ---- a/grub-core/normal/menu_text.c -+++ b/grub-core/normal/menu_text.c -@@ -108,47 +108,6 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right, - grub_print_message_indented_real (msg, margin_left, margin_right, term, 0); - } - --static void --draw_border (struct grub_term_output *term, const struct grub_term_screen_geometry *geo) --{ -- int i; -- -- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); -- -- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y - 1 }); -- grub_putcode (GRUB_UNICODE_CORNER_UL, term); -- for (i = 0; i < geo->entry_width + 1; i++) -- grub_putcode (GRUB_UNICODE_HLINE, term); -- grub_putcode (GRUB_UNICODE_CORNER_UR, term); -- -- for (i = 0; i < geo->num_entries; i++) -- { -- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y + i }); -- grub_putcode (GRUB_UNICODE_VLINE, term); -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x + geo->entry_width + 1, -- geo->first_entry_y + i }); -- grub_putcode (GRUB_UNICODE_VLINE, term); -- } -- -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x - 1, -- geo->first_entry_y - 1 + geo->num_entries + 1 }); -- grub_putcode (GRUB_UNICODE_CORNER_LL, term); -- for (i = 0; i < geo->entry_width + 1; i++) -- grub_putcode (GRUB_UNICODE_HLINE, term); -- grub_putcode (GRUB_UNICODE_CORNER_LR, term); -- -- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); -- -- grub_term_gotoxy (term, -- (struct grub_term_coordinate) { geo->first_entry_x - 1, -- (geo->first_entry_y - 1 + geo->num_entries -- + GRUB_TERM_MARGIN + 1) }); --} -- - static int - print_message (int nested, int edit, struct grub_term_output *term, int dry_run) - { -@@ -167,10 +126,8 @@ command-line or ESC to discard edits and return to the GRUB menu."), - { - char *msg_translated; - -- msg_translated = grub_xasprintf (_("Use the %C and %C keys to select which " -- "entry is highlighted."), -- GRUB_UNICODE_UPARROW, -- GRUB_UNICODE_DOWNARROW); -+ msg_translated = grub_xasprintf (_("Use the arrow keys to select which " -+ "entry is highlighted.")); - if (!msg_translated) - return 0; - ret += grub_print_message_indented_real (msg_translated, STANDARD_MARGIN, -@@ -410,8 +367,6 @@ grub_menu_init_page (int nested, int edit, - - grub_term_normal_color = grub_color_menu_normal; - grub_term_highlight_color = grub_color_menu_highlight; -- if (geo->border) -- draw_border (term, geo); - grub_term_normal_color = old_color_normal; - grub_term_highlight_color = old_color_highlight; - geo->timeout_y = geo->first_entry_y + geo->num_entries --- -2.25.1 - diff --git a/resources/grub/patches/0002-specifically-use-python3-in-gentpl.py.patch b/resources/grub/patches/0002-specifically-use-python3-in-gentpl.py.patch deleted file mode 100644 index b170e29..0000000 --- a/resources/grub/patches/0002-specifically-use-python3-in-gentpl.py.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 49cb9863828b90d1dcbd107f4ce4987d0567b837 Mon Sep 17 00:00:00 2001 -From: Leah Rowe -Date: Sun, 13 Mar 2022 18:08:57 +0000 -Subject: [PATCH 3/3] specifically use python3 in gentpl.py - ---- - gentpl.py | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/gentpl.py b/gentpl.py -index c86550d4f..cb89cef37 100644 ---- a/gentpl.py -+++ b/gentpl.py -@@ -1,4 +1,4 @@ --#! /usr/bin/python -+#! /usr/bin/python3 - # GRUB -- GRand Unified Bootloader - # Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc. - # --- -2.25.1 - diff --git a/resources/grub/patches/0003-say-the-name-gnuboot-in-the-grub-menu.patch b/resources/grub/patches/0003-say-the-name-gnuboot-in-the-grub-menu.patch deleted file mode 100644 index 4e6c6c4..0000000 --- a/resources/grub/patches/0003-say-the-name-gnuboot-in-the-grub-menu.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 319bd622e033aa585ca90692581bb5fe69c45ceb Mon Sep 17 00:00:00 2001 -From: Adrien 'neox' Bourmault -Date: Tue, 8 Aug 2023 12:38:25 +0000 -Subject: [PATCH 3/3] say the name gnuboot, in the grub menu - ---- - grub-core/normal/main.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index c4ebe9e22..3b7a4fc58 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -209,7 +209,7 @@ grub_normal_init_page (struct grub_term_output *term, - - grub_term_cls (term); - -- msg_formatted = grub_xasprintf (_("GNU GRUB version %s"), PACKAGE_VERSION); -+ msg_formatted = grub_xasprintf (_("GNUBoot firmware, based on coreboot. https://gnu.org/software/gnuboot/")); - if (!msg_formatted) - return; - --- -2.25.1 - diff --git a/resources/guix/packages/grub-coreboot.scm b/resources/guix/packages/grub-coreboot.scm new file mode 100644 index 0000000..1481c0b --- /dev/null +++ b/resources/guix/packages/grub-coreboot.scm @@ -0,0 +1,92 @@ +;; This file is part of GNU Boot. +;; +;; This file is free software; you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3 of the License, or (at +;; your option) any later version. +;; +;; This file is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Guix. If not, see . + +(define-module (grub-coreboot)) + +(use-modules (gnu packages bootloaders) + (guix build-system copy) + (guix build-system trivial) + (guix gexp) + ((guix licenses) + #:prefix license:) + (guix packages) + (guix utils)) + +(define-public grub-coreboot + (package + (inherit grub) + (name "grub-coreboot") + (synopsis "GRand Unified Boot loader (Coreboot payload version)") + (arguments + `(,@(substitute-keyword-arguments (package-arguments grub) + ((#:phases phases '%standard-phases) + `(modify-phases ,phases + (add-before 'check 'disable-broken-tests + (lambda _ + (setenv "DISABLE_HARD_ERRORS" "1") + (setenv + "XFAIL_TESTS" + (string-join + ;; TODO: All the tests below use grub shell + ;; (tests/util/grub-shell.in), and here grub-shell uses + ;; QEMU and a Coreboot image to run the tests. Since we + ;; don't have a Coreboot package in Guix yet these tests + ;; are disabled. See the Guix bug #64667 for more details + ;; (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64667). + (list + "pata_test" + "ahci_test" + "uhci_test" + "ehci_test" + "example_grub_script_test" + "ohci_test" + "grub_script_eval" + "grub_script_echo1" + "grub_script_test" + "grub_script_leading_whitespace" + "grub_script_echo_keywords" + "grub_script_vars1" + "grub_script_for1" + "grub_script_while1" + "grub_script_if" + "grub_script_comments" + "grub_script_functions" + "grub_script_continue" + "grub_script_break" + "grub_script_shift" + "grub_script_blockarg" + "grub_script_return" + "grub_script_setparams" + "grub_cmd_date" + "grub_cmd_sleep" + "grub_cmd_regexp" + "grub_script_not" + "grub_cmd_echo" + "grub_script_expansion" + "grub_script_gettext" + "grub_script_escape_comma" + "help_test" + "grub_script_strcmp" + "test_sha512sum" + "grub_cmd_tr" + "test_unset" + "file_filter_test") + " ")))))) + ((#:configure-flags flags + ''()) + `(cons* "--with-platform=coreboot" + ,flags))))))) + +(list grub-coreboot) diff --git a/resources/packages/grub/clean b/resources/packages/grub/clean index 4330dfc..d434eea 100755 --- a/resources/packages/grub/clean +++ b/resources/packages/grub/clean @@ -29,11 +29,4 @@ printf "Cleaning the previous build of GRUB\n" [ ! -d "grub/" ] && exit 0 -( - cd grub/ - if [ -f Makefile ]; then - make distclean - fi -) - -printf "\n\n" +rm -rf grub/ diff --git a/resources/packages/grub/download b/resources/packages/grub/download deleted file mode 100755 index 97bae1e..0000000 --- a/resources/packages/grub/download +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash - -# helper script: Downloads GRUB and patches it. -# -# Copyright (C) 2014, 2015, 2016, 2020, 2021 Leah Rowe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -[ "x${DEBUG+set}" = 'xset' ] && set -v -set -u -e - -usage() -{ - progname="./download grub" - printf "Usage:\n" - printf "\t%s # %s\n" \ - "${progname}" \ - "Download GRUB" - printf "\t%s --help # %s\n" \ - "${progname}" \ - "Prints this help" -} - -if [ $# -ne 0 ] ; then - usage - exit 0 -fi - -# Remove the old version that may still exist -# ------------------------------------------------------------------------------ - -printf "Downloading GRUB\n" - -rm -Rf "grub/" - -# Get latest GRUB -# ------------------------------------------------------------------------------ - -# download it using git -git clone git://git.savannah.gnu.org/grub.git || git clone http://git.savannah.gnu.org/r/grub.git - -if [ ! -d "grub" ]; then - printf "grub not downloaded; check network connection?\n\n" - exit 1 -fi - -( -# modifications are required -cd "grub/" -# reset to known revision -git reset --hard 50aace6bdb918150ba47e3c16146dcca271c134a -for grubpatch in ../resources/grub/patches/*; do - git am "${grubpatch}" -done - -git clone git://git.sv.gnu.org/gnulib gnulib -cd gnulib/ - -# NOTE: when updating this, make sure it's the version specified -# in bootstrap.conf on that version of GRUB, as specified above -git reset --hard d271f868a8df9bbec29049d01e056481b7a1a263 -rm -Rf .git* -) - -printf "\n\n" diff --git a/resources/packages/grub/download b/resources/packages/grub/download new file mode 120000 index 0000000..f8526ec --- /dev/null +++ b/resources/packages/grub/download @@ -0,0 +1 @@ +module \ No newline at end of file diff --git a/resources/packages/grub/module b/resources/packages/grub/module index 62ce0e2..3babdc1 100755 --- a/resources/packages/grub/module +++ b/resources/packages/grub/module @@ -1,9 +1,9 @@ #!/usr/bin/env bash -# helper script: builds GRUB2 source code +# helper script: Downloads GRUB and patches it. # -# Copyright (C) 2014, 2015, 2020 Leah Rowe -# Copyright (C) 2015, 2016 Klemens Nanni +# Copyright (C) 2014, 2015, 2016, 2020, 2021 Leah Rowe +# Copyright (C) 2023 Denis 'GNUtoo' Carikli # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,31 +19,151 @@ # along with this program. If not, see . # -# This script assumes that the working directory is the root -# of git or release archive +guix_revision="v1.4.0" +gnuboot_package_name=$(dirname "$0") +guix_package_name="grub-coreboot" [ "x${DEBUG+set}" = 'xset' ] && set -v set -u -e -# Build GRUB2 as coreboot payload +usage() +{ + if is_download ; then + progname="./download ${gnuboot_package_name}" + elif is_build_module ; then + progname="./build module ${gnuboot_package_name}" + else + progname="$0" + fi -printf "Building GRUB\n" + printf "Usage:\n" + printf "\t%s # %s\n" \ + "${progname}" \ + "Download ${gnuboot_package_name}" + printf "\t%s --help # %s\n" \ + "${progname}" \ + "Prints this help" +} -if [ ! -d "grub/" ]; then - ./download grub +is_download() +{ + [ "$(basename $0)" = "download" ] +} + +is_build_module() +{ + [ "$(basename $0)" = "module" ] +} + +guix_command() +{ + guix time-machine --commit="${guix_revision}" -- "$@" +} + +install_guix_build_package_source() +{ + destination="$1" + + printf \ + "Downloading %s complete and corresponding source code with Guix\n" \ + "${gnuboot_package_name}" + + # Here we want to show the download process if there is one, not to + # panick the user if nothing happens. What is going on will be self + # explanatory as the user will see GRUB's download process. + guix_command \ + build \ + -L resources/guix/packages \ + -L resources/guix/patches \ + --sources=transitive \ + "${guix_package_name}" 1>/dev/null + + # We also want to show the /gnu/store path but with a proper + # explanation as otherwise that could confuse users. + printf \ + "Copying the following %s source code and dependencies in %s:\n" \ + "${gnuboot_package_name}" \ + "${destination}" + + guix_command \ + build \ + -L resources/guix/packages \ + -L resources/guix/patches \ + --sources=transitive \ + "${guix_package_name}" | while IFS='' read -r path + do + printf '%s %s\n' '-' "${path}" + done + + guix_command \ + build \ + -L resources/guix/packages \ + -L resources/guix/patches \ + --sources=transitive \ + "${guix_package_name}" | while IFS='' read -r path + do + cp -a "${path}" "${destination}" + done + + printf "Copying package definition and patch(es) in %s:\n" \ + "${destination}" + + printf '%s %s\n' '-' \ + resources/guix/"${guix_package_name}".scm + + cp \ + resources/guix/"${guix_package_name}".scm \ + "${destination}" +} + +install_guix_build_package() +{ + destination="$1" + + # Here too we want to show the build process if there is one, not to + # panick the user if nothing happens. What is going on will be self + # explanatory as the user will see GRUB's build process. + guix_command build \ + -L resources/guix/packages \ + -L resources/guix/patches \ + "${guix_package_name}" 1>/dev/null + + # Here too we also want to show the /gnu/store path but with a proper + # explanation as otherwise that could confuse users. + printf "Using GRUB binaries from %s\n" \ + "$(guix_command build \ + -L resources/guix/packages \ + -L resources/guix/patches \ + "${guix_package_name}")" + + cp -a "$(guix_command build \ + -L resources/guix/packages \ + -L resources/guix/patches \ + "${guix_package_name}")"/* \ + "${destination}" +} + +if [ $# -ne 0 ] ; then + usage + exit 0 fi -# use a subshell to not end up in grub/ in case of build issues -( -cd grub/ +# Remove the old version that may still exist +# ------------------------------------------------------------------------------ -# clean up first -[ -d Makefile ] && make distclean +printf "+---------------------------------------------------+\n" +printf "| Downloading and/or building the package with Guix |\n" +printf "+---------------------------------------------------+\n" -./bootstrap --gnulib-srcdir=gnulib/ --no-git +# Files in the Guix store don't have write permissions set, so if we +# don't add them we can't delete grub/. +if [ -d "grub/" ] ; then + chmod +w -R grub/ + rm -Rf "grub/" +fi -# build -./autogen.sh -./configure --with-platform=coreboot -make -j$(nproc) -) +install -d grub/bin +install -d grub/src + +install_guix_build_package_source grub/src +install_guix_build_package grub/bin diff --git a/resources/packages/grub/payload b/resources/packages/grub/payload index 8fe593c..2cc937b 100755 --- a/resources/packages/grub/payload +++ b/resources/packages/grub/payload @@ -3,6 +3,7 @@ # generate GRUB ELF files (coreboot payload) and configuration files # # Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe +# Copyright (C) 2023 Denis 'GNUtoo' Carikli # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,11 +28,7 @@ source "resources/grub/modules.list" printf "Creating GRUB payloads and configuration files\n" -if [ ! -d "grub/" ]; then - ./download grub -fi - -if [ ! -f "grub/grub-mkstandalone" ]; then +if [ ! -f "grub/bin/bin/grub-mkstandalone" ]; then ./build module grub fi @@ -50,11 +47,11 @@ for keylayoutfile in resources/grub/keymap/*.gkb; do keymap="${keylayoutfile##resources/grub/keymap/}" keymap="${keymap%.gkb}" - grub/grub-mkstandalone \ - --grub-mkimage="grub/grub-mkimage" \ + grub/bin/bin/grub-mkstandalone \ + --grub-mkimage="grub/bin/bin/grub-mkimage" \ -O i386-coreboot \ - -o payload/grub/grub_${keymap}.elf \ - -d grub/grub-core/ \ + -o payload/grub/grub_"${keymap}".elf \ + -d grub/bin/lib/grub/i386-coreboot/ \ --fonts= --themes= --locales= \ --modules="${grub_modules}" \ --install-modules="${grub_install_modules}" \ @@ -78,4 +75,4 @@ for keylayoutfile in resources/grub/keymap/*.gkb; do "${keymap}" done -printf "Done! Check payload/grub/ to see the files.\n\n" +printf "Done! Check payload/grub/bin/ to see the files.\n\n"