if (!dev->bootloader) {
fprintf(stderr, "\nHM-CFG-USB not in bootloader mode, entering bootloader.\n");
- hmcfgusb_enter_bootloader(dev);
fprintf(stderr, "\nWaiting for device to reappear...\n");
do {
- sleep(2);
- } while ((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL);
-
- if (!dev->bootloader) {
- fprintf(stderr, "Can't enter bootloader, giving up!\n");
- exit(EXIT_FAILURE);
- }
+ 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("Waiting for ack...\n");
do {
errno = 0;
- pfd = hmcfgusb_poll(dev, 1);
+ pfd = hmcfgusb_poll(dev, 1000);
if ((pfd < 0) && errno) {
if (errno != ETIMEDOUT) {
perror("\n\nhmcfgusb_poll");
firmware_free(fw);
hmcfgusb_close(dev);
+ hmcfgusb_exit();
return EXIT_SUCCESS;
}