SPI NOR 框架

如何建议添加新的闪存

大多数 SPI NOR 闪存都符合 JEDEC JESD216 串行闪存可发现参数 (SFDP) 标准。SFDP 在一组标准的内部只读参数表中描述了串行闪存设备的功能和特性。

SPI NOR 驱动程序查询 SFDP 表,以确定闪存的参数和设置。如果闪存定义了 SFDP 表,则很可能根本不需要闪存条目,而是依赖于通用闪存驱动程序,该驱动程序仅基于其 SFDP 数据探测闪存。只需在设备树中指定“jedec,spi-nor”兼容即可。

在某些情况下,您需要定义一个显式的闪存条目。当闪存具有 SFDP 表未涵盖的设置或支持(例如,块保护)时,或者当闪存包含损坏的 SFDP 数据时,通常会发生这种情况。如果属于后者,则需要实现 spi_nor_fixups 钩子,以便使用正确的值修改 SFDP 参数。

最低测试要求

执行以下所有测试,并在提交的注释部分中粘贴它们,在 --- 标记之后。

  1. 指定用于测试闪存的控制器,并指定闪存的运行频率,例如

    This flash is populated on the X board and was tested at Y
    frequency using the Z (put compatible) SPI controller.
    
  2. 转储 sysfs 条目并打印 md5/sha1/sha256 SFDP 校验和

    root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/partname
    sst26vf064b
    root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id
    bf2643
    root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer
    sst
    root@1:~# xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
    53464450060102ff00060110300000ff81000106000100ffbf0001180002
    0001fffffffffffffffffffffffffffffffffd20f1ffffffff0344eb086b
    083b80bbfeffffffffff00ffffff440b0c200dd80fd810d820914824806f
    1d81ed0f773830b030b0f7ffffff29c25cfff030c080ffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffff0004fff37f0000f57f0000f9ff
    7d00f57f0000f37f0000ffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
    ffffbf2643ffb95ffdff30f260f332ff0a122346ff0f19320f1919ffffff
    ffffffff00669938ff05013506040232b03072428de89888a585c09faf5a
    ffff06ec060c0003080bffffffffff07ffff0202ff060300fdfd040700fc
    0300fefe0202070e
    root@1:~# sha256sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
    428f34d0461876f189ac97f93e68a05fa6428c6650b3b7baf736a921e5898ed1  /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
    

    请使用 xxd -p 转储 SFDP 表。它使我们能够进行反向操作,并使用 xxd -rp 将十六进制转储转换为二进制。接受使用 hexdump -Cv 转储 SFDP 数据,但不太理想。

  3. 转储 debugfs 数据

    root@1:~# cat /sys/kernel/debug/spi-nor/spi0.0/capabilities
    Supported read modes by the flash
     1S-1S-1S
      opcode            0x03
      mode cycles       0
      dummy cycles      0
     1S-1S-1S (fast read)
      opcode            0x0b
      mode cycles       0
      dummy cycles      8
     1S-1S-2S
      opcode            0x3b
      mode cycles       0
      dummy cycles      8
     1S-2S-2S
      opcode            0xbb
      mode cycles       4
      dummy cycles      0
     1S-1S-4S
      opcode            0x6b
      mode cycles       0
      dummy cycles      8
     1S-4S-4S
      opcode            0xeb
      mode cycles       2
      dummy cycles      4
     4S-4S-4S
      opcode            0x0b
      mode cycles       2
      dummy cycles      4
    
    Supported page program modes by the flash
     1S-1S-1S
      opcode    0x02
    
    root@1:~# cat /sys/kernel/debug/spi-nor/spi0.0/params
    name                sst26vf064b
    id                  bf 26 43 bf 26 43
    size                8.00 MiB
    write size          1
    page size           256
    address nbytes      3
    flags               HAS_LOCK | HAS_16BIT_SR | SOFT_RESET | SWP_IS_VOLATILE
    
    opcodes
     read               0xeb
      dummy cycles      6
     erase              0x20
     program            0x02
     8D extension       none
    
    protocols
     read               1S-4S-4S
     write              1S-1S-1S
     register           1S-1S-1S
    
    erase commands
     20 (4.00 KiB) [0]
     d8 (8.00 KiB) [1]
     d8 (32.0 KiB) [2]
     d8 (64.0 KiB) [3]
     c7 (8.00 MiB)
    
    sector map
     region (in hex)   | erase mask | flags
     ------------------+------------+----------
     00000000-00007fff |     [01  ] |
     00008000-0000ffff |     [0 2 ] |
     00010000-007effff |     [0  3] |
     007f0000-007f7fff |     [0 2 ] |
     007f8000-007fffff |     [01  ] |
    
  4. 使用 mtd-utils 并验证擦除、读取和页面编程操作是否正常工作

    root@1:~# dd if=/dev/urandom of=./spi_test bs=1M count=2
    2+0 records in
    2+0 records out
    2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.848566 s, 2.5 MB/s
    
    root@1:~# mtd_debug erase /dev/mtd0 0 2097152
    Erased 2097152 bytes from address 0x00000000 in flash
    
    root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
    Copied 2097152 bytes from address 0x00000000 in flash to spi_read
    
    root@1:~# hexdump spi_read
    0000000 ffff ffff ffff ffff ffff ffff ffff ffff
    *
    0200000
    
    root@1:~# sha256sum spi_read
    4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5  spi_read
    
    root@1:~# mtd_debug write /dev/mtd0 0 2097152 spi_test
    Copied 2097152 bytes from spi_test to address 0x00000000 in flash
    
    root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
    Copied 2097152 bytes from address 0x00000000 in flash to spi_read
    
    root@1:~# sha256sum spi*
    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_read
    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_test
    

    如果闪存默认擦除,并且之前的擦除被忽略,我们将无法捕获它,因此请再次测试擦除

    root@1:~# mtd_debug erase /dev/mtd0 0 2097152
    Erased 2097152 bytes from address 0x00000000 in flash
    
    root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
    Copied 2097152 bytes from address 0x00000000 in flash to spi_read
    
    root@1:~# sha256sum spi*
    4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5  spi_read
    c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8  spi_test
    

    转储其他一些相关数据

    root@1:~# mtd_debug info /dev/mtd0
    mtd.type = MTD_NORFLASH
    mtd.flags = MTD_CAP_NORFLASH
    mtd.size = 8388608 (8M)
    mtd.erasesize = 4096 (4K)
    mtd.writesize = 1
    mtd.oobsize = 0
    regions = 0