Skip to content

Ensure header CRC is written as unsigned int #9783

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

Merged
merged 1 commit into from
Feb 21, 2019

Conversation

bridadan
Copy link
Contributor

Description

Fixes #9750. The bootloader merge would fail since the CRC produces an unsigned 32 bit integer, however we specified it as a signed 32 bit integer.

I've tested this on a K64F and ran an update over Pelion, seems to work ok!

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@theotherjimmy - tools team review

Release Notes

@cmonr
Copy link
Contributor

cmonr commented Feb 20, 2019

@bridadan We've done this fix before (#8788), only to have it reverted (#8915)

Thoughts?

@bridadan bridadan force-pushed the fix_unsigned_crc_header branch from 683e0a9 to 434d86b Compare February 21, 2019 02:31
@bridadan
Copy link
Contributor Author

Hey @cmonr, thanks for linking that, I thought this changeset looked familiar 😆

This is the error that appeared in the linked PRs that concerned me: #8788 (comment)

Traceback (most recent call last):
  File "/builds/ws/mbed-os-ci_cloud-client-test/mbed-cloud-client-example/mbed-os/tools/make.py", line 71, in wrapped_build_project
    src_dir, build_dir, mcu, *args, **kwargs
  File "/builds/ws/mbed-os-ci_cloud-client-test/mbed-cloud-client-example/mbed-os/tools/build_api.py", line 549, in build_project
    merge_region_list(region_list, res, notify)
  File "/builds/ws/mbed-os-ci_cloud-client-test/mbed-cloud-client-example/mbed-os/tools/build_api.py", line 422, in merge_region_list
    _fill_header(region_list, region).tofile(header_filename, format='hex')
  File "/builds/ws/mbed-os-ci_cloud-client-test/mbed-cloud-client-example/mbed-os/tools/build_api.py", line 392, in _fill_header
    header.puts(start, struct.pack(fmt, zlib.crc32(ih.tobinarray())))
error: integer out of range for 'L' format code

I've just pushed a change that I believe will solve this issue. I've followed the note in the python docs: https://docs.python.org/2.7/library/zlib.html#zlib.crc32

To generate the same numeric value across all Python versions and platforms use crc32(data) & 0xffffffff. If you are only using the checksum in packed binary format this is not necessary as the return value is the correct 32bit binary representation regardless of sign.

@cmonr
Copy link
Contributor

cmonr commented Feb 21, 2019

@ARMmbed/mbed-os-maintainers @JanneKiiskila #9783 (comment) Thoughts?

@bridadan Yeah, I'm just being cautious. I thought that this would be the right fix as well, and still thing so, but don't want us to get into a bad state again.

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

Lets run CI !

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 21, 2019

Set to 5.12 to sit on master and run additional nightly tests

@bridadan
Copy link
Contributor Author

Hey @cmonr, I'm pretty sure the last commit I pushed should avoid the error: integer out of range for 'L' format code problem. I confirmed the cases that cause that error and also confirmed that bitwise "anding" the values with 0xffffffff forces them to the right size:

import struct
>>> fmt = "<L"
>>> val = 0xffffffff + 1
>>> struct.pack(fmt, val)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: integer out of range for 'L' format code
>>> struct.pack(fmt, val & 0xffffffff)
'\x00\x00\x00\x00'
>>> val = -1
>>> struct.pack(fmt, val)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: integer out of range for 'L' format code
>>> struct.pack(fmt, val & 0xffffffff)
'\xff\xff\xff\xff'

@cmonr
Copy link
Contributor

cmonr commented Feb 21, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Feb 21, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 1
Build artifacts

@cmonr cmonr merged commit 091da53 into ARMmbed:master Feb 21, 2019
@cmonr cmonr removed the needs: CI label Feb 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants