From patchwork Tue Dec 14 13:22:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1567731 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=CIt3q6jo; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JCzZz5PTzz9s5P for ; Wed, 15 Dec 2021 00:23:07 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 499B08129B; Tue, 14 Dec 2021 14:22:51 +0100 (CET) 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="CIt3q6jo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA2C18305D; Tue, 14 Dec 2021 14:22:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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 2317180D1C for ; Tue, 14 Dec 2021 14:22:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@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 CBFF2B819A1; Tue, 14 Dec 2021 13:22:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A868C34606; Tue, 14 Dec 2021 13:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639488151; bh=feGzhAlBiXMbWzkLDO7w6SiyaA4cqerEy+tzuOt++Qw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CIt3q6jo9kVDjbau245m6Oa4IkfciVeKT73WPmJeCFA6GhhV2TF2izniz97qEZjv2 Ipb7TH0xIRYuSr2TehJKJOXjAr/ePeY0otZ6asveee/AsVpct2qbZJ2dr28mIlAocf G4QGnOhAFq/MQr27F91wrbqmtbvz/iN5dMeyINVDhc4Mek7+V8gJ6MnfwcD9Eqqw+J 4wAgq0PBD3f79ZmkgIH8WPy6d9E1P2UC0/azDjO0mjdZvRtd+SjR41UXAbeZOXxgmL 6msaz1mcw4nf6L2RMJlY+2dSBkTr4rmA0KE/q5Oo6FzAb6U1NinVQSUKFq442srY5F CLCQC1FS/TlaA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell v3 3/9] arm: mvebu: Check that kwbimage blockid matches boot mode Date: Tue, 14 Dec 2021 14:22:16 +0100 Message-Id: <20211214132222.21324-4-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211214132222.21324-1-kabel@kernel.org> References: <20211214132222.21324-1-kabel@kernel.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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: Pali Rohár Each boot mode has its own kwbimage specified by blockid. So check that kwbimage is valid by blockid. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- arch/arm/mach-mvebu/spl.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 716217083b..4af52c626c 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -118,22 +118,39 @@ int spl_parse_board_header(struct spl_image_info *spl_image, * (including SPL content) which is not included in U-Boot image_header. */ if (mhdr->version != 1 || - ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr) || - ( + ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr)) { + printf("ERROR: Invalid kwbimage v1\n"); + return -EINVAL; + } + #ifdef CONFIG_SPL_SPI_FLASH_SUPPORT - mhdr->blockid != IBR_HDR_SPI_ID && + if (bootdev->boot_device == BOOT_DEVICE_SPI && + mhdr->blockid != IBR_HDR_SPI_ID) { + printf("ERROR: Wrong blockid (%u) in SPI kwbimage\n", + mhdr->blockid); + return -EINVAL; + } #endif + #ifdef CONFIG_SPL_SATA - mhdr->blockid != IBR_HDR_SATA_ID && + if (bootdev->boot_device == BOOT_DEVICE_SATA && + mhdr->blockid != IBR_HDR_SATA_ID) { + printf("ERROR: Wrong blockid (%u) in SATA kwbimage\n", + mhdr->blockid); + return -EINVAL; + } #endif + #ifdef CONFIG_SPL_MMC - mhdr->blockid != IBR_HDR_SDIO_ID && -#endif - 1 - )) { - printf("ERROR: Not valid SPI/NAND/SATA/SDIO kwbimage v1\n"); + if ((bootdev->boot_device == BOOT_DEVICE_MMC1 || + bootdev->boot_device == BOOT_DEVICE_MMC2 || + bootdev->boot_device == BOOT_DEVICE_MMC2_2) && + mhdr->blockid != IBR_HDR_SDIO_ID) { + printf("ERROR: Wrong blockid (%u) in SDIO kwbimage\n", + mhdr->blockid); return -EINVAL; } +#endif spl_image->offset = mhdr->srcaddr;