Skip to contentSkip to conversation

sunxi: add raw NAND secure storage support

PATCH New James Hilliard 1 participant 1 message May 11 Arm/Allwinner sunXi SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sunxi: add raw NAND secure storage support

Some sunxi boards boot from raw NAND using an Allwinner flash layout. Factory data is stored in redundant secure-storage blocks after the U-Boot proper area.

Mainline U-Boot needs to preserve this area when generating NAND partition tables. It may also need to read factory data, such as the Ethernet MAC address.

Add helpers to locate secure-storage marker blocks, read checksummed store_object items through the MTD ECC path, set ethaddr from a configurable key, and generate runtime mtdparts that place UBI after the last secure-storage marker.

Secure-storage block discovery intentionally mirrors the existing NAND
layout: use marker-only discovery from the computed U-Boot proper end to block 50. Item data remains checksum and CRC validated before use.

---
 board/sunxi/Kconfig               |  39 +++
 board/sunxi/Makefile              |   3 +
 board/sunxi/board.c               | 119 +++++++
 board/sunxi/nand_secure_storage.c | 521 ++++++++++++++++++++++++++++++
 board/sunxi/nand_secure_storage.h |  42 +++
 5 files changed, 724 insertions(+)
 create mode 100644 board/sunxi/nand_secure_storage.c
 create mode 100644 board/sunxi/nand_secure_storage.h
board/sunxi/Kconfig +39 -0
index 084a8b0c6ca..c3826f0ade9 100644
@@ -22,3 +22,42 @@ config SPL_IMAGE_TYPE
 	string
 	default "sunxi_egon" if SPL_IMAGE_TYPE_SUNXI_EGON
 	default "sunxi_toc0" if SPL_IMAGE_TYPE_SUNXI_TOC0
+
+config SUNXI_NAND_SECURE_STORAGE
+	bool "Allwinner NAND secure storage support"
+	depends on NAND_SUNXI && MTD_RAW_NAND
+	help
+	  Enable support for reading the Allwinner raw NAND secure-storage
+	  area from U-Boot proper. This is used by some sunxi boards to
+	  preserve factory data, such as MAC addresses, when booting a
+	  mainline NAND layout.
+
+config SUNXI_NAND_SECURE_STORAGE_ETHADDR
+	bool "Read ethaddr from Allwinner NAND secure storage"
+	depends on SUNXI_NAND_SECURE_STORAGE && NET
+	select CRC32
+	help
+	  Read the configured secure-storage key and use it as the primary
+	  Ethernet MAC address before the normal sunxi fallback environment
+	  value is generated.
+
+config SUNXI_NAND_SECURE_STORAGE_ETHADDR_KEY
+	string "NAND secure-storage key name for ethaddr"
+	depends on SUNXI_NAND_SECURE_STORAGE_ETHADDR
+	default "mac"
+	help
+	  Name of the secure-storage item containing the primary Ethernet MAC
+	  address. The store_object payload is parsed like a U-Boot
+	  Ethernet environment variable.
+
+config SUNXI_NAND_SECURE_STORAGE_MTD_PARTS
+	bool "Generate NAND mtdparts around secure storage"
+	depends on SUNXI_NAND_SECURE_STORAGE && SYS_MTDPARTS_RUNTIME
+	help
+	  Generate the default NAND mtdparts at runtime by locating
+	  secure-storage marker blocks and placing the UBI partition immediately
+	  after the last marker. This avoids hard-coding the secure-storage
+	  offset, which may shift when bad blocks are present before or inside
+	  the secure-storage window. Only SLC raw NAND is supported; MLC/TLC
+	  parts need Allwinner's LSB-block-size mapping, which is not available
+	  here.
board/sunxi/Makefile +3 -0
index ee82493117a..fda2a0bfe76 100644
@@ -8,6 +8,9 @@
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 obj-y	+= board.o
 obj-$(CONFIG_SUN7I_GMAC)	+= gmac.o
+ifndef CONFIG_XPL_BUILD
+obj-$(CONFIG_SUNXI_NAND_SECURE_STORAGE)	+= nand_secure_storage.o
+endif
 obj-$(CONFIG_MACH_SUN4I)	+= dram_sun4i_auto.o
 obj-$(CONFIG_MACH_SUN5I)	+= dram_sun5i_auto.o
 obj-$(CONFIG_MACH_SUN7I)	+= dram_sun5i_auto.o
board/sunxi/board.c +119 -0

134 lines not on this page · raw message

board/sunxi/nand_secure_storage.c new file +521 -0

521 lines not on this page · raw message

board/sunxi/nand_secure_storage.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.53.0