ziesemer
Posts: 12
Joined: Wed May 13, 2015 2:20 am
Location: Appleton, WI
Contact: Website

Non-root GPIO access broken with 4.9 kernel on Pi1

Fri May 12, 2017 3:16 pm

On a Raspberry Pi 1 Model B+, I ran normal OS updates (apt-get update/upgrade - no use of rpi-update / no "bleeding edge") - and the kernel was updated from 4.4.50+ to 4.9.24+. After this, my GPIO programs no longer work, failing with "Failed to add edge detection".

Minimal test case:

Code: Select all

$ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> def test(channel):
...   pass
...
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup(4, GPIO.IN)
>>> GPIO.add_event_detect(4, GPIO.BOTH, callback=test)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Failed to add edge detection
>>>

$ uname -a
Linux raspberypi 4.9.24+ #993 Wed Apr 26 17:56:54 BST 2017 armv6l GNU/Linux
>>>
Edited to only need the default python, 2.7. The same results can be seen with python3. To use:

Code: Select all

sudo apt install python3 python3-rpi.gpio
The same works without error when run as root (or with sudo), or on a Raspberry Pi 2 (running kernel 4.9.24-v7+). I remain a member of the "gpio" group, and all the related /dev objects I can find still appear to have the proper "root:gpio" permissions.

I have referenced Moving Linux kernel to 4.9.

For kicks, installing rpi-update and installing the latest kernel does not help, either:

Code: Select all

Linux raspberrypi 4.9.27+ #997 Tue May 9 19:51:52 BST 2017 armv6l GNU/Linux
Doing nothing other than installing rpi-update and reverting back to 4.4 resolves the issue:

Code: Select all

$ sudo rpi-update 52241088c1da59a359110d39c1875cda56496764

$ uname -a
Linux raspberrypi 4.4.50+ #970 Mon Feb 20 19:12:50 GMT 2017 armv6l GNU/Linux
Can anyone else reproduce? Should I open an issue at https://github.com/raspberrypi/linux/issues ?

