Skip to content

Conversation

@kageurufu
Copy link
Member

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: False as an option to disable this check.

Checklist

  • pr title makes sense
  • added a test case if possible
  • if new feature, added to the readme
  • ci is happy and green

)
elif (
get_danger_options().warn_on_mismatched_firmware_sources
and sources_hash
Copy link
Contributor

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():
Copy link
Contributor

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)
Copy link
Contributor

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)

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.

4 participants