#!/bin/sh # B11 single all-SAFE-LED run (RAM state only; no eMMC/cache writes, no PMIC/TLMM raw writes). # SAFE set from B11-LED-AUDIT.md: L1 = PM8916 MPP4 LCD backlight via /sys/class/backlight/backlight (0/1). No PWM line confirmed. # usage: sh b11-led-run.sh TAG -> log /tmp/b11-run-TAG.log, markers "B11 TAG ..." T=${1:-r1}; LOG=/tmp/b11-run-$T.log; FAIL=/tmp/b11-fail-$T; rm -f $FAIL D=/sys/kernel/debug LEDS="L1:/sys/class/backlight/backlight/brightness:1:0" # name:path:on:off STEP=0.7; ALLON=4 exec >$LOG 2>&1 up() { cut -d' ' -f1 /proc/uptime; } say() { echo "B11 $T $(up) $*"; } mpp4() { dd if=$D/regmap/0-00/registers bs=9 skip=$((0xa340)) count=13 2>/dev/null | grep -E "^a3(40|41|46|4c)" | tr '\n' ' '; } snap() { say "SNAP $1 mpp4[ $(mpp4)] bl=$(cat /sys/class/backlight/backlight/brightness) bl_power=$(cat /sys/class/backlight/backlight/bl_power)"; } DM0=$(dmesg | wc -l) check() { # one pass; prints status, returns 1 on critical loss rc=0; s="" ping -c2 -W2 -I wwan0 77.88.8.8 >/dev/null 2>&1 && s="$s lte=ok" || { s="$s lte=FAIL"; rc=1; } [ "$(cat /sys/class/remoteproc/remoteproc0/state)" = running ] && s="$s mpss=ok" || { s="$s mpss=FAIL"; rc=1; } [ "$(cat /sys/class/remoteproc/remoteproc1/state)" = running ] && s="$s wcnss=ok" || { s="$s wcnss=FAIL"; rc=1; } [ "$(cat /sys/class/net/wlan0/operstate 2>/dev/null)" = up ] && pidof hostapd >/dev/null && s="$s wifi=ok" || { s="$s wifi=FAIL"; rc=1; } [ "$(cat /sys/class/net/usb0/operstate 2>/dev/null)" = up ] && s="$s ncm=ok" || { s="$s ncm=FAIL"; rc=1; } readlink /sys/bus/spi/devices/spi0.0/driver | grep -q panel-mipi-dbi && [ -e /dev/fb0 ] && s="$s disp=ok" || { s="$s disp=FAIL"; rc=1; } c=$(cat /sys/class/power_supply/pm8916-lbc-chgr/status 2>/dev/null); s="$s chg=$c" t=$(cat /sys/class/thermal/thermal_zone5/temp); s="$s pmic=$t"; [ "$t" -lt 70000 ] || { s="$s TEMP-HIGH"; rc=1; } e=$(dmesg | tail -n +$((DM0+1)) | grep -v " HB " | grep -ciE "oops|bug:|panic|crash|fatal|watchdog|fault|error|reset|fail") s="$s kerr=$e"; [ "$e" -eq 0 ] || rc=1 echo "$s"; return $rc } restore() { for l in $LEDS; do IFS=: read n p on off < "$p"; done; snap RESTORED; } mon() { while [ ! -e /tmp/b11-stop-$T ]; do r=$(check); st=$?; say "MON$r"; [ $st -eq 0 ] || { touch $FAIL; say "MON CRITICAL"; }; sleep 1; done; } guard() { [ -e $FAIL ] && { say "ABORT at $1"; restore; dmesg | tail -n +$((DM0+1)) | grep -v " HB " | tail -20; touch /tmp/b11-stop-$T; say "END ABORT"; exit 2; }; } set_all() { for l in $LEDS; do IFS=: read n p on off < $p || echo $off > $p; done; } trap 'touch $FAIL; guard SIGNAL' INT TERM HUP # --- pre-state for l in $LEDS; do IFS=: read n p on off < no LED touched"; say "END PRECHECK-FAIL"; exit 3; }; say "PRECHECK$r" rm -f /tmp/b11-stop-$T; mon & MP=$! # 1. all off say "STAGE1 ALL-OFF"; set_all off; snap S1; sleep 2; guard S1 # 2. all on 4 s say "STAGE2 ALL-ON ${ALLON}s"; set_all on; snap S2; sleep $ALLON; guard S2 # 3. all off say "STAGE3 ALL-OFF"; set_all off; snap S3; sleep 2; guard S3 # 4. chase, 2 cycles for c in 1 2; do for l in $LEDS; do IFS=: read n p on off < $p; sleep $STEP; guard "S4c$c$n"; echo $off > $p; say "STAGE4 CHASE c$c $n OFF"; sleep $STEP; guard "S4c$c${n}off"; done; done # 5. brightness: skipped - no PWM-confirmed line say "STAGE5 SKIPPED no PWM-confirmed line" # 6. restore say "STAGE6 RESTORE"; restore; sleep 2; guard S6 touch /tmp/b11-stop-$T; wait $MP 2>/dev/null r=$(check); say "POSTCHECK$r" say "END OK"