2009-03-04 11:32:55 +08:00
|
|
|
/*
|
|
|
|
* 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
|
2011-02-26 10:38:53 +08:00
|
|
|
* the documentation and/or other materials provided with the
|
2009-03-04 11:32:55 +08:00
|
|
|
* 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
|
2011-02-26 10:38:53 +08:00
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
2009-03-04 11:32:55 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-05-25 08:18:41 +08:00
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
|
2014-05-01 05:05:28 +08:00
|
|
|
#include <ctype.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2012-05-23 08:53:34 +08:00
|
|
|
#include <getopt.h>
|
2014-05-16 11:06:40 +08:00
|
|
|
#include <inttypes.h>
|
2014-05-01 05:05:28 +08:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
#include <sys/time.h>
|
2012-05-25 08:18:41 +08:00
|
|
|
#include <sys/types.h>
|
2014-05-01 05:05:28 +08:00
|
|
|
#include <unistd.h>
|
2012-05-25 08:18:41 +08:00
|
|
|
|
|
|
|
#include <sparse/sparse.h>
|
2015-03-19 14:12:44 +08:00
|
|
|
#include <ziparchive/zip_archive.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
#include "bootimg_utils.h"
|
2009-03-04 11:32:55 +08:00
|
|
|
#include "fastboot.h"
|
2014-03-12 09:28:15 +08:00
|
|
|
#include "fs.h"
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2012-05-25 08:18:41 +08:00
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
|
|
|
|
|
2011-04-05 08:54:59 +08:00
|
|
|
char cur_product[FB_RESPONSE_SZ + 1];
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
static const char *serial = 0;
|
|
|
|
static const char *product = 0;
|
|
|
|
static const char *cmdline = 0;
|
|
|
|
static unsigned short vendor_id = 0;
|
2012-04-07 03:39:30 +08:00
|
|
|
static int long_listing = 0;
|
2012-05-25 08:18:41 +08:00
|
|
|
static int64_t sparse_limit = -1;
|
|
|
|
static int64_t target_sparse_limit = -1;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2013-03-08 09:06:41 +08:00
|
|
|
unsigned page_size = 2048;
|
|
|
|
unsigned base_addr = 0x10000000;
|
|
|
|
unsigned kernel_offset = 0x00008000;
|
|
|
|
unsigned ramdisk_offset = 0x01000000;
|
|
|
|
unsigned second_offset = 0x00f00000;
|
|
|
|
unsigned tags_offset = 0x00000100;
|
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
enum fb_buffer_type {
|
|
|
|
FB_BUFFER,
|
|
|
|
FB_BUFFER_SPARSE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fastboot_buffer {
|
|
|
|
enum fb_buffer_type type;
|
|
|
|
void *data;
|
2014-05-08 07:31:59 +08:00
|
|
|
unsigned int sz;
|
2013-06-29 00:54:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
char img_name[13];
|
|
|
|
char sig_name[13];
|
|
|
|
char part_name[9];
|
|
|
|
bool is_optional;
|
2014-05-29 05:10:01 +08:00
|
|
|
} images[] = {
|
2013-06-29 00:54:59 +08:00
|
|
|
{"boot.img", "boot.sig", "boot", false},
|
|
|
|
{"recovery.img", "recovery.sig", "recovery", true},
|
|
|
|
{"system.img", "system.sig", "system", false},
|
2014-05-29 05:10:01 +08:00
|
|
|
{"vendor.img", "vendor.sig", "vendor", true},
|
2013-06-29 00:54:59 +08:00
|
|
|
};
|
2009-04-29 07:05:07 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
char *find_item(const char *item, const char *product)
|
|
|
|
{
|
|
|
|
char *dir;
|
2015-03-19 13:47:09 +08:00
|
|
|
const char *fn;
|
2009-03-04 11:32:55 +08:00
|
|
|
char path[PATH_MAX + 128];
|
|
|
|
|
|
|
|
if(!strcmp(item,"boot")) {
|
|
|
|
fn = "boot.img";
|
|
|
|
} else if(!strcmp(item,"recovery")) {
|
|
|
|
fn = "recovery.img";
|
|
|
|
} else if(!strcmp(item,"system")) {
|
|
|
|
fn = "system.img";
|
2014-05-29 05:10:01 +08:00
|
|
|
} else if(!strcmp(item,"vendor")) {
|
|
|
|
fn = "vendor.img";
|
2009-03-04 11:32:55 +08:00
|
|
|
} else if(!strcmp(item,"userdata")) {
|
|
|
|
fn = "userdata.img";
|
2011-10-01 05:39:25 +08:00
|
|
|
} else if(!strcmp(item,"cache")) {
|
|
|
|
fn = "cache.img";
|
2009-03-04 11:32:55 +08:00
|
|
|
} else if(!strcmp(item,"info")) {
|
|
|
|
fn = "android-info.txt";
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"unknown partition '%s'\n", item);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(product) {
|
|
|
|
get_my_path(path);
|
|
|
|
sprintf(path + strlen(path),
|
|
|
|
"../../../target/product/%s/%s", product, fn);
|
|
|
|
return strdup(path);
|
|
|
|
}
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
dir = getenv("ANDROID_PRODUCT_OUT");
|
|
|
|
if((dir == 0) || (dir[0] == 0)) {
|
|
|
|
die("neither -p product specified nor ANDROID_PRODUCT_OUT set");
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
sprintf(path, "%s/%s", dir, fn);
|
|
|
|
return strdup(path);
|
|
|
|
}
|
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
static int64_t file_size(int fd)
|
2012-05-25 08:18:41 +08:00
|
|
|
{
|
2013-06-29 00:54:59 +08:00
|
|
|
struct stat st;
|
|
|
|
int ret;
|
2012-05-25 08:18:41 +08:00
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
ret = fstat(fd, &st);
|
2012-05-25 08:18:41 +08:00
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
return ret ? -1 : st.st_size;
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
static void *load_fd(int fd, unsigned *_sz)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
2014-05-08 07:31:59 +08:00
|
|
|
char *data;
|
|
|
|
int sz;
|
2011-12-09 03:59:38 +08:00
|
|
|
int errno_tmp;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
data = 0;
|
|
|
|
|
|
|
|
sz = file_size(fd);
|
2013-06-29 00:54:59 +08:00
|
|
|
if (sz < 0) {
|
|
|
|
goto oops;
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
data = (char*) malloc(sz);
|
|
|
|
if(data == 0) goto oops;
|
|
|
|
|
|
|
|
if(read(fd, data, sz) != sz) goto oops;
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if(_sz) *_sz = sz;
|
|
|
|
return data;
|
|
|
|
|
|
|
|
oops:
|
2011-12-09 03:59:38 +08:00
|
|
|
errno_tmp = errno;
|
2009-03-04 11:32:55 +08:00
|
|
|
close(fd);
|
|
|
|
if(data != 0) free(data);
|
2011-12-09 03:59:38 +08:00
|
|
|
errno = errno_tmp;
|
2009-03-04 11:32:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
static void *load_file(const char *fn, unsigned *_sz)
|
2013-06-29 00:54:59 +08:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(fn, O_RDONLY | O_BINARY);
|
|
|
|
if(fd < 0) return 0;
|
|
|
|
|
|
|
|
return load_fd(fd, _sz);
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-08-11 06:30:54 +08:00
|
|
|
int match_fastboot_with_serial(usb_ifc_info* info, const char* local_serial) {
|
|
|
|
// Require a matching vendor id if the user specified one with -i.
|
2015-08-20 08:49:45 +08:00
|
|
|
if (vendor_id != 0 && info->dev_vendor != vendor_id) {
|
2015-08-11 06:30:54 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->ifc_class != 0xff || info->ifc_subclass != 0x42 || info->ifc_protocol != 0x03) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-07 03:39:30 +08:00
|
|
|
// require matching serial number or device path if requested
|
2009-03-04 11:32:55 +08:00
|
|
|
// at the command line with the -s option.
|
2012-06-07 02:53:33 +08:00
|
|
|
if (local_serial && (strcmp(local_serial, info->serial_number) != 0 &&
|
|
|
|
strcmp(local_serial, info->device_path) != 0)) return -1;
|
2009-03-04 11:32:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-08 09:06:41 +08:00
|
|
|
int match_fastboot(usb_ifc_info *info)
|
|
|
|
{
|
|
|
|
return match_fastboot_with_serial(info, serial);
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
int list_devices_callback(usb_ifc_info *info)
|
|
|
|
{
|
2012-06-07 02:53:33 +08:00
|
|
|
if (match_fastboot_with_serial(info, NULL) == 0) {
|
2015-03-19 13:47:09 +08:00
|
|
|
const char* serial = info->serial_number;
|
2009-10-07 09:07:49 +08:00
|
|
|
if (!info->writable) {
|
|
|
|
serial = "no permissions"; // like "adb devices"
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
if (!serial[0]) {
|
|
|
|
serial = "????????????";
|
|
|
|
}
|
2012-06-05 11:29:11 +08:00
|
|
|
// output compatible with "adb devices"
|
2012-04-07 03:39:30 +08:00
|
|
|
if (!long_listing) {
|
|
|
|
printf("%s\tfastboot\n", serial);
|
2014-11-27 06:54:43 +08:00
|
|
|
} else if (strcmp("", info->device_path) == 0) {
|
2012-06-05 11:29:11 +08:00
|
|
|
printf("%-22s fastboot\n", serial);
|
2012-04-07 03:39:30 +08:00
|
|
|
} else {
|
2012-06-05 11:29:11 +08:00
|
|
|
printf("%-22s fastboot %s\n", serial, info->device_path);
|
2012-04-07 03:39:30 +08:00
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_handle *open_device(void)
|
|
|
|
{
|
|
|
|
static usb_handle *usb = 0;
|
|
|
|
int announce = 1;
|
|
|
|
|
|
|
|
if(usb) return usb;
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
for(;;) {
|
|
|
|
usb = usb_open(match_fastboot);
|
|
|
|
if(usb) return usb;
|
|
|
|
if(announce) {
|
2011-02-26 10:38:53 +08:00
|
|
|
announce = 0;
|
2015-08-20 08:49:45 +08:00
|
|
|
fprintf(stderr, "< waiting for %s >\n", serial ? serial : "any device");
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
2014-05-01 05:05:28 +08:00
|
|
|
usleep(1000);
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 [ <option> ] <command>\n"
|
|
|
|
"\n"
|
|
|
|
"commands:\n"
|
2015-06-11 02:58:14 +08:00
|
|
|
" update <filename> Reflash device from update.zip.\n"
|
|
|
|
" flashall Flash boot, system, vendor, and --\n"
|
|
|
|
" if found -- recovery.\n"
|
|
|
|
" flash <partition> [ <filename> ] Write a file to a flash partition.\n"
|
|
|
|
" flashing lock Locks the device. Prevents flashing.\n"
|
|
|
|
" flashing unlock Unlocks the device. Allows flashing\n"
|
|
|
|
" any partition except\n"
|
|
|
|
" bootloader-related partitions.\n"
|
|
|
|
" flashing lock_critical Prevents flashing bootloader-related\n"
|
|
|
|
" partitions.\n"
|
|
|
|
" flashing unlock_critical Enables flashing bootloader-related\n"
|
|
|
|
" partitions.\n"
|
|
|
|
" flashing get_unlock_ability Queries bootloader to see if the\n"
|
|
|
|
" device is unlocked.\n"
|
|
|
|
" erase <partition> Erase a flash partition.\n"
|
|
|
|
" format[:[<fs type>][:[<size>]] <partition>\n"
|
|
|
|
" Format a flash partition. Can\n"
|
|
|
|
" override the fs type and/or size\n"
|
|
|
|
" the bootloader reports.\n"
|
|
|
|
" getvar <variable> Display a bootloader variable.\n"
|
|
|
|
" boot <kernel> [ <ramdisk> [ <second> ] ] Download and boot kernel.\n"
|
|
|
|
" flash:raw boot <kernel> [ <ramdisk> [ <second> ] ]\n"
|
|
|
|
" Create bootimage and flash it.\n"
|
|
|
|
" devices [-l] List all connected devices [with\n"
|
|
|
|
" device paths].\n"
|
|
|
|
" continue Continue with autoboot.\n"
|
|
|
|
" reboot [bootloader] Reboot device [into bootloader].\n"
|
|
|
|
" reboot-bootloader Reboot device into bootloader.\n"
|
|
|
|
" help Show this help message.\n"
|
2009-03-04 11:32:55 +08:00
|
|
|
"\n"
|
|
|
|
"options:\n"
|
2015-06-11 02:58:14 +08:00
|
|
|
" -w Erase userdata and cache (and format\n"
|
|
|
|
" if supported by partition type).\n"
|
|
|
|
" -u Do not erase partition before\n"
|
|
|
|
" formatting.\n"
|
|
|
|
" -s <specific device> Specify device serial number\n"
|
|
|
|
" or path to device port.\n"
|
|
|
|
" -p <product> Specify product name.\n"
|
|
|
|
" -c <cmdline> Override kernel commandline.\n"
|
|
|
|
" -i <vendor id> Specify a custom USB vendor id.\n"
|
|
|
|
" -b <base_addr> Specify a custom kernel base\n"
|
|
|
|
" address (default: 0x10000000).\n"
|
|
|
|
" -n <page size> Specify the nand page size\n"
|
|
|
|
" (default: 2048).\n"
|
|
|
|
" -S <size>[K|M|G] Automatically sparse files greater\n"
|
|
|
|
" than 'size'. 0 to disable.\n"
|
2009-03-04 11:32:55 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-03-08 09:06:41 +08:00
|
|
|
void *load_bootable_image(const char *kernel, const char *ramdisk,
|
2014-07-17 23:17:54 +08:00
|
|
|
const char *secondstage, unsigned *sz,
|
|
|
|
const char *cmdline)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
2014-07-17 23:17:54 +08:00
|
|
|
void *kdata = 0, *rdata = 0, *sdata = 0;
|
|
|
|
unsigned ksize = 0, rsize = 0, ssize = 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
void *bdata;
|
|
|
|
unsigned bsize;
|
|
|
|
|
|
|
|
if(kernel == 0) {
|
|
|
|
fprintf(stderr, "no image specified\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kdata = load_file(kernel, &ksize);
|
|
|
|
if(kdata == 0) {
|
2011-12-09 03:59:38 +08:00
|
|
|
fprintf(stderr, "cannot load '%s': %s\n", kernel, strerror(errno));
|
2009-03-04 11:32:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
/* is this actually a boot image? */
|
|
|
|
if(!memcmp(kdata, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
|
|
|
|
if(cmdline) bootimg_set_cmdline((boot_img_hdr*) kdata, cmdline);
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
if(ramdisk) {
|
|
|
|
fprintf(stderr, "cannot boot a boot.img *and* ramdisk\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
*sz = ksize;
|
|
|
|
return kdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ramdisk) {
|
|
|
|
rdata = load_file(ramdisk, &rsize);
|
|
|
|
if(rdata == 0) {
|
2011-12-09 03:59:38 +08:00
|
|
|
fprintf(stderr,"cannot load '%s': %s\n", ramdisk, strerror(errno));
|
2009-03-04 11:32:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 23:17:54 +08:00
|
|
|
if (secondstage) {
|
|
|
|
sdata = load_file(secondstage, &ssize);
|
|
|
|
if(sdata == 0) {
|
|
|
|
fprintf(stderr,"cannot load '%s': %s\n", secondstage, strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
fprintf(stderr,"creating boot image...\n");
|
2013-03-08 09:06:41 +08:00
|
|
|
bdata = mkbootimg(kdata, ksize, kernel_offset,
|
|
|
|
rdata, rsize, ramdisk_offset,
|
2014-07-17 23:17:54 +08:00
|
|
|
sdata, ssize, second_offset,
|
2013-03-08 09:06:41 +08:00
|
|
|
page_size, base_addr, tags_offset, &bsize);
|
2009-03-04 11:32:55 +08:00
|
|
|
if(bdata == 0) {
|
|
|
|
fprintf(stderr,"failed to create boot.img\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(cmdline) bootimg_set_cmdline((boot_img_hdr*) bdata, cmdline);
|
|
|
|
fprintf(stderr,"creating boot image - %d bytes\n", bsize);
|
|
|
|
*sz = bsize;
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
return bdata;
|
|
|
|
}
|
|
|
|
|
2015-03-20 02:44:32 +08:00
|
|
|
static void* unzip_file(ZipArchiveHandle zip, const char* entry_name, unsigned* sz)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
2015-06-26 05:39:19 +08:00
|
|
|
ZipString zip_entry_name(entry_name);
|
2015-03-19 14:12:44 +08:00
|
|
|
ZipEntry zip_entry;
|
|
|
|
if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
|
2015-03-20 02:44:32 +08:00
|
|
|
fprintf(stderr, "archive does not contain '%s'\n", entry_name);
|
2014-05-08 07:31:59 +08:00
|
|
|
return 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 14:12:44 +08:00
|
|
|
*sz = zip_entry.uncompressed_length;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-03-19 14:12:44 +08:00
|
|
|
uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
|
|
|
|
if (data == NULL) {
|
2015-03-20 02:44:32 +08:00
|
|
|
fprintf(stderr, "failed to allocate %u bytes for '%s'\n", *sz, entry_name);
|
2014-05-08 07:31:59 +08:00
|
|
|
return 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2015-03-20 02:44:32 +08:00
|
|
|
int error = ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length);
|
|
|
|
if (error != 0) {
|
|
|
|
fprintf(stderr, "failed to extract '%s': %s\n", entry_name, ErrorCodeString(error));
|
2009-03-04 11:32:55 +08:00
|
|
|
free(data);
|
2014-05-08 07:31:59 +08:00
|
|
|
return 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
2014-05-08 07:31:59 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2015-06-04 06:22:11 +08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
|
|
|
// TODO: move this to somewhere it can be shared.
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
// Windows' tmpfile(3) requires administrator rights because
|
|
|
|
// it creates temporary files in the root directory.
|
|
|
|
static FILE* win32_tmpfile() {
|
|
|
|
char temp_path[PATH_MAX];
|
|
|
|
DWORD nchars = GetTempPath(sizeof(temp_path), temp_path);
|
|
|
|
if (nchars == 0 || nchars >= sizeof(temp_path)) {
|
|
|
|
fprintf(stderr, "GetTempPath failed, error %ld\n", GetLastError());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
if (GetTempFileName(temp_path, "fastboot", 0, filename) == 0) {
|
|
|
|
fprintf(stderr, "GetTempFileName failed, error %ld\n", GetLastError());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fopen(filename, "w+bTD");
|
|
|
|
}
|
|
|
|
|
|
|
|
#define tmpfile win32_tmpfile
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-03-20 02:44:32 +08:00
|
|
|
static int unzip_to_file(ZipArchiveHandle zip, char* entry_name) {
|
|
|
|
FILE* fp = tmpfile();
|
|
|
|
if (fp == NULL) {
|
|
|
|
fprintf(stderr, "failed to create temporary file for '%s': %s\n",
|
|
|
|
entry_name, strerror(errno));
|
2014-05-08 07:31:59 +08:00
|
|
|
return -1;
|
2013-06-29 00:54:59 +08:00
|
|
|
}
|
|
|
|
|
2015-06-26 05:39:19 +08:00
|
|
|
ZipString zip_entry_name(entry_name);
|
2015-03-20 02:44:32 +08:00
|
|
|
ZipEntry zip_entry;
|
|
|
|
if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
|
|
|
|
fprintf(stderr, "archive does not contain '%s'\n", entry_name);
|
2013-06-29 00:54:59 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-20 02:44:32 +08:00
|
|
|
int fd = fileno(fp);
|
|
|
|
int error = ExtractEntryToFile(zip, &zip_entry, fd);
|
|
|
|
if (error != 0) {
|
|
|
|
fprintf(stderr, "failed to extract '%s': %s\n", entry_name, ErrorCodeString(error));
|
|
|
|
return -1;
|
2013-06-29 00:54:59 +08:00
|
|
|
}
|
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
2013-06-29 00:54:59 +08:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
static char *strip(char *s)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
while(*s && isspace(*s)) s++;
|
|
|
|
n = strlen(s);
|
|
|
|
while(n-- > 0) {
|
|
|
|
if(!isspace(s[n])) break;
|
|
|
|
s[n] = 0;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_OPTIONS 32
|
|
|
|
static int setup_requirement_line(char *name)
|
|
|
|
{
|
|
|
|
char *val[MAX_OPTIONS];
|
2011-04-05 08:54:59 +08:00
|
|
|
char *prod = NULL;
|
2009-03-04 11:32:55 +08:00
|
|
|
unsigned n, count;
|
|
|
|
char *x;
|
|
|
|
int invert = 0;
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
if (!strncmp(name, "reject ", 7)) {
|
|
|
|
name += 7;
|
|
|
|
invert = 1;
|
|
|
|
} else if (!strncmp(name, "require ", 8)) {
|
|
|
|
name += 8;
|
|
|
|
invert = 0;
|
2011-04-05 08:54:59 +08:00
|
|
|
} else if (!strncmp(name, "require-for-product:", 20)) {
|
|
|
|
// Get the product and point name past it
|
|
|
|
prod = name + 20;
|
|
|
|
name = strchr(name, ' ');
|
|
|
|
if (!name) return -1;
|
|
|
|
*name = 0;
|
|
|
|
name += 1;
|
|
|
|
invert = 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
x = strchr(name, '=');
|
|
|
|
if (x == 0) return 0;
|
|
|
|
*x = 0;
|
|
|
|
val[0] = x + 1;
|
|
|
|
|
|
|
|
for(count = 1; count < MAX_OPTIONS; count++) {
|
|
|
|
x = strchr(val[count - 1],'|');
|
|
|
|
if (x == 0) break;
|
|
|
|
*x = 0;
|
|
|
|
val[count] = x + 1;
|
|
|
|
}
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
name = strip(name);
|
|
|
|
for(n = 0; n < count; n++) val[n] = strip(val[n]);
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
name = strip(name);
|
|
|
|
if (name == 0) return -1;
|
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
const char* var = name;
|
|
|
|
// Work around an unfortunate name mismatch.
|
|
|
|
if (!strcmp(name,"board")) var = "product";
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
const char** out = reinterpret_cast<const char**>(malloc(sizeof(char*) * count));
|
2009-03-04 11:32:55 +08:00
|
|
|
if (out == 0) return -1;
|
|
|
|
|
|
|
|
for(n = 0; n < count; n++) {
|
|
|
|
out[n] = strdup(strip(val[n]));
|
2013-10-30 05:12:46 +08:00
|
|
|
if (out[n] == 0) {
|
|
|
|
for(size_t i = 0; i < n; ++i) {
|
|
|
|
free((char*) out[i]);
|
|
|
|
}
|
|
|
|
free(out);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
fb_queue_require(prod, var, invert, n, out);
|
2009-03-04 11:32:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
static void setup_requirements(char *data, unsigned sz)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
2014-05-08 07:31:59 +08:00
|
|
|
char *s;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
s = data;
|
2009-03-04 11:32:55 +08:00
|
|
|
while (sz-- > 0) {
|
|
|
|
if(*s == '\n') {
|
|
|
|
*s++ = 0;
|
|
|
|
if (setup_requirement_line(data)) {
|
|
|
|
die("out of memory");
|
|
|
|
}
|
|
|
|
data = s;
|
|
|
|
} else {
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void queue_info_dump(void)
|
|
|
|
{
|
|
|
|
fb_queue_notice("--------------------------------------------");
|
|
|
|
fb_queue_display("version-bootloader", "Bootloader Version...");
|
|
|
|
fb_queue_display("version-baseband", "Baseband Version.....");
|
|
|
|
fb_queue_display("serialno", "Serial Number........");
|
|
|
|
fb_queue_notice("--------------------------------------------");
|
|
|
|
}
|
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
static struct sparse_file **load_sparse_files(int fd, int max_size)
|
2012-05-25 08:18:41 +08:00
|
|
|
{
|
2015-04-01 03:09:29 +08:00
|
|
|
struct sparse_file* s = sparse_file_import_auto(fd, false, true);
|
2012-05-25 08:18:41 +08:00
|
|
|
if (!s) {
|
2013-06-29 00:54:59 +08:00
|
|
|
die("cannot sparse read file\n");
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
int files = sparse_file_resparse(s, max_size, NULL, 0);
|
2012-05-25 08:18:41 +08:00
|
|
|
if (files < 0) {
|
2013-06-29 00:54:59 +08:00
|
|
|
die("Failed to resparse\n");
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
sparse_file** out_s = reinterpret_cast<sparse_file**>(calloc(sizeof(struct sparse_file *), files + 1));
|
2012-05-25 08:18:41 +08:00
|
|
|
if (!out_s) {
|
|
|
|
die("Failed to allocate sparse file array\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
files = sparse_file_resparse(s, max_size, out_s, files);
|
|
|
|
if (files < 0) {
|
2013-06-29 00:54:59 +08:00
|
|
|
die("Failed to resparse\n");
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return out_s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t get_target_sparse_limit(struct usb_handle *usb)
|
|
|
|
{
|
|
|
|
int64_t limit = 0;
|
|
|
|
char response[FB_RESPONSE_SZ + 1];
|
|
|
|
int status = fb_getvar(usb, response, "max-download-size");
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
limit = strtoul(response, NULL, 0);
|
|
|
|
if (limit > 0) {
|
2014-05-16 11:06:40 +08:00
|
|
|
fprintf(stderr, "target reported max download size of %" PRId64 " bytes\n",
|
2012-05-25 08:18:41 +08:00
|
|
|
limit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t get_sparse_limit(struct usb_handle *usb, int64_t size)
|
|
|
|
{
|
|
|
|
int64_t limit;
|
|
|
|
|
|
|
|
if (sparse_limit == 0) {
|
|
|
|
return 0;
|
|
|
|
} else if (sparse_limit > 0) {
|
|
|
|
limit = sparse_limit;
|
|
|
|
} else {
|
|
|
|
if (target_sparse_limit == -1) {
|
|
|
|
target_sparse_limit = get_target_sparse_limit(usb);
|
|
|
|
}
|
|
|
|
if (target_sparse_limit > 0) {
|
|
|
|
limit = target_sparse_limit;
|
|
|
|
} else {
|
2012-07-25 09:05:21 +08:00
|
|
|
return 0;
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > limit) {
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-30 05:46:25 +08:00
|
|
|
/* Until we get lazy inode table init working in make_ext4fs, we need to
|
|
|
|
* erase partitions of type ext4 before flashing a filesystem so no stale
|
|
|
|
* inodes are left lying around. Otherwise, e2fsck gets very upset.
|
|
|
|
*/
|
2015-06-03 04:34:07 +08:00
|
|
|
static int needs_erase(usb_handle* usb, const char *part)
|
2012-09-30 05:46:25 +08:00
|
|
|
{
|
|
|
|
/* The function fb_format_supported() currently returns the value
|
|
|
|
* we want, so just call it.
|
|
|
|
*/
|
2014-05-07 06:14:15 +08:00
|
|
|
return fb_format_supported(usb, part, NULL);
|
2012-09-30 05:46:25 +08:00
|
|
|
}
|
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
static int load_buf_fd(usb_handle *usb, int fd,
|
|
|
|
struct fastboot_buffer *buf)
|
2012-05-25 08:18:41 +08:00
|
|
|
{
|
2014-05-06 10:43:15 +08:00
|
|
|
int64_t sz64;
|
2014-05-08 07:31:59 +08:00
|
|
|
void *data;
|
|
|
|
int64_t limit;
|
2012-05-25 08:18:41 +08:00
|
|
|
|
2014-05-08 07:31:59 +08:00
|
|
|
|
|
|
|
sz64 = file_size(fd);
|
|
|
|
if (sz64 < 0) {
|
|
|
|
return -1;
|
2013-06-29 00:54:59 +08:00
|
|
|
}
|
2014-03-12 09:28:15 +08:00
|
|
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2012-05-25 08:18:41 +08:00
|
|
|
limit = get_sparse_limit(usb, sz64);
|
|
|
|
if (limit) {
|
2013-06-29 00:54:59 +08:00
|
|
|
struct sparse_file **s = load_sparse_files(fd, limit);
|
2012-05-25 08:18:41 +08:00
|
|
|
if (s == NULL) {
|
2013-06-29 00:54:59 +08:00
|
|
|
return -1;
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
2013-06-29 00:54:59 +08:00
|
|
|
buf->type = FB_BUFFER_SPARSE;
|
|
|
|
buf->data = s;
|
2012-05-25 08:18:41 +08:00
|
|
|
} else {
|
2014-05-08 07:31:59 +08:00
|
|
|
unsigned int sz;
|
2013-06-29 00:54:59 +08:00
|
|
|
data = load_fd(fd, &sz);
|
2014-05-08 07:31:59 +08:00
|
|
|
if (data == 0) return -1;
|
2013-06-29 00:54:59 +08:00
|
|
|
buf->type = FB_BUFFER;
|
2014-05-06 10:43:15 +08:00
|
|
|
buf->data = data;
|
2014-05-08 07:31:59 +08:00
|
|
|
buf->sz = sz;
|
2013-06-29 00:54:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_buf(usb_handle *usb, const char *fname,
|
|
|
|
struct fastboot_buffer *buf)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(fname, O_RDONLY | O_BINARY);
|
|
|
|
if (fd < 0) {
|
2014-04-30 04:45:05 +08:00
|
|
|
return -1;
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
2013-06-29 00:54:59 +08:00
|
|
|
|
|
|
|
return load_buf_fd(usb, fd, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flash_buf(const char *pname, struct fastboot_buffer *buf)
|
|
|
|
{
|
2015-03-19 13:47:09 +08:00
|
|
|
sparse_file** s;
|
2013-06-29 00:54:59 +08:00
|
|
|
|
|
|
|
switch (buf->type) {
|
|
|
|
case FB_BUFFER_SPARSE:
|
2015-03-19 13:47:09 +08:00
|
|
|
s = reinterpret_cast<sparse_file**>(buf->data);
|
2013-06-29 00:54:59 +08:00
|
|
|
while (*s) {
|
|
|
|
int64_t sz64 = sparse_file_len(*s, true, false);
|
|
|
|
fb_queue_flash_sparse(pname, *s++, sz64);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FB_BUFFER:
|
|
|
|
fb_queue_flash(pname, buf->data, buf->sz);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
die("unknown buffer type: %d", buf->type);
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
void do_flash(usb_handle *usb, const char *pname, const char *fname)
|
|
|
|
{
|
|
|
|
struct fastboot_buffer buf;
|
|
|
|
|
|
|
|
if (load_buf(usb, fname, &buf)) {
|
|
|
|
die("cannot load '%s'", fname);
|
|
|
|
}
|
|
|
|
flash_buf(pname, &buf);
|
2012-05-25 08:18:41 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 14:12:44 +08:00
|
|
|
void do_update_signature(ZipArchiveHandle zip, char *fn)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
2014-05-08 07:31:59 +08:00
|
|
|
unsigned sz;
|
2015-03-19 14:12:44 +08:00
|
|
|
void* data = unzip_file(zip, fn, &sz);
|
2014-05-08 07:31:59 +08:00
|
|
|
if (data == 0) return;
|
2009-03-04 11:32:55 +08:00
|
|
|
fb_queue_download("signature", data, sz);
|
|
|
|
fb_queue_command("signature", "installing signature");
|
|
|
|
}
|
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
void do_update(usb_handle *usb, const char *filename, int erase_first)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
|
|
|
queue_info_dump();
|
|
|
|
|
2011-04-05 08:54:59 +08:00
|
|
|
fb_queue_query_save("product", cur_product, sizeof(cur_product));
|
|
|
|
|
2015-03-19 14:12:44 +08:00
|
|
|
ZipArchiveHandle zip;
|
2015-03-20 02:44:32 +08:00
|
|
|
int error = OpenArchive(filename, &zip);
|
|
|
|
if (error != 0) {
|
2015-05-11 23:59:46 +08:00
|
|
|
CloseArchive(zip);
|
2015-03-20 02:44:32 +08:00
|
|
|
die("failed to open zip file '%s': %s", filename, ErrorCodeString(error));
|
2015-03-19 14:12:44 +08:00
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
unsigned sz;
|
|
|
|
void* data = unzip_file(zip, "android-info.txt", &sz);
|
2014-05-08 07:31:59 +08:00
|
|
|
if (data == 0) {
|
2015-05-11 23:59:46 +08:00
|
|
|
CloseArchive(zip);
|
2015-03-20 01:30:53 +08:00
|
|
|
die("update package '%s' has no android-info.txt", filename);
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
setup_requirements(reinterpret_cast<char*>(data), sz);
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-06-03 12:37:05 +08:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(images); ++i) {
|
2015-03-19 13:47:09 +08:00
|
|
|
int fd = unzip_to_file(zip, images[i].img_name);
|
2015-06-03 12:37:05 +08:00
|
|
|
if (fd == -1) {
|
|
|
|
if (images[i].is_optional) {
|
2013-06-29 00:54:59 +08:00
|
|
|
continue;
|
2015-06-03 12:37:05 +08:00
|
|
|
}
|
2015-05-11 23:59:46 +08:00
|
|
|
CloseArchive(zip);
|
2015-06-03 12:37:05 +08:00
|
|
|
exit(1); // unzip_to_file already explained why.
|
2012-09-30 05:46:25 +08:00
|
|
|
}
|
2015-03-19 13:47:09 +08:00
|
|
|
fastboot_buffer buf;
|
|
|
|
int rc = load_buf_fd(usb, fd, &buf);
|
2013-06-29 00:54:59 +08:00
|
|
|
if (rc) die("cannot load %s from flash", images[i].img_name);
|
|
|
|
do_update_signature(zip, images[i].sig_name);
|
2015-06-03 04:34:07 +08:00
|
|
|
if (erase_first && needs_erase(usb, images[i].part_name)) {
|
2013-06-29 00:54:59 +08:00
|
|
|
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.
|
|
|
|
*/
|
2012-09-30 05:46:25 +08:00
|
|
|
}
|
2015-03-19 14:12:44 +08:00
|
|
|
|
|
|
|
CloseArchive(zip);
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void do_send_signature(char *fn)
|
|
|
|
{
|
|
|
|
void *data;
|
2014-05-08 07:31:59 +08:00
|
|
|
unsigned sz;
|
2009-03-04 11:32:55 +08:00
|
|
|
char *xtn;
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
xtn = strrchr(fn, '.');
|
|
|
|
if (!xtn) return;
|
|
|
|
if (strcmp(xtn, ".img")) return;
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
strcpy(xtn,".sig");
|
|
|
|
data = load_file(fn, &sz);
|
|
|
|
strcpy(xtn,".img");
|
|
|
|
if (data == 0) return;
|
|
|
|
fb_queue_download("signature", data, sz);
|
|
|
|
fb_queue_command("signature", "installing signature");
|
|
|
|
}
|
|
|
|
|
2013-06-29 00:54:59 +08:00
|
|
|
void do_flashall(usb_handle *usb, int erase_first)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
|
|
|
queue_info_dump();
|
|
|
|
|
2011-04-05 08:54:59 +08:00
|
|
|
fb_queue_query_save("product", cur_product, sizeof(cur_product));
|
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
char* fname = find_item("info", product);
|
2009-03-04 11:32:55 +08:00
|
|
|
if (fname == 0) die("cannot find android-info.txt");
|
2015-03-19 13:47:09 +08:00
|
|
|
|
|
|
|
unsigned sz;
|
|
|
|
void* data = load_file(fname, &sz);
|
2011-12-09 03:59:38 +08:00
|
|
|
if (data == 0) die("could not load android-info.txt: %s", strerror(errno));
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-03-19 13:47:09 +08:00
|
|
|
setup_requirements(reinterpret_cast<char*>(data), sz);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
|
2013-06-29 00:54:59 +08:00
|
|
|
fname = find_item(images[i].part_name, product);
|
2015-03-19 13:47:09 +08:00
|
|
|
fastboot_buffer buf;
|
2013-06-29 00:54:59 +08:00
|
|
|
if (load_buf(usb, fname, &buf)) {
|
|
|
|
if (images[i].is_optional)
|
|
|
|
continue;
|
|
|
|
die("could not load %s\n", images[i].img_name);
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
do_send_signature(fname);
|
2015-06-03 04:34:07 +08:00
|
|
|
if (erase_first && needs_erase(usb, images[i].part_name)) {
|
2013-06-29 00:54:59 +08:00
|
|
|
fb_queue_erase(images[i].part_name);
|
2012-09-30 05:46:25 +08:00
|
|
|
}
|
2013-06-29 00:54:59 +08:00
|
|
|
flash_buf(images[i].part_name, &buf);
|
2012-09-30 05:46:25 +08:00
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define skip(n) do { argc -= (n); argv += (n); } while (0)
|
2011-03-02 15:35:07 +08:00
|
|
|
#define require(n) do { if (argc < (n)) {usage(); exit(1);}} while (0)
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
int do_oem_command(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char command[256];
|
|
|
|
if (argc <= 1) return 0;
|
2011-02-26 10:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
command[0] = 0;
|
|
|
|
while(1) {
|
|
|
|
strcat(command,*argv);
|
|
|
|
skip(1);
|
|
|
|
if(argc == 0) break;
|
|
|
|
strcat(command," ");
|
|
|
|
}
|
|
|
|
|
2011-02-26 10:38:53 +08:00
|
|
|
fb_queue_command(command,"");
|
2009-03-04 11:32:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-25 08:18:41 +08:00
|
|
|
static int64_t parse_num(const char *arg)
|
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
unsigned long long num;
|
|
|
|
|
|
|
|
num = strtoull(arg, &endptr, 0);
|
|
|
|
if (endptr == arg) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*endptr == 'k' || *endptr == 'K') {
|
|
|
|
if (num >= (-1ULL) / 1024) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
num *= 1024LL;
|
|
|
|
endptr++;
|
|
|
|
} else if (*endptr == 'm' || *endptr == 'M') {
|
|
|
|
if (num >= (-1ULL) / (1024 * 1024)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
num *= 1024LL * 1024LL;
|
|
|
|
endptr++;
|
|
|
|
} else if (*endptr == 'g' || *endptr == 'G') {
|
|
|
|
if (num >= (-1ULL) / (1024 * 1024 * 1024)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
num *= 1024LL * 1024LL * 1024LL;
|
|
|
|
endptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*endptr != '\0') {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num > INT64_MAX) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2015-06-03 04:34:07 +08:00
|
|
|
void fb_perform_format(usb_handle* usb,
|
|
|
|
const char *partition, int skip_if_not_supported,
|
2014-05-07 06:14:15 +08:00
|
|
|
const char *type_override, const char *size_override)
|
2014-03-12 09:28:15 +08:00
|
|
|
{
|
2014-05-07 06:14:15 +08:00
|
|
|
char pTypeBuff[FB_RESPONSE_SZ + 1], pSizeBuff[FB_RESPONSE_SZ + 1];
|
|
|
|
char *pType = pTypeBuff;
|
|
|
|
char *pSize = pSizeBuff;
|
2014-03-12 09:28:15 +08:00
|
|
|
unsigned int limit = INT_MAX;
|
|
|
|
struct fastboot_buffer buf;
|
|
|
|
const char *errMsg = NULL;
|
|
|
|
const struct fs_generator *gen;
|
|
|
|
uint64_t pSz;
|
|
|
|
int status;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (target_sparse_limit > 0 && target_sparse_limit < limit)
|
|
|
|
limit = target_sparse_limit;
|
|
|
|
if (sparse_limit > 0 && sparse_limit < limit)
|
|
|
|
limit = sparse_limit;
|
|
|
|
|
|
|
|
status = fb_getvar(usb, pType, "partition-type:%s", partition);
|
|
|
|
if (status) {
|
|
|
|
errMsg = "Can't determine partition type.\n";
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-05-07 06:14:15 +08:00
|
|
|
if (type_override) {
|
|
|
|
if (strcmp(type_override, pType)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Warning: %s type is %s, but %s was requested for formating.\n",
|
|
|
|
partition, pType, type_override);
|
|
|
|
}
|
2014-05-01 05:05:28 +08:00
|
|
|
pType = (char *)type_override;
|
2014-05-07 06:14:15 +08:00
|
|
|
}
|
2014-03-12 09:28:15 +08:00
|
|
|
|
|
|
|
status = fb_getvar(usb, pSize, "partition-size:%s", partition);
|
|
|
|
if (status) {
|
|
|
|
errMsg = "Unable to get partition size\n";
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-05-07 06:14:15 +08:00
|
|
|
if (size_override) {
|
|
|
|
if (strcmp(size_override, pSize)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Warning: %s size is %s, but %s was requested for formating.\n",
|
|
|
|
partition, pSize, size_override);
|
|
|
|
}
|
2014-05-01 05:05:28 +08:00
|
|
|
pSize = (char *)size_override;
|
2014-05-07 06:14:15 +08:00
|
|
|
}
|
2014-03-12 09:28:15 +08:00
|
|
|
|
|
|
|
gen = fs_get_generator(pType);
|
|
|
|
if (!gen) {
|
|
|
|
if (skip_if_not_supported) {
|
|
|
|
fprintf(stderr, "Erase successful, but not automatically formatting.\n");
|
|
|
|
fprintf(stderr, "File system type %s not supported.\n", pType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "Formatting is not supported for filesystem with type '%s'.\n", pType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pSz = strtoll(pSize, (char **)NULL, 16);
|
|
|
|
|
|
|
|
fd = fileno(tmpfile());
|
|
|
|
if (fs_generator_generate(gen, fd, pSz)) {
|
|
|
|
close(fd);
|
|
|
|
fprintf(stderr, "Cannot generate image.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_buf_fd(usb, fd, &buf)) {
|
|
|
|
fprintf(stderr, "Cannot read image.\n");
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
flash_buf(partition, &buf);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
failed:
|
|
|
|
if (skip_if_not_supported) {
|
|
|
|
fprintf(stderr, "Erase successful, but not automatically formatting.\n");
|
|
|
|
if (errMsg)
|
|
|
|
fprintf(stderr, "%s", errMsg);
|
|
|
|
}
|
|
|
|
fprintf(stderr,"FAILED (%s)\n", fb_get_error());
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int wants_wipe = 0;
|
|
|
|
int wants_reboot = 0;
|
|
|
|
int wants_reboot_bootloader = 0;
|
2012-09-30 05:46:25 +08:00
|
|
|
int erase_first = 1;
|
2009-03-04 11:32:55 +08:00
|
|
|
void *data;
|
2014-05-08 07:31:59 +08:00
|
|
|
unsigned sz;
|
2010-04-24 03:38:51 +08:00
|
|
|
int status;
|
2012-05-23 08:53:34 +08:00
|
|
|
int c;
|
2014-11-24 18:29:34 +08:00
|
|
|
int longindex;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2013-03-08 09:06:41 +08:00
|
|
|
const struct option longopts[] = {
|
|
|
|
{"base", required_argument, 0, 'b'},
|
|
|
|
{"kernel_offset", required_argument, 0, 'k'},
|
|
|
|
{"page_size", required_argument, 0, 'n'},
|
|
|
|
{"ramdisk_offset", required_argument, 0, 'r'},
|
2014-01-15 10:27:25 +08:00
|
|
|
{"tags_offset", required_argument, 0, 't'},
|
2015-06-03 04:50:00 +08:00
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"unbuffered", no_argument, 0, 0},
|
|
|
|
{"version", no_argument, 0, 0},
|
2013-03-08 09:06:41 +08:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
2012-05-23 08:53:34 +08:00
|
|
|
|
|
|
|
serial = getenv("ANDROID_SERIAL");
|
|
|
|
|
|
|
|
while (1) {
|
2014-11-24 18:29:34 +08:00
|
|
|
c = getopt_long(argc, argv, "wub:k:n:r:t:s:S:lp:c:i:m:h", longopts, &longindex);
|
2012-05-23 08:53:34 +08:00
|
|
|
if (c < 0) {
|
|
|
|
break;
|
|
|
|
}
|
2013-03-08 09:06:41 +08:00
|
|
|
/* Alphabetical cases */
|
2012-05-23 08:53:34 +08:00
|
|
|
switch (c) {
|
|
|
|
case 'b':
|
|
|
|
base_addr = strtoul(optarg, 0, 16);
|
|
|
|
break;
|
2013-03-08 09:06:41 +08:00
|
|
|
case 'c':
|
|
|
|
cmdline = optarg;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
case 'i': {
|
|
|
|
char *endptr = NULL;
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
val = strtoul(optarg, &endptr, 0);
|
|
|
|
if (!endptr || *endptr != '\0' || (val & ~0xffff))
|
|
|
|
die("invalid vendor id '%s'", optarg);
|
|
|
|
vendor_id = (unsigned short)val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'k':
|
|
|
|
kernel_offset = strtoul(optarg, 0, 16);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
long_listing = 1;
|
|
|
|
break;
|
2012-05-23 08:53:34 +08:00
|
|
|
case 'n':
|
|
|
|
page_size = (unsigned)strtoul(optarg, NULL, 0);
|
|
|
|
if (!page_size) die("invalid page size");
|
|
|
|
break;
|
2013-03-08 09:06:41 +08:00
|
|
|
case 'p':
|
|
|
|
product = optarg;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
ramdisk_offset = strtoul(optarg, 0, 16);
|
|
|
|
break;
|
2014-01-15 10:27:25 +08:00
|
|
|
case 't':
|
|
|
|
tags_offset = strtoul(optarg, 0, 16);
|
|
|
|
break;
|
2012-05-23 08:53:34 +08:00
|
|
|
case 's':
|
|
|
|
serial = optarg;
|
|
|
|
break;
|
2012-05-25 08:18:41 +08:00
|
|
|
case 'S':
|
|
|
|
sparse_limit = parse_num(optarg);
|
|
|
|
if (sparse_limit < 0) {
|
|
|
|
die("invalid sparse limit");
|
|
|
|
}
|
|
|
|
break;
|
2013-03-08 09:06:41 +08:00
|
|
|
case 'u':
|
|
|
|
erase_first = 0;
|
2012-05-23 08:53:34 +08:00
|
|
|
break;
|
2013-03-08 09:06:41 +08:00
|
|
|
case 'w':
|
|
|
|
wants_wipe = 1;
|
2012-05-23 08:53:34 +08:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
return 1;
|
2014-11-24 18:29:34 +08:00
|
|
|
case 0:
|
|
|
|
if (strcmp("unbuffered", longopts[longindex].name) == 0) {
|
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
setvbuf(stderr, NULL, _IONBF, 0);
|
2015-06-03 04:50:00 +08:00
|
|
|
} else if (strcmp("version", longopts[longindex].name) == 0) {
|
|
|
|
fprintf(stdout, "fastboot version %s\n", FASTBOOT_REVISION);
|
|
|
|
return 0;
|
2014-11-24 18:29:34 +08:00
|
|
|
}
|
|
|
|
break;
|
2012-05-23 08:53:34 +08:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2012-05-23 08:53:34 +08:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc == 0 && !wants_wipe) {
|
2009-03-04 11:32:55 +08:00
|
|
|
usage();
|
2010-04-24 03:38:51 +08:00
|
|
|
return 1;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2012-07-25 07:36:41 +08:00
|
|
|
if (argc > 0 && !strcmp(*argv, "devices")) {
|
2012-05-23 08:53:34 +08:00
|
|
|
skip(1);
|
2009-03-04 11:32:55 +08:00
|
|
|
list_devices();
|
2011-02-26 10:38:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-30 09:17:06 +08:00
|
|
|
if (argc > 0 && !strcmp(*argv, "help")) {
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-03 04:34:07 +08:00
|
|
|
usb_handle* usb = open_device();
|
2009-10-08 06:38:53 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
while (argc > 0) {
|
2012-05-23 08:53:34 +08:00
|
|
|
if(!strcmp(*argv, "getvar")) {
|
2009-03-04 11:32:55 +08:00
|
|
|
require(2);
|
|
|
|
fb_queue_display(argv[1], argv[1]);
|
|
|
|
skip(2);
|
|
|
|
} else if(!strcmp(*argv, "erase")) {
|
|
|
|
require(2);
|
2012-09-30 05:46:25 +08:00
|
|
|
|
2014-05-07 06:14:15 +08:00
|
|
|
if (fb_format_supported(usb, argv[1], NULL)) {
|
2012-09-30 05:46:25 +08:00
|
|
|
fprintf(stderr, "******** Did you mean to fastboot format this partition?\n");
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
fb_queue_erase(argv[1]);
|
|
|
|
skip(2);
|
2014-05-07 06:14:15 +08:00
|
|
|
} else if(!strncmp(*argv, "format", strlen("format"))) {
|
|
|
|
char *overrides;
|
|
|
|
char *type_override = NULL;
|
|
|
|
char *size_override = NULL;
|
2011-12-16 09:50:18 +08:00
|
|
|
require(2);
|
2014-05-07 06:14:15 +08:00
|
|
|
/*
|
|
|
|
* Parsing for: "format[:[type][:[size]]]"
|
|
|
|
* Some valid things:
|
|
|
|
* - select ontly the size, and leave default fs type:
|
|
|
|
* format::0x4000000 userdata
|
|
|
|
* - default fs type and size:
|
|
|
|
* format userdata
|
|
|
|
* format:: userdata
|
|
|
|
*/
|
|
|
|
overrides = strchr(*argv, ':');
|
|
|
|
if (overrides) {
|
|
|
|
overrides++;
|
|
|
|
size_override = strchr(overrides, ':');
|
|
|
|
if (size_override) {
|
|
|
|
size_override[0] = '\0';
|
|
|
|
size_override++;
|
|
|
|
}
|
|
|
|
type_override = overrides;
|
|
|
|
}
|
|
|
|
if (type_override && !type_override[0]) type_override = NULL;
|
|
|
|
if (size_override && !size_override[0]) size_override = NULL;
|
2015-06-03 04:34:07 +08:00
|
|
|
if (erase_first && needs_erase(usb, argv[1])) {
|
2012-09-30 05:46:25 +08:00
|
|
|
fb_queue_erase(argv[1]);
|
|
|
|
}
|
2015-06-03 04:34:07 +08:00
|
|
|
fb_perform_format(usb, argv[1], 0, type_override, size_override);
|
2011-12-16 09:50:18 +08:00
|
|
|
skip(2);
|
2009-03-04 11:32:55 +08:00
|
|
|
} else if(!strcmp(*argv, "signature")) {
|
|
|
|
require(2);
|
|
|
|
data = load_file(argv[1], &sz);
|
2011-12-09 03:59:38 +08:00
|
|
|
if (data == 0) die("could not load '%s': %s", argv[1], strerror(errno));
|
2009-03-04 11:32:55 +08:00
|
|
|
if (sz != 256) die("signature must be 256 bytes");
|
|
|
|
fb_queue_download("signature", data, sz);
|
|
|
|
fb_queue_command("signature", "installing signature");
|
|
|
|
skip(2);
|
|
|
|
} else if(!strcmp(*argv, "reboot")) {
|
|
|
|
wants_reboot = 1;
|
|
|
|
skip(1);
|
2015-02-26 02:02:00 +08:00
|
|
|
if (argc > 0) {
|
|
|
|
if (!strcmp(*argv, "bootloader")) {
|
|
|
|
wants_reboot = 0;
|
|
|
|
wants_reboot_bootloader = 1;
|
|
|
|
skip(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require(0);
|
2009-03-04 11:32:55 +08:00
|
|
|
} else if(!strcmp(*argv, "reboot-bootloader")) {
|
|
|
|
wants_reboot_bootloader = 1;
|
|
|
|
skip(1);
|
|
|
|
} else if (!strcmp(*argv, "continue")) {
|
|
|
|
fb_queue_command("continue", "resuming boot");
|
|
|
|
skip(1);
|
|
|
|
} else if(!strcmp(*argv, "boot")) {
|
|
|
|
char *kname = 0;
|
|
|
|
char *rname = 0;
|
2014-07-17 23:17:54 +08:00
|
|
|
char *sname = 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
skip(1);
|
|
|
|
if (argc > 0) {
|
|
|
|
kname = argv[0];
|
|
|
|
skip(1);
|
|
|
|
}
|
|
|
|
if (argc > 0) {
|
|
|
|
rname = argv[0];
|
|
|
|
skip(1);
|
|
|
|
}
|
2014-07-17 23:17:54 +08:00
|
|
|
if (argc > 0) {
|
|
|
|
sname = argv[0];
|
|
|
|
skip(1);
|
|
|
|
}
|
|
|
|
data = load_bootable_image(kname, rname, sname, &sz, cmdline);
|
2009-03-04 11:32:55 +08:00
|
|
|
if (data == 0) return 1;
|
|
|
|
fb_queue_download("boot.img", data, sz);
|
|
|
|
fb_queue_command("boot", "booting");
|
|
|
|
} else if(!strcmp(*argv, "flash")) {
|
|
|
|
char *pname = argv[1];
|
|
|
|
char *fname = 0;
|
|
|
|
require(2);
|
|
|
|
if (argc > 2) {
|
|
|
|
fname = argv[2];
|
|
|
|
skip(3);
|
|
|
|
} else {
|
|
|
|
fname = find_item(pname, product);
|
|
|
|
skip(2);
|
|
|
|
}
|
|
|
|
if (fname == 0) die("cannot determine image filename for '%s'", pname);
|
2015-06-03 04:34:07 +08:00
|
|
|
if (erase_first && needs_erase(usb, pname)) {
|
2012-09-30 05:46:25 +08:00
|
|
|
fb_queue_erase(pname);
|
|
|
|
}
|
2012-05-25 08:18:41 +08:00
|
|
|
do_flash(usb, pname, fname);
|
2009-03-04 11:32:55 +08:00
|
|
|
} else if(!strcmp(*argv, "flash:raw")) {
|
|
|
|
char *pname = argv[1];
|
|
|
|
char *kname = argv[2];
|
|
|
|
char *rname = 0;
|
2014-07-17 23:17:54 +08:00
|
|
|
char *sname = 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
require(3);
|
2014-07-17 23:17:54 +08:00
|
|
|
skip(3);
|
|
|
|
if (argc > 0) {
|
|
|
|
rname = argv[0];
|
|
|
|
skip(1);
|
|
|
|
}
|
|
|
|
if (argc > 0) {
|
|
|
|
sname = argv[0];
|
|
|
|
skip(1);
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
2014-07-17 23:17:54 +08:00
|
|
|
data = load_bootable_image(kname, rname, sname, &sz, cmdline);
|
2009-03-04 11:32:55 +08:00
|
|
|
if (data == 0) die("cannot load bootable image");
|
|
|
|
fb_queue_flash(pname, data, sz);
|
|
|
|
} else if(!strcmp(*argv, "flashall")) {
|
|
|
|
skip(1);
|
2013-06-29 00:54:59 +08:00
|
|
|
do_flashall(usb, erase_first);
|
2009-03-04 11:32:55 +08:00
|
|
|
wants_reboot = 1;
|
|
|
|
} else if(!strcmp(*argv, "update")) {
|
|
|
|
if (argc > 1) {
|
2013-06-29 00:54:59 +08:00
|
|
|
do_update(usb, argv[1], erase_first);
|
2009-03-04 11:32:55 +08:00
|
|
|
skip(2);
|
|
|
|
} else {
|
2013-06-29 00:54:59 +08:00
|
|
|
do_update(usb, "update.zip", erase_first);
|
2009-03-04 11:32:55 +08:00
|
|
|
skip(1);
|
|
|
|
}
|
|
|
|
wants_reboot = 1;
|
|
|
|
} else if(!strcmp(*argv, "oem")) {
|
|
|
|
argc = do_oem_command(argc, argv);
|
2015-05-16 07:43:47 +08:00
|
|
|
} else if(!strcmp(*argv, "flashing") && argc == 2) {
|
|
|
|
if(!strcmp(*(argv+1), "unlock") || !strcmp(*(argv+1), "lock")
|
|
|
|
|| !strcmp(*(argv+1), "unlock_critical")
|
|
|
|
|| !strcmp(*(argv+1), "lock_critical")
|
|
|
|
|| !strcmp(*(argv+1), "get_unlock_ability")) {
|
|
|
|
argc = do_oem_command(argc, argv);
|
|
|
|
} else {
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
} else {
|
|
|
|
usage();
|
2011-02-26 10:38:53 +08:00
|
|
|
return 1;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wants_wipe) {
|
|
|
|
fb_queue_erase("userdata");
|
2015-06-03 04:34:07 +08:00
|
|
|
fb_perform_format(usb, "userdata", 1, NULL, NULL);
|
2009-03-04 11:32:55 +08:00
|
|
|
fb_queue_erase("cache");
|
2015-06-03 04:34:07 +08:00
|
|
|
fb_perform_format(usb, "cache", 1, NULL, NULL);
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
if (wants_reboot) {
|
|
|
|
fb_queue_reboot();
|
2014-06-24 23:04:54 +08:00
|
|
|
fb_queue_wait_for_disconnect();
|
2009-03-04 11:32:55 +08:00
|
|
|
} else if (wants_reboot_bootloader) {
|
|
|
|
fb_queue_command("reboot-bootloader", "rebooting into bootloader");
|
2013-10-02 21:35:38 +08:00
|
|
|
fb_queue_wait_for_disconnect();
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2012-04-07 03:39:30 +08:00
|
|
|
if (fb_queue_is_empty())
|
|
|
|
return 0;
|
|
|
|
|
2010-04-24 03:38:51 +08:00
|
|
|
status = fb_execute_queue(usb);
|
|
|
|
return (status) ? 1 : 0;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|