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] [PATCH v3 1/3] sunxi: Create helper function veryfing valid boot signature on MMC
Date: Sat, 06 Jun 2015 16:55:29 +0200	[thread overview]
Message-ID: <557309E1.4090900@redhat.com> (raw)
In-Reply-To: <1432911343-8357-1-git-send-email-dkochmanski@turtle-solutions.eu>

Hi,

On 29-05-15 16:55, Daniel Kochma?ski wrote:
> This patch extracts checking for valid SD card "eGON.BT0" signature from
> `board_mmc_init` into function `sunxi_mmc_has_egon_boot_signature`.
>
> Buffer for mmc sector is allocated and freed at runtime. `panic` is
> triggered on malloc failure.
>
> 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 small bug-fix to u-boot-sunxi/next for merging into
v2015.10 .

Regards,

Hans


> ---
>   arch/arm/include/asm/arch-sunxi/mmc.h |  1 +
>   board/sunxi/board.c                   |  8 ++------
>   drivers/mmc/sunxi_mmc.c               | 17 +++++++++++++++++
>   3 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm/include/asm/arch-sunxi/mmc.h b/arch/arm/include/asm/arch-sunxi/mmc.h
> index cb52e64..3da360b 100644
> --- a/arch/arm/include/asm/arch-sunxi/mmc.h
> +++ b/arch/arm/include/asm/arch-sunxi/mmc.h
> @@ -127,4 +127,5 @@ struct sunxi_mmc {
>   #define SUNXI_MMC_COMMON_RESET			(1 << 18)
>
>   struct mmc *sunxi_mmc_init(int sdc_no);
> +int sunxi_mmc_has_egon_boot_signature(struct mmc *mmc);
>   #endif /* _SUNXI_MMC_H */
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index 3f23f26..dc95431 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -302,12 +302,8 @@ int board_mmc_init(bd_t *bis)
>   	 * Both mmc0 and mmc2 are bootable, figure out where we're booting
>   	 * from. Try mmc0 first, just like the brom does.
>   	 */
> -	if (mmc_getcd(mmc0) && mmc_init(mmc0) == 0 &&
> -	    mmc0->block_dev.block_read(0, 16, 1, buf) == 1) {
> -		buf[12] = 0;
> -		if (strcmp(&buf[4], "eGON.BT0") == 0)
> -			return 0;
> -	}
> +	if (sunxi_mmc_has_egon_boot_signature(mmc0))
> +		return 0;
>
>   	/* no bootable card in mmc0, so we must be booting from mmc2, swap */
>   	mmc0->block_dev.dev = 1;
> diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
> index bb08147..ef3e84c 100644
> --- a/drivers/mmc/sunxi_mmc.c
> +++ b/drivers/mmc/sunxi_mmc.c
> @@ -431,6 +431,23 @@ static int sunxi_mmc_getcd(struct mmc *mmc)
>   	return !gpio_get_value(cd_pin);
>   }
>
> +int sunxi_mmc_has_egon_boot_signature(struct mmc *mmc)
> +{
> +	char *buf = malloc(512);
> +	int valid_signature = 0;
> +
> +	if (buf == NULL)
> +		panic("Failed to allocate memory\n");
> +
> +	if (mmc_getcd(mmc) && mmc_init(mmc) == 0 &&
> +	    mmc->block_dev.block_read(0, 16, 1, buf) == 1 &&
> +	    strncmp(&buf[4], "eGON.BT0", 8) == 0)
> +		valid_signature = 1;
> +
> +	free(buf);
> +	return valid_signature;
> +}
> +
>   static const struct mmc_ops sunxi_mmc_ops = {
>   	.send_cmd	= sunxi_mmc_send_cmd,
>   	.set_ios	= sunxi_mmc_set_ios,
>

      parent reply	other threads:[~2015-06-06 14:55 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
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 ` 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=557309E1.4090900@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