mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-23 07:19:24 +02:00
make GRUB multi-tree and re-add xhci patches
Re-add xHCI only on haswell and broadwell machines, where they are needed. Otherwise, keep the same GRUB code. The xHCI patches were removed because they caused issues on Sandybridge-based Dell Latitude laptops. See: https://codeberg.org/libreboot/lbmk/issues/216 The issue was not reported elsewhere, including on the Haswell/Broadwell hardware where they are needed, but the build system could only build one version of GRUB. The older machines do not need xHCI patches, because they either do not have xHCI patches, or work (in GRUB) because they're in EHCI mode when running the payload. So, the problem is that we need the xHCI patches for GRUB on Haswell/Broadwell hardware, but the patches break Sandybridge hardware, and we only had the one build of GRUB. To mitigate this problem, the build system now supports building multiple revisions of GRUB, with different patches, and each given coreboot target can say which GRUB tree to use by setting this in target.cfg: grubtree="xhci" In the above example, the "xhci" tree would be used. Some generic GRUB config has been moved to config/data/grub/ and config/grub/ now looks like config/coreboot/ - also, the grub.cfg file (named "payload" in each tree) is copied to the GRUB source tree as ".config", then added to GRUB's memdisk in the same way, as grub.cfg. Several other design changes had to be made because of this: * grub.cfg in memdisk no longer automatically jumps to one in CBFS, but now shows a menuentry for it if available * Certain commands in script/trees are disabled for GRUB, such as *config make commands. * gnulib is now defined in config/submodule/grub/, instead of config/git/grub - and this mitigates an existing bug where downloading gnulib first would make grub no longer possible to download in lbmk. The coreboot option CONFIG_FINALIZE_USB_ROUTE_XHCI has been re-enabled on: Dell OptiPlex 9020 MT, Dell OptiPlex 9020 SFF, Lenovo ThinkPad T440p and Lenovo ThinkPad W541 - now USB should work again in GRUB. The GRUB payload has been re-enabled on HP EliteBook 820 G2. This change will enable per-board GRUB optimisation in the future. For example, we hardcode what partitions and LVMs GRUB scans because * is slow on ICH7-based machines, due to GRUB's design. On other machines, * is reasonably fast, for automatically enumerating the list of devices for boot. Use of * (and other wildcards) could enable our GRUB payload to automatically boot more distros, with minimal fuss. This can be done at a later date, in subsequent revisions. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# Copyright (C) 2014-2016,2020-2021,2023-2024 Leah Rowe <leah@libreboot.org>
|
||||
# Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
|
||||
|
||||
set prefix=(memdisk)/boot/grub
|
||||
|
||||
insmod at_keyboard
|
||||
insmod usb_keyboard
|
||||
insmod nativedisk
|
||||
insmod xhci
|
||||
insmod ehci
|
||||
insmod ohci
|
||||
insmod uhci
|
||||
insmod usb
|
||||
insmod usbms
|
||||
insmod regexp
|
||||
|
||||
terminal_input --append at_keyboard
|
||||
terminal_input --append usb_keyboard
|
||||
terminal_output --append cbmemc
|
||||
|
||||
# User interface overrides wherever "keystatus" is supported
|
||||
# Keep SHIFT key pressed before powering on to disable graphics
|
||||
if keystatus --shift; then
|
||||
terminal_output --append vga_text
|
||||
else
|
||||
gfxpayload=keep
|
||||
terminal_output --append gfxterm
|
||||
|
||||
if [ -f (cbfsdisk)/background.png ]; then
|
||||
insmod png
|
||||
background_image (cbfsdisk)/background.png
|
||||
elif [ -f (cbfsdisk)/background.jpg ]; then
|
||||
insmod jpeg
|
||||
background_image (cbfsdisk)/background.jpg
|
||||
fi
|
||||
fi
|
||||
|
||||
# Keep CTRL pressed to enable default serial terminal (COM1 or the like)
|
||||
if keystatus --ctrl; then
|
||||
serial
|
||||
terminal_input --append serial
|
||||
terminal_output --append serial
|
||||
fi
|
||||
|
||||
# Keep ALT pressed to enable spkmodem
|
||||
if keystatus --alt; then
|
||||
terminal_output --append spkmodem
|
||||
fi
|
||||
|
||||
|
||||
set default="0"
|
||||
if [ -f (cbfsdisk)/timeout.cfg ]; then
|
||||
source (cbfsdisk)/timeout.cfg
|
||||
else
|
||||
set timeout=5
|
||||
fi
|
||||
set grub_scan_disk="nvme ahci ata"
|
||||
if [ -f (cbfsdisk)/scan.cfg ]; then
|
||||
source (cbfsdisk)/scan.cfg
|
||||
fi
|
||||
|
||||
if [ -f (cbfsdisk)/keymap.gkb ]; then
|
||||
keymap (cbfsdisk)/keymap.gkb
|
||||
fi
|
||||
|
||||
function really_try_user_config {
|
||||
set root="${1}"
|
||||
|
||||
if [ -f /"${2}"/grub.cfg ]; then
|
||||
unset superusers
|
||||
configfile /"${2}"/grub.cfg
|
||||
fi
|
||||
}
|
||||
|
||||
function try_user_config {
|
||||
# The @/... entries are for cases where the BTRFS filesystem is being used
|
||||
for dir in grub boot/grub @/grub @/boot/grub grub2 boot/grub2 @/grub2 @/boot/grub2 boot @/boot; do
|
||||
really_try_user_config "${1}" "${dir}"
|
||||
done
|
||||
for dir in ubuntu debian redhat; do
|
||||
really_try_user_config "${1}" "EFI/${dir}"
|
||||
done
|
||||
}
|
||||
function search_grub {
|
||||
echo -n "Attempting to load grub.cfg from '${1}' devices"
|
||||
for i in 0 1 2 3 4 5 6 7 8; do
|
||||
for part in 1 2 3 4 5 6 7 8 9 10 11 12; do
|
||||
if [ "${1}" != "nvme" ]; then
|
||||
try_user_config "(${1}${i},${part})"
|
||||
else
|
||||
# TODO: do we care about other namesapces
|
||||
try_user_config "(nvme${i}n1,${part})"
|
||||
fi
|
||||
done
|
||||
if [ "${1}" != "nvme" ]; then
|
||||
# raw devices e.g. (ahci0) instead of (ahci0,1)
|
||||
try_user_config "(${1}${i})"
|
||||
else
|
||||
# TODO: do we care about other namesapces
|
||||
try_user_config "(nvme${i}n1)"
|
||||
fi
|
||||
done
|
||||
echo # Insert newline
|
||||
}
|
||||
|
||||
function try_isolinux_config {
|
||||
set root="${1}"
|
||||
for dir in '' /boot /EFI /@ /@/boot; do
|
||||
if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
|
||||
syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
|
||||
elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
|
||||
syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
|
||||
elif [ -f "${dir}"/syslinux/extlinux.conf ]; then
|
||||
syslinux_configfile -s "${dir}"/syslinux/extlinux.conf
|
||||
elif [ -f "${dir}"/extlinux/extlinux.conf ]; then
|
||||
syslinux_configfile -s "${dir}"/extlinux/extlinux.conf
|
||||
fi
|
||||
done
|
||||
}
|
||||
function search_isolinux {
|
||||
echo "\nAttempting to parse iso/sys/extlinux config from '${1}' devices"
|
||||
for i in 0 1 2 3 4 5 6 7 8; do
|
||||
for part in 1 2 3 4 5 6 7 8 9 10 11 12; do
|
||||
if [ "${1}" != "nvme" ]; then
|
||||
try_isolinux_config "(${1}${i},${part})"
|
||||
else
|
||||
# TODO: see above
|
||||
try_isolinux_config "(nvme${i}n1,${part})"
|
||||
fi
|
||||
done
|
||||
if [ "${1}" != "nvme" ]; then
|
||||
# raw devices e.g. (usb0) instead of (usb0,1)
|
||||
try_isolinux_config "(${1}${i})"
|
||||
else
|
||||
# TODO: do we care about other namesapces
|
||||
try_isolinux_config "(nvme${i}n1)"
|
||||
fi
|
||||
done
|
||||
echo # Insert newline
|
||||
}
|
||||
function try_bootcfg {
|
||||
try_user_config "${1}"
|
||||
try_isolinux_config "${1}"
|
||||
}
|
||||
function search_bootcfg {
|
||||
search_grub "${1}"
|
||||
search_isolinux "${1}"
|
||||
}
|
||||
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
|
||||
|
||||
for grub_disk in ${grub_scan_disk}; do
|
||||
search_bootcfg ${grub_disk}
|
||||
done
|
||||
|
||||
# grub device enumeration is very slow, so checks are hardcoded
|
||||
|
||||
# TODO: add more strings, based on what distros set up when
|
||||
# the user select auto-partitioning on those installers
|
||||
lvmvol="lvm/grubcrypt-bootvol lvm/grubcrypt-rootvol"
|
||||
|
||||
raidvol="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
|
||||
|
||||
# in practise, doing multiple redundant checks is perfectly fast and
|
||||
# TODO: optimize grub itself, and use */? here for everything
|
||||
|
||||
for vol in ${lvmvol} ${raidvol} ; do
|
||||
try_bootcfg "${vol}"
|
||||
done
|
||||
|
||||
unset bootdev
|
||||
for grub_disk in ${grub_scan_disk}; do
|
||||
for i in 0 1 2 3 4 5 6 7 8; do
|
||||
for part in 1 2 3 4 5 6 7 8 9 10 11 12; do
|
||||
if [ "${grub_disk}" = "ahci" ]; then
|
||||
bootdev="${bootdev} (ahci${i},${part})"
|
||||
elif [ "${grub_disk}" = "ata" ]; then
|
||||
bootdev="${bootdev} (ata${i},${part})"
|
||||
elif [ "${grub_disk}" = "nvme" ]; then
|
||||
# TODO: do we care about other namesapces
|
||||
bootdev="${bootdev} (nvme${i}n1,${part})"
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
set pager=0
|
||||
echo -n "Attempting to unlock encrypted volumes"
|
||||
for dev in ${bootdev} ${lvmvol} ${raidvol}; do
|
||||
if cryptomount "${dev}" ; then break ; fi
|
||||
done
|
||||
set pager=1
|
||||
echo
|
||||
|
||||
# after cryptomount, lvm volumes might be available
|
||||
for vol in ${lvmvol}; do
|
||||
try_bootcfg "${vol}"
|
||||
done
|
||||
|
||||
search_bootcfg crypto
|
||||
|
||||
for vol in lvm/* ; do
|
||||
try_bootcfg "${vol}"
|
||||
done
|
||||
|
||||
true # Prevent pager requiring to accept each line instead of whole screen
|
||||
}
|
||||
|
||||
menuentry 'Search for GRUB/SYSLINUX/EXTLINUX/ISOLINUX on USB [s]' --hotkey='s' {
|
||||
search_bootcfg usb
|
||||
}
|
||||
menuentry 'Search for GRUB/SYSLINUX/EXTLINUX/ISOLINUX on AHCI [a]' --hotkey='a' {
|
||||
search_bootcfg ahci
|
||||
}
|
||||
menuentry 'Search for GRUB/SYSLINUX/EXTLINUX/ISOLINUX on ATA/IDE [d]' --hotkey='d' {
|
||||
search_bootcfg ata
|
||||
}
|
||||
menuentry 'Search for GRUB/SYSLINUX/EXTLINUX/ISOLINUX on NVMe [e]' --hotkey='e' {
|
||||
search_bootcfg nvme
|
||||
}
|
||||
if [ -f (cbfsdisk)/grub.cfg ]; then
|
||||
menuentry 'Load configuration (grub.cfg) in CBFS [t]' --hotkey='t' {
|
||||
set root='(cbfsdisk)'
|
||||
if [ -f /grub.cfg ]; then
|
||||
configfile /grub.cfg
|
||||
fi
|
||||
}
|
||||
fi
|
||||
if [ -f (cbfsdisk)/grubtest.cfg ]; then
|
||||
menuentry 'Load test configuration (grubtest.cfg) in CBFS [t]' --hotkey='t' {
|
||||
set root='(cbfsdisk)'
|
||||
if [ -f /grubtest.cfg ]; then
|
||||
configfile /grubtest.cfg
|
||||
fi
|
||||
}
|
||||
fi
|
||||
if [ -f (cbfsdisk)/seabios.elf ]; then
|
||||
menuentry 'Load SeaBIOS (payload) [b]' --hotkey='b' {
|
||||
set root='cbfsdisk'
|
||||
chainloader /seabios.elf
|
||||
}
|
||||
fi
|
||||
if [ -f (cbfsdisk)/img/grub2 ]; then
|
||||
menuentry 'Return to SeaBIOS [b]' --hotkey='b' {
|
||||
set root='cbfsdisk'
|
||||
chainloader /fallback/payload
|
||||
}
|
||||
fi
|
||||
menuentry 'Poweroff [p]' --hotkey='p' {
|
||||
halt
|
||||
}
|
||||
menuentry 'Reboot [r]' --hotkey='r' {
|
||||
reboot
|
||||
}
|
||||
if [ -f (cbfsdisk)/img/memtest ]; then
|
||||
menuentry 'Load MemTest86+ [m]' --hotkey='m' {
|
||||
set root='cbfsdisk'
|
||||
chainloader /img/memtest
|
||||
}
|
||||
fi
|
||||
|
||||
submenu 'Other [z]' --hotkey='z' {
|
||||
menuentry 'Enable default serial terminal [s]' --hotkey='s' {
|
||||
serial
|
||||
terminal_input --append serial
|
||||
terminal_output --append serial
|
||||
}
|
||||
|
||||
menuentry 'Disable default serial terminal' {
|
||||
terminal_input --remove serial
|
||||
terminal_output --remove serial
|
||||
}
|
||||
|
||||
menuentry 'Enable gfxterm' {
|
||||
terminal_output --append gfxterm
|
||||
terminal_output --remove vga_text
|
||||
}
|
||||
menuentry 'Disable gfxterm [g]' --hotkey='g' {
|
||||
terminal_output --remove gfxterm
|
||||
terminal_output --append vga_text
|
||||
}
|
||||
|
||||
menuentry 'Enable spkmodem [a]' --hotkey='a' {
|
||||
terminal_output --append spkmodem
|
||||
}
|
||||
|
||||
menuentry 'Disable spkmodem [z]' --hotkey='z' {
|
||||
terminal_output --remove spkmodem
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
From ce13539fe2103abbd991814d995e06cf96e485f7 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 b1321eb26..e76094dfd 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
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
From 70f9e72c3ff6381fe3519612de3b649c0cf26b9a Mon Sep 17 00:00:00 2001
|
||||
From: Leah Rowe <leah@libreboot.org>
|
||||
Date: Sat, 19 Nov 2022 16:30:24 +0000
|
||||
Subject: [PATCH 2/3] say the name libreboot, 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 bd4431000..31308e16a 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 (_("Libreboot 20240504 release, based on coreboot. https://libreboot.org/"));
|
||||
if (!msg_formatted)
|
||||
return;
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
From de6e7cc62522ce1be21bd2f06e7c15cd234b5426 Mon Sep 17 00:00:00 2001
|
||||
From: Ax333l <main@axelen.xyz>
|
||||
Date: Thu, 17 Aug 2023 00:00:00 +0000
|
||||
Subject: [PATCH 1/6] Add CC0 license
|
||||
|
||||
Signed-off-by: Nicholas Johnson <nick@nicholasjohnson.ch>
|
||||
---
|
||||
grub-core/kern/dl.c | 3 ++-
|
||||
util/grub-module-verifierXX.c | 3 ++-
|
||||
2 files changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
|
||||
index 0bf40caa6..4011e2d15 100644
|
||||
--- a/grub-core/kern/dl.c
|
||||
+++ b/grub-core/kern/dl.c
|
||||
@@ -470,7 +470,8 @@ grub_dl_check_license (grub_dl_t mod, Elf_Ehdr *e)
|
||||
|
||||
if (grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3") == 0
|
||||
|| grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3+") == 0
|
||||
- || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0)
|
||||
+ || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0
|
||||
+ || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=CC0") == 0)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c
|
||||
index a42c20bd1..7157a30aa 100644
|
||||
--- a/util/grub-module-verifierXX.c
|
||||
+++ b/util/grub-module-verifierXX.c
|
||||
@@ -236,7 +236,8 @@ check_license (const char * const filename,
|
||||
Elf_Shdr *s = find_section (arch, e, ".module_license", module_size);
|
||||
if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3") == 0
|
||||
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3+") == 0
|
||||
- || strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0))
|
||||
+ || strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0
|
||||
+ || strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=CC0") == 0))
|
||||
return;
|
||||
grub_util_error ("%s: incompatible license", filename);
|
||||
}
|
||||
--
|
||||
2.39.2
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
From 9edaaffac91d593a439e44bac3b6f5558f5a8245 Mon Sep 17 00:00:00 2001
|
||||
From: Ax333l <main@axelen.xyz>
|
||||
Date: Thu, 17 Aug 2023 00:00:00 +0000
|
||||
Subject: [PATCH 2/6] Define GRUB_UINT32_MAX
|
||||
|
||||
Signed-off-by: Nicholas Johnson <nick@nicholasjohnson.ch>
|
||||
---
|
||||
include/grub/types.h | 8 ++++++++
|
||||
1 file changed, 8 insertions(+)
|
||||
|
||||
diff --git a/include/grub/types.h b/include/grub/types.h
|
||||
index 0d96006fe..a13f3a60b 100644
|
||||
--- a/include/grub/types.h
|
||||
+++ b/include/grub/types.h
|
||||
@@ -156,6 +156,7 @@ typedef grub_int32_t grub_ssize_t;
|
||||
#define GRUB_SHRT_MAX 0x7fff
|
||||
#define GRUB_SHRT_MIN (-GRUB_SHRT_MAX - 1)
|
||||
#define GRUB_UINT_MAX 4294967295U
|
||||
+#define GRUB_UINT32_MAX 4294967295U
|
||||
#define GRUB_INT_MAX 0x7fffffff
|
||||
#define GRUB_INT_MIN (-GRUB_INT_MAX - 1)
|
||||
#define GRUB_INT32_MAX 2147483647
|
||||
@@ -177,6 +178,13 @@ typedef grub_int32_t grub_ssize_t;
|
||||
#define GRUB_TYPE_U_MAX(type) ((unsigned long long)((typeof (type))(~0)))
|
||||
#define GRUB_TYPE_U_MIN(type) 0ULL
|
||||
|
||||
+# define GRUB_UINT32_C(x) x ## U
|
||||
+# if GRUB_ULONG_MAX >> 31 >> 31 >> 1 == 1
|
||||
+# define GRUB_UINT64_C(x) x##UL
|
||||
+# elif 1
|
||||
+# define GRUB_UINT64_C(x) x##ULL
|
||||
+# endif
|
||||
+
|
||||
typedef grub_uint64_t grub_properly_aligned_t;
|
||||
|
||||
#define GRUB_PROPERLY_ALIGNED_ARRAY(name, size) grub_properly_aligned_t name[((size) + sizeof (grub_properly_aligned_t) - 1) / sizeof (grub_properly_aligned_t)]
|
||||
--
|
||||
2.39.2
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,58 @@
|
||||
From 0044d32121bf52c4547c6b3c78f12d7305f57e6b Mon Sep 17 00:00:00 2001
|
||||
From: Ax333l <main@axelen.xyz>
|
||||
Date: Thu, 17 Aug 2023 00:00:00 +0000
|
||||
Subject: [PATCH 4/6] Error on missing Argon2id parameters
|
||||
|
||||
Signed-off-by: Nicholas Johnson <nick@nicholasjohnson.ch>
|
||||
---
|
||||
grub-core/disk/luks2.c | 13 ++++++++-----
|
||||
1 file changed, 8 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
|
||||
index d5106402f..bc818ea69 100644
|
||||
--- a/grub-core/disk/luks2.c
|
||||
+++ b/grub-core/disk/luks2.c
|
||||
@@ -38,6 +38,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
enum grub_luks2_kdf_type
|
||||
{
|
||||
LUKS2_KDF_TYPE_ARGON2I,
|
||||
+ LUKS2_KDF_TYPE_ARGON2ID,
|
||||
LUKS2_KDF_TYPE_PBKDF2
|
||||
};
|
||||
typedef enum grub_luks2_kdf_type grub_luks2_kdf_type_t;
|
||||
@@ -90,7 +91,7 @@ struct grub_luks2_keyslot
|
||||
grub_int64_t time;
|
||||
grub_int64_t memory;
|
||||
grub_int64_t cpus;
|
||||
- } argon2i;
|
||||
+ } argon2;
|
||||
struct
|
||||
{
|
||||
const char *hash;
|
||||
@@ -160,10 +161,11 @@ luks2_parse_keyslot (grub_luks2_keyslot_t *out, const grub_json_t *keyslot)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing or invalid KDF");
|
||||
else if (!grub_strcmp (type, "argon2i") || !grub_strcmp (type, "argon2id"))
|
||||
{
|
||||
- out->kdf.type = LUKS2_KDF_TYPE_ARGON2I;
|
||||
- if (grub_json_getint64 (&out->kdf.u.argon2i.time, &kdf, "time") ||
|
||||
- grub_json_getint64 (&out->kdf.u.argon2i.memory, &kdf, "memory") ||
|
||||
- grub_json_getint64 (&out->kdf.u.argon2i.cpus, &kdf, "cpus"))
|
||||
+ out->kdf.type = !grub_strcmp (type, "argon2i")
|
||||
+ ? LUKS2_KDF_TYPE_ARGON2I : LUKS2_KDF_TYPE_ARGON2ID;
|
||||
+ if (grub_json_getint64 (&out->kdf.u.argon2.time, &kdf, "time") ||
|
||||
+ grub_json_getint64 (&out->kdf.u.argon2.memory, &kdf, "memory") ||
|
||||
+ grub_json_getint64 (&out->kdf.u.argon2.cpus, &kdf, "cpus"))
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing Argon2i parameters");
|
||||
}
|
||||
else if (!grub_strcmp (type, "pbkdf2"))
|
||||
@@ -459,6 +461,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
|
||||
switch (k->kdf.type)
|
||||
{
|
||||
case LUKS2_KDF_TYPE_ARGON2I:
|
||||
+ case LUKS2_KDF_TYPE_ARGON2ID:
|
||||
ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported");
|
||||
goto err;
|
||||
case LUKS2_KDF_TYPE_PBKDF2:
|
||||
--
|
||||
2.39.2
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
From 0a21695c55f76f1c958bb633481d55b3168562f7 Mon Sep 17 00:00:00 2001
|
||||
From: Ax333l <main@axelen.xyz>
|
||||
Date: Thu, 17 Aug 2023 00:00:00 +0000
|
||||
Subject: [PATCH 5/6] Compile with Argon2id support
|
||||
|
||||
Signed-off-by: Nicholas Johnson <nick@nicholasjohnson.ch>
|
||||
---
|
||||
Makefile.util.def | 6 +++++-
|
||||
grub-core/Makefile.core.def | 2 +-
|
||||
grub-core/disk/luks2.c | 13 +++++++++++--
|
||||
3 files changed, 17 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/Makefile.util.def b/Makefile.util.def
|
||||
index 1e9a13d3e..a167825c3 100644
|
||||
--- a/Makefile.util.def
|
||||
+++ b/Makefile.util.def
|
||||
@@ -3,7 +3,7 @@ AutoGen definitions Makefile.tpl;
|
||||
library = {
|
||||
name = libgrubkern.a;
|
||||
cflags = '$(CFLAGS_GNULIB)';
|
||||
- cppflags = '$(CPPFLAGS_GNULIB) -I$(srcdir)/grub-core/lib/json';
|
||||
+ cppflags = '$(CPPFLAGS_GNULIB) -I$(srcdir)/grub-core/lib/json -I$(srcdir)/grub-core/lib/argon2';
|
||||
|
||||
common = util/misc.c;
|
||||
common = grub-core/kern/command.c;
|
||||
@@ -36,6 +36,10 @@ library = {
|
||||
common = grub-core/kern/misc.c;
|
||||
common = grub-core/kern/partition.c;
|
||||
common = grub-core/lib/crypto.c;
|
||||
+ common = grub-core/lib/argon2/argon2.c;
|
||||
+ common = grub-core/lib/argon2/core.c;
|
||||
+ common = grub-core/lib/argon2/ref.c;
|
||||
+ common = grub-core/lib/argon2/blake2/blake2b.c;
|
||||
common = grub-core/lib/json/json.c;
|
||||
common = grub-core/disk/luks.c;
|
||||
common = grub-core/disk/luks2.c;
|
||||
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
|
||||
index 4a06789e5..e939dcc99 100644
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -1238,7 +1238,7 @@ module = {
|
||||
common = disk/luks2.c;
|
||||
common = lib/gnulib/base64.c;
|
||||
cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
|
||||
- cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/json';
|
||||
+ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/json -I$(srcdir)/lib/argon2';
|
||||
};
|
||||
|
||||
module = {
|
||||
diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
|
||||
index bc818ea69..5b9eaa599 100644
|
||||
--- a/grub-core/disk/luks2.c
|
||||
+++ b/grub-core/disk/luks2.c
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <grub/partition.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
+#include <argon2.h>
|
||||
#include <base64.h>
|
||||
#include <json.h>
|
||||
|
||||
@@ -462,8 +463,16 @@ luks2_decrypt_key (grub_uint8_t *out_key,
|
||||
{
|
||||
case LUKS2_KDF_TYPE_ARGON2I:
|
||||
case LUKS2_KDF_TYPE_ARGON2ID:
|
||||
- ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported");
|
||||
- goto err;
|
||||
+ ret = argon2_hash (k->kdf.u.argon2.time, k->kdf.u.argon2.memory, k->kdf.u.argon2.cpus,
|
||||
+ passphrase, passphraselen, salt, saltlen, area_key, k->area.key_size,
|
||||
+ k->kdf.type == LUKS2_KDF_TYPE_ARGON2I ? Argon2_i : Argon2_id,
|
||||
+ ARGON2_VERSION_NUMBER);
|
||||
+ if (ret)
|
||||
+ {
|
||||
+ grub_dprintf ("luks2", "Argon2 failed: %s\n", argon2_error_message (ret));
|
||||
+ goto err;
|
||||
+ }
|
||||
+ break;
|
||||
case LUKS2_KDF_TYPE_PBKDF2:
|
||||
hash = grub_crypto_lookup_md_by_name (k->kdf.u.pbkdf2.hash);
|
||||
if (!hash)
|
||||
--
|
||||
2.39.2
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
From 6c9a6625c0dc038d1bdbdc13665f40e269e86496 Mon Sep 17 00:00:00 2001
|
||||
From: Ax333l <main@axelen.xyz>
|
||||
Date: Thu, 17 Aug 2023 00:00:00 +0000
|
||||
Subject: [PATCH 6/6] Make grub-install work with Argon2
|
||||
|
||||
Signed-off-by: Nicholas Johnson <nick@nicholasjohnson.ch>
|
||||
---
|
||||
util/grub-install.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/util/grub-install.c b/util/grub-install.c
|
||||
index 1ad04db36..a8a3330b8 100644
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -448,6 +448,8 @@ probe_mods (grub_disk_t disk)
|
||||
{
|
||||
grub_util_cryptodisk_get_abstraction (disk,
|
||||
push_cryptodisk_module, NULL);
|
||||
+ /* HACK: always push argon2 */
|
||||
+ grub_install_push_module ("argon2");
|
||||
have_abstractions = 1;
|
||||
have_cryptodisk = 1;
|
||||
}
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
From 96c0bbe5d406b616360a7fce7cee67d7692c0d6d Mon Sep 17 00:00:00 2001
|
||||
From: Leah Rowe <leah@libreboot.org>
|
||||
Date: Mon, 30 Oct 2023 22:19:21 +0000
|
||||
Subject: [PATCH 1/1] at_keyboard coreboot: force scancodes2+translate
|
||||
|
||||
Scan code set 2 with translation should be assumed in
|
||||
every case, as the default starting position.
|
||||
|
||||
However, GRUB is trying to detect and use other modes
|
||||
such as set 2 without translation, or set 1 without
|
||||
translation from set 2; it also detects no-mode and
|
||||
assumes mode 1, on really old keyboards.
|
||||
|
||||
The current behaviour has been retained, for everything
|
||||
except GRUB_MACHINE_COREBOOT; for the latter, scan code
|
||||
set 2 with translation is hardcoded, and forced in code.
|
||||
|
||||
This is required to make keyboard initialisation work on
|
||||
the MEC5035 EC used by the Dell Latitude E6400, when
|
||||
running GRUB as a coreboot payload on that laptop. The
|
||||
EC reports scancode set 2 with translation when probed,
|
||||
but actually only outputs scancode set 1.
|
||||
|
||||
Since GRUB is attempting to use it without translation,
|
||||
and since the machine reports set 2 with translation,
|
||||
but only ever outputs set 1 scancodes, this results in
|
||||
wrong keypresses for every key.
|
||||
|
||||
This fix fixed that, by forcing set 2 with translation,
|
||||
treating it as set 1, but only on coreboot. This is the
|
||||
same behaviour used in GNU+Linux systems and SeaBIOS.
|
||||
With this change, GRUB keyboard initialisation now works
|
||||
just fine on those machines.
|
||||
|
||||
This has *also* been tested on other coreboot machines
|
||||
running GRUB; several HP EliteBooks, ThinkPads and
|
||||
Dell Precision T1650. All seems to work just fine.
|
||||
|
||||
Signed-off-by: Leah Rowe <leah@libreboot.org>
|
||||
---
|
||||
grub-core/term/at_keyboard.c | 20 ++++++++++++++++++--
|
||||
1 file changed, 18 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c
|
||||
index f8a129eb7..8207225c2 100644
|
||||
--- a/grub-core/term/at_keyboard.c
|
||||
+++ b/grub-core/term/at_keyboard.c
|
||||
@@ -138,6 +138,7 @@ write_mode (int mode)
|
||||
return (i != GRUB_AT_TRIES);
|
||||
}
|
||||
|
||||
+#if !defined (GRUB_MACHINE_COREBOOT)
|
||||
static int
|
||||
query_mode (void)
|
||||
{
|
||||
@@ -161,10 +162,12 @@ query_mode (void)
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
+#endif
|
||||
|
||||
static void
|
||||
set_scancodes (void)
|
||||
{
|
||||
+#if !defined (GRUB_MACHINE_COREBOOT)
|
||||
/* You must have visited computer museum. Keyboard without scancode set
|
||||
knowledge. Assume XT. */
|
||||
if (!grub_keyboard_orig_set)
|
||||
@@ -173,20 +176,33 @@ set_scancodes (void)
|
||||
ps2_state.current_set = 1;
|
||||
return;
|
||||
}
|
||||
+#endif
|
||||
|
||||
#if !USE_SCANCODE_SET
|
||||
ps2_state.current_set = 1;
|
||||
return;
|
||||
-#else
|
||||
+#endif
|
||||
|
||||
+#if defined (GRUB_MACHINE_COREBOOT)
|
||||
+ /* enable translation */
|
||||
+ grub_keyboard_controller_write (grub_keyboard_controller_orig
|
||||
+ & ~KEYBOARD_AT_DISABLE);
|
||||
+#else
|
||||
+ /* if not coreboot, disable translation and try mode 2 first, before 1 */
|
||||
grub_keyboard_controller_write (grub_keyboard_controller_orig
|
||||
& ~KEYBOARD_AT_TRANSLATE
|
||||
& ~KEYBOARD_AT_DISABLE);
|
||||
+#endif
|
||||
|
||||
keyboard_controller_wait_until_ready ();
|
||||
grub_outb (KEYBOARD_COMMAND_ENABLE, KEYBOARD_REG_DATA);
|
||||
-
|
||||
write_mode (2);
|
||||
+
|
||||
+#if defined (GRUB_MACHINE_COREBOOT)
|
||||
+ /* mode 2 with translation, so make grub treat as set 1 */
|
||||
+ ps2_state.current_set = 1;
|
||||
+#else
|
||||
+ /* if not coreboot, translation isn't set; test 2 and fall back to 1 */
|
||||
ps2_state.current_set = query_mode ();
|
||||
grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set);
|
||||
if (ps2_state.current_set == 2)
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
From 0a6abeb40ac4284fbff6ef5958989d561b6290a7 Mon Sep 17 00:00:00 2001
|
||||
From: Leah Rowe <leah@libreboot.org>
|
||||
Date: Tue, 31 Oct 2023 10:33:28 +0000
|
||||
Subject: [PATCH 1/1] keylayouts: don't print "Unknown key" message
|
||||
|
||||
on keyboards with stuck keys, this results in GRUB just
|
||||
spewing it repeatedly, preventing use of GRUB.
|
||||
|
||||
in such cases, it's still possible to use the keyboard,
|
||||
and we should let the user at least boot.
|
||||
|
||||
it often appears when people plug in faulty usb keyboards,
|
||||
but can appear for laptop keyboards too; one of my e6400
|
||||
has stuck keys.
|
||||
|
||||
with this patch, grub should be a bit more reliable in
|
||||
terms of user experience, when the keyboard is faulty.
|
||||
|
||||
Signed-off-by: Leah Rowe <leah@libreboot.org>
|
||||
---
|
||||
grub-core/commands/keylayouts.c | 1 -
|
||||
1 file changed, 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/commands/keylayouts.c b/grub-core/commands/keylayouts.c
|
||||
index aa3ba34f2..445fa0601 100644
|
||||
--- a/grub-core/commands/keylayouts.c
|
||||
+++ b/grub-core/commands/keylayouts.c
|
||||
@@ -174,7 +174,6 @@ grub_term_map_key (grub_keyboard_key_t code, int status)
|
||||
key = map_key_core (code, status, &alt_gr_consumed);
|
||||
|
||||
if (key == 0 || key == GRUB_TERM_SHIFT) {
|
||||
- grub_printf ("Unknown key 0x%x detected\n", code);
|
||||
return GRUB_TERM_NO_KEY;
|
||||
}
|
||||
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
From 9e7a651a0f15f2e9dec65a77765c3c4fd97b4165 Mon Sep 17 00:00:00 2001
|
||||
From: Leah Rowe <leah@libreboot.org>
|
||||
Date: Sun, 5 Nov 2023 16:14:58 +0000
|
||||
Subject: [PATCH 1/1] don't print missing prefix errors on the screen
|
||||
|
||||
we do actually set the prefix. this patch modifies
|
||||
grub to still set grub_errno and return accordingly,
|
||||
so the behaviour is otherwise identical, but it will
|
||||
no longer print a warning message on the screen.
|
||||
|
||||
Signed-off-by: Leah Rowe <leah@libreboot.org>
|
||||
---
|
||||
grub-core/commands/keylayouts.c | 2 +-
|
||||
grub-core/commands/loadenv.c | 2 +-
|
||||
grub-core/commands/nativedisk.c | 2 +-
|
||||
grub-core/efiemu/main.c | 3 +--
|
||||
grub-core/font/font.c | 2 +-
|
||||
grub-core/kern/dl.c | 2 +-
|
||||
6 files changed, 6 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/grub-core/commands/keylayouts.c b/grub-core/commands/keylayouts.c
|
||||
index 445fa0601..00bcf7025 100644
|
||||
--- a/grub-core/commands/keylayouts.c
|
||||
+++ b/grub-core/commands/keylayouts.c
|
||||
@@ -211,7 +211,7 @@ grub_cmd_keymap (struct grub_command *cmd __attribute__ ((unused)),
|
||||
{
|
||||
const char *prefix = grub_env_get ("prefix");
|
||||
if (!prefix)
|
||||
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("variable `%s' isn't set"), "prefix");
|
||||
+ return (grub_errno = GRUB_ERR_BAD_ARGUMENT);
|
||||
filename = grub_xasprintf ("%s/layouts/%s.gkb", prefix, argv[0]);
|
||||
if (!filename)
|
||||
return grub_errno;
|
||||
diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c
|
||||
index 166445849..699b39bfa 100644
|
||||
--- a/grub-core/commands/loadenv.c
|
||||
+++ b/grub-core/commands/loadenv.c
|
||||
@@ -58,7 +58,7 @@ open_envblk_file (char *filename,
|
||||
prefix = grub_env_get ("prefix");
|
||||
if (! prefix)
|
||||
{
|
||||
- grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");
|
||||
+ grub_errno = GRUB_ERR_FILE_NOT_FOUND;
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c
|
||||
index 580c8d3b0..6806bff9c 100644
|
||||
--- a/grub-core/commands/nativedisk.c
|
||||
+++ b/grub-core/commands/nativedisk.c
|
||||
@@ -186,7 +186,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
prefix = grub_env_get ("prefix");
|
||||
|
||||
if (! prefix)
|
||||
- return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");
|
||||
+ return (grub_errno = GRUB_ERR_FILE_NOT_FOUND);
|
||||
|
||||
if (prefix)
|
||||
path_prefix = (prefix[0] == '(') ? grub_strchr (prefix, ')') : NULL;
|
||||
diff --git a/grub-core/efiemu/main.c b/grub-core/efiemu/main.c
|
||||
index e7037f4ed..e5d4dbff1 100644
|
||||
--- a/grub-core/efiemu/main.c
|
||||
+++ b/grub-core/efiemu/main.c
|
||||
@@ -231,8 +231,7 @@ grub_efiemu_autocore (void)
|
||||
prefix = grub_env_get ("prefix");
|
||||
|
||||
if (! prefix)
|
||||
- return grub_error (GRUB_ERR_FILE_NOT_FOUND,
|
||||
- N_("variable `%s' isn't set"), "prefix");
|
||||
+ return (grub_errno = GRUB_ERR_FILE_NOT_FOUND);
|
||||
|
||||
suffix = grub_efiemu_get_default_core_name ();
|
||||
|
||||
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
|
||||
index 18de52562..2a0fea6c8 100644
|
||||
--- a/grub-core/font/font.c
|
||||
+++ b/grub-core/font/font.c
|
||||
@@ -461,7 +461,7 @@ grub_font_load (const char *filename)
|
||||
|
||||
if (!prefix)
|
||||
{
|
||||
- grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");
|
||||
+ grub_errno = GRUB_ERR_FILE_NOT_FOUND;
|
||||
goto fail;
|
||||
}
|
||||
file = try_open_from_prefix (prefix, filename);
|
||||
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
|
||||
index 4011e2d15..af3bd00d0 100644
|
||||
--- a/grub-core/kern/dl.c
|
||||
+++ b/grub-core/kern/dl.c
|
||||
@@ -758,7 +758,7 @@ grub_dl_load (const char *name)
|
||||
return 0;
|
||||
|
||||
if (! grub_dl_dir) {
|
||||
- grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");
|
||||
+ grub_errno = GRUB_ERR_FILE_NOT_FOUND;
|
||||
return 0;
|
||||
}
|
||||
|
||||
--
|
||||
2.39.2
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
From 6237c5762edccc1e1fa4746b1d4aa5e8d81e4883 Mon Sep 17 00:00:00 2001
|
||||
From: Leah Rowe <leah@libreboot.org>
|
||||
Date: Sun, 5 Nov 2023 16:36:22 +0000
|
||||
Subject: [PATCH 1/1] don't print error if module not found
|
||||
|
||||
still set grub_errno accordingly, and otherwise
|
||||
behave the same. in libreboot, we remove a lot of
|
||||
modules but then rely on loading a grub.cfg
|
||||
provided by a distro; in almost all cases that works,
|
||||
but also in almost all cases, that will try to load
|
||||
a module we don't actually need, but then it prints
|
||||
a message. this can annoy some users, so silence it.
|
||||
|
||||
Signed-off-by: Leah Rowe <leah@libreboot.org>
|
||||
---
|
||||
grub-core/kern/dl.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
|
||||
index af3bd00d0..21d0cedb1 100644
|
||||
--- a/grub-core/kern/dl.c
|
||||
+++ b/grub-core/kern/dl.c
|
||||
@@ -486,7 +486,7 @@ grub_dl_resolve_name (grub_dl_t mod, Elf_Ehdr *e)
|
||||
|
||||
s = grub_dl_find_section (e, ".modname");
|
||||
if (!s)
|
||||
- return grub_error (GRUB_ERR_BAD_MODULE, "no module name found");
|
||||
+ return (grub_errno = GRUB_ERR_BAD_MODULE);
|
||||
|
||||
mod->name = grub_strdup ((char *) e + s->sh_offset);
|
||||
if (! mod->name)
|
||||
--
|
||||
2.39.2
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
From e5b7ec81421487e71bcaf8b6b5a27f3649a62753 Mon Sep 17 00:00:00 2001
|
||||
From: Leah Rowe <leah@libreboot.org>
|
||||
Date: Sun, 5 Nov 2023 17:25:20 +0000
|
||||
Subject: [PATCH 1/1] don't print empty error messages
|
||||
|
||||
this is part two of the quest to kill the prefix
|
||||
error message. after i disabled prefix-related
|
||||
messages, it still printed "error: ." on screen.
|
||||
|
||||
Signed-off-by: Leah Rowe <leah@libreboot.org>
|
||||
---
|
||||
grub-core/kern/err.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c
|
||||
index 53c734de7..7cac53983 100644
|
||||
--- a/grub-core/kern/err.c
|
||||
+++ b/grub-core/kern/err.c
|
||||
@@ -107,7 +107,8 @@ grub_print_error (void)
|
||||
{
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
{
|
||||
- grub_err_printf (_("error: %s.\n"), grub_errmsg);
|
||||
+ if (grub_strlen(grub_errmsg) > 0)
|
||||
+ grub_err_printf (_("error: %s.\n"), grub_errmsg);
|
||||
grub_err_printed_errors++;
|
||||
}
|
||||
}
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
From 90c9011f2e0350a97e3df44b0fc6dd022e04c276 Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
Date: Sun, 15 Nov 2020 19:00:27 +0100
|
||||
Subject: [PATCH 1/8] grub-core/bus/usb: Parse SuperSpeed companion descriptors
|
||||
|
||||
Parse the SS_ENDPOINT_COMPANION descriptor, which is only present on USB 3.0
|
||||
capable devices and xHCI controllers. Make the descendp an array of pointers
|
||||
to the endpoint descriptor as it's no longer an continous array.
|
||||
|
||||
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
---
|
||||
grub-core/bus/usb/serial/common.c | 2 +-
|
||||
grub-core/bus/usb/usb.c | 44 +++++++++++++++++++------------
|
||||
grub-core/bus/usb/usbhub.c | 22 ++++++++++++----
|
||||
grub-core/commands/usbtest.c | 2 +-
|
||||
grub-core/disk/usbms.c | 2 +-
|
||||
grub-core/term/usb_keyboard.c | 2 +-
|
||||
include/grub/usb.h | 2 +-
|
||||
include/grub/usbdesc.h | 11 +++++++-
|
||||
8 files changed, 59 insertions(+), 28 deletions(-)
|
||||
|
||||
diff --git a/grub-core/bus/usb/serial/common.c b/grub-core/bus/usb/serial/common.c
|
||||
index e9c995a0a..fc847d66d 100644
|
||||
--- a/grub-core/bus/usb/serial/common.c
|
||||
+++ b/grub-core/bus/usb/serial/common.c
|
||||
@@ -72,7 +72,7 @@ grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno,
|
||||
for (j = 0; j < interf->endpointcnt; j++)
|
||||
{
|
||||
struct grub_usb_desc_endp *endp;
|
||||
- endp = &usbdev->config[0].interf[interfno].descendp[j];
|
||||
+ endp = usbdev->config[0].interf[interfno].descendp[j];
|
||||
|
||||
if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2
|
||||
&& (in_endp == GRUB_USB_SERIAL_ENDPOINT_LAST_MATCHING
|
||||
diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c
|
||||
index 7bd49d201..e578af793 100644
|
||||
--- a/grub-core/bus/usb/usb.c
|
||||
+++ b/grub-core/bus/usb/usb.c
|
||||
@@ -118,7 +118,7 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
||||
struct grub_usb_desc_device *descdev;
|
||||
struct grub_usb_desc_config config;
|
||||
grub_usb_err_t err;
|
||||
- int i;
|
||||
+ int i, j;
|
||||
|
||||
/* First we have to read first 8 bytes only and determine
|
||||
* max. size of packet */
|
||||
@@ -152,6 +152,7 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
||||
int currif;
|
||||
char *data;
|
||||
struct grub_usb_desc *desc;
|
||||
+ struct grub_usb_desc_endp *endp;
|
||||
|
||||
/* First just read the first 4 bytes of the configuration
|
||||
descriptor, after that it is known how many bytes really have
|
||||
@@ -201,24 +202,27 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
||||
= (struct grub_usb_desc_if *) &data[pos];
|
||||
pos += dev->config[i].interf[currif].descif->length;
|
||||
|
||||
+ dev->config[i].interf[currif].descendp = grub_malloc (
|
||||
+ dev->config[i].interf[currif].descif->endpointcnt *
|
||||
+ sizeof(struct grub_usb_desc_endp));
|
||||
+
|
||||
+ j = 0;
|
||||
while (pos < config.totallen)
|
||||
{
|
||||
desc = (struct grub_usb_desc *)&data[pos];
|
||||
- if (desc->type == GRUB_USB_DESCRIPTOR_ENDPOINT)
|
||||
- break;
|
||||
- if (!desc->length)
|
||||
- {
|
||||
- err = GRUB_USB_ERR_BADDEVICE;
|
||||
- goto fail;
|
||||
- }
|
||||
- pos += desc->length;
|
||||
- }
|
||||
-
|
||||
- /* Point to the first endpoint. */
|
||||
- dev->config[i].interf[currif].descendp
|
||||
- = (struct grub_usb_desc_endp *) &data[pos];
|
||||
- pos += (sizeof (struct grub_usb_desc_endp)
|
||||
- * dev->config[i].interf[currif].descif->endpointcnt);
|
||||
+ if (desc->type == GRUB_USB_DESCRIPTOR_ENDPOINT) {
|
||||
+ endp = (struct grub_usb_desc_endp *) &data[pos];
|
||||
+ dev->config[i].interf[currif].descendp[j++] = endp;
|
||||
+ pos += desc->length;
|
||||
+ } else {
|
||||
+ if (!desc->length)
|
||||
+ {
|
||||
+ err = GRUB_USB_ERR_BADDEVICE;
|
||||
+ goto fail;
|
||||
+ }
|
||||
+ pos += desc->length;
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,8 +230,14 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
||||
|
||||
fail:
|
||||
|
||||
- for (i = 0; i < GRUB_USB_MAX_CONF; i++)
|
||||
+ for (i = 0; i < GRUB_USB_MAX_CONF; i++) {
|
||||
+ int currif;
|
||||
+
|
||||
+ for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
|
||||
+ grub_free (dev->config[i].interf[currif].descendp);
|
||||
+
|
||||
grub_free (dev->config[i].descconf);
|
||||
+ }
|
||||
|
||||
return err;
|
||||
}
|
||||
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
|
||||
index f5608e330..2ae29cba1 100644
|
||||
--- a/grub-core/bus/usb/usbhub.c
|
||||
+++ b/grub-core/bus/usb/usbhub.c
|
||||
@@ -82,8 +82,14 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
|
||||
if (i == GRUB_USBHUB_MAX_DEVICES)
|
||||
{
|
||||
grub_error (GRUB_ERR_IO, "can't assign address to USB device");
|
||||
- for (i = 0; i < GRUB_USB_MAX_CONF; i++)
|
||||
- grub_free (dev->config[i].descconf);
|
||||
+ for (i = 0; i < GRUB_USB_MAX_CONF; i++) {
|
||||
+ int currif;
|
||||
+
|
||||
+ for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
|
||||
+ grub_free (dev->config[i].interf[currif].descendp);
|
||||
+
|
||||
+ grub_free (dev->config[i].descconf);
|
||||
+ }
|
||||
grub_free (dev);
|
||||
return NULL;
|
||||
}
|
||||
@@ -96,8 +102,14 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
|
||||
i, 0, 0, NULL);
|
||||
if (err)
|
||||
{
|
||||
- for (i = 0; i < GRUB_USB_MAX_CONF; i++)
|
||||
- grub_free (dev->config[i].descconf);
|
||||
+ for (i = 0; i < GRUB_USB_MAX_CONF; i++) {
|
||||
+ int currif;
|
||||
+
|
||||
+ for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
|
||||
+ grub_free (dev->config[i].interf[currif].descendp);
|
||||
+
|
||||
+ grub_free (dev->config[i].descconf);
|
||||
+ }
|
||||
grub_free (dev);
|
||||
return NULL;
|
||||
}
|
||||
@@ -176,7 +188,7 @@ grub_usb_add_hub (grub_usb_device_t dev)
|
||||
i++)
|
||||
{
|
||||
struct grub_usb_desc_endp *endp = NULL;
|
||||
- endp = &dev->config[0].interf[0].descendp[i];
|
||||
+ endp = dev->config[0].interf[0].descendp[i];
|
||||
|
||||
if ((endp->endp_addr & 128) && grub_usb_get_ep_type(endp)
|
||||
== GRUB_USB_EP_INTERRUPT)
|
||||
diff --git a/grub-core/commands/usbtest.c b/grub-core/commands/usbtest.c
|
||||
index 2c6d93fe6..55a657635 100644
|
||||
--- a/grub-core/commands/usbtest.c
|
||||
+++ b/grub-core/commands/usbtest.c
|
||||
@@ -185,7 +185,7 @@ usb_iterate (grub_usb_device_t dev, void *data __attribute__ ((unused)))
|
||||
for (j = 0; j < interf->endpointcnt; j++)
|
||||
{
|
||||
struct grub_usb_desc_endp *endp;
|
||||
- endp = &dev->config[0].interf[i].descendp[j];
|
||||
+ endp = dev->config[0].interf[i].descendp[j];
|
||||
|
||||
grub_printf ("Endpoint #%d: %s, max packed size: %d, transfer type: %s, latency: %d\n",
|
||||
endp->endp_addr & 15,
|
||||
diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c
|
||||
index b81e3ad9d..b1512dc12 100644
|
||||
--- a/grub-core/disk/usbms.c
|
||||
+++ b/grub-core/disk/usbms.c
|
||||
@@ -184,7 +184,7 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno)
|
||||
for (j = 0; j < interf->endpointcnt; j++)
|
||||
{
|
||||
struct grub_usb_desc_endp *endp;
|
||||
- endp = &usbdev->config[0].interf[interfno].descendp[j];
|
||||
+ endp = usbdev->config[0].interf[interfno].descendp[j];
|
||||
|
||||
if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2)
|
||||
/* Bulk IN endpoint. */
|
||||
diff --git a/grub-core/term/usb_keyboard.c b/grub-core/term/usb_keyboard.c
|
||||
index 7322d8dff..d590979f5 100644
|
||||
--- a/grub-core/term/usb_keyboard.c
|
||||
+++ b/grub-core/term/usb_keyboard.c
|
||||
@@ -175,7 +175,7 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
|
||||
for (j = 0; j < usbdev->config[configno].interf[interfno].descif->endpointcnt;
|
||||
j++)
|
||||
{
|
||||
- endp = &usbdev->config[configno].interf[interfno].descendp[j];
|
||||
+ endp = usbdev->config[configno].interf[interfno].descendp[j];
|
||||
|
||||
if ((endp->endp_addr & 128) && grub_usb_get_ep_type(endp)
|
||||
== GRUB_USB_EP_INTERRUPT)
|
||||
diff --git a/include/grub/usb.h b/include/grub/usb.h
|
||||
index 0f346af12..688c11f6d 100644
|
||||
--- a/include/grub/usb.h
|
||||
+++ b/include/grub/usb.h
|
||||
@@ -153,7 +153,7 @@ struct grub_usb_interface
|
||||
{
|
||||
struct grub_usb_desc_if *descif;
|
||||
|
||||
- struct grub_usb_desc_endp *descendp;
|
||||
+ struct grub_usb_desc_endp **descendp;
|
||||
|
||||
/* A driver is handling this interface. Do we need to support multiple drivers
|
||||
for single interface?
|
||||
diff --git a/include/grub/usbdesc.h b/include/grub/usbdesc.h
|
||||
index aac5ab05a..bb2ab2e27 100644
|
||||
--- a/include/grub/usbdesc.h
|
||||
+++ b/include/grub/usbdesc.h
|
||||
@@ -29,7 +29,8 @@ typedef enum {
|
||||
GRUB_USB_DESCRIPTOR_INTERFACE,
|
||||
GRUB_USB_DESCRIPTOR_ENDPOINT,
|
||||
GRUB_USB_DESCRIPTOR_DEBUG = 10,
|
||||
- GRUB_USB_DESCRIPTOR_HUB = 0x29
|
||||
+ GRUB_USB_DESCRIPTOR_HUB = 0x29,
|
||||
+ GRUB_USB_DESCRIPTOR_SS_ENDPOINT_COMPANION = 0x30
|
||||
} grub_usb_descriptor_t;
|
||||
|
||||
struct grub_usb_desc
|
||||
@@ -105,6 +106,14 @@ struct grub_usb_desc_endp
|
||||
grub_uint8_t interval;
|
||||
} GRUB_PACKED;
|
||||
|
||||
+struct grub_usb_desc_ssep {
|
||||
+ grub_uint8_t length;
|
||||
+ grub_uint8_t type;
|
||||
+ grub_uint8_t maxburst;
|
||||
+ grub_uint8_t attrib;
|
||||
+ grub_uint16_t interval;
|
||||
+} GRUB_PACKED;
|
||||
+
|
||||
struct grub_usb_desc_str
|
||||
{
|
||||
grub_uint8_t length;
|
||||
--
|
||||
2.39.2
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
From e111983ca5e2a52bfe2bdc5cd639b06bb2f7902d Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
Date: Sun, 15 Nov 2020 19:47:06 +0100
|
||||
Subject: [PATCH 2/8] usb: Add enum for xHCI
|
||||
|
||||
Will be used in future patches.
|
||||
|
||||
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
---
|
||||
include/grub/usb.h | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/grub/usb.h b/include/grub/usb.h
|
||||
index 688c11f6d..ea6ee8c2c 100644
|
||||
--- a/include/grub/usb.h
|
||||
+++ b/include/grub/usb.h
|
||||
@@ -51,7 +51,8 @@ typedef enum
|
||||
GRUB_USB_SPEED_NONE,
|
||||
GRUB_USB_SPEED_LOW,
|
||||
GRUB_USB_SPEED_FULL,
|
||||
- GRUB_USB_SPEED_HIGH
|
||||
+ GRUB_USB_SPEED_HIGH,
|
||||
+ GRUB_USB_SPEED_SUPER
|
||||
} grub_usb_speed_t;
|
||||
|
||||
typedef int (*grub_usb_iterate_hook_t) (grub_usb_device_t dev, void *data);
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
From 3e25c83a1d1c6e149c7e9f0660ddadb2beca2476 Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
Date: Sun, 15 Nov 2020 19:48:03 +0100
|
||||
Subject: [PATCH 3/8] usbtrans: Set default maximum packet size
|
||||
|
||||
Set the maximum packet size to 512 for SuperSpeed devices.
|
||||
|
||||
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
---
|
||||
grub-core/bus/usb/usbtrans.c | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/bus/usb/usbtrans.c b/grub-core/bus/usb/usbtrans.c
|
||||
index c5680b33a..c1080bb33 100644
|
||||
--- a/grub-core/bus/usb/usbtrans.c
|
||||
+++ b/grub-core/bus/usb/usbtrans.c
|
||||
@@ -128,8 +128,12 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
||||
setupdata_addr = grub_dma_get_phys (setupdata_chunk);
|
||||
|
||||
/* Determine the maximum packet size. */
|
||||
- if (dev->descdev.maxsize0)
|
||||
+ if (dev->descdev.maxsize0 && dev->speed != GRUB_USB_SPEED_SUPER)
|
||||
max = dev->descdev.maxsize0;
|
||||
+ else if (dev->descdev.maxsize0 && dev->speed == GRUB_USB_SPEED_SUPER)
|
||||
+ max = 1UL << dev->descdev.maxsize0;
|
||||
+ else if (dev->speed == GRUB_USB_SPEED_SUPER)
|
||||
+ max = 512;
|
||||
else
|
||||
max = 64;
|
||||
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
From 89701aba00caa81bb566ab10da0c89264393be30 Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
Date: Sun, 15 Nov 2020 19:51:42 +0100
|
||||
Subject: [PATCH 4/8] grub-core/bus/usb: Add function pointer for attach/detach
|
||||
events
|
||||
|
||||
The xHCI code needs to be called for attaching or detaching a device.
|
||||
Introduce two functions pointers and call it from the USB hub code.
|
||||
|
||||
Will be used in future commits, currently this doesn't change any functionality.
|
||||
|
||||
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
---
|
||||
grub-core/bus/usb/ehci.c | 2 ++
|
||||
grub-core/bus/usb/ohci.c | 2 ++
|
||||
grub-core/bus/usb/uhci.c | 2 ++
|
||||
grub-core/bus/usb/usbhub.c | 19 +++++++++++++++++++
|
||||
include/grub/usb.h | 4 ++++
|
||||
5 files changed, 29 insertions(+)
|
||||
|
||||
diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c
|
||||
index 9abebc6bd..953b851c0 100644
|
||||
--- a/grub-core/bus/usb/ehci.c
|
||||
+++ b/grub-core/bus/usb/ehci.c
|
||||
@@ -1812,6 +1812,8 @@ static struct grub_usb_controller_dev usb_controller = {
|
||||
.hubports = grub_ehci_hubports,
|
||||
.portstatus = grub_ehci_portstatus,
|
||||
.detect_dev = grub_ehci_detect_dev,
|
||||
+ .attach_dev = NULL,
|
||||
+ .detach_dev = NULL,
|
||||
/* estimated max. count of TDs for one bulk transfer */
|
||||
.max_bulk_tds = GRUB_EHCI_N_TD * 3 / 4
|
||||
};
|
||||
diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c
|
||||
index 5363a61f6..7a3f3e154 100644
|
||||
--- a/grub-core/bus/usb/ohci.c
|
||||
+++ b/grub-core/bus/usb/ohci.c
|
||||
@@ -1440,6 +1440,8 @@ static struct grub_usb_controller_dev usb_controller =
|
||||
.hubports = grub_ohci_hubports,
|
||||
.portstatus = grub_ohci_portstatus,
|
||||
.detect_dev = grub_ohci_detect_dev,
|
||||
+ .attach_dev = NULL,
|
||||
+ .detach_dev = NULL,
|
||||
/* estimated max. count of TDs for one bulk transfer */
|
||||
.max_bulk_tds = GRUB_OHCI_TDS * 3 / 4
|
||||
};
|
||||
diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c
|
||||
index 0fdea4c1e..03c4605b2 100644
|
||||
--- a/grub-core/bus/usb/uhci.c
|
||||
+++ b/grub-core/bus/usb/uhci.c
|
||||
@@ -845,6 +845,8 @@ static struct grub_usb_controller_dev usb_controller =
|
||||
.hubports = grub_uhci_hubports,
|
||||
.portstatus = grub_uhci_portstatus,
|
||||
.detect_dev = grub_uhci_detect_dev,
|
||||
+ .attach_dev = NULL,
|
||||
+ .detach_dev = NULL,
|
||||
/* estimated max. count of TDs for one bulk transfer */
|
||||
.max_bulk_tds = N_TD * 3 / 4
|
||||
};
|
||||
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
|
||||
index 2ae29cba1..8e963e84b 100644
|
||||
--- a/grub-core/bus/usb/usbhub.c
|
||||
+++ b/grub-core/bus/usb/usbhub.c
|
||||
@@ -66,6 +66,15 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
|
||||
dev->split_hubport = split_hubport;
|
||||
dev->split_hubaddr = split_hubaddr;
|
||||
|
||||
+ if (controller->dev->attach_dev) {
|
||||
+ err = controller->dev->attach_dev (controller, dev);
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_free (dev);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
err = grub_usb_device_initialize (dev);
|
||||
if (err)
|
||||
{
|
||||
@@ -405,6 +414,8 @@ static void
|
||||
detach_device (grub_usb_device_t dev)
|
||||
{
|
||||
unsigned i;
|
||||
+ grub_usb_err_t err;
|
||||
+
|
||||
int k;
|
||||
if (!dev)
|
||||
return;
|
||||
@@ -425,6 +436,14 @@ detach_device (grub_usb_device_t dev)
|
||||
if (inter && inter->detach_hook)
|
||||
inter->detach_hook (dev, i, k);
|
||||
}
|
||||
+ if (dev->controller.dev->detach_dev) {
|
||||
+ err = dev->controller.dev->detach_dev (&dev->controller, dev);
|
||||
+ if (err)
|
||||
+ {
|
||||
+ // XXX
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
grub_usb_devs[dev->addr] = 0;
|
||||
}
|
||||
|
||||
diff --git a/include/grub/usb.h b/include/grub/usb.h
|
||||
index ea6ee8c2c..4dd179db2 100644
|
||||
--- a/include/grub/usb.h
|
||||
+++ b/include/grub/usb.h
|
||||
@@ -126,6 +126,10 @@ struct grub_usb_controller_dev
|
||||
|
||||
grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port, int *changed);
|
||||
|
||||
+ grub_usb_err_t (*attach_dev) (grub_usb_controller_t ctrl, grub_usb_device_t dev);
|
||||
+
|
||||
+ grub_usb_err_t (*detach_dev) (grub_usb_controller_t ctrl, grub_usb_device_t dev);
|
||||
+
|
||||
/* Per controller flag - port reset pending, don't do another reset */
|
||||
grub_uint64_t pending_reset;
|
||||
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
From 5e5d74a4531770258e21dedd45c33f1a9d3afa6b Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
Date: Sun, 15 Nov 2020 19:54:40 +0100
|
||||
Subject: [PATCH 5/8] grub-core/bus/usb/usbhub: Add new private fields for xHCI
|
||||
controller
|
||||
|
||||
Store the root port number, the route, consisting out of the port ID
|
||||
in each nibble, and a pointer to driver private data.
|
||||
|
||||
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
---
|
||||
grub-core/bus/usb/usbhub.c | 11 ++++++++---
|
||||
include/grub/usb.h | 5 +++++
|
||||
2 files changed, 13 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
|
||||
index 8e963e84b..b4b3a1a61 100644
|
||||
--- a/grub-core/bus/usb/usbhub.c
|
||||
+++ b/grub-core/bus/usb/usbhub.c
|
||||
@@ -49,7 +49,9 @@ static grub_usb_controller_dev_t grub_usb_list;
|
||||
static grub_usb_device_t
|
||||
grub_usb_hub_add_dev (grub_usb_controller_t controller,
|
||||
grub_usb_speed_t speed,
|
||||
- int split_hubport, int split_hubaddr)
|
||||
+ int split_hubport, int split_hubaddr,
|
||||
+ int root_portno,
|
||||
+ grub_uint32_t route)
|
||||
{
|
||||
grub_usb_device_t dev;
|
||||
int i;
|
||||
@@ -65,6 +67,8 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
|
||||
dev->speed = speed;
|
||||
dev->split_hubport = split_hubport;
|
||||
dev->split_hubaddr = split_hubaddr;
|
||||
+ dev->root_port = root_portno;
|
||||
+ dev->route = route;
|
||||
|
||||
if (controller->dev->attach_dev) {
|
||||
err = controller->dev->attach_dev (controller, dev);
|
||||
@@ -245,7 +249,7 @@ attach_root_port (struct grub_usb_hub *hub, int portno,
|
||||
and full/low speed device connected to OHCI/UHCI needs not
|
||||
transaction translation - e.g. hubport and hubaddr should be
|
||||
always none (zero) for any device connected to any root hub. */
|
||||
- dev = grub_usb_hub_add_dev (hub->controller, speed, 0, 0);
|
||||
+ dev = grub_usb_hub_add_dev (hub->controller, speed, 0, 0, portno, 0);
|
||||
hub->controller->dev->pending_reset = 0;
|
||||
npending--;
|
||||
if (! dev)
|
||||
@@ -676,7 +680,8 @@ poll_nonroot_hub (grub_usb_device_t dev)
|
||||
|
||||
/* Add the device and assign a device address to it. */
|
||||
next_dev = grub_usb_hub_add_dev (&dev->controller, speed,
|
||||
- split_hubport, split_hubaddr);
|
||||
+ split_hubport, split_hubaddr, dev->root_port,
|
||||
+ dev->route << 4 | (i & 0xf));
|
||||
if (dev->controller.dev->pending_reset)
|
||||
{
|
||||
dev->controller.dev->pending_reset = 0;
|
||||
diff --git a/include/grub/usb.h b/include/grub/usb.h
|
||||
index 4dd179db2..609faf7d0 100644
|
||||
--- a/include/grub/usb.h
|
||||
+++ b/include/grub/usb.h
|
||||
@@ -237,6 +237,11 @@ struct grub_usb_device
|
||||
int split_hubport;
|
||||
|
||||
int split_hubaddr;
|
||||
+
|
||||
+ /* xHCI specific information */
|
||||
+ int root_port;
|
||||
+ grub_uint32_t route;
|
||||
+ void *xhci_priv;
|
||||
};
|
||||
|
||||
|
||||
--
|
||||
2.39.2
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+127
@@ -0,0 +1,127 @@
|
||||
From 2a2c64f6ea62337c1263a70f6ca9a9bade66b78b Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
Date: Thu, 3 Dec 2020 13:44:55 +0100
|
||||
Subject: [PATCH 7/8] grub-core/bus/usb/usbhub: Add xHCI non root hub support
|
||||
|
||||
Tested on Intel PCH C246, the USB3 hub can be configured by grub.
|
||||
|
||||
Issues:
|
||||
* USB3 devices connected behind that hub are sometimes not detected.
|
||||
|
||||
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
---
|
||||
grub-core/bus/usb/usbhub.c | 38 +++++++++++++++++++++++++++++++++-----
|
||||
include/grub/usbdesc.h | 1 +
|
||||
include/grub/usbtrans.h | 4 ++++
|
||||
3 files changed, 38 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
|
||||
index b4b3a1a61..e96505aa9 100644
|
||||
--- a/grub-core/bus/usb/usbhub.c
|
||||
+++ b/grub-core/bus/usb/usbhub.c
|
||||
@@ -148,19 +148,32 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
|
||||
return dev;
|
||||
}
|
||||
|
||||
-
|
||||
+static grub_usb_err_t
|
||||
+grub_usb_set_hub_depth(grub_usb_device_t dev, grub_uint8_t depth)
|
||||
+{
|
||||
+ return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
|
||||
+ | GRUB_USB_REQTYPE_CLASS
|
||||
+ | GRUB_USB_REQTYPE_TARGET_DEV),
|
||||
+ GRUB_USB_HUB_REQ_SET_HUB_DEPTH, depth,
|
||||
+ 0, 0, NULL);
|
||||
+}
|
||||
+
|
||||
static grub_usb_err_t
|
||||
grub_usb_add_hub (grub_usb_device_t dev)
|
||||
{
|
||||
struct grub_usb_usb_hubdesc hubdesc;
|
||||
grub_usb_err_t err;
|
||||
+ grub_uint16_t req;
|
||||
int i;
|
||||
|
||||
+ req = (dev->speed == GRUB_USB_SPEED_SUPER) ? GRUB_USB_DESCRIPTOR_SS_HUB :
|
||||
+ GRUB_USB_DESCRIPTOR_HUB;
|
||||
+
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
|
||||
| GRUB_USB_REQTYPE_CLASS
|
||||
| GRUB_USB_REQTYPE_TARGET_DEV),
|
||||
- GRUB_USB_REQ_GET_DESCRIPTOR,
|
||||
- (GRUB_USB_DESCRIPTOR_HUB << 8) | 0,
|
||||
+ GRUB_USB_REQ_GET_DESCRIPTOR,
|
||||
+ (req << 8) | 0,
|
||||
0, sizeof (hubdesc), (char *) &hubdesc);
|
||||
if (err)
|
||||
return err;
|
||||
@@ -183,6 +196,19 @@ grub_usb_add_hub (grub_usb_device_t dev)
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
+ if (dev->speed == GRUB_USB_SPEED_SUPER)
|
||||
+ {
|
||||
+ grub_uint8_t depth;
|
||||
+ grub_uint32_t route;
|
||||
+ /* Depth maximum value is 5, but root hubs doesn't count */
|
||||
+ for (depth = 0, route = dev->route; (route & 0xf) > 0; route >>= 4)
|
||||
+ depth++;
|
||||
+
|
||||
+ err = grub_usb_set_hub_depth(dev, depth);
|
||||
+ if (err)
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
/* Power on all Hub ports. */
|
||||
for (i = 1; i <= hubdesc.portcnt; i++)
|
||||
{
|
||||
@@ -637,7 +663,9 @@ poll_nonroot_hub (grub_usb_device_t dev)
|
||||
int split_hubaddr = 0;
|
||||
|
||||
/* Determine the device speed. */
|
||||
- if (status & GRUB_USB_HUB_STATUS_PORT_LOWSPEED)
|
||||
+ if (dev->speed == GRUB_USB_SPEED_SUPER)
|
||||
+ speed = GRUB_USB_SPEED_SUPER;
|
||||
+ else if (status & GRUB_USB_HUB_STATUS_PORT_LOWSPEED)
|
||||
speed = GRUB_USB_SPEED_LOW;
|
||||
else
|
||||
{
|
||||
@@ -651,7 +679,7 @@ poll_nonroot_hub (grub_usb_device_t dev)
|
||||
grub_millisleep (10);
|
||||
|
||||
/* Find correct values for SPLIT hubport and hubaddr */
|
||||
- if (speed == GRUB_USB_SPEED_HIGH)
|
||||
+ if (speed == GRUB_USB_SPEED_HIGH || speed == GRUB_USB_SPEED_SUPER)
|
||||
{
|
||||
/* HIGH speed device needs not transaction translation */
|
||||
split_hubport = 0;
|
||||
diff --git a/include/grub/usbdesc.h b/include/grub/usbdesc.h
|
||||
index bb2ab2e27..1697aa465 100644
|
||||
--- a/include/grub/usbdesc.h
|
||||
+++ b/include/grub/usbdesc.h
|
||||
@@ -30,6 +30,7 @@ typedef enum {
|
||||
GRUB_USB_DESCRIPTOR_ENDPOINT,
|
||||
GRUB_USB_DESCRIPTOR_DEBUG = 10,
|
||||
GRUB_USB_DESCRIPTOR_HUB = 0x29,
|
||||
+ GRUB_USB_DESCRIPTOR_SS_HUB = 0x2a,
|
||||
GRUB_USB_DESCRIPTOR_SS_ENDPOINT_COMPANION = 0x30
|
||||
} grub_usb_descriptor_t;
|
||||
|
||||
diff --git a/include/grub/usbtrans.h b/include/grub/usbtrans.h
|
||||
index 039ebed65..d6c3f71dc 100644
|
||||
--- a/include/grub/usbtrans.h
|
||||
+++ b/include/grub/usbtrans.h
|
||||
@@ -110,6 +110,10 @@ enum
|
||||
GRUB_USB_REQ_SET_INTERFACE = 0x0B,
|
||||
GRUB_USB_REQ_SYNC_FRAME = 0x0C
|
||||
};
|
||||
+enum
|
||||
+ {
|
||||
+ GRUB_USB_HUB_REQ_SET_HUB_DEPTH = 0x0C,
|
||||
+ };
|
||||
|
||||
#define GRUB_USB_FEATURE_ENDP_HALT 0x00
|
||||
#define GRUB_USB_FEATURE_DEV_REMOTE_WU 0x01
|
||||
--
|
||||
2.39.2
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
From 871d768f8c5c960cb0d9761a9028b16882e1a7d3 Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
Date: Wed, 24 Feb 2021 08:25:41 +0100
|
||||
Subject: [PATCH 8/8] Fix compilation on x86_64
|
||||
|
||||
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
|
||||
---
|
||||
grub-core/bus/usb/xhci.c | 24 ++++++++++++++++--------
|
||||
1 file changed, 16 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/grub-core/bus/usb/xhci.c b/grub-core/bus/usb/xhci.c
|
||||
index f4591ffb5..3495bb919 100644
|
||||
--- a/grub-core/bus/usb/xhci.c
|
||||
+++ b/grub-core/bus/usb/xhci.c
|
||||
@@ -184,7 +184,7 @@ enum
|
||||
* then we can get it from a trb pointer (provided by evt ring).
|
||||
*/
|
||||
#define XHCI_RING(_trb) \
|
||||
- ((struct grub_xhci_ring*)((grub_uint32_t)(_trb) & ~(GRUB_XHCI_RING_SIZE-1)))
|
||||
+ ((struct grub_xhci_ring*)((grub_addr_t)(_trb) & ~(GRUB_XHCI_RING_SIZE-1)))
|
||||
|
||||
/* slot context */
|
||||
struct grub_xhci_slotctx {
|
||||
@@ -495,6 +495,14 @@ grub_xhci_read8(volatile void *addr) {
|
||||
return (*((volatile grub_uint32_t *)addr));
|
||||
}
|
||||
|
||||
+static inline void *
|
||||
+grub_xhci_read_etrb_ptr(volatile struct grub_xhci_trb *trb) {
|
||||
+ grub_uint64_t tmp;
|
||||
+ tmp = (grub_uint64_t)grub_xhci_read32(&trb->ptr_low);
|
||||
+ tmp |= ((grub_uint64_t)grub_xhci_read32(&trb->ptr_high)) << 32;
|
||||
+ return (void *)(grub_addr_t)tmp;
|
||||
+}
|
||||
+
|
||||
static inline grub_uint32_t
|
||||
grub_xhci_port_read (struct grub_xhci *x, grub_uint32_t port)
|
||||
{
|
||||
@@ -664,7 +672,7 @@ static void xhci_process_events(struct grub_xhci *x)
|
||||
case ER_TRANSFER:
|
||||
case ER_COMMAND_COMPLETE:
|
||||
{
|
||||
- struct grub_xhci_trb *rtrb = (void*)grub_xhci_read32(&etrb->ptr_low);
|
||||
+ struct grub_xhci_trb *rtrb = grub_xhci_read_etrb_ptr(etrb);
|
||||
struct grub_xhci_ring *ring = XHCI_RING(rtrb);
|
||||
volatile struct grub_xhci_trb *evt = &ring->evt;
|
||||
grub_uint32_t eidx = rtrb - ring->ring + 1;
|
||||
@@ -697,9 +705,9 @@ static void xhci_process_events(struct grub_xhci *x)
|
||||
}
|
||||
grub_xhci_write32(&evts->nidx, nidx);
|
||||
volatile struct grub_xhci_ir *ir = x->ir;
|
||||
- grub_uint32_t erdp = (grub_uint32_t)(evts->ring + nidx);
|
||||
- grub_xhci_write32(&ir->erdp_low, erdp);
|
||||
- grub_xhci_write32(&ir->erdp_high, 0);
|
||||
+ grub_uint64_t erdp = (grub_addr_t)(void *)(&evts->ring[nidx]);
|
||||
+ grub_xhci_write32(&ir->erdp_low, erdp & 0xffffffff);
|
||||
+ grub_xhci_write32(&ir->erdp_high, erdp >> 32);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -800,7 +808,7 @@ static void xhci_trb_queue(volatile struct grub_xhci_ring *ring,
|
||||
grub_uint32_t xferlen, grub_uint32_t flags)
|
||||
{
|
||||
grub_dprintf("xhci", "%s: ring %p data %llx len %d flags 0x%x remain 0x%x\n", __func__,
|
||||
- ring, data_or_addr, xferlen & 0x1ffff, flags, xferlen >> 17);
|
||||
+ ring, (unsigned long long)data_or_addr, xferlen & 0x1ffff, flags, xferlen >> 17);
|
||||
|
||||
if (xhci_ring_full(ring))
|
||||
{
|
||||
@@ -1907,7 +1915,7 @@ grub_xhci_setup_transfer (grub_usb_controller_t dev,
|
||||
if (transfer->type == GRUB_USB_TRANSACTION_TYPE_CONTROL)
|
||||
{
|
||||
volatile struct grub_usb_packet_setup *setupdata;
|
||||
- setupdata = (void *)transfer->transactions[0].data;
|
||||
+ setupdata = (void *)(grub_addr_t)transfer->transactions[0].data;
|
||||
grub_dprintf("xhci", "%s: CONTROLL TRANS req %d\n", __func__, setupdata->request);
|
||||
grub_dprintf("xhci", "%s: CONTROLL TRANS length %d\n", __func__, setupdata->length);
|
||||
|
||||
@@ -1974,7 +1982,7 @@ grub_xhci_setup_transfer (grub_usb_controller_t dev,
|
||||
/* Assume the ring has enough free space for all TRBs */
|
||||
if (flags & TRB_TR_IDT && tr->size <= (int)sizeof(inline_data))
|
||||
{
|
||||
- grub_memcpy(&inline_data, (void *)tr->data, tr->size);
|
||||
+ grub_memcpy(&inline_data, (void *)(grub_addr_t)tr->data, tr->size);
|
||||
xhci_trb_queue(reqs, inline_data, tr->size, flags);
|
||||
}
|
||||
else
|
||||
--
|
||||
2.39.2
|
||||
|
||||
+1074
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
tree="xhci"
|
||||
rev="8719cc2040368d43ab2de0b6e1b850b2c9cfc5b7"
|
||||
bootstrapargs="--gnulib-srcdir=gnulib/ --no-git"
|
||||
autoconfargs="--with-platform=coreboot --disable-werror"
|
||||
makeargs="FS_PAYLOAD_MODULES=\"\""
|
||||
Reference in New Issue
Block a user