XELK-AN-006: Modify u-boot environment from userspace
Info Box
|
![]() |
This application note was validated against specific versions of the kit only. It may not work with other versions. Supported versions are listed in the History section. | ![]() |
Contents
History[edit | edit source]
Version | Date | Notes |
---|---|---|
1.0.0 | June 2019 | First release |
Introduction[edit | edit source]
Axel family system-on-modules (SOM for short) are based on u-boot and linux BSP which is configured - at boot time - using the u-boot environment variables configuration.
Many times, it should ve very useful to modify the u-boot environment from linux userspace access. This is possible using the fw_printenv
and fw_setenv
utilities present on u-boot source codes.
Tools required[edit | edit source]
In order to modify the uboot environment variables from userspace the fw_printenv
has to be compiled from the u-boot sources: this is possible using the
make env
command on u-boot source code tree
Once built, the second utility fw_setenv
is just a copy of the built one: the tool itself, uses the recognized file name for identifying if accessing in print or set mode the u-boot environment.
Configuration file[edit | edit source]
fw_printenv uses the /etc/fw_env.config
configuration file for identifying the correct parameters to access the storage device where the u-boot environment is memorized.
Please find below an example on how to identify the u-boot storage device and its configuration:
MTDs[edit | edit source]
Using the
cat /proc/mtd
command, it is possible to see the memory partitioning and where the environment parts are:
root@imx6qxelk:~# cat /proc/mtd dev: size erasesize name mtd0: 00800000 00020000 "nand-uboot" mtd1: 00100000 00020000 "nand-env1" mtd2: 00100000 00020000 "nand-env2" mtd3: 00100000 00020000 "nand-fdt" mtd4: 00100000 00020000 "nand-spare" mtd5: 00800000 00020000 "nand-kernel" mtd6: 00400000 00020000 "nand-splash" mtd7: 3e800000 00020000 "nand-ubi" root@imx6qxelk:~#
So, in this example we can see that the two mtd parts to be used are
mtd1: 00100000 00020000 "nand-env1" mtd2: 00100000 00020000 "nand-env2"
Sizes[edit | edit source]
The two parameters required for properly configuring the fw_env.config
file are:
- Env. size
- Flash sector size
Those values are identifyed at compile time into the proper header file used for building u-boot. On AxelLite family this file is include/configs/mx6axel.h
and the parameters should be found according to the storage device used.
For example, if the boot storage device is a NAND memory, the config var is:
CONFIG_ENV_IS_IN_NAND
and the related section (for the environment sizes) is:
#elif defined(CONFIG_ENV_IS_IN_NAND) #undef CONFIG_ENV_SIZE #define CONFIG_ENV_OFFSET (8 * 1024 * 1024) #define CONFIG_ENV_SECT_SIZE (1 * 1024 * 1024) #define CONFIG_ENV_SIZE (128 * 1024)
So, we found that the proper parameters are:
- Env. size: 0x20000
- Flash sector size: 0x100000
fw_env.config[edit | edit source]
Following the configuration information found before, we can set the proper parameters into the fw_env.config
file as shown below:
root@imx6qxelk:~# cat /etc/fw_env.config # Configuration file for fw_(printenv/setenv) utility. # Up to two entries are valid, in this case the redundant # environment sector is assumed present. # Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash. # Futhermore, if the Flash sector size is ommitted, this value is assumed to # be the same as the Environment size, which is valid for NOR and SPI-dataflash # NOR example # MTD device name Device offset Env. size Flash sector size Number of sectors /dev/mtd1 0x0000 0x20000 0x100000 /dev/mtd2 0x0000 0x20000 0x100000 root@imx6qxelk:~#
u-boot environment access example[edit | edit source]
- display the
ipaddr
andbootfile
environment variables:
root@imx6qxelk:~# fw_printenv ipaddr bootfile ipaddr=192.168.0.90 bootfile=axel/linux/xelk-3.0.7_uImage root@imx6qxelk:~#
Wrong configuration file[edit | edit source]
If some parameters are not correctly configured on the fw_env.config file, the utilities displays an error message:
Warning: Bad CRC, using default environment
It is possible to detect this situation using the return code of fw_printenv
:
- fw_env.config correct file
root@imx6qxelk:~# fw_printenv ipaddr ipaddr=192.168.0.90 root@imx6qxelk:~# echo $? 0 root@imx6qxelk:~#
- wrong fw_env.config file
root@imx6qxelk:~# fw_printenv ipaddr Warning: Bad CRC, using default environment ## Error: "ipaddr" not defined root@imx6qxelk:~# echo $? 1 root@imx6qxelk:~#
Command syntax[edit | edit source]
- print the whole environment
fw_printenv
- print a specific environment variable
fw_printenv <varname>
- delete environment variable
fw_setenv <varname>
- set environment variable
fw_setenv <varname> <varvalue>