QEMU improvements

Since 2018 U-Boot has had a good selection of features for running on top of QEMU, including:
- virtio using PCI devices (legacy and modern)
- virtio using memory-mapped I/O
- block devices, to support filesystems, etc. (virtio-blk)
- network devices (virtio-net)
- random-number device (virtio-rng)
Most of this was written by Bin Meng. It uses driver model and is nicely implemented.
What’s new?
More recently a few more features have been added:
- SCSI devices, for more flexible discovery with multiple disks (virtio-scsi)
- Filesystem devices, for access to host files (virtio-fs). See the separate post about this.
- Visibility into the available virtio devices (
virtio list
) - Additions to the qfw command to improve visibility
The `virtio list` command can be useful for seeing what paravirtualised devices are available and whether U-Boot has a driver for them. Here you can see U-Boot running on an x86 host.
=> virtio scan => virtio list Name Type Driver -------------------- -------------- --------------- virtio-pci.m#0 5: balloon (none) virtio-pci.m#1 4: rng virtio-rng#1 virtio-pci.m#2 12: input-host (none) virtio-pci.m#3 12: input-host (none) virtio-pci.m#4 13: vsock (none) virtio-pci.m#5 3: serial (none) virtio-pci.m#6 8: scsi virtio-scsi#6 virtio-pci.m#7 9: 9p (none) virtio-pci.m#8 1a: fs virtio-fs#8 virtio-pci.m#9 10: gpu (none) virtio-pci.m#10 1: net virtio-net#a =>
Here you can see how the random-number driver can be used:
=> random 1000 10 16 bytes filled with random data => md.b 1000 10 00001000: 00 3f e2 f8 a1 70 4e 5f 8c 19 19 ba 18 76 32 bc .?...pN_.....v2. =>
SCSI is accessed by scanning it first. Note that standard boot does this automatically, if you are just booting an OS.
=> scsi scan scanning bus for devices... Device 0: (0:1) Vendor: QEMU Prod.: QEMU HARDDISK Rev: 2.5+ Type: Hard Disk Capacity: 10240.0 MB = 10.0 GB (20971520 x 512) => part list scsi 0 Partition Map for scsi device 0 -- Partition Type: EFI Part Start LBA End LBA Name Attributes Type GUID Partition GUID 1 0x00200800 0x013fffde "" attrs: 0x0000000000000000 type: 0fc63daf-8483-4772-8e79-3d69d8477de4 (linux) guid: e53def26-b3a7-4227-8175-b933282b824f e 0x00000800 0x000027ff "" attrs: 0x0000000000000000 type: 21686148-6449-6e6f-744e-656564454649 (21686148-6449-6e6f-744e-656564454649) guid: a52718a3-62a4-483a-b8fa-38cefacad2fd f 0x00002800 0x000377ff "" attrs: 0x0000000000000000 type: c12a7328-f81f-11d2-ba4b-00a0c93ec93b (EFI System Partition) guid: 077b8491-26d1-4984-a86f-2c8674c438ee 10 0x00037800 0x00200000 "" attrs: 0x0000000000000000 type: bc13c2ff-59e6-4262-a352-b275fd6f7172 (bc13c2ff-59e6-4262-a352-b275fd6f7172) guid: 3b088c0d-2f7b-4d92-b7c0-561d0e2cdd30 =>
You can also inspect some of the qfw tables directly. The qfw list
command has been around for a while, although some minor updates were added recently. It shows the files that QEMU presents to U-Boot:
=> qfw list Addr Size Sel Name -------- -------- --- ------------ 0 0 20 bios-geometry 0 6d 21 bootorder 3fcab000 14 22 etc/acpi/rsdp 3fcad000 20000 23 etc/acpi/tables 0 4 24 etc/boot-fail-wait 0 28 25 etc/e820 0 8 26 etc/msr_feature_control 0 18 27 etc/smbios/smbios-anchor 0 169 28 etc/smbios/smbios-tables 0 1 29 etc/smi/features-ok 0 8 2a etc/smi/requested-features 0 8 2b etc/smi/supported-features 0 6 2c etc/system-states 0 1000 2d etc/table-loader 0 0 2e etc/tpm/log 0 8 2f etc/vmgenid_addr 3fcac000 1000 30 etc/vmgenid_guid 0 2400 31 genroms/kvmvapic.bin
Low-level features
The new qfw table
command can be useful to seeing exactly how the ACPI tables are provided:
=> qfw table 0 alloc: align 10 zone fseg name 'etc/acpi/rsdp' 1 alloc: align 1000 zone high name 'etc/vmgenid_guid' 2 alloc: align 40 zone high name 'etc/acpi/tables' 3 add-chksum offset 49 start 40 length 30f7 name 'etc/acpi/tables' 4 add-ptr offset 315b size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 5 add-ptr offset 315f size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 6 add-ptr offset 31c3 size 8 dest 'etc/acpi/tables' src 'etc/acpi/tables' 7 add-chksum offset 3140 start 3137 length f4 name 'etc/acpi/tables' 8 add-chksum offset 3234 start 322b length 120 name 'etc/acpi/tables' 9 10 add-ptr offset 3375 size 4 dest 'etc/acpi/tables' src 'etc/vmgenid_guid' 11 add-chksum offset 3354 start 334b length ca name 'etc/acpi/tables' 12 add-chksum offset 341e start 3415 length 38 name 'etc/acpi/tables' 13 add-chksum offset 3456 start 344d length 208 name 'etc/acpi/tables' 14 add-chksum offset 365e start 3655 length 3c name 'etc/acpi/tables' 15 add-chksum offset 369a start 3691 length 28 name 'etc/acpi/tables' 16 add-ptr offset 36dd size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 17 add-ptr offset 36e1 size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 18 add-ptr offset 36e5 size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 19 add-ptr offset 36e9 size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 20 add-ptr offset 36ed size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 21 add-ptr offset 36f1 size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 22 add-ptr offset 36f5 size 4 dest 'etc/acpi/tables' src 'etc/acpi/tables' 23 add-chksum offset 36c2 start 36b9 length 40 name 'etc/acpi/tables' 24 add-ptr offset 10 size 4 dest 'etc/acpi/rsdp' src 'etc/acpi/tables' 25 add-chksum offset 8 start 0 length 14 name 'etc/acpi/rsdp'
Since QEMU can also provide SMBIOS tables, these can be inspected using the smbios
command:
=> smbios SMBIOS 3.0.0 present. 9 structures occupying 361 bytes Table at 0x3fcdc018 Handle 0x0100, DMI type 1, 27 bytes at 0x3fcdc018 System Information Manufacturer: QEMU Product Name: Standard PC (Q35 + ICH9, 2009) Version: pc-q35-8.2 Serial Number: UUID: 8967d155-8cbb-484f-9246-d2c4eeeedff1 Wake-up Type: Power Switch SKU Number: Family: Handle 0x0200, DMI type 2, 15 bytes at 0x3fcdc063 Baseboard Information Manufacturer: Canonical Ltd. Product Name: LXD Version: pc-q35-8.2 Serial Number: Asset Tag: Feature Flags: 0x01 Chassis Location: Chassis Handle: 0x0300 Board Type: Motherboard Number of Contained Object Handles: 0x00 Handle 0x0300, DMI type 3, 22 bytes at 0x3fcdc091 Baseboard Information Manufacturer: QEMU Type: 0x01 Version: pc-q35-8.2 Serial Number: Asset Tag: Boot-up State: Safe Power Supply State: Safe Thermal State: Safe Security Status: Unknown OEM-defined: 0x00000000 Height: 0x00 Number of Power Cords: 0x00 Contained Element Count: 0x00 Contained Element Record Length: 0x00 SKU Number: Handle 0x0400, DMI type 4, 48 bytes at 0x3fcdc0b8 Processor Information: Socket Designation: CPU 0 Processor Type: Central Processor Processor Family: Other Processor Manufacturer: QEMU Processor ID word 0: 0x000a06a4 Processor ID word 1: 0x0f8bfbff Processor Version: pc-q35-8.2 Voltage: 0x00 External Clock: 0x0000 Max Speed: 0x07d0 Current Speed: 0x07d0 Status: 0x41 Processor Upgrade: Other L1 Cache Handle: 0xffff L2 Cache Handle: 0xffff L3 Cache Handle: 0xffff Serial Number: Asset Tag: Part Number: Core Count: 0x16 Core Enabled: 0x16 Thread Count: 0x16 Processor Characteristics: 0x0002 Processor Family 2: Other Core Count 2: 0x0016 Core Enabled 2: 0x0016 Thread Count 2: 0x0016 Thread Enabled: 0x5043 Handle 0x1000, DMI type 16, 23 bytes at 0x3fcdc0ff Header and Data: 00000000: 10 17 00 10 01 03 06 00 00 10 00 fe ff 01 00 00 00000010: 00 00 00 00 00 00 00 Handle 0x1100, DMI type 17, 40 bytes at 0x3fcdc118 Header and Data: 00000000: 11 28 00 11 00 10 fe ff ff ff ff ff 00 04 09 00 00000010: 01 00 07 02 00 00 00 02 00 00 00 00 00 00 00 00 00000020: 00 00 00 00 00 00 00 00 Strings: String 1: DIMM 0 String 2: QEMU Handle 0x1300, DMI type 19, 31 bytes at 0x3fcdc14d Header and Data: 00000000: 13 1f 00 13 00 00 00 00 ff ff 0f 00 00 10 01 00 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Handle 0x2000, DMI type 32, 11 bytes at 0x3fcdc16e Header and Data: 00000000: 20 0b 00 20 00 00 00 00 00 00 00 Handle 0x7f00, DMI type 127, 4 bytes at 0x3fcdc17b End Of Table
You can see above that these are created by QEMU, under control of LXD. Thus the environment which U-Boot sees can be controlled by QEMU or by tools which integrate QEMU.
What’s next?
U-Boot has a fairly solid set of QEMU features at this point. It provides an alternative to OVMF in some cases, with a faster boot, while still using EFI. Future work may include looking at booting without EFI, thus saving time and reducing complexity.