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 EA431C433F5 for ; Fri, 15 Oct 2021 03:19:53 +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 438AE60EE5 for ; Fri, 15 Oct 2021 03:19:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 438AE60EE5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sholland.org 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 B32938382F; Fri, 15 Oct 2021 05:19:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="k9Huyudk"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="GHyX7/IO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 22B8F83818; Fri, 15 Oct 2021 05:19:30 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A460583816 for ; Fri, 15 Oct 2021 05:19:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id EB9B75C0160; Thu, 14 Oct 2021 23:19:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 14 Oct 2021 23:19:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=BM3O5JI//Kxn6 8FG7EVEq696jrMUG93rmWeSVr0Evs4=; b=k9HuyudkJHdyhLXjYmAbaVX6r4UJU c/GVtrVsw9xiGe2/or95ZDXVqXP6IMdluRM0DTvs1cpR/upcr1aoonSzXMmYVBtj MNrVmQc+JVQjz7LIZWK1ycz7l6f66CnwJeBMII+ekYGOfuJZCe3gQz0r7Xv0PKAR IeBnIAsc1QqU0ck9YlhaVFDwhIzeN6y7V982LTkOthvlm0EH1LEAO4HZJRCImA22 fx2fawE6UsmwqDo3fiVQ8V5C4p6eVLKtfP88sPxr7yOfF8Rzx7ms57FN8N++lkPk qA+NxGeNAVXwIFwD9frTG1OzOMZVjQdqHxe5zkpWH1PauBVvHVsLa9ZXg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=BM3O5JI//Kxn68FG7EVEq696jrMUG93rmWeSVr0Evs4=; b=GHyX7/IO 2CX2FwZZlTwVs42Ny+RkoRvNX8sCLysHa/fVUi9qWXNyNAdJR2KPtC+X1Peu5ljZ N2KGzf8Uu3GHsXqQp/3KMr09AacmYQA1x2Z374N4d1e7qRSaLPXtjr0VWjBZJ0v5 76lSqPLWrDuFB/gdpEQfGnUB6w001IWer0Om5ImmModx2jiLGTEXSHGiwVEzuGUh zzQ03/rFOIOlJjnusgoJC5w9hc7jA/TA7iBEl5w4F6LVWUGbj5/iJecwVZJ2r0lX MpRjK04SPdplnR2y6zENQeXakH7i9KeDcMwsXPkrxnUXW6BG71gpBHiIJY9qS2Zz 5LSIflfj3Mjt2Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddufedgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Oct 2021 23:19:22 -0400 (EDT) From: Samuel Holland To: u-boot@lists.denx.de, Jagan Teki , Andre Przywara Cc: =?UTF-8?q?Pali=20Roh=C3=A1r?= , Samuel Holland , Alexandru Gagniuc , Chris Packham , "NXP i.MX U-Boot Team" , Naoki Hayama Subject: [PATCH v3 3/4] sunxi: Support SPL in both eGON and TOC0 images Date: Thu, 14 Oct 2021 22:19:15 -0500 Message-Id: <20211015031916.44461-4-samuel@sholland.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211015031916.44461-1-samuel@sholland.org> References: <20211015031916.44461-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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; } /* -- 2.32.0