diff --git a/python-gpiozero/git/0001-Support-device-detection-under-aarch64.patch b/python-gpiozero/git/0001-Support-device-detection-under-aarch64.patch new file mode 100644 index 00000000..18a20e99 --- /dev/null +++ b/python-gpiozero/git/0001-Support-device-detection-under-aarch64.patch @@ -0,0 +1,50 @@ +From 28845f63eb831f9c0d30b0ce58f23dd3aa95caa2 Mon Sep 17 00:00:00 2001 +From: Martchus +Date: Sat, 3 Nov 2018 21:38:21 +0000 +Subject: [PATCH] Support device detection under aarch64 + +Under aarch64, /proc/cpuinfo does not contain the revision +number. This adds a fallback to /proc/device-tree so the +revision can be detected under 64-bit systems as well. + +See https://github.com/RPi-Distro/python-gpiozero/issues/688 +--- + gpiozero/pins/local.py | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/gpiozero/pins/local.py b/gpiozero/pins/local.py +index 4a9e522..4e25f38 100644 +--- a/gpiozero/pins/local.py ++++ b/gpiozero/pins/local.py +@@ -56,6 +56,8 @@ class LocalPiFactory(PiFactory): + # Cache the result as we can reasonably assume it won't change during + # runtime (this is LocalPin after all; descendents that deal with + # remote Pis should inherit from Pin instead) ++ ++ # Read revision from /proc/cpuinfo + with io.open('/proc/cpuinfo', 'r') as f: + for line in f: + if line.startswith('Revision'): +@@ -64,7 +66,18 @@ class LocalPiFactory(PiFactory): + if overvolted: + revision = revision[-4:] + return revision +- raise PinUnknownPi('unable to locate Pi revision in /proc/cpuinfo') ++ ++ # Fallback to reading /proc/device-tree if available to support 64-bit systems ++ try: ++ with io.open('/proc/device-tree/system/linux,revision', 'rb') as f: ++ f.seek(1) ++ revision = int.from_bytes(f.read(), byteorder='big', signed=False) ++ if revision != 0: ++ return hex(revision)[2:] ++ except FileNotFoundError: ++ pass ++ ++ raise PinUnknownPi('unable to locate Pi revision in /proc/cpuinfo or /proc/device-tree') + + + class LocalPiPin(PiPin): +-- +2.19.1 + diff --git a/python-gpiozero/git/PKGBUILD b/python-gpiozero/git/PKGBUILD index cfd5f6d8..28f10269 100644 --- a/python-gpiozero/git/PKGBUILD +++ b/python-gpiozero/git/PKGBUILD @@ -17,7 +17,8 @@ depends=() makedepends=('git' 'python-setuptools') provides=("${_name}") conflicts=("${_name}") -source=("git://github.com/RPi-Distro/${_name}.git") +source=("git://github.com/RPi-Distro/${_name}.git" + 0001-Support-device-detection-under-aarch64.patch) sha256sums=('SKIP') pkgver() { @@ -25,6 +26,11 @@ pkgver() { echo "$(git rev-list --count HEAD).$(git rev-parse --short HEAD)" } +prepare() { + cd "${srcdir}/${_name}" + patch -p1 -i ../0001-Support-device-detection-under-aarch64.patch +} + build() { cd "${srcdir}/${_name}" python setup.py build