spi-nor.rst 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. =================
  2. SPI NOR framework
  3. =================
  4. How to propose a new flash addition
  5. -----------------------------------
  6. Most SPI NOR flashes comply with the JEDEC JESD216
  7. Serial Flash Discoverable Parameter (SFDP) standard. SFDP describes
  8. the functional and feature capabilities of serial flash devices in a
  9. standard set of internal read-only parameter tables.
  10. The SPI NOR driver queries the SFDP tables in order to determine the
  11. flash's parameters and settings. If the flash defines the SFDP tables
  12. it's likely that you won't need a flash entry at all, and instead
  13. rely on the generic flash driver which probes the flash solely based
  14. on its SFDP data. All one has to do is to specify the "jedec,spi-nor"
  15. compatible in the device tree.
  16. There are cases however where you need to define an explicit flash
  17. entry. This typically happens when the flash has settings or support
  18. that is not covered by the SFDP tables (e.g. Block Protection), or
  19. when the flash contains mangled SFDP data. If the later, one needs
  20. to implement the ``spi_nor_fixups`` hooks in order to amend the SFDP
  21. parameters with the correct values.
  22. Minimum testing requirements
  23. -----------------------------
  24. Do all the tests from below and paste them in the commit's comments
  25. section, after the ``---`` marker.
  26. 1) Specify the controller that you used to test the flash and specify
  27. the frequency at which the flash was operated, e.g.::
  28. This flash is populated on the X board and was tested at Y
  29. frequency using the Z (put compatible) SPI controller.
  30. 2) Dump the sysfs entries and print the md5/sha1/sha256 SFDP checksum::
  31. root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/partname
  32. sst26vf064b
  33. root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id
  34. bf2643
  35. root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer
  36. sst
  37. root@1:~# xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
  38. 53464450060102ff00060110300000ff81000106000100ffbf0001180002
  39. 0001fffffffffffffffffffffffffffffffffd20f1ffffffff0344eb086b
  40. 083b80bbfeffffffffff00ffffff440b0c200dd80fd810d820914824806f
  41. 1d81ed0f773830b030b0f7ffffff29c25cfff030c080ffffffffffffffff
  42. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  43. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  44. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  45. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  46. ffffffffffffffffffffffffffffffffff0004fff37f0000f57f0000f9ff
  47. 7d00f57f0000f37f0000ffffffffffffffffffffffffffffffffffffffff
  48. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  49. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  50. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  51. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  52. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  53. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  54. ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  55. ffffbf2643ffb95ffdff30f260f332ff0a122346ff0f19320f1919ffffff
  56. ffffffff00669938ff05013506040232b03072428de89888a585c09faf5a
  57. ffff06ec060c0003080bffffffffff07ffff0202ff060300fdfd040700fc
  58. 0300fefe0202070e
  59. root@1:~# sha256sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
  60. 428f34d0461876f189ac97f93e68a05fa6428c6650b3b7baf736a921e5898ed1 /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
  61. Please dump the SFDP tables using ``xxd -p``. It enables us to do
  62. the reverse operation and convert the hexdump to binary with
  63. ``xxd -rp``. Dumping the SFDP data with ``hexdump -Cv`` is accepted,
  64. but less desirable.
  65. 3) Dump debugfs data::
  66. root@1:~# cat /sys/kernel/debug/spi-nor/spi0.0/capabilities
  67. Supported read modes by the flash
  68. 1S-1S-1S
  69. opcode 0x03
  70. mode cycles 0
  71. dummy cycles 0
  72. 1S-1S-1S (fast read)
  73. opcode 0x0b
  74. mode cycles 0
  75. dummy cycles 8
  76. 1S-1S-2S
  77. opcode 0x3b
  78. mode cycles 0
  79. dummy cycles 8
  80. 1S-2S-2S
  81. opcode 0xbb
  82. mode cycles 4
  83. dummy cycles 0
  84. 1S-1S-4S
  85. opcode 0x6b
  86. mode cycles 0
  87. dummy cycles 8
  88. 1S-4S-4S
  89. opcode 0xeb
  90. mode cycles 2
  91. dummy cycles 4
  92. 4S-4S-4S
  93. opcode 0x0b
  94. mode cycles 2
  95. dummy cycles 4
  96. Supported page program modes by the flash
  97. 1S-1S-1S
  98. opcode 0x02
  99. root@1:~# cat /sys/kernel/debug/spi-nor/spi0.0/params
  100. name sst26vf064b
  101. id bf 26 43 bf 26 43
  102. size 8.00 MiB
  103. write size 1
  104. page size 256
  105. address nbytes 3
  106. flags HAS_LOCK | HAS_16BIT_SR | SOFT_RESET | SWP_IS_VOLATILE
  107. opcodes
  108. read 0xeb
  109. dummy cycles 6
  110. erase 0x20
  111. program 0x02
  112. 8D extension none
  113. protocols
  114. read 1S-4S-4S
  115. write 1S-1S-1S
  116. register 1S-1S-1S
  117. erase commands
  118. 20 (4.00 KiB) [0]
  119. d8 (8.00 KiB) [1]
  120. d8 (32.0 KiB) [2]
  121. d8 (64.0 KiB) [3]
  122. c7 (8.00 MiB)
  123. sector map
  124. region (in hex) | erase mask | flags
  125. ------------------+------------+----------
  126. 00000000-00007fff | [01 ] |
  127. 00008000-0000ffff | [0 2 ] |
  128. 00010000-007effff | [0 3] |
  129. 007f0000-007f7fff | [0 2 ] |
  130. 007f8000-007fffff | [01 ] |
  131. 4) Use `mtd-utils <https://git.infradead.org/mtd-utils.git>`__
  132. and verify that erase, read and page program operations work fine::
  133. root@1:~# dd if=/dev/urandom of=./spi_test bs=1M count=2
  134. 2+0 records in
  135. 2+0 records out
  136. 2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.848566 s, 2.5 MB/s
  137. root@1:~# mtd_debug erase /dev/mtd0 0 2097152
  138. Erased 2097152 bytes from address 0x00000000 in flash
  139. root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
  140. Copied 2097152 bytes from address 0x00000000 in flash to spi_read
  141. root@1:~# hexdump spi_read
  142. 0000000 ffff ffff ffff ffff ffff ffff ffff ffff
  143. *
  144. 0200000
  145. root@1:~# sha256sum spi_read
  146. 4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_read
  147. root@1:~# mtd_debug write /dev/mtd0 0 2097152 spi_test
  148. Copied 2097152 bytes from spi_test to address 0x00000000 in flash
  149. root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
  150. Copied 2097152 bytes from address 0x00000000 in flash to spi_read
  151. root@1:~# sha256sum spi*
  152. c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8 spi_read
  153. c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8 spi_test
  154. If the flash comes erased by default and the previous erase was ignored,
  155. we won't catch it, thus test the erase again::
  156. root@1:~# mtd_debug erase /dev/mtd0 0 2097152
  157. Erased 2097152 bytes from address 0x00000000 in flash
  158. root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read
  159. Copied 2097152 bytes from address 0x00000000 in flash to spi_read
  160. root@1:~# sha256sum spi*
  161. 4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_read
  162. c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8 spi_test
  163. Dump some other relevant data::
  164. root@1:~# mtd_debug info /dev/mtd0
  165. mtd.type = MTD_NORFLASH
  166. mtd.flags = MTD_CAP_NORFLASH
  167. mtd.size = 8388608 (8M)
  168. mtd.erasesize = 4096 (4K)
  169. mtd.writesize = 1
  170. mtd.oobsize = 0
  171. regions = 0