How to modify UBoot Environment from Userspace

  • To modify the UBoot environment from the userspace you need the tools fw_printenv and fw_setenv. You can bring these programs in 2 different ways to the remote target system. Either by Buildroot or by UBoot.


    Steps for Buildroot:

    • You have to activate the package u-boot tools, rebuild your rootfs and install it on your system. The package is located in Target packages/Hardware handling
    • After you have started your remote target system, the tools fw_printenv and fw_setenv are located in /usr/slib. You also have a file called fw_env.config which you have to modify.
    • Comment out all lines in the file fw_env.config. Then add the following line:
      Code
      1. /dev/mtd4 0x0000 0x4000 0x20000 0x2


    Steps for UBoot:

    • The tools fw_printenv is integrated in UBoot. To build these tool in UBoot you have to setup the following command:
      Code
      1. make env


    • After that the compiled files are located in tools/env.
    • There you find the file fw_printenv. To create fw_setenv you can copy the file fw_printenv to fw_setenv. Both are available in one executable. You also can create a link to fw_printenv.
    • Afterwards you have to modify the file fw_env.config which is also located in tools/env. Comment out all lines in this file. Then add the following line:
      Code
      1. /dev/mtd4 0x0000 0x4000 0x20000 0x2


    • For further information have a look at the topic fw_printenv and fw_setenv from Userspace
    • Now you can transfer these 3 files to your remote target system. You must copy fw_env.config to /etc.

    Now you are able to read the UBoot environment from userspace. Execute the fw_printenv tool to display the UBoot environment.


    If you want to modify these variables you have to remount the UBootEnv partition (default: mtd4). By default the UBootEnv partition is read-only mounted. To remount this partition you have 2 possibilites:

    • The easiest way is to modify the variable mtdparts in UBoot. There you have to change the string ...(UBootEnv)ro,... to ...(UBootEnv),... Just remove the ro so the partition will be mounted read/writeable. For further information have a look at the topic What needs to be contained in UBOOT to start/access nand0 (SOM Flash) After that you can start your system and the partition is read/writeable mounted.
    • If you want to do this without a reboot you can create a kernel module which is mounting this partition as read/writeable. There is an existing GitHub project which do this. The project called mtdRW. You have to modify the source file because all mtd partition will be mounted as read/writeable, but we only need UBootEnv as read/writeable. You also have to modify the Makefile, there is a string called KERNEL_DIR which must point to your linux kernel directory. After that you can compile the module with the command make. Now you can transfer the kernel object mtdRW.ko to your remote target system. To load this module you can use the command insmod mtdRW.ko

    Now you can use the fw_setenv command to modify some UBoot environment variables. Example:

    Code
    1. fw_printenv serverip
    2. 10.0.0.122
    3. fw_setenv serverip 10.0.0.120
    4. fw_printenv serverip
    5. 10.0.0.120


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.