一.保存环境变量到nand flash
第一步:修改mini2440.h
由于我们执行saveenv这个命令,然后保存环境变量,u-boot的命令都是在common下实现的,切进去执行gerp “saveenv” –nr ./*.c,查找出如下结果:
这里出现了很多,打开Makefile:
# environment
obj-y += env_attr.o
obj-y += env_callback.o
obj-y += env_flags.o
obj-$(CONFIG_ENV_IS_IN_DATAFLASH) +=env_dataflash.o
obj-$(CONFIG_ENV_IS_IN_EEPROM) +=env_eeprom.o
extra-$(CONFIG_ENV_IS_EMBEDDED) +=env_embedded.o
obj-$(CONFIG_ENV_IS_IN_EEPROM) +=env_embedded.o
extra-$(CONFIG_ENV_IS_IN_FLASH) +=env_embedded.o
obj-$(CONFIG_ENV_IS_IN_NVRAM) +=env_embedded.o
obj-$(CONFIG_ENV_IS_IN_FLASH) +=env_flash.o
obj-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o
obj-$(CONFIG_ENV_IS_IN_FAT) += env_fat.o
obj-$(CONFIG_ENV_IS_IN_NAND) +=env_nand.o
obj-$(CONFIG_ENV_IS_IN_NVRAM) +=env_nvram.o
obj-$(CONFIG_ENV_IS_IN_ONENAND) +=env_onenand.o
obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) +=env_sf.o
obj-$(CONFIG_ENV_IS_IN_REMOTE) +=env_remote.o
obj-$(CONFIG_ENV_IS_IN_UBI) += env_ubi.o
obj-$(CONFIG_ENV_IS_NOWHERE) +=env_nowhere.o
查找会发现,env_flash.c和env_nand.c是分别保存nor和nand的命令函数。
打开/include/configs/mini2440.h,第172行,注释掉为nor保存环境变量的宏,定义保存到nand,修改如下:
#if 0
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE +0x070000)
#define CONFIG_ENV_IS_IN_FLASH
#define CONFIG_ENV_SIZE 0x10000
#endif
#define CONFIG_ENV_IS_IN_NAND
#define CONFIG_ENV_OFFSET0X40000//256k for u-boot
#define CONFIG_ENV_SIZE 0x20000//128k for env
/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE
第二步:编译测试
从nor 启动,下载到nand,再从nand启动,输入saveenv,出现如下信息:
MINI2440 Deep_l_zh # saveenv
Saving Environment to NAND...
Erasing NAND...
Erasing at 0x40000 -- 100% complete.
Writing to NAND... OK
MINI2440 Deep_l_zh #
说明我们的环境变量保存进去了。。。
二.添加mtd分区
修改mini2440.h
主要是打开被注释掉的配置,第222行添加:
#define CONFIG_CMD_MTDPARTS
#define CONFIG_MTD_DEVICE
#define MTDIDS_DEFAULT"nand0=mini2440-0"
#define MTDPARTS_DEFAULT"mtdparts=mini2440-0:1m(u-boot),"\
"1m(params),"\
"3m(kernel),"\
"-(rootfs)"
再修改下默认的环境变量,根据自己的开发板和虚拟机做设置,我这里修改如下:
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 192.168.1.226
#define CONFIG_SERVERIP 192.168.1.122
#define CONFIG_ETHADDR 08:08:11:18:12:27
#define CONFIG_BOOTARGS"console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.122:/opt/rootfsip=192.168.1.111:192.168.1.122:192.168.1.122:255.255.255.0:SMDK2440A.arm9.net:eth0:off"
#define CONFIG_BOOTCOMMAND"nand read 0x30008000 kernel\;bootm 0x30008000"
编译下载,从nor 启动:
nand erase 0 0x40000
tftp 0x30008000 u-boot.bin
nand write 0x30008000 0 0x40000
然后关闭开发板,从nand启动,输入:
mtdparts default
save
mtdparts
这时候输出如下信息:
MINI2440 Deep_l_zh # mtdparts default
MINI2440 Deep_l_zh # save
Saving Environment to NAND...
Erasing NAND...
Erasing at 0x40000 -- 100% complete.
Writing to NAND... OK
MINI2440 Deep_l_zh # mtdparts
device nand0 <mini2440-0>, # parts =4
#:name size offset mask_flags
0:u-boot 0x00100000 0x00000000 0
1:params 0x00100000 0x00100000 0
2:kernel 0x00300000 0x00200000 0
3:rootfs 0x0fb00000 0x00500000 0
active partition: nand0,0 - (u-boot)0x00100000 @ 0x00000000
defaults:
mtdids : nand0=mini2440-0
mtdparts: mtdparts=mini2440-0:1m(u-boot),1m(params),3m(kernel),-(rootfs)
MINI2440 Deep_l_zh #
说明我们的分区已经成功了,这时候打印环境变量:printenv,输出如下信息:
baudrate=115200
bootargs=console=tty0 console=ttySAC0root=/dev/nfs nfsroot=192.168.1.122:/opt/rootfsip=192.168.1.111:192.168.1.122:192.168.1.122:255.255.255.0:SMDK2440A.arm9.net:eth0:off
bootcmd=nand read 0x30008000 60000500000;bootm 0x30008000
bootdelay=3
embedclub=bmp d 70000
ethact=dm9000
ethaddr=08:08:11:18:12:27
gatewayip=192.168.1.1
ipaddr=192.168.1.226
lcdtype=w
mtddevname=u-boot
mtddevnum=0
mtdids=nand0=mini2440-0
mtdparts=mtdparts=mini2440-0:1m(u-boot),1m(params),3m(kernel),-(rootfs)
netmask=255.255.255.0
partition=nand0,0
serverip=192.168.1.122
stderr=serial
stdin=serial
stdout=serial
说明刚才更改的环境变量也已经生效了。。。
这里我们并没有定义很多环境变量,却出现了,我猜测是因为我之前的u-boot保存的环境变量,这里我我们执行nand scrub,将nand清理一下。然后再把u-boot烧写进去。看看:
nand scrub
nand erase 0 0x4000
tftp 0x30008000 u-boot.bin
nand write 0x30008000 0 0x40000
从nand启动:
saveenv
printenv
MINI2440 Deep_l_zh # printenv
baudrate=115200
bootargs=console=ttySAC0 root=/dev/nfsnfsroot=192.168.1.122:/opt/rootfsip=192.168.1.111:192.168.1.122:192.168.1.122:255.255.255.0:SMDK2440A.arm9.net:eth0:off
bootcmd=nand read 0x30008000 kernel;bootm0x30008000
bootdelay=5
ethact=dm9000
ethaddr=08:08:11:18:12:27
ipaddr=192.168.1.226
netmask=255.255.255.0
serverip=192.168.1.122
stderr=serial
stdin=serial
stdout=serial
Environment size: 413/131068 bytes
MINI2440 Deep_l_zh #
这里就是我们的环境变凉了,自己添加进去的。再看看分区:
mtdparts default
save
mtdparts
输出信息正常,移植结束。