From 19259ab7db73191eaf6dac85282752dc8481fc28 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 13 May 2022 16:03:53 +0000 Subject: [PATCH] mgmt/mcumgr/lib: Fix image list command crashing when no device It is possible, in case of two application images, to have no access to one of devices of the secondary image. When asserts are enabled, such situation causes crash even though the image list command can handle it with no problem. The commit removes the assert and adds additional swap type: IMG_MGMT_SWAP_TYPE_UNKNOWN to indicate situations where it was not possible to obtain swap type from boot_util. Signed-off-by: Dominik Ermel --- .../mgmt/mcumgr/lib/cmd/img_mgmt/include/img_mgmt/img_mgmt.h | 1 + subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/include/img_mgmt/img_mgmt.h b/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/include/img_mgmt/img_mgmt.h index 9861199c251..32c73b26a7e 100644 --- a/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/include/img_mgmt/img_mgmt.h +++ b/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/include/img_mgmt/img_mgmt.h @@ -41,6 +41,7 @@ extern "C" { #define IMG_MGMT_SWAP_TYPE_TEST 1 #define IMG_MGMT_SWAP_TYPE_PERM 2 #define IMG_MGMT_SWAP_TYPE_REVERT 3 +#define IMG_MGMT_SWAP_TYPE_UNKNOWN 255 /** * Command IDs for image management group. diff --git a/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c b/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c index 80c3c4973c0..3d39a357426 100644 --- a/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c +++ b/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c @@ -511,8 +511,7 @@ img_mgmt_impl_swap_type(int slot) case BOOT_SWAP_TYPE_REVERT: return IMG_MGMT_SWAP_TYPE_REVERT; default: - assert(0); - return IMG_MGMT_SWAP_TYPE_NONE; + return IMG_MGMT_SWAP_TYPE_UNKNOWN; } }