70
70
static const char *cmdline = 0;
71
71
static int wipe_data = 0;
72
72
static unsigned short vendor_id = 0;
73
static int long_listing = 0;
73
74
static int64_t sparse_limit = -1;
74
75
static int64_t target_sparse_limit = -1;
180
183
if(data != 0) free(data);
185
189
int match_fastboot(usb_ifc_info *info)
191
return match_fastboot_with_serial(info, serial);
194
int match_fastboot_with_serial(usb_ifc_info *info, const char *local_serial)
187
196
if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
188
197
(info->dev_vendor != 0x18d1) && // Google
189
198
(info->dev_vendor != 0x8087) && // Intel
201
210
if(info->ifc_class != 0xff) return -1;
202
211
if(info->ifc_subclass != 0x42) return -1;
203
212
if(info->ifc_protocol != 0x03) return -1;
204
// require matching serial number if a serial number is specified
213
// require matching serial number or device path if requested
205
214
// at the command line with the -s option.
206
if (serial && strcmp(serial, info->serial_number) != 0) return -1;
215
if (local_serial && (strcmp(local_serial, info->serial_number) != 0 &&
216
strcmp(local_serial, info->device_path) != 0)) return -1;
210
220
int list_devices_callback(usb_ifc_info *info)
212
if (match_fastboot(info) == 0) {
222
if (match_fastboot_with_serial(info, NULL) == 0) {
213
223
char* serial = info->serial_number;
214
224
if (!info->writable) {
215
225
serial = "no permissions"; // like "adb devices"
218
228
serial = "????????????";
220
230
// output compatible with "adb devices"
221
printf("%s\tfastboot\n", serial);
232
printf("%s\tfastboot\n", serial);
233
} else if (!info->device_path) {
234
printf("%-22s fastboot\n", serial);
236
printf("%-22s fastboot %s\n", serial, info->device_path);
271
287
" help show this help message\n"
274
" -w erase userdata and cache\n"
275
" -s <serial number> specify device serial number\n"
290
" -w erase userdata and cache (and format\n"
291
" if supported by partition type)\n"
292
" -u do not first erase partition before\n"
294
" -s <specific device> specify device serial number\n"
295
" or path to device port\n"
296
" -l with \"devices\", lists device paths\n"
276
297
" -p <product> specify product name\n"
277
298
" -c <cmdline> override kernel commandline\n"
278
299
" -i <vendor id> specify a custom USB vendor id\n"
299
320
kdata = load_file(kernel, &ksize);
301
fprintf(stderr, "cannot load '%s'\n", kernel);
322
fprintf(stderr, "cannot load '%s': %s\n", kernel, strerror(errno));
319
340
rdata = load_file(ramdisk, &rsize);
321
fprintf(stderr,"cannot load '%s'\n", ramdisk);
342
fprintf(stderr,"cannot load '%s': %s\n", ramdisk, strerror(errno));
568
/* Until we get lazy inode table init working in make_ext4fs, we need to
569
* erase partitions of type ext4 before flashing a filesystem so no stale
570
* inodes are left lying around. Otherwise, e2fsck gets very upset.
572
static int needs_erase(const char *part)
574
/* The function fb_format_supported() currently returns the value
575
* we want, so just call it.
577
return fb_format_supported(usb, part);
547
580
void do_flash(usb_handle *usb, const char *pname, const char *fname)
566
599
data = load_file(fname, &sz);
567
if (data == 0) die("cannot load '%s'\n", fname);
600
if (data == 0) die("cannot load '%s': %s\n", fname, strerror(errno));
568
601
fb_queue_flash(pname, data, sz);
592
625
fb_queue_query_save("product", cur_product, sizeof(cur_product));
594
627
zdata = load_file(fn, &zsize);
595
if (zdata == 0) die("failed to load '%s'", fn);
628
if (zdata == 0) die("failed to load '%s': %s", fn, strerror(errno));
597
630
zip = init_zipfile(zdata, zsize);
598
631
if(zip == 0) die("failed to access zipdata in '%s'");
617
650
data = unzip_file(zip, "boot.img", &sz);
618
651
if (data == 0) die("update package missing boot.img");
619
652
do_update_signature(zip, "boot.sig");
653
if (erase_first && needs_erase("boot")) {
654
fb_queue_erase("boot");
620
656
fb_queue_flash("boot", data, sz);
622
658
data = unzip_file(zip, "recovery.img", &sz);
624
660
do_update_signature(zip, "recovery.sig");
661
if (erase_first && needs_erase("recovery")) {
662
fb_queue_erase("recovery");
625
664
fb_queue_flash("recovery", data, sz);
628
667
data = unzip_file(zip, "system.img", &sz);
629
668
if (data == 0) die("update package missing system.img");
630
669
do_update_signature(zip, "system.sig");
670
if (erase_first && needs_erase("system")) {
671
fb_queue_erase("system");
631
673
fb_queue_flash("system", data, sz);
662
704
fname = find_item("info", product);
663
705
if (fname == 0) die("cannot find android-info.txt");
664
706
data = load_file(fname, &sz);
665
if (data == 0) die("could not load android-info.txt");
707
if (data == 0) die("could not load android-info.txt: %s", strerror(errno));
666
708
setup_requirements(data, sz);
668
710
fname = find_item("boot", product);
669
711
data = load_file(fname, &sz);
670
if (data == 0) die("could not load boot.img");
712
if (data == 0) die("could not load boot.img: %s", strerror(errno));
671
713
do_send_signature(fname);
714
if (erase_first && needs_erase("boot")) {
715
fb_queue_erase("boot");
672
717
fb_queue_flash("boot", data, sz);
674
719
fname = find_item("recovery", product);
675
720
data = load_file(fname, &sz);
677
722
do_send_signature(fname);
723
if (erase_first && needs_erase("recovery")) {
724
fb_queue_erase("recovery");
678
726
fb_queue_flash("recovery", data, sz);
681
729
fname = find_item("system", product);
682
730
data = load_file(fname, &sz);
683
if (data == 0) die("could not load system.img");
731
if (data == 0) die("could not load system.img: %s", strerror(errno));
684
732
do_send_signature(fname);
733
if (erase_first && needs_erase("system")) {
734
fb_queue_erase("system");
685
736
fb_queue_flash("system", data, sz);
764
816
serial = getenv("ANDROID_SERIAL");
767
c = getopt_long(argc, argv, "wb:n:s:S:p:c:i:m:h", &longopts, NULL);
819
c = getopt_long(argc, argv, "wub:n:s:S:lp:c:i:m:h", &longopts, NULL);
839
902
} else if(!strcmp(*argv, "erase")) {
905
if (fb_format_supported(usb, argv[1])) {
906
fprintf(stderr, "******** Did you mean to fastboot format this partition?\n");
841
909
fb_queue_erase(argv[1]);
843
911
} else if(!strcmp(*argv, "format")) {
913
if (erase_first && needs_erase(argv[1])) {
914
fb_queue_erase(argv[1]);
845
916
fb_queue_format(argv[1], 0);
847
918
} else if(!strcmp(*argv, "signature")) {
849
920
data = load_file(argv[1], &sz);
850
if (data == 0) die("could not load '%s'", argv[1]);
921
if (data == 0) die("could not load '%s': %s", argv[1], strerror(errno));
851
922
if (sz != 256) die("signature must be 256 bytes");
852
923
fb_queue_download("signature", data, sz);
853
924
fb_queue_command("signature", "installing signature");
891
962
if (fname == 0) die("cannot determine image filename for '%s'", pname);
963
if (erase_first && needs_erase(pname)) {
964
fb_queue_erase(pname);
892
966
do_flash(usb, pname, fname);
893
967
} else if(!strcmp(*argv, "flash:raw")) {
894
968
char *pname = argv[1];
906
980
fb_queue_flash(pname, data, sz);
907
981
} else if(!strcmp(*argv, "flashall")) {
983
do_flashall(erase_first);
910
984
wants_reboot = 1;
911
985
} else if(!strcmp(*argv, "update")) {
987
do_update(argv[1], erase_first);
916
do_update("update.zip");
990
do_update("update.zip", erase_first);
919
993
wants_reboot = 1;
920
994
} else if(!strcmp(*argv, "oem")) {
921
995
argc = do_oem_command(argc, argv);
922
} else if (!strcmp(*argv, "help")) {