EBC Exercise 42 udev

From eLinux.org
Revision as of 04:44, 18 July 2019 by Yoder (talk | contribs)
Jump to: navigation, search

thumb‎ Embedded Linux Class by Mark A. Yoder


Here's how to setup udev to set the permissions when a device is brought up. In my case it's setting up permissions so /sys/class/remoteproc doesn't need sudo. Here are the permissions before the udev rule:

bone$ cd /sys/class/remoteproc/remoteproc1
bone$ ls
0 lrwxrwxrwx 1 root root    0 Jul 16 16:28 device -> ../../../4a334000.pru
0 -rw-r--r-- 1 root root 4096 Jul 16 16:28 firmware
0 drwxr-xr-x 2 root root    0 Jul 16 16:28 power
0 -rw-r--r-- 1 root root 4096 Jul 18 08:05 state
0 lrwxrwxrwx 1 root root    0 Jul 16 16:28 subsystem -> ../../../../../../../../class/remoteproc


Clone the BeagleBoard repo

bone$ git clone https://github.com/rcn-ee/repos
bone$ cd repos/bb-customizations/suite/buster/debian

Find some rules that are like what you are doing

bone$ ls
10-of-symlink.rules       85-gpio-noroot.rules           install
60-omap-tty.rules         86-remoteproc-noroot.rules     postinst
80-eeprom-noroot.rules    changelog                      rtl8723bu-blacklist.conf
80-gpio-noroot.rules      compat                         rules
81-pwm-noroot.rules       control                        ti_pru_firmware
82-gpio-config-pin.rules  copyright                      zz-uenv_txt
83-eqep-noroot.rules      generic-board-startup.service

In this case 81-pwm-noroot.rules is a good example.

bone$ cat 81-pwm-noroot.rules
# /etc/udev/rules.d/81-pwm-noroot.rules
#
# ReWritten by: Matthijs van Duin
# Corrects sys PWM permissions on the BB so non-root users in the pwm group can
# manipulate pwm along with creating a symlink under /dev/pwm/
#
SUBSYSTEM=="pwm", ACTION=="add", \
        RUN+="/bin/chgrp -R pwm '/sys%p'", \
        RUN+="/bin/chmod -R g=u '/sys%p'"

# automatically export pwm channels
SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="add",  ATTR{export}="0"
SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="add", ATTR{npwm}!="1",  ATTR{export}="1"




thumb‎ Embedded Linux Class by Mark A. Yoder