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 <amit.pundir@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Amit Pundir 2020-02-03 21:48:37 +05:30 committed by Bjorn Andersson
parent dfb8f3ed1c
commit 9ef260ba6f
3 changed files with 82 additions and 0 deletions

13
Android.bp Normal file
View File

@ -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"],
}

View File

@ -4,7 +4,11 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#ifndef ANDROID
#include <libudev.h>
#else
#include <sys/endian.h>
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@ -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;

View File

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