All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Samuel Holland <samuel@sholland.org>
Cc: u-boot@lists.denx.de, "Jagan Teki" <jagan@amarulasolutions.com>,
	"AKASHI Takahiro" <takahiro.akashi@linaro.org>,
	"Alexandru Gagniuc" <mr.nuke.me@gmail.com>,
	"Baruch Siach" <baruch@tkos.co.il>,
	"Bharat Gooty" <bharat.gooty@broadcom.com>,
	"Chris Packham" <judge.packham@gmail.com>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Frieder Schrempf" <frieder.schrempf@kontron.de>,
	"Jernej Skrabec" <jernej.skrabec@siol.net>,
	"Marek Behún" <marek.behun@nic.cz>,
	"NXP i.MX U-Boot Team" <uboot-imx@nxp.com>,
	"Naoki Hayama" <naoki.hayama@lineo.co.jp>,
	"Pali Rohár" <pali@kernel.org>,
	"Patrick Delaunay" <patrick.delaunay@foss.st.com>,
	"Priyanka Jain" <priyanka.jain@nxp.com>,
	"Rayagonda Kokatanur" <rayagonda.kokatanur@broadcom.com>,
	"Simon Glass" <sjg@chromium.org>, "Stefan Roese" <sr@denx.de>,
	"Stefano Babic" <sbabic@denx.de>,
	"Sughosh Ganu" <sughosh.ganu@linaro.org>,
	"Trevor Woerner" <twoerner@gmail.com>,
	lauri.hintsala@silabs.com
Subject: Re: [PATCH v2 3/4] sunxi: Support SPL in both eGON and TOC0 images
Date: Mon, 6 Sep 2021 01:30:03 +0100	[thread overview]
Message-ID: <20210906013003.1ddeb87f@slackpad.fritz.box> (raw)
In-Reply-To: <20210822044649.13585-4-samuel@sholland.org>

On Sat, 21 Aug 2021 23:46:47 -0500
Samuel Holland <samuel@sholland.org> wrote:

Hi,

> SPL uses the image header to detect the boot device and to find the
> offset of the next U-Boot stage. Since this information is stored
> differently in the eGON and TOC0 image headers, add code to find the
> correct value based on the image type currently in use.

many thanks for determining this at runtime!

> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
> 
> Changes in v2:
>  - Moved SPL header signature checks out of sunxi_image.h
>  - Refactored SPL header signature checks to use fewer casts
> 
>  arch/arm/include/asm/arch-sunxi/spl.h |  2 --
>  arch/arm/mach-sunxi/board.c           | 50 +++++++++++++++++++++++----
>  2 files changed, 43 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-sunxi/spl.h b/arch/arm/include/asm/arch-sunxi/spl.h
> index 58cdf806d9a..157b11e4897 100644
> --- a/arch/arm/include/asm/arch-sunxi/spl.h
> +++ b/arch/arm/include/asm/arch-sunxi/spl.h
> @@ -19,8 +19,6 @@
>  #define SUNXI_BOOTED_FROM_MMC0_HIGH	0x10
>  #define SUNXI_BOOTED_FROM_MMC2_HIGH	0x12
>  
> -#define is_boot0_magic(addr)	(memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
> -
>  uint32_t sunxi_get_boot_device(void);
>  
>  #endif
> diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
> index d9b04f75fc4..b6f92bdc5e7 100644
> --- a/arch/arm/mach-sunxi/board.c
> +++ b/arch/arm/mach-sunxi/board.c
> @@ -244,12 +244,40 @@ void s_init(void)
>  
>  #define SUNXI_INVALID_BOOT_SOURCE	-1
>  
> -static int sunxi_get_boot_source(void)
> +static struct boot_file_head *sunxi_egon_get_head(void)
>  {
> -	if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */
> -		return SUNXI_INVALID_BOOT_SOURCE;
> +	struct boot_file_head *egon_head = (void *)SPL_ADDR;
> +
> +	if (memcmp(egon_head, BOOT0_MAGIC, 8)) /* eGON.BT0 */

For eGON the magic is not at the beginning of the struct, so you need:
	memcmp(&egon_head->magic, BOOT0_MAGIC, 8)

Otherwise 99.9% of all Allwinner users will be very disappointed ;-)

