From ec2052799f860ea6432482dbc26f54b5819130d3 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Mon, 1 Sep 2014 13:58:40 +0200 Subject: Firmware data load from a static file instead of a library Signed-off-by: Paul Kocialkowski --- src/phHal4Nfc.c | 71 ++++++++++++++++++++++++++++++++++++++++----------------- src/phLibNfc.c | 4 ++-- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/phHal4Nfc.c b/src/phHal4Nfc.c index f40ed9b..168d4e6 100755 --- a/src/phHal4Nfc.c +++ b/src/phHal4Nfc.c @@ -304,41 +304,68 @@ phHal4Nfc_Configure_Layers( #define LOG_TAG "NFC-HCI" #include -#include +#include +#include -#define FW_PATH "/system/vendor/firmware/libpn544_fw.so" -#define FW_PATH_2 "/system/lib/libpn544_fw.so" +#define FW_PATH "/system/vendor/firmware/pn544.bin" const unsigned char *nxp_nfc_full_version = NULL; const unsigned char *nxp_nfc_fw = NULL; -int dlopen_firmware() { - void *p; +int open_firmware() { + struct stat firmware_stat; + void *buffer; + size_t length; + int fd; + int rc; - void *handle = dlopen(FW_PATH, RTLD_NOW); - if (handle == NULL) { - handle = dlopen(FW_PATH_2, RTLD_NOW); - if (handle == NULL) { - ALOGE("Could not open %s or %s", FW_PATH, FW_PATH_2); - return -1; - } + if (nxp_nfc_full_version != NULL && nxp_nfc_fw != NULL) + return 0; + + rc = stat(FW_PATH, &firmware_stat); + if (rc < 0) { + ALOGE("Could not open %s", FW_PATH); + return -1; + } + + if (firmware_stat.st_size < NXP_FULL_VERSION_LEN) { + ALOGE("Invalid %s size: %lld", FW_PATH, firmware_stat.st_size); + return -1; } - p = dlsym(handle, "nxp_nfc_full_version"); - if (p == NULL) { - ALOGE("Could not link nxp_nfc_full_version"); + length = (size_t) firmware_stat.st_size; + + fd = open(FW_PATH, O_RDONLY); + if (fd < 0) { + ALOGE("Could not open %s", FW_PATH); return -1; } - nxp_nfc_full_version = (unsigned char *)p; - p = dlsym(handle, "nxp_nfc_fw"); - if (p == NULL) { - ALOGE("Could not link nxp_nfc_fw"); + buffer = malloc(length); + + rc = read(fd, buffer, length); + if (rc < (int) length) { + ALOGE("Could not read %s", FW_PATH); return -1; } - nxp_nfc_fw = (unsigned char *)p; + + close(fd); + + nxp_nfc_full_version = (const unsigned char *) buffer; + nxp_nfc_fw = ((const unsigned char *) buffer + NXP_FULL_VERSION_LEN); return 0; + +} + +void close_firmware() { + if (nxp_nfc_full_version == NULL || nxp_nfc_fw == NULL) + return; + + free((void *) nxp_nfc_full_version); + + nxp_nfc_full_version = NULL; + nxp_nfc_fw = NULL; } #endif @@ -377,7 +404,7 @@ NFCSTATUS phHal4Nfc_Open( else/*Do an initialization*/ { #ifdef ANDROID - dlopen_firmware(); + open_firmware(); #endif /*If hal4 ctxt in Hwreference is NULL create a new context*/ @@ -723,6 +750,8 @@ NFCSTATUS phHal4Nfc_Close( { } + + close_firmware(); } return closeRetVal; } diff --git a/src/phLibNfc.c b/src/phLibNfc.c index 6477a3f..7b9310a 100644 --- a/src/phLibNfc.c +++ b/src/phLibNfc.c @@ -47,7 +47,7 @@ *************************** Macro's ****************************************** */ -extern int dlopen_firmware(); +extern int open_firmware(); #ifndef STATIC_DISABLE #define STATIC static @@ -125,7 +125,7 @@ NFCSTATUS phLibNfc_Download_Mode () int phLibNfc_Load_Firmware_Image () { int status; - status = dlopen_firmware(); + status = open_firmware(); return status; } -- cgit v1.1