Skip to content

Commit 56934f9

Browse files
sigvartmhbjarki-andreasen
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 42e43d0)
1 parent 6facec9 commit 56934f9

File tree

5 files changed

+185
-28
lines changed

5 files changed

+185
-28
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
@@ -1217,42 +1221,52 @@ boot_validated_swap_type(struct boot_loader_state *state,
12171221
{
12181222
int swap_type;
12191223
FIH_DECLARE(fih_rc, FIH_FAILURE);
1220-
#ifdef PM_S1_ADDRESS
1224+
bool upgrade_valid = false;
1225+
1226+
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
1227+
const struct flash_area *secondary_fa =
1228+
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
1229+
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
1230+
uint32_t vtable_addr = 0;
1231+
uint32_t *vtable = 0;
1232+
uint32_t reset_addr = 0;
12211233
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
12221234
* B1 slot S0 or S1) share the same secondary slot, we need to check
12231235
* whether the update candidate in the secondary slot is intended for
12241236
* image 0 or image 1 primary by looking at the address of the reset
12251237
* vector. Note that there are good reasons for not using img_num from
12261238
* the swap info.
12271239
*/
1228-
const struct flash_area *secondary_fa =
1229-
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
1230-
struct image_header *hdr =
1231-
(struct image_header *)secondary_fa->fa_off;
12321240

12331241
if (hdr->ih_magic == IMAGE_MAGIC) {
1234-
const struct flash_area *primary_fa;
1235-
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
1236-
uint32_t *vtable = (uint32_t *)(vtable_addr);
1237-
uint32_t reset_addr = vtable[1];
1238-
int rc = flash_area_open(
1239-
flash_area_id_from_multi_image_slot(
1240-
BOOT_CURR_IMG(state),
1241-
BOOT_PRIMARY_SLOT),
1242-
&primary_fa);
1243-
1244-
if (rc != 0) {
1245-
return BOOT_SWAP_TYPE_FAIL;
1246-
}
1247-
/* Get start and end of primary slot for current image */
1248-
if (reset_addr < primary_fa->fa_off ||
1249-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
1250-
/* The image in the secondary slot is not intended for this image
1251-
*/
1252-
return BOOT_SWAP_TYPE_NONE;
1253-
}
1254-
}
1242+
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
1243+
vtable = (uint32_t *)(vtable_addr);
1244+
reset_addr = vtable[1];
1245+
#ifdef PM_S1_ADDRESS
1246+
#ifdef PM_CPUNET_B0N_ADDRESS
1247+
if(reset_addr < PM_CPUNET_B0N_ADDRESS)
12551248
#endif
1249+
{
1250+
const struct flash_area *primary_fa;
1251+
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
1252+
BOOT_CURR_IMG(state),
1253+
BOOT_PRIMARY_SLOT),
1254+
&primary_fa);
1255+
1256+
if (rc != 0) {
1257+
return BOOT_SWAP_TYPE_FAIL;
1258+
}
1259+
/* Get start and end of primary slot for current image */
1260+
if (reset_addr < primary_fa->fa_off ||
1261+
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
1262+
/* The image in the secondary slot is not intended for this image
1263+
*/
1264+
return BOOT_SWAP_TYPE_NONE;
1265+
}
1266+
}
1267+
#endif /* PM_S1_ADDRESS */
1268+
}
1269+
#endif /* PM_S1_ADDRESS || CONFIG_SOC_NRF5340_CPUAPP */
12561270

12571271
swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
12581272
if (BOOT_IS_UPGRADE(swap_type)) {
@@ -1266,7 +1280,37 @@ boot_validated_swap_type(struct boot_loader_state *state,
12661280
} else {
12671281
swap_type = BOOT_SWAP_TYPE_FAIL;
12681282
}
1283+
} else {
1284+
upgrade_valid = true;
1285+
}
1286+
1287+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
1288+
/* If the update is valid, and it targets the network core: perform the
1289+
* update and indicate to the caller of this function that no update is
1290+
* available
1291+
*/
1292+
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
1293+
uint32_t fw_size = hdr->ih_img_size;
1294+
1295+
BOOT_LOG_INF("Starting network core update");
1296+
int rc = pcd_network_core_update(vtable, fw_size);
1297+
1298+
if (rc != 0) {
1299+
swap_type = BOOT_SWAP_TYPE_FAIL;
1300+
} else {
1301+
BOOT_LOG_INF("Done updating network core");
1302+
#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_MOVE)
1303+
/* swap_erase_trailer_sectors is undefined if upgrade only
1304+
* method is used. There is no need to erase sectors, because
1305+
* the image cannot be reverted.
1306+
*/
1307+
rc = swap_erase_trailer_sectors(state,
1308+
secondary_fa);
1309+
#endif
1310+
swap_type = BOOT_SWAP_TYPE_NONE;
1311+
}
12691312
}
1313+
#endif /* CONFIG_SOC_NRF5340_CPUAPP */
12701314
}
12711315

12721316
return swap_type;
Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1-
CONFIG_NORDIC_QSPI_NOR=n
2-
CONFIG_SPI=n
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
334
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
@@ -91,6 +91,10 @@ const struct boot_uart_funcs boot_funcs = {
9191
#include <arm_cleanup.h>
9292
#endif
9393

94+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
95+
#include <dfu/pcd.h>
96+
#endif
97+
9498
/* CONFIG_LOG_MINIMAL is the legacy Kconfig property,
9599
* replaced by CONFIG_LOG_MODE_MINIMAL.
96100
*/
@@ -594,6 +598,9 @@ int main(void)
594598
;
595599
}
596600

601+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS) && defined(CONFIG_PCD_APP)
602+
pcd_lock_ram();
603+
#endif
597604
#endif /* USE_PARTITION_MANAGER && CONFIG_FPROTECT */
598605

599606
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)