summaryrefslogtreecommitdiffstats
path: root/compatible_devices.c
diff options
context:
space:
mode:
Diffstat (limited to 'compatible_devices.c')
-rw-r--r--compatible_devices.c132
1 files changed, 2 insertions, 130 deletions
diff --git a/compatible_devices.c b/compatible_devices.c
index 4c248fe..1feecbe 100644
--- a/compatible_devices.c
+++ b/compatible_devices.c
@@ -27,121 +27,8 @@
#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;
}
@@ -214,26 +101,11 @@ static int dt_is_compatible(int debug)
int device_is_compatible(int debug)
{
- if (dt_is_compatible(debug)) {
- if (debug)
- printf("%s: dt_is_compatible: true\n", __func__);
+ if (dt_is_compatible(debug))
return true;
- } else {
- if (debug)
- printf("%s: dt_is_compatible: flase\n", __func__);
- }
- if (board_is_compatible(debug)) {
- if (debug)
- printf("%s: board_is_compatible: true\n", __func__);
+ if (board_is_compatible(debug))
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;
}