Skip to content

Commit d6ba220

Browse files
committed
[rp2350] Added cache in RAM for hal_flash_write
1 parent 82e4950 commit d6ba220

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

hal/rp2350.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,21 @@ void hal_prepare_boot(void)
224224

225225
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
226226
{
227-
flash_range_program(address - XIP_BASE, data, len);
227+
uint8_t cache[WOLFBOOT_SECTOR_SIZE];
228+
uint32_t written = 0;
229+
uint32_t sz;
230+
if (((uintptr_t)data & 0x20000000UL) == 0) {
231+
/* Not in RAM: copy to cache before writing */
232+
while (written < len) {
233+
sz = WOLFBOOT_SECTOR_SIZE;
234+
if (sz > (len - written))
235+
sz = len - written;
236+
memcpy(cache, data + written, sz);
237+
flash_range_program(address - XIP_BASE + written, cache, sz);
238+
written += sz;
239+
}
240+
} else
241+
flash_range_program(address - XIP_BASE, data, len);
228242
return 0;
229243
}
230244

src/libwolfboot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ int wolfBoot_nsc_erase_update(uint32_t address, uint32_t len)
20052005
return -1;
20062006
if (address + len > WOLFBOOT_PARTITION_SIZE)
20072007
return -1;
2008-
hal_flash_erase(address + WOLFBOOT_PARTITION_UPDATE_ADDRESS, len);
2008+
return hal_flash_erase(address + WOLFBOOT_PARTITION_UPDATE_ADDRESS, len);
20092009

20102010
}
20112011

@@ -2016,7 +2016,7 @@ int wolfBoot_nsc_write_update(uint32_t address, const uint8_t *buf, uint32_t len
20162016
return -1;
20172017
if (address + len > WOLFBOOT_PARTITION_SIZE)
20182018
return -1;
2019-
hal_flash_write(address + WOLFBOOT_PARTITION_UPDATE_ADDRESS, buf, len);
2019+
return hal_flash_write(address + WOLFBOOT_PARTITION_UPDATE_ADDRESS, buf, len);
20202020
}
20212021

20222022
#endif

0 commit comments

Comments
 (0)