EBC Exercise 42 udev

From eLinux.org
Revision as of 05:59, 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

Edit the rules for you case.

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"

Copy to another file and edit. I'm using 86-remoteproc-noroot.rules.

bone$ cat 86-remoteproc-noroot.rules
# /etc/udev/rules.d/86-remoteproc-noroot.rules
# ReWritten by: Mark A. Yoder
# Corrects sys remoteproc permissions on the BB so non-root users in the remoteproc 
# group can run the PRUs without sudo'ing
SUBSYSTEM=="remoteproc", ACTION=="add", \
        RUN+="/bin/chgrp -R remoteproc '/sys%p'", \
        RUN+="/bin/chmod -R g=u '/sys%p'", \
        RUN+="/usr/bin/touch /lib/firmware/am335x-pru0-fw", \
        RUN+="/usr/bin/touch /lib/firmware/am335x-pru1-fw", \

Install and test

Then copy to /etc/udev/rules.d.

bone$ cp 86-remoteproc-noroot.rules /etc/udev/rules.d

Now test the rule. This won't do anything, but it tells you what it plans to do.

bone$ udevadm test --action="add" /sys/class/remoteproc/remoteproc1
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

Load module index
Network interface NamePolicy= disabled on kernel command line, ignoring.
Parsed configuration file /lib/systemd/network/99-default.link
Created link configuration context.
Reading rules file: /lib/udev/rules.d/85-regulatory.rules
Reading rules file: /etc/udev/rules.d/86-remoteproc-noroot.rules
Reading rules file: /lib/udev/rules.d/89-alsa-ucm.rules

run: '/bin/chgrp -R remoteproc '/sys/devices/platform/ocp/4a326004.pruss-soc-bus/4a300000.pruss/4a334000.pru/remoteproc/remoteproc1
run: '/bin/chmod -R g=u '/sys/devices/platform/ocp/4a326004.pruss-soc-bus/4a300000.pruss/4a334000.pru/remoteproc/remoteproc1
Unload module index
Unloaded link configuration context.

Look carefully for errors.

thumb‎ Embedded Linux Class by Mark A. Yoder