-
Notifications
You must be signed in to change notification settings - Fork 4
Add library to read/write firmware update HEADER files #74
Conversation
When mbl-cloud-client wants to know what version of firmware is running on a device it runs a script "arm_update_active_details.sh" that passes mbl-cloud-client a "HEADER" file that contains information about the last firmware update. Usually, this HEADER file is passed to the device along with a firmware update from the Pelion cloud, but there are two cases where that doesn't happen: * When an update is sent to the device by the mbl-cli tool rather than the Pelion cloud. * When the first version of software is initially written directly to the deivce's flash. We therefore need a mechanism to create these HEADER files independently of the Pelion Cloud and mbl-cloud-client. This commit adds: * The mbl-firmware-update-header Python library for creating and reading HEADER files. * Tests for the mbl-firmware-update-header library. * An update to the mbl-firmware-update-manager library (which is used to install updates that do not arrive via the Pelion cloud) to create a HEADER file for incoming updates.
...e-management/mbl-firmware-update-header/mbl/firmware_update_header/firmware_update_header.py
Outdated
Show resolved
Hide resolved
...e-management/mbl-firmware-update-header/mbl/firmware_update_header/firmware_update_header.py
Outdated
Show resolved
Hide resolved
firmware-management/mbl-firmware-update-header/mbl/firmware_update_header/__init__.py
Outdated
Show resolved
Hide resolved
|
||
if len(data) < self.__header_and_crc_size: | ||
raise FormatError( | ||
"Data is too short (expecting at least {}B)".format( |
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.
Suggest to add len(data) in the message
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.
Good point. Will do that.
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.
Added in latest code.
if header_magic != self.__HEADER_MAGIC: | ||
raise FormatError( | ||
"Invalid header magic value 0x{:x} (should be 0x{:x})".format( | ||
header_magic, self.__HEADER_MAGIC |
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.
I assume this header magic confidential, right?
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.
Nope.
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.
LOL meant "NOT confidential"
|
||
if header_version != self.HEADER_FORMAT_VERSION: | ||
raise FormatError( | ||
"Unsupported header version {}".format(header_version) |
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.
I suggest to add self.HEADER_FORMAT_VERSION to the message
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.
Will do.
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.
Added in latest code.
# Create a "HEADER" file for the update - this is a blob that contains | ||
# information about the update | ||
with open(HEADER_FILE, "wb") as header_file: | ||
header_file.write(_create_header_data(firmware_update_file_path)) |
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.
I think your new script throws exceptions. Are you handling them here in some way?
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.
Yes, this is sloppy, should be fixed in the latest code.
Adding DO NOT MERGE label - I need to re-test after the changes for review comments. |
...e-management/mbl-firmware-update-header/mbl/firmware_update_header/firmware_update_header.py
Outdated
Show resolved
Hide resolved
Regarding the remaining sanity check failures: they are spurious; see PelionIoT/mbl-tools#126 |
* Confusingly, the code was previously sometimes treating firmware hashes as 512-bit values and sometimes treating them as 256-bit values. It sort-of worked by chance, but let's be explicit about what's happenning: the firmware_hash field in HEADER blobs is 512 bits long, but we only use the first 256 bits of it to store sha256 hashes. * Add a missing "self" parameter in _create_header_data.
Even after PelionIoT/mbl-tools#126 was merged there are still sanity check failures... They're in unrelated code and are being dealt with by PelionIoT/mbl-tools#129. I think I've addressed all review comments and I've re-tested, so, reviewers, please re-review. |
Reviewers, sorry for the extra hassle but I want to make another change before this is merged. In another PR I'm going to create a recipe in meta-mbl to use the Python module added in this PR to actually create a firmware update HEADER file... It seems sensible to call this new recipe "mbl-firmware-update-header", so I want to rename the Python module to be called "mbl.firmware_update_header.util". |
I've (partially) retested after the module rename and added a new Jenkins link (build in progress). |
...anagement/mbl-firmware-update-header-util/tests/host/test_mbl_firmware_update_header_util.py
Outdated
Show resolved
Hide resolved
...l-firmware-update-header-util/mbl/firmware_update_header_util/firmware_update_header_util.py
Outdated
Show resolved
Hide resolved
...l-firmware-update-header-util/mbl/firmware_update_header_util/firmware_update_header_util.py
Outdated
Show resolved
Hide resolved
Co-Authored-By: jonathanhaigh-arm <[email protected]>
* Remove optional "0" in some slice syntax. * Remove unnecessary line break.
…ed/mbl-core into jh-update-header-IOTMBL-1099
Thanks for the changes. |
When mbl-cloud-client wants to know what version of firmware is running
on a device it runs a script "arm_update_active_details.sh" that passes
mbl-cloud-client a "HEADER" file that contains information about the
last firmware update.
Usually, this HEADER file is passed to the device along with a firmware
update from the Pelion cloud, but there are two cases where that doesn't
happen:
the Pelion cloud.
the deivce's flash.
We therefore need a mechanism to create these HEADER files independently
of the Pelion Cloud and mbl-cloud-client.
This commit adds:
HEADER files.
install updates that do not arrive via the Pelion cloud) to create
a HEADER file for incoming updates.
Synchronization
Must be merged before: PelionIoT/meta-mbl#367
Jenkins Link
http://jenkins.mbed-linux.arm.com/blue/organizations/jenkins/jh-test/detail/jh-test/34/pipeline (successful)
http://jenkins.mbed-linux.arm.com/blue/organizations/jenkins/jh-test/detail/jh-test/36/pipeline (successful; after addressing review comments).
http://jenkins.mbed-linux.arm.com/blue/organizations/jenkins/jh-test/detail/jh-test/37/pipeline (aborted; after addressing further review comments and fixing sanity check errors).
http://jenkins.mbed-linux.arm.com/blue/organizations/jenkins/jh-test/detail/jh-test/38/pipeline (successful; after more changes).
http://jenkins.mbed-linux.arm.com/blue/organizations/jenkins/jh-test/detail/jh-test/40/pipeline (in progress; after module rename).
Testing done