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,6 +12,7 @@ int overlay = 0;
12 long delay = 500; 12 long delay = 500;
13 char * directory = NULL; 13 char * directory = NULL;
14 char pathname[18]; 14 char pathname[18];
  15 +uint8_t targetPortNo = 99;
15 16
16 int out_ep; 17 int out_ep;
17 int in_ep; 18 int in_ep;
@@ -40,6 +41,7 @@ void usage(int error) @@ -40,6 +41,7 @@ void usage(int error)
40 fprintf(dest, " -m delay : Microseconds delay between checking for new devices (default 500)\n"); 41 fprintf(dest, " -m delay : Microseconds delay between checking for new devices (default 500)\n");
41 fprintf(dest, " -v : Verbose\n"); 42 fprintf(dest, " -v : Verbose\n");
42 fprintf(dest, " -s : Signed using bootsig.bin\n"); 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 fprintf(dest, " -h : This help\n"); 45 fprintf(dest, " -h : This help\n");
44 46
45 exit(error ? -1 : 0); 47 exit(error ? -1 : 0);
@@ -54,7 +56,8 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( @@ -54,7 +56,8 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
54 struct libusb_device_handle *handle = NULL; 56 struct libusb_device_handle *handle = NULL;
55 uint32_t i = 0; 57 uint32_t i = 0;
56 int r, j, len; 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 if (libusb_get_device_list(ctx, &devs) < 0) 62 if (libusb_get_device_list(ctx, &devs) < 0)
60 return NULL; 63 return NULL;
@@ -80,6 +83,14 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( @@ -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 if(verbose == 2) 94 if(verbose == 2)
84 { 95 {
85 printf("Found device %u idVendor=0x%04x idProduct=0x%04x\n", i, desc.idVendor, desc.idProduct); 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,9 +101,23 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
90 if(desc.idProduct == 0x2763 || 101 if(desc.idProduct == 0x2763 ||
91 desc.idProduct == 0x2764) 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,6 +266,34 @@ void get_options(int argc, char *argv[])
241 { 266 {
242 signed_boot = 1; 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 else 297 else
245 { 298 {
246 usage(1); 299 usage(1);