From 462167cc9355770e7b9322375ab82b005073936b Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 20 Feb 2024 12:43:24 -0500 Subject: [PATCH] add udev rules --- rpi/default.nix | 53 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index f1e3087..24d3a45 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -202,7 +202,7 @@ in # linux kernel. kernel = { enable = true; - value = "u-boot-rpi-arm64.bin"; + value = if cfg.uboot.enable then "u-boot-rpi-arm64.bin" else "kernel.img"; }; arm_64bit = { enable = true; @@ -267,11 +267,52 @@ in hardware.enableRedistributableFirmware = true; services = { - udev.extraRules = '' - SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660" - KERNEL=="gpiomem", GROUP="gpio", MODE="0660" - KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" - ''; + udev.extraRules = + let shell = "${pkgs.bash}/bin/bash"; + in '' + # https://raw.githubusercontent.com/RPi-Distro/raspberrypi-sys-mods/master/etc.armhf/udev/rules.d/99-com.rules + SUBSYSTEM=="input", GROUP="input", MODE="0660" + SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660" + SUBSYSTEM=="spidev", GROUP="spi", MODE="0660" + SUBSYSTEM=="*gpiomem*", GROUP="gpio", MODE="0660" + SUBSYSTEM=="rpivid-*", GROUP="video", MODE="0660" + + KERNEL=="vcsm-cma", GROUP="video", MODE="0660" + SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660" + + SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660" + SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${shell} -c 'chgrp -R gpio /sys/class/gpio && chmod -R g=u /sys/class/gpio'" + SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="${shell} -c 'chgrp -R gpio /sys%p && chmod -R g=u /sys%p'" + + # PWM export results in a "change" action on the pwmchip device (not "add" of a new device), so match actions other than "remove". + SUBSYSTEM=="pwm", ACTION!="remove", PROGRAM="${shell} -c 'chgrp -R gpio /sys%p && chmod -R g=u /sys%p'" + + KERNEL=="ttyAMA[0-9]*|ttyS[0-9]*", PROGRAM="${shell} -c '\ + ALIASES=/proc/device-tree/aliases; \ + TTYNODE=$$(readlink /sys/class/tty/%k/device/of_node | sed 's/base/:/' | cut -d: -f2); \ + if [ -e $$ALIASES/bluetooth ] && [ $$TTYNODE/bluetooth = $$(strings $$ALIASES/bluetooth) ]; then \ + echo 1; \ + elif [ -e $$ALIASES/console ]; then \ + if [ $$TTYNODE = $$(strings $$ALIASES/console) ]; then \ + echo 0;\ + else \ + exit 1; \ + fi \ + elif [ $$TTYNODE = $$(strings $$ALIASES/serial0) ]; then \ + echo 0; \ + elif [ $$TTYNODE = $$(strings $$ALIASES/serial1) ]; then \ + echo 1; \ + else \ + exit 1; \ + fi \ + '", SYMLINK+="serial%c" + + ACTION=="add", SUBSYSTEM=="vtconsole", KERNEL=="vtcon1", RUN+="${shell} -c '\ + if echo RPi-Sense FB | cmp -s /sys/class/graphics/fb0/name; then \ + echo 0 > /sys$devpath/bind; \ + fi; \ + '" + ''; }; };