picomite: properly save options

This commit is contained in:
Yatao Li 2025-06-18 15:30:14 +08:00
parent 763a7080a2
commit 9c449b8b03
2 changed files with 8 additions and 11 deletions

View File

@ -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 */

View File

@ -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();
}