Any embedded devices these days use the U-Boot bootloader. This bootloader stores its configuration into an area of the flash called the environment that can be manipulated from within U-Boot using the
printenv
, setenv
and saveenv
commands, or from Linux using the fw_printenv
and fw_setenv
userspace utilities provided with the U-Boot source code.
This environment is typically stored in a specific flash location,
defined in the board configuration header in U-Boot. The environment is
basically stored as a sequence of null-terminated strings, with a little
header containing a checksum at the beginning.
While this environment can easily be manipulated from U-Boot or from
Linux using the above mentioned commands, it is sometimes desirable to
be able to generate a binary image of an environment that can be
directly flashed next to the bootloader, kernel and root filesystem into
the device’s flash memory. For example, on AT91 devices, the SAM-BA
utility provided by Atmel is capable of completely reflashing an AT91
based system connected through the serial port of the USB device port.
Or, in factory, initial flashing of devices typically takes place either
through specific CPU monitors, or through a JTAG interface. For all of
these cases, having a binary environment image is desirable.
David Wagner, who has been an intern with us at Free Electrons from April to September 2011, has written a utility called
mkenvimage
which just does this: generate a valid binary environment image from a text file describing the key=value
pairs of the environment. This utility has been merged into the U-Boot Git repository (see the commit) and will therefore be part of the next U-Boot release.
With
mkenvimage
you can write a text file uboot-env.txt
describing the environment, like:bootargs=console=ttyS0,115200 bootcmd=tftp 22000000 uImage; bootm [...]
Then use
mkenvimage
as follows:./tools/mkenvimage -s 0x4200 -o uboot-env.bin uboot-env.txt
The
-s
option allows to specify the size of the image to
create. It must match the size of the flash area reserved for the
U-Boot environment. Another option worth having in mind is -r
, which must be used when there are two copies of the environment stored in the flash thanks to the CONFIG_ENV_ADDR_REDUND
and CONFIG_ENV_SIZE_REDUND
. Unfortunately, U-Boot has chosen to have a different environment layout in those two cases, so you must tell mkenvimage
whether you’re using a redundant environment or a single environment.
This utility has proven to be really useful, as it allows to
automatically reflash a device with an environment know to work. It also
allows to very easily generate a different environment image
per-device, for example to contain the device MAC address and/or the
device serial number.
No comments:
Post a Comment
Thank You , For Immediate Assistance Plz Put Email Copy to Deviceporting@gmail.com