(Also, is there a reason why "gpio" doesn't work with the search function on this forum?)
Last edited by ziesemer on Fri May 12, 2017 8:52 pm, edited 1 time in total.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5161
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Fri May 12, 2017 6:50 pm

I've tried your test on 4.9 kernel on both pi1 and pi3 and it worked for me. Anyone else tried?

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Fri May 12, 2017 7:25 pm

Works okay for me on an original B and a Pi3.

Linux peter 4.9.27+ #997 Tue May 9 19:51:52 BST 2017 armv6l GNU/Linux
VERSION = '0.6.3'

ziesemer
Posts: 12
Joined: Wed May 13, 2015 2:20 am
Location: Appleton, WI
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Fri May 12, 2017 7:49 pm

Thank you both. I'll continue to try to break this down and see what the difference is. Any suggestions as to some next things to look at and try?

I'll probably include an attempted clean install from https://www.raspberrypi.org/downloads/raspbian/ (2017-04-10 release date). Shows that it still comes with the 4.4 kernel, so I can test with and without the upgrade to 4.9.

FYI - I also found https://github.com/vitormhenrique/OctoP ... /issues/16 and https://github.com/raspberrypi/linux/issues/791 - both of which are reporting similar issues with 4.9.17.

ziesemer
Posts: 12
Joined: Wed May 13, 2015 2:20 am
Location: Appleton, WI
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Fri May 12, 2017 9:34 pm

Re-applied the 4.9 kernel via rpi-update, broken again. Looks to be udev-related. The above code sample successfully created /sys/class/gpio/gpio4 - but everything is owned as root:root, not root:gpio. (Even then, all the files are 644, vs. 770 that I see on a working instance.) As such, I'm also now reproducing this with only sysfs, and completely ruling-out anything Python-related.

Following the April 5-10 discussion at https://github.com/raspberrypi/linux/issues/791, my /etc/udev/rules.d is certainly different between the broken Pi1:

Code: Select all

$ ll 99-com.rules ; md5sum 99-com.rules
-rw-r--r-- 1 root root 506 Nov 21  2015 99-com.rules
1de39a305333e7c5bf0dca7ba5df9bdf  99-com.rules
... and and working Pi2 or Pi3:

Code: Select all

$ ll 99-com.rules ; md5sum 99-com.rules
-rw-r--r-- 1 root root 983 Mar 21  2016 99-com.rules
279f8967ca1013b96aa59416fd8557ab  99-com.rules
So especially given your tests - probably not specific to the version of the Pi, but more related to initial installed versions / upgrade paths...

Fix:

Following https://github.com/raspberrypi/linux/is ... -292901658, my non-working system did not have raspberrypi-sys-mods installed, while my working systems did. Installing this, and confirming to overwrite '/etc/udev/rules.d/99-com.rules' if prompted, resolved the issue. Be sure to remove any existing GPIO exports, or simply reboot - or existing exports will still have the broken permissions.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5161
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Sat May 13, 2017 12:49 pm

ziesemer wrote:my non-working system did not have raspberrypi-sys-mods installed, while my working systems did
Do you know why raspberrypi-sys-mods was missing? It should be installed by default on raspbian jessie.
Was it manually removed? Did you update from a non-supported version (wheezy)? Some other means of installing?

fruitoftheloom
Posts: 17603
Joined: Tue Mar 25, 2014 12:40 pm

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Sat May 13, 2017 1:09 pm

ziesemer wrote:Re-applied the 4.9 kernel via rpi-update, broken again. Looks to be udev-related. The above code sample successfully created /sys/class/gpio/gpio4 - but everything is owned as root:root, not root:gpio. (Even then, all the files are 644, vs. 770 that I see on a working instance.) As such, I'm also now reproducing this with only sysfs, and completely ruling-out anything Python-related.

Following the April 5-10 discussion at https://github.com/raspberrypi/linux/issues/791, my /etc/udev/rules.d is certainly different between the broken Pi1:

Code: Select all

$ ll 99-com.rules ; md5sum 99-com.rules
-rw-r--r-- 1 root root 506 Nov 21  2015 99-com.rules
1de39a305333e7c5bf0dca7ba5df9bdf  99-com.rules
... and and working Pi2 or Pi3:

Code: Select all

$ ll 99-com.rules ; md5sum 99-com.rules
-rw-r--r-- 1 root root 983 Mar 21  2016 99-com.rules
279f8967ca1013b96aa59416fd8557ab  99-com.rules
So especially given your tests - probably not specific to the version of the Pi, but more related to initial installed versions / upgrade paths...

Fix:

Following https://github.com/raspberrypi/linux/is ... -292901658, my non-working system did not have raspberrypi-sys-mods installed, while my working systems did. Installing this, and confirming to overwrite '/etc/udev/rules.d/99-com.rules' if prompted, resolved the issue. Be sure to remove any existing GPIO exports, or simply reboot - or existing exports will still have the broken permissions.
rpi-update should only be used under advisement it installs a Testing Kernel...

Raspbian Jessie all that is required is:

Code: Select all

sudo apt-get update
sudo apt-get dist-upgrade

Code: Select all

uname -a
Linux raspberrypi 4.9.24-v7+ #993 SMP Wed Apr 26 18:01:23 BST 2017 armv7l GNU/Linux
Adieu

ziesemer
Posts: 12
Joined: Wed May 13, 2015 2:20 am
Location: Appleton, WI
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Sat May 13, 2017 1:36 pm

fruitoftheloom wrote: rpi-update should only be used under advisement it installs a Testing Kernel...
Yes, but rpi-update is not relevant here. This was a concern with non-root GPIO access broken after the 4.9 kernel being applied by (only) apt-get dist-upgrade. I only used rpi-update to revert back to 4.4, and now back to 4.9 - using the specific commit hashes. Please correct me if otherwise, but I didn't see any way to revert or to re-upgrade using only apt-get.
dom wrote:
ziesemer wrote:my non-working system did not have raspberrypi-sys-mods installed, while my working systems did
Do you know why raspberrypi-sys-mods was missing? It should be installed by default on raspbian jessie.
Was it manually removed? Did you update from a non-supported version (wheezy)? Some other means of installing?
That's a great question, isn't it? It was a clean Raspbian Jessie install. I'll see what history / logs are left on the card, or if I can reproduce if I still have the same downloaded disk image saved somewhere. My /var/log/apt/history.log* files go back to 2016-05-07, appear to contain my original installation / setups, and have no mention of raspberrypi-sys-mods until yesterday's install. Looking at the downloads I've saved, "2015-11-21-raspbian-jessie-lite.zip" must be what I had originally used here.

I'm not concerned about this for myself, but would like to continue to help to diagnose in case there is something that should be corrected here for anyone else having the same issue.

ziesemer
Posts: 12
Joined: Wed May 13, 2015 2:20 am
Location: Appleton, WI
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Sat May 13, 2017 3:56 pm

ziesemer wrote:
dom wrote:
ziesemer wrote:my non-working system did not have raspberrypi-sys-mods installed, while my working systems did
Do you know why raspberrypi-sys-mods was missing? It should be installed by default on raspbian jessie.
Was it manually removed? Did you update from a non-supported version (wheezy)? Some other means of installing?
ziesemer wrote: Looking at the downloads I've saved, "2015-11-21-raspbian-jessie-lite.zip" must be what I had originally used here.
Using a clean install from "2015-11-21-raspbian-jessie-lite.zip", raspberrypi-sys-mods was / is NOT installed by default:

Code: Select all

[email protected]:~ $ apt show raspberrypi-sys-mods
Package: raspberrypi-sys-mods
Version: 20131021
Maintainer: Serge Schneider <[email protected]>
Installed-Size: 26.6 kB
Homepage: https://github.com/RPi-Distro/raspberrypi-sys-mods
Priority: optional
Section: admin
Download-Size: 2,094 B
APT-Sources: http://archive.raspberrypi.org/debian/ jessie/main armhf Packages
Description: System tweaks for the Raspberry Pi
 Various modifications to improve the performance or user experience.

[email protected]:~ $ dpkg -s raspberrypi-sys-mods
dpkg-query: package 'raspberrypi-sys-mods' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
[email protected]:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
[email protected]:~ $ uname -a
Linux raspberrypi 4.1.13-v7+ #826 SMP PREEMPT Fri Nov 13 20:19:03 GMT 2015 armv7l GNU/Linux
Perhaps it should be considered a dependency of the 4.9 kernel / firmware update?

User avatar
DougieLawson
Posts: 34095
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Sat May 13, 2017 4:00 pm

Why not do a clean install of 2017-04-10
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

ziesemer
Posts: 12
Joined: Wed May 13, 2015 2:20 am
Location: Appleton, WI
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Sat May 13, 2017 4:20 pm

DougieLawson wrote:Why not do a clean install of 2017-04-10
Sure, that's always a "last resort" option. However, myself and others are experiencing this issue after an upgrade. The effort here was to at least explain the issue, and to hopefully help anyone else having the same problem.

Unless we are looking to suggest that certain upgrades (such as the 4.9 kernel upgrade) are not supported? Keep in mind, this system wasn't even an upgrade from wheezy. This also wasn't the result of trying to go "bleeding edge" with rpi-update, but simply running apt update/upgrade.

It seems that there may have been an assumption that raspberrypi-sys-mods would have been installed with any default jessie install. Seeing that this is not the case, this is maybe something that could easily be accounted for in the upgrade process - or at least shown as a notification during the upgrade process if an appropriate automated fix can't be applied without other concerns.

PI_Stuart
Posts: 4
Joined: Mon Jan 04, 2016 6:42 pm

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Tue Dec 12, 2017 11:24 pm

I resolved my issue with this Link. The issue related to permissions on /dev/gpiomem
My system is a Model B upgraded from Wheezy to Jessie to Stretch.
Having checked that my user in this case "pi" was a member of group "gpio"
using $groups pi I when on to check permissions on /dev/gpiomem

$ ls -l /dev/gpiomem
crw------- 1 root root 244, 0 Dec 12 22:39 /dev/gpiomem

should be .......
crw-rw---- 1 root gpio 244, 0 Dec 28 22:51 /dev/gpiomem

So needed to change group to gpio......
$ sudo chown root.gpio /dev/gpiomem
Then change the permissions.
$ sudo chmod g+rw /dev/gpiomem

I have put this in forum as I found this before struggling on and finding the eventual solution.

Now just got node-red working turning LED on/off success!

User avatar
DougieLawson
Posts: 34095
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Thu Dec 14, 2017 2:47 pm

The changing of permissions/ownership stuff for /dev/gpiomen is done in /etc/udev/rules.d/99-com.rules which is in raspberrypi-sys-mods package. You may want to reinstall that package.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

moth-paul
Posts: 6
Joined: Fri Jan 11, 2013 3:39 pm

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Wed Jan 17, 2018 11:07 pm

You say "The changing of permissions/ownership stuff for /dev/gpiomen is done in /etc/udev/rules.d/99-com.rules which is in raspberrypi-sys-mods package."

How does one reinstall reinstall that package?

User avatar
DougieLawson
Posts: 34095
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Non-root GPIO access broken with 4.9 kernel on Pi1

Wed Jan 17, 2018 11:17 pm

sudo apt update; sudo apt install --reinstall raspberrypi-sys-mods;sudo reboot
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Return to “Advanced users”