Skip to content

Commit 42e43d0

Browse files
sigvartmhrlubos
authored andcommitted
[nrf noup] boot: nrf53-specific customizations
- Add network core bootloader implementation Enables network core updates of nrf53 using MCUBoot by identifying images through their start addresses. Also implements the control and transfer using the PCD module. - Add support for multi image DFU using partition manager. - Add check for netcore addr if NSIB is enabled so netcore updates works - boot: zephyr: move thingy53_nrf5340_cpuapp.conf downstream Moved the board configuration for Thingy:53 Application Core to the nRF Connect SDK MCUboot downstream repository. The configuration file contains references to the Kconfig modules that are only available in the nRF Connect SDK. The current configuration is set up to work in the nRF Connect SDK environment and cannot be used upstream. - pm: enable ram flash partition using common flag This patch makes mcuboot_primary_1 ram-flash partition selectable using CONFIG_NRF53_MCUBOOT_PRIMARY_1_RAM_FLASH property. This is needed since CONFIG_NRF53_MULTI_IMAGE_UPDATE become not only configuration which requires that partition. - MCUBoot configures USB CDC by its own. There is no need for BOARD_SERIAL_BACKEND_CDC_ACM option to configure anything which is later overwritten anyway. Jira: NCSDK-18596 Signed-off-by: Andrzej Puzdrowski <[email protected]> Signed-off-by: Emil Obalski <[email protected]> Signed-off-by: Håkon Øye Amundsen <[email protected]> Signed-off-by: Ioannis Glaropoulos <[email protected]> Signed-off-by: Jamie McCrae <[email protected]> Signed-off-by: Johann Fischer <[email protected]> Signed-off-by: Kamil Piszczek <[email protected]> Signed-off-by: Ole Sæther <[email protected]> Signed-off-by: Sigvart Hovland <[email protected]> Signed-off-by: Simon Iversen <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Trond Einar Snekvik <[email protected]> Signed-off-by: Mateusz Kapala <[email protected]> Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 2bbd3b1) (cherry picked from commit 0098451) (cherry picked from commit 2009587) Signed-off-by: Robert Lubos <[email protected]>
1 parent 518617a commit 42e43d0

File tree

5 files changed

+186
-26
lines changed

5 files changed

+186
-26
lines changed

boot/bootutil/src/loader.c

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
#include "bootutil/boot_hooks.h"
5050
#include "bootutil/mcuboot_status.h"
5151

52+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
53+
#include <dfu/pcd.h>
54+
#endif
55+
5256
#ifdef MCUBOOT_ENC_IMAGES
5357
#include "bootutil/enc_key.h"
5458
#endif
@@ -935,42 +939,52 @@ boot_validated_swap_type(struct boot_loader_state *state,
935939
{
936940
int swap_type;
937941
FIH_DECLARE(fih_rc, FIH_FAILURE);
938-
#ifdef PM_S1_ADDRESS
942+
bool upgrade_valid = false;
943+
944+
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
945+
const struct flash_area *secondary_fa =
946+
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
947+
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
948+
uint32_t vtable_addr = 0;
949+
uint32_t *vtable = 0;
950+
uint32_t reset_addr = 0;
939951
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
940952
* B1 slot S0 or S1) share the same secondary slot, we need to check
941953
* whether the update candidate in the secondary slot is intended for
942954
* image 0 or image 1 primary by looking at the address of the reset
943955
* vector. Note that there are good reasons for not using img_num from
944956
* the swap info.
945957
*/
946-
const struct flash_area *secondary_fa =
947-
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
948-
struct image_header *hdr =
949-
(struct image_header *)secondary_fa->fa_off;
950958

951959
if (hdr->ih_magic == IMAGE_MAGIC) {
952-
const struct flash_area *primary_fa;
953-
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
954-
uint32_t *vtable = (uint32_t *)(vtable_addr);
955-
uint32_t reset_addr = vtable[1];
956-
int rc = flash_area_open(
957-
flash_area_id_from_multi_image_slot(
958-
BOOT_CURR_IMG(state),
959-
BOOT_PRIMARY_SLOT),
960-
&primary_fa);
961-
962-
if (rc != 0) {
963-
return BOOT_SWAP_TYPE_FAIL;
964-
}
965-
/* Get start and end of primary slot for current image */
966-
if (reset_addr < primary_fa->fa_off ||
967-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
968-
/* The image in the secondary slot is not intended for this image
969-
*/
970-
return BOOT_SWAP_TYPE_NONE;
971-
}
972-
}
960+
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
961+
vtable = (uint32_t *)(vtable_addr);
962+
reset_addr = vtable[1];
963+
#ifdef PM_S1_ADDRESS
964+
#ifdef PM_CPUNET_B0N_ADDRESS
965+
if(reset_addr < PM_CPUNET_B0N_ADDRESS)
973966
#endif
967+
{
968+
const struct flash_area *primary_fa;
969+
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
970+
BOOT_CURR_IMG(state),
971+
BOOT_PRIMARY_SLOT),
972+
&primary_fa);
973+
974+
if (rc != 0) {
975+
return BOOT_SWAP_TYPE_FAIL;
976+
}
977+
/* Get start and end of primary slot for current image */
978+
if (reset_addr < primary_fa->fa_off ||
979+
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
980+
/* The image in the secondary slot is not intended for this image
981+
*/
982+
return BOOT_SWAP_TYPE_NONE;
983+
}
984+
}
985+
#endif /* PM_S1_ADDRESS */
986+
}
987+
#endif /* PM_S1_ADDRESS || CONFIG_SOC_NRF5340_CPUAPP */
974988

