Virtio-SCSI Arrives, Backed by a Major SCSI Overhaul

We’re excited to announce a significant new feature in U-Boot: a virtio-scsi
driver. While U-Boot has long supported virtio-blk
for block device access in virtualized environments, virtio-scsi
offers greater flexibility, allowing a single virtio device to host multiple disks (LUNs) and supporting features like hotplug.
This comprehensive 27-patch series, does more than just add a new driver. To make virtio-scsi
a reality, U-Boot’s entire SCSI subsystem has received a much-needed modernization, resulting in a faster, more robust, and more maintainable implementation for all SCSI devices.
Smarter Scanning with REPORT LUNS
One of the most significant improvements is in how U-Boot discovers SCSI devices. Previously, a scsi scan
would blindly iterate through every possible target and Logical Unit Number (LUN). In a QEMU environment, this could mean checking up to 256 targets, each with 16,384 LUNs—a time-consuming process for finding just one or two disks.
The SCSI subsystem now uses the REPORT LUNS
command. Instead of guessing, U-Boot simply asks each target which LUNs it actually has. This can dramatically speed up the scanning process and reduce unnecessary bus traffic, providing a much snappier user-experience.
Better Error Reporting and Code Quality
A key focus of this series was improving the robustness and maintainability of the SCSI and partition code.
No More Silent Failures
Have you ever tried to list partitions on a disk and received a cryptic “unsupported partition type” message, even when you knew the disk was valid? This often happened because a lower-level read error (e.g., from a bad LUN or an inaccessible disk) was silently ignored by the partition drivers.
This has now been fixed. The partition probing functions now correctly propagate I/O errors, so if a disk read fails, you will see a clear “Error reading from device” message instead of being led down a confusing diagnostic path.
Cleaning Up the Code
The core scsi_read()
and scsi_write()
functions have been thoroughly refactored. The changes make the logic much easier to follow by:
- Improving the logic for handling read/write loops
- Replacing magic numbers with proper constants and inquiry response structures
- Ensuring compliance with modern SCSI specifications, which handle LUN addressing differently
- Fixing subtle bugs, like off-by-one errors in the device scan loop
The New virtio-scsi
Driver 🚀
With these foundational improvements in place, the new virtio-scsi
driver integrates smoothly into U-Boot. It registers itself as a SCSI host, allowing the standard scsi
commands to work transparently with virtio-based disks.
To make testing and usage easier, the QEMU build scripts have also been updated to support booting from a disk attached via virtio-scsi
, allowing developers and users to immediately take advantage of this new capability.
In summary, this series is a good example of holistic development. It not only delivers a powerful new feature but also strengthens the core infrastructure it’s built upon, benefiting all users of U-Boot’s SCSI subsystem.