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.ermel@nordicsemi.no>
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 @@
/**
* @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 @@
#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 @@
#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 @@
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) {