Skip to content

Commit 252d7bb

Browse files
jonathannilsencarlescufi
authored andcommitted
[nrf noup] boot: add support for loading PERIPHCONF
Add support required to load the application's global domain peripheral configuration (PERIPHCONF) from MCUboot after the initial PERIPHCONF loaded by IronSide before MCUboot was booted. When this feature is enabled, PERIPHCONF sections in each image will remain in the firmware binary, and the signing scripts generate custom TLV metadata which lets MCUboot know where the PERIPHCONF is located in the firmware. MCUboot then loads the parameters from the TLVs and asks IronSide SE to apply them. Since MCUboot/the Application core can lose access to the global peripherals happens after loading the new PERIPHCONF, the call is placed after MCUboot's peripheral deinitialization. The feature depends on a newly added IronSide SE API to work. The API is supported from IronSide SE v23.3.0+26. Signed-off-by: Jonathan Nilsen <jonathan.nilsen@nordicsemi.no>
1 parent 27b373b commit 252d7bb

7 files changed

Lines changed: 357 additions & 1 deletion

File tree

boot/bootutil/src/image_validate.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
6464
#endif
6565
#include "bootutil_priv.h"
6666

67+
#if defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
68+
#include <load_ironside_se_conf.h>
69+
#endif
70+
6771
/*
6872
* Currently, we only support being able to verify one type of
6973
* signature, because there is a single verification function that we
@@ -217,7 +221,8 @@ bootutil_img_validate(struct boot_loader_state *state,
217221
#if (defined(EXPECTED_KEY_TLV) && defined(MCUBOOT_HW_KEY)) || \
218222
(defined(EXPECTED_SIG_TLV) && defined(MCUBOOT_BUILTIN_KEY)) || \
219223
defined(MCUBOOT_HW_ROLLBACK_PROT) || defined(MCUBOOT_MANIFEST_UPDATES) || \
220-
defined(MCUBOOT_UUID_VID) || defined(MCUBOOT_UUID_CID) || defined(MCUBOOT_DECOMPRESS_IMAGES)
224+
defined(MCUBOOT_UUID_VID) || defined(MCUBOOT_UUID_CID) || defined(MCUBOOT_DECOMPRESS_IMAGES) ||\
225+
defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
221226
int image_index = (state == NULL ? 0 : BOOT_CURR_IMG(state));
222227
#endif
223228
uint32_t off;
@@ -266,6 +271,8 @@ bootutil_img_validate(struct boot_loader_state *state,
266271
#ifdef MCUBOOT_MANIFEST_UPDATES
267272
bool manifest_found = false;
268273
bool manifest_valid = false;
274+
#endif
275+
#if defined(MCUBOOT_MANIFEST_UPDATES) || defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
269276
uint8_t slot = (flash_area_get_id(fap) == FLASH_AREA_IMAGE_SECONDARY(image_index) ? 1 : 0);
270277
#endif
271278
#ifdef MCUBOOT_UUID_VID
@@ -735,6 +742,20 @@ bootutil_img_validate(struct boot_loader_state *state,
735742
uuid_cid_valid = fih_rc;
736743
break;
737744
}
745+
#endif
746+
#if defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
747+
default:
748+
{
749+
/* Validate custom/vendor TLVs. */
750+
rc = nrf_validate_custom_tlv_data(hdr, fap, boot_img_slot_off(state, slot),
751+
type, off, len);
752+
if (rc) {
753+
BOOT_LOG_ERR("Slot %d image %d has invalid custom TLV data, error %d",
754+
slot, image_index, rc);
755+
goto out;
756+
}
757+
break;
758+
}
738759
#endif
739760
}
740761
}

boot/bootutil/src/loader.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ int pcd_version_cmp_net(const struct flash_area *fap, struct image_header *hdr);
8484
#include "bootutil/key_revocation.h"
8585
#endif
8686

87+
#if defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
88+
#include <load_ironside_se_conf.h>
89+
#endif
90+
8791
#ifdef CONFIG_SOC_EARLY_RESET_HOOK
8892
void s2ram_designate_slot(uint8_t slot);
8993
#endif
@@ -2420,6 +2424,15 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
24202424
FIH_SET(fih_rc, FIH_FAILURE);
24212425
goto out;
24222426
}
2427+
2428+
#if defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
2429+
rc = nrf_add_custom_tlv_data(state, BOOT_SLOT_PRIMARY);
2430+
if (rc != 0) {
2431+
FIH_SET(fih_rc, FIH_FAILURE);
2432+
goto out;
2433+
}
2434+
#endif
2435+
24232436
++fih_cnt;
24242437
}
24252438
/*
@@ -2921,6 +2934,14 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
29212934
FIH_SET(fih_rc, FIH_FAILURE);
29222935
goto close;
29232936
}
2937+
2938+
#if defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
2939+
rc = nrf_add_custom_tlv_data(state, state->slot_usage[BOOT_CURR_IMG(state)].active_slot);
2940+
if (rc != 0) {
2941+
FIH_SET(fih_rc, FIH_FAILURE);
2942+
goto close;
2943+
}
2944+
#endif
29242945
}
29252946

29262947
#ifdef CONFIG_SOC_EARLY_RESET_HOOK

boot/bootutil/src/loader_manifest_xip.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
#include "bootutil/enc_key.h"
6161
#endif
6262

63+
#if defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
64+
#include <load_ironside_se_conf.h>
65+
#endif
66+
6367
BOOT_LOG_MODULE_DECLARE(mcuboot);
6468

6569
static struct boot_loader_state boot_data;
@@ -613,6 +617,15 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
613617
FIH_SET(fih_rc, FIH_FAILURE);
614618
goto close;
615619
}
620+
621+
#if defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
622+
rc = nrf_add_custom_tlv_data(state,
623+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot);
624+
if (rc != 0) {
625+
FIH_SET(fih_rc, FIH_FAILURE);
626+
goto close;
627+
}
628+
#endif
616629
}
617630

618631
/* All image loaded successfully. */

boot/zephyr/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,10 @@ zephyr_library_sources(
808808
)
809809
endif()
810810

811+
if(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
812+
zephyr_sources(${BOOT_DIR}/zephyr/load_ironside_se_conf.c)
813+
endif()
814+
811815
if(SYSBUILD AND CONFIG_PCD_APP)
812816
# Sysbuild requires details of the RAM flash device are stored to the cache of MCUboot so
813817
# that they can be read when running partition manager
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef H_LOAD_IRONSIDE_SE_CONF_
8+
#define H_LOAD_IRONSIDE_SE_CONF_
9+
10+
#include <stdint.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
struct boot_loader_state;
17+
struct image_header;
18+
struct flash_area;
19+
20+
/* Validate custom TLVs containing configuration metadata. */
21+
int nrf_validate_custom_tlv_data(const struct image_header *hdr, const struct flash_area *fap,
22+
uint32_t slot_off, uint16_t tlv_type, uint32_t tlv_off,
23+
uint16_t tlv_len);
24+
25+
/* Add parameters from custom TLVs containing configuration metadata
26+
* for the active slot. The parameters added here are loaded using the nrf_load_* functions.
27+
*/
28+
int nrf_add_custom_tlv_data(struct boot_loader_state *state, int slot);
29+
30+
/* Configure peripherals using parameters loaded from PERIPHCONF TLVs. */
31+
int nrf_load_periphconf(void);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif /* H_LOAD_IRONSIDE_SE_CONF_ */

0 commit comments

Comments
 (0)