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 <GNUtoo@cyberdimension.org>
This commit is contained in:
Denis 'GNUtoo' Carikli 2023-08-24 00:26:18 +02:00
parent 5b58977b5e
commit 969bfda3c7
Signed by: GNUtoo
GPG Key ID: 5F5DFCC14177E263
8 changed files with 241 additions and 252 deletions

View File

@ -1,90 +0,0 @@
From 2ca3c327501c482ba34af977cd1a7ccac20a35bf Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
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

View File

@ -1,22 +0,0 @@
From 49cb9863828b90d1dcbd107f4ce4987d0567b837 Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
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

View File

@ -1,25 +0,0 @@
From 319bd622e033aa585ca90692581bb5fe69c45ceb Mon Sep 17 00:00:00 2001
From: Adrien 'neox' Bourmault <neox@gnu.org>
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

View File

@ -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 <http://www.gnu.org/licenses/>.
(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)

View File

@ -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/

View File

@ -1,77 +0,0 @@
#!/usr/bin/env bash
# helper script: Downloads GRUB and patches it.
#
# Copyright (C) 2014, 2015, 2016, 2020, 2021 Leah Rowe <info@minifree.org>
#
# 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 <http://www.gnu.org/licenses/>.
#
[ "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"

View File

@ -0,0 +1 @@
module

View File

@ -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 <info@minifree.org>
# Copyright (C) 2015, 2016 Klemens Nanni <contact@autoboot.org>
# Copyright (C) 2014, 2015, 2016, 2020, 2021 Leah Rowe <info@minifree.org>
# Copyright (C) 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
# 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 <http://www.gnu.org/licenses/>.
#
# 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
printf "Building GRUB\n"
if [ ! -d "grub/" ]; then
./download grub
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
# use a subshell to not end up in grub/ in case of build issues
(
cd grub/
printf "Usage:\n"
printf "\t%s # %s\n" \
"${progname}" \
"Download ${gnuboot_package_name}"
printf "\t%s --help # %s\n" \
"${progname}" \
"Prints this help"
}
# clean up first
[ -d Makefile ] && make distclean
is_download()
{
[ "$(basename $0)" = "download" ]
}
./bootstrap --gnulib-srcdir=gnulib/ --no-git
is_build_module()
{
[ "$(basename $0)" = "module" ]
}
# build
./autogen.sh
./configure --with-platform=coreboot
make -j$(nproc)
)
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
# Remove the old version that may still exist
# ------------------------------------------------------------------------------
printf "+---------------------------------------------------+\n"
printf "| Downloading and/or building the package with Guix |\n"
printf "+---------------------------------------------------+\n"
# 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
install -d grub/bin
install -d grub/src
install_guix_build_package_source grub/src
install_guix_build_package grub/bin

View File

@ -3,6 +3,7 @@
# generate GRUB ELF files (coreboot payload) and configuration files
#
# Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe <info@minifree.org>
# Copyright (C) 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
# 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"