Commit bc1fe9e8330a1159baaa796afdf78a7f7d2c7b23
Committed by
Gordon Hollingworth
1 parent
94c87275
Directory overlay support (#23)
* Add boot directory overlay support (USB path) * Sleep before libusb_control_transfer seems to prevent timeout errors?? * Cleanup (removing unneeded sleep/spacing) Break out of "file_server" loop if the device no longer exists (prevents getting stuck in the loop) Sleep longer in the main detection loop (reduces CPU usage) * Cleanup merged code * Add delay option to reduce CPU usage (e.g. 500 = 7% CPU usage, 5000 = 1% CPU usage) * Require space between "-m" option and delay value.
Showing
1 changed file
with
68 additions
and
7 deletions
main.c
100755 → 100644
| @@ -8,7 +8,10 @@ | @@ -8,7 +8,10 @@ | ||
| 8 | int signed_boot = 0; | 8 | int signed_boot = 0; |
| 9 | int verbose = 0; | 9 | int verbose = 0; |
| 10 | int loop = 0; | 10 | int loop = 0; |
| 11 | +int overlay = 0; | ||
| 12 | +long delay = 500; | ||
| 11 | char * directory = NULL; | 13 | char * directory = NULL; |
| 14 | +char pathname[18]; | ||
| 12 | 15 | ||
| 13 | int out_ep; | 16 | int out_ep; |
| 14 | int in_ep; | 17 | int in_ep; |
| @@ -31,6 +34,10 @@ void usage(int error) | @@ -31,6 +34,10 @@ void usage(int error) | ||
| 31 | fprintf(dest, "rpiboot -d [directory] : Boot the device using the boot files in 'directory'\n"); | 34 | fprintf(dest, "rpiboot -d [directory] : Boot the device using the boot files in 'directory'\n"); |
| 32 | fprintf(dest, "Further options:\n"); | 35 | fprintf(dest, "Further options:\n"); |
| 33 | fprintf(dest, " -l : Loop forever\n"); | 36 | fprintf(dest, " -l : Loop forever\n"); |
| 37 | + fprintf(dest, " -o : Use files from overlay subdirectory if they exist (when using a custom directory)\n"); | ||
| 38 | + fprintf(dest, " USB Path (1-1.3.2 for example) is shown in verbose mode.\n"); | ||
| 39 | + fprintf(dest, " (bootcode.bin is always preloaded from the base directory)\n"); | ||
| 40 | + fprintf(dest, " -m delay : Microseconds delay between checking for new devices (default 500)\n"); | ||
| 34 | fprintf(dest, " -v : Verbose\n"); | 41 | fprintf(dest, " -v : Verbose\n"); |
| 35 | fprintf(dest, " -s : Signed using bootsig.bin\n"); | 42 | fprintf(dest, " -s : Signed using bootsig.bin\n"); |
| 36 | fprintf(dest, " -h : This help\n"); | 43 | fprintf(dest, " -h : This help\n"); |
| @@ -46,18 +53,39 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | @@ -46,18 +53,39 @@ libusb_device_handle * LIBUSB_CALL open_device_with_vid( | ||
| 46 | struct libusb_device *dev; | 53 | struct libusb_device *dev; |
| 47 | struct libusb_device_handle *handle = NULL; | 54 | struct libusb_device_handle *handle = NULL; |
| 48 | uint32_t i = 0; | 55 | uint32_t i = 0; |
| 49 | - int r; | 56 | + int r, j, len; |
| 57 | + uint8_t path[8]; | ||
| 50 | 58 | ||
| 51 | if (libusb_get_device_list(ctx, &devs) < 0) | 59 | if (libusb_get_device_list(ctx, &devs) < 0) |
| 52 | return NULL; | 60 | return NULL; |
| 53 | 61 | ||
| 54 | while ((dev = devs[i++]) != NULL) { | 62 | while ((dev = devs[i++]) != NULL) { |
| 63 | + len = 0; | ||
| 55 | struct libusb_device_descriptor desc; | 64 | struct libusb_device_descriptor desc; |
| 56 | r = libusb_get_device_descriptor(dev, &desc); | 65 | r = libusb_get_device_descriptor(dev, &desc); |
| 57 | if (r < 0) | 66 | if (r < 0) |
| 58 | goto out; | 67 | goto out; |
| 68 | + | ||
| 69 | + if(overlay || verbose == 2) | ||
| 70 | + { | ||
| 71 | + r = libusb_get_port_numbers(dev, path, sizeof(path)); | ||
| 72 | + len = snprintf(&pathname[len], 18-len, "%d", libusb_get_bus_number(dev)); | ||
| 73 | + if (r > 0) { | ||
| 74 | + len += snprintf(&pathname[len], 18-len, "-"); | ||
| 75 | + len += snprintf(&pathname[len], 18-len, "%d", path[0]); | ||
| 76 | + for (j = 1; j < r; j++) | ||
| 77 | + { | ||
| 78 | + len += snprintf(&pathname[len], 18-len, ".%d", path[j]); | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + | ||
| 59 | if(verbose == 2) | 83 | if(verbose == 2) |
| 84 | + { | ||
| 60 | printf("Found device %u idVendor=0x%04x idProduct=0x%04x\n", i, desc.idVendor, desc.idProduct); | 85 | printf("Found device %u idVendor=0x%04x idProduct=0x%04x\n", i, desc.idVendor, desc.idProduct); |
| 86 | + printf("Bus: %d, Device: %d Path: %s\n",libusb_get_bus_number(dev), libusb_get_device_address(dev), pathname); | ||
| 87 | + } | ||
| 88 | + | ||
| 61 | if (desc.idVendor == vendor_id) { | 89 | if (desc.idVendor == vendor_id) { |
| 62 | if(desc.idProduct == 0x2763 || | 90 | if(desc.idProduct == 0x2763 || |
| 63 | desc.idProduct == 0x2764) | 91 | desc.idProduct == 0x2764) |
| @@ -142,7 +170,7 @@ int ep_write(void *buf, int len, libusb_device_handle * usb_device) | @@ -142,7 +170,7 @@ int ep_write(void *buf, int len, libusb_device_handle * usb_device) | ||
| 142 | 170 | ||
| 143 | if(ret != 0) | 171 | if(ret != 0) |
| 144 | { | 172 | { |
| 145 | - printf("Failed control transfer\n"); | 173 | + printf("Failed control transfer (%d,%d)\n", ret, len); |
| 146 | return ret; | 174 | return ret; |
| 147 | } | 175 | } |
| 148 | 176 | ||
| @@ -194,6 +222,17 @@ void get_options(int argc, char *argv[]) | @@ -194,6 +222,17 @@ void get_options(int argc, char *argv[]) | ||
| 194 | { | 222 | { |
| 195 | verbose = 1; | 223 | verbose = 1; |
| 196 | } | 224 | } |
| 225 | + else if(strcmp(*argv, "-o") == 0) | ||
| 226 | + { | ||
| 227 | + overlay = 1; | ||
| 228 | + } | ||
| 229 | + else if(strcmp(*argv, "-m") == 0) | ||
| 230 | + { | ||
| 231 | + argv++; argc--; | ||
| 232 | + if(argc < 1) | ||
| 233 | + usage(1); | ||
| 234 | + delay = atol(*argv); | ||
| 235 | + } | ||
| 197 | else if(strcmp(*argv, "-vv") == 0) | 236 | else if(strcmp(*argv, "-vv") == 0) |
| 198 | { | 237 | { |
| 199 | verbose = 2; | 238 | verbose = 2; |
| @@ -209,6 +248,14 @@ void get_options(int argc, char *argv[]) | @@ -209,6 +248,14 @@ void get_options(int argc, char *argv[]) | ||
| 209 | 248 | ||
| 210 | argv++; argc--; | 249 | argv++; argc--; |
| 211 | } | 250 | } |
| 251 | + if(overlay&&!directory) | ||
| 252 | + { | ||
| 253 | + usage(1); | ||
| 254 | + } | ||
| 255 | + if(!delay) | ||
| 256 | + { | ||
| 257 | + usage(1); | ||
| 258 | + } | ||
| 212 | } | 259 | } |
| 213 | 260 | ||
| 214 | boot_message_t boot_message; | 261 | boot_message_t boot_message; |
| @@ -288,10 +335,24 @@ FILE * check_file(char * dir, char *fname) | @@ -288,10 +335,24 @@ FILE * check_file(char * dir, char *fname) | ||
| 288 | // Check directory first then /usr/share/rpiboot | 335 | // Check directory first then /usr/share/rpiboot |
| 289 | if(dir) | 336 | if(dir) |
| 290 | { | 337 | { |
| 291 | - strcpy(path, dir); | ||
| 292 | - strcat(path, "/"); | ||
| 293 | - strcat(path, fname); | ||
| 294 | - fp = fopen(path, "rb"); | 338 | + if(overlay&&(pathname != NULL)) |
| 339 | + { | ||
| 340 | + strcpy(path, dir); | ||
| 341 | + strcat(path, "/"); | ||
| 342 | + strcat(path, pathname); | ||
| 343 | + strcat(path, "/"); | ||
| 344 | + strcat(path, fname); | ||
| 345 | + fp = fopen(path, "rb"); | ||
| 346 | + memset(path, 0, sizeof(path)); | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | + if (fp == NULL) | ||
| 350 | + { | ||
| 351 | + strcpy(path, dir); | ||
| 352 | + strcat(path, "/"); | ||
| 353 | + strcat(path, fname); | ||
| 354 | + fp = fopen(path, "rb"); | ||
| 355 | + } | ||
| 295 | } | 356 | } |
| 296 | 357 | ||
| 297 | if(fp == NULL) | 358 | if(fp == NULL) |
| @@ -514,7 +575,7 @@ int main(int argc, char *argv[]) | @@ -514,7 +575,7 @@ int main(int argc, char *argv[]) | ||
| 514 | 575 | ||
| 515 | if (ret) | 576 | if (ret) |
| 516 | { | 577 | { |
| 517 | - usleep(500); | 578 | + usleep(delay); |
| 518 | } | 579 | } |
| 519 | } | 580 | } |
| 520 | while (ret); | 581 | while (ret); |