JamesBarwell / rpi-gpio.js

Control Raspberry Pi GPIO pins with node.js
MIT License
657 stars 116 forks source link

Broken on 64-bit Linux #95

Open daguej opened 4 years ago

daguej commented 4 years ago

Using this module on a Pi running a 64-bit Linux distro (eg Ubuntu 18.04 arm64) errors out when you call setup().

Error: Unable to match Revision in /proc/cpuinfo: processor       : 0
BogoMIPS        : 38.40
Features        : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 1
BogoMIPS        : 38.40
Features        : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 2
BogoMIPS        : 38.40
Features        : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 3
BogoMIPS        : 38.40
Features        : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

(thrown here)

This happens because /proc/cpuinfo does not contain the expected Revision: … line under 64-bit Linux.

To test, I followed this advice, bind-mounting a fake cpuinfo file on /proc/cpuinfo and adding Revision: a02082. With this, the rpi-gpio library started working.

It appears the correct place to look on a 64-bit system is /proc/device-tree/system/linux,revision.

$ cat /proc/device-tree/system/linux,revision | hexdump
0000000 a000 d320
0000004

(unsure if 32-bit systems have the same thing)

JamesBarwell commented 4 years ago

Thanks for the detailed report.

It looks like at the very least, it's a bug that it assumes the value of /proc/cpuinfo. It shouldn't break. At the moment I'm thinking that a patch to ensure it doesn't break, and to default to the v2 schema when it couldn't find the info, would be a good basic fix.

Reading /proc/device-tree could then be a second phase enhancement. I'm just wondering if it's worth doing given that it looks like that version of Ubuntu only supports Pi 2 and above anyway, which would all use the v2 schema. I'm not very familiar with these alternative OS's for the Pi, so am a bit unsure whether this functionality would be useful, and whether Device Tree would always be available anyway.