Commit 57d692145dda563e40da293efb5cbb415d563c33
1 parent
d3760e11
Add option to look for CM with specific USB path.
Showing
1 changed file
with
17 additions
and
3 deletions
main.c
| @@ -22,6 +22,7 @@ int overlay = 0; | @@ -22,6 +22,7 @@ int overlay = 0; | ||
| 22 | long delay = 500; | 22 | long delay = 500; |
| 23 | char * directory = NULL; | 23 | char * directory = NULL; |
| 24 | char pathname[18] = {0}; | 24 | char pathname[18] = {0}; |
| 25 | +char * targetpathname = NULL; | ||
| 25 | uint8_t targetPortNo = 99; | 26 | uint8_t targetPortNo = 99; |
| 26 | 27 | ||
| 27 | int out_ep; | 28 | int out_ep; |
| @@ -60,6 +61,7 @@ void usage(int error) | @@ -60,6 +61,7 @@ void usage(int error) | ||
| 60 | fprintf(dest, " -v : Verbose\n"); | 61 | fprintf(dest, " -v : Verbose\n"); |
| 61 | fprintf(dest, " -s : Signed using bootsig.bin\n"); | 62 | fprintf(dest, " -s : Signed using bootsig.bin\n"); |
| 62 | fprintf(dest, " -0/1/2/3/4/5/6 : Only look for CMs attached to USB port number 0-6\n"); | 63 | fprintf(dest, " -0/1/2/3/4/5/6 : Only look for CMs attached to USB port number 0-6\n"); |
| 64 | + fprintf(dest, " -p [pathname] : Only look for CM with USB pathname\n"); | ||
| 63 | fprintf(dest, " -h : This help\n"); | 65 | fprintf(dest, " -h : This help\n"); |
| 64 | 66 | ||
| 65 | exit(error ? -1 : 0); | 67 | exit(error ? -1 : 0); |
| @@ -87,7 +89,7 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | @@ -87,7 +89,7 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | ||
| 87 | if (r < 0) | 89 | if (r < 0) |
| 88 | goto out; | 90 | goto out; |
| 89 | 91 | ||
| 90 | - if(overlay || verbose == 2) | 92 | + if(overlay || verbose == 2 || targetpathname!=NULL) |
| 91 | { | 93 | { |
| 92 | r = libusb_get_port_numbers(dev, path, sizeof(path)); | 94 | r = libusb_get_port_numbers(dev, path, sizeof(path)); |
| 93 | len = snprintf(&pathname[len], 18-len, "%d", libusb_get_bus_number(dev)); | 95 | len = snprintf(&pathname[len], 18-len, "%d", libusb_get_bus_number(dev)); |
| @@ -165,7 +167,8 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | @@ -165,7 +167,8 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | ||
| 165 | /////////////////////////////////////////////////////////////////////// | 167 | /////////////////////////////////////////////////////////////////////// |
| 166 | // Check if we should match against a specific port number | 168 | // Check if we should match against a specific port number |
| 167 | /////////////////////////////////////////////////////////////////////// | 169 | /////////////////////////////////////////////////////////////////////// |
| 168 | - if (targetPortNo == 99 || portNo == targetPortNo) | 170 | + if ((targetPortNo == 99 || portNo == targetPortNo) && |
| 171 | + (targetpathname==NULL||strcmp(targetpathname,pathname)==0)) | ||
| 169 | { | 172 | { |
| 170 | if(verbose) printf("Device located successfully\n"); | 173 | if(verbose) printf("Device located successfully\n"); |
| 171 | found = dev; | 174 | found = dev; |
| @@ -174,7 +177,7 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | @@ -174,7 +177,7 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | ||
| 174 | else | 177 | else |
| 175 | { | 178 | { |
| 176 | if(verbose == 2) | 179 | if(verbose == 2) |
| 177 | - printf("...Wrong Port, Trying again\n"); | 180 | + printf("...Wrong Port/Path, Trying again\n"); |
| 178 | } | 181 | } |
| 179 | } | 182 | } |
| 180 | } | 183 | } |
| @@ -307,6 +310,13 @@ void get_options(int argc, char *argv[]) | @@ -307,6 +310,13 @@ void get_options(int argc, char *argv[]) | ||
| 307 | usage(1); | 310 | usage(1); |
| 308 | directory = *argv; | 311 | directory = *argv; |
| 309 | } | 312 | } |
| 313 | + else if(strcmp(*argv, "-p") == 0) | ||
| 314 | + { | ||
| 315 | + argv++; argc--; | ||
| 316 | + if(argc < 1) | ||
| 317 | + usage(1); | ||
| 318 | + targetpathname = *argv; | ||
| 319 | + } | ||
| 310 | else if(strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0) | 320 | else if(strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0) |
| 311 | { | 321 | { |
| 312 | usage(0); | 322 | usage(0); |
| @@ -381,6 +391,10 @@ void get_options(int argc, char *argv[]) | @@ -381,6 +391,10 @@ void get_options(int argc, char *argv[]) | ||
| 381 | { | 391 | { |
| 382 | usage(1); | 392 | usage(1); |
| 383 | } | 393 | } |
| 394 | + if((targetPortNo != 99) && (targetpathname != NULL)) | ||
| 395 | + { | ||
| 396 | + usage(1); | ||
| 397 | + } | ||
| 384 | } | 398 | } |
| 385 | 399 | ||
| 386 | boot_message_t boot_message; | 400 | boot_message_t boot_message; |