mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] omap3-usb-loader fixes
@ 2024-01-10 14:17 Sascha Hauer
  2024-01-10 14:17 ` [PATCH 1/2] omap3-usb-loader: Fix compilation Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-01-10 14:17 UTC (permalink / raw)
  To: open list:BAREBOX

This contains a few fixes for the omap3-usb-loader tool

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Sascha Hauer (2):
      omap3-usb-loader: Fix compilation
      omap3-usb-loader: Fix for big endian hosts

 scripts/omap3-usb-loader.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
---
base-commit: d1f8df4a012ec52f1b4bca785cfd2a67d690c09e
change-id: 20240110-scripts-omap3-usb-loader-fix-compilation-75aa81a52f0a

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

* [PATCH 1/2] omap3-usb-loader: Fix compilation
  2024-01-10 14:17 [PATCH 0/2] omap3-usb-loader fixes Sascha Hauer
@ 2024-01-10 14:17 ` Sascha Hauer
  2024-01-10 14:17 ` [PATCH 2/2] omap3-usb-loader: Fix for big endian hosts Sascha Hauer
  2024-01-11 14:09 ` [PATCH 0/2] omap3-usb-loader fixes Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-01-10 14:17 UTC (permalink / raw)
  To: open list:BAREBOX

Since a4a04ec768e ("scripts: common: fix read_file_2 for windows")
common.c includes compiler.h which defines cpu_to_le32 and friends
which are also defined in omap3-usb-loader.c. Drop the duplicated
definitions from omap3-usb-loader.c to make it compile again.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/omap3-usb-loader.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index 31a03be8e7..d9422a0916 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -19,10 +19,6 @@
 #define PROG_NAME "OMAP Loader"
 #define VERSION "1.0.0"
 
-#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
-#define OMAP_IS_BIG_ENDIAN
-#endif
-
 #include <unistd.h>		/* for usleep and friends */
 #include <getopt.h>
 #include <errno.h>
@@ -46,15 +42,6 @@
 #define OMAP_USB_BULK_OUT 0x01
 #define OMAP_ASIC_ID_LEN 69
 
-#ifdef OMAP_IS_BIG_ENDIAN
-#define cpu_to_le32(v) (((v & 0xff) << 24) | ((v & 0xff00) << 8) | \
-    ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24))
-#define le32_to_cpu(v) cpu_to_le32(v)
-#else
-#define cpu_to_le32(v) (v)
-#define le32_to_cpu(v) (v)
-#endif
-
 /*
  * taken from x-loader/drivers/usb/usb.c
  * All credit to Martin Mueller

-- 
2.39.2




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

* [PATCH 2/2] omap3-usb-loader: Fix for big endian hosts
  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
  2024-01-11 14:09 ` [PATCH 0/2] omap3-usb-loader fixes Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-01-10 14:17 UTC (permalink / raw)
  To: open list:BAREBOX

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




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

* Re: [PATCH 0/2] omap3-usb-loader fixes
  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 ` [PATCH 2/2] omap3-usb-loader: Fix for big endian hosts Sascha Hauer
@ 2024-01-11 14:09 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-01-11 14:09 UTC (permalink / raw)
  To: open list:BAREBOX, Sascha Hauer


On Wed, 10 Jan 2024 15:17:10 +0100, Sascha Hauer wrote:
> This contains a few fixes for the omap3-usb-loader tool
> 
> 

Applied, thanks!

[1/2] omap3-usb-loader: Fix compilation
      commit: 542d86f3c1f9442a4a4bd224f95d2d7c07eb09a0
[2/2] omap3-usb-loader: Fix for big endian hosts
      commit: 8327cfa82d00dcd25300498f67bc4b90869a35f0

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2024-01-11 14:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] omap3-usb-loader: Fix for big endian hosts Sascha Hauer
2024-01-11 14:09 ` [PATCH 0/2] omap3-usb-loader fixes Sascha Hauer

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