Skip to content

Warn when the co-processor rejects corrupt SPI packets - #3

Open
twells46 wants to merge 9 commits into
masterfrom
spi-reject-warning
Open

twells46 wants to merge 9 commits into
masterfrom
spi-reject-warning

Conversation

@twells46

Copy link
Copy Markdown
Owner

Host side of kipr/Wombat-Firmware#12.

What and why

Wombat-Firmware#12 makes the firmware repair or drop corrupt SPI packets instead of desynchronizing. That leaves the host with no sign that writes were lost. The firmware now counts those packets, mod 16, in bits 7:4 of REG_RW_MOT_DONE, which were unused. This PR reads that counter and warns.

Changes

module/core/src/device/wombat/wombat_device.cpp:

  • WombatDevice::transfer() checks the counter after every good transfer.
  • When it moves, libkipr logs [core/wombat] [W]: co-processor rejected N corrupt SPI packet(s); some writes may have been lost.
    • At most one warning every 5 seconds, with the count accumulated in between.
    • Anything still unreported is logged when the device closes.
  • The first value seen is taken as the baseline, so a counter left over from an earlier program doesn't warn.
  • A step of −1 is ignored. The firmware's main loop read-modify-writes the done bits and can briefly put back the previous count.

Nothing else changes. get_motor_done already masks the low four bits. Older firmware leaves the nibble at 0, so this never warns against it.

Verification

Tested on a Wombat with the firmware from Wombat-Firmware#12 (6896e00), using a build of master (cf56155) plus this change:

  • 12 s of analog(0) at about 100 Hz with no bad frames: 0 warnings.
  • The same with a rejected frame injected over raw spidev every 10th call: 4 warnings (1, 48 and 48 at 5 s spacing, then 19 at exit). They total 116, the number injected.
  • Motors (motor, off, freeze, mav, mrp/mtp with the done bit), servos, digital, analog and button reads all behave the same as with stock libkipr 1.2.4. Three injected rejected frames gave one warning for 3 and left the motor done bit set.
  • Not tested against firmware older than Wombat-Firmware#12. By inspection the nibble stays 0 there, so there is nothing to report.
  • Not tested with botui running, or with two processes sharing the SPI device. Each process keeps its own baseline, so each would report the same rejected packets.

🤖 Generated with Claude Code

twells46 and others added 9 commits September 17, 2026 15:43
Wombat-Firmware now counts packets with a corrupt count byte or an
out-of-range address, mod 16, in the high nibble of REG_RW_MOT_DONE
(kipr/Wombat-Firmware#12). Without a reader on the host, those lost
writes are silent.

WombatDevice::transfer() watches the nibble and logs a warning when it
moves, at most once every 5 seconds, and once more on close if any are
still unreported. The first value seen is the baseline. A step of -1 is
ignored: the firmware's main loop can briefly write back the previous
count.

Older firmware leaves the nibble at 0, so it never warns. get_motor_done
already masks the low four bits and is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
twells46 added a commit to twells46/kipr-firmware-dev that referenced this pull request Oct 12, 2026
Attacked Wombat-Firmware PR 12 (oscar/dma-write-bounds, 80ad31a on master
4814ab8), which clamps handle_dma()'s count byte to 42 and skips writes
to addresses < 3 or >= 153. No regression for legitimate traffic, on the
host harness or on hardware (H1-H10).

Two trade-offs were found (A9, A10 in pr12.md):
- A9: a count above 42 is corrupt; the firmware now recovers the real
  count from where the zero padding starts, and applies nothing if the
  body is as suspect as the count.
- A10: rejected packets were invisible to the host; the firmware counts
  them mod 16 in the unused bits 7:4 of REG_RW_MOT_DONE.

The firmware fix for both is Wombat-Firmware 6896e00, pushed to PR 12 with
the review comment in pr12-comment.md. The host side of A10 is
twells46/libwallaby#3. Both are verified on hardware.

Adds:
- pr12/pr12.md: attack summary, falsifiers, tests, results, and log
- harness.sh and harness_*.c: host harness comparing handle_dma() across
  two refs
- pr12_hw.py, pr12_warn.py, pr12_h10.py: hardware tests and the libkipr
  smoke test
- firmware-a9-a10.patch and libwallaby-spi-rejects.patch
- wombat.bin and build-info for every image built, run output, and
  flash logs

Also ignores __pycache__ under investigation/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@twells46
twells46 force-pushed the master branch 2 times, most recently from f29ddd3 to 1dd6cc8 Compare October 23, 2026 15:12
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