The U-Boot fw-utils is a tool provided by the bootloader that contains the
fw_setenv utilities to read and write U-Boot environment variables from Linux user space.
It is supported out-of-the-box in the Yocto compatible Toradex Embedded Linux BSP, which uses the OpenEmbedded build system. Both the Reference Images for Yocto Project and TorizonCore have it available.
Information about this tool can be found in its README file, provided in the U-Boot source-code under
tools/env/README. Notice that the upstream implementation is a demonstration only, since this tool configuration depends on the specific hardware being used.
You can have a look at the OpenEmbedded (Core) article for reference, as well as the specific OpenEmbedded recipes provided in the meta-toradex-nxp and meta-toradex-tegra layers, depending on the computer on module of your choice.
The commands must be executed as root. It means that TorizonCore users must use
sudo if they are executing the commands as the default user
One can set any U-Boot environment variable from Linux user space with fw_setenv:
# fw_setenv [OPTIONS]... [VARIABLE]...
After the variables are updated, the system cannot apply them on-the-fly. You need to reboot so U-Boot can read the updated variables
# fw_setenv fdtfile 'imx6q-apalis-ixora-v1.1.dtb'
fw_setenv also supports a script file as input to change multiple U-Boot environment variables at once:
# fw_setenv --script script.txt
Script File Example
The script file syntax for changing multiple U-Boot environment variables at once from Linux user space is:
key [space] value
A couple of useful tips to write your own script:
- Lines starting with '#' are treated as comments
- Variables without values will be deleted
- Any number of spaces are allowed between key and value
- A space inside of the value is treated as part of the value itself
One can read a U-Boot environment variable from Linux user space with fw_printenv:
# fw_printenv [OPTIONS] [VARIABLE]
# fw_printenv fdtfile
or read all of them at once:
U-Boot fw-utils has options that can be used in both of its utilities such as:
-h, --help print help
-c, --config configuration file, default:/etc/fw_env.config
-n, --noheader do not repeat variable name in output
-l, --lock lock node, default:/var/lock
Since Toradex Linux BSP V2.8, one can display the source version of fw-utils with -v or --version option.
Customize fw-utils Configuration
The U-Boot fw-utils read and write the U-Boot environment variables by accessing the flash location in the partition where the U-Boot environment is stored, pointed in the configuration file /etc/fw_env.config. This file stores different information depending on the exact Toradex module's flash memory type.
One can verify the flash memory type used on the module in its datasheet. To do so, visit Toradex Products page,select your Toradex module and check its datasheet.
In the eMMC flash memory type, the U-Boot environment is stored in at the end of the first eMMC boot partition, just in front of the config block, that occupies the last sector. The fw-utils reads the block device name, device offset (config block plus U-Boot environment size ) and U-Boot environment size.
In the NAND flash memory type, it is possible to configure redundant U-Boot environment adding more than one entry in the fw-utils configuration file located at /etc/fw_env.config. Each entry must have the MTD device name, device offset, U-Boot environment size, flash sector size and number of sectors.