Add runtime warning if the MCU firmware is out of date, based on a hash of the firmware sources#768
Open
Add runtime warning if the MCU firmware is out of date, based on a hash of the firmware sources#768
Conversation
dalegaard
requested changes
Oct 30, 2025
5a372a2 to
fe4d57d
Compare
Laikulo
reviewed
Dec 29, 2025
| ) | ||
| elif ( | ||
| get_danger_options().warn_on_mismatched_firmware_sources | ||
| and sources_hash |
Contributor
There was a problem hiding this comment.
msgproto will give back "unknown" if there is no source hash in the firmware (either pre this change, or non-klipper MCUs using the Anchor/Windlass implementation). This means that this will always alert for such MCUs.
Laikulo
reviewed
Dec 29, 2025
| return git_info | ||
|
|
||
|
|
||
| def get_firmware_hash(): |
Contributor
There was a problem hiding this comment.
Consider prefixing the hash with a leader string indicating the version of the hash being used, to allow for changes to either the algo, or the way that it is fed in the future. (See how crypt(5) works for an example of this)
Laikulo
reviewed
Dec 29, 2025
| last_modified = max(file.stat().st_mtime for file in source_files) | ||
| if hash_cache.is_file() and hash_cache.stat().st_mtime >= last_modified: | ||
| return hash_cache.read_text() | ||
| hash = hashlib.blake2b(digest_size=16, usedforsecurity=False) |
Contributor
There was a problem hiding this comment.
usedforsecurity is py3.9, which is not present in Debian bullseye or derivatives, which are still pretty common in live deployments. Consider wrapping until that leaves LTS (2026-08-31)
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.
Fixes to the MCU firmware currently do not trigger the "firmware out of date" error. That error only compares the MCU API dictionaries.
This generates a hash of the firmware sources, includes that in the MCU firmware build, and then compares against the current firmware at runtime.
I also added
[danger_options] warn_on_mismatched_firmware_sources: Falseas an option to disable this check.Checklist