mcuboot icon indicating copy to clipboard operation
mcuboot copied to clipboard

Mbed-OS: Prevent use of BlockDevice with unreliable erase value

Open AGlass0fMilk opened this issue 4 years ago • 6 comments

The default return value of BlockDevice::get_erase_value is -1. When implicitly cast from an int to a uint8_t, this gets truncated to 0xFF, which is normally a reasonable erase value.

However, the intent of the Mbed-OS BlockDevice API is that an integer value of -1 is to be interpreted as an "unreliable" erase value. ie: the underlying BlockDevice does not have a known erase value.

If a user attempts to use such a BlockDevice (eg: SDBlockDevice at the moment, see ARMmbed/mbed-os#15070), they may encounter hard to debug errors.

Since MCUboot expects some fields to be the "erased value" under certain boot/swap states, a BlockDevice with an unreliable erase value is not compatible with MCUboot. It is recommended that the user wrap the incompatible BlockDevice in a FlashSimBlockDevice to provide a known erase value.

This commit adds an assert that will (hopefully) catch such an error during development.

Signed-off-by: George Beckstein [email protected]

AGlass0fMilk avatar Sep 15 '21 05:09 AGlass0fMilk

@LDong-Arm @boraozgen

AGlass0fMilk avatar Sep 15 '21 05:09 AGlass0fMilk

Updated the comments to recommend use of the FlashSimBlockDevice to ensure a known erase value and enable compatibility with MCUboot.

See ARMmbed/mbed-os#15071

AGlass0fMilk avatar Sep 15 '21 15:09 AGlass0fMilk

The failed mynewt test should pass after re-pushing. The certificate issue has been resolved. Rebasing will bring in a change that ignores the certificate, though.

d3zd3z avatar Sep 17 '21 22:09 d3zd3z

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

github-actions[bot] avatar Jun 27 '22 02:06 github-actions[bot]

Is there still interest in getting this merged?

d3zd3z avatar Jun 29 '22 00:06 d3zd3z

Unfortunately I no longer contribute to Mbed-OS, so someone else will have to push this along.

AGlass0fMilk avatar Jun 29 '22 00:06 AGlass0fMilk

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

github-actions[bot] avatar Dec 27 '22 01:12 github-actions[bot]