[U-Boot] [PATCH v5 14/16] scripts: sunxi: Build an raw SPL image

Maxime Ripard maxime.ripard at free-electrons.com
Mon Feb 27 17:22:13 UTC 2017

Introduce a new sunxi-spl-with-ecc.bin image with already the right header,
ECC, randomizer and padding for the BROM to be able to read it.

It needs to be flashed using a raw access to the NAND so that the
controller doesn't change a thing to it, since we already have all the
right parameters.

Signed-off-by: Maxime Ripard <maxime.ripard at free-electrons.com>
Acked-by: Boris Brezillon <boris.brezillon at free-electrons.com>
Reviewed-by: Heiko Schocher <hs at denx.de>
 Makefile                |  3 ++-
 board/sunxi/README.nand | 54 ++++++++++++++++++++++++++++++++++++++++++-
 scripts/Makefile.spl    | 15 ++++++++++++-
 3 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 board/sunxi/README.nand

diff --git a/Makefile b/Makefile
index 38b42daf3b5b..f8d24849e1fe 100644
--- a/Makefile
+++ b/Makefile
@@ -1344,6 +1344,9 @@ spl/u-boot-spl: tools prepare \
 spl/sunxi-spl.bin: spl/u-boot-spl
+spl/sunxi-spl-with-ecc.bin: spl/sunxi-spl.bin
+	@:
 spl/u-boot-spl.sfp: spl/u-boot-spl
diff --git a/board/sunxi/README.nand b/board/sunxi/README.nand
new file mode 100644
index 000000000000..a5d4ff0e90a3
--- /dev/null
+++ b/board/sunxi/README.nand
@@ -0,0 +1,54 @@
+Allwinner NAND flashing
+A lot of Allwinner devices, especially the older ones (pre-H3 era),
+comes with a NAND. NANDs storages are a pretty weak choice when it
+comes to the reliability, and it comes with a number of flaws like
+read and write disturbs, data retention issues, bloks becoming
+unusable, etc.
+In order to mitigate that, various strategies have been found to be
+able to recover from those issues like ECC, hardware randomization,
+and of course, redundancy for the critical parts.
+This is obviously something that we will take into account when
+creating our images. However, the BROM will use a quite weird pattern
+when accessing the NAND, and will access only at most 4kB per page,
+which means that we also have to split that binary accross several
+In order to accomodate that, we create a tool that will generate an
+SPL image that is ready to be programmed directly embedding the ECCs,
+randomized, and with the necessary bits needed to reduce the number of
+bitflips. The U-Boot build system, when configured for the NAND will
+also generate the image sunxi-spl-with-ecc.bin that will have been
+generated by that tool.
+In order to flash your U-Boot image onto a board, assuming that the
+board is in FEL mode, you'll need the sunxi-tools that you can find at
+this repository: https://github.com/linux-sunxi/sunxi-tools
+Then, you'll need to first load an SPL to initialise the RAM:
+sunxi-fel spl spl/sunxi-spl.bin
+Load the binaries we'll flash into RAM:
+sunxi-fel write 0x4a000000 u-boot-dtb.bin
+sunxi-fel write 0x43000000 spl/sunxi-spl-with-ecc.bin
+And execute U-Boot
+sunxi-fel exe 0x4a000000
+On your board, you'll now have all the needed binaries into RAM, so
+you only need to erase the NAND...
+nand erase.chip
+Then write the SPL and its backup:
+nand write.raw.noverify 0x43000000 0 40
+nand write.raw.noverify 0x43000000 0x400000 40
+And finally write the U-Boot binary:
+nand write 0x4a000000 0x800000 0xc0000
+You can now reboot and enjoy your NAND.
\ No newline at end of file
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index b52f9963f7d0..60ea939ac629 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -173,6 +173,10 @@ endif
 ALL-y	+= $(obj)/sunxi-spl.bin
+ALL-y	+= $(obj)/sunxi-spl-with-ecc.bin
 ifeq ($(CONFIG_SYS_SOC),"at91")
@@ -289,6 +293,17 @@ cmd_mksunxiboot = $(objtree)/tools/mksunxiboot $< $@
 $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE
 	$(call if_changed,mksunxiboot)
+quiet_cmd_sunxi_spl_image_builder = SUNXI_SPL_IMAGE_BUILDER $@
+cmd_sunxi_spl_image_builder = $(objtree)/tools/sunxi-spl-image-builder \
+				-s -b $< $@
+$(obj)/sunxi-spl-with-ecc.bin: $(obj)/sunxi-spl.bin
+	$(call if_changed,sunxi_spl_image_builder)
 # Rule to link u-boot-spl
 # May be overridden by arch/$(ARCH)/config.mk
 quiet_cmd_u-boot-spl ?= LD      $@
git-series 0.8.11

More information about the U-Boot mailing list