mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] imx-usb-loader: fix windows usage
Date: Tue, 17 Oct 2023 23:36:08 +0200	[thread overview]
Message-ID: <20231017213608.3494255-5-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20231017213608.3494255-1-m.felsch@pengutronix.de>

This ports commit 561f0377db5e ("Transfer always specified report 2
length") from imx_usb_loader[1] to our implementation.

| commit 561f0377db5e1a36f5ab5e17f97d774f9f1e22ab
| Author: Stefan Agner <stefan.agner@toradex.com>
| Date:   Wed Nov 2 16:51:24 2016 -0700
|
|     Transfer always specified report 2 length
|
|     The Windows HIDAPI is very strict when it comes to packet lengths:
|     The API always expect the length specified by the device and rejects
|     the transfer otherwise. The report size is specified by the HID
|     Report Descriptor. The i.MX 6 SoC reports a report 2 size of 1024.
|     Currently, imx_usb reads the length from the device specific config
|     files and stores it in max_transfer. This change uses max_transfer
|     for report 2 when using the HID API.
|
|     The boot ROM handles too long transfers just fine. Also NXP's
|     sb_loader transfers always complete reports. The change has been
|     successfully tested on Linux and Windows.
|
|     Given that the device reports the size, it is probably also "the
|     right thing to do"...
|
|     With that change, we might end up transferring up to 1023 bytes
|     more than actually necessary. Make sure that DoIRomDownload does
|     not print an error message and returns successfully even if too
|     many bytes have been transferred (this now typically happens at the
|     end of every file).
|
|     In write_dcd use a signed length variable to keep track of remaining
|     bytes. Continue transfer loop only if more than 0 bytes are left to
|     transfer. Also drop the m_ prefix, m_ is usually used for member
|     variables but this is a local variable.
|
|     Signed-off-by: Stefan Agner <stefan.agner@toradex.com>

[1] https://github.com/boundarydevices/imx_usb_loader/commit/561f0377db5e1a36f5ab5e17f97d774f9f1e22ab

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 scripts/imx/imx-usb-loader.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 676f077c25..ece4603b2b 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -484,12 +484,16 @@ static int transfer(int report, void *p, unsigned cnt, int *last_trans)
 		err = libusb_bulk_transfer(usb_dev_handle,
 					   (report < 3) ? 1 : 2 + EP_IN, p, cnt, last_trans, 1000);
 	} else {
-		unsigned char tmp[1028];
+		unsigned char tmp[1028] = { 0 };
 
 		tmp[0] = (unsigned char)report;
 
 		if (report < 3) {
 			memcpy(&tmp[1], p, cnt);
+
+			if (report == 2)
+				cnt = mach_id->max_transfer;
+
 			if (mach_id->hid_endpoint) {
 				int trans;
 				err = libusb_interrupt_transfer(usb_dev_handle,
@@ -739,7 +743,7 @@ static int send_buf(void *buf, unsigned len)
 	while (1) {
 		int now = get_min(cnt, mach_id->max_transfer);
 
-		if (!now)
+		if (now <= 0)
 			break;
 
 		err = transfer(2, p, now, &now);
-- 
2.41.0




  parent reply	other threads:[~2023-10-17 21:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17 21:36 [PATCH 0/4] i.MX USB Loader Windows Fixes Marco Felsch
2023-10-17 21:36 ` [PATCH 1/4] scripts: common: fix read_file_2 for windows Marco Felsch
2023-10-17 21:36 ` [PATCH 2/4] scripts: common: fix buffer freeing Marco Felsch
2023-10-17 21:36 ` [PATCH 3/4] usb: gadget: fsl_udc: lower state_complete constraints Marco Felsch
2023-10-17 21:36 ` Marco Felsch [this message]
2023-10-18 10:46   ` [PATCH 4/4] imx-usb-loader: fix windows usage Ahmad Fatoum
2023-10-18 12:53     ` Marco Felsch
2023-10-18 13:07       ` Ahmad Fatoum
2023-10-18 14:32         ` Marco Felsch
2023-10-18  8:18 ` [PATCH 0/4] i.MX USB Loader Windows 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=20231017213608.3494255-5-m.felsch@pengutronix.de \
    --to=m.felsch@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