u-boot-2014.10移植(7)修改環境變量的存儲位置
原來環境變量存儲在nor flash裏, 前面mtdparts分區第二個分區就是params
現在修改環境變量到nand裏,
搜索default environment
在Env_common.c函數裏面:
default_environment結構體
default_environment結構體定義在env_common.c裏面
其中有:
#ifdef CONFIG_BOOTARGS "bootargs=" CONFIG_BOOTARGS "\0" #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 */ #defineCONFIG_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
u-boot-2014.10移植(7)修改環境變量的存儲位置