All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 2/3] sunxi/spl: Detect at runtime where from SPL was read
Date: Sat, 06 Jun 2015 16:56:18 +0200	[thread overview]
Message-ID: <55730A12.7080409@redhat.com> (raw)
In-Reply-To: <1432911343-8357-2-git-send-email-dkochmanski@turtle-solutions.eu>

Hi,

On 29-05-15 16:55, Daniel Kochma?ski wrote:
> Make possible using single `u-boot-sunxi-with-spl.bin` binary for both NAND
> memory and SD card. Detection where SPL was read from is implemented in
> `spl_boot_device`.
>
> V2:
> - Move signature verification to helper function
> - Avoid unnecessary condition nesting
>
> V3:
> - Further simplification of conditions
> - Move reassigning mmc block.dev numbers from `board_mmc_init` to
>    `spl_boot_device`
> - If signature wasn't found on mmc0 and SPL_NAND_SUPPORT isn't enabled
>    don't assume mmc2 is a valid boot device - check for egon signature
>    first
>
> Signed-off-by: Daniel Kochma?ski <dkochmanski@turtle-solutions.eu>
> CC: Roy Spliet <r.spliet@ultimaker.com>
> Cc: Ian Campbell <ijc@hellion.org.uk>
> Cc: Hans De Goede <hdegoede@redhat.com>

Thanks, pushed with a few small coding style fixes (braces placement) to
u-boot-sunxi/next for merging into v2015.10 .

Regards,

Hans


> ---
>   arch/arm/cpu/armv7/sunxi/board.c | 63 ++++++++++++++++++++++++++--------------
>   1 file changed, 41 insertions(+), 22 deletions(-)
>
> diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c
> index a82c8b9..c06922c 100644
> --- a/arch/arm/cpu/armv7/sunxi/board.c
> +++ b/arch/arm/cpu/armv7/sunxi/board.c
> @@ -11,6 +11,7 @@
>    */
>
>   #include <common.h>
> +#include <mmc.h>
>   #include <i2c.h>
>   #include <serial.h>
>   #ifdef CONFIG_SPL_BUILD
> @@ -22,6 +23,7 @@
>   #include <asm/arch/gpio.h>
>   #include <asm/arch/sys_proto.h>
>   #include <asm/arch/timer.h>
> +#include <asm/arch/mmc.h>
>
>   #include <linux/compiler.h>
>
> @@ -117,26 +119,18 @@ void s_init(void)
>   }
>
>   #ifdef CONFIG_SPL_BUILD
> +DECLARE_GLOBAL_DATA_PTR;
> +
>   /* The sunxi internal brom will try to loader external bootloader
>    * from mmc0, nand flash, mmc2.
> - *
> - * Unfortunately we can't check how SPL was loaded so assume it's
> - * always the first SD/MMC controller, unless it was explicitly
> - * stated that SPL is on nand flash.
>    */
>   u32 spl_boot_device(void)
>   {
> -#if defined(CONFIG_SPL_NAND_SUPPORT)
> +	struct mmc *mmc0, *mmc1;
>   	/*
> -	 * This is compile time configuration informing SPL, that it
> -	 * was loaded from nand flash.
> -	 */
> -	return BOOT_DEVICE_NAND;
> -#else
> -	/*
> -	 * When booting from the SD card, the "eGON.BT0" signature is expected
> -	 * to be found in memory at the address 0x0004 (see the "mksunxiboot"
> -	 * tool, which generates this header).
> +	 * When booting from the SD card or NAND memory, the "eGON.BT0"
> +	 * signature is expected to be found in memory at the address 0x0004
> +	 * (see the "mksunxiboot" tool, which generates this header).
>   	 *
>   	 * When booting in the FEL mode over USB, this signature is patched in
>   	 * memory and replaced with something else by the 'fel' tool. This other
> @@ -144,16 +138,41 @@ u32 spl_boot_device(void)
>   	 * valid bootable SD card image (because the BROM would refuse to
>   	 * execute the SPL in this case).
>   	 *
> -	 * This branch is just making a decision at runtime whether to load
> -	 * the main u-boot binary from the SD card (if the "eGON.BT0" signature
> -	 * is found) or return to the FEL code in the BROM to wait and receive
> -	 * the main u-boot binary over USB.
> +	 * This checks for the signature and if it is not found returns to
> +	 * the FEL code in the BROM to wait and receive the main u-boot
> +	 * binary over USB. If it is found, it determines where SPL was
> +	 * read from.
>   	 */
> -	if (readl(4) == 0x4E4F4765 && readl(8) == 0x3054422E) /* eGON.BT0 */
> -		return BOOT_DEVICE_MMC1;
> -	else
> +	if (readl(4) != 0x4E4F4765 || readl(8) != 0x3054422E) /* eGON.BT0 */
>   		return BOOT_DEVICE_BOARD;
> -#endif
> +
> +	/* The BROM will try to boot from mmc0 first, so try that first. */
> +	mmc_initialize(gd->bd);
> +	mmc0 = find_mmc_device(0);
> +	if (sunxi_mmc_has_egon_boot_signature(mmc0))
> +		return BOOT_DEVICE_MMC1;
> +
> +	/* Fallback to booting NAND if enabled. */
> +	if (IS_ENABLED(CONFIG_SPL_NAND_SUPPORT))
> +		return BOOT_DEVICE_NAND;
> +
> +	if (IS_ENABLED(CONFIG_MMC_SUNXI_SLOT_EXTRA) &&
> +	    CONFIG_MMC_SUNXI_SLOT_EXTRA == 2)
> +	{
> +		mmc1 = find_mmc_device(1);
> +		if (sunxi_mmc_has_egon_boot_signature(mmc1))
> +		{
> +			/* spl_mmc.c: spl_mmc_load_image() is hard-coded to
> +			 * use find_mmc_device(0), no matter what we
> +			 * return. Swap mmc0 and mmc2 to make this work. */
> +			mmc0->block_dev.dev = 1;
> +			mmc1->block_dev.dev = 0;
> +			return BOOT_DEVICE_MMC2
> +		}
> +	}
> +
> +	panic("Could not determine boot source\n");
> +	return -1;		/* Never reached */
>   }
>
>   /* No confirmation data available in SPL yet. Hardcode bootmode */
>

  reply	other threads:[~2015-06-06 14:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29 14:55 [U-Boot] [PATCH v3 1/3] sunxi: Create helper function veryfing valid boot signature on MMC Daniel Kochmański
2015-05-29 14:55 ` [U-Boot] [PATCH v3 2/3] sunxi/spl: Detect at runtime where from SPL was read Daniel Kochmański
2015-06-06 14:56   ` Hans de Goede [this message]
2015-05-29 14:55 ` [U-Boot] [PATCH v3 3/3] mmc: Protect `mmc_initialize` from initilizing mmc multiple times Daniel Kochmański
2015-06-06  9:53   ` Hans de Goede
2015-06-06 14:55 ` [U-Boot] [PATCH v3 1/3] sunxi: Create helper function veryfing valid boot signature on MMC Hans de Goede

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=55730A12.7080409@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 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.