From b45941967d262861f5758086050e613ea7e61230 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 28 Jul 2022 12:57:17 -0400 Subject: [PATCH] lpc176x: Permit flashing to addresses other than CONFIG_APPLICATION_START Allow flash_write_block() to write to arbitrary addresses as long as the flash address starts at a 256 byte boundary. Signed-off-by: Kevin O'Connor --- src/lpc176x/flash.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lpc176x/flash.c b/src/lpc176x/flash.c index 943e21b..523d3ce 100644 --- a/src/lpc176x/flash.c +++ b/src/lpc176x/flash.c @@ -19,7 +19,7 @@ typedef void (*IAP)(uint32_t *, uint32_t *); static uint8_t iap_buf[IAP_BUF_MIN_SIZE] __aligned(4); -static uint32_t next_address = CONFIG_APPLICATION_START; +static uint32_t next_address; static uint32_t page_write_count; // Return the flash sector index for the page at the given address @@ -131,9 +131,12 @@ flash_write_block(uint32_t block_address, uint32_t *data) // Not a block aligned address return -1; if (CONFIG_BLOCK_SIZE < IAP_BUF_MIN_SIZE) { - if (block_address != next_address) - // out of order request - return -2; + if (block_address != next_address) { + if ((block_address | next_address) & (IAP_BUF_MIN_SIZE - 1)) + // out of order request + return -2; + next_address = block_address; + } uint32_t buf_idx = block_address & (IAP_BUF_MIN_SIZE - 1); memcpy(&iap_buf[buf_idx], data, CONFIG_BLOCK_SIZE); if (buf_idx == IAP_BUF_MIN_SIZE - CONFIG_BLOCK_SIZE) {