Skip to content

Instantly share code, notes, and snippets.

@n1tehawk
Created June 8, 2016 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1tehawk/9899b3f91ae2bdb9235e162cc16fe26c to your computer and use it in GitHub Desktop.
Save n1tehawk/9899b3f91ae2bdb9235e162cc16fe26c to your computer and use it in GitHub Desktop.
From 42caebb0b014565f59a5911ea5273b33baa58215 Mon Sep 17 00:00:00 2001
From: Bernhard Nortmann <bernhard.nortmann@web.de>
Date: Wed, 8 Jun 2016 16:34:06 +0200
Subject: [PATCH] [Experimental] sunxi: Make U-Boot auto-import FEL data in
uEnv format
A suitable format is detected by having the environment data
(at fel_script_addr) start with a special "#=uEnv" marker, which
then triggers a himport_r() as part of the parse_spl_header()
startup code.
That means that environment vars can be changed this way even
before U-Boot will attempt to autoboot. Specifically, this also
allows overriding "bootcmd".
Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
---
board/sunxi/board.c | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index d09cf6d..c96bac1 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -573,6 +573,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
#if !defined(CONFIG_SPL_BUILD)
#include <asm/arch/spl.h>
+#include <environment.h>
/*
* Check the SPL header for the "sunxi" variant. If found: parse values
@@ -582,17 +583,35 @@ void get_board_serial(struct tag_serialnr *serialnr)
static void parse_spl_header(const uint32_t spl_addr)
{
struct boot_file_head *spl = (void *)(ulong)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;
- }
+
+ if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
+ return; /* sunxi signature mismatch, no usable header */
+
+ uint8_t spl_header_version = spl->spl_signature[3];
+ if (spl_header_version != SPL_HEADER_VERSION) {
printf("sunxi SPL version mismatch: expected %u, got %u\n",
SPL_HEADER_VERSION, spl_header_version);
+ return;
+ }
+ if (!spl->fel_script_address)
+ return;
+
+ const char *script = (char *)spl->fel_script_address;
+ if (memcmp(script, "#=uEnv", 6) == 0) {
+ /*
+ * magic for uEnv.txt compatible format, so "env import -t"
+ * the string at fel_script_address right away.
+ *
+ * Caveat: It's up to the uploading utility (sunxi-fel) to make
+ * sure that the environment data is properly NUL-terminated!
+ */
+ himport_r(&env_htab, script, strlen(script),
+ '\n', H_NOCLEAR, 0, 0, NULL);
+ return;
}
+ /* otherwise assume .scr format (mkimage-type script) */
+ setenv_hex("fel_scriptaddr", spl->fel_script_address);
+ return;
}
#endif
--
2.7.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment