Skip to content

Validate GBL magic and size before erasing the app slot#3

Open
balloob wants to merge 1 commit into
OpenDisplay:mainfrom
balloob:fix/validate-gbl-before-erase
Open

Validate GBL magic and size before erasing the app slot#3
balloob wants to merge 1 commit into
OpenDisplay:mainfrom
balloob:fix/validate-gbl-before-erase

Conversation

@balloob

@balloob balloob commented Jul 5, 2026

Copy link
Copy Markdown

Problem

perform_silabs_ota writes control byte 0x00 (which makes the AppLoader erase the application slot) and then streams the firmware with no validation — not even the 4-byte GBL magic.

AppLoader OTA is single-bank / in-place, so once 0x00 is written the old app is gone. Feeding a truncated download, an HTML error page, a .hex, or an nRF .zip leaves the device app-less until a successful retry — an avoidable brick.

Fix

Validate the firmware bytes before connecting/erasing:

  • Require the GBL header magic EB 17 A6 03 (little-endian header tag 0x03A617EB, GBL_TAG_ID_HEADER_V3).
  • Require a sane minimum size (MIN_GBL_SIZE = 64; no real GBL is smaller than its header + end tag).

On failure it raises the existing typed SilabsOTAError with an actionable message and never proceeds to the boot delay, connect, or erase — the device's app slot is left intact.

Tests

  • test_rejects_wrong_magic_before_erase — a wrong-magic blob raises and establish_connection is never awaited.
  • test_rejects_too_short_before_erase — an empty and a magic-only (too short) blob raise before connecting.
  • test_valid_magic_passes_validation — a correctly-magic'd, sane-size blob passes validation and reaches the 0x00 start.

Existing transfer tests updated to use valid GBL blobs via a small _gbl(size) helper. Full suite passes (uv run pytest -q → 14 passed); ruff check and mypy clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_012g2e8mr132vcizx92WsgiR

AppLoader OTA is single-bank and in-place: writing control byte 0x00
erases the application slot, then the firmware is streamed with no
validation. A truncated download, an HTML error page, a .hex, or an
nRF .zip would leave the device app-less until a successful retry.

Validate the image before connecting/erasing: require the GBL header
magic (EB 17 A6 03 = tag 0x03A617EB) and a sane minimum size. On
failure raise SilabsOTAError with an actionable message and never
proceed to erase.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012g2e8mr132vcizx92WsgiR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant