Skip to content

Commit adbf47e

Browse files
de-nordicjfischer-no
authored andcommitted
[nrf noup] mgmt/mcumgr: Bootutil hooks to handle image-1
The commit adds bootutil hook, for nrf5340, to allow it handling the non-accessible image-1/primary slot. Signed-off-by: Andrzej Głąbek <[email protected]> Signed-off-by: Vinayak Kariappa Chettimada <[email protected]> Signed-off-by: Johann Fischer <[email protected]> Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 041e804)
1 parent a7e1fd6 commit adbf47e

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

subsys/mgmt/mcumgr/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ add_subdirectory(transport)
1616
add_subdirectory_ifdef(CONFIG_SMP_CLIENT smp_client)
1717

1818
zephyr_library_link_libraries(mgmt_mcumgr)
19+
20+
if (CONFIG_BOOT_IMAGE_ACCESS_HOOKS)
21+
zephyr_include_directories(
22+
${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/bootutil/include
23+
${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/zephyr/include
24+
)
25+
zephyr_library_sources(bootutil_hooks/nrf53_hooks.c)
26+
endif()

subsys/mgmt/mcumgr/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ menuconfig MCUMGR
66
bool "mcumgr Support"
77
depends on NET_BUF
88
depends on ZCBOR
9+
imply BOOT_IMAGE_ACCESS_HOOKS if (SOC_NRF5340_CPUAPP_QKAA && MCUMGR_GRP_IMG)
910
help
1011
This option enables the mcumgr management library.
1112

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/device.h>
9+
#include "bootutil/bootutil_public.h"
10+
11+
int boot_read_swap_state_primary_slot_hook(int image_index,
12+
struct boot_swap_state *state)
13+
{
14+
if (image_index == 1) {
15+
/* Pretend that primary slot of image 1 unpopulated */
16+
state->magic = BOOT_MAGIC_UNSET;
17+
state->swap_type = BOOT_SWAP_TYPE_NONE;
18+
state->image_num = image_index;
19+
state->copy_done = BOOT_FLAG_UNSET;
20+
state->image_ok = BOOT_FLAG_UNSET;
21+
22+
/* Prevent bootutil from trying to obtain true info */
23+
return 0;
24+
}
25+
26+
return BOOT_HOOK_REGULAR;
27+
}

0 commit comments

Comments
 (0)