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 X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49DC7C48BDF for ; Mon, 21 Jun 2021 02:56:37 +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 916946102A for ; Mon, 21 Jun 2021 02:56:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 916946102A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3B286829BE; Mon, 21 Jun 2021 04:56:16 +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="LWHBDJXq"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="SOIKlEuA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D3EEF829B9; Mon, 21 Jun 2021 04:56:08 +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 18851829A1 for ; Mon, 21 Jun 2021 04:56:00 +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 54F975C0161; Sun, 20 Jun 2021 22:55:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sun, 20 Jun 2021 22:55:59 -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=fm3; bh=fkCJm/avIrVD8 CPHlehG37bU4Tbyob1oWfhN0G+uarM=; b=LWHBDJXqu9Vs3cbKtvk1NDCMmLLNS keALRfRCFKv48knOtSt1XlnUnRn+nQR50taaBBl4Z8NjcLbeKZ2QavUPsbA9cSAi LX7Pu8gWUisxSw2dDnAZkziWu8hePfaLU3FzXpAEWcbpGjnO2CK5KXVSw+XEr2F9 MXtIB5EtfOXNkY5NmnfbQVEmoOHJGa8S6ldi49pq5NRiqCWPGempviXH4oNhr7rD ihLMXSyUOKXT2iVLdlfVRIELBWxy0tk6UpZGDObmfudSr+m36nFv3FmzyKIcXsTo Z7JZmCO7Bi+BSHJ1kX0bYdqBdQl1JZeoYdWhY7Zwx53Kf5m+xpkq69NYA== 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= fm3; bh=fkCJm/avIrVD8CPHlehG37bU4Tbyob1oWfhN0G+uarM=; b=SOIKlEuA 2NZlq1S2eKcV4gu8z2+71M7vPdL8YWT7qiKkRz07mWfuoigL5kpCiFOqn1fAJTeV HHpD+u52foOdPDQjjjCYbKFRknnNkcfoT4AAHWBeYZTSTUqMDVhPzFT/YQVaLEjT ditC0/UFq77imRPJHdkmvaolgPoE0nMlIyXTO2Qhr1vDlvHHIFM0PQG2g4QqABEK zp6eZbAcKRXT8Bp/BNskowOOduf3Crn37uiuC5G7VbqzJRVaLeMTdCNgsrMSq7UL wtVRsytLMFSbOEWOnjgyEnMe5z4dq7N5lElolCGOFTzxe31S56JRJUFLBRFFcXjE bmTQehFoUyMhLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeefkedgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Jun 2021 22:55:58 -0400 (EDT) From: Samuel Holland To: Jagan Teki , Andre Przywara , Hans de Goede Cc: u-boot@lists.denx.de, Samuel Holland Subject: [PATCH 3/4] sunxi: Support both SPL image types Date: Sun, 20 Jun 2021 21:55:54 -0500 Message-Id: <20210621025555.19390-4-samuel@sholland.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210621025555.19390-1-samuel@sholland.org> References: <20210621025555.19390-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 U-Boot proper. Since this information is stored differently in 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 --- arch/arm/include/asm/arch-sunxi/spl.h | 2 -- arch/arm/mach-sunxi/board.c | 20 ++++++++++++++------ include/sunxi_image.h | 14 ++++++++++++++ 3 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 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 9b84132eda6..8147f250f87 100644 --- a/arch/arm/mach-sunxi/board.c +++ b/arch/arm/mach-sunxi/board.c @@ -237,10 +237,13 @@ void s_init(void) static int sunxi_get_boot_source(void) { - if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */ - return SUNXI_INVALID_BOOT_SOURCE; + if (is_egon_image((void *)SPL_ADDR)) + return ((struct boot_file_head *)SPL_ADDR)->boot_media; + if (is_toc0_image((void *)SPL_ADDR)) + return ((struct toc0_main_info *)SPL_ADDR)->platform[0]; - return readb(SPL_ADDR + 0x28); + /* Not a valid BROM image, so we must have been booted via FEL. */ + return SUNXI_INVALID_BOOT_SOURCE; } /* The sunxi internal brom will try to loader external bootloader @@ -285,13 +288,18 @@ uint32_t sunxi_get_boot_device(void) return -1; /* Never reached */ } +#define is_toc0_magic(foo) true + #ifdef CONFIG_SPL_BUILD static u32 sunxi_get_spl_size(void) { - if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */ - return 0; + if (is_egon_image((void *)SPL_ADDR)) + return ((struct boot_file_head *)SPL_ADDR)->length; + if (is_toc0_image((void *)SPL_ADDR)) + return ((struct toc0_main_info *)SPL_ADDR)->length; - return readl(SPL_ADDR + 0x10); + /* Unknown size, so fall back to the default offset. */ + return 0; } /* diff --git a/include/sunxi_image.h b/include/sunxi_image.h index bdf80ec0e0a..b0424b6b7f1 100644 --- a/include/sunxi_image.h +++ b/include/sunxi_image.h @@ -270,4 +270,18 @@ struct toc0_key_item { sizeof(struct toc0_key_item), \ 32) +static inline bool is_egon_image(void *addr) +{ + struct boot_file_head *head = addr; + + return memcmp(head->magic, BOOT0_MAGIC, 8) == 0; +} + +static inline bool is_toc0_image(void *addr) +{ + struct toc0_main_info *main = addr; + + return memcmp(main->name, TOC0_MAIN_INFO_NAME, 8) == 0; +} + #endif -- 2.31.1