U-boot makes use of environment variable which can be read and set from the u-boot command line with printenv and setenv. It can be helpful to read and set these variables from linux as well. The u-boot distribution has sources for these commands, named fw_printenv and fw_setenv, but the Angstrom OE distribution does not build the tools automatically. I'm a novice at OE and bitbake, so here are the instructions for building and installing the tools manually. Theses instructions assume that you have already buillt the angstrom distribution for the beagle board. Substitute directories and compiler locations to match your environment.

+

U-Boot makes use of environment variables which can be read and set from the U-Boot command line with ''printenv'' and ''setenv''. It can be helpful to read and set these variables from Linux as well. The U-Boot distribution has sources for these commands, named ''fw_printenv'' and ''fw_setenv''.

−

#cd to the source for u-boot in the OE tree. For me, it is at "../oe/tmp/work/beagleboard-angstrom-linux-gnueabi/u-boot-git-r18.1/git"

+

== Installation ==

+

===OpenEmbedded===

+

The Angstrom OE distribution does not build the tools automatically. I'm a novice at OE and bitbake, so here are the instructions for building and installing the tools manually. Theses instructions assume that you have already built the angstrom distribution for the beagle board. Substitute directories and compiler locations to match your environment.

+

#cd to the source for U-Boot in the OE tree. For me, it is at "../oe/tmp/work/beagleboard-angstrom-linux-gnueabi/u-boot-git-r18.1/git"

#if the compile succeeded, you should have fw_printenv in the u-boot directory tools/env. Copy fw_printenv to /sbin on the root filesystem of your beagle board.

+

#if the compile succeeded, you should have fw_printenv in the U-Boot directory tools/env. Copy fw_printenv to /sbin on the root filesystem of your beagle board.

#the fw_printenv binary also contains the code for fw_setenv. the functions of fw_setenv are run when the program is invoked with the name "fw_setenv". this is most easily accomplished by creating a symbolic link from fw_printenv to fw_setenv, as in "ln -sf /sbin/fw_printenv /sbin/fw_setenv"

#the fw_printenv binary also contains the code for fw_setenv. the functions of fw_setenv are run when the program is invoked with the name "fw_setenv". this is most easily accomplished by creating a symbolic link from fw_printenv to fw_setenv, as in "ln -sf /sbin/fw_printenv /sbin/fw_setenv"

−

#the last and most important step is creating the config file for the utilities. the file name is fw_env.config and it lives in /etc.

−

to create this file, you need to know information about where u-boot stores its env variables. Specifically, you need the mtd device name, the device offset, the env size and the flash sector size. I found most of what I needed by looking in the file /proc/mtd. here is my fw_env.config file:

−

# Configuration file for fw_(printenv/saveenv) utility.

+

===Buildroot===

−

# Up to two entries are valid, in this case the redundand

+

Buildroot can automatically build these tools for you. You just have to:

+

make menuconfig

+

and then select the following option:

+

Target filesystem options --->

+

[*] Das U-Boot Boot Monitor --->

+

[*] fw_printenv tool in target

+

+

Tools will be installed in ''/usr/sbin/'' of your target's rootfs.

+

+

===OpenWrt===

+

Like Buildroot, OpenWrt can build these tools too but you will find them in a different location in the menu:

+

Utilities --->

+

[*] uboot-envtools

+

+

Tools will also be installed in ''/usr/sbin/''.

+

+

===All distribs===

+

'''The last and most important step''' is creating the config file for the utilities. The file name is ''fw_env.config'' and it lives in ''/etc''.

+

To create this file, you need to know information about where U-Boot stores its env variables. Specifically, you need the mtd device name, the device offset, the env size and the flash sector size. I found most of what I needed by looking in the file ''/proc/mtd''. Here is my ''fw_env.config'' file:

+

+

# Configuration file for fw_(printenv/setenv) utility.

+

# Up to two entries are valid, in this case the redundant

# environment sector is assumed present.

# environment sector is assumed present.

# MTD device name Device offset Env. size Flash sector size

# MTD device name Device offset Env. size Flash sector size

Line 38:

Line 61:

=== Setting and verifying an environment variable ===

=== Setting and verifying an environment variable ===

−

WARNING! If the fw_env.config does not point to u-boots env section in flash, running fw_setenv could corrupt your flash. Make sure that fw_printenv works properly and does not return a message about "bad CRC" before running fw_setenv.

+

WARNING! If the ''fw_env.config'' does not point to U-Boot's env section in Flash, running ''fw_setenv'' could corrupt your Flash. Make sure that ''fw_printenv'' works properly and does not return a message about "bad CRC" before running ''fw_setenv''.

# fw_setenv mytestvariable abcdefg

# fw_setenv mytestvariable abcdefg

Line 45:

Line 68:

−

Care must be taken when changing env variables as a typo could easily render your boot unbootable. Most problems can be fixed by connecting to the serial console and using u-boots command line to fix bad variable.

+

Care must be taken when changing env variables as a typo could easily render your system unbootable. Most problems can be fixed by connecting to the serial console and using U-Boot's command line to fix bad variable.

Latest revision as of 15:38, 31 August 2012

U-Boot makes use of environment variables which can be read and set from the U-Boot command line with printenv and setenv. It can be helpful to read and set these variables from Linux as well. The U-Boot distribution has sources for these commands, named fw_printenv and fw_setenv.

Installation

OpenEmbedded

The Angstrom OE distribution does not build the tools automatically. I'm a novice at OE and bitbake, so here are the instructions for building and installing the tools manually. Theses instructions assume that you have already built the angstrom distribution for the beagle board. Substitute directories and compiler locations to match your environment.

cd to the source for U-Boot in the OE tree. For me, it is at "../oe/tmp/work/beagleboard-angstrom-linux-gnueabi/u-boot-git-r18.1/git"

if the compile succeeded, you should have fw_printenv in the U-Boot directory tools/env. Copy fw_printenv to /sbin on the root filesystem of your beagle board.

the fw_printenv binary also contains the code for fw_setenv. the functions of fw_setenv are run when the program is invoked with the name "fw_setenv". this is most easily accomplished by creating a symbolic link from fw_printenv to fw_setenv, as in "ln -sf /sbin/fw_printenv /sbin/fw_setenv"

Buildroot

Buildroot can automatically build these tools for you. You just have to:

OpenWrt

Like Buildroot, OpenWrt can build these tools too but you will find them in a different location in the menu:

Utilities --->
[*] uboot-envtools

Tools will also be installed in /usr/sbin/.

All distribs

The last and most important step is creating the config file for the utilities. The file name is fw_env.config and it lives in /etc.
To create this file, you need to know information about where U-Boot stores its env variables. Specifically, you need the mtd device name, the device offset, the env size and the flash sector size. I found most of what I needed by looking in the file /proc/mtd. Here is my fw_env.config file:

Printing a single environment variable

# fw_printenv stdin
stdin=serial

Setting and verifying an environment variable

WARNING! If the fw_env.config does not point to U-Boot's env section in Flash, running fw_setenv could corrupt your Flash. Make sure that fw_printenv works properly and does not return a message about "bad CRC" before running fw_setenv.

Care must be taken when changing env variables as a typo could easily render your system unbootable. Most problems can be fixed by connecting to the serial console and using U-Boot's command line to fix bad variable.