/* * Copyright (C) 2008 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include "fastboot.h" //#include "libusb.h" static usb_dev_handle *usb = 0; static struct usb_device *dev = NULL; //added static const char *serial = 0; static unsigned short vendor_id = 0; void die(const char *fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr,"error: "); vfprintf(stderr, fmt, ap); fprintf(stderr,"\n"); va_end(ap); exit(1); } void get_my_path(char *path); void *load_file(char *fn, unsigned *_sz) { char *data; int i = 0; unsigned sz, ret; long int io; HFILE *fd; data = 0; fd = CreateFile(fn, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (fd == INVALID_HANDLE_VALUE) return 0; sz = GetFileSize(fd, NULL); data = (char*) malloc(sz); if (data == NULL) goto oops; ret = ReadFile(fd, data, sz, &io, NULL); if (sz != io) goto oops; if (ret == 0) goto oops; //according to MSDN if (_sz == NULL) goto oops; *_sz = sz; CloseHandle(fd); return data; oops: CloseHandle(fd); if(data != 0) free(data); return 0; } int match_fastboot(usb_ifc_info *info) { if(!(vendor_id && (info->dev_vendor == vendor_id)) && (info->dev_vendor != 0x1949)) // Lab126 return -1; if(info->ifc_class != 0xff) return -1; if(info->ifc_subclass != 0x42) return -1; if(info->ifc_protocol != 0x03) return -1; // require matching serial number if a serial number is specified // at the command line with the -s option. if (serial && strcmp(serial, info->serial_number) != 0) return -1; return 0; } int list_devices_callback(usb_ifc_info *info) { if (match_fastboot(info) == 0) { char* serial = info->serial_number; if (!info->writable) { serial = "no permissions"; // like "adb devices" } if (!serial[0]) { serial = "????????????"; } // output compatible with "adb devices" printf("%s\tfastboot\n", serial); } return -1; } void open_device() { int announce = 1; for(;;) { usb = (usb_dev_handle *) usb_open2(match_fastboot, &dev); if (usb != NULL) { return; //if(usb) return usb; } if(announce) { announce = 0; fprintf(stderr,"< waiting for device >\n"); } sleep(1); } } /* HAVEN'T BEEN USED (ALSO DON'T USE) */ /* void list_devices(void) { // We don't actually open a USB device here, // just getting our callback called so we can // list all the connected devices. usb_open(list_devices_callback); } */ void usage(void) { fprintf(stderr, /* 1234567890123456789012345678901234567890123456789012345678901234567890123456 */ "usage: fastboot [