Repository navigation
fix(flash): check install-if-different against the written bytes only - #472
Merged
Merged
Conversation
The flash handler handed `should_skip_install` the whole MTD partition. `flashcp` and `nandwrite -p` write the object from the start of the partition and leave the rest erased, so with `content-diverges` the checksum covered the object plus the erased tail and never matched: the object was written on every update, however unchanged. A bootloader partition is erased and rewritten each time for nothing. Read exactly the `size` bytes the install writes, from the start of the partition. On NAND, skip the bad erase blocks as `nandwrite` does, so the read sees the data where it was written. That also keeps the version check of `version-diverges` inside the object, which #449 left reading the whole partition because a plain `size` bound would cut off a banner pushed past it by a bad block. The bad-block-aware read is unit tested without hardware. The installer tests over nandsim and mtdram need root, like the other MTD tests.
otavio
force-pushed
the
fix/flash-install-if-different-region
branch
from
November 18, 2026 12:40
1f8546b to
b5865ed
Compare
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.
What
With
install-if-differentset tocontent-diverges, an object installed by theflashhandler is written on every update, even when the partition already holds it.The failure
An i.MX8MM package installs
flash.binto theu-bootMTD partition with theflashhandler. The check handedshould_skip_installthe whole partition, butflashcpandnandwrite -pwrite the object from the start of the partition and leave the rest erased. The checksum then covers the object plus the erased tail, so it never matches the object'ssha256sum: the partition is erased and rewritten on every update.The fix
Read exactly the
sizebytes the install writes, from the start of the partition. On NAND the read skips bad erase blocks (MEMGETBADBLOCK), asnandwritedoes when writing, so it sees the data where it actually landed.#449 left
flashreading the whole partition on purpose, because a plainsizebound would cut off a version banner pushed past it by a bad block. Skipping bad blocks removes that concern, soversion-divergesis now bounded to the object as well. If the installed binary is larger than the new one and its banner lies past the newsize, no version is found and the object is installed. That errs on the safe side, as forrawsince #449.imxkobsis unchanged, for the reasons given in #449.Tests
read_written_stops_at_the_object_size,read_written_skips_bad_blocksandread_written_stops_at_the_end_of_the_devicecover the bad-block-aware read without hardware.install_if_different_checksum_ignores_the_erased_tailandinstall_if_different_checksum_writes_a_changed_objectrun the installer overmtdramand overnandsim. On NAND they use the partitionnandsimregisters itself, since it cannot be split further withoutCONFIG_MTD_PARTITIONED_MASTER. Like the other MTD tests they need root, so CI skips them.Run as root on Linux 7.3.4, all 7 tests of
installer::flashandutils::mtdpass. With the previous check restored,install_if_different_checksum_ignores_the_erased_tailfails (assertion failed: !checksum_install_writes(MtdKind::Nor, &object, &object)): the unchanged object is written again.cargo test --lib(132 passed),cargo fmt --checkandcargo clippy -- -D clippy::allare clean.