From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 2/2] omap3-usb-loader: Fix for big endian hosts
Date: Wed, 10 Jan 2024 15:17:12 +0100 [thread overview]
Message-ID: <20240110-scripts-omap3-usb-loader-fix-compilation-v1-2-0503f170fa59@pengutronix.de> (raw)
In-Reply-To: <20240110-scripts-omap3-usb-loader-fix-compilation-v1-0-0503f170fa59@pengutronix.de>
omap3-usb-loader does a "filelen = cpu_to_le32(file->size)" and does
arithmetic operations on filelen afterwards. Also it passes filelen
to omap_usb_write() as the number of bytes to upload. This obviously
only works on little endian hosts where cpu_to_le32() is a no-op.
Fix this by doing the cpu_to_le32() conversion after all arithmetic
operations and do not use filelen after it has been converted.
This is a drive-by fix, untested currently as I don't have any big
endian host to test it with.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/omap3-usb-loader.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index d9422a0916..38cdbfac93 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -330,7 +330,7 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
/* TODO determine buffer size based on endpoint */
buffer = calloc(bufsize, sizeof (unsigned char));
- filelen = cpu_to_le32(file->size);
+ filelen = file->size;
data = file->data;
dbuf = data;
@@ -397,6 +397,8 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
goto fail;
}
+ filelen = cpu_to_le32(filelen);
+
/* send the length of the first file (little endian) */
if (!omap_usb_write
(handle, (unsigned char *) &filelen, sizeof (filelen))) {
@@ -406,9 +408,9 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
}
/* send the file! */
- if (!omap_usb_write(handle, data, filelen)) {
+ if (!omap_usb_write(handle, data, file->size)) {
log_error("failed to send file \'%s\' (size %u)\n",
- file->basename, filelen);
+ file->basename, file->size);
goto fail;
}
--
2.39.2
next prev parent reply other threads:[~2024-01-10 14:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-10 14:17 [PATCH 0/2] omap3-usb-loader fixes Sascha Hauer
2024-01-10 14:17 ` [PATCH 1/2] omap3-usb-loader: Fix compilation Sascha Hauer
2024-01-10 14:17 ` Sascha Hauer [this message]
2024-01-11 14:09 ` [PATCH 0/2] omap3-usb-loader fixes Sascha Hauer
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=20240110-scripts-omap3-usb-loader-fix-compilation-v1-2-0503f170fa59@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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