fastboot.c revision a032dedefe275b1d5a08b9856dfcfcb12579b4a7
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *  * Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 *  * Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in
12 *    the documentation and/or other materials provided with the
13 *    distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <stdarg.h>
32#include <string.h>
33#include <errno.h>
34#include <fcntl.h>
35#include <unistd.h>
36#include <limits.h>
37#include <ctype.h>
38
39#include <sys/time.h>
40#include <bootimg.h>
41#include <zipfile/zipfile.h>
42
43#include "fastboot.h"
44
45char cur_product[FB_RESPONSE_SZ + 1];
46
47void bootimg_set_cmdline(boot_img_hdr *h, const char *cmdline);
48
49boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size,
50                        void *ramdisk, unsigned ramdisk_size,
51                        void *second, unsigned second_size,
52                        unsigned page_size, unsigned base,
53                        unsigned *bootimg_size);
54
55static usb_handle *usb = 0;
56static const char *serial = 0;
57static const char *product = 0;
58static const char *cmdline = 0;
59static int wipe_data = 0;
60static unsigned short vendor_id = 0;
61static int long_listing = 0;
62
63static unsigned base_addr = 0x10000000;
64
65void die(const char *fmt, ...)
66{
67    va_list ap;
68    va_start(ap, fmt);
69    fprintf(stderr,"error: ");
70    vfprintf(stderr, fmt, ap);
71    fprintf(stderr,"\n");
72    va_end(ap);
73    exit(1);
74}
75
76void get_my_path(char *path);
77
78char *find_item(const char *item, const char *product)
79{
80    char *dir;
81    char *fn;
82    char path[PATH_MAX + 128];
83
84    if(!strcmp(item,"boot")) {
85        fn = "boot.img";
86    } else if(!strcmp(item,"recovery")) {
87        fn = "recovery.img";
88    } else if(!strcmp(item,"system")) {
89        fn = "system.img";
90    } else if(!strcmp(item,"userdata")) {
91        fn = "userdata.img";
92    } else if(!strcmp(item,"cache")) {
93        fn = "cache.img";
94    } else if(!strcmp(item,"info")) {
95        fn = "android-info.txt";
96    } else {
97        fprintf(stderr,"unknown partition '%s'\n", item);
98        return 0;
99    }
100
101    if(product) {
102        get_my_path(path);
103        sprintf(path + strlen(path),
104                "../../../target/product/%s/%s", product, fn);
105        return strdup(path);
106    }
107
108    dir = getenv("ANDROID_PRODUCT_OUT");
109    if((dir == 0) || (dir[0] == 0)) {
110        die("neither -p product specified nor ANDROID_PRODUCT_OUT set");
111        return 0;
112    }
113
114    sprintf(path, "%s/%s", dir, fn);
115    return strdup(path);
116}
117
118#ifdef _WIN32
119void *load_file(const char *fn, unsigned *_sz);
120#else
121void *load_file(const char *fn, unsigned *_sz)
122{
123    char *data;
124    int sz;
125    int fd;
126
127    data = 0;
128    fd = open(fn, O_RDONLY);
129    if(fd < 0) return 0;
130
131    sz = lseek(fd, 0, SEEK_END);
132    if(sz < 0) goto oops;
133
134    if(lseek(fd, 0, SEEK_SET) != 0) goto oops;
135
136    data = (char*) malloc(sz);
137    if(data == 0) goto oops;
138
139    if(read(fd, data, sz) != sz) goto oops;
140    close(fd);
141
142    if(_sz) *_sz = sz;
143    return data;
144
145oops:
146    close(fd);
147    if(data != 0) free(data);
148    return 0;
149}
150#endif
151
152int match_fastboot(usb_ifc_info *info)
153{
154    return match_fastboot_with_serial(info, serial);
155}
156
157int match_fastboot_with_serial(usb_ifc_info *info, const char *local_serial)
158{
159    if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
160       (info->dev_vendor != 0x18d1) &&  // Google
161       (info->dev_vendor != 0x8087) &&  // Intel
162       (info->dev_vendor != 0x0451) &&
163       (info->dev_vendor != 0x0502) &&
164       (info->dev_vendor != 0x0fce) &&  // Sony Ericsson
165       (info->dev_vendor != 0x05c6) &&  // Qualcomm
166       (info->dev_vendor != 0x22b8) &&  // Motorola
167       (info->dev_vendor != 0x0955) &&  // Nvidia
168       (info->dev_vendor != 0x413c) &&  // DELL
169       (info->dev_vendor != 0x2314) &&  // INQ Mobile
170       (info->dev_vendor != 0x0b05) &&  // Asus
171       (info->dev_vendor != 0x0bb4))    // HTC
172            return -1;
173    if(info->ifc_class != 0xff) return -1;
174    if(info->ifc_subclass != 0x42) return -1;
175    if(info->ifc_protocol != 0x03) return -1;
176    // require matching serial number or device path if requested
177    // at the command line with the -s option.
178    if (local_serial && (strcmp(local_serial, info->serial_number) != 0 &&
179                   strcmp(local_serial, info->device_path) != 0)) return -1;
180    return 0;
181}
182
183int list_devices_callback(usb_ifc_info *info)
184{
185    if (match_fastboot_with_serial(info, NULL) == 0) {
186        char* serial = info->serial_number;
187        if (!info->writable) {
188            serial = "no permissions"; // like "adb devices"
189        }
190        if (!serial[0]) {
191            serial = "????????????";
192        }
193        // output compatible with "adb devices"
194        if (!long_listing) {
195            printf("%s\tfastboot\n", serial);
196        } else if (!info->device_path) {
197            printf("%-22s fastboot\n", serial);
198        } else {
199            printf("%-22s fastboot %s\n", serial, info->device_path);
200        }
201    }
202
203    return -1;
204}
205
206usb_handle *open_device(void)
207{
208    static usb_handle *usb = 0;
209    int announce = 1;
210
211    if(usb) return usb;
212
213    for(;;) {
214        usb = usb_open(match_fastboot);
215        if(usb) return usb;
216        if(announce) {
217            announce = 0;
218            fprintf(stderr,"< waiting for device >\n");
219        }
220        sleep(1);
221    }
222}
223
224void list_devices(void) {
225    // We don't actually open a USB device here,
226    // just getting our callback called so we can
227    // list all the connected devices.
228    usb_open(list_devices_callback);
229}
230
231void usage(void)
232{
233    fprintf(stderr,
234/*           1234567890123456789012345678901234567890123456789012345678901234567890123456 */
235            "usage: fastboot [ <option> ] <command>\n"
236            "\n"
237            "commands:\n"
238            "  update <filename>                        reflash device from update.zip\n"
239            "  flashall                                 flash boot + recovery + system\n"
240            "  flash <partition> [ <filename> ]         write a file to a flash partition\n"
241            "  erase <partition>                        erase a flash partition\n"
242            "  format <partition>                       format a flash partition \n"
243            "  getvar <variable>                        display a bootloader variable\n"
244            "  boot <kernel> [ <ramdisk> ]              download and boot kernel\n"
245            "  flash:raw boot <kernel> [ <ramdisk> ]    create bootimage and flash it\n"
246            "  devices                                  list all connected devices\n"
247            "  continue                                 continue with autoboot\n"
248            "  reboot                                   reboot device normally\n"
249            "  reboot-bootloader                        reboot device into bootloader\n"
250            "  help                                     show this help message\n"
251            "\n"
252            "options:\n"
253            "  -w                                       erase userdata and cache\n"
254            "  -s <specific device>                     specify device serial number\n"
255            "                                           or path to device port\n"
256            "  -l                                       with \"devices\", lists device paths\n"
257            "  -p <product>                             specify product name\n"
258            "  -c <cmdline>                             override kernel commandline\n"
259            "  -i <vendor id>                           specify a custom USB vendor id\n"
260            "  -b <base_addr>                           specify a custom kernel base address\n"
261            "  -n <page size>                           specify the nand page size. default: 2048\n"
262        );
263}
264
265void *load_bootable_image(unsigned page_size, const char *kernel, const char *ramdisk,
266                          unsigned *sz, const char *cmdline)
267{
268    void *kdata = 0, *rdata = 0;
269    unsigned ksize = 0, rsize = 0;
270    void *bdata;
271    unsigned bsize;
272
273    if(kernel == 0) {
274        fprintf(stderr, "no image specified\n");
275        return 0;
276    }
277
278    kdata = load_file(kernel, &ksize);
279    if(kdata == 0) {
280        fprintf(stderr, "cannot load '%s'\n", kernel);
281        return 0;
282    }
283
284        /* is this actually a boot image? */
285    if(!memcmp(kdata, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
286        if(cmdline) bootimg_set_cmdline((boot_img_hdr*) kdata, cmdline);
287
288        if(ramdisk) {
289            fprintf(stderr, "cannot boot a boot.img *and* ramdisk\n");
290            return 0;
291        }
292
293        *sz = ksize;
294        return kdata;
295    }
296
297    if(ramdisk) {
298        rdata = load_file(ramdisk, &rsize);
299        if(rdata == 0) {
300            fprintf(stderr,"cannot load '%s'\n", ramdisk);
301            return  0;
302        }
303    }
304
305    fprintf(stderr,"creating boot image...\n");
306    bdata = mkbootimg(kdata, ksize, rdata, rsize, 0, 0, page_size, base_addr, &bsize);
307    if(bdata == 0) {
308        fprintf(stderr,"failed to create boot.img\n");
309        return 0;
310    }
311    if(cmdline) bootimg_set_cmdline((boot_img_hdr*) bdata, cmdline);
312    fprintf(stderr,"creating boot image - %d bytes\n", bsize);
313    *sz = bsize;
314
315    return bdata;
316}
317
318void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
319{
320    void *data;
321    zipentry_t entry;
322    unsigned datasz;
323
324    entry = lookup_zipentry(zip, name);
325    if (entry == NULL) {
326        fprintf(stderr, "archive does not contain '%s'\n", name);
327        return 0;
328    }
329
330    *sz = get_zipentry_size(entry);
331
332    datasz = *sz * 1.001;
333    data = malloc(datasz);
334
335    if(data == 0) {
336        fprintf(stderr, "failed to allocate %d bytes\n", *sz);
337        return 0;
338    }
339
340    if (decompress_zipentry(entry, data, datasz)) {
341        fprintf(stderr, "failed to unzip '%s' from archive\n", name);
342        free(data);
343        return 0;
344    }
345
346    return data;
347}
348
349static char *strip(char *s)
350{
351    int n;
352    while(*s && isspace(*s)) s++;
353    n = strlen(s);
354    while(n-- > 0) {
355        if(!isspace(s[n])) break;
356        s[n] = 0;
357    }
358    return s;
359}
360
361#define MAX_OPTIONS 32
362static int setup_requirement_line(char *name)
363{
364    char *val[MAX_OPTIONS];
365    const char **out;
366    char *prod = NULL;
367    unsigned n, count;
368    char *x;
369    int invert = 0;
370
371    if (!strncmp(name, "reject ", 7)) {
372        name += 7;
373        invert = 1;
374    } else if (!strncmp(name, "require ", 8)) {
375        name += 8;
376        invert = 0;
377    } else if (!strncmp(name, "require-for-product:", 20)) {
378        // Get the product and point name past it
379        prod = name + 20;
380        name = strchr(name, ' ');
381        if (!name) return -1;
382        *name = 0;
383        name += 1;
384        invert = 0;
385    }
386
387    x = strchr(name, '=');
388    if (x == 0) return 0;
389    *x = 0;
390    val[0] = x + 1;
391
392    for(count = 1; count < MAX_OPTIONS; count++) {
393        x = strchr(val[count - 1],'|');
394        if (x == 0) break;
395        *x = 0;
396        val[count] = x + 1;
397    }
398
399    name = strip(name);
400    for(n = 0; n < count; n++) val[n] = strip(val[n]);
401
402    name = strip(name);
403    if (name == 0) return -1;
404
405        /* work around an unfortunate name mismatch */
406    if (!strcmp(name,"board")) name = "product";
407
408    out = malloc(sizeof(char*) * count);
409    if (out == 0) return -1;
410
411    for(n = 0; n < count; n++) {
412        out[n] = strdup(strip(val[n]));
413        if (out[n] == 0) return -1;
414    }
415
416    fb_queue_require(prod, name, invert, n, out);
417    return 0;
418}
419
420static void setup_requirements(char *data, unsigned sz)
421{
422    char *s;
423
424    s = data;
425    while (sz-- > 0) {
426        if(*s == '\n') {
427            *s++ = 0;
428            if (setup_requirement_line(data)) {
429                die("out of memory");
430            }
431            data = s;
432        } else {
433            s++;
434        }
435    }
436}
437
438void queue_info_dump(void)
439{
440    fb_queue_notice("--------------------------------------------");
441    fb_queue_display("version-bootloader", "Bootloader Version...");
442    fb_queue_display("version-baseband",   "Baseband Version.....");
443    fb_queue_display("serialno",           "Serial Number........");
444    fb_queue_notice("--------------------------------------------");
445}
446
447void do_update_signature(zipfile_t zip, char *fn)
448{
449    void *data;
450    unsigned sz;
451    data = unzip_file(zip, fn, &sz);
452    if (data == 0) return;
453    fb_queue_download("signature", data, sz);
454    fb_queue_command("signature", "installing signature");
455}
456
457void do_update(char *fn)
458{
459    void *zdata;
460    unsigned zsize;
461    void *data;
462    unsigned sz;
463    zipfile_t zip;
464
465    queue_info_dump();
466
467    fb_queue_query_save("product", cur_product, sizeof(cur_product));
468
469    zdata = load_file(fn, &zsize);
470    if (zdata == 0) die("failed to load '%s'", fn);
471
472    zip = init_zipfile(zdata, zsize);
473    if(zip == 0) die("failed to access zipdata in '%s'");
474
475    data = unzip_file(zip, "android-info.txt", &sz);
476    if (data == 0) {
477        char *tmp;
478            /* fallback for older zipfiles */
479        data = unzip_file(zip, "android-product.txt", &sz);
480        if ((data == 0) || (sz < 1)) {
481            die("update package has no android-info.txt or android-product.txt");
482        }
483        tmp = malloc(sz + 128);
484        if (tmp == 0) die("out of memory");
485        sprintf(tmp,"board=%sversion-baseband=0.66.04.19\n",(char*)data);
486        data = tmp;
487        sz = strlen(tmp);
488    }
489
490    setup_requirements(data, sz);
491
492    data = unzip_file(zip, "boot.img", &sz);
493    if (data == 0) die("update package missing boot.img");
494    do_update_signature(zip, "boot.sig");
495    fb_queue_flash("boot", data, sz);
496
497    data = unzip_file(zip, "recovery.img", &sz);
498    if (data != 0) {
499        do_update_signature(zip, "recovery.sig");
500        fb_queue_flash("recovery", data, sz);
501    }
502
503    data = unzip_file(zip, "system.img", &sz);
504    if (data == 0) die("update package missing system.img");
505    do_update_signature(zip, "system.sig");
506    fb_queue_flash("system", data, sz);
507}
508
509void do_send_signature(char *fn)
510{
511    void *data;
512    unsigned sz;
513    char *xtn;
514
515    xtn = strrchr(fn, '.');
516    if (!xtn) return;
517    if (strcmp(xtn, ".img")) return;
518
519    strcpy(xtn,".sig");
520    data = load_file(fn, &sz);
521    strcpy(xtn,".img");
522    if (data == 0) return;
523    fb_queue_download("signature", data, sz);
524    fb_queue_command("signature", "installing signature");
525}
526
527void do_flashall(void)
528{
529    char *fname;
530    void *data;
531    unsigned sz;
532
533    queue_info_dump();
534
535    fb_queue_query_save("product", cur_product, sizeof(cur_product));
536
537    fname = find_item("info", product);
538    if (fname == 0) die("cannot find android-info.txt");
539    data = load_file(fname, &sz);
540    if (data == 0) die("could not load android-info.txt");
541    setup_requirements(data, sz);
542
543    fname = find_item("boot", product);
544    data = load_file(fname, &sz);
545    if (data == 0) die("could not load boot.img");
546    do_send_signature(fname);
547    fb_queue_flash("boot", data, sz);
548
549    fname = find_item("recovery", product);
550    data = load_file(fname, &sz);
551    if (data != 0) {
552        do_send_signature(fname);
553        fb_queue_flash("recovery", data, sz);
554    }
555
556    fname = find_item("system", product);
557    data = load_file(fname, &sz);
558    if (data == 0) die("could not load system.img");
559    do_send_signature(fname);
560    fb_queue_flash("system", data, sz);
561}
562
563#define skip(n) do { argc -= (n); argv += (n); } while (0)
564#define require(n) do { if (argc < (n)) {usage(); exit(1);}} while (0)
565
566int do_oem_command(int argc, char **argv)
567{
568    int i;
569    char command[256];
570    if (argc <= 1) return 0;
571
572    command[0] = 0;
573    while(1) {
574        strcat(command,*argv);
575        skip(1);
576        if(argc == 0) break;
577        strcat(command," ");
578    }
579
580    fb_queue_command(command,"");
581    return 0;
582}
583
584int main(int argc, char **argv)
585{
586    int wants_wipe = 0;
587    int wants_reboot = 0;
588    int wants_reboot_bootloader = 0;
589    int wants_device_list = 0;
590    void *data;
591    unsigned sz;
592    unsigned page_size = 2048;
593    int status;
594
595    skip(1);
596    if (argc == 0) {
597        usage();
598        return 1;
599    }
600
601    if (!strcmp(*argv, "help")) {
602        usage();
603        return 0;
604    }
605
606
607    serial = getenv("ANDROID_SERIAL");
608
609    while (argc > 0) {
610        if(!strcmp(*argv, "-w")) {
611            wants_wipe = 1;
612            skip(1);
613        } else if(!strcmp(*argv, "-b")) {
614            require(2);
615            base_addr = strtoul(argv[1], 0, 16);
616            skip(2);
617        } else if(!strcmp(*argv, "-n")) {
618            require(2);
619            page_size = (unsigned)strtoul(argv[1], NULL, 0);
620            if (!page_size) die("invalid page size");
621            skip(2);
622        } else if(!strcmp(*argv, "-s")) {
623            require(2);
624            serial = argv[1];
625            skip(2);
626        } else if(!strcmp(*argv, "-l")) {
627            long_listing = 1;
628            skip(1);
629        } else if(!strcmp(*argv, "-p")) {
630            require(2);
631            product = argv[1];
632            skip(2);
633        } else if(!strcmp(*argv, "-c")) {
634            require(2);
635            cmdline = argv[1];
636            skip(2);
637        } else if(!strcmp(*argv, "-i")) {
638            char *endptr = NULL;
639            unsigned long val;
640
641            require(2);
642            val = strtoul(argv[1], &endptr, 0);
643            if (!endptr || *endptr != '\0' || (val & ~0xffff))
644                die("invalid vendor id '%s'", argv[1]);
645            vendor_id = (unsigned short)val;
646            skip(2);
647        } else if (!strcmp(*argv, "devices")) {
648            skip(1);
649            wants_device_list = 1;
650        } else if(!strcmp(*argv, "getvar")) {
651            require(2);
652            fb_queue_display(argv[1], argv[1]);
653            skip(2);
654        } else if(!strcmp(*argv, "erase")) {
655            require(2);
656            fb_queue_erase(argv[1]);
657            skip(2);
658        } else if(!strcmp(*argv, "format")) {
659            require(2);
660            fb_queue_format(argv[1], 0);
661            skip(2);
662        } else if(!strcmp(*argv, "signature")) {
663            require(2);
664            data = load_file(argv[1], &sz);
665            if (data == 0) die("could not load '%s'", argv[1]);
666            if (sz != 256) die("signature must be 256 bytes");
667            fb_queue_download("signature", data, sz);
668            fb_queue_command("signature", "installing signature");
669            skip(2);
670        } else if(!strcmp(*argv, "reboot")) {
671            wants_reboot = 1;
672            skip(1);
673        } else if(!strcmp(*argv, "reboot-bootloader")) {
674            wants_reboot_bootloader = 1;
675            skip(1);
676        } else if (!strcmp(*argv, "continue")) {
677            fb_queue_command("continue", "resuming boot");
678            skip(1);
679        } else if(!strcmp(*argv, "boot")) {
680            char *kname = 0;
681            char *rname = 0;
682            skip(1);
683            if (argc > 0) {
684                kname = argv[0];
685                skip(1);
686            }
687            if (argc > 0) {
688                rname = argv[0];
689                skip(1);
690            }
691            data = load_bootable_image(page_size, kname, rname, &sz, cmdline);
692            if (data == 0) return 1;
693            fb_queue_download("boot.img", data, sz);
694            fb_queue_command("boot", "booting");
695        } else if(!strcmp(*argv, "flash")) {
696            char *pname = argv[1];
697            char *fname = 0;
698            require(2);
699            if (argc > 2) {
700                fname = argv[2];
701                skip(3);
702            } else {
703                fname = find_item(pname, product);
704                skip(2);
705            }
706            if (fname == 0) die("cannot determine image filename for '%s'", pname);
707            data = load_file(fname, &sz);
708            if (data == 0) die("cannot load '%s'\n", fname);
709            fb_queue_flash(pname, data, sz);
710        } else if(!strcmp(*argv, "flash:raw")) {
711            char *pname = argv[1];
712            char *kname = argv[2];
713            char *rname = 0;
714            require(3);
715            if(argc > 3) {
716                rname = argv[3];
717                skip(4);
718            } else {
719                skip(3);
720            }
721            data = load_bootable_image(page_size, kname, rname, &sz, cmdline);
722            if (data == 0) die("cannot load bootable image");
723            fb_queue_flash(pname, data, sz);
724        } else if(!strcmp(*argv, "flashall")) {
725            skip(1);
726            do_flashall();
727            wants_reboot = 1;
728        } else if(!strcmp(*argv, "update")) {
729            if (argc > 1) {
730                do_update(argv[1]);
731                skip(2);
732            } else {
733                do_update("update.zip");
734                skip(1);
735            }
736            wants_reboot = 1;
737        } else if(!strcmp(*argv, "oem")) {
738            argc = do_oem_command(argc, argv);
739        } else {
740            usage();
741            return 1;
742        }
743    }
744
745    if (wants_device_list)
746        list_devices();
747
748    if (wants_wipe) {
749        fb_queue_erase("userdata");
750        fb_queue_format("userdata", 1);
751        fb_queue_erase("cache");
752        fb_queue_format("cache", 1);
753    }
754    if (wants_reboot) {
755        fb_queue_reboot();
756    } else if (wants_reboot_bootloader) {
757        fb_queue_command("reboot-bootloader", "rebooting into bootloader");
758    }
759
760    if (fb_queue_is_empty())
761        return 0;
762
763    usb = open_device();
764
765    status = fb_execute_queue(usb);
766    return (status) ? 1 : 0;
767}
768