diff options
Diffstat (limited to 'fastboot')
-rw-r--r-- | fastboot/Android.mk | 3 | ||||
-rw-r--r-- | fastboot/engine.c | 25 | ||||
-rw-r--r-- | fastboot/fastboot.c | 124 | ||||
-rw-r--r-- | fastboot/fastboot.h | 2 | ||||
-rw-r--r-- | fastboot/fs.c | 4 | ||||
-rw-r--r-- | fastboot/fs.h | 4 | ||||
-rw-r--r-- | fastboot/protocol.c | 3 | ||||
-rw-r--r-- | fastboot/usb_linux.c | 3 | ||||
-rw-r--r-- | fastboot/usb_windows.c | 8 | ||||
-rw-r--r-- | fastboot/usbtest.c | 14 |
10 files changed, 120 insertions, 70 deletions
diff --git a/fastboot/Android.mk b/fastboot/Android.mk index 05ddf2a..73794a0 100644 --- a/fastboot/Android.mk +++ b/fastboot/Android.mk @@ -21,7 +21,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../mkbootimg \ LOCAL_SRC_FILES := protocol.c engine.c bootimg.c fastboot.c util.c fs.c LOCAL_MODULE := fastboot LOCAL_MODULE_TAGS := debug -LOCAL_CFLAGS += -std=gnu99 +LOCAL_CFLAGS += -std=gnu99 -Werror ifeq ($(HOST_OS),linux) LOCAL_SRC_FILES += usb_linux.c util_linux.c @@ -72,6 +72,7 @@ ifeq ($(HOST_OS),linux) include $(CLEAR_VARS) LOCAL_SRC_FILES := usbtest.c usb_linux.c util.c LOCAL_MODULE := usbtest +LOCAL_CFLAGS := -Werror include $(BUILD_HOST_EXECUTABLE) endif diff --git a/fastboot/engine.c b/fastboot/engine.c index 0fab703..2f90e41 100644 --- a/fastboot/engine.c +++ b/fastboot/engine.c @@ -30,10 +30,10 @@ #include "fs.h" #include <errno.h> -#include <stdio.h> -#include <stdlib.h> #include <stdarg.h> #include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> @@ -45,6 +45,10 @@ #include <sys/mman.h> #endif +#ifndef __unused +#define __unused __attribute__((__unused__)) +#endif + #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define OP_DOWNLOAD 1 @@ -102,18 +106,19 @@ int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...) * Not all devices report the filesystem type, so don't report any errors, * just return false. */ -int fb_format_supported(usb_handle *usb, const char *partition) +int fb_format_supported(usb_handle *usb, const char *partition, const char *type_override) { - char response[FB_RESPONSE_SZ + 1] = {0,}; + char fs_type[FB_RESPONSE_SZ + 1] = {0,}; int status; - unsigned int i; - status = fb_getvar(usb, response, "partition-type:%s", partition); + if (type_override) { + return !!fs_get_generator(type_override); + } + status = fb_getvar(usb, fs_type, "partition-type:%s", partition); if (status) { return 0; } - - return !!fs_get_generator(response); + return !!fs_get_generator(fs_type); } static int cb_default(Action *a, int status, char *resp) @@ -195,9 +200,7 @@ void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz) static int match(char *str, const char **value, unsigned count) { - const char *val; unsigned n; - int len; for (n = 0; n < count; n++) { const char *val = value[n]; @@ -323,7 +326,7 @@ void fb_queue_query_save(const char *var, char *dest, unsigned dest_size) a->func = cb_save; } -static int cb_do_nothing(Action *a, int status, char *resp) +static int cb_do_nothing(Action *a __unused, int status __unused, char *resp __unused) { fprintf(stderr,"\n"); return 0; diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c index 4fd1a8e..266d0b5 100644 --- a/fastboot/fastboot.c +++ b/fastboot/fastboot.c @@ -28,21 +28,21 @@ #define _LARGEFILE64_SOURCE -#include <stdio.h> -#include <stdlib.h> -#include <stdbool.h> -#include <stdint.h> -#include <string.h> +#include <ctype.h> #include <errno.h> #include <fcntl.h> -#include <unistd.h> -#include <limits.h> -#include <ctype.h> #include <getopt.h> - +#include <inttypes.h> +#include <limits.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> -#include <sys/stat.h> +#include <unistd.h> #include <bootimg.h> #include <sparse/sparse.h> @@ -71,7 +71,6 @@ 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; static int long_listing = 0; static int64_t sparse_limit = -1; @@ -100,10 +99,11 @@ static struct { char sig_name[13]; char part_name[9]; bool is_optional; -} images[3] = { +} images[4] = { {"boot.img", "boot.sig", "boot", false}, {"recovery.img", "recovery.sig", "recovery", true}, {"system.img", "system.sig", "system", false}, + {"tos.img", "tos.sig", "tos", true}, }; void get_my_path(char *path); @@ -120,6 +120,8 @@ char *find_item(const char *item, const char *product) fn = "recovery.img"; } else if(!strcmp(item,"system")) { fn = "system.img"; + } else if(!strcmp(item,"tos")) { + fn = "tos.img"; } else if(!strcmp(item,"userdata")) { fn = "userdata.img"; } else if(!strcmp(item,"cache")) { @@ -266,7 +268,7 @@ usb_handle *open_device(void) announce = 0; fprintf(stderr,"< waiting for device >\n"); } - sleep(1); + usleep(1000); } } @@ -285,10 +287,13 @@ void usage(void) "\n" "commands:\n" " update <filename> reflash device from update.zip\n" - " flashall flash boot + recovery + system\n" + " flashall flash boot, system, and if found,\n" + " recovery, tos\n" " flash <partition> [ <filename> ] write a file to a flash partition\n" " erase <partition> erase a flash partition\n" - " format <partition> format a flash partition \n" + " format[:[<fs type>][:[<size>]] <partition> format a flash partition.\n" + " Can override the fs type and/or\n" + " size the bootloader reports.\n" " 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" @@ -309,10 +314,12 @@ void usage(void) " -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 address. default: 0x10000000\n" - " -n <page size> specify the nand page size. default: 2048\n" - " -S <size>[K|M|G] automatically sparse files greater than\n" - " size. 0 to disable\n" + " -b <base_addr> specify a custom kernel base address.\n" + " 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" ); } @@ -419,7 +426,7 @@ static int unzip_to_file(zipfile_t zip, char *name) return -1; } - if (write(fd, data, sz) != sz) { + if (write(fd, data, sz) != (ssize_t)sz) { fd = -1; } @@ -570,7 +577,7 @@ static int64_t get_target_sparse_limit(struct usb_handle *usb) if (!status) { limit = strtoul(response, NULL, 0); if (limit > 0) { - fprintf(stderr, "target reported max download size of %lld bytes\n", + fprintf(stderr, "target reported max download size of %" PRId64 " bytes\n", limit); } } @@ -613,7 +620,7 @@ 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); + return fb_format_supported(usb, part, NULL); } static int load_buf_fd(usb_handle *usb, int fd, @@ -657,7 +664,7 @@ static int load_buf(usb_handle *usb, const char *fname, fd = open(fname, O_RDONLY | O_BINARY); if (fd < 0) { - die("cannot open '%s'\n", fname); + return -1; } return load_buf_fd(usb, fd, buf); @@ -713,7 +720,7 @@ void do_update(usb_handle *usb, char *fn, int erase_first) int fd; int rc; struct fastboot_buffer buf; - int i; + size_t i; queue_info_dump(); @@ -787,7 +794,7 @@ void do_flashall(usb_handle *usb, int erase_first) void *data; unsigned sz; struct fastboot_buffer buf; - int i; + size_t i; queue_info_dump(); @@ -819,7 +826,6 @@ void do_flashall(usb_handle *usb, int erase_first) int do_oem_command(int argc, char **argv) { - int i; char command[256]; if (argc <= 1) return 0; @@ -876,9 +882,12 @@ static int64_t parse_num(const char *arg) return num; } -void fb_perform_format(const char *partition, int skip_if_not_supported) +void fb_perform_format(const char *partition, int skip_if_not_supported, + const char *type_override, const char *size_override) { - char pType[FB_RESPONSE_SZ + 1], pSize[FB_RESPONSE_SZ + 1]; + char pTypeBuff[FB_RESPONSE_SZ + 1], pSizeBuff[FB_RESPONSE_SZ + 1]; + char *pType = pTypeBuff; + char *pSize = pSizeBuff; unsigned int limit = INT_MAX; struct fastboot_buffer buf; const char *errMsg = NULL; @@ -897,12 +906,28 @@ void fb_perform_format(const char *partition, int skip_if_not_supported) errMsg = "Can't determine partition type.\n"; goto failed; } + 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); + } + pType = (char *)type_override; + } status = fb_getvar(usb, pSize, "partition-size:%s", partition); if (status) { errMsg = "Unable to get partition size\n"; goto failed; } + 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); + } + pSize = (char *)size_override; + } gen = fs_get_generator(pType); if (!gen) { @@ -953,13 +978,13 @@ int main(int argc, char **argv) unsigned sz; int status; int c; - int r; 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'}, + {"tags_offset", required_argument, 0, 't'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; @@ -967,8 +992,7 @@ int main(int argc, char **argv) serial = getenv("ANDROID_SERIAL"); while (1) { - int option_index = 0; - c = getopt_long(argc, argv, "wub:k:n:r:s:S:lp:c:i:m:h", longopts, NULL); + c = getopt_long(argc, argv, "wub:k:n:r:t:s:S:lp:c:i:m:h", longopts, NULL); if (c < 0) { break; } @@ -1009,6 +1033,9 @@ int main(int argc, char **argv) case 'r': ramdisk_offset = strtoul(optarg, 0, 16); break; + case 't': + tags_offset = strtoul(optarg, 0, 16); + break; case 's': serial = optarg; break; @@ -1060,18 +1087,42 @@ int main(int argc, char **argv) } else if(!strcmp(*argv, "erase")) { require(2); - if (fb_format_supported(usb, argv[1])) { + if (fb_format_supported(usb, argv[1], NULL)) { fprintf(stderr, "******** Did you mean to fastboot format this partition?\n"); } fb_queue_erase(argv[1]); skip(2); - } else if(!strcmp(*argv, "format")) { + } else if(!strncmp(*argv, "format", strlen("format"))) { + char *overrides; + char *type_override = NULL; + char *size_override = NULL; require(2); + /* + * 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; if (erase_first && needs_erase(argv[1])) { fb_queue_erase(argv[1]); } - fb_perform_format(argv[1], 0); + fb_perform_format(argv[1], 0, type_override, size_override); skip(2); } else if(!strcmp(*argv, "signature")) { require(2); @@ -1159,12 +1210,13 @@ int main(int argc, char **argv) if (wants_wipe) { fb_queue_erase("userdata"); - fb_perform_format("userdata", 1); + fb_perform_format("userdata", 1, NULL, NULL); fb_queue_erase("cache"); - fb_perform_format("cache", 1); + fb_perform_format("cache", 1, NULL, NULL); } if (wants_reboot) { fb_queue_reboot(); + fb_queue_wait_for_disconnect(); } else if (wants_reboot_bootloader) { fb_queue_command("reboot-bootloader", "rebooting into bootloader"); fb_queue_wait_for_disconnect(); diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h index c510a36..fc5d4f4 100644 --- a/fastboot/fastboot.h +++ b/fastboot/fastboot.h @@ -45,7 +45,7 @@ char *fb_get_error(void); /* engine.c - high level command queue engine */ int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...); -int fb_format_supported(usb_handle *usb, const char *partition); +int fb_format_supported(usb_handle *usb, const char *partition, const char *type_override); void fb_queue_flash(const char *ptn, void *data, unsigned sz); void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz); void fb_queue_erase(const char *ptn); diff --git a/fastboot/fs.c b/fastboot/fs.c index 6a1f9e6..cd4b880 100644 --- a/fastboot/fs.c +++ b/fastboot/fs.c @@ -39,12 +39,12 @@ static const struct fs_generator { }; -const struct fs_generator* fs_get_generator(const char* name) +const struct fs_generator* fs_get_generator(const char *fs_type) { unsigned i; for (i = 0; i < sizeof(generators) / sizeof(*generators); i++) - if (!strcmp(generators[i].fs_type, name)) + if (!strcmp(generators[i].fs_type, fs_type)) return generators + i; return NULL; diff --git a/fastboot/fs.h b/fastboot/fs.h index 65b9555..8444081 100644 --- a/fastboot/fs.h +++ b/fastboot/fs.h @@ -1,11 +1,11 @@ #ifndef _FS_H_ -#define _FH_H_ +#define _FS_H_ #include <stdint.h> struct fs_generator; -const struct fs_generator* fs_get_generator(const char* name); +const struct fs_generator* fs_get_generator(const char *fs_type); int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize); #endif diff --git a/fastboot/protocol.c b/fastboot/protocol.c index a0e0fd4..84e9837 100644 --- a/fastboot/protocol.c +++ b/fastboot/protocol.c @@ -110,7 +110,6 @@ static int _command_start(usb_handle *usb, const char *cmd, unsigned size, char *response) { int cmdsize = strlen(cmd); - int r; if(response) { response[0] = 0; @@ -189,8 +188,6 @@ static int _command_send(usb_handle *usb, const char *cmd, static int _command_send_no_data(usb_handle *usb, const char *cmd, char *response) { - int r; - return _command_start(usb, cmd, 0, response); } diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c index f2ce226..a45f9f8 100644 --- a/fastboot/usb_linux.c +++ b/fastboot/usb_linux.c @@ -125,9 +125,6 @@ static int filter_usb_device(char* sysfs_name, unsigned i; unsigned e; - struct stat st; - int result; - if(check(ptr, len, USB_DT_DEVICE, USB_DT_DEVICE_SIZE)) return -1; dev = (void*) ptr; diff --git a/fastboot/usb_windows.c b/fastboot/usb_windows.c index 07f7be2..0d13863 100644 --- a/fastboot/usb_windows.c +++ b/fastboot/usb_windows.c @@ -152,7 +152,7 @@ usb_handle* do_usb_open(const wchar_t* interface_name) { } int usb_write(usb_handle* handle, const void* data, int len) { - unsigned long time_out = 500 + len * 8; + unsigned long time_out = 5000; unsigned long written = 0; unsigned count = 0; int ret; @@ -178,7 +178,7 @@ int usb_write(usb_handle* handle, const void* data, int len) { count += written; len -= written; - data += written; + data = (const char *)data + written; if (len == 0) return count; @@ -194,7 +194,7 @@ int usb_write(usb_handle* handle, const void* data, int len) { } int usb_read(usb_handle *handle, void* data, int len) { - unsigned long time_out = 500 + len * 8; + unsigned long time_out = 0; unsigned long read = 0; int ret; @@ -212,7 +212,7 @@ int usb_read(usb_handle *handle, void* data, int len) { DBG("usb_read got: %ld, expected: %d, errno: %d\n", read, xfer, errno); if (ret) { return read; - } else if (errno != ERROR_SEM_TIMEOUT) { + } else { // assume ERROR_INVALID_HANDLE indicates we are disconnected if (errno == ERROR_INVALID_HANDLE) usb_kick(handle); diff --git a/fastboot/usbtest.c b/fastboot/usbtest.c index b8fb9e2..e6e2b37 100644 --- a/fastboot/usbtest.c +++ b/fastboot/usbtest.c @@ -88,14 +88,14 @@ int match_loop(usb_ifc_info *info) int test_null(usb_handle *usb) { - int i; + unsigned i; unsigned char buf[4096]; memset(buf, 0xee, 4096); long long t0, t1; t0 = NOW(); for(i = 0; i < arg_count; i++) { - if(usb_write(usb, buf, arg_size) != arg_size) { + if(usb_write(usb, buf, arg_size) != (int)arg_size) { fprintf(stderr,"write failed (%s)\n", strerror(errno)); return -1; } @@ -107,13 +107,13 @@ int test_null(usb_handle *usb) int test_zero(usb_handle *usb) { - int i; + unsigned i; unsigned char buf[4096]; long long t0, t1; t0 = NOW(); for(i = 0; i < arg_count; i++) { - if(usb_read(usb, buf, arg_size) != arg_size) { + if(usb_read(usb, buf, arg_size) != (int)arg_size) { fprintf(stderr,"read failed (%s)\n", strerror(errno)); return -1; } @@ -130,11 +130,11 @@ struct int (*test)(usb_handle *usb); const char *help; } tests[] = { - { "list", printifc, 0, "list interfaces" }, + { "list", printifc, NULL, "list interfaces" }, { "send", match_null, test_null, "send to null interface" }, { "recv", match_zero, test_zero, "recv from zero interface" }, - { "loop", match_loop, 0, "exercise loopback interface" }, - {}, + { "loop", match_loop, NULL, "exercise loopback interface" }, + { NULL, NULL, NULL, NULL }, }; int usage(void) |