206 lines · plain
1=================2SPI NOR framework3=================4 5How to propose a new flash addition6-----------------------------------7 8Most SPI NOR flashes comply with the JEDEC JESD2169Serial Flash Discoverable Parameter (SFDP) standard. SFDP describes10the functional and feature capabilities of serial flash devices in a11standard set of internal read-only parameter tables.12 13The SPI NOR driver queries the SFDP tables in order to determine the14flash's parameters and settings. If the flash defines the SFDP tables15it's likely that you won't need a flash entry at all, and instead16rely on the generic flash driver which probes the flash solely based17on its SFDP data. All one has to do is to specify the "jedec,spi-nor"18compatible in the device tree.19 20There are cases however where you need to define an explicit flash21entry. This typically happens when the flash has settings or support22that is not covered by the SFDP tables (e.g. Block Protection), or23when the flash contains mangled SFDP data. If the later, one needs24to implement the ``spi_nor_fixups`` hooks in order to amend the SFDP25parameters with the correct values.26 27Minimum testing requirements28-----------------------------29 30Do all the tests from below and paste them in the commit's comments31section, after the ``---`` marker.32 331) Specify the controller that you used to test the flash and specify34 the frequency at which the flash was operated, e.g.::35 36 This flash is populated on the X board and was tested at Y37 frequency using the Z (put compatible) SPI controller.38 392) Dump the sysfs entries and print the md5/sha1/sha256 SFDP checksum::40 41 root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/partname42 sst26vf064b43 root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id44 bf264345 root@1:~# cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer46 sst47 root@1:~# xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp48 53464450060102ff00060110300000ff81000106000100ffbf000118000249 0001fffffffffffffffffffffffffffffffffd20f1ffffffff0344eb086b50 083b80bbfeffffffffff00ffffff440b0c200dd80fd810d820914824806f51 1d81ed0f773830b030b0f7ffffff29c25cfff030c080ffffffffffffffff52 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff53 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff54 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff55 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff56 ffffffffffffffffffffffffffffffffff0004fff37f0000f57f0000f9ff57 7d00f57f0000f37f0000ffffffffffffffffffffffffffffffffffffffff58 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff59 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff62 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff63 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff64 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff65 ffffbf2643ffb95ffdff30f260f332ff0a122346ff0f19320f1919ffffff66 ffffffff00669938ff05013506040232b03072428de89888a585c09faf5a67 ffff06ec060c0003080bffffffffff07ffff0202ff060300fdfd040700fc68 0300fefe0202070e69 root@1:~# sha256sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp70 428f34d0461876f189ac97f93e68a05fa6428c6650b3b7baf736a921e5898ed1 /sys/bus/spi/devices/spi0.0/spi-nor/sfdp71 72 Please dump the SFDP tables using ``xxd -p``. It enables us to do73 the reverse operation and convert the hexdump to binary with74 ``xxd -rp``. Dumping the SFDP data with ``hexdump -Cv`` is accepted,75 but less desirable.76 773) Dump debugfs data::78 79 root@1:~# cat /sys/kernel/debug/spi-nor/spi0.0/capabilities80 Supported read modes by the flash81 1S-1S-1S82 opcode 0x0383 mode cycles 084 dummy cycles 085 1S-1S-1S (fast read)86 opcode 0x0b87 mode cycles 088 dummy cycles 889 1S-1S-2S90 opcode 0x3b91 mode cycles 092 dummy cycles 893 1S-2S-2S94 opcode 0xbb95 mode cycles 496 dummy cycles 097 1S-1S-4S98 opcode 0x6b99 mode cycles 0100 dummy cycles 8101 1S-4S-4S102 opcode 0xeb103 mode cycles 2104 dummy cycles 4105 4S-4S-4S106 opcode 0x0b107 mode cycles 2108 dummy cycles 4109 110 Supported page program modes by the flash111 1S-1S-1S112 opcode 0x02113 114 root@1:~# cat /sys/kernel/debug/spi-nor/spi0.0/params115 name sst26vf064b116 id bf 26 43 bf 26 43117 size 8.00 MiB118 write size 1119 page size 256120 address nbytes 3121 flags HAS_LOCK | HAS_16BIT_SR | SOFT_RESET | SWP_IS_VOLATILE122 123 opcodes124 read 0xeb125 dummy cycles 6126 erase 0x20127 program 0x02128 8D extension none129 130 protocols131 read 1S-4S-4S132 write 1S-1S-1S133 register 1S-1S-1S134 135 erase commands136 20 (4.00 KiB) [0]137 d8 (8.00 KiB) [1]138 d8 (32.0 KiB) [2]139 d8 (64.0 KiB) [3]140 c7 (8.00 MiB)141 142 sector map143 region (in hex) | erase mask | flags144 ------------------+------------+----------145 00000000-00007fff | [01 ] |146 00008000-0000ffff | [0 2 ] |147 00010000-007effff | [0 3] |148 007f0000-007f7fff | [0 2 ] |149 007f8000-007fffff | [01 ] |150 1514) Use `mtd-utils <https://git.infradead.org/mtd-utils.git>`__152 and verify that erase, read and page program operations work fine::153 154 root@1:~# dd if=/dev/urandom of=./spi_test bs=1M count=2155 2+0 records in156 2+0 records out157 2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.848566 s, 2.5 MB/s158 159 root@1:~# mtd_debug erase /dev/mtd0 0 2097152160 Erased 2097152 bytes from address 0x00000000 in flash161 162 root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read163 Copied 2097152 bytes from address 0x00000000 in flash to spi_read164 165 root@1:~# hexdump spi_read166 0000000 ffff ffff ffff ffff ffff ffff ffff ffff167 *168 0200000169 170 root@1:~# sha256sum spi_read171 4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_read172 173 root@1:~# mtd_debug write /dev/mtd0 0 2097152 spi_test174 Copied 2097152 bytes from spi_test to address 0x00000000 in flash175 176 root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read177 Copied 2097152 bytes from address 0x00000000 in flash to spi_read178 179 root@1:~# sha256sum spi*180 c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8 spi_read181 c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8 spi_test182 183 If the flash comes erased by default and the previous erase was ignored,184 we won't catch it, thus test the erase again::185 186 root@1:~# mtd_debug erase /dev/mtd0 0 2097152187 Erased 2097152 bytes from address 0x00000000 in flash188 189 root@1:~# mtd_debug read /dev/mtd0 0 2097152 spi_read190 Copied 2097152 bytes from address 0x00000000 in flash to spi_read191 192 root@1:~# sha256sum spi*193 4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_read194 c444216a6ba2a4a66cccd60a0dd062bce4b865dd52b200ef5e21838c4b899ac8 spi_test195 196 Dump some other relevant data::197 198 root@1:~# mtd_debug info /dev/mtd0199 mtd.type = MTD_NORFLASH200 mtd.flags = MTD_CAP_NORFLASH201 mtd.size = 8388608 (8M)202 mtd.erasesize = 4096 (4K)203 mtd.writesize = 1204 mtd.oobsize = 0205 regions = 0206