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