Files
simba-rmic-2026/vt/scripts/flash.sh
T
sloray f7ca246b68
构建客户端 / 检查(类型 + 单元测试) (push) Canceled after 0s
构建客户端 / Linux x64(deb + AppImage) (push) Canceled after 0s
构建客户端 / Windows x64(NSIS 安装包) (push) Canceled after 0s
构建客户端 / macOS 通用(.app + .dmg) (push) Canceled after 0s
feat(match): 同步比赛计时与装甲板扣血许可
- feat(client): 增加裁判比赛计时、技术暂停与选手端局域网同步
- feat(armor): 红蓝共用通用固件,按客户端选队并显示网络连接状态
- feat(armor): 仅在对局进行中允许扣血,其他阶段保留受击闪烁
- feat(client): 将计时置于血条中间并增加开赛前五秒全屏动画
- fix(client): 修复连续血条、对手镜像和图传断连灰度遮罩
- fix(client): 统一界面中文字体并整理各页面文案
- fix(maintenance): 备份迁移装甲板分区,恢复 SDK 构建与固件打包
- refactor(repo): 按 armor、vt 和 client 整理工程与脚本,移除旧参考实现
- test: 补充线路、受击许可、回环 UDP、维护和 HUD 验证
- docs: 同步构建、协议、比赛控制和硬件验证边界

验证:前端构建与 19 项相关测试通过;核心 91 项单元测试与 2 项回环 UDP 集成测试通过;装甲板规则 25 项、线路 26 项、Tauri 51 项测试通过;独立探测器 5 项与目录回归 4 项通过。完成 C3 两组阈值实际编译、导出与 ZIP 校验,检查 900×600 / 1280×720 页面、倒计时和随包中文字体。
未执行烧录、板上运行、跨电脑广播或硬件稳定性验证。
2026-10-22 17:08:49 +08:00

132 lines
4.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds, picks a flash offset that avoids the module's defective byte, flashes,
# and prints the serial log.
#
# The module this was developed against has one byte in its SPI flash at
# 0xFADE7 whose bits 5..7 cannot be programmed (see README). Whatever value the
# app image places there gets corrupted, the image checksum fails, and the
# bootloader refuses to boot it. The image itself is unaffected by where it is
# placed in flash, so moving the app partition is enough: this picks the lowest
# 64 KB-aligned offset whose byte at that address the flash can actually store.
#
# Usage from the repository root: vt/scripts/flash.sh [--monitor SECONDS]
set -euo pipefail
cd "$(dirname "$0")/.."
readonly BAD_FLASH_ADDR="${BAD_FLASH_ADDR:-0xFADE7}"
readonly ALIGN="${ALIGN:-0x10000}"
# The same module also showed a high-bit write mismatch at 0x10863. Keep the application
# above its sector; this does not remove the separate 0xFADE7 constraint.
readonly MIN_APP_OFFSET="${MIN_APP_OFFSET:-0x20000}"
readonly MAX_APP_SIZE="${MAX_APP_SIZE:-0x120000}"
MONITOR_SECS=25
if [ "${1:-}" = "--monitor" ]; then
MONITOR_SECS="${2:-25}"
fi
port="${ESP_PORT:-}"
if [ -z "$port" ]; then
port=$(ls /dev/cu.usbmodem* /dev/cu.wchusbserial* /dev/cu.SLAB* /dev/cu.usbserial* 2>/dev/null | head -1 || true)
fi
if [ -z "$port" ]; then
echo "no serial port found; set ESP_PORT=/dev/cu.xxx" >&2
exit 1
fi
out=$(ls -d target/xtensa-esp32s3-espidf/release/build/esp-idf-sys-*/out/build 2>/dev/null | head -1 || true)
echo "==> build"
./scripts/build.sh
echo "==> pick app offset"
espflash save-image --chip esp32s3 --format esp-idf \
target/xtensa-esp32s3-espidf/release/esp32 /tmp/esp32-cam-app.bin >/dev/null
read -r offset < <(python3 - <<PY
import sys
data = open("/tmp/esp32-cam-app.bin", "rb").read()
bad = $BAD_FLASH_ADDR
align = $ALIGN
flash_size = 16 * 1024 * 1024
for off in range(max(align, $MIN_APP_OFFSET), flash_size - len(data), align):
at = bad - off
if at < 0 or at >= len(data):
continue
if data[at] & 0xE0 == 0: # top three bits must be storable
print(off)
break
else:
sys.exit("no usable app offset found; this module's flash is too broken")
PY
)
printf '0x%x\n' "$offset"
# Write the chosen offset into partitions.csv.
python3 - "$offset" <<'PY'
import re, sys
offset = int(sys.argv[1], 0)
p = "partitions.csv"
s = open(p).read()
s2 = re.sub(r"^(factory,\s+app,\s+factory,\s+)0x[0-9a-fA-F]+",
lambda m: m.group(1) + "0x%06x" % offset, s, flags=re.M)
if s2 != s:
open(p, "w").write(s2)
print("partitions.csv updated")
else:
print("partitions.csv already at 0x%06x" % offset)
PY
echo "==> reconfigure + rebuild with the new table"
rm -rf target/xtensa-esp32s3-espidf/release/build/esp-idf-sys-*
./scripts/build.sh
espflash save-image --chip esp32s3 --format esp-idf \
target/xtensa-esp32s3-espidf/release/esp32 /tmp/esp32-cam-app.bin >/dev/null
out=$(ls -d target/xtensa-esp32s3-espidf/release/build/esp-idf-sys-*/out/build | head -1)
# The rebuild can shift the image, so confirm before committing to the flash.
python3 - <<PY || { echo "image moved onto the bad byte again; rerun" >&2; exit 1; }
import sys
data = open("/tmp/esp32-cam-app.bin", "rb").read()
at = $BAD_FLASH_ADDR - $offset
if not (0 <= at < len(data)) or data[at] & 0xE0:
print("byte at 0x%X is 0x%02X, not storable" % ($BAD_FLASH_ADDR, data[at] if 0 <= at < len(data) else -1))
sys.exit(1)
print("byte at 0x%X is 0x%02X, storable" % ($BAD_FLASH_ADDR, data[at]))
PY
echo "==> flash $port"
esptool_py=$(ls "$HOME"/.espressif/tools/python/*/venv/bin/python 2>/dev/null | head -1)
"$esptool_py" -m esptool --chip esp32s3 --port "$port" --baud 460800 write-flash \
0x0 "$out/bootloader/bootloader.bin" \
0x8000 "$out/partition_table/partition-table.bin" \
"$offset" /tmp/esp32-cam-app.bin 2>&1 | grep -viE 'writing at|^\[1A' | tail -4
if [ "$MONITOR_SECS" -gt 0 ]; then
echo "==> serial log (${MONITOR_SECS}s)"
python3 - "$port" "$MONITOR_SECS" <<'PY'
import os, sys, termios, time
fd = os.open(sys.argv[1], os.O_RDONLY | os.O_NOCTTY)
a = termios.tcgetattr(fd)
a[0] = a[1] = a[3] = 0
a[2] = termios.CS8 | termios.CREAD | termios.CLOCAL
a[4] = a[5] = termios.B115200
a[6][termios.VMIN] = 0
a[6][termios.VTIME] = 1
termios.tcsetattr(fd, termios.TCSANOW, a)
end = time.time() + float(sys.argv[2])
while time.time() < end:
try:
d = os.read(fd, 4096)
except OSError:
break
if d:
sys.stdout.write(d.decode("utf-8", "replace"))
sys.stdout.flush()
PY
fi