Building fw printenv and fw setenv
Contents[hide] |
[edit]Overview
You can access and change the U-Boot environment from Linux userspace using the "U-Boot tools" fw_printenv and fw_setenv, which you can build from the current U-Boot source and install on the target system. You can see the source for those in the U-Boot source directory, under tools/env/.
[edit]Building the tools
From the top of the U-Boot source code, you need to explicitly identify the GCC cross-compiler you want to use for the build, as in (for example):
$ make HOSTCC=arm-arago-linux-gnueabi-gcc env
This will create the cross-compiled executable tools/env/fw_printenv. Note that the Makefile will also try to strip that executable but the README file fails to mention that you'd need to also identify the cross-compile version of the strip command, as in HOSTSTRIP=arm-arago-linux-gnueabi-strip. That's not a fatal problem since stripping the executable is optional, so that's up to you.
[edit]Installing the executable(s) and config file
The resulting executable fw_printenv actually does double duty for both printing and setting U-Boot environment variables, so you need to install it in the root filesystem and create an additional symlink to it on the target system. For example (assuming you're logged into the target):
# cd /usr/bin # ... copy fw_printenv here # ln -s fw_printenv fw_setenv
Now you can run that single executable by either name and it will do the right thing.
[edit]Creating the config file
Finally, you need to create the U-Boot environment config file /etc/fw_env.config file on the target system which identifies the properties of the U-Boot environment flash partition. A sample file is in the U-Boot tools/env source directory and it should be fairly self-explanatory. In my case, since the U-Boot environment was in the very first NAND flash partition and was 128K in size with a flash sector size also of 128K, my fw_env.config file looked like:
# MTD device Offset Env size Flash sector size /dev/mtd0 0x0 0x20000 0x20000
[edit]Printing the U-Boot environment
If all goes well, once you boot, you can list the U-Boot environment from Linux userspace:
# fw_printenv DE:AD:BE:EF:01:02== ethaddr baudrate=115200 bootargs=console=ttyS2,115200n8 root=/dev/mtdblock5 rootfstype=jffs2 ip=off bootcmd=nand read C0700000 200000 300000; bootm C0700000 bootdelay=10 bootfile="uImage" davinci_emac.ethaddr=DE:AD:BE:EF:01:02 ethact=DaVinci-EMAC ethaddr=DE:AD:BE:EF:01:02 fileaddr=C0700000 filesize=21362C ipaddr=192.168.3.12 serverip=192.168.3.2 stderr=serial stdin=serial stdout=serial #
and use fw_setenv to change it as well.
[edit]Changing U-Boot environment variables with fw_setenv
Pretty straightforward, but you need to make sure the U-Boot environment partition in flash isn't set as write-protected in your kernel partition table; otherwise, any attempt to change environment information will give you a permission violation. You can still use fw_printenv to list it, of course.