mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] scripts: imx-image: don't pad the final binary for i.MX8M devices
@ 2023-11-14 13:33 Marco Felsch
  2023-12-05  8:12 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Marco Felsch @ 2023-11-14 13:33 UTC (permalink / raw)
  To: barebox

If the padding was required the follwing error may appear:

| found i.MX8MP USB device [1fc9:0146]
| No dcd table in this ivt
| dl_command err=-1, last_trans=-1
| 4 in err=-4, last_trans=0  00 00 00 00

The error is triggered since the target request only the required size
of bytes and move on as soon as all bytes are received while, on the other
hand, host tools like imx-usb-loader and uuu try to send the complete
file size.

The alignment was introduced long time ago by commit 7cb4778e7f49
("imx-image: pad generated image to 4k") and may be required for HAB
boot on older SoCs like i.MX6/7. On these SoCs the CSF data is placed
behind the whole barebox image including the optional padding. On newer
SoCs like the i.MX8M* this isn't the case anymore. On these SoCs the CSF
is placed behind the barebox-pbl (aligned to 0x1000). So the final padding
isn't required anymore on these SoCs.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 scripts/imx/imx-image.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 1f96b383901f..a5639d696931 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -1100,12 +1100,21 @@ int main(int argc, char *argv[])
 
 	xwrite(outfd, infile, insize);
 
-	/* pad until next 4k boundary */
-	now = 4096 - (insize % 4096);
-	if (data.csf && now) {
-		memset(buf, 0x5a, now);
+	/*
+	 * The alignment may be required on ARMv7 SoCs like i.MX6/7 for HAB
+	 * boot. On newer SoCs like i.MX8MP/N this cause libusb communication
+	 * errors while uploading images because these machines request the
+	 * exact amount of required bytes and move on afterwards while the host
+	 * tool still try to send the whole (padded) file size.
+	 */
+	if (!cpu_is_mx8m(&data)) {
+		/* pad until next 4k boundary */
+		now = 4096 - (insize % 4096);
+		if (data.csf && now) {
+			memset(buf, 0x5a, now);
 
-		xwrite(outfd, buf, now);
+			xwrite(outfd, buf, now);
+		}
 	}
 
 	ret = close(outfd);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] scripts: imx-image: don't pad the final binary for i.MX8M devices
  2023-11-14 13:33 [PATCH] scripts: imx-image: don't pad the final binary for i.MX8M devices Marco Felsch
@ 2023-12-05  8:12 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-12-05  8:12 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox

On Tue, Nov 14, 2023 at 02:33:58PM +0100, Marco Felsch wrote:
> If the padding was required the follwing error may appear:
> 
> | found i.MX8MP USB device [1fc9:0146]
> | No dcd table in this ivt
> | dl_command err=-1, last_trans=-1
> | 4 in err=-4, last_trans=0  00 00 00 00
> 
> The error is triggered since the target request only the required size
> of bytes and move on as soon as all bytes are received while, on the other
> hand, host tools like imx-usb-loader and uuu try to send the complete
> file size.
> 
> The alignment was introduced long time ago by commit 7cb4778e7f49
> ("imx-image: pad generated image to 4k") and may be required for HAB
> boot on older SoCs like i.MX6/7. On these SoCs the CSF data is placed
> behind the whole barebox image including the optional padding. On newer
> SoCs like the i.MX8M* this isn't the case anymore. On these SoCs the CSF
> is placed behind the barebox-pbl (aligned to 0x1000). So the final padding
> isn't required anymore on these SoCs.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
>  scripts/imx/imx-image.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
> index 1f96b383901f..a5639d696931 100644
> --- a/scripts/imx/imx-image.c
> +++ b/scripts/imx/imx-image.c
> @@ -1100,12 +1100,21 @@ int main(int argc, char *argv[])
>  
>  	xwrite(outfd, infile, insize);
>  
> -	/* pad until next 4k boundary */
> -	now = 4096 - (insize % 4096);
> -	if (data.csf && now) {
> -		memset(buf, 0x5a, now);
> +	/*
> +	 * The alignment may be required on ARMv7 SoCs like i.MX6/7 for HAB
> +	 * boot. On newer SoCs like i.MX8MP/N this cause libusb communication
> +	 * errors while uploading images because these machines request the
> +	 * exact amount of required bytes and move on afterwards while the host
> +	 * tool still try to send the whole (padded) file size.
> +	 */
> +	if (!cpu_is_mx8m(&data)) {
> +		/* pad until next 4k boundary */
> +		now = 4096 - (insize % 4096);
> +		if (data.csf && now) {
> +			memset(buf, 0x5a, now);
>  
> -		xwrite(outfd, buf, now);
> +			xwrite(outfd, buf, now);
> +		}
>  	}
>  
>  	ret = close(outfd);
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-05  8:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14 13:33 [PATCH] scripts: imx-image: don't pad the final binary for i.MX8M devices Marco Felsch
2023-12-05  8:12 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox