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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2EA48C00140 for ; Tue, 26 Jul 2022 14:12:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 26FA78409F; Tue, 26 Jul 2022 16:12:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.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=kernel.org header.i=@kernel.org header.b="LVlhDnVL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3862484194; Tue, 26 Jul 2022 16:12:19 +0200 (CEST) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C2FC08407F for ; Tue, 26 Jul 2022 16:12:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 55743B8166E; Tue, 26 Jul 2022 14:12:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFEB4C433C1; Tue, 26 Jul 2022 14:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658844735; bh=LWjxhJ6BgtwGfSrZNLxiueTi3UqGPLIAzpUZUFGD3cY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LVlhDnVLpx++8NnBb6vVykxM1Hr/lYIimHJ8C/ttxpFkEHMDJBzAejFBV8dIM/ubl pjzHovfvzaNMbLSFgevnb4hkDHlnAzhagQVyUGSv/rr1ON+uddsFqGuRQvsUcfTubv /A8LemVrbFQjBBOpsmOEzDGhUIypLIl23dq/91ZgijHPmgmiN9KH3K6zbB1IFPuE68 JH+T0Xj/C/QmHt3LT9CPyxh0gJsAwy/ZGvkelLJyYh//jw6MueXiSBVMR9gcsXBXhY Ls1lS//RbwIwEkIV57IJ8koiraVwScXBf6uMoh+GPfrHrbLHQDH8peB1XTPAmV5Thw 4ZiI/osXwa6IQ== Received: by pali.im (Postfix) id CF3B64966; Tue, 26 Jul 2022 16:12:11 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , Michal Simek , Simon Glass Cc: u-boot@lists.denx.de Subject: [PATCH 1/4] cmd: mvebu/bubt: Verify image type for all 32-bit Aramda SoCs and Armada 3700 Date: Tue, 26 Jul 2022 16:11:56 +0200 Message-Id: <20220726141159.19774-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220726141159.19774-1-pali@kernel.org> References: <20220726141159.19774-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean Current image type verification code is specific to 32-bit Armada SoCs but used only for Armada 38x. Implement image type verification for Armada 3700 and enable Armada 38x image verification for all 32-bit Armada SoCs. Signed-off-by: Pali Rohár --- cmd/mvebu/bubt.c | 74 +++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c index 1362c03bcee5..a05e22a5479c 100644 --- a/cmd/mvebu/bubt.c +++ b/cmd/mvebu/bubt.c @@ -56,6 +56,21 @@ struct mvebu_image_header { #define IMAGE_VERSION_3_6_0 0x030600 #define IMAGE_VERSION_3_5_0 0x030500 +struct tim_boot_flash_sign { + unsigned int id; + const char *name; +}; + +struct tim_boot_flash_sign tim_boot_flash_signs[] = { + { 0x454d4d08, "mmc" }, + { 0x454d4d0b, "mmc" }, + { 0x5350490a, "spi" }, + { 0x5350491a, "nand" }, + { 0x55415223, "uart" }, + { 0x53415432, "sata" }, + {}, +}; + struct common_tim_data { u32 version; u32 identifier; @@ -83,7 +98,7 @@ struct mvebu_image_info { u32 encrypt_start_offset; u32 encrypt_size; }; -#endif +#elif defined(CONFIG_ARMADA_32BIT) /* Structure of the main header, version 1 (Armada 370/XP/375/38x/39x) */ struct a38x_main_hdr_v1 { @@ -123,6 +138,8 @@ struct a38x_boot_mode a38x_boot_modes[] = { {}, }; +#endif + struct bubt_dev { char name[8]; size_t (*read)(const char *file_name); @@ -635,7 +652,7 @@ static int check_image_header(void) return 0; } -#elif defined(CONFIG_ARMADA_38X) +#elif defined(CONFIG_ARMADA_32BIT) static size_t a38x_header_size(const struct a38x_main_hdr_v1 *h) { if (h->version == 1) @@ -691,34 +708,39 @@ static int check_image_header(void) static int bubt_check_boot_mode(const struct bubt_dev *dst) { - if (IS_ENABLED(CONFIG_ARMADA_38X)) { - int mode; - const struct a38x_main_hdr_v1 *hdr = - (struct a38x_main_hdr_v1 *)get_load_addr(); - - for (mode = 0; mode < ARRAY_SIZE(a38x_boot_modes); mode++) { - if (strcmp(a38x_boot_modes[mode].name, dst->name) == 0) - break; - } - - if (a38x_boot_modes[mode].id == hdr->blockid) - return 0; +#if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_32BIT) + int mode; +#if defined(CONFIG_ARMADA_3700) + const struct tim_boot_flash_sign *boot_modes = tim_boot_flash_signs; + const struct common_tim_data *hdr = + (struct common_tim_data *)get_load_addr(); + u32 id = hdr->boot_flash_sign; +#elif defined(CONFIG_ARMADA_32BIT) + const struct a38x_boot_mode *boot_modes = a38x_boot_modes; + const struct a38x_main_hdr_v1 *hdr = + (struct a38x_main_hdr_v1 *)get_load_addr(); + u32 id = hdr->blockid; +#endif - for (int i = 0; i < ARRAY_SIZE(a38x_boot_modes); i++) { - if (a38x_boot_modes[i].id == hdr->blockid) { - printf("Error: A38x image meant to be booted from " - "\"%s\", not \"%s\"!\n", - a38x_boot_modes[i].name, dst->name); - return -ENOEXEC; - } - } + for (mode = 0; boot_modes[mode].name; mode++) { + if (boot_modes[mode].id == id) + break; + } - printf("Error: unknown boot device in A38x image header: " - "0x%x\n", hdr->blockid); + if (!boot_modes[mode].name) { + printf("Error: unknown boot device in image header: 0x%x\n", id); return -ENOEXEC; - } else { - return 0; } + + if (strcmp(boot_modes[mode].name, dst->name) == 0) + return 0; + + printf("Error: image meant to be booted from \"%s\", not \"%s\"!\n", + boot_modes[mode].name, dst->name); + return -ENOEXEC; +#else + return 0; +#endif } static int bubt_verify(const struct bubt_dev *dst) -- 2.20.1