Files
ESP32S3_vt/scripts/flash.sh
T
sloray cc6b82d7ec
构建客户端 / 检查(类型 + 单元测试) (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: 链路控制、延迟校准与长测工具,补全文档
- 固件:新增 link_control / stream_control,覆盖运行中 Wi-Fi 断线恢复、取帧节拍、
  温控与质量/帧率减载;UDP 发送增加有界重试预算与帧期限,PSRAM JPEG 直发减少拷贝。
- 协议:重组器严格校验分片布局,统计未收齐、超时与完全缺失的帧,处理帧号回绕与设备重启。
- 桌面端:视频改 latest-value 通道并前置帧时间标记,拒绝积压和慢解码的过期画面;新增
  延迟标记页与 --latency-report 校准,完善录制、服务端与退出流程。
- 文档与脚本:新增硬件、开发、延迟、功耗、实时性、稳定性文档和改动记录,重写根 README;
  新增构建、性能、延迟与串口长测脚本,以及长测客户端脚本。
- 构建:固定 esp-1.97.0.0 工具链,分区表随构建复制,更新 sdkconfig 与忽略规则。
2026-10-19 00:19:07 +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: 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