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


The following commit(s) were added to refs/heads/master by this push:
     new 363eebd  Parametrize img_mgmt_impl_swap_type
363eebd is described below

commit 363eebd69f752a9d6fdf7187e5de546ad10940ba
Author: Dominik Ermel <dominik.er...@nordicsemi.no>
AuthorDate: Wed Aug 25 15:41:16 2021 +0000

    Parametrize img_mgmt_impl_swap_type
    
    The img_mgmt_impl_swap_type will now take slot parameter and will
    return swap type, which would happen between pair the slot belongs
    to.  The change allows to check swap type for multi-image
    configuration.
    Modifications to mynewt and zephyr ports have been provided.
    The commit also moves asserts that check allowed slot numbers
    from img_mgmt_state_flags, to img_mgmt_impl_swap_type (for mynewt),
    making port responsible for deciding what slot number is allowed.
    
    Signed-off-by: Dominik Ermel <dominik.er...@nordicsemi.no>
---
 cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h  | 6 ++++--
 cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c | 4 +++-
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 2 +-
 cmd/img_mgmt/src/img_mgmt_state.c              | 4 +---
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h 
b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
index 53f60bf..eb0445c 100644
--- a/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
@@ -98,11 +98,13 @@ int img_mgmt_impl_write_image_data(unsigned int offset, 
const void *data,
 
 /**
  * @brief Indicates the type of swap operation that will occur on the next
- * reboot, if any.
+ * reboot, if any, between provided slot and it's pair.
+ * Quering any slots of the same pair will give the same result.
  *
+ * @param image                 An slot number;
  * @return                      An IMG_MGMT_SWAP_TYPE_[...] code.
  */
-int img_mgmt_impl_swap_type(void);
+int img_mgmt_impl_swap_type(int slot);
 
 /**
  * Collects information about the specified image slot.
diff --git a/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c 
b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
index 8151001..f75b00d 100644
--- a/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
+++ b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
@@ -510,8 +510,10 @@ done:
 #endif
 
 int
-img_mgmt_impl_swap_type(void)
+img_mgmt_impl_swap_type(int slot)
 {
+    assert(slot == 0 || slot == 1);
+
     switch (boot_swap_type()) {
     case BOOT_SWAP_TYPE_NONE:
         return IMG_MGMT_SWAP_TYPE_NONE;
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 096c47c..cc3b1cd 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -424,7 +424,7 @@ int img_mgmt_impl_erase_if_needed(uint32_t off, uint32_t 
len)
 #endif
 
 int
-img_mgmt_impl_swap_type(void)
+img_mgmt_impl_swap_type(int slot)
 {
     switch (mcuboot_swap_type()) {
     case BOOT_SWAP_TYPE_NONE:
diff --git a/cmd/img_mgmt/src/img_mgmt_state.c 
b/cmd/img_mgmt/src/img_mgmt_state.c
index 3f291a4..cb5a600 100644
--- a/cmd/img_mgmt/src/img_mgmt_state.c
+++ b/cmd/img_mgmt/src/img_mgmt_state.c
@@ -36,14 +36,12 @@ img_mgmt_state_flags(int query_slot)
     uint8_t flags;
     int swap_type;
 
-    assert(query_slot == 0 || query_slot == 1);
-
     flags = 0;
 
     /* Determine if this is is pending or confirmed (only applicable for
      * unified images and loaders.
      */
-    swap_type = img_mgmt_impl_swap_type();
+    swap_type = img_mgmt_impl_swap_type(query_slot);
     switch (swap_type) {
     case IMG_MGMT_SWAP_TYPE_NONE:
         if (query_slot == IMG_MGMT_BOOT_CURR_SLOT) {

Reply via email to