bootutil: Fix issue with align > 1 Some flash devices not only require writes to occur on an `align` byte boundary, but also require that the writes be done in chunks of this size as well. Enhance the sections that write status bytes to write more than a single status byte.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/bf13e99e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bf13e99e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bf13e99e Branch: refs/heads/develop Commit: bf13e99ed1897317dc11032db03df22ae7cb92d4 Parents: 353857b Author: David Brown <[email protected]> Authored: Mon Jan 23 15:50:58 2017 -0700 Committer: Christopher Collins <[email protected]> Committed: Mon Feb 6 14:53:06 2017 -0800 ---------------------------------------------------------------------- boot/bootutil/src/bootutil_misc.c | 19 +++++++++++++------ boot/bootutil/src/loader.c | 9 ++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf13e99e/boot/bootutil/src/bootutil_misc.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c index 87895ba..2fe08e3 100644 --- a/boot/bootutil/src/bootutil_misc.c +++ b/boot/bootutil/src/bootutil_misc.c @@ -309,13 +309,17 @@ int boot_write_copy_done(const struct flash_area *fap) { uint32_t off; - uint8_t val; int rc; + uint8_t buf[8]; + uint8_t align; off = boot_copy_done_off(fap); - val = 1; - rc = flash_area_write(fap, off, &val, 1); + align = hal_flash_align(fap->fa_device_id); + memset(buf, 0xFF, 8); + buf[0] = 1; + + rc = flash_area_write(fap, off, buf, align); if (rc != 0) { return BOOT_EFLASH; } @@ -327,13 +331,16 @@ int boot_write_image_ok(const struct flash_area *fap) { uint32_t off; - uint8_t val; int rc; + uint8_t buf[8]; + uint8_t align; off = boot_image_ok_off(fap); - val = 1; - rc = flash_area_write(fap, off, &val, 1); + align = hal_flash_align(fap->fa_device_id); + memset(buf, 0xFF, 8); + buf[0] = 1; + rc = flash_area_write(fap, off, buf, align); if (rc != 0) { return BOOT_EFLASH; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf13e99e/boot/bootutil/src/loader.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c index 1d9f71b..f2497af 100644 --- a/boot/bootutil/src/loader.c +++ b/boot/bootutil/src/loader.c @@ -462,6 +462,8 @@ boot_write_status(struct boot_status *bs) uint32_t off; int area_id; int rc; + uint8_t buf[8]; + uint8_t align; if (bs->idx == 0) { /* Write to scratch. */ @@ -480,7 +482,12 @@ boot_write_status(struct boot_status *bs) off = boot_status_off(fap) + boot_status_internal_off(bs->idx, bs->state, boot_data.write_sz); - rc = flash_area_write(fap, off, &bs->state, 1); + align = hal_flash_align(fap->fa_device_id); + // ASSERT(align <= 8); + memset(buf, 0xFF, 8); + buf[0] = bs->state; + + rc = flash_area_write(fap, off, buf, align); if (rc != 0) { rc = BOOT_EFLASH; goto done;
