Reference Advanced 18 min read

U-Boot Commands: Bootloader for Embedded Systems

Master U-Boot bootloader commands for embedded Linux. Flash images, configure boot arguments, TFTP boot, environment variables, and troubleshooting.

OceanSoft Solutions
u-bootbootloaderembeddedlinuxarm
U-Boot>

What is U-Boot?

U-Boot (Das U-Boot) is the most widely used bootloader for embedded systems, especially ARM-based boards. It initializes hardware and boots the operating system.

Key responsibilities:

  • Hardware initialization (RAM, clocks, peripherals)
  • Loading kernel and device tree to memory
  • Passing boot arguments to the kernel
  • Providing recovery mechanisms

Basic Commands

# Get help
help
help bootm

# Print environment variables
printenv

# Print specific variable
printenv bootcmd

# Set environment variable
setenv myvar "my value"

# Save environment to flash
saveenv

# Reset the board
reset

# Show board info
bdinfo

# Show memory info
md 0x80000000 100

Environment Variables

Common Variables

# Boot command (executed automatically after bootdelay)
setenv bootcmd 'run nfsboot'

# Delay before auto-boot (seconds)
setenv bootdelay 3

# Kernel arguments
setenv bootargs 'console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait'

# IP configuration
setenv ipaddr 192.168.1.100
setenv serverip 192.168.1.50
setenv netmask 255.255.255.0
setenv gatewayip 192.168.1.1

# MAC address
setenv ethaddr 00:11:22:33:44:55

# Load addresses
setenv kernel_addr 0x82000000
setenv fdt_addr 0x83000000
setenv ramdisk_addr 0x84000000

Save and Load Environment

# Save current environment to storage
saveenv

# Load saved environment
loadenv

# Reset to default environment
env default -a
saveenv

Memory Operations

# Display memory (hex dump)
md 0x80000000 100

# Display as words (32-bit)
md.l 0x80000000 10

# Display as bytes
md.b 0x80000000 100

# Write to memory
mw 0x80000000 0xDEADBEEF

# Copy memory
cp 0x80000000 0x81000000 0x1000

# Compare memory
cmp 0x80000000 0x81000000 0x1000

# Fill memory with pattern
mtest 0x80000000 0x81000000

TFTP Boot (Network Boot)

TFTP is essential for development—load kernel and rootfs over the network.

Setup

# Configure network
setenv ipaddr 192.168.1.100
setenv serverip 192.168.1.50
setenv netmask 255.255.255.0

# Test network
ping 192.168.1.50

Load via TFTP

# Load kernel image
tftp 0x82000000 zImage

# Load device tree
tftp 0x83000000 myboard.dtb

# Load into variable address
tftp ${kernel_addr} zImage

Complete TFTP Boot Script

# Set up TFTP boot command
setenv tftpboot 'setenv bootargs console=ttyS0,115200 root=/dev/nfs nfsroot=${serverip}:/srv/nfs/rootfs,nfsvers=3 rw ip=dhcp; tftp ${kernel_addr} zImage; tftp ${fdt_addr} myboard.dtb; bootz ${kernel_addr} - ${fdt_addr}'

# Run TFTP boot
run tftpboot

SD Card / eMMC Operations

# List MMC devices
mmc list

# Select MMC device
mmc dev 0

# Show MMC info
mmc info

# Read partition table
mmc part

# Rescan for new cards
mmc rescan

Load from FAT Partition

# List files on FAT partition (device 0, partition 1)
fatls mmc 0:1

# Load file from FAT
fatload mmc 0:1 0x82000000 zImage
fatload mmc 0:1 0x83000000 myboard.dtb

Load from ext4 Partition

# List files on ext4 partition
ext4ls mmc 0:2

# Load file from ext4
ext4load mmc 0:2 0x82000000 boot/zImage

Complete SD Boot Script

# Set MMC boot command
setenv mmcboot 'setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait rw; mmc dev 0; fatload mmc 0:1 ${kernel_addr} zImage; fatload mmc 0:1 ${fdt_addr} myboard.dtb; bootz ${kernel_addr} - ${fdt_addr}'

