public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [U-Boot, v3] sunxi: FEL - Add the ability to recognize and auto-import uEnv-style data
Date: Fri, 10 Jun 2016 21:31:00 +0200	[thread overview]
Message-ID: <d6f99eaa-fbcf-b1a3-4e70-97ac97ec6eed@redhat.com> (raw)
In-Reply-To: <1465450655-2477-1-git-send-email-bernhard.nortmann@web.de>

Hi,

On 09-06-16 07:37, Bernhard Nortmann wrote:
> The patch converts one of the "reserved" fields in the sunxi SPL
> header to a fel_uEnv_length entry. When booting over USB ("FEL
> mode"), this enables the sunxi-fel utility to pass the string
> length of uEnv.txt compatible data; at the same time requesting
> that this data be imported into the U-Boot environment.
>
> If parse_spl_header() in the sunxi board.c encounters a non-zero
> value in this header field, it will therefore call himport_r() to
> merge the string (lines) passed via FEL into the default settings.
> Environment vars can be changed this way even before U-Boot will
> attempt to autoboot - specifically, this also allows overriding
> "bootcmd".
>
> With fel_script_addr set and a zero fel_uEnv_length, U-Boot is
> safe to assume that data in .scr format (a mkimage-type script)
> was passed at fel_script_addr, and will handle it using the
> existing mechanism ("bootcmd_fel").
>
> Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
> Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>

Thanks, I've added this to u-boot-sunxi/next for merging into
v2016.09 as soon as the merge window for that opens.

Regards,

Hans



> ---
> A corresponding proof-of-concept version of sunxi-fel is available
> from my https://github.com/n1tehawk/sunxi-tools/tree/20160608_uEnv-magic
> branch. I've picked up the suggestion to use a "#=uEnv" magic string
> to request that a file be treated as uEnv.txt-style data.
>
> For example, use your text editor to save a my.env file with
>
> #=uEnv
> myvar=world
> bootcmd=echo "Hello $myvar."
>
> and then test it with
> ./sunxi-fel uboot u-boot-sunxi-with-spl.bin write 0x43100000 my.env
>
> You should see U-Boot's autoboot print the corresponding message
> and drop you to the prompt, proving that you have successfully
> overwritten the "bootcmd".
>
> Changes in v3:
> - Dropped a surplus "return;" at the end of parse_spl_header()
> - Have "FEL" in the subject line to clarify the scope
> - Added "Acked-by" line
>
> Changes in v2:
> - Patch renamed to something more suitable (was "sunxi: Add the
>   ability to pass (script) filesize in the SPL header")
> - The data field is now named fel_uEnv_length, and comes with
>   a corresponding description in spl.h
> - Instead of simply passing file size, fel_uEnv_length is now
>   associated with uEnv.txt format. The patch modifies U-Boot's
>   sunxi parse_spl_header() to auto-import such data.
>
>  arch/arm/include/asm/arch-sunxi/spl.h |  9 ++++++++-
>  board/sunxi/board.c                   | 29 +++++++++++++++++++++--------
>  2 files changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/arch/arm/include/asm/arch-sunxi/spl.h b/arch/arm/include/asm/arch-sunxi/spl.h
> index a0f33b0..a966a88 100644
> --- a/arch/arm/include/asm/arch-sunxi/spl.h
> +++ b/arch/arm/include/asm/arch-sunxi/spl.h
> @@ -49,7 +49,14 @@ struct boot_file_head {
>  		uint8_t spl_signature[4];
>  	};
>  	uint32_t fel_script_address;
> -	uint32_t reserved1[3];
> +	/*
> +	 * If the fel_uEnv_length member below is set to a non-zero value,
> +	 * it specifies the size (byte count) of data at fel_script_address.
> +	 * At the same time this indicates that the data is in uEnv.txt
> +	 * compatible format, ready to be imported via "env import -t".
> +	 */
> +	uint32_t fel_uEnv_length;
> +	uint32_t reserved1[2];
>  	uint32_t boot_media;		/* written here by the boot ROM */
>  	uint32_t reserved2[5];		/* padding, align to 64 bytes */
>  };
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index d09cf6d..b5a50f4 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,29 @@ 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; /* 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;
> +
> +	if (spl->fel_uEnv_length != 0) {
> +		/*
> +		 * data is expected in uEnv.txt compatible format, so "env
> +		 * import -t" the string(s) at fel_script_address right away.
> +		 */
> +		himport_r(&env_htab, (char *)spl->fel_script_address,
> +			  spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL);
> +		return;
>  	}
> +	/* otherwise assume .scr format (mkimage-type script) */
> +	setenv_hex("fel_scriptaddr", spl->fel_script_address);
>  }
>  #endif
>
>

      reply	other threads:[~2016-06-10 19:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-14  1:13 [U-Boot] [PATCH v2] sunxi: Increase SPL header size to 64 bytes to avoid code corruption Siarhei Siamashka
2016-05-15 10:04 ` Hans de Goede
2016-05-16  9:56 ` Bernhard Nortmann
2016-05-16 17:52   ` Hans de Goede
2016-06-02 14:57     ` Siarhei Siamashka
2016-06-03  7:30       ` Bernhard Nortmann
2016-06-03 10:53         ` Hans de Goede
2016-06-04 17:12           ` [U-Boot] [PATCH] sunxi: Add the ability to pass (script) filesize in the SPL header Bernhard Nortmann
2016-06-05 11:44             ` Siarhei Siamashka
2016-06-05 13:01               ` Bernhard Nortmann
2016-06-06  9:20                 ` Siarhei Siamashka
2016-06-07 14:09                   ` Bernhard Nortmann
2016-06-07 17:14                     ` Siarhei Siamashka
2016-06-08 18:23             ` [U-Boot] [PATCH v2] sunxi: Add the ability to recognize and auto-import uEnv-style data Bernhard Nortmann
2016-06-08 20:13               ` Hans de Goede
2016-06-08 21:29                 ` Bernhard Nortmann
2016-06-09  0:14                 ` Siarhei Siamashka
2016-06-09  5:37                   ` [U-Boot] [PATCH v3] sunxi: FEL - " Bernhard Nortmann
2016-06-10 19:31                     ` Hans de Goede [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d6f99eaa-fbcf-b1a3-4e70-97ac97ec6eed@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox