You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
qr: read compressed BBQr, expanding it through the paced driver
`Z` deflates a file and only then cuts it into parts, so a scan of one collects the
compressed stream and has to expand it. On the Q1 image that is 342 codes instead of
449 -- a quarter fewer, not the half the compression ratio suggests, because the
compressor keeps its back-references inside a kilobyte so a device can expand the
result with a window it can afford.
**Nothing holds a slice over the mapped region.** `inflate_to_slice` would have been
four lines and is the wrong tool: inflate writes a byte at a time and reads its own
history back, and byte stores and unpaced reads are the two things PSRAM mis-issues. So
the window lives in ordinary memory and both ends cross the medium in whole chunks
through `StagingArea` -- `minizlib::Reader` fetching input a chunk at a time,
`minizlib::Stream` handing output back a window at a time. Between them the
decompressor never touches the bus.
Reading the stream and writing the expansion are the same area and the two callbacks
cannot each hold `&mut`. They run strictly in turn, so a `RefCell` says so honestly --
and the borrow is *tried*, because a panic partway through writing a firmware image is
the worst place here to be wrong about a lifetime.
The stream lands at 6 MiB and expands down from zero, so the expansion never overwrites
input it has not read. A test pins that rather than the comment being the only thing
that says it.
It lives in `catcard-upgrade::expand` rather than the firmware so it can be tested
against a memory-backed area: six tests, including that the chunk size changes only how
often the bus turns round, that too wide a sender window is named rather than guessed,
and that **damage survives to where the signature can see it** -- raw deflate has no
checksum, so a corrupt stream can expand to exactly the right length and simply be the
wrong bytes. That is not a gap to close here; the image signature is the check. What
would be wrong is expanding the damage away.
`catcard-image qr` compresses when that makes fewer codes and says which it used. The
compressor can make a file with little redundancy longer, so the shorter of the two
wins.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
0 commit comments