Commit fb86716935f2e820333b037a2ff93a338ad9b695

Authored by Phil Elwell
Committed by GitHub
1 parent bffe2e52

usbboot: Add support for multiple instances

From a patch by mypiandrew.

See: https://github.com/raspberrypi/usbboot/issues/21
Showing 1 changed file with 57 additions and 4 deletions
... ... @@ -12,6 +12,7 @@ int overlay = 0;
12 12 long delay = 500;
13 13 char * directory = NULL;
14 14 char pathname[18];
  15 +uint8_t targetPortNo = 99;
15 16  
16 17 int out_ep;
17 18 int in_ep;
... ... @@ -40,6 +41,7 @@ void usage(int error)
40 41 fprintf(dest, " -m delay : Microseconds delay between checking for new devices (default 500)\n");
41 42 fprintf(dest, " -v : Verbose\n");
42 43 fprintf(dest, " -s : Signed using bootsig.bin\n");
  44 + fprintf(dest, " -0/1/2/3/4/5/6 : Only look for CMs attached to USB port number 0-6\n");
43 45 fprintf(dest, " -h : This help\n");
44 46  
45 47 exit(error ? -1 : 0);
... ... @@ -54,7 +56,8 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
54 56 struct libusb_device_handle *handle = NULL;
55 57 uint32_t i = 0;
56 58 int r, j, len;
57   - uint8_t path[8];
  59 + uint8_t path[8]; // Needed for libusb_get_port_numbers
  60 + uint8_t portNo = 0;
58 61  
59 62 if (libusb_get_device_list(ctx, &devs) < 0)
60 63 return NULL;
... ... @@ -80,6 +83,14 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
80 83 }
81 84 }
82 85  
  86 + /*
  87 + http://libusb.sourceforge.net/api-1.0/group__dev.html#ga14879a0ea7daccdcddb68852d86c00c4
  88 +
  89 + The port number returned by this call is usually guaranteed to be uniquely tied to a physical port,
  90 + meaning that different devices plugged on the same physical port should return the same port number.
  91 + */
  92 + portNo = libusb_get_port_number(dev);
  93 +
83 94 if(verbose == 2)
84 95 {
85 96 printf("Found device %u idVendor=0x%04x idProduct=0x%04x\n", i, desc.idVendor, desc.idProduct);
... ... @@ -90,9 +101,23 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
90 101 if(desc.idProduct == 0x2763 ||
91 102 desc.idProduct == 0x2764)
92 103 {
93   - if(verbose) printf("Device located successfully\n");
94   - found = dev;
95   - break;
  104 + if(verbose == 2)
  105 + printf("Found candidate Compute Module...");
  106 +
  107 + ///////////////////////////////////////////////////////////////////////
  108 + // Check if we should match against a specific port number
  109 + ///////////////////////////////////////////////////////////////////////
  110 + if (targetPortNo == 99 || portNo == targetPortNo)
  111 + {
  112 + if(verbose) printf("Device located successfully\n");
  113 + found = dev;
  114 + break;
  115 + }
  116 + else
  117 + {
  118 + if(verbose == 2)
  119 + printf("...Wrong Port, Trying again\n");
  120 + }
96 121 }
97 122 }
98 123 }
... ... @@ -241,6 +266,34 @@ void get_options(int argc, char *argv[])
241 266 {
242 267 signed_boot = 1;
243 268 }
  269 + else if(strcmp(*argv, "-0") == 0)
  270 + {
  271 + targetPortNo = 0;
  272 + }
  273 + else if(strcmp(*argv, "-1") == 0)
  274 + {
  275 + targetPortNo = 1;
  276 + }
  277 + else if(strcmp(*argv, "-2") == 0)
  278 + {
  279 + targetPortNo = 2;
  280 + }
  281 + else if(strcmp(*argv, "-3") == 0)
  282 + {
  283 + targetPortNo = 3;
  284 + }
  285 + else if(strcmp(*argv, "-4") == 0)
  286 + {
  287 + targetPortNo = 4;
  288 + }
  289 + else if(strcmp(*argv, "-5") == 0)
  290 + {
  291 + targetPortNo = 5;
  292 + }
  293 + else if(strcmp(*argv, "-6") == 0)
  294 + {
  295 + targetPortNo = 6;
  296 + }
244 297 else
245 298 {
246 299 usage(1);
... ...