linux 下更新uboot环境变量

参考网址:

http://www.denx.de/wiki/DULG/HowCanIAccessUBootEnvironmentVariablesInLinux

 
http://blog.csdn.net/hangbing0203/article/details/4314576
http://labs.igep.es/index.php/How_to_modify_the_uboot_environment_from_userspace

 

代码分析:

README:

This is a demo implementation of a Linux command line tool to access
the U-Boot's environment variables.

For the run-time utiltity configuration uncomment the line
#define CONFIG_FILE  "/etc/fw_env.config"
in fw_env.h.

这个有误,应该是用配置文件时,不要注释掉这个宏

See comments in the fw_env.config file for definitions for the
particular board.

Configuration can also be done via #defines in the fw_env.h file. The
following lines are relevant:

#define HAVE_REDUND    /* For systems with 2 env sectors */
#define DEVICE1_NAME    "/dev/mtd1"
#define DEVICE2_NAME    "/dev/mtd2"
#define DEVICE1_OFFSET    0x0000
#define ENV1_SIZE         0x4000
#define DEVICE1_ESIZE     0x4000
#define DEVICE2_OFFSET    0x0000
#define ENV2_SIZE         0x4000
#define DEVICE2_ESIZE     0x4000

Current configuration matches the environment layout of the TRAB
board.

HAVE_REDUND是用来环境变量备份用的

Un-define HAVE_REDUND, if you want to use the utlities on a system
that does not have support for redundant environment enabled.
If HAVE_REDUND is undefined, DEVICE2_NAME is ignored,
as is ENV2_SIZE and DEVICE2_ESIZE.

The DEVICEx_NAME constants define which MTD character devices are to
be used to access the environment.

The DEVICEx_OFFSET constants define the environment offset within the
MTD character device.

ENVx_SIZE defines the size in bytes taken by the environment, which
may be less then flash sector size, if the environment takes less
then 1 sector.

DEVICEx_ESIZE defines the size of the first sector in the flash
partition where the environment resides.

 

DEVICEx_NAME设备名

DEVICEx_OFFSET设备中环境变量的偏移

ENVx_SIZE 环境变量大小,可能比1sector小

 

查看环境变量大小:

pri查看

Environment size: 1560/4092 bytes

include/configs/mv_kv.h

#define CFG_ENV_SIZE        0x1000

所以大小是0x1000

查看环境变量偏移:

#define CFG_MONITOR_LEN            (512 << 10)    /* Reserve 512 kB for Monitor */   uboot镜像长度 0x80000 =512k

//uboot的基址和环境变量的基址
#define CFG_MONITOR_BASE        (CFG_FLASH_BASE)
#define CFG_ENV_ADDR            (CFG_MONITOR_BASE + CFG_MONITOR_LEN)     环境变量开始位置

#define CFG_ENV_SIZE        0x1000   //4k
环境变量从0x80000开始 到0x80000+0x1000

 

根据CFG_ENV_ADDR 知道环境变量偏移是0x80000

 

查看erasesize

/opt/qtmarvell/mvqt/tools # cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00100000 00010000 "uboot"
mtd1: 00700000 00010000 "linux-root"

 

编译fw_printenv:

下载http://ftp.denx.de/pub/u-boot/u-boot-2011.03.tar.bz2

根目录下:

make env HOSTCC=arm-mv5sft-linux-gnueabi-gcc

ln -s fw_printenv fw_setenv

 

修改fw_env.config ,根据上面的信息:

/opt/qtmarvell/mvqt/tools # cat fw_env.config
# 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.

# MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
/dev/mtd0               0x80000         0x1000          0x10000

posted on 2011-07-28 16:16  katago  阅读(5181)  评论(0编辑  收藏  举报