原来环境变量存储在nor flash里, 前面mtdparts分区第二个分区就是params
现在修改环境变量到nand里,
搜索default environment
在Env_common.c函数里面:
default_environment结构体
default_environment结构体定义在env_common.c里面
其中有:
#ifdef CONFIG_BOOTARGS
"bootargs=" CONFIG_BOOTARGS " "
#endif
这里CONFIG_BOOTARGS没有定义,bootargs是传给内核的环境变量,在smdk2440.h里面定义CONFIG_BOOTARGS
#define CONFIG_BOOTARGS "console=ttySAC0 root=/dev/mtdblock3"
此外设置bootcmd参数:
#define CONFIG_BOOTCOMMAND "nand read 30000000 0x30008000 0x400000;bootm 30000000"
假设从0x30008000读2M到30000000
设置ip
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 192.168.1.1110
#define CONFIG_SERVERIP 192.168.1.113
#define CONFIG_ETHADDR 00:0c:29:45:c4:c3
修改默认分区:
0x00000000-0x00040000 : "bootloader" //256k
0x00040000-0x00060000 : "params" //128K
0x00060000-0x00460000 : "kernel" //4M
0x00460000-0x10000000 : "root"
原来的环境变量的配置:
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
#define CONFIG_ENV_IS_IN_FLASH
#define CONFIG_ENV_SIZE 0x10000
/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE
当输入save时:
SMDK2440 # save
Saving Environment to Flash...
Un-Protected 1 sectors
Erasing Flash...
. done
Erased 1 sectors
Writing to Flash... 9....8....7....6....5....4....3....2....1....done
Protected 1 sectors
上面说过不要用save命令保存环境变量设置,目的是防止flash被破坏:
查看save命令帮助信息,知道saveenv,搜索saveenv
或者在SI里面搜索可得,在common目录下看Makefile,知道依赖上面宏
Env_nand.c (common):int saveenv(void)
makefile里面有:
COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
可知需要CONFIG_ENV_IS_IN_NAND
不光如此,还需要知道起始地址和大小
打开env_nand.c,里面有CONFIG_ENV_SIZE和CONFIG_ENV_OFFSET
上面的还不够,还需要擦除长度
nand_erase_options.length = CONFIG_ENV_RANGE;
即需要定义CONFIG_ENV_RANGE,设为CONFIG_ENV_SIZE
综上所知设置为:
#if 0
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
#define CONFIG_ENV_IS_IN_FLASH
#define CONFIG_ENV_SIZE 0x10000
/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE
#endif
#define CONFIG_ENV_IS_IN_NAND
#define CONFIG_ENV_OFFSET 0x00040000
#define CONFIG_ENV_SIZE 0x20000
#define CONFIG_ENV_RANGE CONFIG_ENV_SIZE
改成nand后,输入save:
SMDK2440 # save
Saving Environment to NAND...
Erasing NAND...
Erasing at 0x40000 -- 100% complete.
Writing to NAND... OK