hexdump0815 / u-boot-misc

notes on building, preparing and installing u-boot for allwinner, rockchip, amlogic, exynos arm socs ...
50 stars 17 forks source link

boot_targets priority #5

Closed cattyhouse closed 2 years ago

cattyhouse commented 2 years ago

strings ~/Downloads/gxl-u-boot.bin | grep boot_targets

boot_targets=romusb mmc0 mmc1 mmc2 usb0 pxe dhcp
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done

sometimes we need to boot from usb (ssd type usb for faster IO), right now i used a hex editor to change it to

boot_targets=usb0 romusb mmc0 mmc1 mmc2 pxe dhcp

which worked as expected.

but when there are 2 usb attached at the same time, the chance that our bootable usb got boot is 50% ... is it possible to define the boot_targets like this:

boot_targets=usb0 usb1 usb2 usb3 romusb mmc0 mmc1 mmc2 pxe dhcp

# and
bootcmd_usb0=devnum=0; run usb_boot # this one is already defined in the binary
bootcmd_usb1=devnum=1; run usb_boot
bootcmd_usb2=devnum=2; run usb_boot
bootcmd_usb3=devnum=3; run usb_boot

s905d here.

cattyhouse commented 2 years ago

problem fixed

hexedit u-boot.ext

  1. change bootcmd_mmc0=devnum=0; run mmc_boot to bootcmd_usb1=devnum=1; run usb_boot

and change boot_targets to boot_targets=usb0 usb1 romusb mmc0 mmc1 mmc2 pxe

no bits added or removed, this is acceptable by binary edit. since i don't need mmc0 which is sd card, this is doable.

  1. add 2 lines to s905_autoscript
if fatload usb 0 0x1000000 u-boot.ext; then go 0x1000000; fi;
if fatload usb 1 0x1000000 u-boot.ext; then go 0x1000000; fi;
hexdump0815 commented 2 years ago

@cattyhouse - thanks a lot for sharing what you found out - for what setup is this: u-boot on sd card or u-boot on emmc? maybe i should add some notes about this to the readme ...

cattyhouse commented 2 years ago

@cattyhouse - thanks a lot for sharing what you found out - for what setup is this: u-boot on sd card or u-boot on emmc? maybe i should add some notes about this to the readme ...

on my box, there is no SD card reader. it is just 2 USB 2.0 ports and an internal 8GB emmc.

it depends on the printenv output, on my box, the embedded u-boot 2015 looks for s905_autoscript for USB, emmc_autoscript for emmc, and mmc_autoscript for SD (which always fail because my box does not have a SD Card), sudo fw_printenv | grep start_autoscript

bootcmd=run start_autoscript; run storeboot
start_autoscript=if mmcinfo; then run start_mmc_autoscript; fi; if usb start; then run start_usb_autoscript; fi; run start_emmc_autoscript
boot_targets=usb0 usb1 romusb mmc0 mmc1 mmc2 pxe
bootcmd_usb1=devnum=1; run usb_boot
bootcmd_usb0=devnum=0; run usb_boot

the u-boot.ext and u-boot.emmc are identical binary with a different file name. i keep u-boot.emmc untouched, but hexedit that u-boot.ext to what mentioned above.

so, now the boot is like this

embedded u-boot 2015 -> look for USB first -> look for s905_autoscript on USB -> load u-boot.ext on USB0 -> if fail, load u-boot.ext on USB1 -> u-boot.ext try boot_targets=usb0 usb1 romusb mmc0 mmc1 mmc2 pxe in order...

if embedded u-boot 2015 failed to boot from USB, it looks for emmc, then looks for emmc_autoscript, then load u-boot.emmc ...