Update U-Boot Environment Variables stored in Flash from Linux

Hi folks,

How are you all?

Many of us wondering that, Is it possible to get U-boot environment variables in user space? Is it possible to set U-boot environment variable from user space? Answer to these questions is YES. It is possible to set and retrieve U-boot environment variables from user space through command-line or any application.

In this article I will demonstrate how to set and get U-boot environment from Linux user space through an application or shell command. To explain this I will take a reference of AM335x EVM.

In Linux source code, there is a board file specific to board or processor (in my case it is board-am335xevm.c) which contains a structure of memory partitions, In that memory partions will be a separate memory partition of Uboot environment variables where these variables will be stored. refer the below image.

Untitled

Build fw_printenv / fw_setenv tool

  • first of all cd to top of the u-boot source directory
  • Issue a command
    host# make HOSTCC=arm-arago-linux-gnueabi-gcc env
    

    This must create a fw_printenv and fw_setenv cross compiled binaries in <uboot-src>/tools/env directory. You must see these binaries along with fw_env.config file. You must copy these two binaries to /bin folder and fw_env.config file to /etc directory of the target system.

Test fw_printenv / fw_setenv tool

The executable fw_printenv will dump the entire environment space, individual variables can be read by:

target# ./fw_printenv autoload

To set an environment variable use fw_setenv. This example will set the variable autoload to no, use fw_printenv to read back the change.

target# ./fw_setenv autoload no
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s