Commit 7bc8439ff2141a5a20081c3d588c6aab3d240829

Authored by Tim Gover
Committed by GitHub
2 parents f765585d 57d69214

Merge pull request #66 from burtyb/patch-3

Add option to look for CM with specific USB path.
Showing 1 changed file with 17 additions and 3 deletions
... ... @@ -27,6 +27,7 @@ int overlay = 0;
27 27 long delay = 500;
28 28 char * directory = NULL;
29 29 char pathname[18] = {0};
  30 +char * targetpathname = NULL;
30 31 uint8_t targetPortNo = 99;
31 32  
32 33 int out_ep;
... ... @@ -65,6 +66,7 @@ void usage(int error)
65 66 fprintf(dest, " -v : Verbose\n");
66 67 fprintf(dest, " -s : Signed using bootsig.bin\n");
67 68 fprintf(dest, " -0/1/2/3/4/5/6 : Only look for CMs attached to USB port number 0-6\n");
  69 + fprintf(dest, " -p [pathname] : Only look for CM with USB pathname\n");
68 70 fprintf(dest, " -h : This help\n");
69 71  
70 72 exit(error ? -1 : 0);
... ... @@ -92,7 +94,7 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
92 94 if (r < 0)
93 95 goto out;
94 96  
95   - if(overlay || verbose == 2)
  97 + if(overlay || verbose == 2 || targetpathname!=NULL)
96 98 {
97 99 r = libusb_get_port_numbers(dev, path, sizeof(path));
98 100 len = snprintf(&pathname[len], 18-len, "%d", libusb_get_bus_number(dev));
... ... @@ -170,7 +172,8 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
170 172 ///////////////////////////////////////////////////////////////////////
171 173 // Check if we should match against a specific port number
172 174 ///////////////////////////////////////////////////////////////////////
173   - if (targetPortNo == 99 || portNo == targetPortNo)
  175 + if ((targetPortNo == 99 || portNo == targetPortNo) &&
  176 + (targetpathname==NULL||strcmp(targetpathname,pathname)==0))
174 177 {
175 178 if(verbose) printf("Device located successfully\n");
176 179 found = dev;
... ... @@ -179,7 +182,7 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid(
179 182 else
180 183 {
181 184 if(verbose == 2)
182   - printf("...Wrong Port, Trying again\n");
  185 + printf("...Wrong Port/Path, Trying again\n");
183 186 }
184 187 }
185 188 }
... ... @@ -312,6 +315,13 @@ void get_options(int argc, char *argv[])
312 315 usage(1);
313 316 directory = *argv;
314 317 }
  318 + else if(strcmp(*argv, "-p") == 0)
  319 + {
  320 + argv++; argc--;
  321 + if(argc < 1)
  322 + usage(1);
  323 + targetpathname = *argv;
  324 + }
315 325 else if(strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0)
316 326 {
317 327 usage(0);
... ... @@ -386,6 +396,10 @@ void get_options(int argc, char *argv[])
386 396 {
387 397 usage(1);
388 398 }
  399 + if((targetPortNo != 99) && (targetpathname != NULL))
  400 + {
  401 + usage(1);
  402 + }
389 403 }
390 404  
391 405 boot_message_t boot_message;
... ...