Difference between revisions of "Accessing U-Boot environment variables from Linux"

From ArmadeusWiki
Jump to: navigation, search
(page creation (reworked copy from elinux.org))
 
(Installation)
Line 23: Line 23:
 
# Up to two entries are valid, in this case the redundand
 
# Up to two entries are valid, in this case the redundand
 
# environment sector is assumed present.
 
# environment sector is assumed present.
# MTD device name      Device offset  Env. size      Flash sector size
+
# Notice, that the "Number of sectors" is ignored on NOR.
/dev/mtd1                0x0000          0x20000         0x20000
+
# MTD device name      Device offset  Env. size      Flash sector size       Number of sectors
 +
/dev/mtd1                0x0000          0x20000           0x20000                 3
 
</pre>
 
</pre>
  

Revision as of 22:43, 16 February 2010

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

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.

Then you have to create 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 informations 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. You can guess most of them by looking at /proc/mtd.

  • For the APF27:
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundand
# environment sector is assumed present.
# Notice, that the "Number of sectors" is ignored on NOR.
# MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
/dev/mtd1                 0x0000          0x20000           0x20000                 3
  • For the APF9328:
TBDL

Usage

Printing all the environment variables

# fw_printenv
bootdelay=1
baudrate=115200
ipaddr=192.168.0.2
serverip=192.168.0.1
...

Printing a single environment variable

# fw_printenv stdin
stdin=serial

Setting and verifying an environment variable

Warning 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_printenv mytestvariable
  mytestenv=abcdefg

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.

Links