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 E51A7C433F5 for ; Fri, 26 Nov 2021 14:38:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2E45D83743; Fri, 26 Nov 2021 15:38:28 +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="sSUwA23u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 41DCB8327C; Fri, 26 Nov 2021 15:38:06 +0100 (CET) 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 63FDE83173 for ; Fri, 26 Nov 2021 15:37:53 +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 096C9B827DA; Fri, 26 Nov 2021 14:37:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8ED93C93056; Fri, 26 Nov 2021 14:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637937471; bh=dfi/1cn2fTJ01PQw27oF9Ngx7O0pYLvpc2wXzXIOeT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sSUwA23uHoQTys9z55NadDYhgqUD8CLjqU3H4Cx5Z1FEplyiMLmGTAoYTOxqVjjcD 0LQo/o5FICEf/LDFFMG8CqpdVJCsyQR7ecuh3mFkqcaQx5kNAK0P9KJ12MsvJyIsy5 WBhpTTboRaa3eoyqoSVwztRL/RR2RssOI3fsE2hhQa60qInny1BpOSH7Sdu7RhGkXN qWPNKVfIxVER/u3iZCSWlt76DVKo7JN8SvJyIy8mghcZJGUJQ2We83sXQO7Ky+BZI4 upH714nFWbp6TYhA71p4iebpEMYCSkcYPg+p7SKDSX1jLK+DXjJzvfUTrMZHsojj63 OGbln1fHUNW2Q== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?UTF-8?q?Pali=20Roh=C3=A1r?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-marvell v2 5/9] arm: mvebu: Check for kwbimage data checksum Date: Fri, 26 Nov 2021 15:37:34 +0100 Message-Id: <20211126143738.23830-6-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211126143738.23830-1-kabel@kernel.org> References: <20211126143738.23830-1-kabel@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.37 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 Last 4 bytes of kwbimage boot image is checksum. Verify it via the new spl_check_board_image() function which is called by U-Boot SPL after loading kwbimage. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- Changes since v1: - changed uint32_t to u32 --- arch/arm/mach-mvebu/spl.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 4af52c626c..af9e45ac7a 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -100,6 +100,33 @@ u32 spl_mmc_boot_mode(const u32 boot_device) } #endif +static u32 checksum32(void *start, u32 len) +{ + u32 csum = 0; + u32 *p = start; + + while (len > 0) { + csum += *p++; + len -= sizeof(u32); + }; + + return csum; +} + +int spl_check_board_image(struct spl_image_info *spl_image, + const struct spl_boot_device *bootdev) +{ + u32 csum = *(u32 *)(spl_image->load_addr + spl_image->size - 4); + + if (checksum32((void *)spl_image->load_addr, + spl_image->size - 4) != csum) { + printf("ERROR: Invalid data checksum in kwbimage\n"); + return -EINVAL; + } + + return 0; +} + int spl_parse_board_header(struct spl_image_info *spl_image, const struct spl_boot_device *bootdev, const void *image_header, size_t size) -- 2.32.0