uboot 下nor flash 读写命令使用和验证方法
1 uboot下sf命令
1.1 uboot下sf命令集合
# sf
sf - SPI flash sub-system
Usage:
sf probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus
and chip select
sf read addr offset|partition len - read `len' bytes starting at
`offset' or from start of mtd
`partition'to memory at `addr'
sf write addr offset|partition len - write `len' bytes from memory
at `addr' to flash at `offset'
or to start of mtd `partition'
sf erase offset|partition [+]len - erase `len' bytes from `offset'
or from start of mtd `partition'
`+len' round up `len' to block size
sf update addr offset|partition len - erase and write `len' bytes from memory
at `addr' to flash at `offset'
or to start of mtd `partition'
sf protect lock/unlock sector len - protect/unprotect 'len' bytes starting
at address 'sector'
sf test offset len - run a very basic destructive test
#
1.2 sf probe
sf probe
是用来探测flash设备的,在使用的时候可以直接使用sf probe
后面不加参数也可以。
sf probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus
1.3 sf read
sf read是将从flash offset地址处的flash数据存放到addr内存地址处,所以此处addr要求为一个有效的内存地址,读取的数据长度为len,此处的len被识别为是16进制数据
sf read addr offset|partition len - read `len' bytes starting at
`offset' or from start of mtd
`partition'to memory at `addr'
1.4 sf write
sf read是将从内存addr地址处的内存数据写到flash offset地址处,所以此处addr要求为一个有效的内存地址,写入的数据长度为len,此处的len被识别为是16进制数据
sf write addr offset|partition len - write `len' bytes from memory
at `addr' to flash at `offset'
or to start of mtd `partition'
1.5 sf erase
该命令是将从flash offset地址开始,长度为len的flash空间擦除,需要注意的地方是该处的len需要是erase_size的整数倍才被允许执行擦除动作。
sf erase offset|partition [+]len - erase `len' bytes from `offset'
or from start of mtd `partition'
`+len' round up `len' to block size
2 验证nor flash读写结果正确性
需要注意的一点是nor flash在执行写之前需要先执行擦除操作,否则会提示数据写入失败。
/* 2.1 sf probe 探测设备 */
sf probe
/* 2.2 将从0x10000000内存地址处开始的0x2000的长度的存储空间都写为ab */
mw.b 10000000 ab 2000
/* 2.3 sf erase 擦除nor flash空间 */
sf erase 0 2000 /* 从nor flash 0地址开始的0x2000长度的空间都执行擦除处理 */
/* 2.4 sf write 写nor flash */
sf write 10000000 0 2000 /* 将0x10000000 内存地址处的长度为0x2000的内存数据写入到nor flash 0地址处 */
/* 2.5 sf read 读nor flash */
sf read 12000000 0 2000 /* 将nor flash地址0处,长度为0x2000的内容读出来放到内存0x12000000地址处 */
/* 2.6 比对写入的数据和读出来的数据是否一致 */
cmp 0x10000000 0x12000000 0x20000
3 在处理的时候需要注意的点
3.1 sf read/write addr
在执行sf read/write的时候,addr必须是一个有效的内存地址,否则在执行读写的时候会触发系统的异常。
3.2 len/addr 数据格式
sf 命令的数据默认是按照16进制去处理的,即使在写的len以及addr不加十六进制的标识也会被识别为十六进制,这点也是需要注意的。