1# Nand testing
2
3*** note
4__WARNING:__ Most of these tests are destructive in nature.
5***
6
7## Accessing the desired device
8
9In order to test a particular device, that device must not be in use by the rest
10of the system. There are two ways to make that happen:
11
12* Prevent other drivers from binding to the device. This may involve building
13  the system with modified binding rules for the driver that normally binds
14  to the desired device, or passing kernel command line arguments to disable
15  that driver.
16
17* Unbind devices that are bound to the desired device.
18
19For example, in order to use a test tool against the core nand driver, nandpart
20devices may be removed like so:
21
22```shell
23$ unbind /dev/sys/platform/05:00:d/aml-raw_nand/nand/fvm
24```
25
26*** note
27__WARNING:__ Before removing a particular device, remove its descendants. By
28extension, file systems must be unmounted before a block device is removed.
29Note that this requirement is likely to render a running system unusable, as
30the backing for the OS may be going away. Netboot may be the only viable option.
31***
32
33Note that all other devices created by nandpart must also be removed. Use `dm
34dump` to inspect the device tree.
35
36## Protocol testing
37
38*nand-test* is an integration test which performs basic tests of nand protocol
39drivers.
40
41For example, this command will test an existing ram-nand device making sure the
42test does not modify anything outside blocks [100, 109]:
43
44```shell
45$ /boot/test/sys/nand-test --device /dev/misc/nand-ctl/ram-nand-0 --first-block 100 --num-blocks 10
46```
47
48## Correctness testing
49
50*nand-util* is a troubleshooting tool that can perform a simple read-reliability
51test.
52
53```shell
54$ nand-util --device /dev/misc/nand-ctl/ram-nand-0 --check
55```
56
57## Inspection / manipulation
58
59```shell
60$ nand-util --device /dev/sys/platform/05:00:d/aml-raw_nand/nand --info
61```
62
63*nand-util* can also be used to grab an image of the nand contents:
64
65```shell
66$ nand-util --device /dev/sys/platform/05:00:d/aml-raw_nand/nand/fvm --save --file /tmp/image
67```
68
69Transfer the image file to the host:
70
71```shell
72$ zircon/build-x86/tools/netcp :/tmp/image /tmp/saved_image_file
73```
74
75## Replay
76
77A saved nand image can be loaded on top of a ram-nand device like so:
78
79```shell
80$ nand-loader saved_image_file
81```
82