Skip to content

Commit

Permalink
Clear cache when doing save --verify, else it's just verifying file…
Browse files Browse the repository at this point in the history
… matches cached data
  • Loading branch information
will-v-pi committed Nov 26, 2024
1 parent 882d530 commit 1a59599
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,13 +1872,17 @@ struct picoboot_memory_access : public memory_access {
}
}

void clear_cache() {
flash_cache.clear();
}

void read_cached(uint32_t address, uint8_t *buffer, unsigned int size) {
for (auto range: flash_cache) {
uint32_t cached_start = std::get<0>(range);
uint32_t cached_size = std::get<1>(range);
auto cached_data = std::get<2>(range);
if (address >= cached_start) {
if (address > cached_start + cached_size) {
if (address >= cached_start + cached_size) {
// No data already cached
continue;
} else if (address + size <= cached_start + cached_size) {
Expand Down Expand Up @@ -1976,7 +1980,7 @@ struct picoboot_memory_access : public memory_access {
void write(uint32_t address, uint8_t *buffer, unsigned int size) override {
vector<uint8_t> write_data; // used when erasing flash
if (flash == get_memory_type(address, model)) {
flash_cache.clear(); // clear entire flash cache on any write, to be safe
clear_cache(); // clear entire flash cache on any write, to be safe
connection.exit_xip();
if (erase) {
// Do automatically erase flash, and make it aligned
Expand Down Expand Up @@ -4363,6 +4367,7 @@ bool save_command::execute(device_map &devices) {
}

if (settings.save.verify) {
raw_access.clear_cache();
auto file_access = get_file_memory_access(0);
model_t model = get_model(raw_access);
auto ranges = get_coalesced_ranges(file_access, model);
Expand Down

0 comments on commit 1a59599

Please sign in to comment.