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 B988CC433EF for ; Fri, 14 Jan 2022 13:34:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A90C683531; Fri, 14 Jan 2022 14:34:35 +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="CygzebnK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 606EC834DC; Fri, 14 Jan 2022 14:34:30 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (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 DB1818343B for ; Fri, 14 Jan 2022 14:34:22 +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=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 dfw.source.kernel.org (Postfix) with ESMTPS id 9F3B260AF5; Fri, 14 Jan 2022 13:34:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52A4BC36AE5; Fri, 14 Jan 2022 13:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642167261; bh=BoNK2nWvNC9bpav2vYMrhemJ+3Y+2TGLJQDwlx2lrK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CygzebnKNIBi6igDnf6ZpghG2sfAI98c0vtrZUYn2LNKQiLqC6sd8krrn5sRBSzKD A2lOgC/sazvlk/31dncmx/sYbRSEjKZdb41TBVHAPcEKjrZ42Z0ltQvtDP1Qe1Nm5L QJ6YipbsQ+OXXOchJbj/63xzfCiAc3j5pWVtlgxSj0tmsqNWpW6yqkpIJMDoAiT8mp rWBMEoG7lO5j7BOGn7W6Ctyhqnvg1TIFvwFUvErHx5DASJnhoYcd0H0rJByM+Gn64V fDVdCQf4dFinTKbt1puOPfC9abAWBxx/gvuHnlNqK5OTuzqWajQXGLkiva/DcDu1Y3 2yPSZSdqLyI+Q== Received: by pali.im (Postfix) id 0C8C07D1; Fri, 14 Jan 2022 14:34:21 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-marvell v4 3/9] arm: mvebu: Check that kwbimage blockid matches boot mode Date: Fri, 14 Jan 2022 14:31:39 +0100 Message-Id: <20220114133145.32329-4-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220114133145.32329-1-pali@kernel.org> References: <20220114133145.32329-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.2 at phobos.denx.de X-Virus-Status: Clean 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 fe22951e16c0..62e4fe12d65c 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -117,22 +117,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 (0x%x) 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 (0x%x) 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 (0x%x) in SDIO kwbimage\n", + mhdr->blockid); return -EINVAL; } +#endif spl_image->offset = mhdr->srcaddr; -- 2.20.1