Difference between revisions of "U-Boot"

From krtkl wiki
Jump to navigation Jump to search
Line 131: Line 131:
$ sudo apt install u-boot-tools
$ sudo apt install u-boot-tools
Appending the utility location to the <code>$PATH</code> variable will also make it available for builds that require it.
$ export PATH=$PATH:<path to U-Boot source>/tools

Revision as of 21:08, 24 March 2018

Environment Variables

The boot modes of interest for snickerdoodle are SD card and QSPI flash. The scripted commands associated assigned to the $modeboot variables can be customized and saved to the environment region of the flash memory. U-Boot will load the default environment contained

Normally, U-Boot is configured to utilize the run-time configured environmental variable $modeboot. The default boot command executes

run $modeboot

The default environment in the U-Boot source by defining the CONFIG_EXTRA_ENV_SETTINGS in the board configuration header file.


A text file that utilizes the scripting capabilities of U-Boot can be wrapped with a U-Boot header and used to load and boot system components. A boot script can, and should, utilize the environment variables to determine filenames, memory addresses and boot mode.

if test -e mmc 0 ${bitstream_image}; then
  echo Loading bitstream from ${bitstream_image}.
  fatload mmc 0 ${loadbit_addr} ${bitstream_image} && fpga loadb 0 ${loadbit_addr} ${filesize};
  echo No bitstream present. Bitstream will not be loaded.

if test -e mmc 0 ${kernel_image}; then
  fatload mmc 0 ${kernel_load_address} ${kernel_image};
  fatload mmc 0 ${devicetree_load_address} ${devicetree_image};
  bootm ${kernel_load_address} - ${devicetree_load_address}; fi

Build Script Image

The boot script needs to be wrapped in a U-Boot header by the MkImage utility (compiled along with U-Boot or in the u-boot-tools package. After wrapping the script in a U-Boot header, the resulting script image can be loaded into memory and then run by U-Boot with the source command. The following command will generate a boot script image named bootscr.img from the text file bootscr.txt:

$ mkimage -T script -c none -n 'Boot Script' -d bootscr.txt bootscr.img

The U-Boot header that is attached by MkImage allows for the script to be named using the -n optional argument. The -T and -c options specify the image type as a script and the compression as none, respectively.

Run Script

To run the script, the script image should be loaded into memory with the load command. The memory start address where the script image is loaded is then passed to the source command to begin execution.

snickerdoodle> load mmc 0:1 ${script_address} ${script_name} && source ${script_address}

microSD Boot

The default boot configuration points the Zynq BootROM to execute from the SD card interface. The BootROM will load the binary image with the boot.bin filename from a FAT formatted partition at 1MB offset from the head of the SD card.


In the default U-Boot environment, the SD $modeboot attempts to locate and load environment data from a text file. The filename specified by the bootenv variable is loaded into memory and then the contained environment is imported. The file is expected to be located in the FAT boot partition from which the boot image was loaded.


The standard snickerdoodle SD card image contains a 128MB FAT formatted partition containing a uEnv.txt file with extensible variable settings for booting from the SD card. After U-Boot imports the environment from uEnv.txt, the existence of the variable $uenvcmd. If the variable exists, it runs the associated command. This provides a mechanism for easily changing the boot sequence and pointing the boot command to a scripted process.

Load System Images

snickerdoodle> fatload mmc 0:1 ${kernel_load_address} ${kernel_image}
snickerdoodle> fatload mmc 0:1 ${devicetree_load_address} ${devicetree_image}

Boot without RAM Filesystem

A typical SD card partition scheme includes a Linux formatted root filesystem partition alongside the FAT boot partition. In this case, the RAM disk image can be omitted from the bootm command/

snickerdoodle> bootm ${kernel_load_address} - ${devicetree_load_address}

The root filesystem disk partition will need to be specified by the boot arguments passed to the kernel. The root parameter of the boot arguments should be set to the device file for the root filesystem disk partition. The bootargs U-Boot environment variable (if it exists) is passed to the kernel as boot arguments and will override the bootargs property of the chosen node in the device tree. The bootargs variable is set in the uEnv.txt file located in the FAT boot partition of the standard snickerdoodle SD card image.

bootargs=console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait earlyprink

Build U-Boot

Get Source

$ git clone https://github.com/krtkl/snickerdoodle-u-boot.git

Configure with Base Configuration

$ make ARCH=arm zynq_snickerdoodle_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-none-eabi-

The compiled executable binary (u-boot) is an ELF file, however it will not have the .elf extension.

$ arm-none-eabi-readelf -h u-boot
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x4000000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          3394048 (bytes into file)
  Flags:                             0x5000200, Version5 EABI, soft-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         1
  Size of section headers:           40 (bytes)
  Number of section headers:         27
  Section header string table index: 24

Copy the U-Boot binary to the directory that will be used to build the boot image

$ cp u-boot /home/boot/u-boot.elf

mkimage Utility

The mkimage utility is built along with the U-Boot executable. mkimage is used to build images that can be used with U-Boot. This includes Linux kernel, ramdisk and FIT images that are to be loaded by U-Boot.

The utility can be installed as a package on Debian-based Linux hosts, or the utility path can be added to the $PATH variable to be invoked during the Linux kernel build process.

$ sudo apt install u-boot-tools

Appending the utility location to the $PATH variable will also make it available for builds that require it.

$ export PATH=$PATH:<path to U-Boot source>/tools