grub/xhci: rename to grub/xhci_nvme

we have the "default" tree, then the "nvme" tree which adds
nvme support.

the "xhci" tree adds xhci patches, *and* nvme patches.

riku suggested that i rename it accordingly, and his advice
was quite correct, indeed wise.

this will reduce confusion for contributors, including *myself*.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2025-10-02 23:47:31 +01:00
parent d90defeae3
commit af88a066d0
43 changed files with 24 additions and 24 deletions
+321
View File
@@ -0,0 +1,321 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2014-2016,2020-2021,2023-2025 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
for dt in cbfsdisk memdisk; do
for it in png jpg; do
if [ -f (${dt})/background.${it} ]; then
insmod ${it}
background_image (${dt})/background.${it}
fi
done
done
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=8
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
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
# TODO: optimize grub itself, and use */? here for everything
for vol in ${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} ${raidvol}; do
if cryptomount "${dev}" ; then break ; fi
done
set pager=1
echo
search_bootcfg crypto
lvmvol=""
# after cryptomount, lvm volumes might be available
# using * is slow on some machines, but we use it here,
# just once. in so doing, we find every lvm volume
for vol in (*); do
if regexp ^\\(lvm/ $vol; then
lvmvol="${lvmvol} ${vol}"
try_bootcfg "${vol}"
fi
done
# user might have put luks inside lvm
set pager=0
echo "Attempting to unlock encrypted LVMs"
for vol in ${lvmvol}; do
cryptomount "$vol"
done
set pager=1
echo
search_bootcfg crypto
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)/u-boot ]; then
menuentry 'U-Boot i386 payload (experimental) [u]' --hotkey='u' {
set root='cbfsdisk'
chainloader /u-boot
}
fi
if [ -f (cbfsdisk)/seabios.elf ]; then
if [ -f (cbfsdisk)/img/u-boot ]; then
menuentry 'Load SeaBIOS (U-Boot UEFI available in the ESC menu) [b]' --hotkey='b' {
set root='cbfsdisk'
chainloader /seabios.elf
}
else
menuentry 'Load SeaBIOS [b]' --hotkey='b' {
set root='cbfsdisk'
chainloader /seabios.elf
}
fi
fi
if [ -f (cbfsdisk)/img/grub2 ]; then
if [ -f (cbfsdisk)/img/u-boot ]; then
menuentry 'Return to SeaBIOS (U-Boot UEFI available in the ESC menu) [b]' --hotkey='b' {
set root='cbfsdisk'
chainloader /fallback/payload
}
else
menuentry 'Return to SeaBIOS [b]' --hotkey='b' {
set root='cbfsdisk'
chainloader /fallback/payload
}
fi
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
}
}
@@ -0,0 +1,90 @@
From 6a04ceb244366ddab75ce229afd19687ce35d15a Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Sun, 31 Oct 2021 03:47:05 +0000
Subject: [PATCH 01/26] 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 9c383e64a..8ec1dd1e8 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,
@@ -413,8 +370,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.39.5
@@ -0,0 +1,25 @@
From c18175417d4fa4501dac21ef26b9c30f67ece0fd Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Sat, 19 Nov 2022 16:30:24 +0000
Subject: [PATCH 02/26] 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 96abfda2f..d806db9c4 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 25.06 Luminous Lemon (GRUB menu): https://libreboot.org/"));
if (!msg_formatted)
return;
--
2.39.5
@@ -0,0 +1,42 @@
From 72b0b0f76b3cc7f03e42322b77400b89c3ccf766 Mon Sep 17 00:00:00 2001
From: Ax333l <main@axelen.xyz>
Date: Thu, 17 Aug 2023 00:00:00 +0000
Subject: [PATCH 03/26] 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 de8c3aa8d..4a3be8568 100644
--- a/grub-core/kern/dl.c
+++ b/grub-core/kern/dl.c
@@ -495,7 +495,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.5
@@ -0,0 +1,39 @@
From 451ca97719aa9178f3202554c74ab636baece616 Mon Sep 17 00:00:00 2001
From: Ax333l <main@axelen.xyz>
Date: Thu, 17 Aug 2023 00:00:00 +0000
Subject: [PATCH 04/26] 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 45079bf65..8c0b30395 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.5
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,58 @@
From c75424efa3a6357d4785c7a66721809a642b3968 Mon Sep 17 00:00:00 2001
From: Ax333l <main@axelen.xyz>
Date: Thu, 17 Aug 2023 00:00:00 +0000
Subject: [PATCH 06/26] 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 b17cd2115..bbd8f5579 100644
--- a/grub-core/disk/luks2.c
+++ b/grub-core/disk/luks2.c
@@ -39,6 +39,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;
@@ -91,7 +92,7 @@ struct grub_luks2_keyslot
grub_int64_t time;
grub_int64_t memory;
grub_int64_t cpus;
- } argon2i;
+ } argon2;
struct
{
const char *hash;
@@ -161,10 +162,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"))
@@ -460,6 +462,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.5
@@ -0,0 +1,83 @@
From 801aa8b85d8f3b999f4660cc299a3517e811f0bb Mon Sep 17 00:00:00 2001
From: Ax333l <main@axelen.xyz>
Date: Thu, 17 Aug 2023 00:00:00 +0000
Subject: [PATCH 07/26] 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 038253b37..2f19569c9 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 0ee65d54d..cd29a9df8 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1242,7 +1242,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 bbd8f5579..02cd615d9 100644
--- a/grub-core/disk/luks2.c
+++ b/grub-core/disk/luks2.c
@@ -28,6 +28,7 @@
#include <grub/i18n.h>
#include <grub/safemath.h>
+#include <argon2.h>
#include <base64.h>
#include <json.h>
@@ -463,8 +464,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.5
@@ -0,0 +1,26 @@
From c114684bb103af427296e40b78adc0d036a9b237 Mon Sep 17 00:00:00 2001
From: Ax333l <main@axelen.xyz>
Date: Thu, 17 Aug 2023 00:00:00 +0000
Subject: [PATCH 08/26] 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 060246589..059036d3c 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.5
@@ -0,0 +1,107 @@
From dfbfe525d6f138e3db1e683096302045c064096f Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Mon, 30 Oct 2023 22:19:21 +0000
Subject: [PATCH 09/26] 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.5
@@ -0,0 +1,38 @@
From 18f88785a46e6657e1404e1914638f4768d65008 Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Tue, 31 Oct 2023 10:33:28 +0000
Subject: [PATCH 10/26] 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.5
@@ -0,0 +1,102 @@
From afd68d1e132970e4fa8e26e9ca0ccb7efb69dc37 Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Sun, 5 Nov 2023 16:14:58 +0000
Subject: [PATCH 11/26] 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 4a3be8568..6ae3d73f8 100644
--- a/grub-core/kern/dl.c
+++ b/grub-core/kern/dl.c
@@ -881,7 +881,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.5
@@ -0,0 +1,34 @@
From 06f9480a670d374e1599bf9871f6cd26656418a7 Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Sun, 5 Nov 2023 16:36:22 +0000
Subject: [PATCH 12/26] 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 6ae3d73f8..4c15027fe 100644
--- a/grub-core/kern/dl.c
+++ b/grub-core/kern/dl.c
@@ -511,7 +511,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.5
@@ -0,0 +1,31 @@
From 272c5f5724c0790aff48b0d6ba75928de2275b33 Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Sun, 5 Nov 2023 17:25:20 +0000
Subject: [PATCH 13/26] 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.5
@@ -0,0 +1,246 @@
From 1c5716f42deb27b1111839b9782fd06b077eaa90 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 14/26] 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.5
@@ -0,0 +1,29 @@
From 260f27e1ea1dbcdeb63d4411dbdddb97ebb39668 Mon Sep 17 00:00:00 2001
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Date: Mon, 7 Dec 2020 08:41:22 +0100
Subject: [PATCH 15/26] 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.5
@@ -0,0 +1,33 @@
From 97f71a34c011ad9d37b96c02eb7483fe253c6025 Mon Sep 17 00:00:00 2001
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Date: Mon, 7 Dec 2020 08:41:23 +0100
Subject: [PATCH 16/26] 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.5
@@ -0,0 +1,121 @@
From ea5081844c3112b582f52360cfb14ef95b56f5e1 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 17/26] 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 2db07c7c0..1ee056015 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.5
@@ -0,0 +1,77 @@
From 7db1cdd1cdbb79a8da04648dcbf7318d200f72a4 Mon Sep 17 00:00:00 2001
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Date: Mon, 7 Dec 2020 08:41:25 +0100
Subject: [PATCH 18/26] 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.5
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,127 @@
From d84ac94dc55baad9a2297980b2017cd22e4ecb3c Mon Sep 17 00:00:00 2001
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Date: Mon, 7 Dec 2020 08:41:27 +0100
Subject: [PATCH 20/26] 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.5
@@ -0,0 +1,26 @@
From 0433c5bb1e40fba93205e1c9fd6b1b397d31ae5a Mon Sep 17 00:00:00 2001
From: Sven Anderson <sven@anderson.de>
Date: Sat, 28 May 2022 21:39:23 +0200
Subject: [PATCH 21/26] xHCI: also accept SBRN 0x31 and 0x32
Signed-off-by: Sven Anderson <sven@anderson.de>
---
grub-core/bus/usb/xhci-pci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/grub-core/bus/usb/xhci-pci.c b/grub-core/bus/usb/xhci-pci.c
index a5bd3c97d..cde21f57a 100644
--- a/grub-core/bus/usb/xhci-pci.c
+++ b/grub-core/bus/usb/xhci-pci.c
@@ -76,7 +76,7 @@ grub_xhci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
/* Check Serial Bus Release Number */
addr = grub_pci_make_address (dev, GRUB_XHCI_PCI_SBRN_REG);
release = grub_pci_read_byte (addr);
- if (release != 0x30)
+ if (release != 0x30 && release != 0x31 &&release != 0x32)
{
grub_dprintf ("xhci", "XHCI grub_xhci_pci_iter: Wrong SBRN: %0x\n",
release);
--
2.39.5
@@ -0,0 +1,43 @@
From d300f12cb624998f3d5ab5948c3fc64d6d7baf4f Mon Sep 17 00:00:00 2001
From: Sven Anderson <sven@anderson.de>
Date: Mon, 13 Jan 2025 19:51:41 +0100
Subject: [PATCH 22/26] xhci: fix port indexing
---
grub-core/bus/usb/xhci.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/grub-core/bus/usb/xhci.c b/grub-core/bus/usb/xhci.c
index f4591ffb5..dc89b9619 100644
--- a/grub-core/bus/usb/xhci.c
+++ b/grub-core/bus/usb/xhci.c
@@ -2250,7 +2250,7 @@ grub_xhci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
*changed = 0;
grub_dprintf("xhci", "%s: dev=%p USB%d_%d port %d\n", __func__, dev,
- x->psids[port-1].major, x->psids[port-1].minor, port);
+ x->psids[port].major, x->psids[port].minor, port);
/* On shutdown advertise all ports as disconnected. This will trigger
* a gracefull detatch. */
@@ -2285,13 +2285,13 @@ grub_xhci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
if (!(portsc & GRUB_XHCI_PORTSC_CCS))
return GRUB_USB_SPEED_NONE;
- for (grub_uint8_t i = 0; i < 16 && x->psids[port-1].psids[i].id > 0; i++)
+ for (grub_uint8_t i = 0; i < 16 && x->psids[port].psids[i].id > 0; i++)
{
- if (x->psids[port-1].psids[i].id == speed)
+ if (x->psids[port].psids[i].id == speed)
{
grub_dprintf("xhci", "%s: grub_usb_speed = %d\n", __func__,
- x->psids[port-1].psids[i].grub_usb_speed );
- return x->psids[port-1].psids[i].grub_usb_speed;
+ x->psids[port].psids[i].grub_usb_speed );
+ return x->psids[port].psids[i].grub_usb_speed;
}
}
--
2.39.5
@@ -0,0 +1,98 @@
From 0a669ef9815267de4fb14f3c329431ac531755c9 Mon Sep 17 00:00:00 2001
From: Sven Anderson <sven@anderson.de>
Date: Mon, 13 Jan 2025 20:26:32 +0100
Subject: [PATCH 23/26] xhci: configure TT for non-root-hubs
---
grub-core/bus/usb/usbhub.c | 6 +++++
grub-core/bus/usb/xhci.c | 45 +++++++++++++++++++++++++++++++++-----
include/grub/usb.h | 2 ++
3 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
index e96505aa9..629b3ed53 100644
--- a/grub-core/bus/usb/usbhub.c
+++ b/grub-core/bus/usb/usbhub.c
@@ -818,3 +818,9 @@ grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data)
return 0;
}
+
+grub_usb_device_t
+grub_usb_get_dev (int addr)
+{
+ return grub_usb_devs[addr];
+}
diff --git a/grub-core/bus/usb/xhci.c b/grub-core/bus/usb/xhci.c
index dc89b9619..88c9ac57f 100644
--- a/grub-core/bus/usb/xhci.c
+++ b/grub-core/bus/usb/xhci.c
@@ -623,13 +623,46 @@ grub_xhci_alloc_inctx(struct grub_xhci *x, int maxepid,
break;
}
- /* Route is greater zero on devices that are connected to a non root hub */
- if (dev->route)
- {
- /* FIXME: Implement this code for non SuperSpeed hub devices */
+ /* Set routing string */
+ slot->ctx[0] |= dev->route;
+
+ /* Set root hub port number */
+ slot->ctx[1] |= (dev->root_port + 1) << 16;
+
+ if (dev->split_hubaddr && (dev->speed == GRUB_USB_SPEED_LOW ||
+ dev->speed == GRUB_USB_SPEED_FULL)) {
+
+ grub_usb_device_t hubdev = grub_usb_get_dev(dev->split_hubaddr);
+
+ if (!hubdev || hubdev->descdev.class != GRUB_USB_CLASS_HUB) {
+ grub_dprintf("xhci", "Invalid hub device at addr %d!\n", dev->split_hubaddr);
+ return NULL;
+ }
+
+ struct grub_xhci_priv *hub_priv = hubdev->xhci_priv;
+ if (!hub_priv) {
+ grub_dprintf("xhci", "Hub has no xhci_priv!\n");
+ return NULL;
+ }
+
+ if (hubdev->speed == GRUB_USB_SPEED_HIGH) {
+ /* Direct connection to high-speed hub - set up TT */
+ grub_dprintf("xhci", "Direct high-speed hub connection - configuring TT with "
+ "hub slot %d port %d\n", hub_priv->slotid, dev->split_hubport);
+ slot->ctx[2] |= hub_priv->slotid;
+ slot->ctx[2] |= dev->split_hubport << 8;
}
- slot->ctx[0] |= dev->route;
- slot->ctx[1] |= (dev->root_port+1) << 16;
+ else {
+ /* Hub is not high-speed, inherit TT settings from parent */
+ volatile struct grub_xhci_slotctx *hubslot;
+ grub_dprintf("xhci", "Non high-speed hub - inheriting TT settings from parent\n");
+ hubslot = grub_dma_phys2virt(x->devs[hub_priv->slotid].ptr_low, x->devs_dma);
+ slot->ctx[2] = hubslot->ctx[2];
+ }
+ }
+
+ grub_dprintf("xhci", "Slot context: ctx[0]=0x%08x ctx[1]=0x%08x ctx[2]=0x%08x\n",
+ slot->ctx[0], slot->ctx[1], slot->ctx[2]);
grub_arch_sync_dma_caches(in, size);
diff --git a/include/grub/usb.h b/include/grub/usb.h
index eb71fa1c7..df97a60cc 100644
--- a/include/grub/usb.h
+++ b/include/grub/usb.h
@@ -62,6 +62,8 @@ typedef int (*grub_usb_controller_iterate_hook_t) (grub_usb_controller_t dev,
/* Call HOOK with each device, until HOOK returns non-zero. */
int grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data);
+grub_usb_device_t grub_usb_get_dev (int addr);
+
grub_usb_err_t grub_usb_device_initialize (grub_usb_device_t dev);
grub_usb_err_t grub_usb_get_descriptor (grub_usb_device_t dev,
--
2.39.5
@@ -0,0 +1,90 @@
From 625fdcf42f2cf11a4bfe644412450c9e4f551d25 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 24/26] 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 88c9ac57f..9b9bae6e5 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)
{
@@ -697,7 +705,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;
@@ -730,9 +738,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);
}
}
@@ -833,7 +841,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))
{
@@ -1940,7 +1948,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);
@@ -2007,7 +2015,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.5
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,37 @@
From d73ca74ef879bf602274bee6eb24f0080a45d235 Mon Sep 17 00:00:00 2001
From: Paul Menzel <pmenzel@molgen.mpg.de>
Date: Mon, 17 May 2021 10:24:36 +0200
Subject: [PATCH 26/26] kern/coreboot/mmap: Map to reserved
https://git.savannah.gnu.org/cgit/grub.git/commit/?id=6de9ee86bf9ae50967413e6a73b5dfd13e5ffb50
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
grub-core/kern/coreboot/mmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/grub-core/kern/coreboot/mmap.c b/grub-core/kern/coreboot/mmap.c
index caf8f7cef..2fc316e8d 100644
--- a/grub-core/kern/coreboot/mmap.c
+++ b/grub-core/kern/coreboot/mmap.c
@@ -59,7 +59,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
/* Multiboot mmaps match with the coreboot mmap
definition. Therefore, we can just pass type
through. */
- mem_region->type,
+ (mem_region->type >= 13) ? 2 : mem_region->type,
ctx->hook_data))
return 1;
if (start < 0xa0000)
@@ -81,7 +81,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
/* Multiboot mmaps match with the coreboot mmap
definition. Therefore, we can just pass type
through. */
- mem_region->type,
+ (mem_region->type >= 13) ? 2 : mem_region->type,
ctx->hook_data))
return 1;
}
--
2.39.5
+4
View File
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
tree="xhci"
rev="a68a7dece464c35b1c8d20b98502b6881b103911"