From 17ab45450104c18155ae43440a9dda6f89840847 Mon Sep 17 00:00:00 2001 From: Alex Ray Date: Wed, 19 Mar 2014 15:47:58 -0700 Subject: [PATCH] fastbootd: build static binary instead of dynamic This removes the requirement to hunt down dynamic libs for building an image, and switches the normal vendor_trigger HAL to a static HAL. Change-Id: Ifb603f1ee91fbbbff04ddbe66a1bf38a3c22be9e --- fastbootd/Android.mk | 34 ++++------ fastbootd/trigger.c | 43 ++---------- fastbootd/trigger.h | 5 -- fastbootd/{include => }/vendor_trigger.h | 43 ++++++------ ...dor_trigger.c => vendor_trigger_default.c} | 66 ++++--------------- 5 files changed, 51 insertions(+), 140 deletions(-) rename fastbootd/{include => }/vendor_trigger.h (68%) rename fastbootd/{other/vendor_trigger.c => vendor_trigger_default.c} (57%) diff --git a/fastbootd/Android.mk b/fastbootd/Android.mk index 0f32dbfcb..6aa740020 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/trigger.c b/fastbootd/trigger.c index e63e64d7c..df0f89571 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"); - 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 404acb4b9..d2d95739e 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 similarity index 68% rename from fastbootd/include/vendor_trigger.h rename to fastbootd/vendor_trigger.h index 51204fabe..0c83be639 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 - __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; +/* + * 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 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); +/* + * 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 similarity index 57% rename from fastbootd/other/vendor_trigger.c rename to fastbootd/vendor_trigger_default.c index 101959bda..362702491 100644 --- a/fastbootd/other/vendor_trigger.c +++ b/fastbootd/vendor_trigger_default.c @@ -30,67 +30,29 @@ */ #include - -#include "vendor_trigger.h" -#include "debug.h" - -unsigned int debug_level = DEBUG; +#include +#include static const int version = 1; -int check_version(const int fastboot_version, int *libversion) { +int trigger_init(void) { + klog_init(); + klog_set_level(7); + 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); } -int gpt_layout(struct GPT_content *table) { - D(DEBUG, "message from libvendor"); +int trigger_gpt_layout(struct GPT_content *table) { + KLOG_DEBUG("fastbootd", "%s: %p", __func__, table); return 0; } -int oem_cmd(const char *arg, const char **response) { - D(DEBUG, "message from libvendor, oem catched request %s", arg); +int trigger_oem_cmd(const char *arg, const char **response) { + KLOG_DEBUG("fastbootd", "%s: %s", __func__, arg); return 0; } - -static int close_triggers(struct vendor_trigger_t *dev) -{ - if (dev) - free(dev); - - 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; - - 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, -}; -