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:


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_1 Recovery receiver validates X-Pylot-Token and checks the first streamed bytes for the ESP-IDF image header (0xE9 at byte 0 + 0xABCD5432 app-desc magic at byte 32) before erasing a single sector of ota_0.


3. Health-Gated Boot Confirmation & boot_fails >= 3 Safe Mode

  1. On every boot before confirm_boot() runs, PylotOS increments boot_fails in NVS.
  2. Only after all 7 Power-On Self-Test (POST) stages succeed does the kernel call sys_ota.confirm_boot() and reset boot_fails = 0.
  3. When boot_fails >= 3 (e.g., a buggy /apps autostart script triggers repeated panics or WDT resets), PylotOS boots into Safe Mode: user /apps and /apps/services/ are skipped while USB TTY (pylot>), :8080 Web Admin, and :8266 LAN 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:

  1. microSD Recovery (/sd/update.bin): Copy pylotos-<board>-ota.bin to /sd/update.bin (with optional /sd/update.sha256) and trigger pylot> sd recover.
  2. NimBLE BLE DFU (pylotos.ble_dfu.BleDfuSession): Framed GATT protocol (OP_BEGIN=0x01, OP_DATA=0x02, OP_COMMIT=0x03, OP_ABORT=0x04) over service UUID 50594c4f-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