- fd = open("hmusbif.enc", O_RDONLY);
- if (fd < 0) {
- perror("Can't open hmusbif.enc");
- exit(EXIT_FAILURE);
+ if (!dev->bootloader) {
+ fprintf(stderr, "\nHM-CFG-USB not in bootloader mode, entering bootloader.\n");
+ fprintf(stderr, "\nWaiting for device to reappear...\n");
+
+ do {
+ if (dev) {
+ if (!dev->bootloader)
+ hmcfgusb_enter_bootloader(dev);
+ hmcfgusb_close(dev);
+ }
+ sleep(1);
+ } while (((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL) || (!dev->bootloader));
+ }
+
+ printf("\nHM-CFG-USB opened.\n\n");
+
+
+ printf("Flashing %d blocks", fw->fw_blocks);
+ if (debug) {
+ printf("\n");
+ } else {
+ printf(": %c", twiddlie[0]);
+ fflush(stdout);