Pi3 USB boot support

Ah, yes, it uses /boot/uboot.env to store the environment rather than the free space before the boot partition which I think is the default. It’s been a while since I’ve played with this, so I’m a bit rusty.

well it was not the storage interface, will continue digging tomorrow. I’ve double-confirmed, just to be sure, that without the mender patch u-boot does find usb. I’ll compare your patch properly tomorrow.

Sorry it wasn’t an easy fix. Let me know if I can help.

As suggested i’ve isolated what makes it fail usb. After reapplying every bit of the diff one by one and checking the boot, it happens that these are the lines that make it fail:

CONFIG_ENV_IS_IN_MMC=y
CONFIG_ENV_OFFSET=0x400000
CONFIG_ENV_OFFSET_REDUND=0x800000

@stiltr maybe that was why you’ve moved it away? i’m going to check how you did it, if you have any advice about it don’t hesitate

Does the u-boot build come preloaded with some env it writes at start if it can’t read it? Maybe that env states something that is incompatible with loading usb?

EDIT: When these exports are not defined, the generated .config file defaults to

CONFIG_ENV_IS_IN_FAT=y

is that sufficient to get mender working ?

We’re getting closer ! any idea? the files are present.

U-Boot 2021.07-rc2-00175-g7a1638c263-dirty (May 19 2021 - 23:52:56 +0200)

DRAM:  7.9 GiB
RPI 4 Model B (0xd03114)
MMC:   mmcnr@7e300000: 1, emmc2@7e340000: 0
Loading Environment from FAT... In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 5 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
Hit any key to stop autoboot:  0 
Saving Environment to FAT... OK
Failed to load '/boot/bcm2711-rpi-4-b.dtb'
Failed to load '/boot/kernel7l.img'
Wrong Image Format for bootm command
ERROR: can't get kernel image!
U-Boot> 
#define MENDER_BOOT_KERNEL_TYPE "bootm"
#define MENDER_KERNEL_NAME "kernel7l.img"
#define MENDER_DTB_NAME "bcm2711-rpi-4-b.dtb"
-rwxr-xr-x. 1 root root   49218 18 mai   23:17 bcm2711-rpi-4-b.dtb
-rwxr-xr-x. 1 root root 6886671  7 janv. 16:53 kernel7l.img
/mnt/kernel7l.img: COM executable for DOS

Nice! I believe you want booti. Also, I’m guessing you need to remove “/boot” from the kernel/dtb paths. I skipped loading the dtb in u-boot in favor of letting the firmware handle it and the necessary overlays.

1 Like

removed it from here, but still:

U-Boot 2021.07-rc2-00175-g7a1638c263-dirty (May 20 2021 - 00:09:44 +0200)

DRAM:  7.9 GiB
RPI 4 Model B (0xd03114)
MMC:   mmcnr@7e300000: 1, emmc2@7e340000: 0
Loading Environment from FAT... In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 5 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
Hit any key to stop autoboot:  0 
Saving Environment to FAT... OK
Failed to load 'bcm2711-rpi-4-b.dtb'
Failed to load 'kernel7.img'
Unknown command 'booti' - try 'help'
U-Boot> 

actually i think it’s loading from the wrong device or i messed something up

I forget what the default mender paths are since I’ve kind of gone my own direction with those, but I think it’s trying to load it from /boot/ on the “root” partition. I’m guessing you have the files on the fat partition, so you’ll need to set it to use that device and path. Probably something like:
load ${mender_uboot_boot} ${kernel_addr_r} /${mender_kernel_name};
Oh, the booti command is for arm64 images, so you’re probably right to use bootm. Sorry about that.

Edit:
You can also press a key to disable autoboot and manually test it from the CLI. Just typing load usb 0:1 ${kernel_addr_r} /kernel7.img should let you know if you’re on the right track. If it loads, you should be able to type bootm ${kernel_addr_r} - ${fdt_addr} to try and boot.

as expected i’m starting to be tired of the day and the files were not in place. Now that they are, there really seems to be a problem of format of the kernel, as suggested in this guide. Will try this conversion tomorrow. Thanks for your help!

U-Boot 2021.07-rc2-00175-g7a1638c263-dirty (May 20 2021 - 00:27:13 +0200)

DRAM:  7.9 GiB
RPI 4 Model B (0xd03114)
MMC:   mmcnr@7e300000: 1, emmc2@7e340000: 0
Loading Environment from FAT... In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 5 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
Hit any key to stop autoboot:  0 
Saving Environment to FAT... OK
49090 bytes read in 1 ms (46.8 MiB/s)
6694528 bytes read in 25 ms (255.4 MiB/s)
Wrong Image Format for bootm command
ERROR: can't get kernel image!
U-Boot> load usb 0:2 $kernel_addr_r /boot/kernel7l.img
6694528 bytes read in 24 ms (266 MiB/s)
U-Boot> bootm $kernel_addr_r - $fdt_addr
Wrong Image Format for bootm command
ERROR: can't get kernel image!
U-Boot> 

No worries. I’ve not tried u-boot with a 32-bit kernel, so I probably won’t be much help. That mkimage command does look familiar though. You can try running iminfo ${kernel_addr_r} in u-boot and see if it gives you any useful information about the kernel’s format.

