u-boot environment variables in linux

212 views
Skip to first unread message

Frank Agius

unread,
Oct 27, 2008, 7:51:22 AM10/27/08
to discu...@beagleboard.org
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.

1) 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"

2) manually build fw_printenv with make:  "make env ARCH=arm CROSS_COMPILE= /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnuabi-"

3)  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.

4) 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"

5) 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.
   # Up to two entries are valid, in this case the redundand
   # environment sector is assumed present.

   # MTD device name       Device offset   Env. size       Flash sector size
          /dev/mtd2               0x0000          0x20000         0x20000

6) usage
  a) printing all the environment variables

  # fw_printenv
  bootdelay=1
  baudrate=115200
  ipaddr=192.168.0.2
  serverip=192.168.0.1
  netmask=255.255.255.0
  bootfile="uImage"
  filesize=B81A24
  bootcmd=nand read 80200000 280000 400000;bootm 80200000
  bootargs=console=ttyS2,115200n8 console=tty0 root=/dev/mtdblock4 rw rootfstyp
=j
  ffs2 nohz=off
  stdin=serial   
  stdout=serial
  stderr=serial

b) printing a single environment variable

   # fw_printenv stdin
   stdin=serial

c) 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.

  # fw_setenv mytestvariable abcdefg
  # fw_printenv mytestvariable
  mytestenv=abcdefg


I use these utilities most often to change the boot characteristic of my board (ie boot from nand, boot from mmc, boot from nfs).  Again, 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.

frank agius

Robert Kuhn

unread,
Oct 27, 2008, 8:13:47 AM10/27/08
to beagl...@googlegroups.com
2008/10/27 Frank Agius <fta...@gmail.com>:

> U-boot makes use of environment variable which can be read and set from the
>...

http://elinux.org/U-boot_environment_variables_in_linux
Okay?

Robert

fta...@gmail.com

unread,
Oct 27, 2008, 8:43:54 AM10/27/08
to Beagle Board
On Oct 27, 8:13 am, "Robert Kuhn" <rowka...@googlemail.com> wrote:
> 2008/10/27 Frank Agius <ftag...@gmail.com>:
>
> > U-boot makes use of environment variable which can be read and set from the
> >...
>
> http://elinux.org/U-boot_environment_variables_in_linux
> Okay?
>
> Robert

Robert,

Thanks for posting so quickly. It looks good.

regards,
frank
Reply all
Reply to author
Forward
0 new messages