Skip to contentSkip to conversation

sunxi: support FEL-provided environment vars and "fel" boot target

PATCH Superseded Bernhard Nortmann 2 participants 10 messages Sep 17, 2015 – Sep 20, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover sunxi: support FEL-provided environment vars and "fel" boot target

This patch series builds upon
http://lists.denx.de/pipermail/u-boot/2015-September/226515.html
http://lists.denx.de/pipermail/u-boot/2015-September/226688.html

v2 combines the previous submissions, and adds some suggested fixes/changes.

v3 introduces another patch at the start of the series to allow using shared definitions from a common asm/arch-sunxi/spl.h include. It's also aimed at addressing some of Siarhei's comments.

Siarhei: As I've shuffled things around a bit for that, I'm not including your ACK on patch v3 2/4. The 4/4 one (bootcmd_fel) is unchanged, and now includes your ACK.

The sunxi-tool side of things is discussed here:
https://www.mail-archive.com/linux-sunxi at googlegroups.com/msg13071.html

* Hans de Goede already pointed out that it might be preferable to make use of the spl_boot_device() function even from the main (non-SPL) U-Boot binary (e.g. for the "NAND" case). Currently this function is only available with CONFIG_SPL_BUILD set, and implemented in arch/arm/cpu/armv7/sunxi/board.c
Would it be safe to enable it for non-SPL builds and use something like "(spl_boot_device == BOOT_DEVICE_BOARD)" for misc_init_r()?

* Side note: the sunxi spl_boot_device() will probably require some future refinement anyway, to account for the 'oddball' A80. That SoC requires the SPL at a different address (0x10000 instead of 0x0).
I've tried to address this (at least in part) by introducing a SPL_ADDR definition in the platform-specific spl.h.

Regards, B. Nortmann

Changes in v3:
- (new with v3)
- adapted to use asm/arch/spl.h
- make use of asm/arch/spl.h to share definitions / helper macro
- revert SPL version check to expect exact SPL_HEADER_VERSION

Changes in v2:
- Rename field to fel_script_address, discard fel_data_size
- Clearing header fields is no longer needed, as mksunxiboot.c zeroes entire image first
- renamed fel_data_addr to fel_script_addr, discarded fel_data_size
- make sure that FEL-related environment vars are always cleared first
- support minimum and maximum SPL (header) version, more verbose error messages
- renamed fel_data_addr to fel_scriptaddr
- combined both tests into one as suggested by Hans de Goede

Bernhard Nortmann (4):
sunxi: move SPL-related definitions to platform-specific include
sunxi: (mksunxiboot) signature to indicate "sunxi" SPL variant
sunxi: retrieve FEL-provided values to environment variables
sunxi: add "fel" boot target

 arch/arm/cpu/armv7/sunxi/board.c      |  2 +-
 arch/arm/include/asm/arch-sunxi/spl.h | 47 +++++++++++++++++++++++++++++------
 arch/arm/include/asm/spl.h            |  5 ++++
 board/sunxi/board.c                   | 35 ++++++++++++++++++++++++++
 include/configs/sunxi-common.h        | 11 ++++++++
 tools/mksunxiboot.c                   | 21 ++++------------
 6 files changed, 96 insertions(+), 25 deletions(-)
Signature · 1 line
2.4.6
#1 lore raw

PATCH v3 1/4 sunxi: move SPL-related definitions to platform-specific include

The sunxi platform currently doesn't seem to make any use of the asm/arch-sunxi/spl.h file. This patch moves some declarations from tools/mksunxiboot.c into it.

This enables us to reuse those definitions when extending the sunxi board code (boards/sunxi/boards.c).

---

Changes in v3:
- (new with v3)

Changes in v2: None

 arch/arm/include/asm/arch-sunxi/spl.h | 25 +++++++++++++++++--------
 tools/mksunxiboot.c                   | 17 +----------------
 2 files changed, 18 insertions(+), 24 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +17 -8
index acbec46..751de75 100644
@@ -9,12 +9,21 @@
 #ifndef	_ASM_ARCH_SPL_H_
 #define	_ASM_ARCH_SPL_H_
 