975989
swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
976990
if (BOOT_IS_UPGRADE(swap_type)) {
@@ -984,7 +998,37 @@ boot_validated_swap_type(struct boot_loader_state *state,
984998
} else {
985999
swap_type = BOOT_SWAP_TYPE_FAIL;
9861000
}
1001+
} else {
1002+
upgrade_valid = true;
1003+
}
1004+
1005+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
1006+
/* If the update is valid, and it targets the network core: perform the
1007+
* update and indicate to the caller of this function that no update is
1008+
* available
1009+
*/
1010+
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
1011+
uint32_t fw_size = hdr->ih_img_size;
1012+
1013+
BOOT_LOG_INF("Starting network core update");
1014+
int rc = pcd_network_core_update(vtable, fw_size);
1015+
1016+
if (rc != 0) {
1017+
swap_type = BOOT_SWAP_TYPE_FAIL;
1018+
} else {
1019+
BOOT_LOG_INF("Done updating network core");
1020+
#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_MOVE)
1021+
/* swap_erase_trailer_sectors is undefined if upgrade only
1022+
* method is used. There is no need to erase sectors, because
1023+
* the image cannot be reverted.
1024+
*/
1025+
rc = swap_erase_trailer_sectors(state,
1026+
secondary_fa);
1027+
#endif
1028+
swap_type = BOOT_SWAP_TYPE_NONE;
1029+
}
9871030
}
1031+
#endif /* CONFIG_SOC_NRF5340_CPUAPP */
9881032
}
9891033

9901034
return swap_type;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
CONFIG_SIZE_OPTIMIZATIONS=y
2+
3+
CONFIG_SYSTEM_CLOCK_NO_WAIT=y
4+
CONFIG_PM=n
5+
6+
CONFIG_MAIN_STACK_SIZE=10240
7+
CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"
8+
9+
CONFIG_BOOT_MAX_IMG_SECTORS=2048
10+
CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
11+
12+
# Flash
13+
CONFIG_FLASH=y
14+
CONFIG_BOOT_ERASE_PROGRESSIVELY=y
15+
CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y
16+
CONFIG_FPROTECT=y
17+
18+
# Serial
19+
CONFIG_SERIAL=y
20+
CONFIG_UART_LINE_CTRL=y
21+
22+
# MCUBoot serial
23+
CONFIG_GPIO=y
24+
CONFIG_MCUBOOT_SERIAL=y
25+
CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y
26+
CONFIG_BOOT_SERIAL_CDC_ACM=y
27+
28+
# Required by QSPI
29+
CONFIG_NORDIC_QSPI_NOR=y
30+
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
31+
CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16
32+
33+
# Required by USB and QSPI
34+
CONFIG_MULTITHREADING=y
35+
36+
# USB
37+
CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n
38+
CONFIG_USB_DEVICE_REMOTE_WAKEUP=n
39+
CONFIG_USB_DEVICE_MANUFACTURER="Nordic Semiconductor ASA"
40+
CONFIG_USB_DEVICE_PRODUCT="Bootloader Thingy:53"
41+
CONFIG_USB_DEVICE_VID=0x1915
42+
CONFIG_USB_DEVICE_PID=0x5300
43+
CONFIG_USB_CDC_ACM=y
44+
45+
# Decrease memory footprint
46+
CONFIG_CBPRINTF_NANO=y
47+
CONFIG_TIMESLICING=n
48+
CONFIG_BOOT_BANNER=n
49+
CONFIG_CONSOLE=n
50+
CONFIG_CONSOLE_HANDLER=n
51+
CONFIG_UART_CONSOLE=n
52+
CONFIG_USE_SEGGER_RTT=n
53+
CONFIG_LOG=n
54+
CONFIG_ERRNO=n
55+
CONFIG_PRINTK=n
56+
CONFIG_RESET_ON_FATAL_ERROR=n
57+
CONFIG_SPI=n
58+
CONFIG_I2C=n
59+
CONFIG_UART_NRFX=n
60+
61+
# The following configurations are required to support simultaneous multi image update
62+
CONFIG_PCD_APP=y
63+
CONFIG_UPDATEABLE_IMAGE_NUMBER=2
64+
CONFIG_BOOT_UPGRADE_ONLY=y
65+
# The network core cannot access external flash directly. The flash simulator must be used to
66+
# provide a memory region that is used to forward the new firmware to the network core.
67+
CONFIG_FLASH_SIMULATOR=y
68+
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
69+
CONFIG_FLASH_SIMULATOR_STATS=n
70+
71+
# Enable custom command to erase settings partition.
72+
CONFIG_ENABLE_MGMT_PERUSER=y
73+
CONFIG_BOOT_MGMT_CUSTOM_STORAGE_ERASE=y

