OpenWrt Forum Archive

Topic: uboot fw_env.config ???

The content of this topic has been archived on 17 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Greetings,
I am trying to access the u-boot env variables from the OS using fw_printenv.  I would like to adjust the bootdelay.
I am unable to create a working fw_env.config file for my router.

/proc/mtd looks like this:
dev:    size   erasesize  name
mtd0: 00050000 00010000 "u-boot"
mtd1: 00180000 00010000 "kernel"
mtd2: 00610000 00010000 "rootfs"
mtd3: 00010000 00010000 "nvram"
mtd4: 00010000 00010000 "factory"
mtd5: 00790000 00010000 "firmware"

I can't find anything on the web about how to properly create the config file based on these values.
It shoudl look something like this, but I cant figure out how to set the values properly.

# MTD device name       Device offset   Env. size       Flash sector size
  /dev/mtd0               0x0000          0x50000         0x10000

This is a non-branded RT3052 router running Openwrt.
If you know the answer, please share.

Thank you.

(All of info below is specific to Dockstar, may or may not be correct for your router.)
I have been interested in just this question for a while, and have messed with source code, etc. trying to figure out the settings.  Today I hooked up a serial cable and in the second-stage uboot bootloader I set a marker variable (setenv marker_var test) then ran saveenv. Then I booted into linux and did dd if=/dev/mtd1 of=/tmp/mtd1.cp.  I then scp'd mtd1.cp to my desktop and ran hexdump on it.  I found the marker variable at 0x40000.
Hence with /etc/fw_env.config having the contents:
# cat /etc/fw_env.config
#MTD device name       Device offset   Env. size       Flash sector size
#/dev/mtd0              0xc0000         0x20000         0x20000
/dev/mtd1              0x40000         0x20000         0x20000

fw_printenv works correctly:
# fw_printenv
bootcmd=${x_bootcmd_kernel}; setenv bootargs ${x_bootargs} ${x_bootargs_root}; ${x_bootcmd_usb}; bootm 0x6400000;
bootdelay=3
baudrate=115200
ipaddr=169.254.254.243
serverip=169.254.254.254x_bootargs=console=ttyS0,115200 mtdparts=orion_nand:1M(u-boot),1M@1M(second_stage_u-boot),3M@2M(kernel),32M@5M(rootfs),219M@37M(data) rw
x_bootcmd_kernel=nand read 0x6400000 0x200000 0x300000
x_bootcmd_usb=usb start
x_bootargs_root=root=/dev/mtdblock3 rw rootfstype=jffs2
stdin=serial
stdout=serial
stderr=serial
ethaddr= <edited out>
ethact=egiga0
marker_var=test


The /dev/mtd0 settings in /etc/fw_env.config are for the old uboot environment, and also work if uncommented.

So far I have only used fw_printenv, I don't have the guts to try fw_setenv, for fear of messing up the environment and possibly having to use a JTAG cable for the first time.

FWIW.

Follow up: I have several Dockstars.  Today I downloaded and installed uboot-envtools, configured /etc/fw_env.config as above, then was surprised when fw_printenv gave the usual "Bad CRC" error.  Looking at mtd1 I see that the area at 0x40000 is unpopulated:
--
00029380  ff ff 00 00 ff ff 00 00  ff ff 00 00 ff ff 00 00  |................|
*
00040000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00100000
--
I booted with a serial connection.  I noticed that in the U-boot boot messages was "Bad CRC".   On a hunch I ran saveenv.  Now the fw_printenv works, and dumping mtd1 I can see the environment at 0x40000:
--
00029380  ff ff 00 00 ff ff 00 00  ff ff 00 00 ff ff 00 00  |................|
*
00040000  72 89 b3 f3 62 6f 6f 74  63 6d 64 3d 24 7b 78 5f  |r...bootcmd=${x_|
00040010  62 6f 6f 74 63 6d 64 5f  6b 65 72 6e 65 6c 7d 3b  |bootcmd_kernel};|
...
---
I wonder if the need to save the enviroment with a serial connection could be gotten around by running fw_setenv?

yawlhoo, thanks for the updates.

Another question that I have is sometimes I see a partition called "uboot" and sometimes 2 partitions: "uboot" and "uboot-env".
It depends on which router I specify during the build process.
I was thinking there is only one "Uboot" software (well, revisions of it) so how does the Uboot code know to use 1 partiion or 2?
Or maybe that 2nd partition just a segment of the single partition? Maybe the build just mapped it into 2 partions to specify which part is code vs which part is data for user ease, but the Uboot code just uses offsets from the base of partition one?
I looked at the Uboot manual, but I didnt find a reference to this.

Per my post above it seems to me that the lack of a default environment at 0x40000 unless one saves the environment is a bug, and I have filed a ticket at https://dev.openwrt.org/ticket/8819.

Orca, I will look at documenting what I have found, as you suggest.

razor, maybe these uboot differences are due to whether the router's uboot is left intact, as installed by the manufacturer and then used to boot, or something is substituted, as is the case with the Dockstar, where a second stage bootloader is installed and used to boot?  But this is just a guess, I really cannot answer your questions definitively.

Orca, I have "dumped" my docs into http://wiki.openwrt.org/inbox/start as you mentioned, I hope I did it right, the wiki documentation leaves a lot to be desired!

I screwed up my courage and issued fw_setenv.  It works, it updates an environment value, writing the value to mtd storage.  If I set the variable with an empty field (for example, "fw_setenv marker_var") the variable is deleted from the environment.  This persists over reboots.

The discussion might have continued from here.