Download Linux Journal | October 2014 | Issue 246

Transcript
Figure 8. Each environment variable can be associated with a type and access
permission in the environment variable .flags.
“decimal”, “hexadecimal”, “boolean”,
“IP address” and “MAC address”.
There are corresponding codes for
these type modifiers: “s”, “d”, “x”,
“b”, “i” and “m”. Again, U-Boot
stores this type information of variables
in flags as a bitmap (Figure 5).
You can associate “type” and
“access control” to a variable either
at compile time or at runtime.
For compile-time association, you
need to define a config #define
CONFIG_ENV_FLAGS_LIST_DEFAULT
foo:sr in your board file. For
runtime association, you can define
an environment variable .flags
(Figure 8). Here, I am associating an
environment variable foo with type
s (meaning the value is a string) and
access control r (meaning it is readonly). Once deployed, if you try to
modify the variable foo , U-Boot will
reject your request. Also, if a value is
not of specified “type”, your update to
the environment variable will fail.
Environment variables like MAC
address make use of type m . This will
make U-Boot do a sanity check on the
value entered by the user to confirm
whether the value is indeed a valid
MAC address.
Modifying the U-Boot User
Environment from Linux
U-Boot environment variables can
be added, modified or deleted from
Linux as well. U-Boot provides a set
of utilities called fw_printenv and
fw_setenv to do the job. First, you
need to compile these utilities for
Linux. Figure 9 shows the compilation
steps for the utility. Here, I am crosscompiling it for the ARM platform. It
is a multi-call binary. So, you need to
make a symlink named fw_setenv to
the binary fw_printenv .
To modify the environment, you
first need to boot in to Linux on
the target board. Next, you need to
create a file called /etc/fw_env.config.
This file contains all the information
needed to specify the location of
WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 79
LJ246-Oct2014.indd 79
9/17/14 4:49 PM