public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Stefan Roese <sr@denx.de>, Martin Rowe <martin.p.rowe@gmail.com>
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	[thread overview]
Message-ID: <20230323195755.5131-6-pali@kernel.org> (raw)
In-Reply-To: <20230323195755.5131-1-pali@kernel.org>

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 <pali@kernel.org>
---
 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


  parent reply	other threads:[~2023-03-23 19:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 19:57 [PATCH u-boot-mvebu 0/5] mvebu: Fix UART booting Pali Rohár
2023-03-23 19:57 ` [PATCH u-boot-mvebu 1/5] tools: kwbimage: Fix invalid UART kwbimage v1 headersz Pali Rohár
2023-03-24  8:22   ` Stefan Roese
2023-03-23 19:57 ` [PATCH u-boot-mvebu 2/5] tools: kwboot: " Pali Rohár
2023-03-24  8:22   ` Stefan Roese
2023-03-23 19:57 ` [PATCH u-boot-mvebu 3/5] tools: kwboot: Fix inserting UART data checksum without -B option Pali Rohár
2023-03-24  8:23   ` Stefan Roese
2023-03-23 19:57 ` [PATCH u-boot-mvebu 4/5] tools: kwboot: Fix sending very small images Pali Rohár
2023-03-24  8:23   ` Stefan Roese
2023-03-23 19:57 ` Pali Rohár [this message]
2023-03-24  8:24   ` [PATCH u-boot-mvebu 5/5] tools: kwboot: Workaround A38x BootROM bug for images with a gap Stefan Roese
2023-03-24  3:31 ` [PATCH u-boot-mvebu 0/5] mvebu: Fix UART booting Martin Rowe
2023-03-24 14:44 ` Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230323195755.5131-6-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=martin.p.rowe@gmail.com \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox