From 9ef260ba6f550857dd87c3818ba3759343f45d2d Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Mon, 3 Feb 2020 21:48:37 +0530 Subject: [PATCH] ANDROID: Add Android support * Add Android.bp makefile to build rmtfs for AOSP. * libudev is not supported on AOSP so read /sys/class/rmtfs sysfs entries directly. Signed-off-by: Amit Pundir Signed-off-by: Bjorn Andersson --- Android.bp | 13 +++++++++++ sharedmem.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ storage.c | 4 ++++ 3 files changed, 82 insertions(+) create mode 100644 Android.bp diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..7865a99 --- /dev/null +++ b/Android.bp @@ -0,0 +1,13 @@ +cc_binary { + name: "rmtfs", + vendor: true, + srcs: [ + "qmi_rmtfs.c", + "rmtfs.c", + "rproc.c", + "sharedmem.c", + "storage.c", + "util.c", + ], + shared_libs: ["libqrtr"], +} diff --git a/sharedmem.c b/sharedmem.c index c54fbbe..66bbd5d 100644 --- a/sharedmem.c +++ b/sharedmem.c @@ -4,7 +4,11 @@ #include #include #include +#ifndef ANDROID #include +#else +#include +#endif #include #include #include @@ -22,6 +26,8 @@ struct rmtfs_mem { int fd; }; +#ifndef ANDROID + static int parse_hex_sysattr(struct udev_device *dev, const char *name, uint64_t *value) { @@ -191,6 +197,65 @@ err_close_fd: return -saved_errno; } +#else + +#define PAGE_SIZE 4096 + +static int rmtfs_mem_open_rfsa(struct rmtfs_mem *rmem, int client_id) +{ + int saved_errno; + int fd; + char path[PATH_MAX]; + char val[PAGE_SIZE]; + char *endptr; + + errno = 0; + + snprintf(path, sizeof(path), "/sys/class/rmtfs/qcom_rmtfs_mem%d/phys_addr", client_id); + fd = open(path, O_RDONLY); + if (fd < 0) { + saved_errno = errno; + fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); + return -saved_errno; + } + read(fd, val, sizeof(val)); + rmem->address = strtoull(val, &endptr, 16); + if ((rmem->address == ULLONG_MAX && errno == ERANGE) || endptr == val) { + saved_errno = errno; + goto err_close_fd; + } + close(fd); + + snprintf(path, sizeof(path), "/sys/class/rmtfs/qcom_rmtfs_mem%d/size", client_id); + fd = open(path, O_RDONLY); + if (fd < 0) { + saved_errno = errno; + fprintf(stderr, "failed to open %s: %s\n", path, strerror(errno)); + return -saved_errno; + } + read(fd, val, sizeof(val)); + rmem->size = strtoull(val, &endptr, 16); + if ((rmem->size == ULLONG_MAX && errno == ERANGE) || endptr == val) { + saved_errno = errno; + goto err_close_fd; + } + close(fd); + + return 0; + +err_close_fd: + close(fd); + return -saved_errno; +} + +static int rmtfs_mem_open_uio(struct rmtfs_mem *rmem, int client_id) +{ + fprintf(stderr, "uio access is not supported on ANDROID yet\n"); + return -EINVAL; +} + +#endif + struct rmtfs_mem *rmtfs_mem_open(void) { struct rmtfs_mem *rmem; diff --git a/storage.c b/storage.c index d812419..d31f757 100644 --- a/storage.c +++ b/storage.c @@ -11,7 +11,11 @@ #define MAX_CALLERS 10 #define STORAGE_MAX_SIZE (16 * 1024 * 1024) +#ifndef ANDROID #define BY_PARTLABEL_PATH "/dev/disk/by-partlabel" +#else +#define BY_PARTLABEL_PATH "/dev/block/by-name" +#endif #define MIN(x, y) ((x) < (y) ? (x) : (y))