Reading from ISO9660 in U-Boot
Heinrich Schuchardt
xypron.glpk at gmx.de
Sat Sep 23 02:57:12 CEST 2023
On 9/23/23 00:13, Simon Glass wrote:
> Hi Heinrick & Bin,
>
> I'd like to be able to figure out in U-Boot what OS is on a USB stick.
> For example, with the Ubuntu installer, I can boot it (through grub),
> but I cannot see how to read anything useful from the USB stick that
> would indicate that it is Ubuntu, what version it is, etc.
>
> Does U-Boot need an ISO9660-filesystem driver for that? Is there any other way?
>
> With Debian I can see the actual files (linux and initrd) , so it is a
> bit easier.
>
> Regards,
> SImon
The format of the Ubuntu images depends on the architecture. Let's
assume that you relate to amd64
(https://cdimage.ubuntu.com/daily-live/current/mantic-desktop-amd64.iso).
This is a hybrid image, which can be either read as ISO 9660 or as a GPT
partitioned image. This is the gdisk output:
Number Start (sector) End (sector) Size Code Name
1 64 10049451 4.8 GiB 0700 ISO9660
2 10049452 10059487 4.9 MiB EF00 Appended2
3 10059488 10060087 300.0 KiB 0700 Gap1
You can mount partition 2 as FAT file system in Linux:
$ sudo kpartx mantic-desktop-amd64.iso -a -v
[sudo] password for zfsdt:
add map loop1p1 (252:4): 0 10049388 linear 7:1 64
add map loop1p2 (252:5): 0 10036 linear 7:1 10049452
add map loop1p3 (252:6): 0 600 linear 7:1 10059488
$ sudo mount /dev/mapper/loop1p2 /mnt
$ mount
/dev/mapper/loop1p2 on /mnt type vfat
(rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
The problem is upstream U-Boot is that the partition drivers are scanned
alphabetically: a_efi, dos, iso
If we change this to a_iso, b_efi, dos, we can read the ISO image:
=> host bind 0 /tmp/mantic-desktop-amd64.iso
=> part list host 0
Partition Map for HOST device 0 -- Partition Type: ISO
Part Start Sect x Size Type
1 3684 4 512 U-Boot
2 10049452 10036 512 U-Boot
=> ls host 0:2
EFI/
=> load host 0:2 $kernel_addr_r EFI/boot/bootx64.efi
960472 bytes read in 0 ms
Unfortunately the sandbox crashes when executing the EFI binary.
So let't try qemu-x86_64_defconfig:
qemu-system-x86_64 -m 3G -nographic -bios u-boot.rom \
-drive if=none,file=/tmp/mantic-desktop-amd64.iso,format=raw,id=VIRTIO1 \
-device virtio-blk,drive=VIRTIO1
And voilá your are in GRUB.
As it does not find the /boot directory let's go to the GRUB console:
grub> root=(cd0,gpt1)
grub> linux /casper/vmlinuz root=/dev/vda1 efi=debug console=/dev/ttyS0
grub> initrd /casper/initrd
grub> boot
EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path
I have no clue why it stops here.
Best regards
Heinrich
More information about the U-Boot
mailing list