硬件平台:tq2440
开发环境:Ubuntu-3.11
u-boot版本:2014.10
本文允许转载,请注明出处:http://blog.csdn.net/fulinus
在Nand flash中保存环境变量
u-boot中的环境变量可以通过pri命令可以查看,可以通过set(setenv)命令设置一个参数,设置之后的参数仅仅是保存在SDRAM中,掉电后丢失,
使用save命令可以保存参数到Nor flash或Nand flash中去,但是u-boot默认是保存到Nor flash中去,下面修改u-boot,使其保存的环境变量保存到
Nand flash中去。
在include/configs/tq2440.h文件中修改:
+ #if NONE_FLAG #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000) #define CONFIG_ENV_IS_IN_FLASH #define CONFIG_ENV_SIZE 0x10000 + #else + #define CONFIG_ENV_IS_IN_NAND + #define CONFIG_ENV_OFFSET 0x40000 /* 256K for u-boot */ + #define CONFIG_ENV_SIZE 0x20000 /* 128K for environment */ + #endif
编译、烧录到SDRAM中去,运行。演示:
*** Warning - bad CRC, using default environment这条提示说明没有没有环境变量,使用默认的环境变量,使用pri查看有哪些环境变量:
[TQ2440 #] pri
baudrate=115200
bootdelay=5
ethact=dm9000
ipaddr=10.0.0.110
netmask=255.255.255.0
serverip=10.0.0.1
stderr=serial
stdin=serial
stdout=serial
使用save命令保存默认的环境变量:
[TQ2440 #] save
Saving Environment to NAND...
Erasing NAND...
Erasing at 0x5c000 -- 100% complete.
Writing to NAND... OK
[TQ2440 #]
[TQ2440 #] nand dump 40000
Page 00040000 dump:
fd 4a d7 7a 62 61 75 64 72 61 74 65 3d 31 31 35
32 30 30 00 62 6f 6f 74 64 65 6c 61 79 3d 35 00
65 74 68 61 63 74 3d 64 6d 39 30 30 30 00 69 70
61 64 64 72 3d 31 30 2e 30 2e 30 2e 31 31 30 00
6e 65 74 6d 61 73 6b 3d 32 35 35 2e 32 35 35 2e
32 35 35 2e 30 00 73 65 72 76 65 72 69 70 3d 31
30 2e 30 2e 30 2e 31 00 73 74 64 65 72 72 3d 73
65 72 69 61 6c 00 73 74 64 69 6e 3d 73 65 72 69
61 6c 00 73 74 64 6f 75 74 3d 73 65 72 69 61 6c
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
再次烧录运行,就没有上面的警告了。在tq2440.h头文件中设置环境变量:
#define CONFIG_NETMASK 255.255.255.0 + #define CONFIG_IPADDR 192.168.169.9 + #define CONFIG_SERVERIP 192.168.169.8 + #define CONFIG_ETHADDR 12:34:56:78:9A:BC
添加mtd分区命令
修改tq2440.h文件,使能该命令宏:
/* * File system */ + #if NONE_FLAG #define CONFIG_CMD_FAT #define CONFIG_CMD_EXT2 #define CONFIG_CMD_UBI #define CONFIG_CMD_UBIFS #define CONFIG_CMD_MTDPARTS #define CONFIG_MTD_DEVICE #define CONFIG_MTD_PARTITIONS #define CONFIG_YAFFS2 #define CONFIG_RBTREE + #else + #define CONFIG_CMD_MTDPARTS + define CONFIG_MTD_DEVICE #endif
编译、烧录到SDRAM中去,运行。演示:
[TQ2440 #] mtd mtdids not defined, no default present上述提示位于common/cmd_mtdparts.c文件1751行
if (mtdids_default) { debug("mtdids variable not defined, using default\n"); ids = mtdids_default; setenv("mtdids", (char *)ids); } else { printf("mtdids not defined, no default present\n"); return 1; }mtdids_default为假时错误打印该条信息,mtdids_default变量在该文件中定义如下:
/* default values for mtdids and mtdparts variables */ #if defined(MTDIDS_DEFAULT) static const char *const mtdids_default = MTDIDS_DEFAULT; #else static const char *const mtdids_default = NULL; #endif #if defined(MTDPARTS_DEFAULT) static const char *const mtdparts_default = MTDPARTS_DEFAULT; #else static const char *const mtdparts_default = NULL; #endif现在这里的mtdids_default=NULL,因为未定义MTDIDS_DEFAULT宏。下面定义MTDIDS_DEFAULT宏和MTDPARTS_DEFAULT宏,参考该文件中最上面注释部分内容:
* Examples:
*
* 1 NOR Flash, with 1 single writable partition:
* mtdids=nor0=edb7312-nor
* mtdparts=mtdparts=edb7312-nor:-
*
* 1 NOR Flash with 2 partitions, 1 NAND with one
* mtdids=nor0=edb7312-nor,nand0=edb7312-nand
* mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
*
*/
在tq2440.h头文件中定义:
#else #define CONFIG_CMD_MTDPARTS #define CONFIG_MTD_DEVICE + #define MTDIDS_DEFAULT "nand0=tq2440-0" + #define MTDPARTS_DEFAULT "mtdparts=tq2440-0:1m(u-boot)," \ + "4m(kernel)," \ + "-(rootfs)" #endif编译、烧录到SDRAM中去,运行。演示:
[TQ2440 #] pri
baudrate=115200
bootdelay=5
ethact=dm9000
ethaddr=12:34:56:78:9A:BC
ipaddr=192.168.169.9
netmask=255.255.255.0
serverip=192.168.169.8
stderr=serial
stdin=serial
stdout=serial
[TQ2440 #] mtdparts
mtdparts variable not set, see 'help mtdparts'
no partitions defined
defaults:
mtdids : nand0=tq2440-0
mtdparts: mtdparts=tq2440-0:1m(u-boot),4m(kernel),-(rootfs)
[TQ2440 #] mtdparts default
[TQ2440 #] save
[TQ2440 #] mtdparts
device nand0 <tq2440-0>, # parts = 3
#: name size offset mask_flags
0: u-boot 0x00100000 0x00000000 0
1: kernel 0x00400000 0x00100000 0
2: rootfs 0x03b00000 0x00500000 0
active partition: nand0,0 - (u-boot) 0x00100000 @ 0x00000000