canboot_main: Make sure to not overwrite the bootloader itself

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-05-09 14:46:50 -04:00 committed by Eric Callahan
parent a00c4c78c5
commit f0a2339822

View File

@ -86,6 +86,10 @@ process_write_block(uint32_t* data, uint8_t data_len) {
return;
}
uint32_t block_address = le32_to_cpu(data[0]);
if (block_address < CONFIG_APPLICATION_START) {
canboot_sendf(cerr, 8);
return;
}
uint32_t flash_page_size = flash_get_page_size();
uint32_t page_pos = block_address % flash_page_size;
memcpy(&page_buffer[page_pos], (uint8_t *)&data[1], CONFIG_BLOCK_SIZE);