+ if (filename[0] != '\0') {
+ struct stat st;
+
+ image_fd = open(filename, O_RDONLY);
+ if (image_fd < 0) {
+ perror("open");
+ exit_code = EXIT_FAILURE;
+ goto out;
+ }
+ if (fstat(image_fd, &st) < 0) {
+ perror("fstat");
+ exit_code = EXIT_FAILURE;
+ goto out_close_image_fd;
+ }
+ size = st.st_size;
+
+ image = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, image_fd, 0);
+ if (image == NULL) {
+ perror("mmap");
+ exit_code = EXIT_FAILURE;
+ goto out_close_image_fd;
+ }
+ }
+
+ libusb_init(NULL);
+ libusb_set_debug(NULL, 3);
+
+ dev = libusb_open_device_with_vid_pid(NULL,
+ AM7x01_VENDOR_ID,
+ AM7x01_PRODUCT_ID);
+ if (dev == NULL) {
+ errno = ENODEV;
+ perror("libusb_open_device_with_vid_pid");
+ exit_code = EXIT_FAILURE;
+ goto out_libusb_exit;
+ }
+
+ libusb_set_configuration(dev, 1);
+ libusb_claim_interface(dev, 0);
+