# Save and run
saveenv
run mmcboot

NAND Flash Operations

# Show NAND info
nand info

# Read from NAND to RAM
nand read 0x82000000 0x100000 0x500000
# (dest_addr, nand_offset, size)

# Write from RAM to NAND
nand write 0x82000000 0x100000 0x500000

# Erase NAND region
nand erase 0x100000 0x500000

# Mark bad block
nand markbad 0x100000

UBI for NAND

# Attach UBI
ubi part ubi

# List UBI volumes
ubi info layout

# Load from UBI volume
ubi read 0x82000000 kernel

# Write to UBI volume
ubi write 0x82000000 kernel ${filesize}

Flashing Firmware

Flash Kernel via TFTP + NAND

# Download kernel
tftp 0x82000000 zImage

# Erase kernel partition
nand erase 0x100000 0x500000

# Write kernel to NAND
nand write 0x82000000 0x100000 ${filesize}

Flash UBI Image

# Download UBI image
tftp 0x82000000 rootfs.ubi

# Erase rootfs partition
nand erase 0x600000 0x1FA00000

# Flash UBI
nand write.trimffs 0x82000000 0x600000 ${filesize}

# Or for UBI update:
ubi part ubi
ubi write 0x82000000 rootfs ${filesize}

Flash eMMC

# Download image
tftp 0x82000000 sdcard.img

# Write to eMMC (raw)
mmc dev 0
mmc write 0x82000000 0 ${filesize}

Boot Commands

# Boot zImage (ARM)
bootz ${kernel_addr} - ${fdt_addr}

# Boot uImage (legacy)
bootm ${kernel_addr} - ${fdt_addr}

# Boot with ramdisk
bootz ${kernel_addr} ${ramdisk_addr} ${fdt_addr}

# Boot from command line
boot

# Boot from specific source
run mmcboot
run nfsboot
run tftpboot

Boot Scripts

# Create multi-line boot script
setenv nfsboot 'setenv bootargs console=ttyS0,115200 root=/dev/nfs nfsroot=${serverip}:/srv/nfs/rootfs,nfsvers=3,tcp rw ip=${ipaddr}::${gatewayip}:${netmask}::eth0:off; tftp ${kernel_addr} zImage; tftp ${fdt_addr} am335x-board.dtb; bootz ${kernel_addr} - ${fdt_addr}'

# Set as default boot command
setenv bootcmd 'run nfsboot'
saveenv

# Run a saved script
run nfsboot

Fallback Boot Logic

# Try SD first, fall back to NAND
setenv bootcmd 'if mmc dev 0; then run mmcboot; else run nandboot; fi'
saveenv

Debugging

# Show version
version

# Show board info
bdinfo

# Show clock configuration
clk dump

# Test memory
mtest 0x80000000 0x81000000

# Check CRC of loaded image
crc32 0x82000000 ${filesize}

# Verify image header
iminfo 0x82000000

# Read device tree info
fdt addr 0x83000000
fdt print

Debug GPIO/Registers

# Read hardware register
md.l 0x44E07000 1

# Write hardware register
mw.l 0x44E07000 0x00000001

# GPIO operations (if supported)
gpio status
gpio set 10
gpio clear 10

Recovery Scenarios

Boot Stops at U-Boot

# Check bootargs
printenv bootargs

# Check bootcmd
printenv bootcmd

# Manually boot
tftp 0x82000000 zImage
tftp 0x83000000 board.dtb
setenv bootargs 'console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait'
bootz 0x82000000 - 0x83000000

Reset to Defaults

# Reset environment to defaults
env default -a

# Save defaults
saveenv

# Or don't save - just boot with defaults this once

Quick Reference

Task Command
Print all variables printenv
Set variable setenv name value
Save environment saveenv
Load via TFTP tftp addr filename
Load from SD (FAT) fatload mmc 0:1 addr file
Boot zImage bootz kernel - dtb
Erase NAND nand erase offset size
Write NAND nand write addr offset size
Reset board reset

Resources

Need help with embedded systems development? Contact us for consulting.