diff --git a/main.c b/main.c index 2d8fd45..aff2ac1 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ int overlay = 0; long delay = 500; char * directory = NULL; char pathname[18]; +uint8_t targetPortNo = 99; int out_ep; int in_ep; @@ -40,6 +41,7 @@ void usage(int error) fprintf(dest, " -m delay : Microseconds delay between checking for new devices (default 500)\n"); fprintf(dest, " -v : Verbose\n"); fprintf(dest, " -s : Signed using bootsig.bin\n"); + fprintf(dest, " -0/1/2/3/4/5/6 : Only look for CMs attached to USB port number 0-6\n"); fprintf(dest, " -h : This help\n"); exit(error ? -1 : 0); @@ -54,7 +56,8 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( struct libusb_device_handle *handle = NULL; uint32_t i = 0; int r, j, len; - uint8_t path[8]; + uint8_t path[8]; // Needed for libusb_get_port_numbers + uint8_t portNo = 0; if (libusb_get_device_list(ctx, &devs) < 0) return NULL; @@ -80,6 +83,14 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( } } + /* + http://libusb.sourceforge.net/api-1.0/group__dev.html#ga14879a0ea7daccdcddb68852d86c00c4 + + The port number returned by this call is usually guaranteed to be uniquely tied to a physical port, + meaning that different devices plugged on the same physical port should return the same port number. + */ + portNo = libusb_get_port_number(dev); + if(verbose == 2) { 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( if(desc.idProduct == 0x2763 || desc.idProduct == 0x2764) { - if(verbose) printf("Device located successfully\n"); - found = dev; - break; + if(verbose == 2) + printf("Found candidate Compute Module..."); + + /////////////////////////////////////////////////////////////////////// + // Check if we should match against a specific port number + /////////////////////////////////////////////////////////////////////// + if (targetPortNo == 99 || portNo == targetPortNo) + { + if(verbose) printf("Device located successfully\n"); + found = dev; + break; + } + else + { + if(verbose == 2) + printf("...Wrong Port, Trying again\n"); + } } } } @@ -241,6 +266,34 @@ void get_options(int argc, char *argv[]) { signed_boot = 1; } + else if(strcmp(*argv, "-0") == 0) + { + targetPortNo = 0; + } + else if(strcmp(*argv, "-1") == 0) + { + targetPortNo = 1; + } + else if(strcmp(*argv, "-2") == 0) + { + targetPortNo = 2; + } + else if(strcmp(*argv, "-3") == 0) + { + targetPortNo = 3; + } + else if(strcmp(*argv, "-4") == 0) + { + targetPortNo = 4; + } + else if(strcmp(*argv, "-5") == 0) + { + targetPortNo = 5; + } + else if(strcmp(*argv, "-6") == 0) + { + targetPortNo = 6; + } else { usage(1);