Repository navigation
rpi-u-boot-scr: load the kernel from the bootflow device - #1635
wonwondogs wants to merge 2 commits into
Conversation
|
Thanks for this! This was one of the fixes I had pending. Could clarify how are those uboot flow variables provided/defined? |
It's auto detected by uboot as the device/part on which bootscr is on. |
Yes, exactly. In the bootflow path, U-Boot's script bootmeth sets My Pi 4 image uses |
agherzan
left a comment
There was a problem hiding this comment.
Thanks once again for looking into this. A couple of small things:
- Bootflow also sets
${devtype}, so there's no need for@@BOOT_MEDIA@@in thefatload. - Could you add a fallback for when the script runs outside bootflow (a manual
source, an old custombootcmd)? Defaulting to@@BOOT_MEDIA@@and0:1would keep the old behaviour.
|
Looking a bit more into this, I think the saveenv part needs fixing too: the check looks at the boot device while the env always lives on mmc 0:1, and the saved env picks up the bootflow variables, which can go stale. Would you be able to look into this as well, or at least open a small issue so we can pick it up later? |
|
Thanks for catching this! I'll look into the environment location and the stale bootflow variables, and address them in this PR. I'll update the patch after testing the change. |
|
Thanks for the review and for catching the The script now uses the bootflow device type, number, and partition to load the kernel. When that information is unavailable, it falls back to I tested SD-only and USB-only boot, manual For the two-USB test, I changed the Linux root argument to the boot drive's PARTUUID in the FDT in RAM, because Selected serial excerpts follow. With a markerless environment containing stale USB values, a manual With two USB drives, Dell was device 0 and KIOXIA was device 1; the script bootflow then read the KIOXIA kernel: I have retained the full redacted serial logs. |
agherzan
left a comment
There was a problem hiding this comment.
So I'm thinking something simpler like:
fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
if test -n "${devtype}" -a -n "${devnum}" -a -n "${distro_bootpart}"; then
fatload ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} @@KERNEL_IMAGETYPE@@
else
fatload @@BOOT_MEDIA@@ 0:1 ${kernel_addr_r} @@KERNEL_IMAGETYPE@@
fi
if test "${devtype}" = mmc -a "${devnum}" = 0 -a "${distro_bootpart}" = 1 -a ! -e mmc 0:1 uboot.env; then
env delete devtype devnum distro_bootpart prefix
saveenv
fi
@@KERNEL_BOOTCMD@@ ${kernel_addr_r} - ${fdt_addr}
With some extra nice comments :)
Also, can you squash the commits? Unless there is a food reason to split it in multiple commits - o can't see why though.
When bootflow finds boot.scr on a USB drive other than device 0, the script still loads the kernel from BOOT_MEDIA 0:1 and can pick the wrong drive. Use devtype, devnum and distro_bootpart set by bootflow, falling back to BOOT_MEDIA 0:1 when they are not set, and update the BOOT_MEDIA documentation to match. Only create uboot.env when booting from mmc 0:1, where U-Boot keeps it, so a USB boot does not write to an inserted SD card. Delete the per-boot bootflow variables before saving. Tested on a Raspberry Pi 4: SD boot, USB boot, and kernel loading from the second of two USB drives. Signed-off-by: Keisuke Tsukuda <tkdkei@outlook.jp>
f916a67 to
f34d8ae
Compare
|
@agherzan I retested on a Pi 4: two SD boots (env saved once, without bootflow variables), USB-only, USB with an SD card lacking Old |
agherzan
left a comment
There was a problem hiding this comment.
Thanks, this looks good. No need for a separate fix for existing envs: bootflow overwrites those variables on every boot, so they only affect a manual source. There are some things we can improve but I'd leave them for another PR/commit/issue:
- The fixed env location
- The save is a snapshot of everything including the old env defaults
- fw_printenv not working on USB boot
- U-Boot reading another image's uboot.env from an inserted SD card
All these existed before and I'd look into them separately as an improvement to the environment setup.
Once again, cheers for this!
|
@agherzan |
Happy to hear. BTW, I'm currently refreshing the CI infrastructure a bit, and as soon as that lands, I'll update your branch and kick off the CI for it. |
- What I did
Fix kernel loading when another USB drive is enumerated before the boot drive. U-Boot can find
boot.scron USB device 1, while the old script loads the kernel from device 0. The script now uses the bootflow device and partition, with the previousBOOT_MEDIA 0:1behavior as a fallback when bootflow information is unavailable.- How I did it
Use
${devtype},${devnum}, and${distro_bootpart}for the kernel load when bootflow provides them. Checkuboot.envonmmc 0:1, where U-Boot stores it, rather than on the boot device. An existing environment without therpi_bootscr_envmarker may contain stale bootflow variables saved by an older script. On that migration boot, ignore those variables and save the environment once without them and with the marker. Guard the save withmmc dev 0so USB-only systems do not attempt to save to a missing SD card. Update the boot media documentation to explain the fallback and migration behavior.- Testing
Built
core-image-minimalforraspberrypi4-64withRPI_USE_U_BOOT=1. On a Pi 4, tested SD-only boot, USB-only boot without an SD card, migration with SD and USB connected, manualsourceafter reloading an environment with stale variables, and two USB drives with the boot drive enumerated as USB 1. The tested paths reached the serial login prompt. In the SD-plus-USB migration test, U-Boot started from SD,boot_targets=usbwas set in RAM, the kernel was read from USB, and Linux used the SD root filesystem.For the two-USB test,
root=/dev/sda2pointed to the other drive, so I set the boot drive's PARTUUID in the FDT in RAM. This test verifies U-Boot's kernel source selection; the PR does not change Linux root selection or claim that Pi firmware chooses the same USB drive when both are present at power-on.git diff --checkpassed.