diff options
| author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-05-24 17:42:50 +0200 |
|---|---|---|
| committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-05-24 19:32:24 +0200 |
| commit | bb935903a453b59072c57f93acdc597a9b1d3051 (patch) | |
| tree | fb020769cb1490de816ed89e66e0050b073a6320 | |
| parent | 5f6ce05fb54a4c8aef818d1dd3f6c9a6f9a4c168 (diff) | |
| download | exynos-gpio-tool-bb935903a453b59072c57f93acdc597a9b1d3051.tar.gz exynos-gpio-tool-bb935903a453b59072c57f93acdc597a9b1d3051.tar.bz2 exynos-gpio-tool-bb935903a453b59072c57f93acdc597a9b1d3051.zip | |
Implement board detection code for Replicant 6
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
| -rw-r--r-- | Android.mk | 17 | ||||
| -rw-r--r-- | compatible_devices.c | 132 |
2 files changed, 147 insertions, 2 deletions
diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..fb7cce1 --- /dev/null +++ b/Android.mk @@ -0,0 +1,17 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + compatible_devices.c \ + exynos4412_gpios.c \ + exynos4412_gpios_data.c \ + main.c \ + modem_gpios_data.c \ + tests.c \ + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := i9300-modem-pins +LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) + +include $(BUILD_EXECUTABLE) diff --git a/compatible_devices.c b/compatible_devices.c index 1feecbe..4c248fe 100644 --- a/compatible_devices.c +++ b/compatible_devices.c @@ -27,8 +27,121 @@ #include "compatible_devices.h" +static char *get_board_name(int debug, char *buf) +{ + char *result; + int rc; + + do { + char *start; + char *end; + + /* Look for 'H' in "Hardware : SMDK4x12" */ + start = strchr(buf, 'H'); + if (start == NULL) { + /* Not found */ + return NULL; + } + + buf = start; + + /* Look for "Hardware : " in "Hardware : SMDK4x12" */ + if (strcmp(start, "Hardware\t: ")) { + /* Start after the 'H' next time */ + buf += 1; + continue; + } + + buf += strlen("Hardware\t: "); + + end = strchr(buf, '\n'); + if (end == NULL) { + /* Not found */ + return NULL; + } + + /* Found */ + + result = malloc (1 + end - start); + if (result == NULL) { + rc = errno; + printf("%s: Malloc failed with error %d: %s\n", + __func__, rc, strerror(rc)); + return NULL; + } + + result = memcpy(result, start, end - start); + if (result == NULL) + return NULL; + + result[end - start] = '\0'; + + } while (true); + + return result; +} static int board_is_compatible(int debug) { + int fd; + int rc; + + off_t len = 4096; /* It should be sufficient for /proc/cpuinfo */ + ssize_t count; + char *buf; + char *board_name; + char *path = "/proc/cpuinfo"; + + fd = open(path, O_RDONLY); + if (fd == -1) { + rc = errno; + if (rc != ENOENT) + printf("%s: Opening %s failed with error %d: %s\n", + __func__, path, rc, strerror(rc)); + return false; + } + + /* Make sure we at least have a trailing \0 to simplify the code */ + buf = malloc(len + 1); + if (buf == NULL) { + rc = errno; + printf("%s: Malloc failed with error %d: %s\n", + __func__, rc, strerror(rc)); + return false; + } + + do { + count = read(fd, buf, len); + if (count == -1) { + rc = errno; + printf("%s: Reading %s failed with error %d: %s\n", + __func__, path, rc, strerror(rc)); + return false; + } + len -= count; + + if (debug) + printf("%s: read %d\n", __func__, count); + } while(len && count > 0); + + if (debug) + printf("%s: read DONE\n", __func__); + + board_name = get_board_name(debug, buf); + if (board_name == NULL) { + free(buf); + return false; + } + + if (debug) + printf("%s: board name: %s\n", __func__, board_name); + + if (!strcmp(board_name, "SMDK4x12")) { + free(buf); + return true; + } + + free(buf); + return false; } @@ -101,11 +214,26 @@ static int dt_is_compatible(int debug) int device_is_compatible(int debug) { - if (dt_is_compatible(debug)) + if (dt_is_compatible(debug)) { + if (debug) + printf("%s: dt_is_compatible: true\n", __func__); return true; + } else { + if (debug) + printf("%s: dt_is_compatible: flase\n", __func__); + } - if (board_is_compatible(debug)) + if (board_is_compatible(debug)) { + if (debug) + printf("%s: board_is_compatible: true\n", __func__); return true; + } else { + if (debug) + printf("%s: board_is_compatible: false\n", __func__); + } + + if (debug) + printf("%s: device is not compatible\n", __func__); return false; } |