-#define BOOT_DEVICE_NONE	0
-#define BOOT_DEVICE_XIP		1
-#define BOOT_DEVICE_NAND	2
-#define BOOT_DEVICE_ONE_NAND	3
-#define BOOT_DEVICE_MMC2	5 /*emmc*/
-#define BOOT_DEVICE_MMC1	6
-#define BOOT_DEVICE_XIPWAIT	7
-#define BOOT_DEVICE_MMC2_2      0xff
+#define BOOT0_MAGIC		"eGON.BT0"
+
+/* boot head definition from sun4i boot code */
+struct boot_file_head {
+	uint32_t b_instruction;	/* one intruction jumping to real code */
+	uint8_t magic[8];	/* ="eGON.BT0" or "eGON.BT1", not C-style str */
+	uint32_t check_sum;	/* generated by PC */
+	uint32_t length;	/* generated by PC */
+	/*
+	 * We use a simplified header, only filling in what is needed
+	 * by the boot ROM. To be compatible with Allwinner tools we
+	 * would need to implement the proper fields here instead of
+	 * padding.
+	 */
+	uint8_t pad[12];		/* align to 32 bytes */
+};
+
 #endif
tools/mksunxiboot.c +1 -16
index 676d392..54f4d05 100644
@@ -15,23 +15,8 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include "asm/arch/spl.h"
 
-/* boot head definition from sun4i boot code */
-struct boot_file_head {
-	uint32_t b_instruction;	/* one intruction jumping to real code */
-	uint8_t magic[8];	/* ="eGON.BT0" or "eGON.BT1", not C-style str */
-	uint32_t check_sum;	/* generated by PC */
-	uint32_t length;	/* generated by PC */
-	/*
-	 * We use a simplified header, only filling in what is needed
-	 * by the boot ROM. To be compatible with Allwinner tools we
-	 * would need to implement the proper fields here instead of
-	 * padding.
-	 */
-	uint8_t pad[12];		/* align to 32 bytes */
-};
-
-#define BOOT0_MAGIC                     "eGON.BT0"
 #define STAMP_VALUE                     0x5F0A6C39
 
 /* check sum functon from sun4i boot code */
Signature · 1 line
2.4.6
#2 lore raw

PATCH v3 1/4 sunxi: move SPL-related definitions to platform-specific include

Am 17.09.2015 um 18:52 schrieb Bernhard Nortmann:

Quoted 73 lines

The sunxi platform currently doesn't seem to make any use of the asm/arch-sunxi/spl.h file. This patch moves some declarations from tools/mksunxiboot.c into it.

This enables us to reuse those definitions when extending the sunxi board code (boards/sunxi/boards.c).

---

Changes in v3:
- (new with v3)

Changes in v2: None

  arch/arm/include/asm/arch-sunxi/spl.h | 25 +++++++++++++++++--------
  tools/mksunxiboot.c                   | 17 +----------------
  2 files changed, 18 insertions(+), 24 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +17 -8
index acbec46..751de75 100644
@@ -9,12 +9,21 @@
  #ifndef	_ASM_ARCH_SPL_H_
  #define	_ASM_ARCH_SPL_H_
 
-#define BOOT_DEVICE_NONE	0
-#define BOOT_DEVICE_XIP		1
-#define BOOT_DEVICE_NAND	2
-#define BOOT_DEVICE_ONE_NAND	3
-#define BOOT_DEVICE_MMC2	5 /*emmc*/
-#define BOOT_DEVICE_MMC1	6
-#define BOOT_DEVICE_XIPWAIT	7
-#define BOOT_DEVICE_MMC2_2      0xff
+#define BOOT0_MAGIC		"eGON.BT0"
+
+/* boot head definition from sun4i boot code */
+struct boot_file_head {
+	uint32_t b_instruction;	/* one intruction jumping to real code */
+	uint8_t magic[8];	/* ="eGON.BT0" or "eGON.BT1", not C-style str */
+	uint32_t check_sum;	/* generated by PC */
+	uint32_t length;	/* generated by PC */
+	/*
+	 * We use a simplified header, only filling in what is needed
+	 * by the boot ROM. To be compatible with Allwinner tools we
+	 * would need to implement the proper fields here instead of
+	 * padding.
+	 */
+	uint8_t pad[12];		/* align to 32 bytes */
+};
+
  #endif
