Tutorial: Asymmetric Recovery-OTA (asym-v1), SD Recovery & BLE DFU
PylotOS uses a unified Two-Stage Hybrid Asymmetric Recovery-OTA (asym-v1) architecture across all 30 supported boards (4 MiB, 8 MiB, and 16 MiB Flash profiles).
1. Why Asymmetric OTA Beats Symmetric Dual-OTA
Traditional ESP-IDF Dual-OTA splits flash into two equal ota_0 and ota_1 partitions. On a 4 MiB RISC-V board (m5stack_nanoc6, seeed_xiao_esp32c3), symmetric slots cap the OS at ~1.5 MiB — making it impossible to fit MicroPython + Wi-Fi 6 + NimBLE BLE 5.3 + C HAL drivers + a 1 MiB LittleFS /vfs.
asym-v1 solves this permanently:
ota_0(0x20000): Maximized main OS partition (2,176 KiBon 4 MiB,3,200 KiBon 8 MiB,4,096 KiBon 16 MiB).ota_1: Permanent768 KiBslot holding a board-agnostic pure-C Recovery firmware (<= 736 KiBacrossesp32,esp32s3,esp32c3,esp32c6).- Pre-
ota_0Gap (0x12000..0x1FFFF): Housesnvs_keys(4 KiB@0x12000) andcoredump(52 KiB@0x13000) while keepingnvsat0x9000(24 KiB) for 100% Web Flasher &provision.pycompatibility.
2. Inspecting & Controlling OTA from Python (import sys_ota)
import sys_ota
st = sys_ota.status()
# {
# 'ota_schema': 'asym-v1',
# 'running_partition': 'ota_0',
# 'boot_confirmed': True,
# 'boot_fails': 0,
# 'recovery_present': True,
# }
# Explicitly confirm boot health (normally called automatically after 7-stage POST):
sys_ota.confirm_boot()
Staging an HTTPS Pull Update (GitHub Releases / Private Server)
sys_ota.stage_pull(
url="https://github.com/PylotOS/pylotos/releases/latest/download/pylotos-m5stack_cardputer_adv-ota.bin",
sha256="2605f24c4142a7df...", # Required 64-hex SHA-256 digest
sig="3045022100...", # Optional ECDSA-P256 hex signature
reboot=True,
)
Staging a Token-Protected LAN Fleet Push (:8266/api/ota/push)
sys_ota.stage_push(
sha256="2605f24c4142a7df...",
token="ephemeral-32-char-push-secret",
image_size=2163152,
port=8266,
reboot=True,
)
Anti-Brick Erase Guard: The pure-C
ota_1Recovery receiver validatesX-Pylot-Tokenand checks the first streamed bytes for the ESP-IDF image header (0xE9at byte0+0xABCD5432app-desc magic at byte32) before erasing a single sector ofota_0.
3. Health-Gated Boot Confirmation & boot_fails >= 3 Safe Mode
- On every boot before
confirm_boot()runs, PylotOS incrementsboot_failsin NVS. - Only after all 7 Power-On Self-Test (POST) stages succeed does the kernel call
sys_ota.confirm_boot()and resetboot_fails = 0. - When
boot_fails >= 3(e.g., a buggy/appsautostart script triggers repeated panics or WDT resets), PylotOS boots into Safe Mode: user/appsand/apps/services/are skipped while USB TTY (pylot>),:8080Web Admin, and:8266LAN recovery remain online so you can fix or roll back the offending script.
4. Offline microSD Recovery & Secondary NimBLE BLE DFU (pylotos.ble_dfu)
When Wi-Fi is unavailable in the field:
- microSD Recovery (
/sd/update.bin): Copypylotos-<board>-ota.binto/sd/update.bin(with optional/sd/update.sha256) and triggerpylot> sd recover. - NimBLE BLE DFU (
pylotos.ble_dfu.BleDfuSession): Framed GATT protocol (OP_BEGIN=0x01,OP_DATA=0x02,OP_COMMIT=0x03,OP_ABORT=0x04) over service UUID50594c4f-5400-4446-5500-000000000001:
import hashlib
import struct
from pylotos.ble_dfu import BleDfuSession, OP_BEGIN, OP_COMMIT, OP_DATA, STATUS_OK
session = BleDfuSession(target="recovery")
digest_bytes = hashlib.sha256(fw_bytes).digest()
# 1. Send BEGIN packet: [0x01][size:u32 LE][sha256:32B]
st_code, msg = session.handle_packet(bytes([OP_BEGIN]) + struct.pack("<I", len(fw_bytes)) + digest_bytes)
assert st_code == STATUS_OK
# 2. Stream MTU-sized DATA chunks (validates 0xE9 + 0xABCD5432 magic on first 36 bytes):
for off in range(0, len(fw_bytes), 240):
st_code, _ = session.handle_packet(bytes([OP_DATA]) + fw_bytes[off : off + 240])
assert st_code == STATUS_OK
# 3. Verify full SHA-256 (+ optional ECDSA-P256) and commit:
st_code, hex_sha = session.handle_packet(bytes([OP_COMMIT]))
assert st_code == STATUS_OK
Try the interactive OTA & CoreDump diagnostic dashboard in the simulator:
pylotos-sim examples/ota_and_coredump_diagnostics.py --board m5stack_cardputer_adv --port 8080