diff --git a/build b/build index 890ebc3..e226675 100755 --- a/build +++ b/build @@ -77,6 +77,9 @@ configure_gpiomem() { sudo=${WIRINGPI_SUDO-sudo} make="make -j $(( $(nproc) + 1 ))" hardware=$(fgrep -a Hardware /proc/cpuinfo | head -1 | awk '{ printf("%s %s %s\n", $3, $4, $5) }' | xargs) +[ "$hardware",, != *"odroid"* ] \ + && [ -f "/sys/firmware/devicetree/base/model" ] \ + && hardware=$(cat /sys/firmware/devicetree/base/model) if [ x$1 = "xclean" ]; then cd wiringPi diff --git a/debian/odroid-wiringpi.postinst b/debian/odroid-wiringpi.postinst index 427e51c..83c66ec 100644 --- a/debian/odroid-wiringpi.postinst +++ b/debian/odroid-wiringpi.postinst @@ -10,6 +10,9 @@ case "$1" in configure) if [ -c "/dev/gpiomem" ] && [ "$(stat -c "%a %G" "/dev/gpiomem")" != "660"*"odroid" ]; then hardware=$(fgrep -a Hardware /proc/cpuinfo | head -1 | awk '{ printf("%s %s %s\n", $3, $4, $5) }' | xargs) + [ "$hardware",, != *"odroid"* ] \ + && [ -f "/sys/firmware/devicetree/base/model" ] \ + && hardware=$(cat /sys/firmware/devicetree/base/model) case "$(echo $hardware | tr [:upper:] [:lower:])" in *xu4) cp -f /tmp/odroid-wiringpi/rules.d/99-odroid-wiringpi-exynos.rules /etc/udev/rules.d/ diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 870315e..6a44312 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -315,7 +315,7 @@ void setUsingGpioMem( const unsigned int value ) /*----------------------------------------------------------------------------*/ int piGpioLayout (void) { - FILE *cpuFd ; + FILE *cpuFd, *dtFd; char line [120] ; char *c ; static int gpioLayout = -1 ; @@ -325,21 +325,34 @@ int piGpioLayout (void) gpioLayout = 1; - if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL) + if ((cpuFd = fopen ("/proc/cpuinfo", "r")) != NULL) { + while (fgets (line, 120, cpuFd) != NULL) + if (strncmp (line, "Hardware", 8) == 0) + break ; + + if (strncmp (line, "Hardware", 8) != 0) + wiringPiFailure (WPI_FATAL, "No \"Hardware\" line") ; + + if (wiringPiDebug) + printf ("piGpioLayout: Hardware: %s\n", line) ; + + if (!(strstr (line, "ODROID"))) { + if ((dtFd = fopen("/sys/firmware/devicetree/base/model", "r")) != NULL) { + if (fgets(line, 30, dtFd) == NULL) + wiringPiFailure (WPI_FATAL, "Unable to read /sys/firmware/devicetree/base/model"); + + if (wiringPiDebug) + printf ("piGpioLayout: devicetree/base/model: %s\n", line) ; + + if (!(strstr (line, "Odroid"))) + wiringPiFailure (WPI_FATAL, "** This board is not ODROID. **") ; + } else { + wiringPiFailure (WPI_FATAL, "Unable to open /sys/firmware/devicetree/base/model") ; + } + } + } else { wiringPiFailure (WPI_FATAL, "Unable to open /proc/cpuinfo") ; - - while (fgets (line, 120, cpuFd) != NULL) - if (strncmp (line, "Hardware", 8) == 0) - break ; - - if (strncmp (line, "Hardware", 8) != 0) - wiringPiFailure (WPI_FATAL, "No \"Hardware\" line") ; - - if (wiringPiDebug) - printf ("piGpioLayout: Hardware: %s\n", line) ; - - if (!(strstr (line, "ODROID"))) - wiringPiFailure (WPI_FATAL, "** This board is not ODROID. **") ; + } rewind (cpuFd) ; while (fgets (line, 120, cpuFd) != NULL)