I am modifying the AOSP based on Android version 4.3 by adding a new system service and trying to extend the Hardware Abstraction Layer (HAL).
Implementing the System Service did work and it is usable when a App in the Emulator accesses the Service through Binder. The Service itself tries to load the new HAL module in the cpp part of the service.
The problem is, I cannot add the HAL implementation to the build as the Emulator is then just not starting up. The HAL module itself consists of a simple C-file and the Android.mk
There are no compilation errors and a the .so library is added in the build. All this based on a post Karim Yaghmour for Android 2.3
I created a header file under hardware/libhardware/include/hardware/gen_gpio.h and placed the implementation shown below into sdk/emulator/gen_gpio
The example provided in the post has the same problem. So I am wondering if there were major changes between Android 2.3 and Android 4.3 and what has to be done differently to add a HAL module to the Emulator (Karim Yaghmour states in his book the same topic that it should still work).
My c-file looks like this.
#include <errno.h>
#define LOG_TAG "gen_gpio_odroidxu4"
#include <cutils/log.h>
#include <cutils/sockets.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <hardware/gen_gpio.h>
static int gen_gpio_read (char* buffer, int length, int gpio_pin) {
return 0;
};
static int gen_gpio_write (char* buffer, int length, int gpio_pin) {
return 0;
};
static int open_gen_gpio(const struct hw_module_t* module, char const* name, struct hw_device_t** device) {
struct gen_gpio_device_t *dev = malloc(sizeof(struct gen_gpio_device_t)); //Reserve memory for device struct
memset(dev, 0, sizeof(*dev)); //Clear memory area
dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0;
dev->common.module = (struct hw_module_t*) module;
dev->read = gen_gpio_read;
dev->write = gen_gpio_write;
*device = (struct hw_device_t*) dev;
return 0;
};
static struct hw_module_methods_t gen_gpio_module_methods = {
.open = open_gen_gpio
};
const struct hw_module_t HAL_MODULE_INFO_SYM = {
.tag = HARDWARE_MODULE_TAG,
.version_major = 1,
.version_minor = 0,
.id = GEN_GPIO_HARDWARE_MODULE_ID,
.name = "Generic GPIO HW Module",
.author = "Christoph Fraedrich",
.methods = &gen_gpio_module_methods,
};
And the make file like this:
LOCAL_PATH := $(call my-dir)
ifneq ($(TARGET_PRODUCT),sim)
# HAL module implemenation, not prelinked and stored in
# hw/<GPS_HARDWARE_MODULE_ID>.<ro.hardware>.so
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_CFLAGS += -DQEMU_HARDWARE
LOCAL_SHARED_LIBRARIES := liblog libcutils libhardware
LOCAL_SRC_FILES := gen_gpio_qemu.c
LOCAL_MODULE := gen_gpio.goldfish
LOCAL_MODULE_TAGS := debug
include $(BUILD_SHARED_LIBRARY)
endif
I too experimented with adding a HAL module to AOSP 4.2 based on Karim Yaghmour's book and had some troubles. If I remember correctly a mistake in the book was caused by defining struct hw_module_t
as const
which resulted in a memory access/write error preventing emulator to boot. Try it as
struct hw_module_t HAL_MODULE_INFO_SYM