diff --git a/MCUME_pico2/flash/flash_t.c b/MCUME_pico2/flash/flash_t.c index 0510398..fda43d7 100644 --- a/MCUME_pico2/flash/flash_t.c +++ b/MCUME_pico2/flash/flash_t.c @@ -10,24 +10,51 @@ #include "hardware/sync.h" #include "emuapi.h" +extern size_t _psram_size; + +static bool using_psram; + +#define PSRAM_BASE (0x11000000) +// #define PSRAM_BASE (0x15000000) // there's no reason to use uncached access unsigned char * flash_start = (unsigned char *)(XIP_BASE + HW_FLASH_STORAGE_BASE); unsigned char * flash_end = (unsigned char *)(XIP_BASE + HW_FLASH_STORAGE_TOP); static uint8_t cache[FLASH_SECTOR_SIZE]; -int flash_load(const char * filename) +static void flash_setup() { + if (_psram_size) { + using_psram = true; + flash_start = (unsigned char*)PSRAM_BASE; + flash_end = flash_start + _psram_size; + } else { + using_psram = false; + } +} + +int flash_load_common(const char * filename, bool do_bswap) { - uint32_t offset = HW_FLASH_STORAGE_BASE; + flash_setup(); + + uint8_t *dest = flash_start; int n; int size = 0; emu_printf("flash_load..."); int f = emu_FileOpen(filename,"r+b"); 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); - if (memcmp(cache, (unsigned char*)XIP_BASE + offset, n)) { + while ( (dest < (flash_end-FLASH_SECTOR_SIZE)) && (n = emu_FileRead(cache,FLASH_SECTOR_SIZE,f) ) ) { + if (do_bswap) { + for (int i=0;i