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. 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.
One can set any U-Boot environment variable from Linux user space with fw_setenv:
root@apalis-imx6:~# 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
root@apalis-imx6:~# fw_setenv fdt_file 'imx6q-apalis-ixora-v1.1.dtb'
fw_setenv also supports a script file as input to change multiple U-Boot environment variables at once:
root@apalis-imx6:~# 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:
vidargs 'video=mxcfb0:dev=hdmi,1920x1080M@60,if=RGB24' fdt_file 'imx6q-apalis-ixora.dtb'
One can read a U-Boot environment variable from Linux user space with fw_printenv:
root@apalis-imx6:~# fw_printenv [OPTIONS] [VARIABLE]
root@apalis-imx6:~# fw_printenv fdt_file fdt_file=imx6q-apalis-ixora-v1.1.dtb
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
Note: Since Toradex Linux BSP V2.8, one can display the source version of fw-utils with -v or --version option.
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.
Note: 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.