Project

General

Profile

U-boot env userspace tool

U-boot provides a userspace tool you can build, to print and update the u-boot environment stored in mtd4

tools/env/README

root@mityomapl138:~# cat /proc/mtd
mtd0: 08000000 00020000 "rootfs" 
mtd1: 08000000 00020000 "homefs" 
mtd2: 00010000 00010000 "ubl" 
mtd3: 00080000 00010000 "u-boot" 
mtd4: 00010000 00010000 "u-boot-env" <---------------
mtd5: 00010000 00010000 "periph-config" 
mtd6: 00050000 00010000 "reserved" 
mtd7: 00300000 00010000 "kernel" 
mtd8: 00200000 00010000 "fpga" 
mtd9: 00200000 00010000 "spare" 

Build and install

  • Follow instructions to build Das_U-Boot_Port
  • Run makearm env
  • Copy tools/env/fw_printenv to /usr/sbin
  • Symlink fw_setenv
    ln -sf fw_printenv /usr/sbin/fw_setenv
  • Copy tools/env/fw_env.config to /etc/fw_env.config

Use tool

Usage:

   fw_printenv [[ -n name ] | [ name ... ]]
           - prints the value of a single environment variable
             "name", the ``name=value'' pairs of one or more
             environment variables "name", or the whole
             environment if no names are specified.
   fw_setenv name [ value ... ]
           - If a name without any values is given, the variable
             with this name is deleted from the environment;
             otherwise, all "value" arguments are concatenated,
             separated by single blank characters, and the
             resulting string is assigned to the environment
             variable "name" 

root@mityomapl138:~# fw_printenv 
bootdelay=3
baudrate=115200
flashuboot=tftp 0xc0700000 mityomap/u-boot-ubl.bin; sf probe 0; sf erase 0x10000 0x80000; sf write 0xc0700000 0x10000 ${filesize}
flashkernel=tftp 0xc0700000 mityomap/uImage; sf probe 0; sf erase 0x100000 0x280000; sf write 0xc0700000 0x100000 ${filesize}
...

root@mityomapl138:~# fw_setenv test 1
root@mityomapl138:~# fw_printenv test
test=1

Read-only

Note if you get a "Can't open /dev/mtd4: Permission denied", the mtd partition may be marked as read-only

  • Check board-mityomapl138.c
    .mask_flags = MTD_WRITEABLE will clear the writeable flag
  • You can also check mtdinfo
    # mtdinfo /dev/mtd4
    mtd4
    Name:                           u-boot-env
    Type:                           nor
    Eraseblock size:                65536 bytes, 64.0 KiB
    Amount of eraseblocks:          1 (65536 bytes, 64.0 KiB)
    Minimum input/output unit size: 1 byte
    Sub-page size:                  1 byte
    Character device major/minor:   90:8
    Bad blocks are allowed:         false
    Device is writable:             false  <------
    

To make the partition writable, you can either remove the .mask_flag line from the mtd partition. board-mityomapl138.c

Or a mtd unlock option was added in our 3.2 kernel but needs to be enabled CONFIG_MTD_UNLOCK
This makes the partition writable until relocked.

echo unlock > /sys/devices/platform/spi_davinci.1/spi1.0/mtd/mtd4/unlock
fw_setenv test 1
echo lock > /sys/devices/platform/spi_davinci.1/spi1.0/mtd/mtd4/unlock

Go to top
Add picture from clipboard (Maximum size: 1 GB)