From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4386CC433F5 for ; Wed, 20 Oct 2021 23:50:32 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 87704611B0 for ; Wed, 20 Oct 2021 23:50:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 87704611B0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC09B83434; Thu, 21 Oct 2021 01:50:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C094F8344A; Thu, 21 Oct 2021 01:50:17 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id E6FB883409 for ; Thu, 21 Oct 2021 01:50:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0C4EBD6E; Wed, 20 Oct 2021 16:50:03 -0700 (PDT) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A69413F694; Wed, 20 Oct 2021 16:50:01 -0700 (PDT) Date: Thu, 21 Oct 2021 00:49:59 +0100 From: Andre Przywara To: Samuel Holland Cc: u-boot@lists.denx.de, Jagan Teki , "Alex G ." , Pali =?UTF-8?B?Um9ow6Fy?= , Artem Lapkin , Priyanka Jain , Sughosh Ganu Subject: Re: [PATCH v4 3/4] sunxi: Support SPL in both eGON and TOC0 images Message-ID: <20211021004959.0b0a779f@slackpad.fritz.box> In-Reply-To: <20211020024455.48136-4-samuel@sholland.org> References: <20211020024455.48136-1-samuel@sholland.org> <20211020024455.48136-4-samuel@sholland.org> Organization: Arm Ltd. X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.31; x86_64-slackware-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Tue, 19 Oct 2021 21:44:53 -0500 Samuel Holland wrote: > 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. > > Signed-off-by: Samuel Holland Many thanks for fixing the issues, actually in a more elegant way than I did here internally. Tested for regressions on A20, H3, A64, H616, all non-secure (those were the ones broken in v2). Reviewed-by: Andre Przywara Cheers, Andre > --- > > (no changes since v3) > > Changes in v3: > - Fixed offset of magic passed to memcmp > - Refactored functions to not return pointers (fixes ambiguous NULL) > > 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 | 34 ++++++++++++++++++++++----- > 2 files changed, 28 insertions(+), 8 deletions(-) > > diff --git a/arch/arm/include/asm/arch-sunxi/spl.h b/arch/arm/include/asm/arch-sunxi/spl.h > index 58cdf806d9..157b11e489 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 b4ba2a72c4..b2cd64bb3f 100644 > --- a/arch/arm/mach-sunxi/board.c > +++ b/arch/arm/mach-sunxi/board.c > @@ -243,12 +243,28 @@ void s_init(void) > > #define SUNXI_INVALID_BOOT_SOURCE -1 > > +static int sunxi_egon_valid(struct boot_file_head *egon_head) > +{ > + return !memcmp(egon_head->magic, BOOT0_MAGIC, 8); /* eGON.BT0 */ > +} > + > +static int sunxi_toc0_valid(struct toc0_main_info *toc0_info) > +{ > + return !memcmp(toc0_info->name, TOC0_MAIN_INFO_NAME, 8); /* TOC0.GLH */ > +} > + > static int sunxi_get_boot_source(void) > { > - if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */ > - return SUNXI_INVALID_BOOT_SOURCE; > + struct boot_file_head *egon_head = (void *)SPL_ADDR; > + struct toc0_main_info *toc0_info = (void *)SPL_ADDR; > + > + if (sunxi_egon_valid(egon_head)) > + return readb(&egon_head->boot_media); > + if (sunxi_toc0_valid(toc0_info)) > + return readb(&toc0_info->platform[0]); > > - return readb(SPL_ADDR + 0x28); > + /* 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 > @@ -296,10 +312,16 @@ 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 = (void *)SPL_ADDR; > + struct toc0_main_info *toc0_info = (void *)SPL_ADDR; > > - return readl(SPL_ADDR + 0x10); > + if (sunxi_egon_valid(egon_head)) > + return readl(&egon_head->length); > + if (sunxi_toc0_valid(toc0_info)) > + return readl(&toc0_info->length); > + > + /* Not a valid image, so use the default U-Boot offset. */ > + return 0; > } > > /*