From 58ce1fb99f7b1d862c384eb2aafa769449605f45 Mon Sep 17 00:00:00 2001 From: Chris Blake Date: Tue, 18 Jun 2024 19:13:31 -0500 Subject: [PATCH] fix: additional fixups for UNVR/UNVRPro * Fixup fan control so it works on UNVR * Add LED integration work for UNVR * Rename our mtd-ro kernel module dir * Fixup shortnames in ubnteeprom --- overlay/filesystem/usr/bin/unvr-fan-daemon | 8 ++++- .../usr/lib/init/boot/ubnt-ulcmd.sh | 3 +- .../lib/python3/dist-packages/ubnthelpers.py | 11 ------- .../systemd/system-shutdown/unifi-shutdown | 5 +++ scripts/docker/build_kernel.sh | 2 +- scripts/docker/run_debootstrap.sh | 3 +- tools/{mtd-lock => ubnt-mtd-lock}/Kbuild | 0 tools/{mtd-lock => ubnt-mtd-lock}/README.md | 4 +-- .../ubnt-mtd-lock.c | 0 tools/ubnteeprom/main.go | 31 ++++++++++--------- 10 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 overlay/filesystem/usr/lib/python3/dist-packages/ubnthelpers.py rename tools/{mtd-lock => ubnt-mtd-lock}/Kbuild (100%) rename tools/{mtd-lock => ubnt-mtd-lock}/README.md (56%) rename tools/{mtd-lock => ubnt-mtd-lock}/ubnt-mtd-lock.c (100%) diff --git a/overlay/filesystem/usr/bin/unvr-fan-daemon b/overlay/filesystem/usr/bin/unvr-fan-daemon index db1e2a0..6fa2cfc 100755 --- a/overlay/filesystem/usr/bin/unvr-fan-daemon +++ b/overlay/filesystem/usr/bin/unvr-fan-daemon @@ -3,7 +3,7 @@ import os import re import time -from ubnthelpers import get_ubnt_shortname +from functools import lru_cache SMARTCTL_PATH = "/usr/sbin/smartctl" @@ -36,6 +36,12 @@ THERMAL_SYS_PATHS = { }, } + +@lru_cache(None) +def get_ubnt_shortname() -> str: + return os.popen("ubnteeprom -systeminfo -key shortname").read().rstrip("\n") + + def __get_board_temps(): # Are we supported? if get_ubnt_shortname() not in THERMAL_SYS_PATHS: diff --git a/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh b/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh index 2b79977..ec95b34 100755 --- a/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh +++ b/overlay/filesystem/usr/lib/init/boot/ubnt-ulcmd.sh @@ -16,7 +16,8 @@ case "$(ubnteeprom -systeminfo -key shortname)" in exec ulcmd ;; "UNVR4") - # TODO: LED setup (2=white, 1=blue) against /sys/class/leds/ulogo_ctrl + # 2=white, 1=blue, 0=off, needs a value set with :x for ms + echo 1:500 > /sys/class/leds/ulogo_ctrl/pattern # Start our "daemon" loop so systemd stays happy while true; do sleep 3600 diff --git a/overlay/filesystem/usr/lib/python3/dist-packages/ubnthelpers.py b/overlay/filesystem/usr/lib/python3/dist-packages/ubnthelpers.py deleted file mode 100644 index f48fb74..0000000 --- a/overlay/filesystem/usr/lib/python3/dist-packages/ubnthelpers.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/python3 -import os -from functools import lru_cache - -""" -A handful of Ubiquiti Unifi device specific functions -""" - -@lru_cache(None) -def get_ubnt_shortname() -> str: - return os.popen("ubnteeprom -systeminfo -key shortname").read().rstrip("\n") diff --git a/overlay/filesystem/usr/lib/systemd/system-shutdown/unifi-shutdown b/overlay/filesystem/usr/lib/systemd/system-shutdown/unifi-shutdown index 601da30..34269ab 100755 --- a/overlay/filesystem/usr/lib/systemd/system-shutdown/unifi-shutdown +++ b/overlay/filesystem/usr/lib/systemd/system-shutdown/unifi-shutdown @@ -36,3 +36,8 @@ elif [ -f "/sys/class/hwmon/hwmon0/pwm1" ]; then echo 0 > "${pwm}" done fi + +# If UNVR, turn off LED +if [ -f "/sys/class/leds/ulogo_ctrl/pattern" ]; then + echo 0:500 > /sys/class/leds/ulogo_ctrl/pattern +fi diff --git a/scripts/docker/build_kernel.sh b/scripts/docker/build_kernel.sh index c7982ab..3a93a22 100755 --- a/scripts/docker/build_kernel.sh +++ b/scripts/docker/build_kernel.sh @@ -55,7 +55,7 @@ mv ./modules-dir ${build_path}/kernel/kernel-modules # Now that the kernel is done, build our out of tree modules! :) module_builddir=$(mktemp -d) -cp ${root_path}/tools/mtd-lock/* "${module_builddir}" +cp ${root_path}/tools/ubnt-mtd-lock/* "${module_builddir}" cd "${module_builddir}" make -C ${kernel_builddir}/${kernel_filename%.tar.gz} M=$PWD cp "${module_builddir}/ubnt-mtd-lock.ko" ${build_path}/kernel diff --git a/scripts/docker/run_debootstrap.sh b/scripts/docker/run_debootstrap.sh index 3f4e54e..a05b189 100755 --- a/scripts/docker/run_debootstrap.sh +++ b/scripts/docker/run_debootstrap.sh @@ -70,8 +70,7 @@ else "${build_path}/rootfs/usr/bin/ubnt-systool" \ "${build_path}/rootfs/usr/bin/ubnt-tools" \ "${build_path}/rootfs/usr/bin/ustorage" \ - "${build_path}/rootfs/usr/lib/init/boot/ubnt-ulcmd.sh" \ - "${build_path}/rootfs/usr/lib/python3/dist-packages/ubnthelpers.py" + "${build_path}/rootfs/usr/lib/init/boot/ubnt-ulcmd.sh" fi # Copy over bluetooth firmware files diff --git a/tools/mtd-lock/Kbuild b/tools/ubnt-mtd-lock/Kbuild similarity index 100% rename from tools/mtd-lock/Kbuild rename to tools/ubnt-mtd-lock/Kbuild diff --git a/tools/mtd-lock/README.md b/tools/ubnt-mtd-lock/README.md similarity index 56% rename from tools/mtd-lock/README.md rename to tools/ubnt-mtd-lock/README.md index db1b4ea..7062aae 100644 --- a/tools/mtd-lock/README.md +++ b/tools/ubnt-mtd-lock/README.md @@ -1,6 +1,6 @@ -# mtd-lock +# ubnt-mtd-lock -A stupid basic kernel module to ensure we set /dev/mtd as RO (fully) in our firmware. This is done to prevent users/bad actors from wiping your bootloader/Unifi EEPROM, which are required for your device to function! +A stupid basic kernel module to ensure we set /dev/mtd* as RO (fully) in our firmware. This is done to prevent users/bad actors from wiping your bootloader/Unifi EEPROM, which are required for your device to function! ## Building diff --git a/tools/mtd-lock/ubnt-mtd-lock.c b/tools/ubnt-mtd-lock/ubnt-mtd-lock.c similarity index 100% rename from tools/mtd-lock/ubnt-mtd-lock.c rename to tools/ubnt-mtd-lock/ubnt-mtd-lock.c diff --git a/tools/ubnteeprom/main.go b/tools/ubnteeprom/main.go index 1c5a397..82100a6 100644 --- a/tools/ubnteeprom/main.go +++ b/tools/ubnteeprom/main.go @@ -15,27 +15,30 @@ import ( // Type for device map type UBNTSysMap struct { - name, shortname, cpu, sysid string + name, shortname, sysshortname, cpu, sysid string } var UBNTDeviceMap = []UBNTSysMap{ { - name: "Unifi-NVR-PRO", - shortname: "UNVRPRO", - cpu: "AL324V2", - sysid: "ea20", + name: "UniFi Network Video Recorder Pro", + shortname: "UNVRPRO", + sysshortname: "UNVRPRO", + cpu: "AL324V2", + sysid: "ea20", }, { - name: "UniFi-NVR-4", - shortname: "UNVR4", - cpu: "AL324V2", - sysid: "ea16", // USB drive (non emmc) variant + name: "UniFi Network Video Recorder", + shortname: "UNVR", + sysshortname: "UNVR4", + cpu: "AL324V2", + sysid: "ea16", // USB drive (non emmc) variant }, { - name: "UniFi-NVR-4", - shortname: "UNVR4", - cpu: "AL324V2", - sysid: "ea1a", + name: "UniFi Network Video Recorder", + shortname: "UNVR", + sysshortname: "UNVR4", + cpu: "AL324V2", + sysid: "ea1a", }, } @@ -411,7 +414,7 @@ func return_values(rtype string, file string, filter string) { } else if rtype == "system" { okeys = UBNT_SystemInfo_Vars ret_data = append(ret_data, UBNT_Return_Values{name: "cpu", value: ourboard.cpu}) - ret_data = append(ret_data, UBNT_Return_Values{name: "shortname", value: ourboard.shortname}) + ret_data = append(ret_data, UBNT_Return_Values{name: "shortname", value: ourboard.sysshortname}) } else if rtype == "tools" { okeys = UBNT_Tools_vars ret_data = append(ret_data, UBNT_Return_Values{name: "board.name", value: ourboard.name})