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

From ArmadeusWiki
Jump to: navigation, search
m
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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 to remote control some U-Boot processes like software updates.  The U-Boot distribution has sources for these commands, named ''fw_printenv'' and ''fw_setenv''.
+
[[Category: Linux]]
 +
[[Category: U-Boot]]
 +
 
 +
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, for ex. to remote control some U-Boot processes like software updates.  The U-Boot distribution has sources for these commands, named ''fw_printenv'' and ''fw_setenv''.
  
 
== Installation ==
 
== Installation ==
  
{{Note|U-Boot tools are now installed and configured on the target since Armadeus 5.0. Therefore this installation procedure is only usefull for reference information.}}
+
{{Note|U-Boot tools are now installed and configured on your APF since Armadeus 5.0. Therefore following installation procedure is only useful for reference information.}}
  
 
Buildroot can automatically build these tools for you. You just have to:
 
Buildroot can automatically build these tools for you. You just have to:
Line 11: Line 14:
 
and then select the following option:
 
and then select the following option:
 
<pre class="config">
 
<pre class="config">
  Target filesystem options --->
+
  Hardware handling --->
     [*] Das U-Boot Boot Monitor  --->
+
     [*] u-boot tools
         [*]  fw_printenv tool in target
+
         [*]  fw_printenv
 
</pre>
 
</pre>
  
Line 21: Line 24:
 
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''.
 
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 / U-Boot 1.3.4:
+
* For the [[APF27]] with U-Boot 1.3.4:
 
<pre class="apf">
 
<pre class="apf">
 
# Configuration file for fw_(printenv/saveenv) utility.
 
# Configuration file for fw_(printenv/saveenv) utility.
Line 31: Line 34:
 
</pre>
 
</pre>
  
* For the APF51 / U-Boot 2010.03:
+
* For the [[APF51]] with U-Boot 2010.03:
 
<pre class="apf">
 
<pre class="apf">
 
# Configuration file for fw_(printenv/saveenv) utility.
 
# Configuration file for fw_(printenv/saveenv) utility.
Line 41: Line 44:
 
</pre>
 
</pre>
  
* For the APF9328:
+
* For the [[APF9328]] with U-Boot 1.3.4:
 
<pre class="apf">
 
<pre class="apf">
 
# Configuration file for fw_(printenv/saveenv) utility.
 
# Configuration file for fw_(printenv/saveenv) utility.
Line 50: Line 53:
 
/dev/mtd1                0x0000          0x20000          0x20000
 
/dev/mtd1                0x0000          0x20000          0x20000
 
</pre>
 
</pre>
 +
 +
* For the [[APF9328]] / [[APF27]] / [[APF28]] / [[APF51]] since U-Boot since 2012.04.01 (Armadeus-5.0 and upper):
 +
<pre class="apf">
 +
# Configuration file for fw_(printenv/saveenv) utility.
 +
# Up to two entries are valid, in this case the redundant
 +
# environment sector is assumed present.
 +
# Notice, that the "Number of sectors" is ignored on NOR and SPI-dataflash.
 +
# Futhermore, if the Flash sector size is ommitted, this value is assumed to
 +
# be the same as the Environment size, which is valid for NOR and SPI-dataflash
 +
 +
# Armadeus boards default environment configuration
 +
# MTD device name Device offset Env. size Flash sector size Number of sectors
 +
/dev/mtd1                0x0000          0x20000          0x20000                4
 +
/dev/mtd2                0x0000          0x20000          0x20000                4
 +
</pre>
 +
 +
* For the [[APF6]], as it uses an [[eMMC]] and no NOR/NAND Flash, there is a custom configuration file ''/etc/fw_env_apf6.config'' that should be moved to ''/etc/fw_env.config'' before going further.
 +
* For the [[OPOS6UL]], as it uses an [[eMMC]] and no NOR/NAND Flash, there is a custom configuration file ''/etc/fw_env_opos6ul.config'' that should be moved to ''/etc/fw_env.config'' before going further.
  
 
== Usage ==
 
== Usage ==
Line 69: Line 90:
  
 
=== Setting and verifying an environment variable ===
 
=== Setting and verifying an environment variable ===
{{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''.}}
+
* Unlock Flash access (if needed):
 +
** On [[APF6]], you have to do this first:
 +
<pre class="apf">
 +
echo 0 > /sys/block/mmcblk2boot0/force_ro
 +
</pre>
 +
** On [[OPOS6UL]], you have to do this first:
 +
<pre class="apf">
 +
echo 0 > /sys/block/mmcblk0boot0/force_ro
 +
</pre>
 +
* Then set your variable:
 
<pre class="apf">
 
<pre class="apf">
 
   # fw_setenv mytestvariable abcdefg
 
   # fw_setenv mytestvariable abcdefg
Line 80: Line 110:
 
==Links==
 
==Links==
 
* This page is an adaptation on this one: http://elinux.org/U-boot_environment_variables_in_linux
 
* This page is an adaptation on this one: http://elinux.org/U-boot_environment_variables_in_linux
 
[[Category: Linux]]
 
[[Category: U-Boot]]
 

Latest revision as of 09:52, 14 September 2018


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, for ex. to remote control some U-Boot processes like software updates. The U-Boot distribution has sources for these commands, named fw_printenv and fw_setenv.

Installation

Note Note: U-Boot tools are now installed and configured on your APF since Armadeus 5.0. Therefore following installation procedure is only useful for reference information.


Buildroot can automatically build these tools for you. You just have to:

$ make menuconfig

and then select the following option:

 Hardware handling  --->
     [*] u-boot tools
         [*]   fw_printenv

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 with U-Boot 1.3.4:
# 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 APF51 with U-Boot 2010.03:
# 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                 4
  • For the APF9328 with U-Boot 1.3.4:
# 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
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
# Notice, that the "Number of sectors" is ignored on NOR and SPI-dataflash.
# Futhermore, if the Flash sector size is ommitted, this value is assumed to
# be the same as the Environment size, which is valid for NOR and SPI-dataflash

# Armadeus boards default environment configuration
# MTD device name	Device offset	Env. size	Flash sector size	Number of sectors
/dev/mtd1                 0x0000          0x20000           0x20000                 4
/dev/mtd2                 0x0000          0x20000           0x20000                 4
  • For the APF6, as it uses an eMMC and no NOR/NAND Flash, there is a custom configuration file /etc/fw_env_apf6.config that should be moved to /etc/fw_env.config before going further.
  • For the OPOS6UL, as it uses an eMMC and no NOR/NAND Flash, there is a custom configuration file /etc/fw_env_opos6ul.config that should be moved to /etc/fw_env.config before going further.

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

  • Unlock Flash access (if needed):
    • On APF6, you have to do this first:
echo 0 > /sys/block/mmcblk2boot0/force_ro
    • On OPOS6UL, you have to do this first:
echo 0 > /sys/block/mmcblk0boot0/force_ro
  • Then set your variable:
  # 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