* [PATCH 0/4] make imx-usb-loader usable for unknown device IDs
@ 2018-09-03 19:32 Roland Hieber
2018-09-03 19:32 ` [PATCH 1/4] scripts: imx-usb-loader: rename imx_device() to imx_device_by_usb_id() Roland Hieber
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Roland Hieber @ 2018-09-03 19:32 UTC (permalink / raw)
To: barebox; +Cc: Roland Hieber
Some newer i.MX processors allow changing the USB Vendor/Product ID by
blowing fuses. This short series allws imx-usb-loader to deal with such
hardware that is indeed an i.MX device and supports the USB bootloader
protocol, but doesn't identify as an i.MX device via its USB ID.
Patches 1 and 2 do some small preparation, Patch 3 is the real work, and
Patch 4 polishes it nicely.
Roland Hieber (4):
scripts: imx-usb-loader: rename imx_device() to imx_device_by_usb_id()
scripts: imx-usb-loader: fail early if the USB device path does not
match
scripts: imx-usb-loader: allow use of unknown USB IDs
scripts: imx-usb-loader: make i.MX6SoloX better to type
scripts/imx/imx-usb-loader.c | 76 +++++++++++++++++++++++++++++-------
1 file changed, 62 insertions(+), 14 deletions(-)
--
2.18.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] scripts: imx-usb-loader: rename imx_device() to imx_device_by_usb_id()
2018-09-03 19:32 [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Roland Hieber
@ 2018-09-03 19:32 ` Roland Hieber
2018-09-03 19:32 ` [PATCH 2/4] scripts: imx-usb-loader: fail early if the USB device path does not match Roland Hieber
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Roland Hieber @ 2018-09-03 19:32 UTC (permalink / raw)
To: barebox; +Cc: Roland Hieber
Make its purpose more clear when we introduce other similar functions
in one of the next commits.
Signed-off-by: Roland Hieber <r.hieber@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 541c59e36e..a88bca0e83 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -214,7 +214,8 @@ struct mxs_command {
uint32_t dw_size; /* Download size */
} __attribute__((packed));
-static const struct mach_id *imx_device(unsigned short vid, unsigned short pid)
+static const struct mach_id *imx_device_by_usb_id(unsigned short vid,
+ unsigned short pid)
{
int i;
@@ -306,7 +307,7 @@ static libusb_device *find_imx_dev(libusb_device **devs, const struct mach_id **
return NULL;
}
- p = imx_device(desc.idVendor, desc.idProduct);
+ p = imx_device_by_usb_id(desc.idVendor, desc.idProduct);
if (!p)
continue;
--
2.18.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] scripts: imx-usb-loader: fail early if the USB device path does not match
2018-09-03 19:32 [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Roland Hieber
2018-09-03 19:32 ` [PATCH 1/4] scripts: imx-usb-loader: rename imx_device() to imx_device_by_usb_id() Roland Hieber
@ 2018-09-03 19:32 ` Roland Hieber
2018-09-03 19:32 ` [PATCH 3/4] scripts: imx-usb-loader: allow use of unknown USB IDs Roland Hieber
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Roland Hieber @ 2018-09-03 19:32 UTC (permalink / raw)
To: barebox; +Cc: Roland Hieber
find_imx_dev() loops through all USB devices, tries to open them, and
then compares the chosen device path (given with -p on the command line)
to the path of the currently opened device. The device path can be
checked earlier, opening the device is not neccessary.
We fail early here because in the next commit we want to enable the user
to force using a device by specifying its path. Opening every single
device available on the system then leads to unnecessary error messages
for all devices that do not match the provided path.
Signed-off-by: Roland Hieber <r.hieber@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index a88bca0e83..6615ce3ca8 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -307,6 +307,12 @@ static libusb_device *find_imx_dev(libusb_device **devs, const struct mach_id **
return NULL;
}
+ if (location && !device_location_equal(dev, location)) {
+ libusb_close(usb_dev_handle);
+ usb_dev_handle = NULL;
+ continue;
+ }
+
p = imx_device_by_usb_id(desc.idVendor, desc.idProduct);
if (!p)
continue;
@@ -318,12 +324,6 @@ static libusb_device *find_imx_dev(libusb_device **devs, const struct mach_id **
continue;
}
- if (location && !device_location_equal(dev, location)) {
- libusb_close(usb_dev_handle);
- usb_dev_handle = NULL;
- continue;
- }
-
*pp_id = p;
return dev;
}
--
2.18.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] scripts: imx-usb-loader: allow use of unknown USB IDs
2018-09-03 19:32 [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Roland Hieber
2018-09-03 19:32 ` [PATCH 1/4] scripts: imx-usb-loader: rename imx_device() to imx_device_by_usb_id() Roland Hieber
2018-09-03 19:32 ` [PATCH 2/4] scripts: imx-usb-loader: fail early if the USB device path does not match Roland Hieber
@ 2018-09-03 19:32 ` Roland Hieber
2018-09-03 19:32 ` [PATCH 4/4] scripts: imx-usb-loader: make i.MX6SoloX better to type Roland Hieber
2018-09-04 8:21 ` [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Roland Hieber @ 2018-09-03 19:32 UTC (permalink / raw)
To: barebox; +Cc: Roland Hieber
Some vendors fuse their devices so that the IMX USB ROM loader
identifies itself with a different Vendor and Product ID on USB
enumeration. Currently, imx-usb-loader will refuse to detect and work
with such devices, so let's teach it.
Because we cannot easily detect the device type from the USB ID in this
case, introduce the new command line parameter -d <type> to specify the
device type to use on the device path specified with -p <path>, even if
the VID/PID pair of that device is unknown. The device name is sourced
from the "name" field of the imx_ids array of known devices at the top
of the file. Using "-d list" will print a list of known device types.
Using -d without -p will not do anything useful, except generate a
warning.
Signed-off-by: Roland Hieber <r.hieber@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 61 +++++++++++++++++++++++++++++++-----
1 file changed, 54 insertions(+), 7 deletions(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 6615ce3ca8..53e1c7ebb5 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -231,6 +231,29 @@ static const struct mach_id *imx_device_by_usb_id(unsigned short vid,
return NULL;
}
+static const struct mach_id *imx_device_by_type(const char *name)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(imx_ids); i++) {
+ const struct mach_id *id = &imx_ids[i];
+ if (strcmp(id->name, name) == 0) {
+ fprintf(stderr, "found %s USB device\n", id->name);
+ return id;
+ }
+ }
+
+ fprintf(stderr, "unknown device type: '%s', try '-d list'.\n", name);
+ return NULL;
+}
+
+static void list_imx_device_types(void)
+{
+ for (int i = 0; i < ARRAY_SIZE(imx_ids); i++) {
+ printf("%s\n", imx_ids[i].name);
+ }
+}
+
static int device_location_equal(libusb_device *device, const char *location)
{
uint8_t port_path[MAX_USB_PORTS];
@@ -287,7 +310,7 @@ done:
}
static libusb_device *find_imx_dev(libusb_device **devs, const struct mach_id **pp_id,
- const char *location)
+ const char *location, const char *type)
{
int i = 0;
int err;
@@ -313,14 +336,21 @@ static libusb_device *find_imx_dev(libusb_device **devs, const struct mach_id **
continue;
}
- p = imx_device_by_usb_id(desc.idVendor, desc.idProduct);
- if (!p)
- continue;
+ if (location && type) {
+ p = imx_device_by_type(type);
+ if (!p)
+ return NULL; // unknown type
+ }
+ else {
+ p = imx_device_by_usb_id(desc.idVendor, desc.idProduct);
+ if (!p)
+ continue;
+ }
err = libusb_open(dev, &usb_dev_handle);
if (err) {
fprintf(stderr, "Could not open device vid=0x%x pid=0x%x err=%d\n",
- p->vid, p->pid, err);
+ desc.idVendor, desc.idProduct, err);
continue;
}
@@ -1523,6 +1553,10 @@ static void usage(const char *prgname)
{
fprintf(stderr, "usage: %s [OPTIONS] [FILENAME]\n\n"
"-c check correctness of flashed image\n"
+ "-d <devtype> with -p: Specify device type to use, and use <devpath> even if\n"
+ " its USB VID/PID is unknown. Note that this could potentially be\n"
+ " dangerous, as the device autodetection is overridden!\n"
+ " Use '-d list' to get a list of known device types.\n"
"-i <cfgfile> Specify custom SoC initialization file\n"
"-p <devpath> Specify device path: <bus>-<port>[.<port>]...\n"
"-s skip DCD included in image\n"
@@ -1546,10 +1580,11 @@ int main(int argc, char *argv[])
int opt;
char *initfile = NULL;
char *devpath = NULL;
+ char *devtype = NULL;
w.do_dcd_once = 1;
- while ((opt = getopt(argc, argv, "cvhi:p:s")) != -1) {
+ while ((opt = getopt(argc, argv, "cvhd:i:p:s")) != -1) {
switch (opt) {
case 'c':
verify = 1;
@@ -1559,6 +1594,9 @@ int main(int argc, char *argv[])
break;
case 'h':
usage(argv[0]);
+ case 'd':
+ devtype = optarg;
+ break;
case 'i':
initfile = optarg;
break;
@@ -1573,6 +1611,15 @@ int main(int argc, char *argv[])
}
}
+ if (devtype && strcmp(devtype, "list") == 0) {
+ list_imx_device_types();
+ exit(0);
+ }
+
+ if (devtype && !devpath) {
+ fprintf(stderr, "Note: ignoring -d <type> given without -p <path>.\n");
+ }
+
if (optind == argc) {
fprintf(stderr, "no filename given\n");
usage(argv[0]);
@@ -1592,7 +1639,7 @@ int main(int argc, char *argv[])
goto out;
}
- dev = find_imx_dev(devs, &mach, devpath);
+ dev = find_imx_dev(devs, &mach, devpath, devtype);
if (!dev) {
fprintf(stderr, "no supported device found\n");
goto out;
--
2.18.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] scripts: imx-usb-loader: make i.MX6SoloX better to type
2018-09-03 19:32 [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Roland Hieber
` (2 preceding siblings ...)
2018-09-03 19:32 ` [PATCH 3/4] scripts: imx-usb-loader: allow use of unknown USB IDs Roland Hieber
@ 2018-09-03 19:32 ` Roland Hieber
2018-09-04 8:21 ` [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Roland Hieber @ 2018-09-03 19:32 UTC (permalink / raw)
To: barebox; +Cc: Roland Hieber
Now that users can select the device type on the command line, having a
name without whitespace makes input for that device type easier.
Signed-off-by: Roland Hieber <r.hieber@pengutronix.de>
---
scripts/imx/imx-usb-loader.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 53e1c7ebb5..4336bc8d53 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -160,7 +160,7 @@ static const struct mach_id imx_ids[] = {
}, {
.vid = 0x15a2,
.pid = 0x0071,
- .name = "i.MX6 SoloX",
+ .name = "i.MX6SoloX",
.header_type = HDR_MX53,
.mode = MODE_HID,
.max_transfer = 1024,
--
2.18.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] make imx-usb-loader usable for unknown device IDs
2018-09-03 19:32 [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Roland Hieber
` (3 preceding siblings ...)
2018-09-03 19:32 ` [PATCH 4/4] scripts: imx-usb-loader: make i.MX6SoloX better to type Roland Hieber
@ 2018-09-04 8:21 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2018-09-04 8:21 UTC (permalink / raw)
To: Roland Hieber; +Cc: barebox
On Mon, Sep 03, 2018 at 09:32:51PM +0200, Roland Hieber wrote:
> Some newer i.MX processors allow changing the USB Vendor/Product ID by
> blowing fuses. This short series allws imx-usb-loader to deal with such
> hardware that is indeed an i.MX device and supports the USB bootloader
> protocol, but doesn't identify as an i.MX device via its USB ID.
>
> Patches 1 and 2 do some small preparation, Patch 3 is the real work, and
> Patch 4 polishes it nicely.
>
> Roland Hieber (4):
> scripts: imx-usb-loader: rename imx_device() to imx_device_by_usb_id()
> scripts: imx-usb-loader: fail early if the USB device path does not
> match
> scripts: imx-usb-loader: allow use of unknown USB IDs
> scripts: imx-usb-loader: make i.MX6SoloX better to type
>
> scripts/imx/imx-usb-loader.c | 76 +++++++++++++++++++++++++++++-------
> 1 file changed, 62 insertions(+), 14 deletions(-)
Applied, thanks
Sascha
>
> --
> 2.18.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-09-04 8:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 19:32 [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Roland Hieber
2018-09-03 19:32 ` [PATCH 1/4] scripts: imx-usb-loader: rename imx_device() to imx_device_by_usb_id() Roland Hieber
2018-09-03 19:32 ` [PATCH 2/4] scripts: imx-usb-loader: fail early if the USB device path does not match Roland Hieber
2018-09-03 19:32 ` [PATCH 3/4] scripts: imx-usb-loader: allow use of unknown USB IDs Roland Hieber
2018-09-03 19:32 ` [PATCH 4/4] scripts: imx-usb-loader: make i.MX6SoloX better to type Roland Hieber
2018-09-04 8:21 ` [PATCH 0/4] make imx-usb-loader usable for unknown device IDs Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox