From 40ef362351a6d015478a33306e35c1ab9dfa077e Mon Sep 17 00:00:00 2001 From: Marcus Aram <4435760+marcusaram@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:15:52 +0100 Subject: [PATCH 1/2] Load the LED timer trigger on Armbian The ROCK 4C+ kernel has the timer trigger as a module. Setting the LED was the first thing the first start did, and under set -e the failed write ended it: no user, no storage, no squirreld, at every boot. The first start now loads ledtrig-timer and goes on without the LED if that fails; squirreld loads it too, as it already did for the pattern trigger. --- deploy/firstboot.sh | 7 ++++--- internal/led/led.go | 24 +++++++++++++++++------- internal/led/led_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/deploy/firstboot.sh b/deploy/firstboot.sh index a7598ce..350b183 100755 --- a/deploy/firstboot.sh +++ b/deploy/firstboot.sh @@ -39,9 +39,10 @@ for l in /sys/class/leds/ACT /sys/class/leds/led0 /sys/class/leds/blue:status; d done led() { [ -n "$LED" ] || return 0 - echo timer > "$LED/trigger" - echo "$1" > "$LED/delay_on" - echo "$2" > "$LED/delay_off" + # Armbian has the timer trigger as a module. The LED never stops the + # start: without the trigger it keeps what it had. + grep -qw timer "$LED/trigger" || modprobe ledtrig-timer 2> /dev/null || true + { echo timer > "$LED/trigger" && echo "$1" > "$LED/delay_on" && echo "$2" > "$LED/delay_off"; } 2> /dev/null || true } led 120 120 on_exit() { diff --git a/internal/led/led.go b/internal/led/led.go index f345283..38d9284 100644 --- a/internal/led/led.go +++ b/internal/led/led.go @@ -23,7 +23,7 @@ const ( type LED struct { dir string - // load loads a kernel module (the pattern trigger); replaced in tests. + // load loads a kernel module (a trigger); replaced in tests. load func(module string) error mu sync.Mutex @@ -51,6 +51,9 @@ func (l *LED) write(name, value string) { } func (l *LED) timer(on, off string) { + if !l.trigger("timer") { + return + } l.write("trigger", "timer") l.write("delay_on", on) l.write("delay_off", off) @@ -115,13 +118,20 @@ func (l *LED) Load(avg float64) { l.avg = avg } -// heartbeat sets the heartbeat through the kernel's pattern trigger, -// loading it when needed; false when the kernel has none. +// trigger tells whether the kernel has a trigger, loading its module when +// needed: Armbian has timer and pattern as modules. +func (l *LED) trigger(name string) bool { + if strings.Contains(l.read("trigger"), name) { + return true + } + return l.load != nil && l.load("ledtrig-"+name) == nil && strings.Contains(l.read("trigger"), name) +} + +// heartbeat sets the heartbeat through the kernel's pattern trigger; +// false when the kernel has none. func (l *LED) heartbeat() bool { - if !strings.Contains(l.read("trigger"), "pattern") { - if l.load == nil || l.load("ledtrig-pattern") != nil || !strings.Contains(l.read("trigger"), "pattern") { - return false - } + if !l.trigger("pattern") { + return false } max := 255 if n, err := strconv.Atoi(strings.TrimSpace(l.read("max_brightness"))); err == nil && n > 0 { diff --git a/internal/led/led_test.go b/internal/led/led_test.go index 5e8c2b0..8154db3 100644 --- a/internal/led/led_test.go +++ b/internal/led/led_test.go @@ -63,3 +63,27 @@ func TestPatterns(t *testing.T) { var none *LED none.Set(Problem) // a Pi without LED must not crash } + +// Armbian has the timer trigger as a module: loaded on demand, and the LED +// is left alone when that fails. +func TestTimerModule(t *testing.T) { + sys := t.TempDir() + dir := filepath.Join(sys, "class/leds/blue:status") + os.MkdirAll(dir, 0o755) + os.WriteFile(filepath.Join(dir, "trigger"), []byte("none [heartbeat] pattern\n"), 0o644) + read := func(n string) string { b, _ := os.ReadFile(filepath.Join(dir, n)); return string(b) } + l := Find(sys) + var loaded []string + l.load = func(m string) error { loaded = append(loaded, m); return os.ErrNotExist } + l.Set(Busy) + if read("trigger") != "none [heartbeat] pattern\n" || len(loaded) != 1 || loaded[0] != "ledtrig-timer" { + t.Errorf("busy without the timer module: %q, loaded %q", read("trigger"), loaded) + } + l.load = func(m string) error { + return os.WriteFile(filepath.Join(dir, "trigger"), []byte("none [heartbeat] pattern timer\n"), 0o644) + } + l.Set(Problem) + if read("trigger") != "timer\n" || read("delay_on") != "40\n" { + t.Errorf("problem with the timer module: %q %q", read("trigger"), read("delay_on")) + } +} From 0a152b43b06c62fa136072cb755e0fbfe4eb5386 Mon Sep 17 00:00:00 2001 From: Marcus Aram <4435760+marcusaram@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:46:12 +0100 Subject: [PATCH 2/2] Keep the USB 2 PHY on the ROCK 4C+'s device port The overlay from the teslausb wiki also set the port's phys to the USB 3 PHY alone, so a USB 2 connection (a USB 2 hub, cable or adapter) never showed up. It now only changes dr_mode; the port keeps both PHYs and falls back to USB 2 when there is no USB 3 link. Checked on a ROCK 4C+: the drive appears on a Mac behind a USB 2 hub. --- deploy/armbian/dwc3-0-device.dts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/deploy/armbian/dwc3-0-device.dts b/deploy/armbian/dwc3-0-device.dts index da19755..17dc493 100644 --- a/deploy/armbian/dwc3-0-device.dts +++ b/deploy/armbian/dwc3-0-device.dts @@ -1,7 +1,8 @@ // Puts the upper USB 3 port (dwc3_0) of the Radxa ROCK 4C+ in device mode, -// so it can be the car's drive. From the teslausb wiki, where it works -// with Armbian on this board: -// https://github.com/marcone/teslausb/wiki/Rock-Pi-4C-plus-Installation +// so it can be the car's drive. Only the mode changes: the port keeps its +// USB 2 and USB 3 PHYs, so it works with USB 2 hosts and cables too. (The +// overlay in the teslausb wiki also sets phys to the USB 3 PHY alone; a +// USB 2 connection then never shows up.) /dts-v1/; /plugin/; @@ -12,16 +13,6 @@ target = <&usbdrd_dwc3_0>; __overlay__ { dr_mode = "peripheral"; - compatible = "snps,dwc3"; - reg = <0x0 0xfe800000 0x0 0x100000>; - phys = <&tcphy0_usb3>; - phy-names = "usb3-phy"; - phy_type = "utmi_wide"; - snps,dis_enblslpm_quirk; - snps,dis-u2-freeclk-exists-quirk; - snps,dis_u2_susphy_quirk; - snps,dis-del-phy-power-chg-quirk; - snps,xhci-slow-suspend-quirk; }; }; };