Maxime Ripard | d2fdcc7 | 2017-02-27 18:22:13 +0100 | [diff] [blame] | 1 | Allwinner NAND flashing |
| 2 | ======================= |
| 3 | |
| 4 | A lot of Allwinner devices, especially the older ones (pre-H3 era), |
| 5 | comes with a NAND. NANDs storages are a pretty weak choice when it |
| 6 | comes to the reliability, and it comes with a number of flaws like |
| 7 | read and write disturbs, data retention issues, bloks becoming |
| 8 | unusable, etc. |
| 9 | |
| 10 | In order to mitigate that, various strategies have been found to be |
| 11 | able to recover from those issues like ECC, hardware randomization, |
| 12 | and of course, redundancy for the critical parts. |
| 13 | |
| 14 | This is obviously something that we will take into account when |
| 15 | creating our images. However, the BROM will use a quite weird pattern |
| 16 | when accessing the NAND, and will access only at most 4kB per page, |
| 17 | which means that we also have to split that binary accross several |
| 18 | pages. |
| 19 | |
| 20 | In order to accomodate that, we create a tool that will generate an |
| 21 | SPL image that is ready to be programmed directly embedding the ECCs, |
| 22 | randomized, and with the necessary bits needed to reduce the number of |
Priit Laes | df4ad94 | 2018-10-23 20:20:30 +0300 | [diff] [blame] | 23 | bitflips. The U-Boot build system, when configured for the NAND (with |
Miquel Raynal | 88718be | 2019-10-03 19:50:03 +0200 | [diff] [blame] | 24 | CONFIG_MTD_RAW_NAND=y) will also generate the image sunxi-spl-with-ecc.bin |
Priit Laes | df4ad94 | 2018-10-23 20:20:30 +0300 | [diff] [blame] | 25 | that will have been generated by that tool. |
Maxime Ripard | d2fdcc7 | 2017-02-27 18:22:13 +0100 | [diff] [blame] | 26 | |
| 27 | In order to flash your U-Boot image onto a board, assuming that the |
| 28 | board is in FEL mode, you'll need the sunxi-tools that you can find at |
| 29 | this repository: https://github.com/linux-sunxi/sunxi-tools |
| 30 | |
| 31 | Then, you'll need to first load an SPL to initialise the RAM: |
| 32 | sunxi-fel spl spl/sunxi-spl.bin |
| 33 | |
| 34 | Load the binaries we'll flash into RAM: |
| 35 | sunxi-fel write 0x4a000000 u-boot-dtb.bin |
| 36 | sunxi-fel write 0x43000000 spl/sunxi-spl-with-ecc.bin |
| 37 | |
| 38 | And execute U-Boot |
| 39 | sunxi-fel exe 0x4a000000 |
| 40 | |
| 41 | On your board, you'll now have all the needed binaries into RAM, so |
| 42 | you only need to erase the NAND... |
| 43 | |
| 44 | nand erase.chip |
| 45 | |
| 46 | Then write the SPL and its backup: |
| 47 | |
| 48 | nand write.raw.noverify 0x43000000 0 40 |
| 49 | nand write.raw.noverify 0x43000000 0x400000 40 |
| 50 | |
| 51 | And finally write the U-Boot binary: |
| 52 | nand write 0x4a000000 0x800000 0xc0000 |
| 53 | |
| 54 | You can now reboot and enjoy your NAND. |