From 4553ffb49fada86a35ec0160b42b3f91ecba9ad3 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 1 Jan 2000 00:34:23 +0900 Subject: add code to detect beaglebone vs olimex --- bus.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'bus.c') diff --git a/bus.c b/bus.c index 51bd54b..e07efee 100644 --- a/bus.c +++ b/bus.c @@ -59,13 +59,38 @@ static int devmemfd = -1; -static bool util_isbeaglebone() + +static bool util_model_is (char *check_model) +{ + FILE *fp; + char content[100]; + + if ((fp=fopen("/sys/firmware/devicetree/base/model", "r"))==NULL) { + return FALSE; + } + + while(fgets(content, sizeof(content), fp)) { + if(strstr(content,check_model)) { + return TRUE; + } + } + + return FALSE; +} + + +static bool util_is_beaglebone() +{ + return util_model_is ("TI AM335x BeagleBone"); +} + + +static bool util_is_olimex() { - int fd = open("/sys/devices/avtech.9/modalias", O_RDONLY); - close(fd); - return fd > -1; + return util_model_is ("Olimex AM335x SOM"); } + static void* util_mapmemoryblock(off_t offset, size_t len) { devmemfd = open("/dev/mem", O_RDWR | O_SYNC); @@ -323,11 +348,14 @@ static volatile uint8_t* extbus; void bus_init() { + globals.HWDetect.beaglebone = util_is_beaglebone(); + globals.HWDetect.olimex = util_is_olimex(); - globals.HWDetect.beaglebone = util_isbeaglebone(); + printf("Beaglebone: %d. Olimex: %d.\n", + globals.HWDetect.beaglebone, globals.HWDetect.olimex); - if (!globals.HWDetect.beaglebone) { - printf("This doesn't seem to be a beaglebone.. bus stuff disabled!\n"); + if (!globals.HWDetect.beaglebone && !globals.HWDetect.olimex) { + printf("No recognized hardware. Bus stuff disabled!\n"); } else { gpmc_setup(); -- cgit