Introduction
This page gives an overview of Zynq Ultrascale+ MPSoC nand driver which is located at drivers/mtd/nand/raw/arasan_nand.c. link: nand source file
NAND driver provides basic functions that are required for accessing the nand flash memory including the support for hw ecc, on-die ecc and bad block management.
HW IP Features
Controller Features
- Complies with the ONFI 3.1 specification
- Supports interleaving operations
- Supports BCH error correction code (ECC) data widths of 4, 8, 12, and 24 bits.
- All ONFI 3.1 commands
- PIO and MDMA support
- SDR and NVDDR modes
- supports only 8-bit bus support
- Hardware ECC (Hamming code and BCH)
- Page size up to 16K
- Programmable timing modes
- 64-bit dma support.
- Supports multiple chip selects (up to 2)
Driver Features
- Supports only the mandatory ONFI 3.1 commands. i.e Reset, Read status, Read ID, Read Parameter Page, Read Page, Program Page, Erase Block, Set/Get Features
- Supports SDR/DDR modes
- Supports timing modes 0-5
- Supports PIO and MDMA support
- Support for multiple chip selection
- Support 64-bit dma
- Support BBT management
- Hardware ECC (Hamming code and BCH upto 24 bits)
Missing features, Known Issues, limitations
- No support for interleaved and all optional ONFI 3.1 commands
Bad Block management
Bad block management implementation is same as Linux MTD bad block management with the exception of reserving number of blocks to store Bad Block Table (BBT) from default 4 blocks to 64 blocks. This is because one of the Micron flash part MT29F32G08ABCDB has last 32 blocks as bad most of the times. Since it was difficult to store bad block table in last 4 blocks, the number of blocks are increased to 64 blocks.
Kernel Configuration Options
The following config options should be enabled in order to build Zynq Ultrascale+ MPSoC
CONFIG_MTD_NAND_ARASAN
CONFIG_MTD_NAND
config MTD_NAND_ARASAN tristate "Support for Arasan Nand Flash controller" depends on MTD_NAND help Enables the driver for the Arasan Nand Flash controller in ZynqMP SoC.
Device Tree Settings
More information on nand device tree node details, refer the link Nand device tree
Example for device tree
nand0: nand@ff100000 { compatible = "arasan,nfc-v3p10"; reg = <0x0 0xff100000 0x0 0x1000>; clock-names = "clk_sys", "clk_flash"; interrupt-parent = <&gic>; interrupts = <0 14 4>; #address-cells = <2>; #size-cells = <1>; };
Nand Partition details
Below example assumes that controller is using 2 chip select lines
&nand0 { status = "okay"; arasan,has-mdma; nand@0 { reg = <0x0>; #address-cells = <0x2>; #size-cells = <0x1>; partition@0 { /* for testing purpose */ label = "nand-fsbl-uboot"; reg = <0x0 0x0 0x400000>; }; partition@1 { /* for testing purpose */ label = "nand-linux"; reg = <0x0 0x400000 0x1400000>; }; partition@2 { /* for testing purpose */ label = "nand-device-tree"; reg = <0x0 0x1800000 0x400000>; }; partition@3 { /* for testing purpose */ label = "nand-rootfs"; reg = <0x0 0x1C00000 0x1400000>; }; partition@4 { /* for testing purpose */ label = "nand-bitstream"; reg = <0x0 0x3000000 0x400000>; }; partition@5 { /* for testing purpose */ label = "nand-misc"; reg = <0x0 0x3400000 0xFCC00000>; }; }; nand@1 { reg = <0x1>; #address-cells = <0x2>; #size-cells = <0x1>; partition@0 { /* for testing purpose */ label = "nand1-fsbl-uboot"; reg = <0x1 0x0 0x400000>; }; partition@1 { /* for testing purpose */ label = "nand1-linux"; reg = <0x1 0x400000 0x1400000>; }; partition@2 { /* for testing purpose */ label = "nand1-device-tree"; reg = <0x1 0x1800000 0x400000>; }; partition@3 { /* for testing purpose */ label = "nand1-rootfs"; reg = <0x1 0x1C00000 0x1400000>; }; partition@4 { /* for testing purpose */ label = "nand1-bitstream"; reg = <0x1 0x3000000 0x400000>; }; partition@5 { /* for testing purpose */ label = "nand1-misc"; reg = <0x1 0x3400000 0xFCC00000>; }; }; };
Performance
Mode | Write Speed | Read Speed |
DDR Timing mode 5 | 32MB/sec | 111MB/sec |
Testing Procedure
Prerequisites
Kernel tools
mtd layer provides a rich set of tests for validating the nand access including the performance and stress tests
Following kernel config options should be enabled for mtd tests
CONFIG_MTD_TESTS
user space tools
Below test cases requires the following user space tools
mtd_debug, nandtest
All these tools are part of the mtd-utils and source is available from link http://git.infradead.org/mtd-utils.git
Note: expected output may not be same and its all depends on the flash device and configuration of the target system.
Driver Probe
Assuming the target has nand flash memory installed
How to Run
Boot the target till Linux and ensure that nand driver is enabled.
Expected Output
nand: device found, Manufacturer ID: 0x2c, Chip ID: 0x44 nand: Micron MT29F32G08ABCDBJ4
Block Erase test
How to Run
After linux boot,
root@zynqmp:~# mtd_debug erase /dev/mtd0 0x00000000 0x400000
Expected Output
Erased 4194304 bytes from address 0x00000000 in flash
Write Page test
How to Run
After linux boot,
Create a test image
root@zynqmp:~# dd if=/dev/urandom of=/tmp/test1.img bs=1024 count=16 root@zynqmp:~# mtd_debug write /dev/mtd0 0x00000000 0x4000 /tmp/test1.img
Expected Output
Copied 16384 bytes from /tmp/test1.img to address 0x00000000 in flash
Read Page and Data integrity test
How to Run
After linux boot,
root@zynqmp:~# mtd_debug read /dev/mtd0 0x00000000 0x4000 /tmp/test2.img root@zynqmp:~# cmp /tmp/test1.img /tmp/test2.img root@zynqmp:~# md5sum /tmp/test1.img /tmp/test2.img
Expected Output
Copied 16384 bytes from address 0x00000000 in flash to /tmp/test2.img 7a0c68453dfb8028fca49f30d5cc798f /tmp/test1.img 7a0c68453dfb8028fca49f30d5cc798f /tmp/test2.img
Data integrity test using nandtest utility
How to Run
After linux boot,
root@zynqmp:~# nandtest /dev/mtd0
Expected Output
ECC corrections: 0 ECC failures : 0 Bad blocks : 0 BBT blocks : 0 00000000: erasing... 00000000: writing... 00000000: reading...[ 403.220080] random: nonblocking pool is initialized 00000000: checking... 00400000: erasing... 00400000: writing... 00400000: reading... 256 bit(s) ECC corrected at 00400000 00400000: checking... 00800000: erasing... 00800000: writing... 00800000: reading... 00800000: checking... 00c00000: erasing... 00c00000: writing... 00c00000: reading... 00c00000: checking... 01000000: erasing... 01000000: writing... 01000000: reading... 256 bit(s) ECC corrected at 01000000 01000000: checking... 01400000: erasing... 01400000: writing... 01400000: reading... 256 bit(s) ECC corrected at 01400000 01400000: checking... 01800000: erasing... 01800000: writing... 01800000: reading... 01800000: checking... 01c00000: erasing... 01c00000: writing... 01c00000: reading... 256 bit(s) ECC corrected at 01c00000 01c00000: checking... Finished pass 1 successfully.
MTD oob test
How to Run
After linux boot,
root@zynqmp:~# insmod /lib64/modules/5.4/kernel/drivers/mtd/tests/mtd_oobtest.ko dev=0 bitflip_limit=2
Expected Output
[ 444.334675] ================================================= [ 444.342927] mtd_oobtest: MTD device: 1 [ 444.346672] mtd_oobtest: MTD device size 20971520, eraseblock size 4194304, page size 16384, count of eraseblocks 5, pages per eraseblock 256, OOB size 1216 [ 444.360737] mtd_test: scanning for bad eraseblocks [ 444.365527] mtd_test: block 0 is bad [ 444.369102] mtd_test: block 2 is bad [ 444.372670] mtd_test: scanned 5 eraseblocks, 2 are bad [ 444.377803] mtd_oobtest: test 1 of 5 [ 444.385838] mtd_oobtest: writing OOBs of whole device [ 444.679949] mtd_oobtest: written 5 eraseblocks [ 444.684388] mtd_oobtest: verifying all eraseblocks [ 444.773915] mtd_oobtest: verified 5 eraseblocks [ 444.778445] mtd_oobtest: test 2 of 5 [ 444.787197] mtd_oobtest: writing OOBs of whole device [ 445.081722] mtd_oobtest: written 5 eraseblocks [ 445.086161] mtd_oobtest: verifying all eraseblocks [ 445.217473] mtd_oobtest: test 3 of 5 [ 445.226214] mtd_oobtest: writing OOBs of whole device [ 445.514542] mtd_oobtest: written 5 eraseblocks [ 445.518987] mtd_oobtest: verifying all eraseblocks [ 445.767054] mtd_oobtest: verified 5 eraseblocks [ 445.771587] mtd_oobtest: test 4 of 5 [ 445.780341] mtd_oobtest: attempting to start write past end of OOB [ 445.786515] mtd_oobtest: an error is expected... [ 445.791132] mtd_oobtest: error occurred as expected [ 445.795998] mtd_oobtest: attempting to start read past end of OOB [ 445.802086] mtd_oobtest: an error is expected... [ 445.806693] mtd_oobtest: error occurred as expected [ 445.811564] mtd_oobtest: attempting to write past end of device [ 445.817474] mtd_oobtest: an error is expected... [ 445.822084] mtd_oobtest: error occurred as expected [ 445.826952] mtd_oobtest: attempting to read past end of device [ 445.832780] mtd_oobtest: an error is expected... [ 445.837394] mtd_oobtest: error occurred as expected [ 445.843530] mtd_oobtest: attempting to write past end of device [ 445.849446] mtd_oobtest: an error is expected... [ 445.854061] mtd_oobtest: error occurred as expected [ 445.858930] mtd_oobtest: attempting to read past end of device [ 445.864756] mtd_oobtest: an error is expected... [ 445.869363] mtd_oobtest: error occurred as expected [ 445.874234] mtd_oobtest: test 5 of 5 [ 445.881568] mtd_oobtest: writing OOBs of whole device [ 445.887336] mtd_oobtest: written 4 eraseblocks [ 445.891782] mtd_oobtest: verifying all eraseblocks [ 445.896794] mtd_oobtest: verified 4 eraseblocks [ 445.901316] mtd_oobtest: finished with 0 errors [ 445.905843] =================================================
MTD speed test
How to Run
After Linux boot,
root@zynqmp:~# insmod /lib64/modules/5.4/kernel/drivers/mtd/tests/mtd_speedtest.ko dev=1
Expected Output
[ 202.787497] ================================================= [ 202.794681] mtd_speedtest: MTD device: 1 [ 202.798603] mtd_speedtest: MTD device size 20971520, eraseblock size 4194304, page size 16384, count of eraseblocks 5, pages per eraseblock 256, OOB size 1216 [ 202.830374] mtd_test: scanning for bad eraseblocks [ 202.835189] mtd_test: block 0 is bad [ 202.838843] mtd_test: block 2 is bad [ 202.842426] mtd_test: scanned 5 eraseblocks, 2 are bad [ 202.853508] mtd_speedtest: testing eraseblock write speed [ 203.233967] mtd_speedtest: eraseblock write speed is 32768 KiB/s [ 203.239976] mtd_speedtest: testing eraseblock read speed [ 203.356050] mtd_speedtest: eraseblock read speed is 111709 KiB/s [ 203.367929] mtd_speedtest: testing page write speed [ 203.757967] mtd_speedtest: page write speed is 31916 KiB/s [ 203.763454] mtd_speedtest: testing page read speed [ 203.879196] mtd_speedtest: page read speed is 111709 KiB/s [ 203.890574] mtd_speedtest: testing 2 page write speed [ 204.275591] mtd_speedtest: 2 page write speed is 32422 KiB/s [ 204.281248] mtd_speedtest: testing 2 page read speed [ 204.396816] mtd_speedtest: 2 page read speed is 111709 KiB/s [ 204.402475] mtd_speedtest: Testing erase speed [ 204.412806] mtd_speedtest: erase speed is 2457600 KiB/s [ 204.418027] mtd_speedtest: Testing 2x multi-block erase speed [ 204.427544] mtd_speedtest: 2x multi-block erase speed is 4096000 KiB/s [ 204.434069] mtd_speedtest: Testing 4x multi-block erase speed [ 204.443586] mtd_speedtest: 4x multi-block erase speed is 4096000 KiB/s [ 204.450110] mtd_speedtest: Testing 8x multi-block erase speed [ 204.459622] mtd_speedtest: 8x multi-block erase speed is 4096000 KiB/s [ 204.466149] mtd_speedtest: Testing 16x multi-block erase speed [ 204.475743] mtd_speedtest: 16x multi-block erase speed is 4096000 KiB/s [ 204.482355] mtd_speedtest: Testing 32x multi-block erase speed [ 204.491959] mtd_speedtest: 32x multi-block erase speed is 4096000 KiB/s [ 204.498571] mtd_speedtest: Testing 64x multi-block erase speed [ 204.508173] mtd_speedtest: 64x multi-block erase speed is 4096000 KiB/s [ 204.514784] mtd_speedtest: finished [ 109.341560] =================================================
MTD stress test
How to Run
After Linux boot,
root@zynqmp:~# insmod /lib64/modules/5.4/kernel/drivers/mtd/tests/mtd_stresstest.ko count=100 dev=1
Expected Output
[ 36.339646] ================================================= [ 36.347710] mtd_stresstest: MTD device: 1 [ 36.351722] mtd_stresstest: MTD device size 20971520, eraseblock size 4194304, page size 16384, count of eraseblocks 5, pages per eraseblock 256, OOB size 1216 [ 36.402798] mtd_test: scanning for bad eraseblocks [ 36.407604] mtd_test: block 0 is bad [ 36.411204] mtd_test: block 2 is bad [ 36.414787] mtd_test: scanned 5 eraseblocks, 2 are bad [ 36.419917] mtd_stresstest: doing operations [ 36.424184] mtd_stresstest: 0 operations done [ 36.925795] random: crng init done [ 37.451376] mtd_stresstest: finished, 5 operations done [ 37.459647] =================================================
MTD page read test
How to Run
After Linux boot,
root@zynqmp:~# insmod /lib64/modules/5.4/kernel/drivers/mtd/tests/mtd_readtest.ko dev=0
Expected Output
[ 383.850772] ================================================= [ 383.857809] mtd_readtest: MTD device: 1 [ 383.861648] mtd_readtest: MTD device size 20971520, eraseblock size 4194304, page size 16384, count of eraseblocks 5, pages per eraseblock 256, OOB size 1216 [ 383.875808] mtd_test: scanning for bad eraseblocks [ 383.880599] mtd_test: block 0 is bad [ 383.884204] mtd_test: block 2 is bad [ 383.887775] mtd_test: scanned 5 eraseblocks, 2 are bad [ 383.892915] mtd_readtest: testing page read [ 384.155680] mtd_readtest: finished [ 384.159103] ================================================= **Note:** Paths for the modules and tool names may vary from release to release. Please cross verify before starting the test.
Change Log
2016.3
2016.4
- Summary
- None
- Commits
- None
- Summary
2017.1
2017.2
2017.3
2017.4
- None
2018.1
- None
2018.2
- None
2018.3
- Summary
- Fix initialization of controller structure
- Commits
- 17c06e9 Fix initialization of controller structure
- Summary
2019.1
- Summary
- Updated the driver to use →exec_op()
- Commits:
- d0674f0 Added support for →exec_op()
- Summary
2019.2
- Summary
- Move interrupt completion at the end
- Commits:
- cf17190e Disable the interrupts and then signal the completion
- Summary
2020.1
2020.2
- Summary
- None
- Commits
- None
- Summary
Mainline status
Mainlined