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 {
if (dev) {
+ if (!dev->bootloader)
+ hmcfgusb_enter_bootloader(dev);
hmcfgusb_close(dev);
}
sleep(1);
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;
}