boot/zephyr/include/sysflash/sysflash.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
#elif (MCUBOOT_IMAGE_NUMBER == 2)
2222

23+
/* If B0 is present then two bootloaders are present, and we must use
24+
* a single secondary slot for both primary slots.
25+
*/
26+
#ifdef PM_B0_ADDRESS
27+
2328
extern uint32_t _image_1_primary_slot_id[];
2429

2530
#define FLASH_AREA_IMAGE_PRIMARY(x) \
@@ -35,6 +40,24 @@ extern uint32_t _image_1_primary_slot_id[];
3540
(x == 1) ? \
3641
PM_MCUBOOT_SECONDARY_ID: \
3742
255 )
43+
#else
44+
45+
#define FLASH_AREA_IMAGE_PRIMARY(x) \
46+
((x == 0) ? \
47+
PM_MCUBOOT_PRIMARY_ID : \
48+
(x == 1) ? \
49+
PM_MCUBOOT_PRIMARY_1_ID : \
50+
255 )
51+
52+
#define FLASH_AREA_IMAGE_SECONDARY(x) \
53+
((x == 0) ? \
54+
PM_MCUBOOT_SECONDARY_ID: \
55+
(x == 1) ? \
56+
PM_MCUBOOT_SECONDARY_1_ID: \
57+
255 )
58+
59+
#endif /* PM_B0_ADDRESS */
60+
3861
#endif
3962
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
4063

boot/zephyr/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ const struct boot_uart_funcs boot_funcs = {
8787
#include <arm_cleanup.h>
8888
#endif
8989

90+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
91+
#include <dfu/pcd.h>
92+
#endif
93+
9094
/* CONFIG_LOG_MINIMAL is the legacy Kconfig property,
9195
* replaced by CONFIG_LOG_MODE_MINIMAL.
9296
*/
@@ -571,6 +575,9 @@ int main(void)
571575
;
572576
}
573577

578+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS) && defined(CONFIG_PCD_APP)
579+
pcd_lock_ram();
580+
#endif
574581
#endif /* USE_PARTITION_MANAGER && CONFIG_FPROTECT */
575582

576583
ZEPHYR_BOOT_LOG_STOP();

boot/zephyr/pm.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ mcuboot_pad:
7272
#ifdef CONFIG_FPROTECT
7373
align: {start: CONFIG_FPROTECT_BLOCK_SIZE}
7474
#endif
75+
76+
#if (CONFIG_NRF53_MCUBOOT_PRIMARY_1_RAM_FLASH)
77+
mcuboot_primary_1:
78+
region: ram_flash
79+
size: CONFIG_NRF53_RAM_FLASH_SIZE
80+
#endif /* CONFIG_NRF53_MULTI_IMAGE_UPDATE */
81+
82+
#if (CONFIG_NRF53_MULTI_IMAGE_UPDATE)
83+
mcuboot_secondary_1:
84+
region: external_flash
85+
size: CONFIG_NRF53_RAM_FLASH_SIZE
86+
87+
#endif /* CONFIG_NRF53_MULTI_IMAGE_UPDATE */

0 commit comments

Comments
 (0)