4.9.78-ti-r94 发行版附带 81-pwm-nonroot.rules
# /etc/udev/rules.d/81-pwm-noroot.rules
#
# Corrects sys PWM permissions on the BB so non-root users in the gpio group can manipulate bits
#
SUBSYSTEM=="pwm", ACTION=="add", PROGRAM="/bin/sh -c '/bin/chown -R root:pwm /sys/class/pwm/"
SUBSYSTEM=="pwm", ACTION=="add", PROGRAM="/bin/sh -c '/bin/chmod -R ug+rw /sys/class/pwm/"
SUBSYSTEM=="pwm", ACTION=="add", PROGRAM="/bin/sh -c '/bin/chown -R root:pwm /sys/class/pwm/pwmchip*/'"
SUBSYSTEM=="pwm", ACTION=="add", PROGRAM="/bin/sh -c '/bin/chmod -R ug+rw /sys/class/pwm/pwmchip*/'"
无论如何,似乎是行不通的。 rwxr-xr-x 3 root root 0 Oct 11 03:17 pwm1 IS ROOT:ROOT
lrwxrwxrwx 1 root pwm 0 Oct 11 02:32 device -> ../../../48304200.pwm
-rw-rw---- 1 root pwm 4096 Oct 11 03:14 export
-rw-rw-r-- 1 root pwm 4096 Oct 11 02:31 npwm
drwxrwxr-x 2 root pwm 0 Oct 11 02:31 power
lrwxrwxrwx 1 root pwm 0 Oct 11 02:32 subsystem -> ../../../../../../../class/pwm
-rw-rw-r-- 1 root pwm 4096 Oct 11 02:31 uevent
-rw-rw---- 1 root pwm 4096 Oct 11 03:17 unexport
root@s2w10l:/sys/class/pwm/pwmchip6# echo 1 > export
total 0
lrwxrwxrwx 1 root pwm 0 Oct 11 02:32 device -> ../../../48304200.pwm
-rw-rw---- 1 root pwm 4096 Oct 11 03:17 export
-rw-rw-r-- 1 root pwm 4096 Oct 11 02:31 npwm
drwxrwxr-x 2 root pwm 0 Oct 11 02:31 power
drwxr-xr-x 3 root root 0 Oct 11 03:17 pwm1<<< IS ROOT ROOT <<<<<<<<<?!?!?!?!?!
lrwxrwxrwx 1 root pwm 0 Oct 11 02:32 subsystem -> ../../../../../../../class/pwm
-rw-rw-r-- 1 root pwm 4096 Oct 11 02:31 uevent
-rw-rw---- 1 root pwm 4096 Oct 11 03:17 unexport
答案1
我必须添加 90 条规则
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;'"
SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c 'chown -R root:pwm /sys/class/pwm/* && chmod -R 770 /sys/class/pwm/*;'"
并且确实解决了 GPIO 的问题,因为 udev 感知到了 GPIO 导出
# on a second temrinal monitor the udev
udevadm monitor
...
KERNEL - the kernel uevent
KERNEL[46318.324637] add /devices/platform/ocp/44e07000.gpio/gpiochip0/gpio/gpio24 (gpio)
UDEV [46318.648582] add /devices/platform/ocp/44e07000.gpio/gpiochip0/gpio/gpio24 (gpio)
但对于 PWM 来说则不然
echo 0 > /sys/class/pwm/pwmchip6/export
# on the second terminal
udevadm monitor # remains silent
任何帮助,将不胜感激。谢谢