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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4B00C433F5 for ; Thu, 11 Nov 2021 16:01:00 +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 04D646124D for ; Thu, 11 Nov 2021 16:01:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 04D646124D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.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 62D5283A49; Thu, 11 Nov 2021 17:00:40 +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="Mmq2ugYq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3325783A3F; Thu, 11 Nov 2021 17:00:23 +0100 (CET) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (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 DB22883A3F for ; Thu, 11 Nov 2021 17:00:03 +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: by mail.kernel.org (Postfix) with ESMTPSA id 9B8486135E; Thu, 11 Nov 2021 16:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636646403; bh=lQF7kTuGrzQSsH5eHZvI7gDiDK2gZj43F8hjVhgrcKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mmq2ugYqxeZzk8kB6nMFMlcDA86xs6uyAHy/ioQrOHsbNp22mhKCHhU/fmUt3+kdc jMWE/uV24K89ZXnX/KnT8hhslk5Yschq6KnY9tfXhojFGWSn9dqIYE9dZyY+JVQscZ 37XjcHC9uxW0mIb2aIaXWWRKuwnQ0TDdDMWklfDPNYswfpsBAoUGYT5x3b+J2oxrWA SLISFrVWbV88KJYCpqUI3pNEQvSCwDbRRSul38a0w2+5S0vZ1ukZkbyeVafzDk8Vb7 hHhX6w0zaaY//EEA9+nV0LTrhOMMPPFStJcXby5+2n1lVnNyNYnK25xMsqd86IRSUe RVITsu8kuhaLw== 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 5/5] arm: mvebu: Check for kwbimage data checksum Date: Thu, 11 Nov 2021 16:59:53 +0100 Message-Id: <20211111155953.31526-6-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211111155953.31526-1-kabel@kernel.org> References: <20211111155953.31526-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.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: 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 --- arch/arm/mach-mvebu/spl.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 662f430503..f0b84167b9 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -100,6 +100,34 @@ u32 spl_mmc_boot_mode(const u32 boot_device) } #endif +static uint32_t checksum32(void *start, uint32_t len) +{ + uint32_t csum = 0; + uint32_t *p = start; + + while (len > 0) { + csum += *p++; + len -= sizeof(uint32_t); + }; + + return csum; +} + +int spl_check_board_image(struct spl_image_info *spl_image, + const struct spl_boot_device *bootdev) +{ + uint32_t csum = *(uint32_t *)(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