mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-05-24 16:34:46 +02:00
Fix flash bounds check
This commit is contained in:
@@ -34,6 +34,12 @@
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
void flash_driver_write(uint32_t flash_offset, const uint8_t *data, uint32_t len) {
|
||||
if (data == NULL || flash_offset >= FLASH_DRIVER_SIZE_BYTES) {
|
||||
return;
|
||||
}
|
||||
if (len > FLASH_DRIVER_SIZE_BYTES - flash_offset) {
|
||||
len = FLASH_DRIVER_SIZE_BYTES - flash_offset;
|
||||
}
|
||||
uint32_t ints = save_and_disable_interrupts();
|
||||
flash_range_erase(flash_offset, FLASH_SECTOR_SIZE);
|
||||
flash_range_program(flash_offset, data, len);
|
||||
@@ -41,6 +47,12 @@ void flash_driver_write(uint32_t flash_offset, const uint8_t *data, uint32_t len
|
||||
}
|
||||
|
||||
void flash_driver_read(uint32_t flash_offset, uint8_t *out, uint32_t len) {
|
||||
if (out == NULL || flash_offset >= FLASH_DRIVER_SIZE_BYTES) {
|
||||
return;
|
||||
}
|
||||
if (len > FLASH_DRIVER_SIZE_BYTES - flash_offset) {
|
||||
len = FLASH_DRIVER_SIZE_BYTES - flash_offset;
|
||||
}
|
||||
const uint8_t *flash_target_contents = (const uint8_t *)(XIP_BASE + flash_offset);
|
||||
memcpy(out, flash_target_contents, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user