1

I'm working with a beaglebone black board (ubuntu release for ARM architecture), which has some general purpose input/output (GPIO) interface to read sensors/drive motors etc.. which are configurable by 'exporting' the wanted pin using the following commmand:

bbb@arm:/sys/class/gpio$echo 30 > export

here the default folder and its contents:

bbb@arm:~$ ls -l /sys/class/gpio/
total 0
-rwxrwxrwx 1 bbb users 4096 Jan  6 12:13 export
lrwxrwxrwx 1 bbb users    0 Jan  6 12:13 gpiochip0 -> ../../devices/platform/ocp/44e07000.gpio/gpio/gpiochip0
lrwxrwxrwx 1 bbb users    0 Jan  6 12:13 gpiochip32 -> ../../devices/platform/ocp/4804c000.gpio/gpio/gpiochip32
lrwxrwxrwx 1 bbb users    0 Jan  6 12:13 gpiochip64 -> ../../devices/platform/ocp/481ac000.gpio/gpio/gpiochip64
lrwxrwxrwx 1 bbb users    0 Jan  6 12:13 gpiochip96 -> ../../devices/platform/ocp/481ae000.gpio/gpio/gpiochip96
-rwxrwxrwx 1 bbb users 4096 Jan  6 12:13 unexport

Since I want to use those pins as a normal user I tried to configure some rules to change the proprietary and user's group through the following rule:

bbb@arm:~$ cat /etc/udev/rules.d/99-gpio.rules 
KERNEL=="gpio*", SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c 'chown -R bbb:users /sys/class/gpio; chmod -R 777 /sys/class/gpio'"
KERNEL=="gpio*", SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c 'chown -R bbb:users /sys/class/virtual/gpio; chmod -R 777 /sys/class/virtual/gpio'"

It works pretty good and the rule gets loaded while booting. BUT if I export a pin, that I want to use:

bbb@arm:/sys/class/gpio$ echo 30 > export
bbb@arm:/sys/class/gpio$ cd gpio30
bbb@arm:/sys/class/gpio/gpio30$ ls -l
total 0
-rw-r--r-- 1 root root 4096 Jan  7 16:16 active_low
lrwxrwxrwx 1 root root    0 Jan  7 16:16 device -> ../../../44e07000.gpio
-rw-r--r-- 1 root root 4096 Jan  7 16:16 direction
-rw-r--r-- 1 root root 4096 Jan  7 16:16 edge
drwxr-xr-x 2 root root    0 Jan  7 16:16 power
lrwxrwxrwx 1 root root    0 Jan  7 16:16 subsystem -> ../../../../../../class/gpio
-rw-r--r-- 1 root root 4096 Jan  7 16:15 uevent
-rw-r--r-- 1 root root 4096 Jan  7 16:16 value

I have the problem that all subdirectory and folders still have root as a ownwer and as a group. So I cannot configure the single pin (gpio) using my user account.

How should I modify my rules to get everything the new exported folder under my user's name (bbb) and group (users) ?????

1
  • That's a great question, I'm stuck right now with PWM that I am trying to export. The exported PWM channel is always owned by root! Commented Sep 2, 2019 at 11:02

1 Answer 1

2

OK, I take back everything I said after testing on my Pi. Add one additional rule to your current file:
KERNEL=="gpio*",SUBSYSTEM=="gpio",ACTION=="add",PROGRAM="/bin/sh -c 'chown -R bbb:users /sys%p;chmod -R 770 /sys%p'"

Now test with: echo 30 > export

If you do an ls -l /sys/class/gpio30 it looks like it's still owned by root, but if you notice it is a link to /sys/devices/virtual/gpio/gpio30.

ls -la /sys/devices/virtual/gpio/gpio30
and you'll see your script has run successfully.

This might help: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=9667

1
  • Yeah...it works!!!!
    – Dave
    Commented Jan 8, 2016 at 7:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .