找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 7613|回复: 6

uboot 中 Nand flash 常用操作命令解释

[复制链接]
发表于 2019-12-27 14:48 | 显示全部楼层 |阅读模式
本帖最后由 jiuweiljp 于 2019-12-27 15:51 编辑

本文基本上抄至网络:
但命令在 wndr 4300 V1 原厂 uboot (
AR9344)的机器上实现
引用博文Url:
https://blog.csdn.net/li_wen01/article/details/88918066
https://www.cnblogs.com/casey/archive/2013/04/17/3027139.html
https://blog.csdn.net/lifengxun20121019/article/details/8659291
--------------------------------------------------

uboot 支持nand flash的数据及oob数据的读写显示操作,也至此手动标记坏块的命令,当一般不建议手动修改flash的坏块标志。
这里介绍在uboot中操作和查看flash数据的常用命令及方法。

说明:
本文测试使用的flash信息如下:
  1. Atheros on-chip NAND FLash Controller Driver, Version 0.1 (c) 2010 Atheros Communications, Ltd.
  2. Ath Nand ID[87ff0178]: 2c:f1:80:95:02
  3. ONFI MICRON      MT29F1G08ABADAWP   
  4. Micron NAND 128MiB 3,3V 8-bit [128MB]
  5. ====== NAND Parameters ======
  6. sc = 0x87ff0158 bbt = 0x87f68008 bbt_size = 0x100 nf_ctrl = 0x344
  7. page = 0x800 block = 0x20000 oob = 0x40
  8. size = 128MB
  9. Setting 0xb8116290 to 0x20402d0f
复制代码

(1)、nand info 查看nandflash 信息
  1. ar7240> nand info
  2. Device 0: ath-nand, sector size 128 KiB
复制代码

(2)、nand device
  1. ar7240> nand device
  2. Device 0: ath-nand
复制代码