tools/mksunxiboot.c +1 -9
index 676d392..54f4d05 100644
@@ -15,23 +15,8 @@
  #include <errno.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+#include "asm/arch/spl.h"
 
-/* boot head definition from sun4i boot code */
-struct boot_file_head {
-	uint32_t b_instruction;	/* one intruction jumping to real code */
-	uint8_t magic[8];	/* ="eGON.BT0" or "eGON.BT1", not C-style str */
-	uint32_t check_sum;	/* generated by PC */
-	uint32_t length;	/* generated by PC */
-	/*
-	 * We use a simplified header, only filling in what is needed
-	 * by the boot ROM. To be compatible with Allwinner tools we

tools/mksunxiboot.c line 22

Quoted 10 lines
tools/mksunxiboot.c +0 -7
-	 * would need to implement the proper fields here instead of
-	 * padding.
-	 */
-	uint8_t pad[12];		/* align to 32 bytes */
-};
-
-#define BOOT0_MAGIC                     "eGON.BT0"
  #define STAMP_VALUE                     0x5F0A6C39
 
  /* check sum functon from sun4i boot code */

One minor thing: This doesn't touch the boilerplate header of asm/arch-sunxi/spl.h. However "a copy of omap3/spl.h" and the copyright notice don't really apply any longer, so feel free to change that to something more suitable...

Regards, B. Nortmann

#3 lore raw

PATCH v3 1/4 sunxi: move SPL-related definitions to platform-specific include

Hi,

Quoted 78 lines · Bernhard Nortmann

Am 17.09.2015 um 18:52 schrieb Bernhard Nortmann:

Quoted 77 lines

The sunxi platform currently doesn't seem to make any use of the asm/arch-sunxi/spl.h file. This patch moves some declarations from tools/mksunxiboot.c into it.

This enables us to reuse those definitions when extending the sunxi board code (boards/sunxi/boards.c).

---

Changes in v3:
- (new with v3)

Changes in v2: None

  arch/arm/include/asm/arch-sunxi/spl.h | 25 +++++++++++++++++--------
  tools/mksunxiboot.c                   | 17 +----------------
  2 files changed, 18 insertions(+), 24 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +17 -8
index acbec46..751de75 100644
@@ -9,12 +9,21 @@
  #ifndef    _ASM_ARCH_SPL_H_
  #define    _ASM_ARCH_SPL_H_
-#define BOOT_DEVICE_NONE    0
-#define BOOT_DEVICE_XIP        1
-#define BOOT_DEVICE_NAND    2
-#define BOOT_DEVICE_ONE_NAND    3
-#define BOOT_DEVICE_MMC2    5 /*emmc*/
-#define BOOT_DEVICE_MMC1    6
-#define BOOT_DEVICE_XIPWAIT    7
-#define BOOT_DEVICE_MMC2_2      0xff
+#define BOOT0_MAGIC        "eGON.BT0"
+
+/* boot head definition from sun4i boot code */
+struct boot_file_head {
+    uint32_t b_instruction;    /* one intruction jumping to real code */
+    uint8_t magic[8];    /* ="eGON.BT0" or "eGON.BT1", not C-style str */
+    uint32_t check_sum;    /* generated by PC */
+    uint32_t length;    /* generated by PC */
+    /*
+     * We use a simplified header, only filling in what is needed
+     * by the boot ROM. To be compatible with Allwinner tools we
+     * would need to implement the proper fields here instead of
+     * padding.
+     */
+    uint8_t pad[12];        /* align to 32 bytes */
+};
+
  #endif
tools/mksunxiboot.c +1 -15
index 676d392..54f4d05 100644
@@ -15,23 +15,8 @@
  #include <errno.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+#include "asm/arch/spl.h"
-/* boot head definition from sun4i boot code */
-struct boot_file_head {
-    uint32_t b_instruction;    /* one intruction jumping to real code */
-    uint8_t magic[8];    /* ="eGON.BT0" or "eGON.BT1", not C-style str */
-    uint32_t check_sum;    /* generated by PC */
-    uint32_t length;    /* generated by PC */
-    /*
-     * We use a simplified header, only filling in what is needed
-     * by the boot ROM. To be compatible with Allwinner tools we
-     * would need to implement the proper fields here instead of
-     * padding.
-     */
-    uint8_t pad[12];        /* align to 32 bytes */
-};
-
Quoted 8 lines

