-
-
Notifications
You must be signed in to change notification settings - Fork 195
Add runtime warning if the MCU firmware is out of date, based on a hash of the firmware sources #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
5a372a2 to
fe4d57d
Compare
| ) | ||
| elif ( | ||
| get_danger_options().warn_on_mismatched_firmware_sources | ||
| and sources_hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| return git_info | ||
|
|
||
|
|
||
| def get_firmware_hash(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
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