#!/bin/bash # R2/T2 watcher (480s; board side read-only). Usage: t2-watch.sh # For each SBL1 start: class A/B/C from pm_device_init, furthest stage, PASS/FAIL; Linux -> PON dump over UART (md5-checked); # hang -> wait for auto-reset (max 120 s from start), next start is recorded as a follow-up of the same attempt. L=$1; TAG=$2; TTY=/dev/ttyUSB0 OUT=~/doc/modem/jz08-aurora/logs/r2/t2d; mkdir -p $OUT; RES=$OUT/results.tsv [ -f $RES ] || printf 'attempt\tstart#\tstart\tclass\tsblS\tpm_device\tcdt\tpm_driver\tsbl_end\tsbl_delta\tbatt\tsbl1End\tlk\tlinux\tstage\tresult\tautoreset\trtc\t807\t808\t80a\t80c\t80d\tnote\n' > $RES lg() { tr -d '\000' < $L; } dumpcmd() { printf '%s\r' "grep -q ' /sys/kernel/debug ' /proc/mounts || mount -t debugfs debugfs /sys/kernel/debug; R=/sys/kernel/debug/regmap/0-00/registers; { dd if=\$R bs=9 skip=2048 count=256 2>/dev/null; dd if=\$R bs=9 skip=2304 count=256 2>/dev/null | grep -v ': 00\$'; } > /tmp/t2.txt; echo T2-BEGIN-$1; sed 's/^/T2R /' /tmp/t2.txt; echo T2-SUM-$1 \$(md5sum < /tmp/t2.txt) up=\$(cut -d' ' -f1 /proc/uptime); echo T2-END-$1" > $TTY } capture() { # id startline for try in 1 2 3; do dumpcmd $1-$try for i in $(seq 1 25); do sleep 1; lg | tail -n +$2 | grep -a -q "T2-END-$1-$try" && break; done seg=$(lg | tail -n +$2 | sed -n "/T2-BEGIN-$1-$try/,/T2-END-$1-$try/p") body=$(echo "$seg" | grep -a -o "T2R [0-9a-f]\{4\}: [0-9a-f]\{2\}" | cut -c5-) want=$(echo "$seg" | grep -a -o "T2-SUM-$1-$try [0-9a-f]\{32\}" | awk '{print $2}' | tail -1) got=$(printf '%s\n' "$body" | md5sum | awk '{print $1}') [ -n "$want" ] && [ "$want" = "$got" ] && { printf '%s\n' "$body" > $OUT/$1-regs.txt; return 0; } echo "try $try md5 mismatch want=$want got=$got" >> $OUT/$1-meta.txt done; return 1 } n=$(lg | wc -l); capture $3 $n && echo CAPTURED || echo CAPTURE-FAILED