Add xHCI support
RFC 1/1 Add xHCI support
Add support for xHCI USB controllers.
The code is based on seabios implementation, but has been heavily modified to match grubs internals.
A version of this patch was suggested to Qemu developers in 12/2020. Since then it was modified by Eltan to work on more hardware. Afterwards my colleague Deividas Puplauskas fixed a lot of bugs, which were found while using xHCI support on our own hardware.
xHCI support was tested in Qemu and on MSC C6B-CFLR¹ boards.
Support for following devices was tested:
- USB mass storage
- USB DVD burner
- USB 2.0 hub
¹ https://embedded.avnet.com/product/msc-c6b-cflr/
---
This patch is meant as a RFC. I know it is rather big patch, please tell me what is required to get a review. What parts should be splitted into parts? We would like to get these changes into upstream.
--- Makefile.am | 2 +- grub-core/Makefile.core.def | 7 + grub-core/bus/usb/ehci.c | 2 + grub-core/bus/usb/ohci.c | 2 + grub-core/bus/usb/serial/common.c | 2 +- grub-core/bus/usb/uhci.c | 2 + grub-core/bus/usb/usb.c | 46 +- grub-core/bus/usb/usbhub.c | 121 +- grub-core/bus/usb/usbtrans.c | 6 +- grub-core/bus/usb/xhci-pci.c | 194 +++ grub-core/bus/usb/xhci.c | 2578 +++++++++++++++++++++++++++++ grub-core/commands/usbtest.c | 2 +- grub-core/disk/usbms.c | 2 +- grub-core/term/usb_keyboard.c | 3 +- include/grub/usb.h | 22 +- include/grub/usbdesc.h | 12 +- include/grub/usbtrans.h | 5 + 17 files changed, 2963 insertions(+), 45 deletions(-) create mode 100644 grub-core/bus/usb/xhci-pci.c create mode 100644 grub-core/bus/usb/xhci.c
Makefile.am +1 -1
@@ -434,7 +434,7 @@ if COND_i386_coreboot FS_PAYLOAD_MODULES ?= $(shell cat grub-core/fs.lst) default_payload.elf: grub-mkstandalone grub-mkimage FORCE test -f $@ && rm $@ || true - pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu $(FS_PAYLOAD_MODULES) password_pbkdf2 $(EXTRA_PAYLOAD_MODULES)' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg + pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata xhci ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu $(FS_PAYLOAD_MODULES) password_pbkdf2 $(EXTRA_PAYLOAD_MODULES)' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg endif endif
grub-core/Makefile.core.def +7 -0
@@ -667,6 +667,13 @@ module = { enable = arm_coreboot; }; +module = { + name = xhci; + common = bus/usb/xhci.c; + pci = bus/usb/xhci-pci.c; + enable = pci; +}; + module = { name = pci; common = bus/pci.c;
grub-core/bus/usb/ehci.c +2 -0
@@ -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 };
grub-core/bus/usb/ohci.c +2 -0
@@ -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 };
grub-core/bus/usb/serial/common.c +1 -1
@@ -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
grub-core/bus/usb/uhci.c +2 -0
@@ -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 };
grub-core/bus/usb/usb.c +28 -18
66 lines not on this page · raw message
grub-core/bus/usb/usbhub.c +103 -18
225 lines not on this page · raw message
grub-core/bus/usb/usbtrans.c +5 -1
@@ -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 ;
grub-core/bus/usb/xhci-pci.c new file +194 -0
194 lines not on this page · raw message
grub-core/bus/usb/xhci.c new file +2578 -0
2,449 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.39.5
Get grub and gnulib:
$ git clone git://git.sv.gnu.org/grub.git $ git clone git://git.sv.gnu.org/gnulib.git
Configure Grub:
$ cd grub $ ./bootstrap --no-git --gnulib-srcdir=../gnulib $ mkdir build $ cd build $ ../configure --target=x86_64 --disable-efiemu --with-platform=coreboot
Build Grub:
$ make -j4 $ make default_payload.elf
Get coreboot:
$ git clone https://review.coreboot.org/coreboot.git
Build Coreboot:
$ cd coreboot $ make menuconfig $ make
Exchange Payload:
$ build/util/cbfstool/cbfstool build/coreboot.rom remove -n fallback/payload -r COREBOOT $ build/util/cbfstool/cbfstool build/coreboot.rom add-payload -f ../grub/build/default_payload.elf -n fallback/payload -r COREBOOT $ cd ..
Get minmal Linux kernel for testing purpose:
$ wget https://debug.openadk.org/qemu-x86_64.img
Start Qemu:
$ qemu-system-x86_64 -bios coreboot/build/coreboot.rom -drive if=none,id=stick,format=raw,file=qemu-x86_64.img \ -device nec-usb-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick -serial stdio
Grub console:
grub> set root=(usb0)
grub> linux (usb0)/kernel
grub> boot
If you want to use an USB stick connected to your host you need to start Qemu as root like this. Find out your USB product and vendor id via lsusb:
$ sudo qemu-system-x86_64 -bios coreboot.rom -drive if=none,id=stick,format=raw,file=qemu-x86_64.img -device nec-usb-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick -serial stdio -device usb-host,bus=xhci.0,vendorid=0x058f,productid=0x6387
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Part of the diff is not shown here. View the raw message.
Hi,
friendly ping
best regards
Waldemar
Waldemar Brodkorb wrote,
Quoted 16 lines
Add support for xHCI USB controllers.
The code is based on seabios implementation, but has been heavily modified to match grubs internals.A version of this patch was suggested to Qemu developers in 12/2020. Since then it was modified by Eltan to work on more hardware. Afterwards my colleague Deividas Puplauskas fixed a lot of bugs, which were found while using xHCI support on our own hardware.
xHCI support was tested in Qemu and on MSC C6B-CFLR¹ boards.
Support for following devices was tested:
- USB mass storage
- USB DVD burner
- USB 2.0 hub
Quoted 8 lines
¹ https://embedded.avnet.com/product/msc-c6b-cflr/
Signed-off-by Patrick Rudolph <[email protected]>Signed-off-by sylv <[email protected]>Signed-off-by Frans Hendriks <[email protected]>Signed-off-by Erik van den Bogaert <[email protected]>Signed-off-by Deividas Puplauskas <[email protected]>Signed-off-by Waldemar Brodkorb <[email protected]>
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel