Menu Close

Obtaining Environment Information and Modifying Environment Variables

This article talks about the commands that allow the user to obtain information about the environment and modify the environment variables.

For related subjects, please refer to the SOC Table of Contents.

Information Commands

There are three main commands regarding obtaining information, being bdinfo, version, and printenv.

bdinfo is used to display detailed information about the current board and is typically used as-is.

We can obtain information such as and starting address and size of DRAM, as well as information like start address for boot parameters and Baud rate.

version is used to check the version of U-Boot. We can see that the current version is 2018.01, and compiled on Jan 27 2021.

Finally, printenv is used to display the environment variables. Note that U-Boot also boasts the auto-fill feature, where pressing [Tab] will allow for the command to be auto-completed like in Ubuntu.


Changing Environment Variables

There are two main commands when it comes to environment variables: setenv and saveenv. setenv is mainly used for setting up or changing environment variables, and saveenv is used to save the changed environment variables to flash; this allows for U-Boot to still use the saved environment variables upon next boot-up, or else it will keep using the previous environment.

We can directly use saveenv to change the environment variable like so:

saveenv [command] [value]


saveenv [command] ‘[value 1] [value 2] … [value n]’

We can also use setenv to change the environment variables first without writing to flash:

setenv [command] [value]

and then use saveenv directly to save the change if we want to keep it:


As an example, we will be changing the bootdelay to 5 seconds from the default 4:

setenv bootdelay 5


Creating New Environment Variables

The command setenv can also be used to create new variables. The formatting is the same as changing an environment variable. For example, if we wanted to create a new environment variable named test, and set its value to “testvalue”, we would use the following command:

setenv test testvalue

After we create the new test variable, we can restart U-Boot, and use the printenv command to see the current environment variables. We can see that it correctly displays test as having the value of testvalue.



Deleting Environment Variables

In order to delete environment variables, we only need to set the variable as having a blank value. For example, if we were to delete the testvariable we just created, we would use the following command:

setenv test

After restarting U-Boot and using the printenv command, we won’t be able to find the test variable.


Posted in Textbook and Training Project

Related Articles

Leave a Reply

Your email address will not be published.

Leave the field below empty!