Faster sector copy

pull/5/head
Daniele Lacamera 2019-03-10 09:48:06 +01:00
parent 8a8875fc05
commit 7f60f68474
2 changed files with 7 additions and 7 deletions

View File

@ -90,7 +90,6 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_
# define PART_IS_EXT(x) (0)
# define wb_flash_erase(im, of, siz) hal_flash_erase(((uint32_t)(((im)->hdr)) + of), siz)
# define wb_flash_write(im, of, dat, siz) hal_flash_write(((uint32_t)((im)->hdr)) + of, dat, siz)
# define wb_flash_write_verify_word(im, of, x) do { hal_flash_write(((uint32_t)((im)->hdr)) + of, (void *)&x, sizeof(uint32_t)); } while (*(uint32_t *)(((im)->hdr) + of) != x)
#endif /* EXT_FLASH */
#endif /* IMAGE_H */

View File

@ -24,6 +24,7 @@
extern void do_boot(const uint32_t *app_offset);
#define FLASHBUFFER_SIZE 256
static int wolfBoot_copy_sector(struct wolfBoot_image *src, struct wolfBoot_image *dst, uint32_t sector)
{
volatile uint32_t *orig, *copy;
@ -39,12 +40,12 @@ static int wolfBoot_copy_sector(struct wolfBoot_image *src, struct wolfBoot_imag
dst_sector_offset = 0;
#ifdef EXT_FLASH
if (PART_IS_EXT(src)) {
uint32_t word;
uint8_t buffer[FLASHBUFFER_SIZE];
wb_flash_erase(dst, dst_sector_offset, WOLFBOOT_SECTOR_SIZE);
while (pos < WOLFBOOT_SECTOR_SIZE) {
ext_flash_read((uint32_t)(src->hdr) + src_sector_offset + pos, (void *)&word, sizeof(uint32_t));
wb_flash_write_verify_word(dst, dst_sector_offset + pos, word);
pos += sizeof(uint32_t);
ext_flash_read((uint32_t)(src->hdr) + src_sector_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
wb_flash_write(dst, dst_sector_offset + pos, buffer, FLASHBUFFER_SIZE);
pos += FLASHBUFFER_SIZE;
}
return pos;
}
@ -52,8 +53,8 @@ static int wolfBoot_copy_sector(struct wolfBoot_image *src, struct wolfBoot_imag
wb_flash_erase(dst, dst_sector_offset, WOLFBOOT_SECTOR_SIZE);
while (pos < WOLFBOOT_SECTOR_SIZE) {
orig = (volatile uint32_t *)(src->hdr + src_sector_offset + pos);
wb_flash_write_verify_word(dst, dst_sector_offset + pos, *orig);
pos += sizeof(uint32_t);
wb_flash_write(dst, dst_sector_offset + pos, orig, FLASHBUFFER_SIZE);
pos += FLASHBUFFER_SIZE;
}
return pos;
}