Lab 02 U Boot
Lab 02 U Boot
Bootloader - U-Boot
Objectives: Compile and install the U-Boot bootloader, use basic
U-Boot commands, set up TFTP communication with the devel-
opment workstation.
Setup
Go to the $HOME/embedded-linux-qemu-labs/bootloader directory.
Install the qemu-system-arm package. In this lab and in the following ones, we will use a
QEMU emulated ARM Vexpress Cortex A9 board.
Configuring U-Boot
Download U-Boot v2020.04.
First apply a patch that fixes the editenv command in U-Boot:
$ cd u-boot-2020.04
$ cat ../data/vexpress_flags_reset.patch | patch -p1
Now configure U-Boot to support the ARM Vexpress Cortex A9 board (vexpress_ca9x4_
defconfig).
Get an understanding of U-Boot’s configuration and compilation steps by reading the README
file, and specifically the Building the Software section.
Basically, you need to specify the cross-compiler prefix (the part before gcc in the cross-
compiler executable name):
$ export CROSS_COMPILE=arm-linux-
Now that you have a valid initial configuration, run make menuconfig to further edit your
bootloader features:
• In the Environment submenu, we will configure U-Boot so that it stores its environment
inside a file called uboot.env in a FAT filesystem on an MMC/SD card, as our emulated
machine won’t have flash storage:
– Unset Environment in flash memory (CONFIG_ENV_IS_IN_FLASH)
– Set Environment is in a FAT filesystem (CONFIG_ENV_IS_IN_FAT)
– Set Name of the block device for the environment (CONFIG_ENV_FAT_INTERFACE):
mmc
– Device and partition for where to store the environment in FAT (CONFIG_
ENV_FAT_DEVICE_AND_PART): 0:1
The above two settings correspond to the arguments of the fatload command.
• Also add support for the editenv (CONFIG_CMD_EDITENV) and bootd (which can be ab-
breviated as boot, CONFIG_CMD_BOOTD) that are not present in the default configuration
for our board.
In recent versions of U-Boot and for some boards, you will need to have the Device Tree
compiler:
Testing U-Boot
Still in U-Boot sources, test that U-Boot works:
SD card setup
We now need to add an SD card image to the QEMU virtual machine, in particular to get
a way to store U-Boot’s environment.
In later labs, we will also use such storage for other purposes (to store the kernel and device
tree, root filesystem and other filesystems).
The commands that we are going to use will be further explained during the Block filesystems
lectures.
First, using the dd command, create a 1 GB file filled with zeros, called codesd.img:
$ cfdisk sd.img
If cfdisk asks you to Select a label type, choose dos, as we don’t really need a gpt
partition table for our labs.
In the cfdisk interface, create three primary partitions, starting from the beginning, with
the following properties:
• One partition, 64MB big, with the FAT16 partition type. Mark this partition as
bootable.
• One partition, 8 MB big4 , that will be used for the root filesystem. Due to the geometry
of the device, the partition might be larger than 8 MB, but it does not matter. Keep
the Linux type for the partition.
3 You can speed up the compiling by using the -jX option with make, where X is the number of parallel
jobs used for compiling. Twice the number of CPU cores is a good value.
4 For the needs of our system, the partition could even be much smaller, and 1 MB would be enough.
However, with the 8 GB SD cards that we use in our labs, 8 MB will be the smallest partition that cfdisk
will allow you to create.
• One partition, that fills the rest of the SD card image, that will be used for the data
filesystem. Here also, keep the Linux type for the partition.
Press Write when you are done.
We will now use the loop driver5 to emulate block devices from this image and its partitions:
Now, in the U-Boot prompt, make sure that you can set and store an environment variable:
Type reset which reboots the board, and then check that the foo variable is still set:
$ printenv foo
$ chmod +x qemu-myifup
As you can see, the host side will have the 192.168.0.1 IP address. We will use 192.168.
0.100 for the target side. Of course, use a different IP address range if this conflicts with
5 Once again, this will be properly be explained during our Block filesystems lectures.
tftp setup
Install a tftp server on your host as explained in the slides.
Back in U-Boot, run bdinfo, which will allow you to find out that RAM starts at 0x60000000.
Therefore, we will use the 0x61000000 address to test tftp.
To test the TFTP connection, put a small text file in the directory exported through TFTP
on your development workstation. Then, from U-Boot, do:
=> md 0x61000000
Rescue binary
If you have trouble generating binaries that work properly, or later make a mistake that
causes you to lose your bootloader binary, you will find a working version under data/ in
the current lab directory.