You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/08/19 22:12:08 UTC

[09/12] incubator-mynewt-core git commit: bootutil; make status element size depend on flash alignment restrictions.

bootutil; make status element size depend on flash alignment restrictions.


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/857e611e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/857e611e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/857e611e

Branch: refs/heads/develop
Commit: 857e611ee3c070e76f51ffd47240af982a069414
Parents: cc0317c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Aug 17 16:07:37 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/src/bootutil_misc.c | 15 ++++++++-------
 libs/bootutil/src/bootutil_priv.h |  5 +++--
 libs/bootutil/src/loader.c        | 15 +++++++++++++++
 3 files changed, 26 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/857e611e/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index e353b62..cf48f84 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -19,6 +19,7 @@
 
 #include <string.h>
 #include <inttypes.h>
+#include <assert.h>
 #include <hal/hal_flash.h>
 #include <hal/flash_map.h>
 #include <os/os.h>
@@ -150,13 +151,14 @@ boot_read_status_bytes(struct boot_status *bs, uint8_t flash_id, uint32_t off)
 {
     uint8_t status;
 
-    off -= sizeof(status) * 2;
+    assert(bs->elem_sz);
+    off -= bs->elem_sz * 2;
     while (1) {
         hal_flash_read(flash_id, off, &status, sizeof(status));
         if (status == 0xff) {
             break;
         }
-        off--;
+        off -= bs->elem_sz;
         if (bs->state == 2) {
             bs->idx++;
             bs->state = 0;
@@ -186,14 +188,14 @@ boot_read_status(struct boot_status *bs)
     if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
         boot_magic_loc(0, &flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in slot0, %lu/%lu\n", bs->idx, bs->state);
+        console_printf("status in slot0, %lu/%u\n", bs->idx, bs->state);
         return 1;
     }
     boot_scratch_magic(&bit);
     if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
         boot_scratch_loc(&flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in scratch, %lu/%lu\n", bs->idx, bs->state);
+        console_printf("status in scratch, %lu/%u\n", bs->idx, bs->state);
         return 1;
     }
     return 0;
@@ -227,10 +229,9 @@ boot_write_status(struct boot_status *bs)
          */
         boot_magic_loc(0, &flash_id, &off);
     }
-    off -= ((3 * sizeof(uint8_t)) * bs->idx +
-      sizeof(uint8_t) * (bs->state + 1));
+    off -= ((3 * bs->elem_sz) * bs->idx + bs->elem_sz * (bs->state + 1));
 
-    console_printf("status write, %lu/%lu -> %lx\n", bs->idx, bs->state, off);
+    console_printf("status write, %lu/%u -> %lx\n", bs->idx, bs->state, off);
 
     val = bs->state;
     hal_flash_write(flash_id, off, &val, sizeof(val));

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/857e611e/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index ffdfcb2..697145d 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.h
@@ -40,8 +40,9 @@ struct boot_image_location {
  * Maintain state of copy progress.
  */
 struct boot_status {
-    uint32_t idx;
-    uint32_t state;
+    uint32_t idx;       /* Which area we're operating on */
+    uint8_t elem_sz;    /* Size of the status element to write in bytes */
+    uint8_t state;      /* Which part of the swapping process are we at */
 };
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/857e611e/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index 22187a7..3171c05 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -137,6 +137,7 @@ boot_image_info(void)
 {
     int i;
     struct boot_img *b;
+    struct flash_area *scratch;
 
     for (i = 0; i < BOOT_NUM_SLOTS; i++) {
         b = &boot_img[i];
@@ -144,6 +145,20 @@ boot_image_info(void)
         boot_read_image_header(&b->loc, &b->hdr);
         b->area = boot_req->br_img_sz;
     }
+
+    /*
+     * Figure out what size to write update status update as.
+     * The size depends on what the minimum write size is for scratch
+     * area, active image slot. We need to use the bigger of those 2
+     * values.
+     */
+    boot_state.elem_sz = hal_flash_align(boot_img[0].loc.bil_flash_id);
+
+    scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
+    i = hal_flash_align(scratch->fa_flash_id);
+    if (i > boot_state.elem_sz) {
+        boot_state.elem_sz = i;
+    }
 }
 
 /*