Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop e85352c61 -> dc0fe7ff2


Don't overwrite image-in-use with core dump.


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

Branch: refs/heads/develop
Commit: dc0fe7ff28df8d3828bb304959298f7c9033e331
Parents: e85352c
Author: Christopher Collins <ccoll...@apache.org>
Authored: Sat Oct 15 02:32:37 2016 -0700
Committer: Christopher Collins <ccoll...@apache.org>
Committed: Sat Oct 15 02:32:55 2016 -0700

----------------------------------------------------------------------
 sys/coredump/src/coredump.c                 | 11 +++++++++++
 sys/flash_map/include/flash_map/flash_map.h |  1 +
 sys/flash_map/src/flash_map.c               | 22 ++++++++++++++++++++++
 3 files changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dc0fe7ff/sys/coredump/src/coredump.c
----------------------------------------------------------------------
diff --git a/sys/coredump/src/coredump.c b/sys/coredump/src/coredump.c
index a35c070..13c7a89 100644
--- a/sys/coredump/src/coredump.c
+++ b/sys/coredump/src/coredump.c
@@ -52,6 +52,7 @@ coredump_dump(void *regs, int regs_sz)
     uint8_t hash[IMGMGR_HASH_LEN];
     uint32_t off;
     uint32_t area_off, area_end;
+    int slot;
 
     if (coredump_disabled) {
         return;
@@ -70,6 +71,16 @@ coredump_dump(void *regs, int regs_sz)
         return;
     }
 
+    /* Don't overwrite an image that has any flags set (pending, active, or
+     * confirmed).
+     */
+    slot = flash_area_id_to_image_slot(MYNEWT_VAL(COREDUMP_FLASH_AREA));
+    if (slot != -1) {
+        if (imgmgr_state_slot_in_use(slot)) {
+            return;
+        }
+    }
+
     if (flash_area_erase(fa, 0, fa->fa_size)) {
         return;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dc0fe7ff/sys/flash_map/include/flash_map/flash_map.h
----------------------------------------------------------------------
diff --git a/sys/flash_map/include/flash_map/flash_map.h 
b/sys/flash_map/include/flash_map/flash_map.h
index bfac289..b7f1136 100644
--- a/sys/flash_map/include/flash_map/flash_map.h
+++ b/sys/flash_map/include/flash_map/flash_map.h
@@ -87,6 +87,7 @@ uint8_t flash_area_align(const struct flash_area *);
 int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret);
 
 int flash_area_id_from_image_slot(int slot);
+int flash_area_id_to_image_slot(int area_id);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dc0fe7ff/sys/flash_map/src/flash_map.c
----------------------------------------------------------------------
diff --git a/sys/flash_map/src/flash_map.c b/sys/flash_map/src/flash_map.c
index f310400..17aada4 100644
--- a/sys/flash_map/src/flash_map.c
+++ b/sys/flash_map/src/flash_map.c
@@ -129,6 +129,11 @@ flash_area_align(const struct flash_area *fa)
     return hal_flash_align(fa->fa_device_id);
 }
 
+/**
+ * Converts the specified image slot index to a flash area ID.  If the
+ * specified value is not a valid image slot index (0 or 1), a crash is
+ * triggered.
+ */
 int
 flash_area_id_from_image_slot(int slot)
 {
@@ -143,6 +148,23 @@ flash_area_id_from_image_slot(int slot)
     }
 }
 
+/**
+ * Converts the specified flash area ID to an image slot index (0 or 1).  If
+ * the area ID does not correspond to an image slot, -1 is returned.
+ */
+int
+flash_area_id_to_image_slot(int area_id)
+{
+    switch (area_id) {
+    case FLASH_AREA_IMAGE_0:
+        return 0;
+    case FLASH_AREA_IMAGE_1:
+        return 1;
+    default:
+        return -1;
+    }
+}
+
 void
 flash_map_init(void)
 {

Reply via email to