boot: boot_serial: add COBS framing for raw serial recovery#5
Draft
JPHutchins wants to merge 1 commit into
Draft
boot: boot_serial: add COBS framing for raw serial recovery#5JPHutchins wants to merge 1 commit into
JPHutchins wants to merge 1 commit into
Conversation
Add BOOT_SERIAL_RAW_PROTOCOL_COBS, a framing layer on top of the raw
(non-console) SMP recovery protocol that wraps each SMP packet as:
COBS(header || payload || CRC16) || 0x00
The CRC16 is CRC-16/XMODEM (polynomial 0x1021, initial value 0x0000, no
reflection), computed over the header and payload and appended big-endian,
identical to the CRC used by the SMP over console encoding. The packet and
its CRC are then COBS-encoded, which removes every 0x00 from the stream, so
a single trailing 0x00 is an unambiguous frame delimiter.
Unlike the bare raw protocol, this encoding is self-synchronising: the
delimiter gives a resync point after any corruption or truncation, and the
CRC16 rejects damaged packets. It therefore takes over the role of the input
timeout, and the two are mutually exclusive. The existing
BOOT_SERIAL_RAW_PROTOCOL_INPUT_TIMEOUT option becomes one member of a new
choice, alongside the COBS option and BOOT_SERIAL_RAW_PROTOCOL_NONE (the
original unframed behaviour). Migration: a configuration that previously set
CONFIG_BOOT_SERIAL_RAW_PROTOCOL_INPUT_TIMEOUT=n to obtain the unframed raw
behaviour must now set CONFIG_BOOT_SERIAL_RAW_PROTOCOL_NONE=y; configurations
that leave the timeout at its default, or set it =y, are unaffected.
The COBS codec is a small dependency-free module (boot_serial/src/cobs.c)
rather than Zephyr's CONFIG_COBS, which is net_buf-based and would pull the
net_buf subsystem into serial recovery. It decodes in place, so the receive
buffer grows only by the COBS overhead (at most one byte per 254 input bytes,
under 1%) plus the delimiter.
The SMP client must be configured to use a matching COBS+CRC16 transport. No
stock mcumgr client speaks this encoding yet, so this option is provided for
evaluation and community review; the PR is intentionally a draft to gauge
interest.
A serial_recovery_raw_cobs.conf fragment and a matching Twister build test
(sample.bootloader.mcuboot.serial_recovery_raw_cobs) are added, along with a
native_sim ztest for the COBS codec (boot/zephyr/tests/cobs).
Signed-off-by: JP Hutchins <jp@intercreate.io>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
JPHutchins
added a commit
to intercreate/smp-server-fixtures
that referenced
this pull request
Jun 25, 2026
feat: COBS-framed raw serial recovery fixture (intercreate/mcuboot#5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add BOOT_SERIAL_RAW_PROTOCOL_COBS, a framing layer on top of the raw
(non-console) SMP recovery protocol that wraps each SMP packet as:
The CRC16 is CRC-16/XMODEM (polynomial 0x1021, initial value 0x0000, no
reflection), computed over the header and payload and appended big-endian,
identical to the CRC used by the SMP over console encoding. The packet and
its CRC are then COBS-encoded, which removes every 0x00 from the stream, so
a single trailing 0x00 is an unambiguous frame delimiter.
Unlike the bare raw protocol, this encoding is self-synchronising: the
delimiter gives a resync point after any corruption or truncation, and the
CRC16 rejects damaged packets. It therefore takes over the role of the input
timeout, and the two are mutually exclusive. The existing
BOOT_SERIAL_RAW_PROTOCOL_INPUT_TIMEOUT option becomes one member of a new
choice, alongside the COBS option and BOOT_SERIAL_RAW_PROTOCOL_NONE (the
original unframed behaviour). Migration: a configuration that previously set
CONFIG_BOOT_SERIAL_RAW_PROTOCOL_INPUT_TIMEOUT=n to obtain the unframed raw
behaviour must now set CONFIG_BOOT_SERIAL_RAW_PROTOCOL_NONE=y; configurations
that leave the timeout at its default, or set it =y, are unaffected.
The COBS codec is a small dependency-free module (boot_serial/src/cobs.c)
rather than Zephyr's CONFIG_COBS, which is net_buf-based and would pull the
net_buf subsystem into serial recovery. It decodes in place, so the receive
buffer grows only by the COBS overhead (at most one byte per 254 input bytes,
under 1%) plus the delimiter.
The SMP client must be configured to use a matching COBS+CRC16 transport. No
stock mcumgr client speaks this encoding yet, so this option is provided for
evaluation and community review; the PR is intentionally a draft to gauge
interest.
A serial_recovery_raw_cobs.conf fragment and a matching Twister build test
(sample.bootloader.mcuboot.serial_recovery_raw_cobs) are added, along with a
native_sim ztest for the COBS codec (boot/zephyr/tests/cobs).
Signed-off-by: JP Hutchins jp@intercreate.io
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com