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.7 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,URIBL_BLOCKED, 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 A6E1EC4338F for ; Sun, 22 Aug 2021 04:47:49 +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 2F6C0611C8 for ; Sun, 22 Aug 2021 04:47:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2F6C0611C8 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 5061B82E8E; Sun, 22 Aug 2021 06:47:25 +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="dxYlTHTd"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="wNa3fy9u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BC88C82EEA; Sun, 22 Aug 2021 06:47:16 +0200 (CEST) Received: from new1-smtp.messagingengine.com (new1-smtp.messagingengine.com [66.111.4.221]) (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 87FDC82EA1 for ; Sun, 22 Aug 2021 06:47:05 +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 compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id CB48D580C24; Sun, 22 Aug 2021 00:47:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sun, 22 Aug 2021 00:47:04 -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=xPGVJuQCIegPL fG0VTVHfCCaE6sEO5EzLXn8p19JFOQ=; b=dxYlTHTdFfsZXVJs8SRzBRBI7azX6 +SreyyjjLwSgyTsZ80jI/KU8K2boD+ZTROcSclzHNmLDiVJkY2R27+JXL9c66Fux IQ4kvOnCLdsUqdkAIJPPsxr6akhFLmE+YezvoYkb2dVO80Ocywhzye8kpqfwvzNt E1egr/ga3+6TsH38+tyBoqDqVG4a7QZLsQwaM3RDbbKZpU4hzCmNsI70/jP2A5bb 0qKyq1vWV+Dw63nnMYxLE+Fyc8fRPdoQkEGGxLvkLvWY2AYLSeZrQ28XZOauykKR VPbS4vRjtb6hZ/pJ5xEGvEoq8c9CwagWpYg7giGWkOChjQ7RzvWWwXK/g== 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=xPGVJuQCIegPLfG0VTVHfCCaE6sEO5EzLXn8p19JFOQ=; b=wNa3fy9u GaH/C+jm0Zo4zJdTYA6kS3j/CZzmfu4ZTjbnvgtt/5xoPSjGfZc6q34b6wE28l8e BWy1xFvEeUELq1DcaGBoWtBY1A2W/dLPHDcf6Fxv3xTJF5GHkG/1jIFkKelKRRdk iFkrlBp58zo0H0VoeZg+ctPlsbY2j0gDuAzOGO9bcyUnEfvqmaIi3rqKn5GJ89KO y4ERlVt0I0TcLzQUwgEdjZ6xRB1aP+Z63bt1e64UOJVD8HXFinoQI9RjTx1Zl/yS QewQySHbWO57k4w9U5w14bjHUgPdDh3O0WpiF4OwrUgDdww3X2aIVq7K82fim5kH REg6ZL2yWMEq1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddtvddgkeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 22 Aug 2021 00:47:03 -0400 (EDT) From: Samuel Holland To: u-boot@lists.denx.de, Jagan Teki , Andre Przywara Cc: Samuel Holland , AKASHI Takahiro , Alexandru Gagniuc , Baruch Siach , Bharat Gooty , Chris Packham , Fabio Estevam , Frieder Schrempf , Jernej Skrabec , =?UTF-8?q?Marek=20Beh=C3=BAn?= , "NXP i.MX U-Boot Team" , Naoki Hayama , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Patrick Delaunay , Priyanka Jain , Rayagonda Kokatanur , Simon Glass , Stefan Roese , Stefano Babic , Sughosh Ganu , Trevor Woerner , lauri.hintsala@silabs.com Subject: [PATCH v2 3/4] sunxi: Support SPL in both eGON and TOC0 images Date: Sat, 21 Aug 2021 23:46:47 -0500 Message-Id: <20210822044649.13585-4-samuel@sholland.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210822044649.13585-1-samuel@sholland.org> References: <20210822044649.13585-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 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 | 50 +++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 9 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 d9b04f75fc4..b6f92bdc5e7 100644 --- a/arch/arm/mach-sunxi/board.c +++ b/arch/arm/mach-sunxi/board.c @@ -244,12 +244,40 @@ void s_init(void) #define SUNXI_INVALID_BOOT_SOURCE -1 -static int sunxi_get_boot_source(void) +static struct boot_file_head *sunxi_egon_get_head(void) { - if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */ - return SUNXI_INVALID_BOOT_SOURCE; + struct boot_file_head *egon_head = (void *)SPL_ADDR; + + if (memcmp(egon_head, BOOT0_MAGIC, 8)) /* eGON.BT0 */ + return NULL; + + return egon_head; +} + +static struct toc0_main_info *sunxi_toc0_get_info(void) +{ + struct toc0_main_info *toc0_info = (void *)SPL_ADDR; + + if (memcmp(toc0_info->name, TOC0_MAIN_INFO_NAME, 8)) /* TOC0.GLH */ + return NULL; - return readb(SPL_ADDR + 0x28); + return toc0_info; +} + +static int sunxi_get_boot_source(void) +{ + struct boot_file_head *egon_head; + struct toc0_main_info *toc0_info; + + egon_head = sunxi_egon_get_head(); + if (egon_head) + return readb(&egon_head->boot_media); + toc0_info = sunxi_toc0_get_info(); + if (toc0_info) + return readb(&toc0_info->platform[0]); + + /* 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 @@ -297,10 +325,18 @@ 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; + struct toc0_main_info *toc0_info; + + egon_head = sunxi_egon_get_head(); + if (egon_head) + return readl(&egon_head->length); + toc0_info = sunxi_toc0_get_info(); + if (toc0_info) + return readl(&toc0_info->length); - return readl(SPL_ADDR + 0x10); + /* Not a valid image, so use the default U-Boot offset. */ + return 0; } /* -- 2.31.1