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 EFF4CC433EF for ; Fri, 15 Oct 2021 01:53:54 +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 60D52611ED for ; Fri, 15 Oct 2021 01:53:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 60D52611ED 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 18B35837F4; Fri, 15 Oct 2021 03:53:35 +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="ahxpWm9E"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="j17DwJI/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9F87A83774; Fri, 15 Oct 2021 03:53:20 +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 0A2FF837DE for ; Fri, 15 Oct 2021 03:53:13 +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 mailout.nyi.internal (Postfix) with ESMTP id 4ED185C0113; Thu, 14 Oct 2021 21:53:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 14 Oct 2021 21:53:12 -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=+Pfp1OhWyzfdM ebgmI3o0Gdm/Y8tvbUiUsI59kWriqM=; b=ahxpWm9E/PQmNlwvZ7/8q/lusuEZA uzy2i/szxvIEW9zURTD0ScT/XgY7VxYW7mWlFrNc77SSFua7vKiI74EuqqheTsMm FnAn7K4BapKM2w3WbtXbJDY2lUD1CJ3lnqhQEZyZ+MFPN8XqCIJqpp43rjKYQF93 n0oKcgHK7ZJ+L82ikhniaiPq+ipyMt0JSTUEOiOGJLaeDeOthilz84LvSbpoXSpi tdVo7ubSo3iuvkykiVuG9MYrljKngCu84geYmrfrresEII8GflCfMU9BIQXagttn NbltEfQ27eM6h3nAjwxxgDz6VXGc1oI5beP1uZmLAlFQem4uFlxGxQbAg== 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=+Pfp1OhWyzfdMebgmI3o0Gdm/Y8tvbUiUsI59kWriqM=; b=j17DwJI/ /XL73wDcBWpF9IvJ9zVXkR+U8J7/R8nRLmTdjvTK4pJmvNVpEe3EStLBmK21onHv FMloITyFOM15SRB8siSJYnkuTokol+S+Ti/MrOfIoFIUFvhrLm/zDzaXTcH1OcAl ApZn0hvCgtk2+5xpn+zXvLpywV67fBR5ZErxLniWZqmY447yuWQmPlZZ+rDlhgZd RFjsf4nmFRMr7NAcks9G0lIgl9cG9DJ1mn4NKQvalaKc+0M+mdoKWnJLX1f397dj VrKM1FhhJ6QeYgC5v+x2PI2DkdlM8rR5u5vqUZeoJE2KL8itnfvuhv/gRAJUBL4J VlsTcDSgnLHCDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddufedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Oct 2021 21:53:11 -0400 (EDT) From: Samuel Holland To: u-boot@lists.denx.de, Jagan Teki , Andre Przywara Cc: Icenowy Zheng , Samuel Holland Subject: [PATCH v3 2/4] mkimage: sunxi_egon: refactor for multi-architecture support Date: Thu, 14 Oct 2021 20:53:05 -0500 Message-Id: <20211015015308.65265-3-samuel@sholland.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211015015308.65265-1-samuel@sholland.org> References: <20211015015308.65265-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 From: Icenowy Zheng Refactor some functions in mkimage sunxi_egon type, in order to prepare for adding support for more CPU architectures (e.g. RISC-V). In addition, compatibility for operation w/o specified architecture is kept, in this case the architecture is assumed as ARM. Reviewed-by: Andre Przywara Signed-off-by: Icenowy Zheng Signed-off-by: Samuel Holland --- Changes in v3: - Factor out an egon_get_arch() function as suggested by Andre tools/sunxi_egon.c | 50 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/tools/sunxi_egon.c b/tools/sunxi_egon.c index a5299eb6a1..e1c945a12f 100644 --- a/tools/sunxi_egon.c +++ b/tools/sunxi_egon.c @@ -14,9 +14,28 @@ */ #define PAD_SIZE 8192 +static int egon_get_arch(struct image_tool_params *params) +{ + if (params->Aflag) + return params->arch; + + /* For compatibility, assume ARM when no architecture specified */ + return IH_ARCH_ARM; +} + static int egon_check_params(struct image_tool_params *params) { - /* We just need a binary image file. */ + /* + * Check whether the architecture is supported. + */ + switch (egon_get_arch(params)) { + case IH_ARCH_ARM: + break; + default: + return EXIT_FAILURE; + } + + /* We need a binary image file. */ return !params->dflag; } @@ -26,9 +45,18 @@ static int egon_verify_header(unsigned char *ptr, int image_size, const struct boot_file_head *header = (void *)ptr; uint32_t length; - /* First 4 bytes must be an ARM branch instruction. */ - if ((le32_to_cpu(header->b_instruction) & 0xff000000) != 0xea000000) - return EXIT_FAILURE; + /* + * First 4 bytes must be a branch instruction of the corresponding + * architecture. + */ + switch (egon_get_arch(params)) { + case IH_ARCH_ARM: + if ((le32_to_cpu(header->b_instruction) & 0xff000000) != 0xea000000) + return EXIT_FAILURE; + break; + default: + return EXIT_FAILURE; /* Unknown architecture */ + } if (memcmp(header->magic, BOOT0_MAGIC, sizeof(header->magic))) return EXIT_FAILURE; @@ -77,9 +105,17 @@ static void egon_set_header(void *buf, struct stat *sbuf, int infd, uint32_t checksum = 0, value; int i; - /* Generate an ARM branch instruction to jump over the header. */ - value = 0xea000000 | (sizeof(struct boot_file_head) / 4 - 2); - header->b_instruction = cpu_to_le32(value); + /* + * Different architectures need different first instruction to + * branch to the body. + */ + switch (egon_get_arch(params)) { + case IH_ARCH_ARM: + /* Generate an ARM branch instruction to jump over the header. */ + value = 0xea000000 | (sizeof(struct boot_file_head) / 4 - 2); + header->b_instruction = cpu_to_le32(value); + break; + } memcpy(header->magic, BOOT0_MAGIC, sizeof(header->magic)); header->check_sum = cpu_to_le32(BROM_STAMP_VALUE); -- 2.32.0