skip reprogramming flash with identical content

this is a terrible workaround: the disabled interrupts of flash copy(?)
cause USB HID input to break. with this change, I can play Kirby
merely by selecting it from the menu, resetting once I reach the
title screen, then selecting it from the menu a second time.
This commit is contained in:
Jeff Epler 2025-03-05 11:18:56 -06:00
parent eb646218f5
commit 94381019f4

View file

@ -2,6 +2,8 @@
RP2350 flash driver
*/
#include <string.h>
#include "flash_t.h"
#include "hardware/flash.h"
@ -24,17 +26,19 @@ int flash_load(const char * filename)
if (f) {
while ( (offset < (HW_FLASH_STORAGE_TOP-FLASH_SECTOR_SIZE)) && (n = emu_FileRead(cache,FLASH_SECTOR_SIZE,f) ) ) {
//memcpy(cache, (unsigned char *)offset, n);
uint32_t ints = save_and_disable_interrupts();
flash_range_erase(offset, FLASH_SECTOR_SIZE);
flash_range_program(offset, (const uint8_t *)&cache[0], FLASH_SECTOR_SIZE);
restore_interrupts(ints);
emu_printi(n);
emu_printi(offset);
//uint8_t * pt = (uint8_t*)(XIP_BASE + offset);
//emu_printi(pt[0]);
//emu_printi(pt[1]);
//emu_printi(pt[2]);
//emu_printi(pt[3]);
if (memcmp(cache, (unsigned char*)XIP_BASE + offset, n)) {
uint32_t ints = save_and_disable_interrupts();
flash_range_erase(offset, FLASH_SECTOR_SIZE);
flash_range_program(offset, (const uint8_t *)&cache[0], FLASH_SECTOR_SIZE);
restore_interrupts(ints);
emu_printi(n);
emu_printi(offset);
//uint8_t * pt = (uint8_t*)(XIP_BASE + offset);
//emu_printi(pt[0]);
//emu_printi(pt[1]);
//emu_printi(pt[2]);
//emu_printi(pt[3]);
}
offset += FLASH_SECTOR_SIZE;
size += n;
}
@ -99,4 +103,4 @@ int flash_verify(unsigned char * buf, int size)
}
emu_printf("flash_verify OK.");
return 0;
}
}