You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2021/06/16 10:21:19 UTC

[mynewt-mcumgr] branch master updated (a5d3441 -> e71063a)

This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git.


    from a5d3441  Merge pull request #125 from vrahane/img_mgmt_erase_stop_dfu
     new 71c76f5  zephyr: Upload should use g_img_mgmt_state
     new e215d26  zephyr: Check area id in erase slot processing
     new e71063a  zephyr: Improve and rename img_mgmt_find_best_area_id

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 76 +++++++++++++-------------
 1 file changed, 38 insertions(+), 38 deletions(-)

[mynewt-mcumgr] 02/03: zephyr: Check area id in erase slot processing

Posted by ut...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit e215d26bb7c7ea1352bc954b2b59a6fc0a234a46
Author: Dominik Ermel <do...@nordicsemi.no>
AuthorDate: Wed Jun 9 13:51:18 2021 +0000

    zephyr: Check area id in erase slot processing
    
    The img_mgmt_impl_erase_slot was not checking the return value
    of the img_mgmt_find_best_area_id.
    
    Signed-off-by: Dominik Ermel <do...@nordicsemi.no>
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 25b9318..9eb9450 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -192,11 +192,13 @@ int
 img_mgmt_impl_erase_slot(void)
 {
     bool empty;
-    int rc;
+    int rc, best_id;
 
     /* Select non-active slot */
-    const int best_id = img_mgmt_find_best_area_id();
-
+    best_id = img_mgmt_find_best_area_id();
+    if (best_id < 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
     rc = zephyr_img_mgmt_flash_check_empty(best_id, &empty);
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;

[mynewt-mcumgr] 03/03: zephyr: Improve and rename img_mgmt_find_best_area_id

Posted by ut...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit e71063a3c01d6ea8b73a06f14c1d3006f2de9e7a
Author: Dominik Ermel <do...@nordicsemi.no>
AuthorDate: Wed Jun 9 13:15:52 2021 +0000

    zephyr: Improve and rename img_mgmt_find_best_area_id
    
    The img_mgmt_find_best_area_id has been renamed to
    img_mgmt_get_unused_slot_area_id and now takes one integer parameter,
    that is a slot number to check.
    The parameter may be -1, in which case the function will check the
    first two slots for availability to perform DFU.  In case when
    positive integer is provided the function will address directly
    selected slot, and will perform the same tests, as in auto-select,
    for first two slots, but in case of slot numbers above 1, it will
    just check if the slot has been defined.
    
    Signed-off-by: Dominik Ermel <do...@nordicsemi.no>
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 66 +++++++++++++-------------
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 9eb9450..be139c4 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -93,7 +93,7 @@ zephyr_img_mgmt_flash_check_empty(uint8_t fa_id, bool *out_empty)
 /**
  * Get flash_area ID for a image slot number.
  */
-static uint8_t
+static int
 zephyr_img_mgmt_flash_area_id(int slot)
 {
     uint8_t fa_id;
@@ -108,48 +108,46 @@ zephyr_img_mgmt_flash_area_id(int slot)
         break;
 
     default:
-        assert(0);
-        fa_id = FLASH_AREA_ID(image_1);
+        fa_id = -1;
         break;
     }
 
     return fa_id;
 }
 
+/**
+ * The function will check if given slot is available, and allowed, for DFU;
+ * providing -1 as a parameter means find any unused and non-active available;
+ * if checks area positive, then area ID is returned, -1 is returned otherwise.
+ * Note that auto-selection is performed only between two first slots.
+ */
 static int
-img_mgmt_find_best_area_id(void)
+img_mgmt_get_unused_slot_area_id(int slot)
 {
-    struct image_version ver;
-    int best = -1;
-    int i;
-    int rc;
-
-    for (i = 0; i < 2; i++) {
-        rc = img_mgmt_read_info(i, &ver, NULL, NULL);
-        if (rc < 0) {
-            continue;
-        }
-        if (rc == 0) {
-            /* Image in slot is ok. */
-            if (img_mgmt_slot_in_use(i)) {
-                /* Slot is in use; can't use this. */
-                continue;
-            } else {
-                /*
-                 * Not active slot, but image is ok. Use it if there are
-                 * no better candidates.
-                 */
-                best = i;
+    /* Auto select slot; note that this is performed only between two first
+     * slots, at this pointi, which will require fix when Direct-XIP, which may
+     * support more slots, gets support within Zephyr. */
+    if (slot < -1) {
+        return -1;
+    } else if (slot == -1) {
+        for (slot = 0; slot < 2; slot++) {
+            if (img_mgmt_slot_in_use(slot) == 0) {
+                int area_id = zephyr_img_mgmt_flash_area_id(slot);
+                if (area_id != -1) {
+                    return area_id;
+                }
             }
-            continue;
         }
-        best = i;
-        break;
+        return -1;
     }
-    if (best >= 0) {
-        best = zephyr_img_mgmt_flash_area_id(best);
+    /* Direct selection; the first two slots are checked for being available
+     * and unused; the all other slots are just checked for availability. */
+    if (slot < 2) {
+        slot = img_mgmt_slot_in_use(slot) == 0 ? slot : -1;
     }
-    return best;
+
+    /* Return area ID for the slot or -1 */
+    return slot != -1  ? zephyr_img_mgmt_flash_area_id(slot) : -1;
 }
 
 /**
@@ -194,8 +192,8 @@ img_mgmt_impl_erase_slot(void)
     bool empty;
     int rc, best_id;
 
-    /* Select non-active slot */
-    best_id = img_mgmt_find_best_area_id();
+    /* Select any non-active, unused slot */
+    best_id = img_mgmt_get_unused_slot_area_id(-1);
     if (best_id < 0) {
         return MGMT_ERR_EUNKNOWN;
     }
@@ -492,7 +490,7 @@ img_mgmt_impl_upload_inspect(const struct img_mgmt_upload_req *req,
             }
         }
 
-        action->area_id = img_mgmt_find_best_area_id();
+        action->area_id = img_mgmt_get_unused_slot_area_id(-1);
         if (action->area_id < 0) {
             /* No slot where to upload! */
             *errstr = img_mgmt_err_str_no_slot;

[mynewt-mcumgr] 01/03: zephyr: Upload should use g_img_mgmt_state

Posted by ut...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 71c76f5642af0f5567c50b0d7430eb2cda47220f
Author: Dominik Ermel <do...@nordicsemi.no>
AuthorDate: Wed Jun 9 13:09:16 2021 +0000

    zephyr: Upload should use g_img_mgmt_state
    
    The upload was calling img_mgmt_find_best_area_id each time it needed
    to provide area_id, while it should have been using the already selected
    area from the g_img_mgmt_state.area_id.
    
    Signed-off-by: Dominik Ermel <do...@nordicsemi.no>
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 777aad5..25b9318 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -292,7 +292,7 @@ img_mgmt_impl_write_image_data(unsigned int offset, const void *data,
 			}
 		}
 #endif
-		rc = flash_img_init_id(ctx, img_mgmt_find_best_area_id());
+		rc = flash_img_init_id(ctx, g_img_mgmt_state.area_id);
 
 		if (rc != 0) {
 			return MGMT_ERR_EUNKNOWN;
@@ -330,7 +330,7 @@ img_mgmt_impl_erase_image_data(unsigned int off, unsigned int num_bytes)
         goto end;
     }
 
-    rc = flash_area_open(img_mgmt_find_best_area_id(), &fa);
+    rc = flash_area_open(g_img_mgmt_state.area_id, &fa);
     if (rc != 0) {
         LOG_ERR("Can't bind to the flash area (err %d)", rc);
         rc = MGMT_ERR_EUNKNOWN;