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

):
pconfig = self._printer.lookup_object("configfile")
pconfig.runtime_warning(
f"MCU {self._name!r} firmware is out of date, it will still work but an update is recommended"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be more assertive. Something like: "it may not function as intended, please update as soon as possible."

last_modified = max(file.stat().st_mtime for file in sources)
if hash_cache.is_file() and hash_cache.stat().st_mtime >= last_modified:
return hash_cache.read_text()
hash = hashlib.md5()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use something modern. I know this isn't for security, but using a modern algorithm is also likely to be faster. Also apparently sometimes md5 isn't available because there are FIPS compliant versions of Python. Since we pretty much always recommend 64 bit platforms, Blake2b would be a good choice.

def generate_code(self, options):
cleanbuild, self.toolstr = tool_versions(options.tools)
self.version = build_version(options.extra, cleanbuild)
self.sources = 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.

I think this should be called sources_hash. Same goes in all locations where sources is really the hash of the source dir.

and sources != self._printer.get_start_args().get("sources_hash")
):
pconfig = self._printer.lookup_object("configfile")
pconfig.runtime_warning(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do these runtime warnings a few times. The cost of always looking up pconfig is negligible. Hoist it out of the condtionals.

self._get_status_info["app"] = app
self._get_status_info["mcu_version"] = version
self._get_status_info["mcu_build_versions"] = build_versions
self._get_status_info["mcu_sources"] = sources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mcu_sources_hash

)
app = msgparser.get_app_info()
version, build_versions = msgparser.get_version_info()
sources = msgparser.get_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.

sources_hash

.config
.config.old
klippy/.version
klippy/.sources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it actually makes more sense to place .sources at the root instead, since it's pulled in from both Klippy and buildcommands.

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.

3 participants