@@ -131,6 +131,18 @@ img_mgmt_state_flags(int query_slot)
131131 int image = query_slot / 2 ; /* We support max 2 images for now */
132132 int active_slot = img_mgmt_active_slot (image );
133133
134+ #ifdef CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES
135+ /* If manifest-based updates are used, only the manifest image is considered. */
136+ image = CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER ;
137+ if (query_slot == active_slot ) {
138+ active_slot = img_mgmt_active_slot (image );
139+ query_slot = active_slot ;
140+ } else {
141+ active_slot = img_mgmt_active_slot (image );
142+ query_slot = img_mgmt_get_opposite_slot (active_slot );
143+ }
144+ #endif /* CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
145+
134146 /* In case when MCUboot is configured for FW loader/updater mode, slots
135147 * can be either active or non-active. There is no concept of pending
136148 * or confirmed slots.
@@ -223,9 +235,29 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
223235static int read_directxip_state (int slot )
224236{
225237 struct boot_swap_state bss ;
226- int fa_id = img_mgmt_flash_area_id ( slot ) ;
238+ int fa_id ;
227239 const struct flash_area * fa ;
228240 int rc = 0 ;
241+ #ifdef CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES
242+ int active_slot = img_mgmt_active_slot (slot / 2 );
243+ #endif /* CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
244+
245+ #ifdef CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES
246+ /* If manifest-based updates are used, only the manifest image is considered. */
247+ if (slot == active_slot ) {
248+ slot = img_mgmt_active_slot (CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER );
249+ } else {
250+ slot = img_mgmt_get_opposite_slot (img_mgmt_active_slot (
251+ CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER ));
252+ }
253+
254+ if (!boot_check_manifest (slot % 2 )) {
255+ LOG_ERR ("Failed to read manifest of slot %d with error %d" , slot , rc );
256+ return -1 ;
257+ }
258+ #endif /* CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
259+
260+ fa_id = img_mgmt_flash_area_id (slot );
229261
230262 __ASSERT (fa_id != -1 , "Could not map slot to area ID" );
231263
@@ -258,18 +290,22 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
258290{
259291 struct image_version aver ;
260292 struct image_version over ;
261- int active_slot = img_mgmt_active_slot (image );
262- int other_slot = img_mgmt_get_opposite_slot (active_slot );
263293#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT )
264294 int active_slot_state ;
265295 int other_slot_state ;
266296#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */
267297 enum img_mgmt_next_boot_type lt = NEXT_BOOT_TYPE_NORMAL ;
268- int return_slot = active_slot ;
269298
299+ #ifdef CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES
300+ /* If manifest-based updates are used, only the manifest image is considered. */
301+ image = CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER ;
302+ #endif /* CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
270303
304+ int active_slot = img_mgmt_active_slot (image );
305+ int other_slot = img_mgmt_get_opposite_slot (active_slot );
271306 int rcs = img_mgmt_read_info (other_slot , & over , NULL , NULL );
272307 int rca = img_mgmt_read_info (active_slot , & aver , NULL , NULL );
308+ int return_slot = active_slot ;
273309
274310#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT )
275311 active_slot_state = read_directxip_state (active_slot );
0 commit comments