2009-03-04 04:32:55 +01: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 03:38:53 +01:00
|
|
|
* the documentation and/or other materials provided with the
|
2009-03-04 04:32:55 +01: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 03:38:53 +01:00
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
2009-03-04 04:32:55 +01: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 02:18:41 +02:00
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2012-05-25 02:18:41 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <ctype.h>
|
2012-05-23 02:53:34 +02:00
|
|
|
#include <getopt.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
2012-05-25 02:18:41 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <bootimg.h>
|
2012-05-25 02:18:41 +02:00
|
|
|
#include <sparse/sparse.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <zipfile/zipfile.h>
|
|
|
|
|
|
|
|
#include "fastboot.h"
|
|
|
|
|
2012-05-25 02:18:41 +02:00
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2011-04-05 02:54:59 +02:00
|
|
|
char cur_product[FB_RESPONSE_SZ + 1];
|
|
|
|
|
2009-04-29 01:05:07 +02:00
|
|
|
void bootimg_set_cmdline(boot_img_hdr *h, const char *cmdline);
|
|
|
|
|
|
|
|
boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size,
|
|
|
|
void *ramdisk, unsigned ramdisk_size,
|
|
|
|
void *second, unsigned second_size,
|
|
|
|
unsigned page_size, unsigned base,
|
|
|
|
unsigned *bootimg_size);
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
static usb_handle *usb = 0;
|
|
|
|
static const char *serial = 0;
|
|
|
|
static const char *product = 0;
|
|
|
|
static const char *cmdline = 0;
|
|
|
|
static int wipe_data = 0;
|
|
|
|
static unsigned short vendor_id = 0;
|
2012-04-06 21:39:30 +02:00
|
|
|
static int long_listing = 0;
|
2012-05-25 02:18:41 +02:00
|
|
|
static int64_t sparse_limit = -1;
|
|
|
|
static int64_t target_sparse_limit = -1;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2009-04-29 01:05:07 +02:00
|
|
|
static unsigned base_addr = 0x10000000;
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
void die(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr,"error: ");
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
va_end(ap);
|
|
|
|
exit(1);
|
2011-02-26 03:38:53 +01:00
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
void get_my_path(char *path);
|
|
|
|
|
|
|
|
char *find_item(const char *item, const char *product)
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
char *fn;
|
|
|
|
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";
|
|
|
|
} else if(!strcmp(item,"userdata")) {
|
|
|
|
fn = "userdata.img";
|
2011-09-30 23:39:25 +02:00
|
|
|
} else if(!strcmp(item,"cache")) {
|
|
|
|
fn = "cache.img";
|
2009-03-04 04:32:55 +01: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 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01: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 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
sprintf(path, "%s/%s", dir, fn);
|
|
|
|
return strdup(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
void *load_file(const char *fn, unsigned *_sz);
|
2012-05-25 02:18:41 +02:00
|
|
|
int64_t file_size(const char *fn);
|
2009-03-04 04:32:55 +01:00
|
|
|
#else
|
2012-05-25 02:18:41 +02:00
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
|
|
|
#define lseek64 lseek
|
|
|
|
#define off64_t off_t
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int64_t file_size(const char *fn)
|
|
|
|
{
|
|
|
|
off64_t off;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(fn, O_RDONLY);
|
|
|
|
if (fd < 0) return -1;
|
|
|
|
|
|
|
|
off = lseek64(fd, 0, SEEK_END);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return off;
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
void *load_file(const char *fn, unsigned *_sz)
|
|
|
|
{
|
|
|
|
char *data;
|
|
|
|
int sz;
|
|
|
|
int fd;
|
2011-12-08 20:59:38 +01:00
|
|
|
int errno_tmp;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
data = 0;
|
|
|
|
fd = open(fn, O_RDONLY);
|
|
|
|
if(fd < 0) return 0;
|
|
|
|
|
|
|
|
sz = lseek(fd, 0, SEEK_END);
|
|
|
|
if(sz < 0) goto oops;
|
|
|
|
|
|
|
|
if(lseek(fd, 0, SEEK_SET) != 0) goto oops;
|
|
|
|
|
|
|
|
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-08 20:59:38 +01:00
|
|
|
errno_tmp = errno;
|
2009-03-04 04:32:55 +01:00
|
|
|
close(fd);
|
|
|
|
if(data != 0) free(data);
|
2011-12-08 20:59:38 +01:00
|
|
|
errno = errno_tmp;
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int match_fastboot(usb_ifc_info *info)
|
2012-06-06 20:53:33 +02:00
|
|
|
{
|
|
|
|
return match_fastboot_with_serial(info, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
int match_fastboot_with_serial(usb_ifc_info *info, const char *local_serial)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
|
|
|
if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
|
2009-08-05 23:04:36 +02:00
|
|
|
(info->dev_vendor != 0x18d1) && // Google
|
2012-01-17 21:04:11 +01:00
|
|
|
(info->dev_vendor != 0x8087) && // Intel
|
2009-03-19 01:39:49 +01:00
|
|
|
(info->dev_vendor != 0x0451) &&
|
2009-09-21 03:51:35 +02:00
|
|
|
(info->dev_vendor != 0x0502) &&
|
2010-05-14 23:48:30 +02:00
|
|
|
(info->dev_vendor != 0x0fce) && // Sony Ericsson
|
|
|
|
(info->dev_vendor != 0x05c6) && // Qualcomm
|
2009-08-05 23:04:36 +02:00
|
|
|
(info->dev_vendor != 0x22b8) && // Motorola
|
2010-01-21 02:40:05 +01:00
|
|
|
(info->dev_vendor != 0x0955) && // Nvidia
|
2010-01-22 02:39:25 +01:00
|
|
|
(info->dev_vendor != 0x413c) && // DELL
|
2012-01-14 01:03:37 +01:00
|
|
|
(info->dev_vendor != 0x2314) && // INQ Mobile
|
2012-02-24 22:00:34 +01:00
|
|
|
(info->dev_vendor != 0x0b05) && // Asus
|
2009-08-05 23:04:36 +02:00
|
|
|
(info->dev_vendor != 0x0bb4)) // HTC
|
|
|
|
return -1;
|
2009-03-04 04:32:55 +01:00
|
|
|
if(info->ifc_class != 0xff) return -1;
|
|
|
|
if(info->ifc_subclass != 0x42) return -1;
|
|
|
|
if(info->ifc_protocol != 0x03) return -1;
|
2012-04-06 21:39:30 +02:00
|
|
|
// require matching serial number or device path if requested
|
2009-03-04 04:32:55 +01:00
|
|
|
// at the command line with the -s option.
|
2012-06-06 20:53:33 +02:00
|
|
|
if (local_serial && (strcmp(local_serial, info->serial_number) != 0 &&
|
|
|
|
strcmp(local_serial, info->device_path) != 0)) return -1;
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int list_devices_callback(usb_ifc_info *info)
|
|
|
|
{
|
2012-06-06 20:53:33 +02:00
|
|
|
if (match_fastboot_with_serial(info, NULL) == 0) {
|
2009-03-04 04:32:55 +01:00
|
|
|
char* serial = info->serial_number;
|
2009-10-07 03:07:49 +02:00
|
|
|
if (!info->writable) {
|
|
|
|
serial = "no permissions"; // like "adb devices"
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
if (!serial[0]) {
|
|
|
|
serial = "????????????";
|
|
|
|
}
|
2012-06-05 05:29:11 +02:00
|
|
|
// output compatible with "adb devices"
|
2012-04-06 21:39:30 +02:00
|
|
|
if (!long_listing) {
|
|
|
|
printf("%s\tfastboot\n", serial);
|
2012-06-05 05:29:11 +02:00
|
|
|
} else if (!info->device_path) {
|
|
|
|
printf("%-22s fastboot\n", serial);
|
2012-04-06 21:39:30 +02:00
|
|
|
} else {
|
2012-06-05 05:29:11 +02:00
|
|
|
printf("%-22s fastboot %s\n", serial, info->device_path);
|
2012-04-06 21:39:30 +02:00
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_handle *open_device(void)
|
|
|
|
{
|
|
|
|
static usb_handle *usb = 0;
|
|
|
|
int announce = 1;
|
|
|
|
|
|
|
|
if(usb) return usb;
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
for(;;) {
|
|
|
|
usb = usb_open(match_fastboot);
|
|
|
|
if(usb) return usb;
|
|
|
|
if(announce) {
|
2011-02-26 03:38:53 +01:00
|
|
|
announce = 0;
|
2009-03-04 04:32:55 +01:00
|
|
|
fprintf(stderr,"< waiting for device >\n");
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
" update <filename> reflash device from update.zip\n"
|
|
|
|
" flashall flash boot + recovery + system\n"
|
|
|
|
" flash <partition> [ <filename> ] write a file to a flash partition\n"
|
|
|
|
" erase <partition> erase a flash partition\n"
|
2011-12-16 02:50:18 +01:00
|
|
|
" format <partition> format a flash partition \n"
|
2009-03-04 04:32:55 +01:00
|
|
|
" getvar <variable> display a bootloader variable\n"
|
|
|
|
" boot <kernel> [ <ramdisk> ] download and boot kernel\n"
|
|
|
|
" flash:raw boot <kernel> [ <ramdisk> ] create bootimage and flash it\n"
|
|
|
|
" devices list all connected devices\n"
|
2010-10-14 18:43:26 +02:00
|
|
|
" continue continue with autoboot\n"
|
2009-03-04 04:32:55 +01:00
|
|
|
" reboot reboot device normally\n"
|
|
|
|
" reboot-bootloader reboot device into bootloader\n"
|
2011-02-26 03:38:53 +01:00
|
|
|
" help show this help message\n"
|
2009-03-04 04:32:55 +01:00
|
|
|
"\n"
|
|
|
|
"options:\n"
|
2012-09-29 23:46:25 +02:00
|
|
|
" -w erase userdata and cache (and format\n"
|
|
|
|
" if supported by partition type)\n"
|
|
|
|
" -u do not first erase partition before\n"
|
|
|
|
" formatting\n"
|
2012-04-06 21:39:30 +02:00
|
|
|
" -s <specific device> specify device serial number\n"
|
|
|
|
" or path to device port\n"
|
|
|
|
" -l with \"devices\", lists device paths\n"
|
2009-03-04 04:32:55 +01:00
|
|
|
" -p <product> specify product name\n"
|
|
|
|
" -c <cmdline> override kernel commandline\n"
|
|
|
|
" -i <vendor id> specify a custom USB vendor id\n"
|
2009-05-01 00:03:05 +02:00
|
|
|
" -b <base_addr> specify a custom kernel base address\n"
|
2010-02-13 05:26:33 +01:00
|
|
|
" -n <page size> specify the nand page size. default: 2048\n"
|
2012-05-25 02:18:41 +02:00
|
|
|
" -S <size>[K|M|G] automatically sparse files greater than\n"
|
2012-07-25 03:05:21 +02:00
|
|
|
" size. 0 to disable\n"
|
2009-03-04 04:32:55 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-02-13 05:26:33 +01:00
|
|
|
void *load_bootable_image(unsigned page_size, const char *kernel, const char *ramdisk,
|
2009-03-04 04:32:55 +01:00
|
|
|
unsigned *sz, const char *cmdline)
|
|
|
|
{
|
|
|
|
void *kdata = 0, *rdata = 0;
|
|
|
|
unsigned ksize = 0, rsize = 0;
|
|
|
|
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-08 20:59:38 +01:00
|
|
|
fprintf(stderr, "cannot load '%s': %s\n", kernel, strerror(errno));
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01: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 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(ramdisk) {
|
|
|
|
fprintf(stderr, "cannot boot a boot.img *and* ramdisk\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
*sz = ksize;
|
|
|
|
return kdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ramdisk) {
|
|
|
|
rdata = load_file(ramdisk, &rsize);
|
|
|
|
if(rdata == 0) {
|
2011-12-08 20:59:38 +01:00
|
|
|
fprintf(stderr,"cannot load '%s': %s\n", ramdisk, strerror(errno));
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr,"creating boot image...\n");
|
2010-02-13 05:26:33 +01:00
|
|
|
bdata = mkbootimg(kdata, ksize, rdata, rsize, 0, 0, page_size, base_addr, &bsize);
|
2009-03-04 04:32:55 +01: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 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
return bdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
zipentry_t entry;
|
|
|
|
unsigned datasz;
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
entry = lookup_zipentry(zip, name);
|
|
|
|
if (entry == NULL) {
|
|
|
|
fprintf(stderr, "archive does not contain '%s'\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sz = get_zipentry_size(entry);
|
|
|
|
|
|
|
|
datasz = *sz * 1.001;
|
|
|
|
data = malloc(datasz);
|
|
|
|
|
|
|
|
if(data == 0) {
|
|
|
|
fprintf(stderr, "failed to allocate %d bytes\n", *sz);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decompress_zipentry(entry, data, datasz)) {
|
|
|
|
fprintf(stderr, "failed to unzip '%s' from archive\n", name);
|
|
|
|
free(data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
const char **out;
|
2011-04-05 02:54:59 +02:00
|
|
|
char *prod = NULL;
|
2009-03-04 04:32:55 +01:00
|
|
|
unsigned n, count;
|
|
|
|
char *x;
|
|
|
|
int invert = 0;
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if (!strncmp(name, "reject ", 7)) {
|
|
|
|
name += 7;
|
|
|
|
invert = 1;
|
|
|
|
} else if (!strncmp(name, "require ", 8)) {
|
|
|
|
name += 8;
|
|
|
|
invert = 0;
|
2011-04-05 02:54:59 +02: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 04:32:55 +01: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 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
name = strip(name);
|
|
|
|
for(n = 0; n < count; n++) val[n] = strip(val[n]);
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
name = strip(name);
|
|
|
|
if (name == 0) return -1;
|
|
|
|
|
|
|
|
/* work around an unfortunate name mismatch */
|
|
|
|
if (!strcmp(name,"board")) name = "product";
|
|
|
|
|
|
|
|
out = malloc(sizeof(char*) * count);
|
|
|
|
if (out == 0) return -1;
|
|
|
|
|
|
|
|
for(n = 0; n < count; n++) {
|
|
|
|
out[n] = strdup(strip(val[n]));
|
|
|
|
if (out[n] == 0) return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-05 02:54:59 +02:00
|
|
|
fb_queue_require(prod, name, invert, n, out);
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_requirements(char *data, unsigned sz)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = data;
|
|
|
|
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("--------------------------------------------");
|
|
|
|
}
|
|
|
|
|
2012-05-25 02:18:41 +02:00
|
|
|
|
|
|
|
struct sparse_file **load_sparse_files(const char *fname, int max_size)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
struct sparse_file *s;
|
|
|
|
int files;
|
|
|
|
struct sparse_file **out_s;
|
|
|
|
|
|
|
|
fd = open(fname, O_RDONLY | O_BINARY);
|
|
|
|
if (fd < 0) {
|
|
|
|
die("cannot open '%s'\n", fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = sparse_file_import_auto(fd, false);
|
|
|
|
if (!s) {
|
|
|
|
die("cannot sparse read file '%s'\n", fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
files = sparse_file_resparse(s, max_size, NULL, 0);
|
|
|
|
if (files < 0) {
|
|
|
|
die("Failed to resparse '%s'\n", fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
out_s = calloc(sizeof(struct sparse_file *), files + 1);
|
|
|
|
if (!out_s) {
|
|
|
|
die("Failed to allocate sparse file array\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
files = sparse_file_resparse(s, max_size, out_s, files);
|
|
|
|
if (files < 0) {
|
|
|
|
die("Failed to resparse '%s'\n", fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "target reported max download size of %lld bytes\n",
|
|
|
|
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 03:05:21 +02:00
|
|
|
return 0;
|
2012-05-25 02:18:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > limit) {
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-29 23:46:25 +02: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.
|
|
|
|
*/
|
|
|
|
static int needs_erase(const char *part)
|
|
|
|
{
|
|
|
|
/* The function fb_format_supported() currently returns the value
|
|
|
|
* we want, so just call it.
|
|
|
|
*/
|
|
|
|
return fb_format_supported(usb, part);
|
|
|
|
}
|
|
|
|
|
2012-05-25 02:18:41 +02:00
|
|
|
void do_flash(usb_handle *usb, const char *pname, const char *fname)
|
|
|
|
{
|
|
|
|
int64_t sz64;
|
|
|
|
void *data;
|
|
|
|
int64_t limit;
|
|
|
|
|
|
|
|
sz64 = file_size(fname);
|
|
|
|
limit = get_sparse_limit(usb, sz64);
|
|
|
|
if (limit) {
|
|
|
|
struct sparse_file **s = load_sparse_files(fname, limit);
|
|
|
|
if (s == NULL) {
|
|
|
|
die("cannot sparse load '%s'\n", fname);
|
|
|
|
}
|
|
|
|
while (*s) {
|
|
|
|
sz64 = sparse_file_len(*s, true, false);
|
|
|
|
fb_queue_flash_sparse(pname, *s++, sz64);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned int sz;
|
|
|
|
data = load_file(fname, &sz);
|
2011-12-08 20:59:38 +01:00
|
|
|
if (data == 0) die("cannot load '%s': %s\n", fname, strerror(errno));
|
2012-05-25 02:18:41 +02:00
|
|
|
fb_queue_flash(pname, data, sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
void do_update_signature(zipfile_t zip, char *fn)
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
unsigned sz;
|
|
|
|
data = unzip_file(zip, fn, &sz);
|
|
|
|
if (data == 0) return;
|
|
|
|
fb_queue_download("signature", data, sz);
|
|
|
|
fb_queue_command("signature", "installing signature");
|
|
|
|
}
|
|
|
|
|
2012-09-29 23:46:25 +02:00
|
|
|
void do_update(char *fn, int erase_first)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
|
|
|
void *zdata;
|
|
|
|
unsigned zsize;
|
|
|
|
void *data;
|
|
|
|
unsigned sz;
|
|
|
|
zipfile_t zip;
|
|
|
|
|
|
|
|
queue_info_dump();
|
|
|
|
|
2011-04-05 02:54:59 +02:00
|
|
|
fb_queue_query_save("product", cur_product, sizeof(cur_product));
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
zdata = load_file(fn, &zsize);
|
2011-12-08 20:59:38 +01:00
|
|
|
if (zdata == 0) die("failed to load '%s': %s", fn, strerror(errno));
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
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");
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase("boot")) {
|
|
|
|
fb_queue_erase("boot");
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
fb_queue_flash("boot", data, sz);
|
|
|
|
|
|
|
|
data = unzip_file(zip, "recovery.img", &sz);
|
|
|
|
if (data != 0) {
|
|
|
|
do_update_signature(zip, "recovery.sig");
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase("recovery")) {
|
|
|
|
fb_queue_erase("recovery");
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
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");
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase("system")) {
|
|
|
|
fb_queue_erase("system");
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
fb_queue_flash("system", data, sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_send_signature(char *fn)
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
unsigned sz;
|
|
|
|
char *xtn;
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
xtn = strrchr(fn, '.');
|
|
|
|
if (!xtn) return;
|
|
|
|
if (strcmp(xtn, ".img")) return;
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01: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");
|
|
|
|
}
|
|
|
|
|
2012-09-29 23:46:25 +02:00
|
|
|
void do_flashall(int erase_first)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
|
|
|
char *fname;
|
|
|
|
void *data;
|
|
|
|
unsigned sz;
|
|
|
|
|
|
|
|
queue_info_dump();
|
|
|
|
|
2011-04-05 02:54:59 +02:00
|
|
|
fb_queue_query_save("product", cur_product, sizeof(cur_product));
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
fname = find_item("info", product);
|
|
|
|
if (fname == 0) die("cannot find android-info.txt");
|
|
|
|
data = load_file(fname, &sz);
|
2011-12-08 20:59:38 +01:00
|
|
|
if (data == 0) die("could not load android-info.txt: %s", strerror(errno));
|
2009-03-04 04:32:55 +01:00
|
|
|
setup_requirements(data, sz);
|
|
|
|
|
|
|
|
fname = find_item("boot", product);
|
|
|
|
data = load_file(fname, &sz);
|
2011-12-08 20:59:38 +01:00
|
|
|
if (data == 0) die("could not load boot.img: %s", strerror(errno));
|
2009-03-04 04:32:55 +01:00
|
|
|
do_send_signature(fname);
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase("boot")) {
|
|
|
|
fb_queue_erase("boot");
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
fb_queue_flash("boot", data, sz);
|
|
|
|
|
|
|
|
fname = find_item("recovery", product);
|
|
|
|
data = load_file(fname, &sz);
|
|
|
|
if (data != 0) {
|
|
|
|
do_send_signature(fname);
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase("recovery")) {
|
|
|
|
fb_queue_erase("recovery");
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
fb_queue_flash("recovery", data, sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
fname = find_item("system", product);
|
|
|
|
data = load_file(fname, &sz);
|
2011-12-08 20:59:38 +01:00
|
|
|
if (data == 0) die("could not load system.img: %s", strerror(errno));
|
2009-03-04 04:32:55 +01:00
|
|
|
do_send_signature(fname);
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase("system")) {
|
|
|
|
fb_queue_erase("system");
|
|
|
|
}
|
2011-02-26 03:38:53 +01:00
|
|
|
fb_queue_flash("system", data, sz);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define skip(n) do { argc -= (n); argv += (n); } while (0)
|
2011-03-02 08:35:07 +01:00
|
|
|
#define require(n) do { if (argc < (n)) {usage(); exit(1);}} while (0)
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
int do_oem_command(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char command[256];
|
|
|
|
if (argc <= 1) return 0;
|
2011-02-26 03:38:53 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
command[0] = 0;
|
|
|
|
while(1) {
|
|
|
|
strcat(command,*argv);
|
|
|
|
skip(1);
|
|
|
|
if(argc == 0) break;
|
|
|
|
strcat(command," ");
|
|
|
|
}
|
|
|
|
|
2011-02-26 03:38:53 +01:00
|
|
|
fb_queue_command(command,"");
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-25 02:18:41 +02: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;
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int wants_wipe = 0;
|
|
|
|
int wants_reboot = 0;
|
|
|
|
int wants_reboot_bootloader = 0;
|
2012-09-29 23:46:25 +02:00
|
|
|
int erase_first = 1;
|
2009-03-04 04:32:55 +01:00
|
|
|
void *data;
|
|
|
|
unsigned sz;
|
2010-02-13 05:26:33 +01:00
|
|
|
unsigned page_size = 2048;
|
2010-04-23 21:38:51 +02:00
|
|
|
int status;
|
2012-05-23 02:53:34 +02:00
|
|
|
int c;
|
2012-05-25 02:18:41 +02:00
|
|
|
int r;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2012-05-25 02:18:41 +02:00
|
|
|
const struct option longopts = { 0, 0, 0, 0 };
|
2012-05-23 02:53:34 +02:00
|
|
|
|
|
|
|
serial = getenv("ANDROID_SERIAL");
|
|
|
|
|
|
|
|
while (1) {
|
2012-09-29 23:46:25 +02:00
|
|
|
c = getopt_long(argc, argv, "wub:n:s:S:lp:c:i:m:h", &longopts, NULL);
|
2012-05-23 02:53:34 +02:00
|
|
|
if (c < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'w':
|
|
|
|
wants_wipe = 1;
|
|
|
|
break;
|
2012-09-29 23:46:25 +02:00
|
|
|
case 'u':
|
|
|
|
erase_first = 0;
|
|
|
|
break;
|
2012-05-23 02:53:34 +02:00
|
|
|
case 'b':
|
|
|
|
base_addr = strtoul(optarg, 0, 16);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
page_size = (unsigned)strtoul(optarg, NULL, 0);
|
|
|
|
if (!page_size) die("invalid page size");
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
serial = optarg;
|
|
|
|
break;
|
2012-05-25 02:18:41 +02:00
|
|
|
case 'S':
|
|
|
|
sparse_limit = parse_num(optarg);
|
|
|
|
if (sparse_limit < 0) {
|
|
|
|
die("invalid sparse limit");
|
|
|
|
}
|
|
|
|
break;
|
2012-07-18 08:35:21 +02:00
|
|
|
case 'l':
|
|
|
|
long_listing = 1;
|
|
|
|
break;
|
2012-05-23 02:53:34 +02:00
|
|
|
case 'p':
|
|
|
|
product = optarg;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cmdline = optarg;
|
|
|
|
break;
|
|
|
|
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 'h':
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
case '?':
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2012-05-23 02:53:34 +02:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc == 0 && !wants_wipe) {
|
2009-03-04 04:32:55 +01:00
|
|
|
usage();
|
2010-04-23 21:38:51 +02:00
|
|
|
return 1;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2012-07-25 01:36:41 +02:00
|
|
|
if (argc > 0 && !strcmp(*argv, "devices")) {
|
2012-05-23 02:53:34 +02:00
|
|
|
skip(1);
|
2009-03-04 04:32:55 +01:00
|
|
|
list_devices();
|
2011-02-26 03:38:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-30 03:17:06 +02:00
|
|
|
if (argc > 0 && !strcmp(*argv, "help")) {
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-23 02:53:34 +02:00
|
|
|
usb = open_device();
|
2009-10-08 00:38:53 +02:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
while (argc > 0) {
|
2012-05-23 02:53:34 +02:00
|
|
|
if(!strcmp(*argv, "getvar")) {
|
2009-03-04 04:32:55 +01:00
|
|
|
require(2);
|
|
|
|
fb_queue_display(argv[1], argv[1]);
|
|
|
|
skip(2);
|
|
|
|
} else if(!strcmp(*argv, "erase")) {
|
|
|
|
require(2);
|
2012-09-29 23:46:25 +02:00
|
|
|
|
|
|
|
if (fb_format_supported(usb, argv[1])) {
|
|
|
|
fprintf(stderr, "******** Did you mean to fastboot format this partition?\n");
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
fb_queue_erase(argv[1]);
|
|
|
|
skip(2);
|
2011-12-16 02:50:18 +01:00
|
|
|
} else if(!strcmp(*argv, "format")) {
|
|
|
|
require(2);
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase(argv[1])) {
|
|
|
|
fb_queue_erase(argv[1]);
|
|
|
|
}
|
2012-05-08 05:25:24 +02:00
|
|
|
fb_queue_format(argv[1], 0);
|
2011-12-16 02:50:18 +01:00
|
|
|
skip(2);
|
2009-03-04 04:32:55 +01:00
|
|
|
} else if(!strcmp(*argv, "signature")) {
|
|
|
|
require(2);
|
|
|
|
data = load_file(argv[1], &sz);
|
2011-12-08 20:59:38 +01:00
|
|
|
if (data == 0) die("could not load '%s': %s", argv[1], strerror(errno));
|
2009-03-04 04:32:55 +01: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);
|
|
|
|
} 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;
|
|
|
|
skip(1);
|
|
|
|
if (argc > 0) {
|
|
|
|
kname = argv[0];
|
|
|
|
skip(1);
|
|
|
|
}
|
|
|
|
if (argc > 0) {
|
|
|
|
rname = argv[0];
|
|
|
|
skip(1);
|
|
|
|
}
|
2010-02-13 05:26:33 +01:00
|
|
|
data = load_bootable_image(page_size, kname, rname, &sz, cmdline);
|
2009-03-04 04:32:55 +01: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);
|
2012-09-29 23:46:25 +02:00
|
|
|
if (erase_first && needs_erase(pname)) {
|
|
|
|
fb_queue_erase(pname);
|
|
|
|
}
|
2012-05-25 02:18:41 +02:00
|
|
|
do_flash(usb, pname, fname);
|
2009-03-04 04:32:55 +01:00
|
|
|
} else if(!strcmp(*argv, "flash:raw")) {
|
|
|
|
char *pname = argv[1];
|
|
|
|
char *kname = argv[2];
|
|
|
|
char *rname = 0;
|
|
|
|
require(3);
|
|
|
|
if(argc > 3) {
|
|
|
|
rname = argv[3];
|
|
|
|
skip(4);
|
|
|
|
} else {
|
|
|
|
skip(3);
|
|
|
|
}
|
2010-02-13 05:26:33 +01:00
|
|
|
data = load_bootable_image(page_size, kname, rname, &sz, cmdline);
|
2009-03-04 04:32:55 +01:00
|
|
|
if (data == 0) die("cannot load bootable image");
|
|
|
|
fb_queue_flash(pname, data, sz);
|
|
|
|
} else if(!strcmp(*argv, "flashall")) {
|
|
|
|
skip(1);
|
2012-09-29 23:46:25 +02:00
|
|
|
do_flashall(erase_first);
|
2009-03-04 04:32:55 +01:00
|
|
|
wants_reboot = 1;
|
|
|
|
} else if(!strcmp(*argv, "update")) {
|
|
|
|
if (argc > 1) {
|
2012-09-29 23:46:25 +02:00
|
|
|
do_update(argv[1], erase_first);
|
2009-03-04 04:32:55 +01:00
|
|
|
skip(2);
|
|
|
|
} else {
|
2012-09-29 23:46:25 +02:00
|
|
|
do_update("update.zip", erase_first);
|
2009-03-04 04:32:55 +01:00
|
|
|
skip(1);
|
|
|
|
}
|
|
|
|
wants_reboot = 1;
|
|
|
|
} else if(!strcmp(*argv, "oem")) {
|
|
|
|
argc = do_oem_command(argc, argv);
|
|
|
|
} else {
|
|
|
|
usage();
|
2011-02-26 03:38:53 +01:00
|
|
|
return 1;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wants_wipe) {
|
|
|
|
fb_queue_erase("userdata");
|
2012-05-08 05:25:24 +02:00
|
|
|
fb_queue_format("userdata", 1);
|
2009-03-04 04:32:55 +01:00
|
|
|
fb_queue_erase("cache");
|
2012-05-08 05:25:24 +02:00
|
|
|
fb_queue_format("cache", 1);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
if (wants_reboot) {
|
|
|
|
fb_queue_reboot();
|
|
|
|
} else if (wants_reboot_bootloader) {
|
|
|
|
fb_queue_command("reboot-bootloader", "rebooting into bootloader");
|
|
|
|
}
|
|
|
|
|
2012-04-06 21:39:30 +02:00
|
|
|
if (fb_queue_is_empty())
|
|
|
|
return 0;
|
|
|
|
|
2010-04-23 21:38:51 +02:00
|
|
|
status = fb_execute_queue(usb);
|
|
|
|
return (status) ? 1 : 0;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|