6.2.5. Update U-Boot Environment Variables stored in SPI Flash from Linux

Purpose

The purpose of this article is to demonstrate how the U-Boot Environment variables stored in SPI Flash can be accessed from a Linux command line using a tool provided from U-Boot.

Assumptions

  1. This example is based on the AMSDK, AM335x GP EVM and the User is has the latest version of the AMSDK installed

Summary/Checklist

  1. Build(Cross Compile) fw_printenv/fw_setenv U-Boot Tool provided with U-Boot source in the AMSDK
  2. Prepare configuration file for U-Boot Tool fw_printenv/fw_setenv
  3. Load fw_printenv/fw_setenv into target file system
  4. Test fw_printenv/fw_setenv tool

Overview

To access the environment variables from Linux one of the tools from u-boot must be cross compiled and copied into the file system. This tool is located in the board-support/u-boot<version>/tools/env directory of the latest AMSDK.

../../../_images/Sitara-Linux-Spi_nor_overview_1.png

Build(Cross Compile) fw_printenv/fw_setenv U-Boot Tool

Please note that all paths are refereneced to the u-boot source within the AMSDK, ti-sdk-am335x-<version>/board-support/u-boot<version>.....

Prior to building the The flag in board-support/u-boot<version>/tools/envfw_env.h “HAVE_REDUND” must be undefined as only a single env partition has been defined in the AMSDK SPI MTD partitioning.

Please note that the CROSS_COMPILE flag is not used by the u-boot makefile here, the HOSTCC= variable must be set.

host# make HOSTCC=arm-arago-linux-gnueabi-gcc env

This command is issued from the top of the u-boot source directory. Please be sure to see that the cross compiler was actually called and not just gcc.


Prepare configuration file for U-Boot Tool fw_printenv/fw_setenv

After building the executable a configuration file must be created and placed into a specific directory that is called in fw_env.h in the board-support/u-boot<version>/tools/env directory. The default location for the configuration file (fw_env.config) is /etc/.


MTD device name Device offset Env. size Flash sector size (only the line below is needed in the file)
/dev/mtd2               0x0000          0x2000          0x1000

Load fw_printenv/fw_setenv into target file system

This creates the executable fw_printenv, this file must be copied into the target file system, place in /sbin or the user’s directory.

You must copy fw_printenv to fw_setenv to be able to set variables. The program detects the name it was called as and sets the context it will run in.


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