diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index 80023be74eea..5d8138ee3407 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -77,3 +77,4 @@ add_subdirectory(suit) add_subdirectory_ifdef(CONFIG_MGMT_SUITFU mgmt/suitfu) add_subdirectory_ifdef(CONFIG_DULT dult) add_subdirectory_ifdef(CONFIG_NRF_COMPRESS nrf_compress) +add_subdirectory_ifdef(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO_B0_ACTIVE_SLOT mgmt/b0_active_slot) diff --git a/subsys/Kconfig b/subsys/Kconfig index 37be60487f97..59bb3ca5bdbb 100644 --- a/subsys/Kconfig +++ b/subsys/Kconfig @@ -28,6 +28,7 @@ rsource "nrf_rpc/Kconfig" rsource "zigbee/Kconfig" rsource "mgmt/fmfu/Kconfig" rsource "mgmt/suitfu/Kconfig" +rsource "mgmt/b0_active_slot/Kconfig" rsource "caf/Kconfig" rsource "ieee802154/Kconfig" rsource "dm/Kconfig" diff --git a/subsys/mgmt/b0_active_slot/CMakeLists.txt b/subsys/mgmt/b0_active_slot/CMakeLists.txt new file mode 100644 index 000000000000..0c2bdc791326 --- /dev/null +++ b/subsys/mgmt/b0_active_slot/CMakeLists.txt @@ -0,0 +1,8 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +zephyr_library() +zephyr_library_sources(src/suitfu_mgmt_suit_os.c) diff --git a/subsys/mgmt/b0_active_slot/Kconfig b/subsys/mgmt/b0_active_slot/Kconfig new file mode 100644 index 000000000000..c242158cc463 --- /dev/null +++ b/subsys/mgmt/b0_active_slot/Kconfig @@ -0,0 +1,15 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +menuconfig MCUMGR_GRP_OS_BOOTLOADER_INFO_B0_ACTIVE_SLOT + bool "b0 active slot" + depends on MCUMGR_GRP_OS_BOOTLOADER_INFO + depends on BOOTLOADER_MCUBOOT + depends on MCUBOOT_MCUBOOT_IMAGE_NUMBER != -1 + select MCUMGR_MGMT_NOTIFICATION_HOOKS + select MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK + help + todo diff --git a/subsys/mgmt/b0_active_slot/src/suitfu_mgmt_suit_os.c b/subsys/mgmt/b0_active_slot/src/suitfu_mgmt_suit_os.c new file mode 100644 index 000000000000..3e4034425c38 --- /dev/null +++ b/subsys/mgmt/b0_active_slot/src/suitfu_mgmt_suit_os.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include +#include +#include + +static enum mgmt_cb_return bootloader_info_hook(uint32_t event, enum mgmt_cb_return prev_status, + int32_t *rc, uint16_t *group, bool *abort_more, + void *data, size_t data_size) +{ + struct os_mgmt_bootloader_info_data *bootloader_info_data = (struct os_mgmt_bootloader_info_data *)data; + + if (event != MGMT_EVT_OP_OS_MGMT_BOOTLOADER_INFO + || data_size != sizeof(*bootloader_info_data)) { + *rc = MGMT_ERR_EUNKNOWN; + return MGMT_CB_ERROR_RC; + } + + /* If no parameter is recognized then just introduce the bootloader. */ + if (*(bootloader_info_data->decoded) >= 1 && (sizeof("active_b0_slot") - 1) == bootloader_info_data->query->len && memcmp("active_b0_slot", bootloader_info_data->query->value, bootloader_info_data->query->len) == 0) { + bool ok = zcbor_tstr_put_lit(bootloader_info_data->zse, "active"); +#if 1 +const struct fw_info *s0_info = fw_info_find(PM_S0_ADDRESS); +const struct fw_info *s1_info = fw_info_find(PM_S1_ADDRESS); + +printk("gots %p, %p, %d, %d\n", s0_info, s1_info, s0_info->version, s1_info->version); + +if (!s1_info || (s0_info && s0_info->version >= s1_info->version)) { + ok &= zcbor_tstr_put_lit(bootloader_info_data->zse, "s0"); +//s0 +} else { + ok &= zcbor_tstr_put_lit(bootloader_info_data->zse, "s1"); +//s1 +} +#endif + + *rc = (ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE); + return MGMT_CB_ERROR_RC; + } + + return MGMT_CB_OK; +} + +static struct mgmt_callback cmd_bootloader_info_cb = { + .callback = bootloader_info_hook, + .event_id = MGMT_EVT_OP_OS_MGMT_BOOTLOADER_INFO, +}; + +static int suitfu_mgmt_register_bootloader_info_hook(void) +{ + mgmt_callback_register(&cmd_bootloader_info_cb); + return 0; +} + +SYS_INIT(suitfu_mgmt_register_bootloader_info_hook, APPLICATION, 0); diff --git a/sysbuild/CMakeLists.txt b/sysbuild/CMakeLists.txt index 2763eeddf753..051adb7d8656 100644 --- a/sysbuild/CMakeLists.txt +++ b/sysbuild/CMakeLists.txt @@ -399,6 +399,7 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake) set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG "CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER=${SB_CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER}\n") set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG "CONFIG_MCUBOOT_WIFI_PATCHES_IMAGE_NUMBER=${SB_CONFIG_MCUBOOT_WIFI_PATCHES_IMAGE_NUMBER}\n") set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG "CONFIG_MCUBOOT_QSPI_XIP_IMAGE_NUMBER=${SB_CONFIG_MCUBOOT_QSPI_XIP_IMAGE_NUMBER}\n") + set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG "CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER=${SB_CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER}\n") endif() if(SB_CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION)