What is a uEnv.txt File?

Beaglebone black board






In this article, we explain what a uEnv.txt file is and its role in booting a linux kernel.

So a uEnv.txt is an important file placed in the BOOT partition of a device medium (such as an SD card or USB drive) to give certain instructions to U-Boot to explain how to load the linux kernel.

The uEnv.txt tells U-boot very importants such as where in the device medium is the linux kernel file located. This way, U-boot knows where the linux kernel file is located, so that it can load the linux kernel.

Remember that U-Boot is a third stage bootloader.

U-boot's role is to load the linux kernel, so that we can then get to our final destination, which is booting the linux kernel, which is the embedded operating system that we want to run on our device.

In order for U-boot to do this, it has to know all of the information about the linux kernel, including where it's located on the device medium and which address to load the kernel into it when it is executing the kernel.

Let's look at an example uEnv.txt file to get an idea of the information that it contains and passes to U-boot.

An example uEnv.txt file is shown below.


console=ttyO0,115200n8
ipaddr=192.168.7.2
serverip=192.168.7.1
loadaddr=0x82000000
fdtaddr=0x88000000
loadfromsd=load mmc 0:2 ${loadaddr} /boot/uImage;load mmc 0:2 ${fdtaddr} /boot/am335x-boneblack.dtb
linuxbootargs=setenv bootargs console=${console} root=/dev/mmcblk0p2 rw
uenvcmd=setenv autoload no; run loadfromsd; run linuxbootargs; bootm ${loadaddr} - ${fdtaddr}



The first line, console=ttyO0,115200n8, tells U-boot where to place place debug messages and at what baud rate.

Device ttyO0 is where U-boot will write debug messages at a baud rate of 115200.

We specify within the uEnv.txt file our ip address and our server IP address.

Next, we specify the load address for the linux kernel. This is the address that the linux kernel file is loaded into. We place this into the environment variable, loadaddr.

Next we specify the load address for the device tree binary (or device tree blob). the device tree binary is a file that contains all the hardware information for the device in use. We place this into the environment variable, fdtaddr.

We then have our next environment variable, loadfromsd.

We will break down each part of this variable now.

The first half of the variable is, load mmc 0:2 ${loadaddr} /boot/uImage

This loads the uImage (linux kernel) from the second partition of the SD card into the memory address specified at loadaddr, which is 0x82000000. The linux kernel is now stored within the eMMC memory of the board.

The second half of the variable is, load mmc 0:2 ${fdtaddr} /boot/am335x-boneblack.dtb

Now that we loaded the linux kernel into memory, we then load the dtb (device tree binary) file into memory. We load the dtb into the memory address specified at fdt, which is 0x88000000. The device tree binary explains the hardware components of a board.

We then have an environment variable, linuxbootargs, which we set equal to, setenv bootargs console=${console} root=/dev/mmcblk0p2 rw

console=${console} will print debug statements to the USB0 serial port.

root=/dev/mmcblk0p2 rw tells U-boot that the root file system is located on the second partition of the SD card.

The last line is, setenv autoload no; run loadfromsd; run linuxbootargs; bootm ${loadaddr} - ${fdtaddr}

The first part, setenv autoload no, does the following according to the U-Boot manual. If set to "no" (or any string beginning with 'n'), the rarpboot, bootp, or dhcp command performs a configuration lookup from the BOOTP/DHCP server but does not try to load any image using TFTP.

The second part, run loadfromsd, runs the command loadfromsd, which loads the linux kernel and the device tree binary file for the am335x boneblack board.

The third part, run linuxbootargs, runs the command linuxbootargs, which sends debug statements to the USB0 serial port and lets U-boot know that the root filesystem is located in the second partition of the SD card.

We then boot the linux kernel using the bootm command (boot from memory) from the load address of the linux kernel. The line, bootm ${loadaddr} - ${fdtaddr}, encompasses both the linux kernel and the device tree binary.

This is a basic uEnv.txt file.

We can also add other elements that change the functioning of U-boot.

We can allow U-Boot to automatically boot the linux kenel image without any delay. This would be done by setting the autostart attribute to "yes". By default, this attribute is "no".

On the contrary, we can increase the bootdelay, which is the time in seconds that U-boot waits before starting the automatic boot process.

So there are several more modifications that you can cause in U-boot to change its behavior or the operation of the program.

So the uEnv.txt is all about controlling the behavior of U-boot and giving U-boot the instructions it needs to locate all the files it needs.

It is the file that controls how U-boot will operate and for U-boot to correctly run the linux kernel.



Related Resources





HTML Comment Box is loading comments...