diff options
Diffstat (limited to 'fastbootd')
-rw-r--r-- | fastbootd/Android.mk | 34 | ||||
-rw-r--r-- | fastbootd/commands.c | 6 | ||||
-rw-r--r-- | fastbootd/commands/boot.c | 8 | ||||
-rw-r--r-- | fastbootd/commands/boot.h | 4 | ||||
-rw-r--r-- | fastbootd/protocol.c | 2 | ||||
-rw-r--r-- | fastbootd/transport.c | 2 | ||||
-rw-r--r-- | fastbootd/trigger.c | 43 | ||||
-rw-r--r-- | fastbootd/trigger.h | 5 | ||||
-rw-r--r-- | fastbootd/vendor_trigger.h (renamed from fastbootd/include/vendor_trigger.h) | 43 | ||||
-rw-r--r-- | fastbootd/vendor_trigger_default.c (renamed from fastbootd/other/vendor_trigger.c) | 64 |
10 files changed, 61 insertions, 150 deletions
diff --git a/fastbootd/Android.mk b/fastbootd/Android.mk index 0f32dbf..6aa7400 100644 --- a/fastbootd/Android.mk +++ b/fastbootd/Android.mk @@ -45,19 +45,17 @@ LOCAL_MODULE_TAGS := optional LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter -DFLASH_CERT LOCAL_LDFLAGS := -ldl -LOCAL_SHARED_LIBRARIES := \ - libhardware \ - libcrypto \ - libhardware_legacy \ - libmdnssd - LOCAL_STATIC_LIBRARIES := \ - libsparse_static \ libc \ + libcrypto_static \ libcutils \ + libmdnssd \ + libsparse_static \ libz -#LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_HAL_STATIC_LIBRARIES := libvendortrigger + +LOCAL_FORCE_STATIC_EXECUTABLE := true include $(BUILD_EXECUTABLE) @@ -84,21 +82,11 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true include $(BUILD_EXECUTABLE) +# vendor trigger HAL include $(CLEAR_VARS) - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/include \ - -LOCAL_STATIC_LIBRARIES := \ - $(EXTRA_STATIC_LIBS) \ - libcutils - -LOCAL_SRC_FILES := \ - other/vendor_trigger.c - +LOCAL_CFLAGS := -Wall -Werror LOCAL_MODULE := libvendortrigger.default LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter - - -include $(BUILD_SHARED_LIBRARY) +LOCAL_SRC_FILES := vendor_trigger_default.c +LOCAL_STATIC_LIBRARIES := libcutils +include $(BUILD_STATIC_LIBRARY) diff --git a/fastbootd/commands.c b/fastbootd/commands.c index 063e1a6..98b7866 100644 --- a/fastbootd/commands.c +++ b/fastbootd/commands.c @@ -124,9 +124,9 @@ static void cmd_boot(struct protocol_handle *phandle, const char *arg) goto error; } - kernel_ptr = (void *)((unsigned) ptr + hdr->page_size); - ramdisk_ptr = (void *)((unsigned) kernel_ptr + kernel_actual); - second_ptr = (void *)((unsigned) ramdisk_ptr + ramdisk_actual); + kernel_ptr = (void *)((uintptr_t) ptr + hdr->page_size); + ramdisk_ptr = (void *)((uintptr_t) kernel_ptr + kernel_actual); + second_ptr = (void *)((uintptr_t) ramdisk_ptr + ramdisk_actual); D(INFO, "preparing to boot"); // Prepares boot physical address. Addresses from header are ignored diff --git a/fastbootd/commands/boot.c b/fastbootd/commands/boot.c index 8da9a28..922914b 100644 --- a/fastbootd/commands/boot.c +++ b/fastbootd/commands/boot.c @@ -89,10 +89,10 @@ long kexec_load(unsigned int entry, unsigned long nr_segments, * Kernel address is not set into kernel_phys * Ramdisk is set to position relative to kernel */ -int prepare_boot_linux(unsigned kernel_phys, void *kernel_addr, int kernel_size, - unsigned ramdisk_phys, void *ramdisk_addr, int ramdisk_size, - unsigned second_phys, void *second_addr, int second_size, - unsigned atags_phys, void *atags_addr, int atags_size) { +int prepare_boot_linux(uintptr_t kernel_phys, void *kernel_addr, int kernel_size, + uintptr_t ramdisk_phys, void *ramdisk_addr, int ramdisk_size, + uintptr_t second_phys, void *second_addr, int second_size, + uintptr_t atags_phys, void *atags_addr, int atags_size) { struct kexec_segment segment[4]; int segment_count = 2; unsigned entry = START_ADDRESS + KEXEC_ARM_ZIMAGE_OFFSET; diff --git a/fastbootd/commands/boot.h b/fastbootd/commands/boot.h index 901c38a..a5efd01 100644 --- a/fastbootd/commands/boot.h +++ b/fastbootd/commands/boot.h @@ -40,8 +40,8 @@ #define KEXEC_TYPE_DEFAULT 0 #define KEXEC_TYPE_CRASH 1 -int prepare_boot_linux(unsigned, void *, int, unsigned, void *, int, - unsigned, void *, int, unsigned, void *, int); +int prepare_boot_linux(uintptr_t, void *, int, uintptr_t, void *, int, + uintptr_t, void *, int, uintptr_t, void *, int); unsigned *create_atags(unsigned *, int, const struct boot_img_hdr *, int *); long kexec_load(unsigned int, unsigned long, struct kexec_segment *, unsigned long); char *read_atags(const char *, int *); diff --git a/fastbootd/protocol.c b/fastbootd/protocol.c index 0086b4a..3908020 100644 --- a/fastbootd/protocol.c +++ b/fastbootd/protocol.c @@ -142,7 +142,7 @@ void fastboot_data(struct protocol_handle *phandle, size_t len) char response[64]; ssize_t ret; - snprintf(response, 64, "DATA%08x", len); + snprintf(response, 64, "DATA%08zx", len); ret = protocol_handle_write(phandle, response, strlen(response)); if (ret < 0) return; diff --git a/fastbootd/transport.c b/fastbootd/transport.c index ce8f9d0..9a16fd7 100644 --- a/fastbootd/transport.c +++ b/fastbootd/transport.c @@ -55,7 +55,7 @@ int transport_handle_download(struct transport_handle *thandle, size_t len) ftruncate(fd, len); buffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (buffer == NULL) { + if (buffer == MAP_FAILED) { D(ERR, "mmap(%zu) failed: %d %s", len, errno, strerror(errno)); goto err; } diff --git a/fastbootd/trigger.c b/fastbootd/trigger.c index e63e64d..df0f895 100644 --- a/fastbootd/trigger.c +++ b/fastbootd/trigger.c @@ -39,52 +39,19 @@ static const int version = 1; -static struct vendor_trigger_t *triggers = NULL; - int load_trigger() { - int err; - hw_module_t* module; - hw_device_t* device; int libversion; - err = hw_get_module(TRIGGER_MODULE_ID, (hw_module_t const**)&module); - - if (err == 0) { - err = module->methods->open(module, NULL, &device); - - if (err == 0) { - triggers = (struct vendor_trigger_t *) device; - } else { - D(WARN, "Libvendor load error"); - return 1; - } - } - else { - D(WARN, "Libvendor not load: %s", strerror(-err)); - return 0; + if (trigger_init() != 0) { + D(ERR, "libvendortrigger failed to initialize"); + return 1; } - if (triggers->check_version != NULL && - triggers->check_version(version, &libversion)) { - - triggers = NULL; + if (trigger_check_version(version, &libversion)) { D(ERR, "Library report incompability"); return 1; } - D(INFO, "libvendortrigger loaded"); + D(INFO, "libvendortrigger loaded"); return 0; } - -int trigger_oem_cmd(const char *arg, const char **response) { - if (triggers != NULL && triggers->oem_cmd != NULL) - return triggers->oem_cmd(arg, response); - return 0; -} - -int trigger_gpt_layout(struct GPT_content *table) { - if (triggers != NULL && triggers->gpt_layout != NULL) - return triggers->gpt_layout(table); - return 0; -} - diff --git a/fastbootd/trigger.h b/fastbootd/trigger.h index 404acb4..d2d9573 100644 --- a/fastbootd/trigger.h +++ b/fastbootd/trigger.h @@ -37,9 +37,4 @@ int load_trigger(); -/* same as in struct triggers */ - -int trigger_gpt_layout(struct GPT_content *table); -int trigger_oem_cmd(const char *arg, const char **response); - #endif diff --git a/fastbootd/include/vendor_trigger.h b/fastbootd/vendor_trigger.h index 51204fa..0c83be6 100644 --- a/fastbootd/include/vendor_trigger.h +++ b/fastbootd/vendor_trigger.h @@ -32,38 +32,37 @@ #ifndef __VENDOR_TRIGGER_H_ #define __VENDOR_TRIGGER_H_ -#define TRIGGER_MODULE_ID "fastbootd" -#include <hardware/hardware.h> - __BEGIN_DECLS struct GPT_entry_raw; struct GPT_content; /* - * Structer with function pointers may become longer in the future + * Implemented in libvendortrigger to handle platform-specific behavior. */ -struct vendor_trigger_t { - struct hw_device_t common; - - /* - * This function runs at the beggining and shoud never be changed - * - * version is number parameter indicating version on the fastbootd side - * libversion is version indicateing version of the library version - * - * returns 0 if it can cooperate with the current version and 1 in opposite - */ - int (*check_version)(const int version, int *libversion); +/* + * trigger_init() is called once at startup time before calling any other method + * + * returns 0 on success and nonzero on error + */ +int trigger_init(void); +/* + * This function runs once after trigger_init completes. + * + * version is number parameter indicating version on the fastbootd side + * libversion is version indicateing version of the library version + * + * returns 0 if it can cooperate with the current version and 1 in opposite + */ +int trigger_check_version(const int version, int *libversion); - /* - * Return value -1 forbid the action from the vendor site and sets errno - */ - int (* gpt_layout)(struct GPT_content *); - int (* oem_cmd)(const char *arg, const char **response); -}; +/* + * Return value -1 forbid the action from the vendor site and sets errno + */ +int trigger_gpt_layout(struct GPT_content *); +int trigger_oem_cmd(const char *arg, const char **response); __END_DECLS diff --git a/fastbootd/other/vendor_trigger.c b/fastbootd/vendor_trigger_default.c index 101959b..3627024 100644 --- a/fastbootd/other/vendor_trigger.c +++ b/fastbootd/vendor_trigger_default.c @@ -30,67 +30,29 @@ */ #include <stdlib.h> - -#include "vendor_trigger.h" -#include "debug.h" - -unsigned int debug_level = DEBUG; +#include <cutils/klog.h> +#include <vendor_trigger.h> static const int version = 1; -int check_version(const int fastboot_version, int *libversion) { - *libversion = version; - return !(fastboot_version == version); -} - -int gpt_layout(struct GPT_content *table) { - D(DEBUG, "message from libvendor"); +int trigger_init(void) { + klog_init(); + klog_set_level(7); return 0; } -int oem_cmd(const char *arg, const char **response) { - D(DEBUG, "message from libvendor, oem catched request %s", arg); - return 0; +int trigger_check_version(const int fastboot_version, int *libversion) { + KLOG_DEBUG("fastbootd", "%s: %d (%d)", __func__, fastboot_version, version); + *libversion = version; + return !(fastboot_version == version); } -static int close_triggers(struct vendor_trigger_t *dev) -{ - if (dev) - free(dev); - +int trigger_gpt_layout(struct GPT_content *table) { + KLOG_DEBUG("fastbootd", "%s: %p", __func__, table); return 0; } -static int open_triggers(const struct hw_module_t *module, char const *name, - struct hw_device_t **device) { - struct vendor_trigger_t *dev = malloc(sizeof(struct vendor_trigger_t)); - klog_init(); - klog_set_level(6); - - memset(dev, 0, sizeof(*dev)); - dev->common.module = (struct hw_module_t *) module; - dev->common.close = (int (*)(struct hw_device_t *)) close_triggers; - - dev->gpt_layout = gpt_layout; - dev->oem_cmd = oem_cmd; - - *device = (struct hw_device_t *) dev; - +int trigger_oem_cmd(const char *arg, const char **response) { + KLOG_DEBUG("fastbootd", "%s: %s", __func__, arg); return 0; } - - -static struct hw_module_methods_t trigger_module_methods = { - .open = open_triggers, -}; - -struct hw_module_t HAL_MODULE_INFO_SYM = { - .tag = HARDWARE_MODULE_TAG, - .version_major = 1, - .version_minor = 0, - .id = TRIGGER_MODULE_ID, - .name = "vendor trigger library for fastbootd", - .author = "Google, Inc.", - .methods = &trigger_module_methods, -}; - |