From e54eebbf1a908d65ee8cf80bab62821c05666d70 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Tue, 3 Mar 2009 18:29:04 -0800 Subject: auto import from //depot/cupcake/@135843 --- fastboot/Android.mk | 57 ---- fastboot/bootimg.c | 85 ------ fastboot/engine.c | 289 ------------------- fastboot/engineering_key.p12 | Bin 2610 -> 0 bytes fastboot/fastboot.c | 673 ------------------------------------------- fastboot/fastboot.h | 57 ---- fastboot/genkey.sh | 25 -- fastboot/p12topem.sh | 9 - fastboot/protocol.c | 181 ------------ fastboot/signfile.sh | 10 - fastboot/usb.h | 64 ---- fastboot/usb_linux.c | 373 ------------------------ fastboot/usb_osx.c | 538 ---------------------------------- fastboot/usb_windows.c | 375 ------------------------ fastboot/usbtest.c | 212 -------------- fastboot/util_linux.c | 52 ---- fastboot/util_osx.c | 47 --- fastboot/util_windows.c | 93 ------ 18 files changed, 3140 deletions(-) delete mode 100644 fastboot/Android.mk delete mode 100644 fastboot/bootimg.c delete mode 100644 fastboot/engine.c delete mode 100644 fastboot/engineering_key.p12 delete mode 100644 fastboot/fastboot.c delete mode 100644 fastboot/fastboot.h delete mode 100755 fastboot/genkey.sh delete mode 100755 fastboot/p12topem.sh delete mode 100644 fastboot/protocol.c delete mode 100755 fastboot/signfile.sh delete mode 100644 fastboot/usb.h delete mode 100644 fastboot/usb_linux.c delete mode 100644 fastboot/usb_osx.c delete mode 100644 fastboot/usb_windows.c delete mode 100644 fastboot/usbtest.c delete mode 100644 fastboot/util_linux.c delete mode 100644 fastboot/util_osx.c delete mode 100644 fastboot/util_windows.c (limited to 'fastboot') diff --git a/fastboot/Android.mk b/fastboot/Android.mk deleted file mode 100644 index 7a9d35f2..00000000 --- a/fastboot/Android.mk +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (C) 2007 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../mkbootimg -LOCAL_SRC_FILES := protocol.c engine.c bootimg.c fastboot.c -LOCAL_MODULE := fastboot - -ifeq ($(HOST_OS),linux) - LOCAL_SRC_FILES += usb_linux.c util_linux.c -endif - -ifeq ($(HOST_OS),darwin) - LOCAL_SRC_FILES += usb_osx.c util_osx.c - LOCAL_LDLIBS += -lpthread -framework CoreFoundation -framework IOKit \ - -framework Carbon -endif - -ifeq ($(HOST_OS),windows) - LOCAL_SRC_FILES += usb_windows.c util_windows.c - EXTRA_STATIC_LIBS := AdbWinApi - LOCAL_C_INCLUDES += /usr/include/w32api/ddk development/host/windows/usb/api - ifeq ($(strip $(USE_CYGWIN)),) - LOCAL_LDLIBS += -lws2_32 - USE_SYSDEPS_WIN32 := 1 - endif -endif - -LOCAL_STATIC_LIBRARIES := $(EXTRA_STATIC_LIBS) libzipfile libunz - -include $(BUILD_HOST_EXECUTABLE) -$(call dist-for-goals,droid,$(LOCAL_BUILT_MODULE)) - -ifeq ($(HOST_OS),linux) -include $(CLEAR_VARS) -LOCAL_SRC_FILES := usbtest.c usb_linux.c -LOCAL_MODULE := usbtest -include $(BUILD_HOST_EXECUTABLE) -endif - -ifeq ($(HOST_OS),windows) -$(LOCAL_INSTALLED_MODULE): $(HOST_OUT_EXECUTABLES)/AdbWinApi.dll -endif diff --git a/fastboot/bootimg.c b/fastboot/bootimg.c deleted file mode 100644 index 1d77b3c4..00000000 --- a/fastboot/bootimg.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 - * the documentation and/or other materials provided with the - * 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 - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * 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. - */ - -#include -#include -#include - -#include - -void bootimg_set_cmdline(boot_img_hdr *h, const char *cmdline) -{ - strcpy((char*) h->cmdline, cmdline); -} - -boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size, - void *ramdisk, unsigned ramdisk_size, - void *second, unsigned second_size, - unsigned page_size, - unsigned *bootimg_size) -{ - unsigned kernel_actual; - unsigned ramdisk_actual; - unsigned second_actual; - unsigned page_mask; - boot_img_hdr *hdr; - - page_mask = page_size - 1; - - kernel_actual = (kernel_size + page_mask) & (~page_mask); - ramdisk_actual = (ramdisk_size + page_mask) & (~page_mask); - second_actual = (second_size + page_mask) & (~page_mask); - - *bootimg_size = page_size + kernel_actual + ramdisk_actual + second_actual; - - hdr = calloc(*bootimg_size, 1); - - if(hdr == 0) { - return hdr; - } - - memcpy(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE); - - hdr->kernel_size = kernel_size; - hdr->kernel_addr = 0x10008000; - hdr->ramdisk_size = ramdisk_size; - hdr->ramdisk_addr = 0x11000000; - hdr->second_size = second_size; - hdr->second_addr = 0x10F00000; - - hdr->tags_addr = 0x10000100; - hdr->page_size = page_size; - - memcpy(hdr->magic + page_size, - kernel, kernel_size); - memcpy(hdr->magic + page_size + kernel_actual, - ramdisk, ramdisk_size); - memcpy(hdr->magic + page_size + kernel_actual + ramdisk_actual, - second, second_size); - return hdr; -} diff --git a/fastboot/engine.c b/fastboot/engine.c deleted file mode 100644 index 4c7e197f..00000000 --- a/fastboot/engine.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * 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 - * the documentation and/or other materials provided with the - * 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 - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * 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. - */ - -#include -#include -#include -#include - -#include "fastboot.h" - -char *mkmsg(const char *fmt, ...) -{ - char buf[256]; - char *s; - va_list ap; - - va_start(ap, fmt); - vsprintf(buf, fmt, ap); - va_end(ap); - - s = strdup(buf); - if (s == 0) die("out of memory"); - return s; -} - -#define OP_DOWNLOAD 1 -#define OP_COMMAND 2 -#define OP_QUERY 3 -#define OP_NOTICE 4 - -typedef struct Action Action; - -struct Action -{ - unsigned op; - Action *next; - - char cmd[64]; - void *data; - unsigned size; - - const char *msg; - int (*func)(Action *a, int status, char *resp); -}; - -static Action *action_list = 0; -static Action *action_last = 0; - -static int cb_default(Action *a, int status, char *resp) -{ - if (status) { - fprintf(stderr,"FAILED (%s)\n", resp); - } else { - fprintf(stderr,"OKAY\n"); - } - return status; -} - -static Action *queue_action(unsigned op, const char *fmt, ...) -{ - Action *a; - va_list ap; - - a = calloc(1, sizeof(Action)); - if (a == 0) die("out of memory"); - - va_start(ap, fmt); - vsprintf(a->cmd, fmt, ap); - va_end(ap); - - if (action_last) { - action_last->next = a; - } else { - action_list = a; - } - action_last = a; - a->op = op; - a->func = cb_default; - return a; -} - -void fb_queue_erase(const char *ptn) -{ - Action *a; - a = queue_action(OP_COMMAND, "erase:%s", ptn); - a->msg = mkmsg("erasing '%s'", ptn); -} - -void fb_queue_flash(const char *ptn, void *data, unsigned sz) -{ - Action *a; - - a = queue_action(OP_DOWNLOAD, ""); - a->data = data; - a->size = sz; - a->msg = mkmsg("sending '%s' (%d KB)", ptn, sz / 1024); - - a = queue_action(OP_COMMAND, "flash:%s", ptn); - a->msg = mkmsg("writing '%s'", ptn); -} - -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]; - int len = strlen(val); - int match; - - if ((len > 1) && (val[len-1] == '*')) { - len--; - match = !strncmp(val, str, len); - } else { - match = !strcmp(val, str); - } - - if (match) return 1; - } - - return 0; -} - - - -static int cb_check(Action *a, int status, char *resp, int invert) -{ - const char **value = a->data; - unsigned count = a->size; - unsigned n; - int yes; - - if (status) { - fprintf(stderr,"FAILED (%s)\n", resp); - return status; - } - - yes = match(resp, value, count); - if (invert) yes = !yes; - - if (yes) { - fprintf(stderr,"OKAY\n"); - return 0; - } - - fprintf(stderr,"FAILED\n\n"); - fprintf(stderr,"Device %s is '%s'.\n", a->cmd + 7, resp); - fprintf(stderr,"Update %s '%s'", - invert ? "rejects" : "requires", value[0]); - for (n = 1; n < count; n++) { - fprintf(stderr," or '%s'", value[n]); - } - fprintf(stderr,".\n\n"); - return -1; -} - -static int cb_require(Action *a, int status, char *resp) -{ - return cb_check(a, status, resp, 0); -} - -static int cb_reject(Action *a, int status, char *resp) -{ - return cb_check(a, status, resp, 1); -} - -void fb_queue_require(const char *var, int invert, unsigned nvalues, const char **value) -{ - Action *a; - a = queue_action(OP_QUERY, "getvar:%s", var); - a->data = value; - a->size = nvalues; - a->msg = mkmsg("checking %s", var); - a->func = invert ? cb_reject : cb_require; - if (a->data == 0) die("out of memory"); -} - -static int cb_display(Action *a, int status, char *resp) -{ - if (status) { - fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); - return status; - } - fprintf(stderr, "%s: %s\n", (char*) a->data, resp); - return 0; -} - -void fb_queue_display(const char *var, const char *prettyname) -{ - Action *a; - a = queue_action(OP_QUERY, "getvar:%s", var); - a->data = strdup(prettyname); - if (a->data == 0) die("out of memory"); - a->func = cb_display; -} - -static int cb_do_nothing(Action *a, int status, char *resp) -{ - fprintf(stderr,"\n"); - return 0; -} - -void fb_queue_reboot(void) -{ - Action *a = queue_action(OP_COMMAND, "reboot"); - a->func = cb_do_nothing; - a->msg = "rebooting"; -} - -void fb_queue_command(const char *cmd, const char *msg) -{ - Action *a = queue_action(OP_COMMAND, cmd); - a->msg = msg; -} - -void fb_queue_download(const char *name, void *data, unsigned size) -{ - Action *a = queue_action(OP_DOWNLOAD, ""); - a->data = data; - a->size = size; - a->msg = mkmsg("downloading '%s'", name); -} - -void fb_queue_notice(const char *notice) -{ - Action *a = queue_action(OP_NOTICE, ""); - a->data = (void*) notice; -} - -void fb_execute_queue(usb_handle *usb) -{ - Action *a; - char resp[FB_RESPONSE_SZ+1]; - int status; - - a = action_list; - resp[FB_RESPONSE_SZ] = 0; - - for (a = action_list; a; a = a->next) { - if (a->msg) { - fprintf(stderr,"%s... ",a->msg); - } - if (a->op == OP_DOWNLOAD) { - status = fb_download_data(usb, a->data, a->size); - status = a->func(a, status, status ? fb_get_error() : ""); - if (status) break; - } else if (a->op == OP_COMMAND) { - status = fb_command(usb, a->cmd); - status = a->func(a, status, status ? fb_get_error() : ""); - if (status) break; - } else if (a->op == OP_QUERY) { - status = fb_command_response(usb, a->cmd, resp); - status = a->func(a, status, status ? fb_get_error() : resp); - if (status) break; - } else if (a->op == OP_NOTICE) { - fprintf(stderr,"%s\n",(char*)a->data); - } else { - die("bogus action"); - } - } -} - diff --git a/fastboot/engineering_key.p12 b/fastboot/engineering_key.p12 deleted file mode 100644 index d8183b05..00000000 Binary files a/fastboot/engineering_key.p12 and /dev/null differ diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c deleted file mode 100644 index e220dbea..00000000 --- a/fastboot/fastboot.c +++ /dev/null @@ -1,673 +0,0 @@ -/* - * 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 - * the documentation and/or other materials provided with the - * 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 - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "fastboot.h" - -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; - -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); -} - -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"; - } 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); - } - - dir = getenv("ANDROID_PRODUCT_OUT"); - if((dir == 0) || (dir[0] == 0)) { - die("neither -p product specified nor ANDROID_PRODUCT_OUT set"); - return 0; - } - - sprintf(path, "%s/%s", dir, fn); - return strdup(path); -} - -#ifdef _WIN32 -void *load_file(const char *fn, unsigned *_sz); -#else -void *load_file(const char *fn, unsigned *_sz) -{ - char *data; - int sz; - int fd; - - 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: - close(fd); - if(data != 0) free(data); - return 0; -} -#endif - -int match_fastboot(usb_ifc_info *info) -{ - if(!(vendor_id && (info->dev_vendor == vendor_id)) && - (info->dev_vendor != 0x18d1) && - (info->dev_vendor != 0x0bb4)) return -1; - if(info->ifc_class != 0xff) return -1; - if(info->ifc_subclass != 0x42) return -1; - if(info->ifc_protocol != 0x03) return -1; - // require matching serial number if a serial number is specified - // at the command line with the -s option. - if (serial && strcmp(serial, info->serial_number) != 0) return -1; - return 0; -} - -int list_devices_callback(usb_ifc_info *info) -{ - if (match_fastboot(info) == 0) { - char* serial = info->serial_number; - if (!serial[0]) { - serial = "????????????"; - } - // output compatible with "adb devices" - printf("%s\tfastboot\n", serial); - } - - return -1; -} - -usb_handle *open_device(void) -{ - static usb_handle *usb = 0; - int announce = 1; - - if(usb) return usb; - - for(;;) { - usb = usb_open(match_fastboot); - if(usb) return usb; - if(announce) { - announce = 0; - 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 [