- Question:
- I would like to access U-Boot's environment variables from my Linux application.
Is this possible?
- Answer:
- Yes, you can. The environment variables must be stored in flash memory,
and your Linux kernel must support flash access through the MTD layer.
In the U-Boot source tree you can find the environment tools in the directory
tools/env
, which can be built with command:
make env
For building against older versions of the
MTD headers (meaning before v2.6.8-rc1) it
is required to pass the argument "MTD_VERSION=old" to make:
make MTD_VERSION=old env
The resulting binary is called
fw_printenv
, but actually includes support for setting
environment variables too. To achieve this, the binary behaves according to the
name it is invoked as, so you will have to create a link called
fw_setenv
to
fw_printenv
.
These tools work exactly like the U-Boot commands
printenv
resp.
setenv
You can either build these tools with a fixed configuration selected at compile time,
or you can configure the tools using the
/etc/fw_env.config
configuration file
in your target root filesystem. Here is an example configuration file:
# Configuration file for fw_(printenv/setenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
#########################################################################
# For TQM8xxL modules:
#########################################################################
# MTD device name Device offset Env. size Flash sector size
/dev/mtd0 0x8000 0x4000 0x4000
/dev/mtd0 0xC000 0x4000 0x4000
#########################################################################
# For NSCU:
#########################################################################
# MTD device name Device offset Env. size Flash sector size
#/dev/mtd1 0x0000 0x8000 0x20000
#/dev/mtd2 0x0000 0x8000 0x20000
#########################################################################
# For LWMON
#########################################################################
# MTD device name Device offset Env. size Flash sector size
#/dev/mtd1 0x0000 0x2000 0x40000