void do_flashall(usb_handle *usb, int erase_first)
{
    queue_info_dump();

    fb_queue_query_save("product", cur_product, sizeof(cur_product));

    char* fname = find_item("info", product);
    if (fname == 0) die("cannot find android-info.txt");

    unsigned sz;
    void* data = load_file(fname, &sz);
    if (data == 0) die("could not load android-info.txt: %s", strerror(errno));

    setup_requirements(reinterpret_cast<char*>(data), sz);

    for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
        fname = find_item(images[i].part_name, product);
        fastboot_buffer buf;
        if (load_buf(usb, fname, &buf)) {
            if (images[i].is_optional)
                continue;
            die("could not load %s\n", images[i].img_name);
        }
        do_send_signature(fname);
        if (erase_first && needs_erase(usb, images[i].part_name)) {
            fb_queue_erase(images[i].part_name);
        }
        flash_buf(images[i].part_name, &buf);
    }
}
示例#2
0
void do_flashall(void)
{
    char *fname;
    void *data;
    unsigned sz;

    queue_info_dump();

    fb_queue_query_save("product", cur_product, sizeof(cur_product));

    fname = find_item("info", product);
    if (fname == 0) die("cannot find android-info.txt");
    data = load_file(fname, &sz);
    if (data == 0) die("could not load android-info.txt");
    setup_requirements(data, sz);

    fname = find_item("boot", product);
    data = load_file(fname, &sz);
    if (data == 0) die("could not load boot.img");
    do_send_signature(fname);
    fb_queue_flash("boot", data, sz);

    fname = find_item("recovery", product);
    data = load_file(fname, &sz);
    if (data != 0) {
        do_send_signature(fname);
        fb_queue_flash("recovery", data, sz);
    }

    fname = find_item("system", product);
    data = load_file(fname, &sz);
    if (data == 0) die("could not load system.img");
    do_send_signature(fname);
    fb_queue_flash("system", data, sz);
}
void do_update(char *fn, int erase_first)
{
    void *zdata;
    unsigned zsize;
    void *data;
    unsigned sz;
    zipfile_t zip;

    queue_info_dump();

    fb_queue_query_save("product", cur_product, sizeof(cur_product));

    zdata = load_file(fn, &zsize);
    if (zdata == 0) die("failed to load '%s': %s", fn, strerror(errno));

    zip = init_zipfile(zdata, zsize);
    if(zip == 0) die("failed to access zipdata in '%s'");

    data = unzip_file(zip, "android-info.txt", &sz);
    if (data == 0) {
        char *tmp;
            /* fallback for older zipfiles */
        data = unzip_file(zip, "android-product.txt", &sz);
        if ((data == 0) || (sz < 1)) {
            die("update package has no android-info.txt or android-product.txt");
        }
        tmp = malloc(sz + 128);
        if (tmp == 0) die("out of memory");
        sprintf(tmp,"board=%sversion-baseband=0.66.04.19\n",(char*)data);
        data = tmp;
        sz = strlen(tmp);
    }

    setup_requirements(data, sz);

    data = unzip_file(zip, "boot.img", &sz);
    if (data == 0) die("update package missing boot.img");
    do_update_signature(zip, "boot.sig");
    if (erase_first && needs_erase("boot")) {
        fb_queue_erase("boot");
    }
    fb_queue_flash("boot", data, sz);

    data = unzip_file(zip, "recovery.img", &sz);
    if (data != 0) {
        do_update_signature(zip, "recovery.sig");
        if (erase_first && needs_erase("recovery")) {
            fb_queue_erase("recovery");
        }
        fb_queue_flash("recovery", data, sz);
    }

    data = unzip_file(zip, "system.img", &sz);
    if (data == 0) die("update package missing system.img");
    do_update_signature(zip, "system.sig");
    if (erase_first && needs_erase("system")) {
        fb_queue_erase("system");
    }
    fb_queue_flash("system", data, sz);
}
void do_update(usb_handle *usb, char *fn, int erase_first)
{
    void *zdata;
    unsigned zsize;
    void *data;
    unsigned sz;
    zipfile_t zip;
    int fd;
    int rc;
    struct fastboot_buffer buf;
    size_t i;

    queue_info_dump();

    fb_queue_query_save("product", cur_product, sizeof(cur_product));

    zdata = load_file(fn, &zsize);
    if (zdata == 0) die("failed to load '%s': %s", fn, strerror(errno));

    zip = init_zipfile(zdata, zsize);
    if(zip == 0) die("failed to access zipdata in '%s'");

    data = unzip_file(zip, "android-info.txt", &sz);
    if (data == 0) {
        char *tmp;
        /* fallback for older zipfiles */
        data = unzip_file(zip, "android-product.txt", &sz);
        if ((data == 0) || (sz < 1)) {
            die("update package has no android-info.txt or android-product.txt");
        }
        tmp = malloc(sz + 128);
        if (tmp == 0) die("out of memory");
        sprintf(tmp,"board=%sversion-baseband=0.66.04.19\n",(char*)data);
        data = tmp;
        sz = strlen(tmp);
    }

    setup_requirements(data, sz);

    for (i = 0; i < ARRAY_SIZE(images); i++) {
        fd = unzip_to_file(zip, images[i].img_name);
        if (fd < 0) {
            if (images[i].is_optional)
                continue;
            die("update package missing %s", images[i].img_name);
        }
        rc = load_buf_fd(usb, fd, &buf);
        if (rc) die("cannot load %s from flash", images[i].img_name);
        do_update_signature(zip, images[i].sig_name);
        if (erase_first && needs_erase(images[i].part_name)) {
            fb_queue_erase(images[i].part_name);
        }
        flash_buf(images[i].part_name, &buf);
        /* not closing the fd here since the sparse code keeps the fd around
         * but hasn't mmaped data yet. The tmpfile will get cleaned up when the
         * program exits.
         */
    }
}
void do_update(usb_handle *usb, const char *filename, int erase_first)
{
    queue_info_dump();

    fb_queue_query_save("product", cur_product, sizeof(cur_product));

    ZipArchiveHandle zip;
    int error = OpenArchive(filename, &zip);
    if (error != 0) {
        CloseArchive(zip);
        die("failed to open zip file '%s': %s", filename, ErrorCodeString(error));
    }

    unsigned sz;
    void* data = unzip_file(zip, "android-info.txt", &sz);
    if (data == 0) {
        CloseArchive(zip);
        die("update package '%s' has no android-info.txt", filename);
    }

    setup_requirements(reinterpret_cast<char*>(data), sz);

    for (size_t i = 0; i < ARRAY_SIZE(images); ++i) {
        int fd = unzip_to_file(zip, images[i].img_name);
        if (fd == -1) {
            if (images[i].is_optional) {
                continue;
            }
            CloseArchive(zip);
            exit(1); // unzip_to_file already explained why.
        }
        fastboot_buffer buf;
        int rc = load_buf_fd(usb, fd, &buf);
        if (rc) die("cannot load %s from flash", images[i].img_name);
        do_update_signature(zip, images[i].sig_name);
        if (erase_first && needs_erase(usb, images[i].part_name)) {
            fb_queue_erase(images[i].part_name);
        }
        flash_buf(images[i].part_name, &buf);
        /* not closing the fd here since the sparse code keeps the fd around
         * but hasn't mmaped data yet. The tmpfile will get cleaned up when the
         * program exits.
         */
    }

    CloseArchive(zip);
}
示例#6
0
void do_flashall(char *fn)
{
    void *zdata;
    unsigned zsize;
    void *data;
    unsigned sz;
    zipfile_t zip;
    struct config conf;
    char ver[FB_RESPONSE_SZ + 1];
    char *pc;
    int status;

    /* get target IFWI major version */
    fprintf(stderr, "query system info...\n");
    fb_queue_query_save("ifwi", ver, sizeof(ver));
    usb = open_device();
    fb_execute_queue(usb);

    if ((pc = strchr(ver, '.')))
        *pc = 0;

    queue_info_dump();

    zdata = load_file(fn, &zsize);
    if (zdata == 0) die("failed to load '%s': %s", fn, strerror(errno));

    zip = init_zipfile(zdata, zsize);
    if(zip == 0) die("failed to access zipdata in '%s', is it a zip file?", fn);

    /* is converted-system tarball? */
    data = unzip_file(zip, CONFIG_FILE, &sz);
    if (data == 0) {
        /* is raw container tarball? */
        data = unzip_file(zip, FW_CONFIG, &sz);
        if (data != 0 && parse_config(data, (size_t)sz, &conf, ver))
            die("parse config: %s failed.", FW_CONFIG);
        data = unzip_file(zip, PREOS_CONFIG, &sz);
        if (data != 0 && parse_config(data, (size_t)sz, &conf, ver))
            die("parse config: %s failed.", PREOS_CONFIG);
    } else {
        if (parse_config(data, (size_t)sz, &conf, ver))
            die("parse config failed.");
    }

    /*
     * every component is optional, no need to check
     * the second of unzip_file argument if it's not null
     * memcmp can handle NULL pointer.
     */
    data = unzip_file(zip, conf.fwr_dnx, &sz);
    if (data != 0)
        fb_queue_stream_flash("dnx", data, sz);

    data = unzip_file(zip, conf.ifwi, &sz);
    if (data != 0)
        fb_queue_stream_flash("ifwi", data, sz);

    data = unzip_file(zip, conf.boot, &sz);
    if (data != 0)
        fb_queue_stream_flash("boot", data, sz);

    data = unzip_file(zip, conf.preos, &sz);
    if (data != 0)
        fb_queue_stream_flash("preos", data, sz);

    /* try to get platform image.
     * first, try gziped.
     * second, try bzip2.
     * at last, try raw image
     */
    data = unzip_file(zip, PLATFORM_IMG ".gz", &sz);
    if (data == 0) {
        data = unzip_file(zip, PLATFORM_IMG ".bz2", &sz);
        if (data == 0) {
            data = unzip_file(zip, PLATFORM_IMG, &sz);
        }
    }
    if (data != 0)
        fb_queue_stream_flash("platform", data, sz);

    /* data and csa partition image */
    data = unzip_file(zip, DATA_IMG ".gz", &sz);
    if (data == 0) {
        data = unzip_file(zip, DATA_IMG ".bz2", &sz);
        if (data == 0) {
            data = unzip_file(zip, DATA_IMG, &sz);
        }
    }
    if (data != 0)
        fb_queue_stream_flash("data", data, sz);

    data = unzip_file(zip, CSA_IMG ".gz", &sz);
    if (data == 0) {
        data = unzip_file(zip, CSA_IMG ".bz2", &sz);
        if (data == 0) {
            data = unzip_file(zip, CSA_IMG, &sz);
        }
    }
    if (data != 0)
        fb_queue_stream_flash("csa", data, sz);
}