diff --git a/Code/pico_multi_booter/picomite/FileIO.c b/Code/pico_multi_booter/picomite/FileIO.c index 4c4f2bc..8fed748 100644 --- a/Code/pico_multi_booter/picomite/FileIO.c +++ b/Code/pico_multi_booter/picomite/FileIO.c @@ -5484,14 +5484,19 @@ void ClearSavedVars(void) } void SaveOptions(void) { + uint8_t buf[FLASH_ERASE_SIZE]; + // load flash content to buf + memcpy(buf, (const void*)(XIP_BASE + FLASH_TARGET_OFFSET), FLASH_ERASE_SIZE); + // overwrite the options + memcpy(buf, (const uint8_t *)&Option, sizeof(struct option_s)); uSec(100000); disable_interrupts_pico(); flash_range_erase(FLASH_TARGET_OFFSET, FLASH_ERASE_SIZE); enable_interrupts_pico(); uSec(10000); disable_interrupts_pico(); - // XXX @cuu erased 4K, but only write sizeof(option) back? - flash_range_program(FLASH_TARGET_OFFSET, (const uint8_t *)&Option, sizeof(struct option_s)); + // save flash block back + flash_range_program(FLASH_TARGET_OFFSET, buf, FLASH_ERASE_SIZE); enable_interrupts_pico(); } /* @endcond */ diff --git a/Code/pico_multi_booter/picomite/MM_Misc.c b/Code/pico_multi_booter/picomite/MM_Misc.c index 4f634f2..875962e 100644 --- a/Code/pico_multi_booter/picomite/MM_Misc.c +++ b/Code/pico_multi_booter/picomite/MM_Misc.c @@ -4653,15 +4653,7 @@ tp = checkstring(cmdline, (unsigned char *)"HEARTBEAT"); } Option.Magic=MagicKey; //This isn't ideal but it improves the chances of a older config working in a new build FileClose(fnbr); - uSec(100000); - disable_interrupts_pico(); - flash_range_erase(FLASH_TARGET_OFFSET, FLASH_ERASE_SIZE); - enable_interrupts_pico(); - uSec(10000); - disable_interrupts_pico(); - // XXX @cuu not writing sizeof(option)? - flash_range_program(FLASH_TARGET_OFFSET, (const uint8_t *)&Option, sizeof(struct option_s)); - enable_interrupts_pico(); + SaveOptions(); _excep_code = RESET_COMMAND; SoftReset(); }