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
This commit is contained in:
Alex Ray 2014-03-19 15:47:58 -07:00
parent 3fcd9ed6e3
commit 17ab454501
5 changed files with 51 additions and 140 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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

View File

@ -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;
/*
* 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

View File

@ -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) {
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,
};