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 C9E38C6FD1C for ; Thu, 23 Mar 2023 19:59:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A4FA685D80; Thu, 23 Mar 2023 20:58:48 +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="Usz8Wqav"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C935885A1B; Thu, 23 Mar 2023 20:58:38 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (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 EE3BF85CA9 for ; Thu, 23 Mar 2023 20:58:32 +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 715F662866; Thu, 23 Mar 2023 19:58:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A002FC433A4; Thu, 23 Mar 2023 19:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679601510; bh=AM5e4FdThzWMvoezrkjW7xY6qJuY1/G/Fzfu4vylmJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Usz8WqavCKHTDMXmcKYNKtLiAfR3C57WQfSWCRN5PAdG8rnHNZVPR3jG6FDtGH6Hq jC2NpD53DCO2aXfYlXbTcLm9sF8jlC7014L/ZZ/R4Y0KbLQoMvcrevoKTXCh55gUvS g6fE8qwp3mGuQLHwyMX1OUbaDSNFtjPde9boQElDBCeRf66boGQvhxVy/5jQlZmi0G Rrhpwl7GAO0VhN2tq/UACBc+WN1xdVqvonKRkfDDw7q2Nz85vFGXTQBnk1wjgW+8MB HGIk4OkpSBJWkZDun+Udan5nkqCySZYguUub0pax5InIDdQeuQ+Bkah+OeL1Mv+K8b NT7QNFjRq6Yqg== Received: by pali.im (Postfix) id 1ABAA2776; Thu, 23 Mar 2023 20:58:28 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , Martin Rowe Cc: u-boot@lists.denx.de Subject: [PATCH u-boot-mvebu 5/5] tools: kwboot: Workaround A38x BootROM bug for images with a gap Date: Thu, 23 Mar 2023 20:57:55 +0100 Message-Id: <20230323195755.5131-6-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230323195755.5131-1-pali@kernel.org> References: <20230323195755.5131-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.8 at phobos.denx.de X-Virus-Status: Clean A38x BootROM has a bug which cause that BootROM loads data part of UART image into RAM target address increased by one byte when source address and header size stored in the image header are not same. Workaround this bug by completely removing a gap between header and data part of the UART image. Without gap, this BootROM bug is not triggered. This gap can be present in SDIO or SATA image types which have aligned start of the data part to the media sector size. With this workaround kwboot should be able to convert and send SDIO or SATA images for UART booting. Signed-off-by: Pali Rohár --- tools/kwboot.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/kwboot.c b/tools/kwboot.c index 1cf78dda6755..2b92966919da 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -78,6 +78,17 @@ * * - IBR_HDR_UART_ID (0x69): * UART image can be transfered via xmodem protocol over first UART. + * Unlike all other image types, header size stored in the image must be + * multiply of the 128 bytes (for all other image types it can be any size) + * and data part of the image does not have to contain 32-bit checksum + * (all other image types must have valid 32-bit checksum in its data part). + * And data size stored in the image is ignored. A38x BootROM determinates + * size of the data part implicitly by the end of the xmodem transfer. + * A38x BootROM has a bug which cause that BootROM loads data part of UART + * image into RAM target address increased by one byte when source address + * and header size stored in the image header are not same. So UART image + * should be constructed in a way that there is no gap between header and + * data part. * * - IBR_HDR_I2C_ID (0x4D): * It is unknown for what kind of storage is used this image. It is not @@ -2188,6 +2199,18 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) } } + /* Header size and source address must be same for UART type due to A38x BootROM bug */ + if (hdrsz != le32_to_cpu(hdr->srcaddr)) { + if (is_secure) { + fprintf(stderr, "Cannot align image with secure header\n"); + goto err; + } + + kwboot_printv("Removing gap between image header and data\n"); + memmove(img + hdrsz, img + le32_to_cpu(hdr->srcaddr), le32_to_cpu(hdr->blocksize)); + hdr->srcaddr = cpu_to_le32(hdrsz); + } + hdr->checksum = kwboot_hdr_csum8(hdr) - csum; *size = le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize); -- 2.20.1