And there is another problem: For 32-bit SoCs the SPL address is
literally 0 (SRAM A1), so the return value in the successful case is
NULL as well :-(

Maybe have a function to return an enum (EGON, TOC0, NONE/FEL) instead?
After all the address will always be SPL_ADDR. 

Cheers,
Andre

> +		return NULL;
> +
> +	return egon_head;
> +}
> +
> +static struct toc0_main_info *sunxi_toc0_get_info(void)
> +{
> +	struct toc0_main_info *toc0_info = (void *)SPL_ADDR;
> +
> +	if (memcmp(toc0_info->name, TOC0_MAIN_INFO_NAME, 8)) /* TOC0.GLH */
> +		return NULL;
>  
> -	return readb(SPL_ADDR + 0x28);
> +	return toc0_info;
> +}
> +
> +static int sunxi_get_boot_source(void)
> +{
> +	struct boot_file_head *egon_head;
> +	struct toc0_main_info *toc0_info;
> +
> +	egon_head = sunxi_egon_get_head();
> +	if (egon_head)
> +		return readb(&egon_head->boot_media);
> +	toc0_info = sunxi_toc0_get_info();
> +	if (toc0_info)
> +		return readb(&toc0_info->platform[0]);
> +
> +	/* Not a valid image, so we must have been booted via FEL. */
> +	return SUNXI_INVALID_BOOT_SOURCE;
>  }
>  
>  /* The sunxi internal brom will try to loader external bootloader
> @@ -297,10 +325,18 @@ uint32_t sunxi_get_boot_device(void)
>  #ifdef CONFIG_SPL_BUILD
>  static u32 sunxi_get_spl_size(void)
>  {
> -	if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */
> -		return 0;
> +	struct boot_file_head *egon_head;
> +	struct toc0_main_info *toc0_info;
> +
> +	egon_head = sunxi_egon_get_head();
> +	if (egon_head)
> +		return readl(&egon_head->length);
> +	toc0_info = sunxi_toc0_get_info();
> +	if (toc0_info)
> +		return readl(&toc0_info->length);
>  
> -	return readl(SPL_ADDR + 0x10);
> +	/* Not a valid image, so use the default U-Boot offset. */
> +	return 0;
>  }
>  
>  /*


  reply	other threads:[~2021-09-06  0:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-22  4:46 [PATCH v2 0/4] sunxi: TOC0 image type support Samuel Holland
2021-08-22  4:46 ` [PATCH v2 1/4] tools: Separate image types which depend on OpenSSL Samuel Holland
2021-08-22  9:58   ` Pali Rohár
2021-08-22 17:32     ` Samuel Holland
2021-08-24  0:51       ` Andre Przywara
2021-08-22  4:46 ` [PATCH v2 2/4] tools: mkimage: Add Allwinner TOC0 support Samuel Holland
2021-08-22 10:07   ` Pali Rohár
2021-08-22 17:44     ` Samuel Holland
2021-08-22 17:51       ` Pali Rohár
2021-09-06  0:29   ` Andre Przywara
2021-08-22  4:46 ` [PATCH v2 3/4] sunxi: Support SPL in both eGON and TOC0 images Samuel Holland
2021-09-06  0:30   ` Andre Przywara [this message]
2021-08-22  4:46 ` [PATCH v2 4/4] sunxi: Support building a SPL as a TOC0 image Samuel Holland

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=20210906013003.1ddeb87f@slackpad.fritz.box \
    --to=andre.przywara@arm.com \
    --cc=baruch@tkos.co.il \
    --cc=bharat.gooty@broadcom.com \
    --cc=festevam@gmail.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=jagan@amarulasolutions.com \
    --cc=jernej.skrabec@siol.net \
    --cc=judge.packham@gmail.com \
    --cc=lauri.hintsala@silabs.com \
    --cc=marek.behun@nic.cz \
    --cc=mr.nuke.me@gmail.com \
    --cc=naoki.hayama@lineo.co.jp \
    --cc=pali@kernel.org \
    --cc=patrick.delaunay@foss.st.com \
    --cc=priyanka.jain@nxp.com \
    --cc=rayagonda.kokatanur@broadcom.com \
    --cc=samuel@sholland.org \
    --cc=sbabic@denx.de \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=sughosh.ganu@linaro.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=twoerner@gmail.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.