4545#include "bootutil/boot_record.h"
4646#include "bootutil/fault_injection_hardening.h"
4747
48- #ifdef CONFIG_SOC_NRF5340_CPUAPP
49- #include <dfu/pcd.h>
50- #endif
51-
5248#ifdef MCUBOOT_ENC_IMAGES
5349#include "bootutil/enc_key.h"
5450#endif
@@ -728,47 +724,42 @@ boot_validated_swap_type(struct boot_loader_state *state,
728724{
729725 int swap_type ;
730726 fih_int fih_rc = FIH_FAILURE ;
731- bool upgrade_valid = false;
732-
733- #if defined(PM_S1_ADDRESS ) || defined(CONFIG_SOC_NRF5340_CPUAPP )
734- const struct flash_area * secondary_fa =
735- BOOT_IMG_AREA (state , BOOT_SECONDARY_SLOT );
736- struct image_header * hdr = (struct image_header * )secondary_fa -> fa_off ;
737- uint32_t vtable_addr = 0 ;
738- uint32_t * vtable = 0 ;
739- uint32_t reset_addr = 0 ;
727+ #ifdef PM_S1_ADDRESS
740728 /* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
741729 * B1 slot S0 or S1) share the same secondary slot, we need to check
742730 * whether the update candidate in the secondary slot is intended for
743731 * image 0 or image 1 primary by looking at the address of the reset
744732 * vector. Note that there are good reasons for not using img_num from
745733 * the swap info.
746734 */
735+ const struct flash_area * secondary_fa =
736+ BOOT_IMG_AREA (state , BOOT_SECONDARY_SLOT );
737+ struct image_header * hdr =
738+ (struct image_header * )secondary_fa -> fa_off ;
747739
748740 if (hdr -> ih_magic == IMAGE_MAGIC ) {
749- vtable_addr = (uint32_t )hdr + hdr -> ih_hdr_size ;
750- vtable = (uint32_t * )(vtable_addr );
751- reset_addr = vtable [1 ];
752- #ifdef PM_S1_ADDRESS
753- const struct flash_area * primary_fa ;
754- int rc = flash_area_open (flash_area_id_from_multi_image_slot (
755- BOOT_CURR_IMG (state ),
756- BOOT_PRIMARY_SLOT ),
757- & primary_fa );
758-
759- if (rc != 0 ) {
760- return BOOT_SWAP_TYPE_FAIL ;
761- }
762- /* Get start and end of primary slot for current image */
763- if (reset_addr < primary_fa -> fa_off ||
764- reset_addr > (primary_fa -> fa_off + primary_fa -> fa_size )) {
765- /* The image in the secondary slot is not intended for this image
766- */
767- return BOOT_SWAP_TYPE_NONE ;
768- }
769- #endif /* PM_S1_ADDRESS */
741+ const struct flash_area * primary_fa ;
742+ uint32_t vtable_addr = (uint32_t )hdr + hdr -> ih_hdr_size ;
743+ uint32_t * vtable = (uint32_t * )(vtable_addr );
744+ uint32_t reset_addr = vtable [1 ];
745+ int rc = flash_area_open (
746+ flash_area_id_from_multi_image_slot (
747+ BOOT_CURR_IMG (state ),
748+ BOOT_PRIMARY_SLOT ),
749+ & primary_fa );
750+
751+ if (rc != 0 ) {
752+ return BOOT_SWAP_TYPE_FAIL ;
753+ }
754+ /* Get start and end of primary slot for current image */
755+ if (reset_addr < primary_fa -> fa_off ||
756+ reset_addr > (primary_fa -> fa_off + primary_fa -> fa_size )) {
757+ /* The image in the secondary slot is not intended for this image
758+ */
759+ return BOOT_SWAP_TYPE_NONE ;
760+ }
770761 }
771- #endif /* PM_S1_ADDRESS || CONFIG_SOC_NRF5340_CPUAPP */
762+ #endif
772763
773764 swap_type = boot_swap_type_multi (BOOT_CURR_IMG (state ));
774765 if (BOOT_IS_UPGRADE (swap_type )) {
@@ -782,31 +773,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
782773 } else {
783774 swap_type = BOOT_SWAP_TYPE_FAIL ;
784775 }
785- } else {
786- upgrade_valid = true;
787- }
788-
789- #if defined(CONFIG_SOC_NRF5340_CPUAPP ) && defined(PM_CPUNET_B0N_ADDRESS )
790- /* If the update is valid, and it targets the network core: perform the
791- * update and indicate to the caller of this function that no update is
792- * available
793- */
794- if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS ) {
795- uint32_t fw_size = hdr -> ih_img_size ;
796-
797- BOOT_LOG_INF ("Starting network core update" );
798- int rc = pcd_network_core_update (vtable , fw_size );
799-
800- if (rc != 0 ) {
801- swap_type = BOOT_SWAP_TYPE_FAIL ;
802- } else {
803- BOOT_LOG_INF ("Done updating network core" );
804- rc = swap_erase_trailer_sectors (state ,
805- secondary_fa );
806- swap_type = BOOT_SWAP_TYPE_NONE ;
807- }
808776 }
809- #endif /* CONFIG_SOC_NRF5340_CPUAPP */
810777 }
811778
812779 return swap_type ;
0 commit comments