U-Boot Distro Boot

Tags: linux u-boot embedded

U-Boot offers a "distro boot" function that allows the user to specify how U-Boot should boot the device. This allows support for a large multitude of different devices and boot modes.

Distro boot is the default bootcmd in U-Boot. Distro boot will iterate through a series of "boot targets" (typically an SD card, SPI flash, NAND flash, USB, etc.) and look for any one of a set of valid file names (boot.scr and boot.scr.uimg by default) within a set of directories (/ and /boot by default). If it finds this file, it will source it. The contents of that file should then instruct U-Boot how to actually boot the device.

If U-Boot can't find the boot.scr script on any of the boot targets it will then try to run PXE boot. It will attempt to get a DHCP address from a server on the network and then try to download pxelinux.cfg/default from the connected TFTP server (this requires working DHCP and TFTP servers on the host machine). The pxelinux.cfg/default file also instructs U-Boot how to boot. The file format is documented here. A short example is

label Linux
kernel Image
fdt system.dtb

This will download the Linux kernel image file called Image and the flattened device tree (FDT) file system.dtb via TFTP into memory and then boot with bootm.