
Recall first from The flash layout and U-Boot basics
- A boot SD card uses GPT partitions found by name: fsbl1 and fsbl2 for TF-A BL2, fip for the FIP with U-Boot, and a bootable root partition
- version, help and printenv only read state; setenv, saveenv and reset change it
- setenv edits the environment in RAM, and only saveenv copies it to the environment storage so it survives reset
Reading the card and loading a kernel
3 min readThe U-Boot prompt is not just for inspecting; it is where you boot the system. This lesson answers mmc, fatload, ext4load, bootm and bootz, booting from a partition, and the DFU and UART recovery modes.
The previous lesson gave you the flash layout and a prompt. The first family of commands you need there is the U-Boot command group for SD cards and eMMC devices. mmc list shows the storage controllers U-Boot knows about, mmc dev 0 selects one as current, mmc info prints the selected device's capacity and bus settings, and mmc part lists its partitions with their numbers, types and sizes. If you swap the card while powered, mmc rescan makes U-Boot look again. On many STM32MP1 boards the SD card is device 0 and the eMMC (when the board has one) is device 1, but confirm with mmc list rather than assuming.
Every load command names its source as device:partition, for example mmc 0:1 for the first partition of the first card. Partition numbers start at 1 and come from the layout you saw in the previous lesson. Before loading anything, look at what is actually there:
mmc dev 0
mmc part
fatls mmc 0:1
fatls lists a FAT partition; ext4ls does the same for ext4. On many images the boot partition is FAT and holds the kernel image, the device tree blob and sometimes an initramfs, which is why fatload is a command you will type often; the minimal card in U-Boot's STM32MP1 documentation instead has a bootable root partition with an extlinux.conf (generic distro boot), so check with fatls or ext4ls which one your card uses.
Loading is a copy into RAM:
fatload mmc 0:1 ${kernel_addr_r} uImage
fatload mmc 0:1 ${fdt_addr_r} stm32mp157c-dk2.dtb
The syntax is fatload <interface> <dev:part> <addr> <filename>. The address is a RAM address, and ${kernel_addr_r} is an environment variable that the board's default configuration sets to a region known to be safe: far from U-Boot's own code and stack. The environment deserves its own lesson (the next one); for now treat kernel_addr_r and fdt_addr_r as pre-agreed parking spots. ext4load works identically but reads ext4 and takes an absolute path inside the filesystem:
ext4load mmc 0:2 ${kernel_addr_r} /boot/zImage
A successful load reports how many bytes were read; the exact count and timing on your board will differ from anyone else's. If the file is missing or the partition number is wrong, the command fails and nothing is loaded, so check fatls output before blaming the kernel.
Select the device:
mmc dev 0, thenmmc partto confirm the partition numbers.Find the files:
fatls mmc 0:1and note the exact kernel and .dtb file names.Load the kernel:
fatload mmc 0:1 ${kernel_addr_r} uImage.Load the device tree:
fatload mmc 0:1 ${fdt_addr_r} <yourboard>.dtb.Set the command line:
setenv bootargs console=ttySTM0,115200 root=/dev/mmcblk0p5 rootwait(your root partition number comes from your layout).Start it:
bootm ${kernel_addr_r} - ${fdt_addr_r}.
bootm, bootz and the boot command
3 min readA a kernel image wrapped by mkimage with a 64-byte U-Boot header naming its type, load address, entry point and checksums is the legacy U-Boot format. bootm reads that header, verifies the checksum, and only then jumps to the entry point. A the raw self-decompressing compressed kernel produced by the ARM32 kernel build, with no U-Boot header has no such header, so it needs bootz, which knows the zImage convention directly. On AArch64 the plain Image is started with booti. The kernel build and its image formats get a full session later; here you only need to pick the command that matches the file you loaded. FIT images, which bundle kernel, device tree and hashes into one file, come in a later lesson and are also started with bootm.
The full form is bootm <kernel_addr> [initrd] [fdt_addr]. The middle argument is the initramfs address; a single - means "no initramfs" and lets you pass the device tree as the third argument:
bootm ${kernel_addr_r} - ${fdt_addr_r}
bootz and booti take the same three arguments. The kernel gets its command line from the bootargs environment variable, not from anything you type after bootm. The parameters that matter first are console= (on STM32MP1 the serial console is ttySTM0, so console=ttySTM0,115200), root= (which block device holds the root filesystem, for example /dev/mmcblk0p5) and rootwait (tell the kernel to wait for the card to appear instead of panicking early). How U-Boot hands the device tree to the kernel is covered in its own later lesson.
You rarely want to type all of this on every power-up. The boot command simply runs the bootcmd environment variable, and autoboot does the same thing automatically after bootdelay seconds unless you press a key. That is the whole relationship: boot, autoboot and bootcmd are one mechanism, and a manual boot is you doing by hand what bootcmd would have done.
Failures at this stage are readable if you know the three classic messages. The wording of the first message depends on the U-Boot version. In the U-Boot source of this review (boot/bootm.c, a recent master), a file that is neither a legacy uImage nor a FIT makes bootm print Wrong Image Type for bootm command followed by ERROR <number>E: can't get kernel image!, while the text Bad Magic Number is printed when a legacy-format header fails its magic check (for example a bad initramfs header) and by older U-Boot versions. Either way the meaning is that the bytes at that address are not a uImage: usually you ran bootm on a zImage (use bootz) or the load silently failed. A board that prints Starting kernel ... and then goes silent usually has a wrong console= value or a mismatched device tree: the kernel may be running with its output going nowhere. And VFS: Unable to mount root fs is a kernel panic meaning root= points at a partition that does not exist or does not hold a filesystem. Each message tells you which of the three inputs (image, command line, device tree) to fix.
Boot sources and recovery: DFU and UART
4 min readEverything above assumes you reached the prompt. When you cannot, remember who is in charge: the ROM code samples the boot configuration pins (the GPIO boot pins lesson covered the mechanism) and tries boot sources in the order those pins select. On STM32MP1 the pins choose between flash sources (SD, eMMC, NAND, NOR) and serial boot; on BeagleBone Black the boot button changes the order so the SD card is tried before the eMMC, which is the standard way to rescue a board with a broken eMMC image. Recovery always means steering an earlier stage of the chain to load something known-good.
The first recovery tool is Device Firmware Upgrade, a standard USB class for transferring firmware to (and from) a device. It appears twice in this boot chain. U-Boot itself can act as a DFU device: the command dfu 0 mmc 0 starts a DFU session on USB controller 0 over the mmc backend: the entities the host sees are the ones listed in the dfu_alt_info variable (U-Boot's DFU documentation: the dfu command uses dfu_alt_info to configure the alternates). On your Ubuntu 24.04 host, dfu-util -l then lists the exposed partitions as DFU "alternates", and dfu-util -a <name> -D <file> writes a file to one of them. This is how you repair a corrupted boot partition without pulling the card out. ST's STM32CubeProgrammer uses the same mechanism with a friendlier interface.
The second appearance is deeper: when the boot pins select serial boot, the ROM itself enumerates as a USB DFU device (or listens on a UART), before any of your software exists. STM32CubeProgrammer, which runs on Linux, can then push TF-A and U-Boot into RAM and reflash the board from completely empty or corrupted storage. UART boot is the same idea over the serial line: slower, but it works when USB is not wired or not working, which is why board bring-up engineers care about it. This is the recovery of last resort, and it is guaranteed by mask ROM: no software mistake you make can remove it.
dfu-util -l only lists and is safe to run any time. dfu-util -a <name> -D <file> overwrites that partition, and pointing it at the wrong alternate can erase your bootloader. Confirm the alternate list first, and keep a known-good card image before experimenting.
The practical ladder, from cheapest to deepest: press a key to stop autoboot and boot manually with fatload and bootm; if the files themselves are bad, reflash the partition through U-Boot's dfu command; if U-Boot never reaches its banner, change the boot pins to serial boot and reflash over USB or UART through the ROM. Each rung needs less working software than the one above it.
Typing this sequence at every power-up gets old fast, and one typo in bootargs costs you a reboot. The next lesson, "The U-Boot environment and its commands", shows how these variables are stored, edited and made persistent, so your working sequence becomes the board's automatic boot.
Key takeaways
- fatload and ext4load copy a file from an mmc device:partition into RAM; bootm starts a uImage, bootz a zImage, booti an arm64 Image
- bootm takes kernel address, optional initrd (a dash means none), then the device tree address
- The boot command simply runs the bootcmd environment variable, which is what autoboot executes after bootdelay seconds
- When U-Boot itself is broken, the boot pins steer the ROM to serial boot over USB (DFU) or UART so the board can be reflashed
Reflect
- Explain to a colleague, in two sentences: inspect SD and eMMC partitions from U-Boot with mmc list, mmc dev and mmc part
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Kernel docsKernel parameters: console, root and rootwait
- Kernel docsBooting ARM Linux: the kernel entry contract
- Man pageboot(7): overview of the boot process
Official documentation first. Links checked when the lesson was published.