2525
2626#include "hal.h"
2727#include "hal/stm32h5.h"
28+ #include "hal/armv8m_tz.h"
2829
2930#define PLL_SRC_HSE 1
3031
3132#if TZ_SECURE ()
33+
34+ /* This function assumes that the boot and the update
35+ * partitions are at the same address in the two banks,
36+ * regardless wheather DUALBANK_SWAP is active or not.
37+ */
3238static int is_flash_nonsecure (uint32_t address )
3339{
3440 uint32_t in_bank_offset = address & 0x000FFFFF ;
35- #ifdef DUALBANK_SWAP
3641 if (in_bank_offset >= (WOLFBOOT_PARTITION_BOOT_ADDRESS - FLASHMEM_ADDRESS_SPACE ))
3742 return 1 ;
3843 else
3944 return 0 ;
40- #else
41- if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS )
42- return 1 ;
43- else
44- return 0 ;
45- #endif
4645}
4746#endif
4847
@@ -101,11 +100,9 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
101100 dst = (uint32_t * )address ;
102101
103102#if (TZ_SECURE ())
103+ dst = (uint32_t * )(address | FLASH_SECURE_MMAP_BASE );
104104 if (is_flash_nonsecure (address )) {
105105 hal_tz_claim_nonsecure_area (address , len );
106- } else if (((uint32_t )dst & 0x0F000000 ) == 0x08000000 ) {
107- /* Convert into secure address space */
108- dst = (uint32_t * )((address & (~FLASHMEM_ADDRESS_SPACE )) | FLASH_SECURE_MMAP_BASE );
109106 }
110107#endif
111108 while (i < len ) {
@@ -124,6 +121,7 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
124121 FLASH_SR |= FLASH_SR_EOP ;
125122 FLASH_CR &= ~FLASH_CR_PG ;
126123 i += 8 ;
124+ DSB ();
127125 }
128126#if (TZ_SECURE ())
129127 if (is_flash_nonsecure (address )) {
@@ -201,7 +199,6 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
201199 base = FLASH_BANK2_BASE ;
202200 bnksel = 1 ;
203201 }
204-
205202#if TZ_SECURE ()
206203 /* When in secure mode, skip erasing non-secure pages: will be erased upon claim */
207204 if (is_flash_nonsecure (address )) {
0 commit comments