1*d2fdcc76SMaxime RipardAllwinner NAND flashing 2*d2fdcc76SMaxime Ripard======================= 3*d2fdcc76SMaxime Ripard 4*d2fdcc76SMaxime RipardA lot of Allwinner devices, especially the older ones (pre-H3 era), 5*d2fdcc76SMaxime Ripardcomes with a NAND. NANDs storages are a pretty weak choice when it 6*d2fdcc76SMaxime Ripardcomes to the reliability, and it comes with a number of flaws like 7*d2fdcc76SMaxime Ripardread and write disturbs, data retention issues, bloks becoming 8*d2fdcc76SMaxime Ripardunusable, etc. 9*d2fdcc76SMaxime Ripard 10*d2fdcc76SMaxime RipardIn order to mitigate that, various strategies have been found to be 11*d2fdcc76SMaxime Ripardable to recover from those issues like ECC, hardware randomization, 12*d2fdcc76SMaxime Ripardand of course, redundancy for the critical parts. 13*d2fdcc76SMaxime Ripard 14*d2fdcc76SMaxime RipardThis is obviously something that we will take into account when 15*d2fdcc76SMaxime Ripardcreating our images. However, the BROM will use a quite weird pattern 16*d2fdcc76SMaxime Ripardwhen accessing the NAND, and will access only at most 4kB per page, 17*d2fdcc76SMaxime Ripardwhich means that we also have to split that binary accross several 18*d2fdcc76SMaxime Ripardpages. 19*d2fdcc76SMaxime Ripard 20*d2fdcc76SMaxime RipardIn order to accomodate that, we create a tool that will generate an 21*d2fdcc76SMaxime RipardSPL image that is ready to be programmed directly embedding the ECCs, 22*d2fdcc76SMaxime Ripardrandomized, and with the necessary bits needed to reduce the number of 23*d2fdcc76SMaxime Ripardbitflips. The U-Boot build system, when configured for the NAND will 24*d2fdcc76SMaxime Ripardalso generate the image sunxi-spl-with-ecc.bin that will have been 25*d2fdcc76SMaxime Ripardgenerated by that tool. 26*d2fdcc76SMaxime Ripard 27*d2fdcc76SMaxime RipardIn order to flash your U-Boot image onto a board, assuming that the 28*d2fdcc76SMaxime Ripardboard is in FEL mode, you'll need the sunxi-tools that you can find at 29*d2fdcc76SMaxime Ripardthis repository: https://github.com/linux-sunxi/sunxi-tools 30*d2fdcc76SMaxime Ripard 31*d2fdcc76SMaxime RipardThen, you'll need to first load an SPL to initialise the RAM: 32*d2fdcc76SMaxime Ripardsunxi-fel spl spl/sunxi-spl.bin 33*d2fdcc76SMaxime Ripard 34*d2fdcc76SMaxime RipardLoad the binaries we'll flash into RAM: 35*d2fdcc76SMaxime Ripardsunxi-fel write 0x4a000000 u-boot-dtb.bin 36*d2fdcc76SMaxime Ripardsunxi-fel write 0x43000000 spl/sunxi-spl-with-ecc.bin 37*d2fdcc76SMaxime Ripard 38*d2fdcc76SMaxime RipardAnd execute U-Boot 39*d2fdcc76SMaxime Ripardsunxi-fel exe 0x4a000000 40*d2fdcc76SMaxime Ripard 41*d2fdcc76SMaxime RipardOn your board, you'll now have all the needed binaries into RAM, so 42*d2fdcc76SMaxime Ripardyou only need to erase the NAND... 43*d2fdcc76SMaxime Ripard 44*d2fdcc76SMaxime Ripardnand erase.chip 45*d2fdcc76SMaxime Ripard 46*d2fdcc76SMaxime RipardThen write the SPL and its backup: 47*d2fdcc76SMaxime Ripard 48*d2fdcc76SMaxime Ripardnand write.raw.noverify 0x43000000 0 40 49*d2fdcc76SMaxime Ripardnand write.raw.noverify 0x43000000 0x400000 40 50*d2fdcc76SMaxime Ripard 51*d2fdcc76SMaxime RipardAnd finally write the U-Boot binary: 52*d2fdcc76SMaxime Ripardnand write 0x4a000000 0x800000 0xc0000 53*d2fdcc76SMaxime Ripard 54*d2fdcc76SMaxime RipardYou can now reboot and enjoy your NAND.