52
52
#include <dfu/pcd.h>
53
53
#endif
54
54
55
+ #if defined(CONFIG_FLASH_SIMULATOR )
56
+ #include <zephyr/drivers/flash/flash_simulator.h>
57
+ #endif
58
+
55
59
#ifdef MCUBOOT_ENC_IMAGES
56
60
#include "bootutil/enc_key.h"
57
61
#endif
@@ -936,7 +940,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
936
940
bool upgrade_valid = false;
937
941
938
942
#if defined(PM_S1_ADDRESS ) || defined(CONFIG_SOC_NRF5340_CPUAPP )
939
- const struct flash_area * secondary_fa =
943
+ const struct flash_area * fap_secondary_slot =
940
944
BOOT_IMG_AREA (state , BOOT_SECONDARY_SLOT );
941
945
struct image_header * hdr = boot_img_hdr (state , BOOT_SECONDARY_SLOT );
942
946
uint32_t reset_addr = 0 ;
@@ -950,7 +954,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
950
954
*/
951
955
952
956
if (hdr -> ih_magic == IMAGE_MAGIC ) {
953
- rc = flash_area_read (secondary_fa , hdr -> ih_hdr_size +
957
+ rc = flash_area_read (fap_secondary_slot , hdr -> ih_hdr_size +
954
958
sizeof (uint32_t ), & reset_addr ,
955
959
sizeof (reset_addr ));
956
960
if (rc != 0 ) {
@@ -1018,24 +1022,52 @@ boot_validated_swap_type(struct boot_loader_state *state,
1018
1022
* available
1019
1023
*/
1020
1024
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS ) {
1021
- struct image_header * hdr = ( struct image_header * ) secondary_fa -> fa_off ;
1025
+ uint32_t fw_size = hdr -> ih_img_size ;
1022
1026
uint32_t vtable_addr = (uint32_t )hdr + hdr -> ih_hdr_size ;
1023
1027
uint32_t * net_core_fw_addr = (uint32_t * )(vtable_addr );
1024
- uint32_t fw_size = hdr -> ih_img_size ;
1028
+ #if defined(CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY )
1029
+ size_t mock_size ;
1030
+ uint32_t * flash_sim_addr = flash_simulator_get_memory (NULL , & mock_size );
1031
+ /* Direct copy from flash to mocked flash in SRAM. */
1032
+ rc = flash_area_read (fap_secondary_slot , hdr -> ih_hdr_size , (void * )(flash_sim_addr ),
1033
+ fw_size );
1034
+ if (rc != 0 ) {
1035
+ BOOT_LOG_INF ("Error whilst copying image from Flash to SRAM(flash_sim): %d" ,
1036
+ rc );
1037
+ return BOOT_SWAP_TYPE_FAIL ;
1038
+ }
1039
+ net_core_fw_addr = flash_sim_addr ;
1040
+ #endif
1025
1041
BOOT_LOG_INF ("Starting network core update" );
1026
1042
rc = pcd_network_core_update (net_core_fw_addr , fw_size );
1027
1043
1028
1044
if (rc != 0 ) {
1029
1045
swap_type = BOOT_SWAP_TYPE_FAIL ;
1030
1046
} else {
1031
1047
BOOT_LOG_INF ("Done updating network core" );
1048
+
1032
1049
#if defined(MCUBOOT_SWAP_USING_SCRATCH ) || defined(MCUBOOT_SWAP_USING_MOVE )
1033
1050
/* swap_erase_trailer_sectors is undefined if upgrade only
1034
1051
* method is used. There is no need to erase sectors, because
1035
1052
* the image cannot be reverted.
1036
1053
*/
1037
- rc = swap_erase_trailer_sectors (state ,
1038
- secondary_fa );
1054
+ rc = swap_erase_trailer_sectors (state , fap_secondary_slot );
1055
+ if (rc != 0 ) {
1056
+ BOOT_LOG_DBG ("Unable to erase swap trailer info" );
1057
+ }
1058
+ #elif defined(MCUBOOT_OVERWRITE_ONLY )
1059
+ size_t last_sector = boot_img_num_sectors (state , BOOT_SECONDARY_SLOT ) - 1 ;
1060
+ rc = boot_erase_region (fap_secondary_slot ,
1061
+ boot_img_sector_off (state , BOOT_SECONDARY_SLOT ,
1062
+ last_sector ),
1063
+ boot_img_sector_size (state , BOOT_SECONDARY_SLOT ,
1064
+ last_sector ));
1065
+ if (rc != 0 ) {
1066
+ /* This will cause the network update to happen again
1067
+ * on the next reboot
1068
+ */
1069
+ BOOT_LOG_DBG ("Unable to erase trailer info" );
1070
+ }
1039
1071
#endif
1040
1072
swap_type = BOOT_SWAP_TYPE_NONE ;
1041
1073
}
0 commit comments