若文件系统或者内核在用户态完成升级后(升级到新的分区),uboot启动需要修改环境变量,所以有了今天的内容
1.uboot中定义了#define CFG_ENV_OFFSET 0x00100000,环境变量存放位置,#define CFG_ENV_SIZE 0x4000 环境变量大小(实际用到的没有这么大),这个flash一 个page是0x800,那么就把数据存放在0x00100800的位置
2.修改内核mtd配置,.mask_flags = MTD_CAP_NANDFLASH =》.mask_flags=0, 使分区可写,否则用户态擦写会出错
[root@EmbedSky arm-linux]# ./flash_erase /dev/mtd1 0 0
flash_erase: error!: /dev/mtd1
error 13 (Permission denied
3.将数据在用户态写进去,再启动uboot把数据读出来就完成了
首先准备数据,1.bin: 内容很简单 12345,
烧写数据
[root@EmbedSky /]# cd /home/arm-linux/
[root@EmbedSky arm-linux]# ./flash_erase /dev/mtd0 0x100800 1
//首先格式化为FF Erasing 128 Kibyte @ 100000 -- 100 % complete
[root@EmbedSky arm-linux]# ./nanddump -s 0x100800 -l 1 -f 1.txt /dev/mtd0
//导出数据看看是否都为FF,ECC failed: 0
ECC corrected: 0
Number of bad blocks: 0
Number of bbt blocks: 0
Block size 131072, page size 2048, OOB size 64
Dumping data starting at 0x00100800 and ending at 0x00100801...
[root@EmbedSky arm-linux]# ./nandwrite --help
Usage: nandwrite [OPTION] MTD_DEVICE [INPUTFILE|-]
Writes to the specified MTD device.
-a, --autoplace Use auto OOB layout
-m, --markbad Mark blocks bad if write fails
-n, --noecc Write without ecc
-N, --noskipbad Write without bad block skipping
-o, --oob Input contains oob data
-O, --onlyoob Input contains oob data and only write the oob part
-s addr, --start=addr Set output start address (default is 0)
-p, --pad Pad writes to page size
-b, --blockalign=1|2|4 Set multiple of eraseblocks to align to
--input-skip=length Skip |length| bytes of the input file
--input-size=length Only read |length| bytes of the input file
-q, --quiet Don't display progress messages
-h, --help Display this help and exit
--version Output version information and exit
[root@EmbedSky arm-linux]# ./nandwrite -p -s 0x100800 /dev/mtd0 1.bin
Writing data to block 8 at offset 0x100000
len:2048,oob:0,eb:8,mtd->eb_size:131072,offs:2048,seek:1074318008
[root@EmbedSky arm-linux]# ./nanddump -s 0x100800 -l 10 -f 2.txt /dev/mtd0
//烧写数据,就写10个字节,ECC failed: 0
ECC corrected: 0
Number of bad blocks: 0
Number of bbt blocks: 0
Block size 131072, page size 2048, OOB size 64
Dumping data starting at 0x00100800 and ending at 0x0010080a...
[root@EmbedSky arm-linux]# disconnect::Already Disconnected..