[U-Boot] [PATCH v3 2/3] arm:at91: enable ROM loadable atmel image

Andreas Bießmann andreas.devel at googlemail.com
Mon May 19 14:23:40 CEST 2014


For sama5d3xek we need to modify the SPL image for correct detection by ROM
code.

Signed-off-by: Andreas Bießmann <andreas.devel at googlemail.com>
---

Changes in v3:
* add atmel_pmecc_params host tool, it generates an appropriate string for
  mkimage -n switch with compiled in values also used in atmel_nand driver

Changes in v2:
* add -n switch to mkimage for PMECC type NAND and CONFIG_SYS_NANDFLASH

 arch/arm/cpu/armv7/at91/config.mk |   10 ++++++++
 doc/README.atmel_pmecc            |   21 +++++++++++++++
 spl/Makefile                      |   11 ++++++++
 tools/Makefile                    |    2 ++
 tools/atmel_pmecc_params.c        |   51 +++++++++++++++++++++++++++++++++++++
 5 files changed, 95 insertions(+)
 create mode 100644 arch/arm/cpu/armv7/at91/config.mk
 create mode 100644 tools/atmel_pmecc_params.c

diff --git a/arch/arm/cpu/armv7/at91/config.mk b/arch/arm/cpu/armv7/at91/config.mk
new file mode 100644
index 0000000..09eab70
--- /dev/null
+++ b/arch/arm/cpu/armv7/at91/config.mk
@@ -0,0 +1,10 @@
+#
+# Copyright (C) 2014, Andreas Bießmann <andreas.devel at googlemail.com>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+ifdef CONFIG_SPL_BUILD
+ALL-y	+= boot.bin
+else
+ALL-y	+= u-boot.img
+endif
diff --git a/doc/README.atmel_pmecc b/doc/README.atmel_pmecc
index cf8373b..cc0f73d 100644
--- a/doc/README.atmel_pmecc
+++ b/doc/README.atmel_pmecc
@@ -27,3 +27,24 @@ Take AT91SAM9X5EK as an example, the board definition file likes:
 #define CONFIG_ATMEL_NAND_HW_PMECC	1
 #define CONFIG_PMECC_CAP		2
 #define CONFIG_PMECC_SECTOR_SIZE	512
+
+How to enable PMECC header for direct programmable boot.bin
+-----------------------------------------------------------
+2014-05-19 Andreas Bießmann <andreas.devel at googlemail.com>
+
+The usual way to program SPL into NAND flash is to use the SAM-BA Atmel tool.
+This however is often not usable when doing field updates. To be able to
+program a SPL binary into NAND flash we need to add the PMECC header to the
+binary before. Chapter '12.4.4.1 NAND Flash Boot: NAND Flash Detection' in
+sama5d3 SoC spec (as of 03. April 2014) defines how this PMECC header has to
+look like. In order to do so we have a new image type added to mkimage to
+generate this PMECC header and integrated this into the build process of SPL.
+
+To enable the generation of atmel PMECC header for SPL one need to define
+CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER. The required parameters are taken from
+board configuration and compiled into the host tools atmel_pmecc_params. This
+tool will be called in build process to parametrize mkimage for atmelimage
+type. The mkimage tool has intentionally _not_ compiled in those parameters.
+
+The mkimage image type atmelimage also set the 6'th interrupt vector to the
+correct value. This feature can also be used to setup a boot.bin for MMC boot.
diff --git a/spl/Makefile b/spl/Makefile
index 55500fd..402b1c6 100644
--- a/spl/Makefile
+++ b/spl/Makefile
@@ -183,6 +183,17 @@ MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE)
 MLO MLO.byteswap: $(obj)/u-boot-spl.bin
 	$(call if_changed,mkimage)
 
+MKIMAGEFLAGS_boot.bin = -T atmelimage
+
+ifeq ($(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER),y)
+MKIMAGEFLAGS_boot.bin += -n $(shell $(obj)/../tools/atmel_pmecc_params)
+
+boot.bin: $(obj)/../tools/atmel_pmecc_params
+endif
+
+boot.bin: $(obj)/u-boot-spl.bin
+	$(call if_changed,mkimage)
+
 ALL-y	+= $(obj)/$(SPL_BIN).bin
 
 ifdef CONFIG_SAMSUNG
diff --git a/tools/Makefile b/tools/Makefile
index 421ff50..62bdd84 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -38,6 +38,8 @@ ENVCRC-$(CONFIG_ENV_IS_IN_NVRAM) = y
 ENVCRC-$(CONFIG_ENV_IS_IN_SPI_FLASH) = y
 CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
 
+hostprogs-$(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER) += atmel_pmecc_params$(SFX)
+
 # TODO: CONFIG_CMD_LICENSE does not work
 hostprogs-$(CONFIG_CMD_LICENSE) += bin2header$(SFX)
 hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo$(SFX)
diff --git a/tools/atmel_pmecc_params.c b/tools/atmel_pmecc_params.c
new file mode 100644
index 0000000..8eaf27f
--- /dev/null
+++ b/tools/atmel_pmecc_params.c
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2014 Andreas Bießmann <andreas.devel at googlemail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+/*
+ * This is a host tool for generating an appropriate string out of board
+ * configuration. The string is required for correct generation of PMECC
+ * header which in turn is required for NAND flash booting of Atmel AT91 style
+ * hardware.
+ *
+ * See doc/README.atmel_pmecc for more information.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+
+static int pmecc_get_ecc_bytes(int cap, int sector_size)
+{
+	int m = 12 + sector_size / 512;
+	return (m * cap + 7) / 8;
+}
+
+int main(int argc, char *argv[])
+{
+	unsigned int use_pmecc = 0;
+	unsigned int sector_per_page;
+	unsigned int sector_size = CONFIG_PMECC_SECTOR_SIZE;
+	unsigned int oob_size = CONFIG_SYS_NAND_OOBSIZE;
+	unsigned int ecc_bits = CONFIG_PMECC_CAP;
+	unsigned int ecc_offset;
+
+#ifdef CONFIG_ATMEL_NAND_HW_PMECC
+	use_pmecc = 1;
+#endif
+
+	sector_per_page = CONFIG_SYS_NAND_PAGE_SIZE / CONFIG_PMECC_SECTOR_SIZE;
+	ecc_offset = oob_size -
+		pmecc_get_ecc_bytes(ecc_bits, sector_size) * sector_per_page;
+
+	printf("usePmecc=%d,", use_pmecc);
+	printf("sectorPerPage=%d,", sector_per_page);
+	printf("sectorSize=%d,", sector_size);
+	printf("spareSize=%d,", oob_size);
+	printf("eccBits=%d,", ecc_bits);
+	printf("eccOffset=%d", ecc_offset);
+	printf("\n");
+
+	exit(EXIT_SUCCESS);
+}
-- 
1.7.10.4



More information about the U-Boot mailing list