Skip to content

Commit c82a8ab

Browse files
committed
mcuboot: nrf53_hooks: Update network core from hook
Moved network_core_update() from loader.c to here. In this way, we support network core update from different secondary slot locations: external secondary slot, internal secondary slot and external secondary slot 1 and internal secondary slot 1. Signed-off-by: Kevin Ai <[email protected]>
1 parent 2b33158 commit c82a8ab

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

modules/mcuboot/hooks/nrf53_hooks.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@
1515

1616
#define NET_CORE_SECONDARY_SLOT 1
1717
#define NET_CORE_VIRTUAL_PRIMARY_SLOT 3
18+
#define NRF5340_CPUNET_FLASH_SIZE 0x40000
1819

1920
#include <dfu/pcd.h>
2021

22+
#ifndef CONFIG_FLASH_SIMULATOR
23+
static uint8_t mock_flash[NRF5340_CPUNET_FLASH_SIZE];
24+
#endif
25+
int network_core_update(bool wait);
26+
2127
int boot_read_image_header_hook(int img_index, int slot,
2228
struct image_header *img_head)
2329
{
30+
31+
#ifdef PM_MCUBOOT_PRIMARY_1_ADDRESS
2432
if (img_index == 1 && slot == 0) {
2533
img_head->ih_magic = IMAGE_MAGIC;
2634
img_head->ih_hdr_size = PM_MCUBOOT_PAD_SIZE;
@@ -34,6 +42,7 @@ int boot_read_image_header_hook(int img_index, int slot,
3442
img_head->_pad1 = 0;
3543
return 0;
3644
}
45+
#endif
3746

3847
return BOOT_HOOK_REGULAR;
3948
}
@@ -50,6 +59,33 @@ fih_int boot_image_check_hook(int img_index, int slot)
5059
int boot_perform_update_hook(int img_index, struct image_header *img_head,
5160
const struct flash_area *area)
5261
{
62+
63+
#ifndef CONFIG_FLASH_SIMULATOR
64+
uint32_t reset_addr = 0;
65+
int32_t rc;
66+
67+
rc = flash_area_read(area, img_head->ih_hdr_size + 4, &reset_addr, 4);
68+
69+
if (reset_addr > PM_CPUNET_B0N_ADDRESS) {
70+
if (img_head->ih_hdr_size + img_head->ih_img_size > NRF5340_CPUNET_FLASH_SIZE) {
71+
return 1;
72+
}
73+
rc = flash_area_read(area, 0, (uint8_t *)mock_flash,
74+
img_head->ih_hdr_size + img_head->ih_img_size);
75+
if (rc == 0) {
76+
struct flash_sector fs[CONFIG_BOOT_MAX_IMG_SECTORS];
77+
uint32_t count = CONFIG_BOOT_MAX_IMG_SECTORS;
78+
79+
rc = network_core_update(true);
80+
81+
//erase the trailer of secondary slot
82+
flash_area_get_sectors(area->fa_id, &count, fs);
83+
flash_area_erase(area, area->fa_size - fs[0].fs_size, fs[0].fs_size);
84+
}
85+
return rc;
86+
}
87+
#endif
88+
5389
return BOOT_HOOK_REGULAR;
5490
}
5591

@@ -76,7 +112,9 @@ int boot_read_swap_state_primary_slot_hook(int image_index,
76112

77113
int network_core_update(bool wait)
78114
{
115+
79116
struct image_header *hdr;
117+
#ifdef CONFIG_FLASH_SIMULATOR
80118
static const struct device *mock_flash_dev;
81119
void *mock_flash;
82120
size_t mock_size;
@@ -87,7 +125,9 @@ int network_core_update(bool wait)
87125
}
88126

89127
mock_flash = flash_simulator_get_memory(NULL, &mock_size);
90-
hdr = (struct image_header *) mock_flash;
128+
#endif
129+
130+
hdr = (struct image_header *)mock_flash;
91131
if (hdr->ih_magic == IMAGE_MAGIC) {
92132
uint32_t fw_size = hdr->ih_img_size;
93133
uint32_t vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
@@ -110,9 +150,12 @@ int network_core_update(bool wait)
110150
int boot_copy_region_post_hook(int img_index, const struct flash_area *area,
111151
size_t size)
112152
{
153+
154+
#ifdef CONFIG_FLASH_SIMULATOR
113155
if (img_index == NET_CORE_SECONDARY_SLOT) {
114156
return network_core_update(true);
115157
}
158+
#endif
116159

117160
return 0;
118161
}

0 commit comments

Comments
 (0)