Skip to content

Commit 58baba2

Browse files
committed
Fix STM32H5 update
1 parent a93f2b7 commit 58baba2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

hal/stm32_tz.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,21 @@ void hal_tz_claim_nonsecure_area(uint32_t address, int len)
9696
uint32_t reg;
9797
uint32_t end = address + len;
9898
uint32_t start_address = address;
99+
uint32_t start_page_n;
99100
uint32_t bank = 0;
100101
int pos;
101102

102103
if (!is_range_nonsecure(address, len))
103104
return;
104105

105106
if (address < FLASH_BANK2_BASE) {
106-
page_n = (address - ARCH_FLASH_OFFSET) / FLASH_PAGE_SIZE;
107+
start_page_n = (address - ARCH_FLASH_OFFSET) / FLASH_PAGE_SIZE;
107108
bank = 0;
108109
} else {
109-
page_n = (address - FLASH_BANK2_BASE) / FLASH_PAGE_SIZE;
110+
start_page_n = (address - FLASH_BANK2_BASE) / FLASH_PAGE_SIZE;
110111
bank = 1;
111112
}
113+
page_n = start_page_n;
112114
#ifdef TARGET_stm32h5
113115
/* Take into account current swap configuration */
114116
if ((FLASH_OPTSR_CUR & FLASH_OPTSR_SWAP_BANK) >> 31)
@@ -129,13 +131,14 @@ void hal_tz_claim_nonsecure_area(uint32_t address, int len)
129131
page_n++;
130132
}
131133
address = start_address;
134+
page_n = start_page_n;
132135
while (address < end) {
133136
/* Erase claimed non-secure page, in secure mode */
134137
#ifndef TARGET_stm32h5
135138
reg = FLASH_CR & (~((FLASH_CR_PNB_MASK << FLASH_CR_PNB_SHIFT) | FLASH_CR_PER | FLASH_CR_BKER | FLASH_CR_PG | FLASH_CR_MER1 | FLASH_CR_MER2));
136139
FLASH_CR = reg | ((page_n << FLASH_CR_PNB_SHIFT) | FLASH_CR_PER);
137140
#else
138-
reg = FLASH_CR & (~((FLASH_CR_PNB_MASK << FLASH_CR_PNB_SHIFT) | FLASH_CR_SER | FLASH_CR_BER | FLASH_CR_PG | FLASH_CR_MER));
141+
reg = FLASH_CR & (~((FLASH_CR_PNB_MASK << FLASH_CR_PNB_SHIFT) | FLASH_CR_SER | FLASH_CR_BER | FLASH_CR_PG | FLASH_CR_MER | (1 << 31)));
139142
FLASH_CR = reg | ((page_n << FLASH_CR_PNB_SHIFT) | FLASH_CR_SER | (bank << 31));
140143
#endif
141144

@@ -162,8 +165,10 @@ void hal_tz_release_nonsecure_area(void)
162165
{
163166
#ifndef DUALBANK_SWAP
164167
int i;
165-
for (i = 0; i < FLASH_SECBB_NREGS; i++)
168+
for (i = 0; i < FLASH_SECBB_NREGS; i++) {
169+
FLASH_SECBB1[i] = 0;
166170
FLASH_SECBB2[i] = 0;
171+
}
167172
#else
168173
uint32_t addr;
169174
int bank_swp = 0;

hal/stm32h5.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@
3333

3434
#if TZ_SECURE()
3535

36-
/* This function assumes that the boot and the update
37-
* partitions are at the same address in the two banks,
38-
* regardless if DUALBANK_SWAP is active or not.
39-
*/
4036
static int is_flash_nonsecure(uint32_t address)
4137
{
38+
#ifndef DUALBANK_SWAP
39+
if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS) {
40+
return 1;
41+
}
42+
return 0;
43+
#else
4244
uint32_t in_bank_offset = (address & 0x000FFFFF);
4345
if (in_bank_offset >= (WOLFBOOT_PARTITION_BOOT_ADDRESS - FLASHMEM_ADDRESS_SPACE)) {
4446
return 1;
4547
}
4648
return 0;
49+
#endif
4750
}
4851
#endif
4952

0 commit comments

Comments
 (0)