tools/mksunxiboot.c line 22

Quoted 3 lines
tools/mksunxiboot.c +0 -1
-#define BOOT0_MAGIC                     "eGON.BT0"
  #define STAMP_VALUE                     0x5F0A6C39
  /* check sum functon from sun4i boot code */

One minor thing: This doesn't touch the boilerplate header of asm/arch-sunxi/spl.h. However "a copy of omap3/spl.h" and the copyright notice don't really apply any longer, so feel free to change that to something more suitable...

Good point, I've fixed this up in my personal tree.

Regards,

Hans

#4 lore raw

PATCH v3 2/4 sunxi: (mksunxiboot) signature to indicate "sunxi" SPL variant

In reply to Bernhard Nortmann

This patch follows up on a discussion of ways to improve support for the sunxi FEL ("USB boot") mechanism, especially with regard to boot scripts, see:
https://groups.google.com/d/msg/linux-sunxi/wBEGUoLNRro/rHGq6nSYCQAJ

The idea is to convert the (currently unused) "pad" bytes in the SPL header into an area where data can be passed to U-Boot. To do this safely, we have to make sure that we're actually using our "sunxi" flavor of the SPL, and not the Allwinner boot0.

The modified mksunxiboot introduces a special signature to the SPL header in place of the "pub_head_size" field. This can be used to reliably distinguish between compatible versions of sunxi SPL and anything else (older variants or Allwinner's boot0).

---

Changes in v3:
- adapted to use asm/arch/spl.h

Changes in v2:
- Rename field to fel_script_address, discard fel_data_size
- Clearing header fields is no longer needed, as mksunxiboot.c zeroes entire image first

 arch/arm/include/asm/arch-sunxi/spl.h | 19 ++++++++++++++++++-
 tools/mksunxiboot.c                   |  4 ++++
 2 files changed, 22 insertions(+), 1 deletion(-)
arch/arm/include/asm/arch-sunxi/spl.h +18 -1
index 751de75..08fe32d 100644
@@ -10,6 +10,8 @@
 #define	_ASM_ARCH_SPL_H_
 
 #define BOOT0_MAGIC		"eGON.BT0"
+#define SPL_SIGNATURE		"SPL" /* marks "sunxi" SPL header */
+#define SPL_HEADER_VERSION	1
 
 /* boot head definition from sun4i boot code */
 struct boot_file_head {
@@ -22,8 +24,23 @@ struct boot_file_head {
 	 * by the boot ROM. To be compatible with Allwinner tools we
 	 * would need to implement the proper fields here instead of
 	 * padding.
+	 *
+	 * Actually we want the ability to recognize our "sunxi" variant
+	 * of the SPL. To do so, let's place a special signature into the
+	 * "pub_head_size" field. We can reasonably expect Allwinner's
+	 * boot0 to always have the upper 16 bits of this set to 0 (after
+	 * all the value shouldn't be larger than the limit imposed by
+	 * SRAM size).
+	 * If the signature is present (at 0x14), then we know it's safe
+	 * to use the remaining 8 bytes (at 0x18) for our own purposes.
+	 * (E.g. sunxi-tools "fel" utility can pass information there.)
 	 */
-	uint8_t pad[12];		/* align to 32 bytes */
+	union {
+		uint32_t pub_head_size;
+		uint8_t spl_signature[4];
+	};
+	uint32_t fel_script_address;
+	uint32_t reserved;		/* padding, align to 32 bytes */
 };
 
 #endif
tools/mksunxiboot.c +4 -0
index 54f4d05..9c1c5b7 100644
@@ -118,6 +118,10 @@ int main(int argc, char *argv[])
 		ALIGN(file_size + sizeof(struct boot_file_head), BLOCK_SIZE);
 	img.header.b_instruction = cpu_to_le32(img.header.b_instruction);
 	img.header.length = cpu_to_le32(img.header.length);
+
+	memcpy(img.header.spl_signature, SPL_SIGNATURE, 3); /* "sunxi" marker */
+	img.header.spl_signature[3] = SPL_HEADER_VERSION;
+
 	gen_check_sum(&img.header);
 
 	count = write(fd_out, &img, le32_to_cpu(img.header.length));
Signature · 1 line
2.4.6
#5 lore raw

PATCH v3 3/4 sunxi: retrieve FEL-provided values to environment variables

In reply to Bernhard Nortmann

This patch extends the misc_init_r() function on sunxi boards to test for the presence of a suitable "sunxi" SPL header. If found, and the loader ("fel" utility) provided a non-zero value for the boot.scr address, then the corresponding environment variable fel_scriptaddr gets set.

misc_init_r() also sets (or clears) the "fel_booted" variable depending on the active boot device, using the same logic as spl_boot_device().

The goal is to provide sufficient information (within the U-Boot environment) to make intelligent decisions on how to continue the boot process, allowing specific customizations for the "FEL boot" case.

---

Changes in v3:
- make use of asm/arch/spl.h to share definitions / helper macro
- revert SPL version check to expect exact SPL_HEADER_VERSION

Changes in v2:
- renamed fel_data_addr to fel_script_addr, discarded fel_data_size
- make sure that FEL-related environment vars are always cleared first
- support minimum and maximum SPL (header) version, more verbose error messages

 arch/arm/cpu/armv7/sunxi/board.c      |  2 +-
 arch/arm/include/asm/arch-sunxi/spl.h |  5 +++++
 arch/arm/include/asm/spl.h            |  5 +++++
 board/sunxi/board.c                   | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 1 deletion(-)
arch/arm/cpu/armv7/sunxi/board.c +1 -1
index b40198b..0d68d20 100644
@@ -152,7 +152,7 @@ u32 spl_boot_device(void)
 	 * binary over USB. If it is found, it determines where SPL was
 	 * read from.
 	 */
-	if (readl(4) != 0x4E4F4765 || readl(8) != 0x3054422E) /* eGON.BT0 */
+	if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */
 		return BOOT_DEVICE_BOARD;
 
 	/* The BROM will try to boot from mmc0 first, so try that first. */
arch/arm/include/asm/arch-sunxi/spl.h +5 -0
index 08fe32d..8abf79a 100644
@@ -13,6 +13,9 @@
 #define SPL_SIGNATURE		"SPL" /* marks "sunxi" SPL header */
 #define SPL_HEADER_VERSION	1
 
+/* Note: A80 will require special handling here: SPL_ADDR 0x10000 */
+#define SPL_ADDR		0x0
+
 /* boot head definition from sun4i boot code */
 struct boot_file_head {
 	uint32_t b_instruction;	/* one intruction jumping to real code */
@@ -43,4 +46,6 @@ struct boot_file_head {
 	uint32_t reserved;		/* padding, align to 32 bytes */
 };
 
+#define is_boot0_magic(addr)	(memcmp((void *)addr, BOOT0_MAGIC, 8) == 0)
+
 #endif
arch/arm/include/asm/spl.h +5 -0
index 6db405d..6587732 100644
@@ -7,6 +7,11 @@
 #ifndef	_ASM_SPL_H_
 #define	_ASM_SPL_H_
 
+#if defined(CONFIG_SUNXI)
+/* sunxi platform-specific additions */
+#include <asm/arch/spl.h>
+#endif
+
 #if defined(CONFIG_OMAP) \
 	|| defined(CONFIG_EXYNOS4) || defined(CONFIG_EXYNOS5) \
 	|| defined(CONFIG_EXYNOS4210)
board/sunxi/board.c +35 -0
index 9c855f6..096d127 100644
@@ -516,6 +516,31 @@ void get_board_serial(struct tag_serialnr *serialnr)
 }
 #endif
 
+#if !defined(CONFIG_SPL_BUILD)
+#include <asm/arch/spl.h>
+
+/*
+ * Check the SPL header for the "sunxi" variant. If found: parse values
+ * that might have been passed by the loader ("fel" utility), and update
+ * the environment accordingly.
+ */
+static void parse_spl_header(const uint32_t spl_addr)
+{
+	struct boot_file_head *spl = (void *)spl_addr;
+	if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) == 0) {
+		uint8_t spl_header_version = spl->spl_signature[3];
+		if (spl_header_version == SPL_HEADER_VERSION) {
+			if (spl->fel_script_address)
+				setenv_hex("fel_scriptaddr",
+					   spl->fel_script_address);
+			return;
+		}
+		printf("sunxi SPL version mismatch: expected %u, got %u\n",
+		       SPL_HEADER_VERSION, spl_header_version);
+	}
+}
+#endif
+
 #ifdef CONFIG_MISC_INIT_R
 int misc_init_r(void)
 {
@@ -524,6 +549,16 @@ int misc_init_r(void)
 	uint8_t mac_addr[6];
 	int ret;
 
+#if !defined(CONFIG_SPL_BUILD)
+	setenv("fel_booted", NULL);
+	setenv("fel_scriptaddr", NULL);
+	/* determine if we are running in FEL mode */
+	if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
+		setenv("fel_booted", "1");
+		parse_spl_header(SPL_ADDR);
+	}
+#endif
+
 	ret = sunxi_get_sid(sid);
 	if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
 		if (!getenv("ethaddr")) {
Signature · 1 line
2.4.6
#6 lore raw

PATCH v3 3/4 sunxi: retrieve FEL-provided values to environment variables

Hi,

Quoted 71 lines · Bernhard Nortmann

This patch extends the misc_init_r() function on sunxi boards to test for the presence of a suitable "sunxi" SPL header. If found, and the loader ("fel" utility) provided a non-zero value for the boot.scr address, then the corresponding environment variable fel_scriptaddr gets set.

misc_init_r() also sets (or clears) the "fel_booted" variable depending on the active boot device, using the same logic as spl_boot_device().

The goal is to provide sufficient information (within the U-Boot environment) to make intelligent decisions on how to continue the boot process, allowing specific customizations for the "FEL boot" case.

---

Changes in v3:
- make use of asm/arch/spl.h to share definitions / helper macro
- revert SPL version check to expect exact SPL_HEADER_VERSION

Changes in v2:
- renamed fel_data_addr to fel_script_addr, discarded fel_data_size
- make sure that FEL-related environment vars are always cleared first
- support minimum and maximum SPL (header) version, more verbose error messages

  arch/arm/cpu/armv7/sunxi/board.c      |  2 +-
  arch/arm/include/asm/arch-sunxi/spl.h |  5 +++++
  arch/arm/include/asm/spl.h            |  5 +++++
  board/sunxi/board.c                   | 35 +++++++++++++++++++++++++++++++++++
  4 files changed, 46 insertions(+), 1 deletion(-)
arch/arm/cpu/armv7/sunxi/board.c +1 -1
index b40198b..0d68d20 100644
@@ -152,7 +152,7 @@ u32 spl_boot_device(void)
  	 * binary over USB. If it is found, it determines where SPL was
  	 * read from.
  	 */
-	if (readl(4) != 0x4E4F4765 || readl(8) != 0x3054422E) /* eGON.BT0 */
+	if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */
  		return BOOT_DEVICE_BOARD;
 
  	/* The BROM will try to boot from mmc0 first, so try that first. */
arch/arm/include/asm/arch-sunxi/spl.h +5 -0
index 08fe32d..8abf79a 100644
@@ -13,6 +13,9 @@
  #define SPL_SIGNATURE		"SPL" /* marks "sunxi" SPL header */
  #define SPL_HEADER_VERSION	1
 
+/* Note: A80 will require special handling here: SPL_ADDR 0x10000 */
+#define SPL_ADDR		0x0
+
  /* boot head definition from sun4i boot code */
  struct boot_file_head {
  	uint32_t b_instruction;	/* one intruction jumping to real code */
@@ -43,4 +46,6 @@ struct boot_file_head {
  	uint32_t reserved;		/* padding, align to 32 bytes */
  };
 
+#define is_boot0_magic(addr)	(memcmp((void *)addr, BOOT0_MAGIC, 8) == 0)
+
  #endif
arch/arm/include/asm/spl.h +0 -0
index 6db405d..6587732 100644
@@ -7,6 +7,11 @@
  #ifndef	_ASM_SPL_H_

arch/arm/include/asm/spl.h line 17

Quoted 10 lines
arch/arm/include/asm/spl.h +5 -0
  #define	_ASM_SPL_H_
 
+#if defined(CONFIG_SUNXI)
+/* sunxi platform-specific additions */
+#include <asm/arch/spl.h>
+#endif
+
  #if defined(CONFIG_OMAP) \
  	|| defined(CONFIG_EXYNOS4) || defined(CONFIG_EXYNOS5) \
  	|| defined(CONFIG_EXYNOS4210)

There is no need to pollute a non sunxi header this way, we can simply do "#include <asm/arch/spl.h>" where needed.

No need to resend I've fixed this up in my tree.

Regards,

Hans

Quoted 54 lines
board/sunxi/board.c +35 -0
index 9c855f6..096d127 100644
@@ -516,6 +516,31 @@ void get_board_serial(struct tag_serialnr *serialnr)
  }
  #endif
 
+#if !defined(CONFIG_SPL_BUILD)
+#include <asm/arch/spl.h>
+
+/*
+ * Check the SPL header for the "sunxi" variant. If found: parse values
+ * that might have been passed by the loader ("fel" utility), and update
+ * the environment accordingly.
+ */
+static void parse_spl_header(const uint32_t spl_addr)
+{
+	struct boot_file_head *spl = (void *)spl_addr;
+	if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) == 0) {
+		uint8_t spl_header_version = spl->spl_signature[3];
+		if (spl_header_version == SPL_HEADER_VERSION) {
+			if (spl->fel_script_address)
+				setenv_hex("fel_scriptaddr",
+					   spl->fel_script_address);
+			return;
+		}
+		printf("sunxi SPL version mismatch: expected %u, got %u\n",
+		       SPL_HEADER_VERSION, spl_header_version);
+	}
+}
+#endif
+
  #ifdef CONFIG_MISC_INIT_R
  int misc_init_r(void)
  {
@@ -524,6 +549,16 @@ int misc_init_r(void)
  	uint8_t mac_addr[6];
  	int ret;
 
+#if !defined(CONFIG_SPL_BUILD)
+	setenv("fel_booted", NULL);
+	setenv("fel_scriptaddr", NULL);
+	/* determine if we are running in FEL mode */
+	if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
+		setenv("fel_booted", "1");
+		parse_spl_header(SPL_ADDR);
+	}
+#endif
+
  	ret = sunxi_get_sid(sid);
  	if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
  		if (!getenv("ethaddr")) {
#7 lore raw

PATCH v3 4/4 sunxi: add "fel" boot target

In reply to Bernhard Nortmann

This patch makes use of the previous changes to add a new "fel" boot target for sunxi boards.

When booting via FEL, it's often desirable to work around the absence of other (usable) boot devices - or to be able to override them, deviating from the standard boot sequence. To achieve this, the "fel" boot target gets the highest priority, but won't actually do anything unless certain criteria are met.

The "bootcmd_fel" implementation proposed here first tests if an actual FEL boot takes place (using the "fel_booted" env var), and secondly checks that "fel_scriptaddr" was set (originating from the 'loader', i.e. the sunxi-tools fel utility). If both checks pass, then it will try to execute the boot script (boot.scr) at the given address. In case of an error (e.g. an invalid image), the source command might return "false", causing "distro_bootcmd" to proceed with the next boot target.

---

Changes in v3: None
Changes in v2:
- renamed fel_data_addr to fel_scriptaddr
- combined both tests into one as suggested by Hans de Goede

 include/configs/sunxi-common.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/configs/sunxi-common.h +11 -0
index 8e47d11..0161631 100644
@@ -431,7 +431,18 @@ extern int soft_i2c_gpio_scl;
 #define BOOT_TARGET_DEVICES_USB(func)
 #endif
 
+/* FEL boot support, auto-execute boot.scr if a script address was provided */
+#define BOOTENV_DEV_FEL(devtypeu, devtypel, instance) \
+	"bootcmd_fel=" \
+		"if test -n ${fel_booted} && test -n ${fel_scriptaddr}; then " \
+			"echo '(FEL boot)'; " \
+			"source ${fel_scriptaddr}; " \
+		"fi\0"
+#define BOOTENV_DEV_NAME_FEL(devtypeu, devtypel, instance) \
+	"fel "
+
 #define BOOT_TARGET_DEVICES(func) \
+	func(FEL, fel, na) \
 	BOOT_TARGET_DEVICES_MMC(func) \
 	BOOT_TARGET_DEVICES_SCSI(func) \
 	BOOT_TARGET_DEVICES_USB(func) \
Signature · 1 line
2.4.6
#8 lore raw

v3 cover sunxi: support FEL-provided environment vars and "fel" boot target

In reply to Bernhard Nortmann

Hi,

Quoted 58 lines · Bernhard Nortmann

This patch series builds upon
http://lists.denx.de/pipermail/u-boot/2015-September/226515.html
http://lists.denx.de/pipermail/u-boot/2015-September/226688.html

v2 combines the previous submissions, and adds some suggested fixes/changes.

v3 introduces another patch at the start of the series to allow using shared definitions from a common asm/arch-sunxi/spl.h include. It's also aimed at addressing some of Siarhei's comments.

Siarhei: As I've shuffled things around a bit for that, I'm not including your ACK on patch v3 2/4. The 4/4 one (bootcmd_fel) is unchanged, and now includes your ACK.

The sunxi-tool side of things is discussed here:
https://www.mail-archive.com/linux-sunxi at googlegroups.com/msg13071.html

* Hans de Goede already pointed out that it might be preferable to make use of the spl_boot_device() function even from the main (non-SPL) U-Boot binary (e.g. for the "NAND" case). Currently this function is only available with CONFIG_SPL_BUILD set, and implemented in arch/arm/cpu/armv7/sunxi/board.c
Would it be safe to enable it for non-SPL builds and use something like "(spl_boot_device == BOOT_DEVICE_BOARD)" for misc_init_r()?

* Side note: the sunxi spl_boot_device() will probably require some future refinement anyway, to account for the 'oddball' A80. That SoC requires the SPL at a different address (0x10000 instead of 0x0).
I've tried to address this (at least in part) by introducing a SPL_ADDR definition in the platform-specific spl.h.

Regards, B. Nortmann

Changes in v3:
- (new with v3)
- adapted to use asm/arch/spl.h
- make use of asm/arch/spl.h to share definitions / helper macro
- revert SPL version check to expect exact SPL_HEADER_VERSION

Changes in v2:
- Rename field to fel_script_address, discard fel_data_size
- Clearing header fields is no longer needed, as mksunxiboot.c zeroes entire image first
- renamed fel_data_addr to fel_script_addr, discarded fel_data_size
- make sure that FEL-related environment vars are always cleared first
- support minimum and maximum SPL (header) version, more verbose error messages
- renamed fel_data_addr to fel_scriptaddr
- combined both tests into one as suggested by Hans de Goede

Bernhard Nortmann (4):
sunxi: move SPL-related definitions to platform-specific include
sunxi: (mksunxiboot) signature to indicate "sunxi" SPL variant
sunxi: retrieve FEL-provided values to environment variables
sunxi: add "fel" boot target

Quoted 7 lines
  arch/arm/cpu/armv7/sunxi/board.c      |  2 +-
  arch/arm/include/asm/arch-sunxi/spl.h | 47 +++++++++++++++++++++++++++++------
  arch/arm/include/asm/spl.h            |  5 ++++
  board/sunxi/board.c                   | 35 ++++++++++++++++++++++++++
  include/configs/sunxi-common.h        | 11 ++++++++
  tools/mksunxiboot.c                   | 21 ++++------------
  6 files changed, 96 insertions(+), 25 deletions(-)

Thanks, I've added these to my personal tree and will include it in a future pull-req.

Regards,

Hans

#9 lore raw

v3 cover sunxi: support FEL-provided environment vars and "fel" boot target

Hello Hans!

Am 17.09.2015 um 23:48 schrieb Hans de Goede:

Quoted 8 lines

Hi,

Thanks, I've added these to my personal tree and will include it in a future pull-req.

Regards,

Hans

Great. Thanks!

Regards, Bernhard