EBC Exercise 42 udev

Here's how to setup udev to set the permissions when a device is brought up. Some of this came from.

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 -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 your 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  is a good example.

bone$ cat 81-pwm-noroot.rules # # SUBSYSTEM=="pwm", ACTION=="add", \ RUN+="/bin/chgrp -R pwm '/sys%p'", \ RUN+="/bin/chmod -R g=u '/sys%p'" SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="add", ATTR{export}="0" SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="add", ATTR{npwm}!="1", ATTR{export}="1" ...
 * 1) /etc/udev/rules.d/81-pwm-noroot.rules
 * 1) ReWritten by: Matthijs van Duin
 * 2) Corrects sys PWM permissions on the BB so non-root users in the pwm group can
 * 3) manipulate pwm along with creating a symlink under /dev/pwm/
 * 1) automatically export pwm channels

Copy to another file and edit. I'm using. bone$ cat 86-remoteproc-noroot.rules # # 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", \ ...
 * 1) /etc/udev/rules.d/86-remoteproc-noroot.rules
 * 1) ReWritten by: Mark A. Yoder
 * 2) Corrects sys remoteproc permissions on the BB so non-root users in the remoteproc
 * 3) group can run the PRUs without sudo'ing

Install and test
Then copy to. 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 DEVPATH=/devices/platform/ocp/4a326004.pruss-soc-bus/4a300000.pruss/4a334000.pru/remoteproc/remoteproc1 DEVTYPE=remoteproc ACTION=add SUBSYSTEM=remoteproc net.ifnames=0 USEC_INITIALIZED=8250606 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.

Reboot and check
The final check is to reboot and check the permissions. bone$ sudo reboot bone$ cd /sys/class/remoteproc/remoteproc1 bone$ ls -ls total 0 0 lrwxrwxrwx 1 root remoteproc   0 Jul 16 16:28 device -> ../../../4a334000.pru 0 -rw-rw-r-- 1 root remoteproc 4096 Jul 16 16:28 firmware 0 drwxrwxr-x 2 root remoteproc   0 Jul 16 16:28 power 0 -rw-rw-r-- 1 root remoteproc 4096 Jul 18 08:05 state 0 lrwxrwxrwx 1 root remoteproc   0 Jul 16 16:28 subsystem -> ../../../../../../../../class/remoteproc 0 -rw-rw-r-- 1 root remoteproc 4096 Jul 16 16:28 uevent Looks like it worked.

See https://digitaldrummerj.me/git-syncing-fork-with-original-repo/ for syncing with remote repo