This is definitely possible.
By default u-boot performs run distro_bootcmd
on boot. This is defined at compile-time by the CONFIG_BOOTCOMMAND
variable.
I can simply set my own CONFIG_BOOTCOMMAND and compile u-boot:
cat <<EOF >> include/configs/rpi.h
#define CONFIG_BOOTCOMMAND \\
"setenv autoload no;" \\
"setenv autostart no;" \\
"bootp;" \\
"tftp 0x100000 /rpi/boot.scr;" \\
"source 0x100000;"
EOF
make rpi_3_32b_defconfig
make all
This is the quick'n'dirty way. Digging a bit deeper I found that distro_bootcmd
should already do what I need.
The command's behaviour is controlled by the variable BOOT_TARGET_DEVICES
at compile time. For instance for the rpi it's at include/configs/rpi.h
:
#define BOOT_TARGET_DEVICES(func) \
func(MMC, mmc, 0) \
func(USB, usb, 0) \
func(PXE, pxe, na) \
func(DHCP, dhcp, na)
The PXE target looks for an extlinux config file the same way pxelinux does, so by placing a config file in pxelinux.cfg/default-arm
I can instruct u-boot to load a kernel and initrd, or do something else.
The DHCP target seems to try to load the file provided by the dhcp server, or a default <IP>.img
if none was specified. (<IP>
is the ip address in hex).
So loading u-boot.img with no sdcard/msd present (or with no boot.scr or boot.scr.uimg in / or /boot) should trigger the DHCP and PXE boot right out of the box.
I'm not sure why this wasn't working for me, probably a network setup issue or a bad u-boot image. Haven't had a chance to play with the pi again yet.
BTW, u-boot docs are awesome. I don't think I've come accross such good documentation in the past.