Skip to content

Commit 02f1335

Browse files
committed
add udev rules and script for non-root access to gpio
Refer to Issue #137 for details: Access to GPIO and PWM as non-root user not functioning #137
1 parent c087b3c commit 02f1335

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KERNEL=="gpio*", SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/usr/local/bin/udev-non-root-gpio-permissions.sh"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Result: chown debian:debian /sys/class/gpio
4+
5+
chown -R debian:debian /sys/devices/gpio
6+
chown -R debian:debian /sys/class/gpio
7+
chown -R debian:debian /sys/devices/platform/ocp
8+
chown -R debian:debian /sys/class/pwm
9+
10+
#GPIO ( active_low device direction edge power subsystem uevent value )
11+
find /sys/class/gpio -type d -exec chmod 2770 {} \;
12+
find /sys/class/gpio -name "direction" -exec chmod 0660 {} \;
13+
find /sys/class/gpio -name "edge" -exec chmod 0660 {} \;
14+
find /sys/class/gpio -name "value" -exec chmod 0660 {} \;
15+
find /sys/class/gpio -name "active_low" -exec chmod 0660 {} \;
16+
find /sys/class/gpio -name "device" -exec chmod 0660 {} \;
17+
find /sys/class/gpio -name "power" -exec chmod 0660 {} \;
18+
find /sys/class/gpio -name "subsystem" -exec chmod 0660 {} \;
19+
20+
#PWM ( duty_cycle enable period polarity power uevent )
21+
find /sys/devices/platform/ocp -name "duty_cycle" -exec chmod 0660 {} \;
22+
find /sys/devices/platform/ocp -name "enable" -exec chmod 0660 {} \;
23+
find /sys/devices/platform/ocp -name "period" -exec chmod 0660 {} \;
24+
find /sys/devices/platform/ocp -name "polarity" -exec chmod 0660 {} \;
25+
find /sys/devices/platform/ocp -name "power" -exec chmod 0660 {} \;
26+
find /sys/class/pwm -name "duty_cycle" -exec chmod 0660 {} \;
27+
find /sys/class/pwm -name "enable" -exec chmod 0660 {} \;
28+
find /sys/class/pwm -name "period" -exec chmod 0660 {} \;
29+
find /sys/class/pwm -name "polarity" -exec chmod 0660 {} \;
30+
find /sys/class/pwm -name "power" -exec chmod 0660 {} \;
31+
32+
chmod 0220 /sys/class/gpio/export
33+
chmod 0220 /sys/class/gpio/unexport
34+
chmod 0220 /sys/class/pwm/export
35+
chmod 0220 /sys/class/pwm/unexport
36+
37+
find /sys/class/gpio -name "uevent" -exec chmod 0660 {} \;
38+
find /sys/class/gpio -name "autosuspend_delay_ms" -exec chmod 0660 {} \;
39+
find /sys/class/gpio -name "control" -exec chmod 0660 {} \;
40+
find /sys/class/pwm -name "uevent" -exec chmod 0660 {} \;
41+
find /sys/devices/platform/ocp -name "uevent" -exec chmod 0660 {} \;
42+
43+
# Additional code for getting AIN pins set up
44+
ain_activator=/sys/devices/platform/bone_capemgr/slots
45+
chown -R debian:debian $ain_activator/
46+
chmod -R 2770 $ain_activator/

0 commit comments

Comments
 (0)