Skip to content

mgmt/mcumgr/transport: uart: assert UART MTU fits the netbuf#2

Draft
JPHutchins wants to merge 2 commits into
mainfrom
mcumgr/uart-mtu-netbuf-build-assert
Draft

mgmt/mcumgr/transport: uart: assert UART MTU fits the netbuf#2
JPHutchins wants to merge 2 commits into
mainfrom
mcumgr/uart-mtu-netbuf-build-assert

Conversation

@JPHutchins
Copy link
Copy Markdown
Collaborator

Summary

The mcumgr UART SMP transport documents MCUMGR_TRANSPORT_UART_MTU <= MCUMGR_TRANSPORT_NETBUF_SIZE + 2 in Kconfig.uart as a "must satisfy" relation, but only BUILD_ASSERT(UART_MTU != 0) is actually enforced. Since the transport reassembles the base64-decoded SMP frame into one NETBUF_SIZE buffer, a UART_MTU larger than the netbuf can never be used — yet a misconfiguration is silent until runtime. This adds the missing BUILD_ASSERT, mirroring the existing one.

  • Default configs satisfy it with margin (256 ≤ 386), so no in-tree config breaks.
  • smp_uart.c depends on UART_MCUMGR && !UART_MCUMGR_RAW_PROTOCOL, so all referenced symbols are always defined here.

Context

Found while investigating what an SMP serial client may send (mcu-tools/mcuboot#2746, intercreate/smpclient#81). The advertised/buf_size value is the decoded netbuf; the on-wire frame is ~1.37× larger (base64 + line framing), decoded fragment-by-fragment into the netbuf — so the netbuf is the real per-transaction ceiling. Confirmed empirically against native_sim/QEMU/mps2 servers (a NETBUF_SIZE − 4 message round-trips while the encoded frame exceeds NETBUF_SIZE).

Open questions (intentionally out of this PR — see the plan doc commit)

  • The second documented relation, RX_BUF_COUNT * RX_BUF_SIZE >= UART_MTU, looks like a throughput heuristic rather than a hard requirement (fragments are decoded + recycled incrementally), so asserting it could reject configs that work today. Left for discussion.
  • UART_MTU's get_mtu is never called on the UART path; the help text ("sent and received") may warrant clarification.

Note: the [not for upstream] plan commit is a design/analysis doc for review and should be dropped before any upstream submission.

JPHutchins and others added 2 commits June 4, 2026 12:38
The mcumgr UART transport reassembles the base64-decoded SMP frame into a
single CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE buffer, so CONFIG_MCUMGR_TRANSPORT_UART_MTU
cannot exceed it. Kconfig.uart documents this relation
(MCUMGR_TRANSPORT_UART_MTU <= MCUMGR_TRANSPORT_NETBUF_SIZE + 2) but it was only
prose; a violation was silently broken at runtime. Enforce it with a BUILD_ASSERT,
mirroring the existing UART_MTU != 0 check. Default configs satisfy it (256 <= 386).

Signed-off-by: JP Hutchins <jp@intercreate.io>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Design/analysis doc for review; drop before any upstream submission.

Signed-off-by: JP Hutchins <jp@intercreate.io>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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