linux用户态下写flash数据,共享给uboot

若文件系统或者内核在用户态完成升级后(升级到新的分区),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.. 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值