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 17E6DC61DA3 for ; Tue, 21 Feb 2023 20:49:08 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 27C9085AA1; Tue, 21 Feb 2023 21:48:42 +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="DB4DWPpr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5FC8385A7C; Tue, 21 Feb 2023 21:48:36 +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 4D6CD85AAA for ; Tue, 21 Feb 2023 21:22:42 +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 ams.source.kernel.org (Postfix) with ESMTPS id 7AA0BB810C5; Tue, 21 Feb 2023 20:22:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0662FC433A7; Tue, 21 Feb 2023 20:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677010953; bh=2UoY7DTiEhspyqSzpJqzWtnVc9kyCSsUaHo6mCnbjfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DB4DWPprvg1V1znuYrr+GXMdOnGYFgD6og1QYfjLW4IQMQT796kRWTd1/JeFmqBk1 bjocwWABZP5EZnCaNJp47zcU3ZLFJRkQG5caIIvHKdmTbayvA1XY+KuourXvjjZGks 46ouKiPOobOvW8TLrVFxF8LvwCcAlQWYy3ErRvUvVlo7pFcJrpBN+gPu6thJiQCUvq iFXDWpjDnUtSnG6QbHac2SIL5mTbR1YZajijZAy/0cwUicLX7QQ4Huhl4whRkmYvu3 38/q+DSREENp7nDE3AfulvCCXeHR/fz62VsXQL2H+AbGR/yGpgarZppXpm0FpXcezO PtOINJ+5c81mA== Received: by pali.im (Postfix) id CC09A2832; Tue, 21 Feb 2023 21:22:29 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: u-boot@lists.denx.de Cc: Stefan Roese , Tony Dinh , Josua Mayer Subject: [PATCH RFC u-boot-mvebu 15/59] tools: kwboot: Fix parsing UART image without data checksum Date: Tue, 21 Feb 2023 21:18:41 +0100 Message-Id: <20230221201925.9644-16-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230221201925.9644-1-pali@kernel.org> References: <20230221201925.9644-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 The 32-bit data checksum in UART image is not checked by the BootROM and also Marvell tools do not generate it. So if data checksum stored in UART image does not match calculated checksum from the image then treat those checksum bytes as part of the executable image code (and not as the checksum) and for compatibility with the rest of the code manually insert data checksum into the in-memory image after the executable code, without overwriting it. This should allow to boot UART images generated by Marvell tools. Signed-off-by: Pali Rohár --- tools/kwboot.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index 7a7dd5bf3d7b..da840864b565 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -1990,8 +1990,18 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) *size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize)) goto err; - if (kwboot_img_csum32(img) != *kwboot_img_csum32_ptr(img)) - goto err; + /* + * The 32-bit data checksum is optional for UART image. If it is not + * present (checksum detected as invalid) then grow data part of the + * image for the checksum, so it can be inserted there. + */ + if (kwboot_img_csum32(img) != *kwboot_img_csum32_ptr(img)) { + if (hdr->blockid != IBR_HDR_UART_ID) { + fprintf(stderr, "Image has invalid data checksum\n"); + goto err; + } + kwboot_img_grow_data_right(img, size, sizeof(uint32_t)); + } is_secure = kwboot_img_is_secure(img); @@ -2256,6 +2266,7 @@ main(int argc, char **argv) KWBOOT_XM_BLKSZ + sizeof(kwboot_baud_code) + sizeof(kwboot_baud_code_data_jump) + + sizeof(uint32_t) + KWBOOT_XM_BLKSZ; if (imgpath) { -- 2.20.1