forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
add_subdirectory(grp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
menu "Additional MCUmgr configuration" | ||
|
||
rsource "grp/Kconfig" | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
add_subdirectory_ifdef(CONFIG_MCUMGR_GRP_OS os_mgmt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
menu "Additional MCUmgr group configuration" | ||
|
||
rsource "os_mgmt/Kconfig" | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
if(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO_B0_ACTIVE_SLOT) | ||
zephyr_library_amend() | ||
zephyr_library_sources(src/os_mgmt_b0_active_slot.c) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
menu "Additional MCUmgr OS group management functionality" | ||
|
||
config MCUMGR_GRP_OS_BOOTLOADER_INFO_B0_ACTIVE_SLOT | ||
bool "Bootloader info query for active b0 slot" | ||
depends on MCUMGR_GRP_OS_BOOTLOADER_INFO | ||
depends on BOOTLOADER_MCUBOOT | ||
depends on MCUBOOT_MCUBOOT_IMAGE_NUMBER != -1 | ||
depends on FW_INFO | ||
depends on FW_INFO_API | ||
select MCUMGR_MGMT_NOTIFICATION_HOOKS | ||
select MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK | ||
help | ||
Enables a bootloader info command for `active_b0_slot` which will return the active b0 | ||
image slot number, and can be used to determine which update image should be loaded. | ||
|
||
endmenu |
71 changes: 71 additions & 0 deletions
71
subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt_b0_active_slot.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <zcbor_common.h> | ||
#include <zcbor_encode.h> | ||
#include <pm_config.h> | ||
#include <fw_info.h> | ||
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h> | ||
#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h> | ||
|
||
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) { | ||
const struct fw_info *s0_info = fw_info_find(PM_S0_ADDRESS); | ||
const struct fw_info *s1_info = fw_info_find(PM_S1_ADDRESS); | ||
|
||
if (s0_info || s1_info) { | ||
int active_slot; | ||
bool ok; | ||
|
||
if (!s1_info || (s0_info && s0_info->version >= s1_info->version)) { | ||
active_slot = 0; | ||
} else if (!s0_info || (s1_info && s1_info->version > s0_info->version)) { | ||
active_slot = 1; | ||
} | ||
|
||
ok = zcbor_tstr_put_lit(bootloader_info_data->zse, "active") && | ||
zcbor_int32_put(bootloader_info_data->zse, active_slot); | ||
*rc = (ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE); | ||
return MGMT_CB_ERROR_RC; | ||
} | ||
|
||
/* Return reponse not valid error when active slot cannot be determined */ | ||
*group = MGMT_GROUP_ID_OS; | ||
*rc = OS_MGMT_ERR_QUERY_RESPONSE_VALUE_NOT_VALID; | ||
return MGMT_CB_ERROR_ERR; | ||
} | ||
|
||
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 os_mgmt_register_bootloader_info_hook_b0_active_slot(void) | ||
{ | ||
mgmt_callback_register(&cmd_bootloader_info_cb); | ||
return 0; | ||
} | ||
|
||
SYS_INIT(os_mgmt_register_bootloader_info_hook_b0_active_slot, APPLICATION, 0); |