Skip to content

Added mem verify to read back and compare memory contents - #20

Merged
evoggy merged 1 commit into
mainfrom
evoggy/mem-verify
Sep 24, 2026
Merged

evoggy merged 1 commit into
mainfrom
evoggy/mem-verify

Conversation

@evoggy

@evoggy evoggy commented Sep 24, 2026

Copy link
Copy Markdown
Member

Adds mem verify, which takes the same arguments as mem write but reads the
memory back and compares it against the expected data instead of writing it.

cfcli mem verify DeckMemory -s 0x10000000 -i color-led.bin
cfcli mem verify EEPROMConfig -s 0x20 --data 0x01,1,0x02

The length read back is the length of the expected data, so the same
--data/--input arguments that wrote a region verify exactly that region.
Like write, one of the two is required and they're mutually exclusive.

On success it prints a confirmation and exits 0:

Read back 32 bytes from memory ID=3 at offset 0x0
Verify OK: 32 bytes at offset 0x0 match

On a mismatch it lists the differing bytes with their absolute offsets and
exits 1, so a script can act on it:

Read back 32 bytes from memory ID=3 at offset 0x0
Offset     | Expected | Actual
-----------+----------+--------
0x00000004 | 0xFF     | 0x00
0x00000005 | 0xBD     | 0xBC
0x00000014 | 0xEF     | 0x6F
Error: Verify FAILED: 3 of 32 bytes differ

At most 16 differing bytes are listed, the rest summarised as ... and N more
with the total on the final line — enough to spot a pattern (a shifted image,
a stuck bit) without burying the summary. The listing uses the shared table
helper from #19.

The read shows the same progress bar as mem read, which matters when
verifying a firmware image over the radio.

docs/memory.md gets a "Verifying memory" section, and the deck-bootloading
example now ends with a verify step.

On the exit code

A mismatch exits 1 (unspecified error). The documented codes don't have a
better fit — it isn't a connection failure, a missing resource, a bad argument
or a timeout. If it'd be useful to distinguish "verification failed" from
"something broke" in scripts, a dedicated code would be easy to add; I left
the documented contract alone for now.

Testing

Against a Crazyflie with a Lighthouse deck: matching data (exit 0), three
deliberately corrupted bytes (reported at exactly the right offsets, exit 1),
the --data form at a non-zero offset, and a 32-byte all-zero file to exercise
the 16-row truncation (29 of 32 differing).

@evoggy
evoggy merged commit 737bca5 into main Sep 24, 2026
1 check passed
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