Files
Kill_LIFE/tools/sim/run_qemu_esp32s3.sh
T
root e67fb754c2 feat: KiCad 10 native, QEMU simulation, compliance EU, firmware fixes
Session kxkm-ai 25-26 mars 2026 — 98/98 tâches TODO complétées.

Hardware:
- KiCad 10.0.0 native avec sym/fp-lib-table locales
- Nouveau block SPI (gen_spi_header.py), ERC clean
- Module partagé hardware/lib/kicad_gen.py (5 générateurs refactorisés)
- Pipeline export: tools/hw/hw_export.sh (ERC + SVG + PDF + netlist)
- KiBot 1.8.5 installé, .kibot.yaml configuré

Firmware:
- Fix I2S driver conflict: migration I2sMic vers nouvelle API i2s_channel_*
- Fix WDT risk: yield() dans CompletePushToTalk (voice_controller.cpp)
- Fix XSS wifi_manager.cpp: innerHTML → createElement/textContent
- Fix null check FwIsValidWavHeader
- Dead code supprimé: i2s_audio.cpp.bak, i2s_audio.h

Simulation MCU:
- QEMU ESP32-S3 v9.2.2 installé (tools/sim/)
- Script run_qemu_esp32s3.sh — boot OK vérifié
- [env:esp32s3_qemu] dans platformio.ini
- Wokwi CI: wokwi.toml + diagram.json + scenario.yaml
- SPICE bridge POC: tools/sim/spice_bridge.py (ngspice → ADC/brownout)

Compliance:
- Profil iot_wifi_eu validé (16 standards, 8 evidence)
- 4 evidence remplis: risk_assessment, security_architecture,
  test_plan_radio_emc, supply_chain_declarations
- plan.yaml complété avec données produit réelles

CI:
- Job hardware-export (KiCad 10 ERC + SVG + PDF + netlist)
- Job firmware-sim (Wokwi, conditionnel WOKWI_CLI_TOKEN)
- evidence_pack.yml enrichi avec exports hardware

Docs & RAG:
- specs/02_arch.md complet (481 lignes, 4 ADR, diagrammes)
- docs/SIMULATION.md (3 niveaux: native, QEMU, Wokwi)
- 6 chunks ingérés dans kb-kicad RAG
- Dataset HF: tools/generate_hf_dataset.py + datasets/kb_kicad_qa.jsonl
- Rapport analyse: docs/plans/ANALYSIS_REPORT_2026-03-25.md
- Recherche OSS: docs/research/oss_similar_projects.md

Infra:
- ZeroClaw 0.1.7 installé (cargo install)
- APIFY_API_KEY configurée, smoke OK
- Tests: 39/39 firmware + 26/26 Python stable

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 09:52:00 +01:00

123 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Kill_LIFE — QEMU ESP32-S3 Firmware Simulation
# Usage: bash tools/sim/run_qemu_esp32s3.sh [--timeout N] [--build]
#
# Prerequisites:
# - QEMU Xtensa (Espressif fork) in tools/sim/qemu-system-xtensa
# - ROM file in tools/sim/esp32s3_rev0_rom.bin (or -L path)
# - Built firmware in firmware/.pio/build/esp32s3_waveshare/
#
# Options:
# --timeout N Seconds to run before killing QEMU (default: 10)
# --build Build firmware before running simulation
# --gdb Start QEMU with GDB server on port 1234
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
QEMU="$SCRIPT_DIR/qemu-system-xtensa"
ROM_DIR="$SCRIPT_DIR"
FW_DIR="$REPO_ROOT/firmware"
BUILD_DIR="$FW_DIR/.pio/build/esp32s3_waveshare"
FLASH_IMG="/tmp/kill_life_qemu_flash.bin"
TIMEOUT=10
DO_BUILD=0
GDB_OPTS=""
LOG_FILE="$REPO_ROOT/artifacts/sim/qemu_$(date +%Y%m%d_%H%M%S).log"
# Parse args
while [[ $# -gt 0 ]]; do
case "$1" in
--timeout) TIMEOUT="$2"; shift 2 ;;
--build) DO_BUILD=1; shift ;;
--gdb) GDB_OPTS="-s -S"; shift ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
# Checks
if [[ ! -x "$QEMU" ]]; then
echo "[sim] ERROR: QEMU not found at $QEMU"
echo " Install: download from github.com/espressif/qemu/releases"
exit 1
fi
if [[ ! -f "$ROM_DIR/esp32s3_rev0_rom.bin" ]]; then
echo "[sim] ERROR: ROM file not found at $ROM_DIR/esp32s3_rev0_rom.bin"
exit 1
fi
# Build if requested
if [[ "$DO_BUILD" -eq 1 ]]; then
echo "[sim] Building firmware..."
cd "$FW_DIR"
"$REPO_ROOT/.pio-venv/bin/pio" run -e esp32s3_waveshare
fi
# Check firmware exists
if [[ ! -f "$BUILD_DIR/firmware.bin" ]]; then
echo "[sim] ERROR: Firmware not found. Run with --build or: pio run -e esp32s3_waveshare"
exit 1
fi
# Create merged flash image (16MB)
echo "[sim] Creating flash image..."
ESPTOOL="$REPO_ROOT/.pio-venv/bin/esptool"
if [[ ! -x "$ESPTOOL" ]]; then
ESPTOOL="$(which esptool 2>/dev/null || echo "")"
fi
if [[ -z "$ESPTOOL" ]]; then
echo "[sim] ERROR: esptool not found. Install: pip install esptool"
exit 1
fi
"$ESPTOOL" --chip esp32s3 merge-bin \
-o "$FLASH_IMG.tmp" \
--flash-mode dio \
--flash-size 16MB \
0x0 "$BUILD_DIR/bootloader.bin" \
0x8000 "$BUILD_DIR/partitions.bin" \
0x10000 "$BUILD_DIR/firmware.bin" \
2>/dev/null
# Pad to exactly 16MB
truncate -s 16M "$FLASH_IMG"
dd if="$FLASH_IMG.tmp" of="$FLASH_IMG" conv=notrunc 2>/dev/null
rm -f "$FLASH_IMG.tmp"
# Create log directory
mkdir -p "$(dirname "$LOG_FILE")"
# Run QEMU
echo "[sim] Booting Kill_LIFE firmware in QEMU ESP32-S3..."
echo "[sim] Timeout: ${TIMEOUT}s | Log: $LOG_FILE"
echo "[sim] Flash: $(du -h "$FLASH_IMG" | cut -f1) | GDB: ${GDB_OPTS:-disabled}"
echo "---"
timeout "$TIMEOUT" "$QEMU" \
-nographic \
-machine esp32s3 \
-drive "file=$FLASH_IMG,if=mtd,format=raw" \
-serial mon:stdio \
-no-reboot \
-L "$ROM_DIR" \
$GDB_OPTS \
2>&1 | tee "$LOG_FILE"
EXIT_CODE=${PIPESTATUS[0]}
echo ""
echo "---"
echo "[sim] QEMU exited (code=$EXIT_CODE). Log saved: $LOG_FILE"
# Quick analysis
if grep -q "abort() was called" "$LOG_FILE" 2>/dev/null; then
echo "[sim] RESULT: ABORT detected in firmware"
ABORT_LINE=$(grep "abort() was called" "$LOG_FILE" | head -1)
echo "[sim] $ABORT_LINE"
elif grep -q "Rebooting" "$LOG_FILE" 2>/dev/null; then
echo "[sim] RESULT: Firmware rebooted (crash or watchdog)"
else
echo "[sim] RESULT: Firmware ran for ${TIMEOUT}s without crash"
fi