fix:u30air boot led

This commit is contained in:
kanoqwq committed 2026-10-23 23:59:32 +08:00
1 parent f0b5ad43df
commit ac21653ddd
9 files changed
+161 -11

No files matched your search

+35
View File
@@ -54,3 +54,38 @@ initramfs `/init`,均未找到该机型的 RGB 开机轮换实现;U30 Air
- [部署及当前电池状态](../out/build-logs/20261023-060316-u30-low-charge-led-live-2513/command.log)
旧脚本保留在设备 `/mnt/mu300-disk/.mu300/backups/low-charge-led-20261023/`。
## 电池开机时轮换前的全灭间隔
用户继续反馈:红白蓝轮换存在,但开机后先全灭数秒。读取当前 U30 Air 的历史
启动记录,initramfs 在约 1.29 秒切换根目录,常规硬件服务约 9.23 秒进入。
原早期 USB preinit 已调用 `led-status boot`,但 `boot on` 没有初始化亮灯时限;
无外部电源且尚无 `.awake-until` 时,帧被 `awake()` 当成休眠而写成 0。
这是一项可确定性复现的代码缺陷;上述历史记录不是第一帧的光学实测时间。
修复使用现有共享 LED 控制器:
- `boot on` 建立原配置的亮灯时限,并在现有互斥锁内同步显示第一帧,再启动轮换
worker。重复通知保持幂等,不延长已开始的开机时限。
- 新增 `04_mu300_early_leds`,在 `preinit_essential` 先于 recorder 和 USB 设置
通知开机灯;移除 USB 钩子里的灯效调用,电池开机不再依赖 USB 接口是否存在。
- 复用同一帧函数、亮度、灯光开关、温控 owner 和 token 交接检查。没有新增常驻
服务、等待或 initramfs 写灯实现;现有 Linux boot 镜像无需更换。
新增测试在 worker 尚未运行时检查电池供电第一帧、配置禁用、亮度、重复通知和
原时限;旧实现会因没有亮灯时限而失败。另检查早期钩子注册、USB 解耦及 Unix
行尾。宿主组 39 项中 31 项执行通过;8 项缺少 ucode 的用例随后在既有 ARM64
容器补跑全部通过,共 39 项均有实际通过结果。覆盖原灯效、充电低电量颜色、
温控优先权、按键、F50/V50 和板级偏好。
- 复现:`out/build-logs/20261023-133200-u30air-led-dark-gap-reproduce-23466/command.log`
- 修复后回归:`out/build-logs/20261023-133243-u30air-early-led-regression-23496/command.log`
- 原生补跑:`out/build-logs/20261023-133332-u30air-early-led-native-33759/command.log`
已在核验身份的 U30 Air 更新四个启动文件,先核对原文件与提交版本一致、备份,
再校验 shell 语法并替换、回读 SHA-256。17 份 UCI 配置文件摘要不变,未重启或
触发当前开机灯,没有修改 boot、misc、GPT、NV 或充电配置。备份位于:
`/mnt/mu300-disk/.mu300/backups/early-leds-20261023-133442/`。
实际冷启动和电池独立供电的第一帧时刻仍待用户观察;本轮没有宣称从按电源键
到 Linux 接管前的 bootloader 阶段也消除了全灭。没有组装新包或提交本轮修改。
+2 -1
View File
@@ -203,6 +203,7 @@ done
chmod 0755 $R/opt/mu300/bin/cpu-voltage-platform $R/etc/init.d/mu300-cpu-driver
chmod 0755 $R/opt/mu300/bin/mu300-lowlatency $R/opt/mu300/bin/wifi-ready $R/opt/mu300/bin/mu300-service-cpus $R/etc/init.d/mu300-service-cpus
chmod 0755 $R/etc/init.d/mu300-sysd
chmod 0755 $R/opt/mu300/bin/mu300-modemd $R/opt/mu300/bin/mu300-sysd
for helper in mu300-data-sim-u30 mu300-sim-u30 u30air-led-status; do
[ -s "$R/opt/mu300/bin/$helper" ] || { echo "missing U30 helper: $helper" >&2; exit 1; }
chmod 0755 "$R/opt/mu300/bin/$helper"
@@ -250,7 +251,7 @@ if [ -d /in/luci-plugin ]; then
chmod 0755 $R/etc/init.d/unisoc-modem-ui $R/etc/init.d/unisoc-sms-forward $R/etc/init.d/unisoc-traffic $R/etc/hotplug.d/net/90-unisoc-usb-host $R/etc/hotplug.d/iface/90-unisoc-usb-host $R/usr/libexec/rpcd/mu300dash $R/usr/libexec/unisoc-modem/*
# rpcd refuses world-writable plugins from a Windows bind mount.
chmod 0644 $R/usr/share/rpcd/ucode/*.uc $R/usr/share/ucode/mu300/*.uc
chroot "$R" /usr/bin/ucode -e 'import * as dash from "mu300.dash"; import * as rates from "mu300.rates"; import * as placement from "mu300.service-cpus";'
chroot "$R" /usr/bin/ucode -e "import * as dash from \"mu300.dash\"; import * as rates from \"mu300.rates\"; import * as placement from \"mu300.service-cpus\";"
mkdir -p $R/usr/lib/lua/luci/i18n
cp -a /in/luci-plugin/lmo/. $R/usr/lib/lua/luci/i18n/
# The source-tree install does not run the package postinst. Register only
+2 -3
View File
@@ -15,9 +15,8 @@ boot() {
hw_bringup() {
[ ! -x /opt/mu300/bin/bootmark ] || /opt/mu300/bin/bootmark wifi-hw-enter
# switch_root terminates initramfs background jobs. Resume the same tracked
# chase immediately and keep it until mu300-post (or an earlier WAN success)
# selects the steady state.
# Preinit already starts the chase. This idempotent notification also
# covers direct service starts; mu300-post or WAN success hands it off.
/opt/mu300/bin/led-status boot 2>/dev/null
/opt/mu300/bin/openwrt-board-check >>/tmp/mu300-wifi-start.log 2>&1 || return 1
[ ! -x /opt/mu300/bin/bootmark ] || /opt/mu300/bin/bootmark wifi-board-ready
@@ -0,0 +1,9 @@
#!/bin/sh
# Indicate boot before recorder/USB setup, including battery-only starts.
# The shared controller applies the saved brightness, switch and thermal owner.
mu300_early_leds() {
/opt/mu300/bin/led-status boot 2>/dev/null
/opt/mu300/bin/bootmark early-leds
}
boot_hook_add preinit_essential mu300_early_leds
@@ -12,7 +12,6 @@
# alone decides the pool and lease time.
mu300_early_usb() {
[ -e /sys/class/net/usb0 ] || return 0
/opt/mu300/bin/led-status boot 2>/dev/null
/opt/mu300/bin/busybox ifconfig usb0 192.168.77.1 netmask 255.255.255.0 up
cat > /run/udhcpd-usb0.conf <<'EOF'
start 192.168.77.200
+17 -6
View File
@@ -215,12 +215,28 @@ battery() {
if [ "$KEEP_LIT" = 1 ] && [ "$previous_power" != 1 ] && ! siren_running; then show_all; fi
}
boot_frame() {
[ "$DEVICE" = u30air ] && [ "$(rd "$BOOT_STATE")" = "$1" ] || return 1
siren_running && return 1
case $2 in sc27xx:red|sc27xx:green|sc27xx:blue) ;; *) return 1 ;; esac
BOOT_FRAME=1
for l in $SIREN; do [ "$l" = "$2" ] || write "$l" 0; done
if awake; then write "$2" 1; else write "$2" 0; fi
}
case "$1 ${2:-}" in
"boot on")
[ "$DEVICE" = u30air ] || exit 0
[ ! -f "$BOOT_STATE" ] || exit 0
siren_running && exit 0
# Preinit has not called power-on yet. Start the normal wake lease
# here as well, so a battery-only boot does not render black frames.
if [ "$TIMEOUT" != 0 ]; then
echo $(( $(uptime_s) + TIMEOUT )) > "$STATE/.awake-until"
fi
echo $$ > "$BOOT_STATE"
# Draw while holding this lock; do not wait for worker scheduling.
boot_frame "$$" sc27xx:red
"$0" boot-worker "$$" 9>&- </dev/null >/dev/null 2>&1 & ;;
"boot off")
[ -f "$BOOT_STATE" ] || exit 0
@@ -228,12 +244,7 @@ case "$1 ${2:-}" in
battery
if awake && ! siren_running; then show_all; fi ;;
"boot-frame "*)
[ "$DEVICE" = u30air ] && [ "$(rd "$BOOT_STATE")" = "${2:-}" ] || exit 1
siren_running && exit 1
case ${3:-} in sc27xx:red|sc27xx:green|sc27xx:blue) ;; *) exit 1 ;; esac
BOOT_FRAME=1
for l in $SIREN; do [ "$l" = "$3" ] || write "$l" 0; done
if awake; then write "$3" 1; else write "$3" 0; fi ;;
boot_frame "${2:-}" "${3:-}" || exit 1 ;;
"boot-worker "*)
# Each frame takes the same lock as battery/thermal writes. The token
# prevents an old worker from drawing after stop/restart. Never hold
+19
View File
@@ -64,6 +64,7 @@ class WirelessReadiness(unittest.TestCase):
class BootContracts(unittest.TestCase):
def test_device_entrypoints_have_unix_line_endings(self):
for name in ['boot/init','openwrt/build-rootfs.sh',
'openwrt/overlay/lib/preinit/04_mu300_early_leds',
'openwrt/overlay/etc/init.d/mu300-hw',
'openwrt/overlay/etc/init.d/mu300-service-cpus',
'rootfs/overlay/opt/mu300/bin/mu300-led',
@@ -85,6 +86,24 @@ class BootContracts(unittest.TestCase):
self.assertIn('sprd_pcie_clear_unhandled_msi',driver)
self.assertFalse((TOP/'openwrt/overlay/lib/preinit/31_mu300_failsafe_wait').exists())
class EarlyLeds(ShellTest):
def test_preinit_lights_before_usb_or_recorder_without_a_usb_interface(self):
hooks=TOP/'openwrt/overlay/lib/preinit'
self.assertLess('04_mu300_early_leds','05_mu300_early_recorder')
for name in ('led-status','bootmark'):
self.stub(name,'echo "'+name+' $*" >> "$STUBLOG/calls"')
source=(hooks/'04_mu300_early_leds').read_text().replace('/opt/mu300/bin/',str(self.stubs)+'/')
code='''boot_hook_add() { printf '%s %s' "$1" "$2"; }
'''+source+'\nmu300_early_leds\n'
for shell in self.each_shell():
(self.tmp/'calls').write_text('')
result=self.sh(shell,code)
self.assertEqual(result.returncode,0,result.stderr)
self.assertEqual(result.stdout,'preinit_essential mu300_early_leds')
self.assertEqual((self.tmp/'calls').read_text().splitlines(),
['led-status boot','bootmark early-leds'])
self.assertNotIn('led-status boot',(hooks/'06_mu300_early_usb').read_text())
class DelegateReadiness(ShellTest):
def setUp(self):
super().setUp()
+46
View File
@@ -0,0 +1,46 @@
"""Parse the actual Docker rootfs shell argument without running Docker/apk."""
import json
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
from helpers import TOP, shells
class RootfsShell(unittest.TestCase):
def test_container_script_remains_one_complete_argument(self):
source=(TOP/'openwrt/build-rootfs.sh').read_text()
start=source.rindex('docker run --rm --platform linux/arm64')
end=source.index('\n# Remove optional VPN helpers',start)
command=source[start:end]
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp)
capture=root/'args.json'
# An accidentally unquoted * must not expand into repository files.
(root/'AGENTS.md').write_text('fixture only\n')
env=dict(os.environ,CAPTURE=str(capture))
prefix='''set -eu
TOP=/input; IN=/input; ROOTFS_DIR=/output; REGDB=/regdb
THEME_APK=/theme.apk; BLOCK_APK=/block.apk; WIFI_APKS=/wifi
KREL=test-kernel; OUT=test.tar.gz; FLAVOUR=openwrt; VER=25.12.5
opt() { :; }
mainline_opt() { :; }
plugin_opt() { :; }
docker() {
python3 -c 'import sys,json,os; open(os.environ["CAPTURE"],"w").write(json.dumps(sys.argv[1:]))' "$@"
}
'''
for shell in shells():
with self.subTest(shell=shell):
result=subprocess.run(shell+['-c',prefix+command],cwd=root,env=env,
capture_output=True,text=True,timeout=10)
self.assertEqual(result.returncode,0,result.stderr)
args=json.loads(capture.read_text())
index=args.index('-c',args.index('/bin/sh'))
self.assertEqual(len(args),index+2,'Docker script split into extra arguments')
# BusyBox ash can ignore noexec for -c. Parse stdin and
# fail closed before any build command if noexec is absent.
checked=subprocess.run(shell+['-n'],input='exit 97\n'+args[index+1],
capture_output=True,text=True,timeout=10)
self.assertEqual(checked.returncode,0,checked.stderr)
+31
View File
@@ -72,6 +72,37 @@ esac""")
finally:
token.unlink(missing_ok=True)
def test_battery_only_boot_lights_first_frame_before_worker_runs(self):
# Stop the worker at its entry so only the boot command can draw.
# This reproduces preinit before power-on has established a wake lease.
controller=self.tmp/'boot-led'
source=(BIN/'mu300-led').read_text()
controller.write_text(source.replace('#!/bin/sh\n',
'#!/bin/sh\n[ "${1:-}" != boot-worker ] || exit 0\n',1))
controller.chmod(0o755)
(self.battery/'status').write_text('Discharging\n')
state=self.root/'run/mu300/led'
for shell in self.each_shell():
for enabled in ('1','0'):
state.mkdir(exist_ok=True)
for name in ('.boot-chase','.awake-until'):
(state/name).unlink(missing_ok=True)
(self.root/'proc/uptime').write_text('100.00 999.00\n')
extra=dict(self.extra,TEST_TIMEOUT='60',TEST_BATTERY=enabled,TEST_BRIGHTNESS='40')
result=self.script(shell,controller,'boot','on',**extra)
self.assertEqual(result.returncode,0,result.stderr)
self.assertEqual([self.value('sc27xx:'+c) for c in ('red','green','blue')],
['40' if enabled=='1' else '0','0','0'])
self.assertEqual((state/'.awake-until').read_text().strip(),'160')
# Repeated boot notifications must not reset a user's timeout.
token=(state/'.boot-chase').read_text()
(self.root/'proc/uptime').write_text('130.00 999.00\n')
result=self.script(shell,controller,'boot','on',**extra)
self.assertEqual(result.returncode,0,result.stderr)
self.assertEqual((state/'.boot-chase').read_text(),token)
self.assertEqual((state/'.awake-until').read_text().strip(),'160')
(state/'.boot-chase').unlink()
def test_boot_worker_exits_on_handoff_and_cannot_outlive_its_token(self):
if not shutil.which('busybox'): self.skipTest('bundled BusyBox applets required')
for shell in self.each_shell():