well i did not resist to still try it. IT BOOTS. The rapspberry is set to boot from USB in eeprom, so it’s a full usb boot, no sd card inserted. :tada:

Now the kernel does kernel panic. It says

not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

On this volume i’ve only replaced the boot partition with what we’ve just built, the rest is raspios which was already booting usb using raspios’ own bootloader. Any ideas ?

EDIT: will recheck tomorrow on a fresh mind, as i don’t have the required partition scheme, that’s likely to make it fail if i don’t have a /data partition. Thanks again!

1 Like

Great news! It looks like it’s probably not setting the bootargs properly. Specifically the root=/dev/sda2 line. In my setup I’m taking the bootargs passed along from the firmware (which sources config.txt/cmdline.txt) and then modifying the root= part based on the mender logic. I’m not sure how it handles that in the default configuration, but if nothing else you could manually modify it in u-boot before running the bootm command. It should still boot ok without the /data partition. Mender won’t work properly, but mender isn’t even installed on the default raspbian image anyway. One thing I had an issue with, was that it wasn’t loading the u-boot environment automatically, since usb isn’t started until later. So I had to add it to the preboot cmd. After that it worked fine. Anyway, have a good night!

my cmdline.txt in sda2’s /boot has:

root=${mender_kernel_root}

how can i debug if that’s getting properly replaced ?

EDIT: i’ve tried to move cmdline.txt in sda1, and get the same result even when using root=/dev/sda2 directly. Overall, what exactly should be in sda1 (/uboot) and sda2 (/boot) ?

Hi @peac, I’m not sure that the RpI with Mender uses the cmdline.txt file. I think it is all processed by the u-boot boot script, boot.scr. You may want to investigate that as the next troubleshooting step.

Overall, sda1 should be the original boot directory contents. I think when Mender is enabled it is mounted at /uboot and copied to /boot in the actual root filesystem. sda2 should be your root filesystem A.

Drew

i can properly set the boot command line for the kernel from u-boot’s prompt, using

setenv bootargs 'key=value'

It does not seem to be defined (env print -a does not show a bootargs entry) prior to doing it manually for now. Using an empty string or 'logo.nologo' does provide the same result or the same result without the raspberries indicating the number of cores during bootlog before panic, which shows that by default there’s no argument and they can be added properly with this method, without impacting current behavior.

Using console=serial0,115200 or any variation using ttyAMA0 does NOT output the kernel log before the panic to the UART connection, so i cannot really get prior information. Moreover, doing so completely removes the log from the screen too, for instance only raspberries appear with a black screen.

Using root=/dev/sda2 rootfstype=ext4 also results in a black screen without logging.

What should be the correct cmdline, and where should be inserted to be persistant?

I think you will need to create a custom boot.scr file. You can see how that is done for another RpI variant here.

This looks quite similar to what i have in my boot.scr:

fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
run mender_setup
mmc dev ${mender_uboot_dev}
if load ${mender_uboot_root} ${kernel_addr_r} /boot/zImage; then
    bootz ${kernel_addr_r} - ${fdt_addr}
elif load ${mender_uboot_root} ${kernel_addr_r} /boot/uImage; then
    bootm ${kernel_addr_r} - ${fdt_addr}
else
    echo "No bootable Kernel found."
fi
run mender_try_to_recover

# Recompile with:
# mkimage -C none -A arm -T script -d boot.cmd boot.scr

What i’m really looking for is the boot command for the kernel, not the boot script for u-boot. In case that can be relevant, here’s the last log i get before kernel handoff and no more serial input:

U-Boot 2021.07-rc2-00175-g7a1638c263-dirty (May 20 2021 - 00:43:37 +0200)

DRAM:  7.9 GiB
RPI 4 Model B (0xd03114)
MMC:   mmcnr@7e300000: 1, emmc2@7e340000: 0
Loading Environment from FAT... In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 5 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
Hit any key to stop autoboot:  0 
Saving Environment to FAT... OK
49090 bytes read in 1 ms (46.8 MiB/s)
6694592 bytes read in 25 ms (255.4 MiB/s)
## Booting kernel from Legacy Image at 00080000 ...
   Image Name:   Linux kernel
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    6694528 Bytes = 6.4 MiB
   Load Address: 00008000
   Entry Point:  00008000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 02600000
   Booting using the fdt blob at 0x2600000
   Loading Kernel Image
   Using Device Tree in place at 02600000, end 0260efc1

Starting kernel ...

The boot script for U-Boot is what defines the boot cmd for the kernel. If you need to modify the bootargs you can do so in the boot script before it calls boot*. The run mender_setup line should set the values for that. You can always run it by hand to see what it ends up with and how it will need to be modified.

Drew

rootwait was the missing parameter, it’s not even documented on the official raspi docs

Hit any key to stop autoboot:  0 
U-Boot> setenv bootargs 'root=/dev/sda2 rootfstype=ext4 rootwait'                  
U-Boot> boot

Thanks for your help !! I’ll try to post a final working patch for usb boot when i get some free time