5,354 bytes added,
07:39, 28 June 2019 {{InfoBoxTop}}
{{AppliesToAxel}}
{{AppliesToAxelEsatta}}
{{AppliesToAxelLite}}
{{InfoBoxBottom}}
{{WarningMessage|text=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.}}
==History==
{| class="wikitable" border="1"
!Version
!Date
!Notes
|-
|1.0.0
|June 2019
|First release
|-
|}
==Introduction==
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 <code>fw_printenv</code> and <code>fw_setenv</code> utilities present on u-boot source codes.
==Tools required==
In order to modify the uboot environment variables from userspace the <code>fw_printenv</code> 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 <code>fw_setenv</code> 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 ==
''fw_printenv'' uses the <code>/etc/fw_env.config</code> 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 ===
Using the
<pre>
cat /proc/mtd
</pre>
command, it is possible to see the memory partitioning and where the '''environment''' parts are:
<pre class="board-terminal">
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:~#
</pre>
So, in this example we can see that the two mtd parts to be used are
<pre>
mtd1: 00100000 00020000 "nand-env1"
mtd2: 00100000 00020000 "nand-env2"
</pre>
=== Sizes ===
The two parameters required for properly configuring the <code>fw_env.config</code> 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 [[:Category:AxelLite | AxelLite]] family this file is <code>include/configs/mx6axel.h</code> 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:
<pre>
CONFIG_ENV_IS_IN_NAND
</pre>
and the related section (for the environment sizes) is:
<pre>
#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)
</pre>
So, we found that the proper parameters are:
* '''Env. size''': 0x20000
* '''Flash sector size''': 0x100000
== fw_env.config ==
Following the configuration information found before, we can set the proper parameters into the <code>fw_env.config</code> file as shown below:
<pre class="board-terminal">
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:~#
</pre>
== u-boot environment access example ==
* display the <code>ipaddr</code> and <code>bootfile</code> environment variables:
<pre class="board-terminal">
root@imx6qxelk:~# fw_printenv ipaddr bootfile
ipaddr=192.168.0.90
bootfile=axel/linux/xelk-3.0.7_uImage
root@imx6qxelk:~#
</pre>
=== Wrong configuration file ===
If some parameters are not correctly configured on the ''fw_env.config'' file, the utilities displays an error message:
<pre>
Warning: Bad CRC, using default environment
</pre>
It is possible to detect this situation using the return code of <code>fw_printenv</code>:
* ''fw_env.config'' correct file
<pre class="board-terminal">
root@imx6qxelk:~# fw_printenv ipaddr
ipaddr=192.168.0.90
root@imx6qxelk:~# echo $?
0
root@imx6qxelk:~#
</pre>
* '''wrong''' ''fw_env.config'' file
<pre class="board-terminal">
root@imx6qxelk:~# fw_printenv ipaddr
Warning: Bad CRC, using default environment
## Error: "ipaddr" not defined
root@imx6qxelk:~# echo $?
1
root@imx6qxelk:~#
</pre>
== Command syntax ==
* 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>''