(3)、nand read(.oob) [addr] [off] [size]   

     注:这条命令是将nand flash中的内容复制到内存中去

    读取命令,这里是两条命令:
    nand read [addr] [off] [size]
    nand read.oob [addr] [off] [size]

    不管是读取data, 使用nand read,还是读取oob,使用命令nand read.oob, 后面跟的地址addr,都是ram的地址,off:指的是nand flash的地址,

    size:指要读取nand flash的数据大小, 但是如果是读取oob, size不能超过一个page的oob size, 如果page size为512个字节, oob size就是16个字节.
    如果一次想读取完整的一个page 的值,包含oob, 使用下面将的命令, nand dump. (注意这条命令在 4300上无法实现



  1. ar7240>  nand read 0x81000000 0x0 0x1000
  2. NAND read: device 0 offset 0x0, size 4096 ...  4096 bytes read: OK

  3. ar7240> nand read.oob 0x81000000 0x0 0x1000
  4. NAND read: device 0 offset 0x0, size 4096 ...  4096 bytes read: OK
复制代码

注意:在4300的uboot中没有 nand read.oob这个命令,或者说这条命令不起作用,可以执行,但执行结果没有区别
  1. ar7240> mw.b 0x81000000 0xff 0x40000  (将RAM填充256K大小的FF)

  2. ar7240> nand read 0x81000000 0x1000 0x200 (读取nand 中0x1000 处大小为0x200 到ram)
  3. NAND read: device 0 offset 0x1000, size 512 ...  512 bytes read: OK

  4. ar7240> md.b 0x81000000 0x240 (显示RAM中的数据)
  5. 81000000: ae 22 00 00 00 60 f8 09 24 04 00 0a 8e 05 74 a8     ."...`..$.....t.
  6. 81000010: 36 43 00 08 24 02 00 33 ac 62 00 00 00 a0 f8 09     6C..$..3.b......
  7. 81000020: 24 04 00 64 8e 03 74 a8 24 02 00 01 ae 22 00 00     $..d..t.$...."..
  8. 81000030: 00 60 f8 09 24 04 00 0a 8e 03 74 a8 36 42 00 14      .`..$.....t.6B..
  9. 81000040: ac 5e 00 00 00 60 f8 09 24 04 00 64 36 42 00 1c       .^...`..$..d6B..
  10. 81000050: ac 53 00 00 36 43 00 20 3c 04 b8 06 8c 42 00 00    .S..6C. <....B..
  11. 81000060: ac 73 00 00 34 82 00 90 8c 63 00 00 8c 42 00 00    .s..4....c...B..
  12. 81000070: 30 42 00 0f 10 40 00 05 34 82 00 b0 8c 42 00 00    0B...@..4....B..
  13. 81000080: 30 42 00 08 10 40 00 09 3c 11 bd 00 12 80 00 06    0B...@..<.......
  14. 81000090: 36 42 00 24 ac 53 00 00 36 43 00 28 8c 42 00 00    6B.$.S..6C.(.B..
  15. 810000a0: ac 73 00 00 8c 62 00 00 3c 11 bd 00 3c 10 b8 00    .s...b..<...<...
  16. 810000b0: 8e 23 74 a8 36 02 00 18 ac 56 00 00 00 60 f8 09    .#t.6....V...`..
  17. 810000c0: 24 04 00 64 8e 25 74 a8 3c 02 74 44 36 03 00 c4    $..d.%t.<.tD6...
  18. 810000d0: 34 42 44 44 ac 62 00 00 00 a0 f8 09 24 04 00 64    4BDD.b......$..d
  19. 810000e0: 8e 25 74 a8 36 03 00 c8 24 02 02 22 ac 62 00 00    .%t.6...$..".b..
  20. 810000f0: 00 a0 f8 09 24 04 00 64 8e 23 74 a8 3c 02 00 0f    ....$..d.#t.<...
  21. 81000100: 34 42 ff ff 36 10 00 cc ae 02 00 00 00 60 f8 09    4B..6........`..
  22. 81000110: 24 04 00 64 8f bf 00 3c 02 80 10 21 8f be 00 38    $..d...<...!...8
  23. 81000120: 8f b7 00 34 8f b6 00 30 8f b5 00 2c 8f b4 00 28    ...4...0...,...(
  24. 81000130: 8f b3 00 24 8f b2 00 20 8f b1 00 1c 8f b0 00 18    ...$... ........
  25. 81000140: 03 e0 00 08 27 bd 00 40 27 bd ff e8 af bf 00 14    ....'..@'.......
  26. 81000150: 0f 40 13 21 24 04 42 70 3c 04 b8 06 34 86 00 1c    .@.!$.Bp<...4...
  27. 81000160: 8c c3 00 00 00 40 40 21 3c 02 f7 ff 34 42 ff ff    .....@@!<...4B..
  28. 81000170: 00 62 18 24 3c 07 b8 11 3c 02 63 3c 34 42 81 76    .b.[        DISCUZ_CODE_2408        ]lt;...<.c<4B.v
  29. 81000180: 34 e5 6c 40 ac c3 00 00 34 84 00 90 ac a2 00 00    4.l@....4.......
  30. 81000190: 8c 82 00 00 30 42 00 0f 10 40 00 06 34 e3 6c 44    ....0B...@..4.lD
  31. 810001a0: 24 02 00 02 55 02 00 04 3c 02 10 38 0b 40 14 6a    $...U...<..8.@.j
  32. 810001b0: 3c 02 10 00 3c 02 10 38 ac 62 00 00 0f 40 12 c9    <...<..8.b...@..
  33. 810001c0: 00 00 00 00 3c 04 b8 06 34 85 00 1c 8c a2 00 00    ....<...4.......
  34. 810001d0: 24 03 cf ff 34 84 00 b0 00 43 10 24 ac a2 00 00    $...4....C.$....
  35. 810001e0: 8c 82 00 00 30 42 00 10 14 40 00 04 3c 02 b8 05    ....0B...@..<...
  36. 810001f0: 34 42 00 24 0b 40 14 7d 24 03 02 71 34 42 00 24    4B.$.@.}$..q4B.$
  37. 81000200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  38. 81000210: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  39. 81000220: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................


  40. ar7240> mw.b 0x81000000 0xff 0x40000

  41. ar7240> nand read.oob 0x81000000 0x1000 0x200
  42. NAND read: device 0 offset 0x1000, size 512 ...  512 bytes read: OK

  43. ar7240> md.b 0x81000000 0x240
  44. 81000000: ae 22 00 00 00 60 f8 09 24 04 00 0a 8e 05 74 a8    ."...`..$.....t.
  45. 81000010: 36 43 00 08 24 02 00 33 ac 62 00 00 00 a0 f8 09    6C..$..3.b......
  46. 81000020: 24 04 00 64 8e 03 74 a8 24 02 00 01 ae 22 00 00    $..d..t.$...."..
  47. 81000030: 00 60 f8 09 24 04 00 0a 8e 03 74 a8 36 42 00 14    .`..$.....t.6B..
  48. 81000040: ac 5e 00 00 00 60 f8 09 24 04 00 64 36 42 00 1c    .^...`..$..d6B..
  49. 81000050: ac 53 00 00 36 43 00 20 3c 04 b8 06 8c 42 00 00    .S..6C. <....B..
  50. 81000060: ac 73 00 00 34 82 00 90 8c 63 00 00 8c 42 00 00    .s..4....c...B..
  51. 81000070: 30 42 00 0f 10 40 00 05 34 82 00 b0 8c 42 00 00    0B...@..4....B..
  52. 81000080: 30 42 00 08 10 40 00 09 3c 11 bd 00 12 80 00 06    0B...@..<.......
  53. 81000090: 36 42 00 24 ac 53 00 00 36 43 00 28 8c 42 00 00    6B.$.S..6C.(.B..
  54. 810000a0: ac 73 00 00 8c 62 00 00 3c 11 bd 00 3c 10 b8 00    .s...b..<...<...
  55. 810000b0: 8e 23 74 a8 36 02 00 18 ac 56 00 00 00 60 f8 09    .#t.6....V...`..
  56. 810000c0: 24 04 00 64 8e 25 74 a8 3c 02 74 44 36 03 00 c4    $..d.%t.<.tD6...
  57. 810000d0: 34 42 44 44 ac 62 00 00 00 a0 f8 09 24 04 00 64    4BDD.b......$..d
  58. 810000e0: 8e 25 74 a8 36 03 00 c8 24 02 02 22 ac 62 00 00    .%t.6...$..".b..
  59. 810000f0: 00 a0 f8 09 24 04 00 64 8e 23 74 a8 3c 02 00 0f    ....$..d.#t.<...
  60. 81000100: 34 42 ff ff 36 10 00 cc ae 02 00 00 00 60 f8 09    4B..6........`..
  61. 81000110: 24 04 00 64 8f bf 00 3c 02 80 10 21 8f be 00 38    $..d...<...!...8
  62. 81000120: 8f b7 00 34 8f b6 00 30 8f b5 00 2c 8f b4 00 28    ...4...0...,...(
  63. 81000130: 8f b3 00 24 8f b2 00 20 8f b1 00 1c 8f b0 00 18    ...$... ........
  64. 81000140: 03 e0 00 08 27 bd 00 40 27 bd ff e8 af bf 00 14    ....'..@'.......
  65. 81000150: 0f 40 13 21 24 04 42 70 3c 04 b8 06 34 86 00 1c    .@.!$.Bp<...4...
  66. 81000160: 8c c3 00 00 00 40 40 21 3c 02 f7 ff 34 42 ff ff    .....@@!<...4B..
  67. 81000170: 00 62 18 24 3c 07 b8 11 3c 02 63 3c 34 42 81 76    .b.[        DISCUZ_CODE_2408        ]lt;...<.c<4B.v
  68. 81000180: 34 e5 6c 40 ac c3 00 00 34 84 00 90 ac a2 00 00    4.l@....4.......
  69. 81000190: 8c 82 00 00 30 42 00 0f 10 40 00 06 34 e3 6c 44    ....0B...@..4.lD
  70. 810001a0: 24 02 00 02 55 02 00 04 3c 02 10 38 0b 40 14 6a    $...U...<..8.@.j
  71. 810001b0: 3c 02 10 00 3c 02 10 38 ac 62 00 00 0f 40 12 c9    <...<..8.b...@..
  72. 810001c0: 00 00 00 00 3c 04 b8 06 34 85 00 1c 8c a2 00 00    ....<...4.......
  73. 810001d0: 24 03 cf ff 34 84 00 b0 00 43 10 24 ac a2 00 00    $...4....C.$....
  74. 810001e0: 8c 82 00 00 30 42 00 10 14 40 00 04 3c 02 b8 05    ....0B...@..<...
  75. 810001f0: 34 42 00 24 0b 40 14 7d 24 03 02 71 34 42 00 24    4B.$.@.}$..q4B.$
  76. 81000200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  77. 81000210: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  78. 81000220: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  79. 81000230: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................

复制代码
另外:4300 中多了几条命令nand read.jffs2 和 nand write.jffs2
  1. nand read[.jffs2]     - addr off size
  2. nand write[.jffs2]    - addr off size - read/write `size' bytes starting
  3.     at offset `off' to/from memory address `addr'
复制代码
baidu查询:(我没有用过不知道,这只是查询结果)
------------------------------------------------------
使用uboot  写nand flash 是不需要FS支持的,但是我查看 uboot 源代码的时候,发现这行 "nand write.jffs2 xxxxx.." jffs 是一个文件系统,这是为什么呢?

nand write:向Nand Flash写入数据,如果NandFlash相应的区域有坏块,则直接报错。
nand write.jffs2:向Nand Flash写入数据,如果NandFlash相应的区域有坏块,可以跳过坏块。
nand read:读取Nand Flash相应区域的数据,如果NandFlash相应的区域有坏块,则直接报错。
nand read.jffs2s:读取Nand Flash相应区域的数据,如果NandFlash相应的区域有坏块,将对应坏块区域的缓冲填充0xff,然后跳过此坏块继续读取。
nand read.jffs2:读取Nand Flash相应区域的数据,如果NandFlash相应的区域有坏块,直接跳过坏块。

由此,我们得出结论,nand write 和 nand write.jffs2 没有本质区别,只是对坏快的处理稍微不同而已!

--------------------------------------------------------------
(4)、nand dump [addr] [size]      
       读取flash addr地址开始的size 大小数据出来。最小单位是一个page.也就是说size小于一个page,也会读出一个page的数据。该数据包括oob数据。

       注:这个读取应该是显示的意思

       调用过程: nand dump addr size (common/cmd_nand.c)==> nand_dump() ==> nand_read_raw();
       nand dump 不管你的size有多大,至少会dump出一个page的大小:

可以看到

nand dump 0x0 0x1
nand dump 0x1 0x7ff
执行结果相同
另外:可以发现在4300上1个page是2Kbye 大小)

  1. ar7240> nand dump 0x0 0x1
  2. Page 00000000 dump:
  3.         bd 00 40 00 bd 00 40 00  00 00 30 00 c2 00 e8 6c
  4.         27 bd ff e0 af b1 00 18  3c 11 b8 06 36 22 00 90
  5.         ......
  6.         00 00 00 00 00 00 00 00  3c 0c 41 c0 3c 0d 42 80
  7.         0b 40 12 00 00 00 00 00  00 00 00 00 3c 0c 29 c0
  8. OOB:
  9.         ff ff ff ff ff ff ff ff
  10.         ff ff ff ff ff ff ff ff
  11.         ff ff ff ff 3c 97 45 9d
  12.         31 0c 8e 12 50 a1 eb 4d
  13.         3f 54 01 16 f6 a9 21 c9
  14.         0f f1 c8 08 0f 10 73 c6
  15.         ff ff ff ff ff ff ff ff
  16.         ff ff ff ff ff ff ff ff
  17.                
  18. ar7240> nand dump 0x1 0x7ff
  19. Page 00000000 dump:
  20.         bd 00 40 00 bd 00 40 00  00 00 30 00 c2 00 e8 6c
  21.         27 bd ff e0 af b1 00 18  3c 11 b8 06 36 22 00 90
  22.         ......
  23.         00 00 00 00 00 00 00 00  3c 0c 41 c0 3c 0d 42 80
  24.         0b 40 12 00 00 00 00 00  00 00 00 00 3c 0c 29 c0
  25. OOB:
  26.         ff ff ff ff ff ff ff ff
  27.         ff ff ff ff ff ff ff ff
  28.         ff ff ff ff 3c 97 45 9d
  29.         31 0c 8e 12 50 a1 eb 4d
  30.         3f 54 01 16 f6 a9 21 c9
  31.         0f f1 c8 08 0f 10 73 c6
  32.         ff ff ff ff ff ff ff ff
  33.         ff ff ff ff ff ff ff ff
复制代码
另外我也执行了
nand dump 0x0 0x1000
道理说应该能显示2个page 但实际结果只显示了1个page,谁知道呢我也不太懂

  1. ar7240> nand dump 0x0 0x1000
  2. Page 00000000 dump:
  3.         bd 00 40 00 bd 00 40 00  00 00 30 00 c2 00 e8 6c
  4.         27 bd ff e0 af b1 00 18  3c 11 b8 06 36 22 00 90
  5.         ......
  6.         00 00 00 00 00 00 00 00  3c 0c 41 c0 3c 0d 42 80
  7.         0b 40 12 00 00 00 00 00  00 00 00 00 3c 0c 29 c0
  8. OOB:
  9.         ff ff ff ff ff ff ff ff
  10.         ff ff ff ff ff ff ff ff
  11.         ff ff ff ff 3c 97 45 9d
  12.         31 0c 8e 12 50 a1 eb 4d
  13.         3f 54 01 16 f6 a9 21 c9
  14.         0f f1 c8 08 0f 10 73 c6
  15.         ff ff ff ff ff ff ff ff
  16.         ff ff ff ff ff ff ff ff
复制代码

如果在地址0x800 处执行,结果就不同了,显示了下一个page


  1. ar7240> nand dump 0x800 0x1
  2. Page 00000800 dump:
  3.         3c 0d 2a 80 0b 40 12 00  00 00 00 00 00 00 00 00
  4.         3c 19 bd 00 37 39 00 04  af 20 00 00 3c 19 bd 00
  5.         ......
  6.         8e 03 74 a8 36 51 00 10  24 02 00 02 ae 22 00 00
  7.         00 60 f8 09 24 04 00 0a  8e 03 74 a8 24 02 00 08
  8. OOB:
  9.         ff ff ff ff ff ff ff ff
  10.         ff ff ff ff ff ff ff ff
  11.         ff ff ff ff 0c de e5 e6
  12.         6b 0a 01 36 d4 52 cd dc
  13.         16 bd 0d 56 37 d6 36 4d
  14.         ee f2 4a 0c 01 09 64 88
  15.         ff ff ff ff ff ff ff ff
  16.         ff ff ff ff ff ff ff ff
复制代码

在这个机器上多了个命令
nand dump[.oob] off - dump page
这个命令是只显示 oob的,按page显示
  1. ar7240> nand dump.oob 0x0
  2. Page 00000000 dump:
  3. OOB:
  4.         ff ff ff ff ff ff ff ff
  5.         ff ff ff ff ff ff ff ff
  6.         ff ff ff ff 3c 97 45 9d
  7.         31 0c 8e 12 50 a1 eb 4d
  8.         3f 54 01 16 f6 a9 21 c9
  9.         0f f1 c8 08 0f 10 73 c6
  10.         ff ff ff ff ff ff ff ff
  11.         ff ff ff ff ff ff ff ff
  12. ar7240> nand dump.oob 0x800
  13. Page 00000800 dump:
  14. OOB:
  15.         ff ff ff ff ff ff ff ff
  16.         ff ff ff ff ff ff ff ff
  17.         ff ff ff ff 0c de e5 e6
  18.         6b 0a 01 36 d4 52 cd dc
  19.         16 bd 0d 56 37 d6 36 4d
  20.         ee f2 4a 0c 01 09 64 88
  21.         ff ff ff ff ff ff ff ff
  22.         ff ff ff ff ff ff ff ff
  23. ar7240> nand dump.oob 0x1000
  24. Page 00001000 dump:
  25. OOB:
  26.         ff ff ff ff ff ff ff ff
  27.         ff ff ff ff ff ff ff ff
  28.         ff ff ff ff f7 64 95 01
  29.         65 0a b9 73 dc d8 c8 43
  30.         9b a1 04 7b fc 94 35 82
  31.         49 b9 7a 08 09 c2 f2 6a
  32.         ff ff ff ff ff ff ff ff
  33.         ff ff ff ff ff ff ff ff
复制代码

(5)、nand write [addr] [off] [size]      
   
     这个命令和nand read一样, 只是方向是反的, 是把ram的值写到 nand flash中, 但是这个写只能将1改为0, 不能将0写成1. 这个命令会自动skipping bad blocks(会自动跳过坏块)。

    注:如果按照上文的解释,刷nand flash之前一定要用擦除命令(后文会讲到)


(6)、nand erase/clean [off] [size]    清除flash off偏移地址开始的size大小的数据,最小单位是一个page。
    在擦之前会先check是不是坏块,如果是坏块,就不能做擦的动作了。(这个动作不清楚不知道会不会check

(7)、nand bad        
   检查nand 中的坏块(这个命令在引用的博文中没有讲到,4300 uboot有我就提一下)
  1. ar7240> nand bad
  2. Device 0 bad blocks:
复制代码
(8)、其它命令 (这个命令用的很少,且不安全(应该是不可靠的意思)能不用就不用吧)
  1. nand scrub - really clean NAND erasing bad blocks (UNSAFE)
  2. nand markbad off - mark bad block at offset (UNSAFE)
  3. nand biterr off - make a bit error at offset (UNSAFE)
复制代码
特别提醒:
       在原博文中uboot 中Nand flash 常用操作命令解析  第三节有数据显示命令,这个数据在内存中与在flash中存储结构是不同的。
         应该是cpu 大端、小端的原因 (32位翻转)      
         falsh 中
为 “27 05 19 56” 内存中为“56 19 05 27”
  1. --------------------------------------
  2. nand dump 0 100
  3.     直接输出flash 0地址开始的0x100字节数据及它所在page的OOB数据。从实际输出我们可以看出它实际输出了一个page 的数据。
  4. Wisdom #
  5. Wisdom #
  6. isdom # nand dump 0x100000 0x100  (falsh 数据显示)
  7. Page 00100000 dump:
  8.         27 05 19 56 11 f0 e6 37  5c 97 4f bc 00 30 ae e8
  9.         80 00 80 00 80 00 80 00  e9 70 d4 3f 05 02 02 00
  10. --------------------------------
  11. Wisdom # nand read 0x82000000 0x100000 0x100
  12. NAND read: device 0 offset 0x100000, size 0x100
  13. 256 bytes read: OK
  14. Wisdom # md 0x82000000 50  (内存 数据显示)
  15. 82000000: 56190527 37e6f011 bc4f975c e8ae3000    '..V...7\.O..0..
  16. 82000010: 00800080 00800080 3fd470e9 00020205    .........p.?....
复制代码
这儿现象在4300的机器上,字节没有翻转,4300用的是ar9344 的cpu 大端的
  1. ar7240> nand dump 0x0 0x800
  2. Page 00000000 dump:
  3.         bd 00 40 00 bd 00 40 00  00 00 30 00 c2 00 e8 6c
  4.         27 bd ff e0 af b1 00 18  3c 11 b8 06 36 22 00 90
  5.         ......
  6.         00 00 00 00 00 00 00 00  3c 0c 41 c0 3c 0d 42 80
  7.         0b 40 12 00 00 00 00 00  00 00 00 00 3c 0c 29 c0
  8. OOB:
  9.         ff ff ff ff ff ff ff ff
  10.         ff ff ff ff ff ff ff ff
  11.         ff ff ff ff 3c 97 45 9d
  12.         31 0c 8e 12 50 a1 eb 4d
  13.         3f 54 01 16 f6 a9 21 c9
  14.         0f f1 c8 08 0f 10 73 c6
  15.         ff ff ff ff ff ff ff ff
  16.         ff ff ff ff ff ff ff ff
  17.                
  18. ar7240> mw.b 0x81000000 0xff 0x40000

  19. ar7240> nand read 0x81000000 0x0 0x800
  20. NAND read: device 0 offset 0x0, size 2048 ...  2048 bytes read: OK

  21. ar7240> md.b 0x81000000 0x800
  22. 81000000: bd 00 40 00 bd 00 40 00 00 00 30 00 c2 00 e8 6c    ..@...@...0....l
  23. 81000010: 27 bd ff e0 af b1 00 18 3c 11 b8 06 36 22 00 90    '.......<...6"..
  24.           ......
  25. 810007e0: 00 00 00 00 00 00 00 00 3c 0c 41 c0 3c 0d 42 80    ........<.A.<.B.
  26. 810007f0: 0b 40 12 00 00 00 00 00 00 00 00 00 3c 0c 29 c0    .@..........<.).
复制代码


我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2019-12-27 14:49 | 显示全部楼层
本帖最后由 jiuweiljp 于 2019-12-27 15:42 编辑

实战一把:刷4300 nand flash 中的uboot ,操作有危险,没有装双flash的朋友请谨慎对待

1、显示环境变量,看看本机ip及tftp的ip
  1. ar7240> printenv
  2. bootargs=console=ttyS0,115200 root=31:03 rootfstype=jffs2 init=/sbin/init mtdparts=ath-nand:128k(u-boot),384k(u-boot-env),1280k(uImage),7m(rootfs),128k(dummy),128k(caldata)
  3. bootcmd=nmrp;if loadn_dniimg 0 0x6c0000 0x81000000 && chk_dniimg 0x81000000; then bootm 0x81000000;else fw_recovery; fi
  4. baudrate=115200
  5. ethaddr=0x00:0xaa:0xbb:0xcc:0xdd:0xee
  6. ipaddr=192.168.1.1
  7. serverip=192.168.1.7
  8. dir=
  9. lu=tftp 0x80060000 ${dir}2fw.bin&&nand erase 0x0 0x20000&&nand write $fileaddr 0x0 $filesize
  10. lf=tftp 0x80060000 ${dir}db12x${bc}-nand-jffs2${ns}&&nand erase 0x1c0000 0x700000&&nand write $fileaddr 0x1c0000 $filesize
  11. lk=tftp 0x80060000 ${dir}vmlinux${bc}.lzma.uImage&&nand erase 0x80000 0x140000&&nand write $fileaddr 0x80000 $filesize
  12. stdin=serial
  13. stdout=serial
  14. stderr=serial
  15. bootdelay=2
  16. ethact=eth0
复制代码
2、setenv serverip 192.168.1.10 设置tftp 服务器ip
  1. setenv serverip 192.168.1.10
复制代码
3、将tftp 服务器架设好了后,将文件载入内存
  1. ar7240> tftp 0x81000000 u-boot-wndr4300-v1-factory.bin
  2. Using eth0 device
  3. TFTP from server 192.168.1.10; our IP address is 192.168.1.1
  4. Filename 'u-boot-wndr4300-v1-factory.bin'.
  5. Load address: 0x81000000
  6. Loading: ####################################################
  7. done
  8. Bytes transferred = 262144 (40000 hex)
复制代码
4、擦除nand flash
注:起始地址为0x0 大小为0x40000 也就是上一条命令中的(40000 hex)
  1. ar7240> nand erase 0x0 0x40000
  2. NAND erase: device 0 offset 0x0, size 0x40000 ath_nand_erase: 0x0 2
  3.    1Skipped 0 bad blocks

  4. OK
复制代码
5、查看擦除结果 必须为全FF
  1. ar7240> nand dump 0x0
  2. Page 00000000 dump:
  3.         ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff
  4.         ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff
  5.         ......
  6.         ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff
  7.         ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff
  8. OOB:
  9.         ff ff ff ff ff ff ff ff
  10.         ff ff ff ff ff ff ff ff
  11.         ff ff ff ff ff ff ff ff
  12.         ff ff ff ff ff ff ff ff
  13.         ff ff ff ff ff ff ff ff
  14.         ff ff ff ff ff ff ff ff
  15.         ff ff ff ff ff ff ff ff
  16.         ff ff ff ff ff ff ff ff
复制代码
6、将内存中的数据写到nand flash 中
  1. ar7240> nand write 0x81000000 0x0 0x40000

  2. NAND write: device 0 offset 0x0, size 262144 ...  262144 bytes written: OK
复制代码
7、查看写进nand 中的结果
  1. ar7240> nand dump 0x0
  2. Page 00000000 dump:
  3.         bd 00 40 00 bd 00 40 00  00 00 30 00 c2 00 e8 6c
  4.         27 bd ff e0 af b1 00 18  3c 11 b8 06 36 22 00 90
  5.         ......
  6.         00 00 00 00 00 00 00 00  3c 0c 41 c0 3c 0d 42 80
  7.         0b 40 12 00 00 00 00 00  00 00 00 00 3c 0c 29 c0
  8. OOB:
  9.         ff ff ff ff ff ff ff ff
  10.         ff ff ff ff ff ff ff ff
  11.         ff ff ff ff 3c 97 45 9d
  12.         31 0c 8e 12 50 a1 eb 4d
  13.         3f 54 01 16 f6 a9 21 c9
  14.         0f f1 c8 08 0f 10 73 c6
  15.         ff ff ff ff ff ff ff ff
  16.         ff ff ff ff ff ff ff ff
复制代码
注:nand flash 没有比较命令,所以操作要小心点

我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-12-27 15:13 | 显示全部楼层
不错,学习下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2019-12-27 16:03 | 显示全部楼层
可能有朋友问用nand启动后能不能对spi进行操作呢。
答案是:可以看,但不能写。
  1. ar7240> md.b 0x9f000000 0x600
  2. 9f000000: 10 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00    ................
  3. 9f000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  4. ................
  5. 9f0005e0: 00 00 00 00 8f bc 00 10 3c 02 37 54 24 42 01 78    ........<.7T$B.x
  6. 9f0005f0: 8f a3 00 18 10 62 00 04 26 44 00 10 8f 90 00 08    .....b..&D......
复制代码
因为4300 nand的uboot 中没有对spi专门的擦除命令只有用mw 试试看了
  1. mw.b 0x9f000000 0xff 0x600
复制代码
结果很悲催
  1. 9f000000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  2. 9f000010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  3. ......
  4. 9f000130: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  5. 9f000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  6. 9f000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  7. 9f000160: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  8. ......
  9. 9f000230: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  10. 9f000240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  11. 9f000250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  12. 9f000260: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  13. 9f000270: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  14. 9f000280: 10 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00    ................
  15. 9f000290: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  16. 9f0002a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
  17. ......
  18. 9f0005f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
复制代码
写FF结果都不对
重启4300后,发现spi中内容没有任何变化

看来这个4300 nand Uboot将spi flash的命令删除了,没有办法操作 spi flash


点评

你说的很对,我赞同你的说法。: 5.0
你说的很对,我赞同你的说法。: 5
  发表于 2019-12-27 18:45
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-12-27 18:44 | 显示全部楼层
顶,高人!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2024-4-6 09:23 | 显示全部楼层
感谢分享。
有基础才能玩好设备。
不然只能依葫芦画瓢。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-23 23:10

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表