[SC64][SW] Added firmware update overwrite safeguard

This commit is contained in:
Mateusz Faderewski 2023-02-10 11:45:15 +01:00
parent 4795e23890
commit ce957faaa9
3 changed files with 15 additions and 2 deletions

View File

@ -356,6 +356,12 @@ bool cfg_update (uint32_t *args) {
return false; return false;
} }
bool cfg_set_rom_write_enable (bool value) {
uint32_t scr = fpga_reg_get(REG_CFG_SCR);
cfg_change_scr_bits(CFG_SCR_ROM_WRITE_ENABLED, value);
return (scr & CFG_SCR_ROM_WRITE_ENABLED);
}
save_type_t cfg_get_save_type (void) { save_type_t cfg_get_save_type (void) {
return p.save_type; return p.save_type;
} }

View File

@ -19,6 +19,7 @@ typedef enum {
uint32_t cfg_get_version (void); uint32_t cfg_get_version (void);
bool cfg_query (uint32_t *args); bool cfg_query (uint32_t *args);
bool cfg_update (uint32_t *args); bool cfg_update (uint32_t *args);
bool cfg_set_rom_write_enable (bool value);
save_type_t cfg_get_save_type (void); save_type_t cfg_get_save_type (void);
void cfg_get_time (uint32_t *args); void cfg_get_time (uint32_t *args);
void cfg_set_time (uint32_t *args); void cfg_set_time (uint32_t *args);

View File

@ -252,15 +252,19 @@ static void usb_rx_process (void) {
} }
break; break;
case 'f': case 'f': {
bool rom_write_enable_restore = cfg_set_rom_write_enable(false);
p.response_info.data[0] = update_backup(p.rx_args[0], &p.response_info.data[1]); p.response_info.data[0] = update_backup(p.rx_args[0], &p.response_info.data[1]);
p.rx_state = RX_STATE_IDLE; p.rx_state = RX_STATE_IDLE;
p.response_pending = true; p.response_pending = true;
p.response_error = (p.response_info.data[0] != UPDATE_OK); p.response_error = (p.response_info.data[0] != UPDATE_OK);
p.response_info.data_length = 8; p.response_info.data_length = 8;
cfg_set_rom_write_enable(rom_write_enable_restore);
break; break;
}
case 'F': case 'F': {
bool rom_write_enable_restore = cfg_set_rom_write_enable(false);
p.response_info.data[0] = update_prepare(p.rx_args[0], p.rx_args[1]); p.response_info.data[0] = update_prepare(p.rx_args[0], p.rx_args[1]);
p.rx_state = RX_STATE_IDLE; p.rx_state = RX_STATE_IDLE;
p.response_pending = true; p.response_pending = true;
@ -269,8 +273,10 @@ static void usb_rx_process (void) {
p.response_info.done_callback = update_start; p.response_info.done_callback = update_start;
} else { } else {
p.response_error = true; p.response_error = true;
cfg_set_rom_write_enable(rom_write_enable_restore);
} }
break; break;
}
case 'p': case 'p':
if (p.rx_args[0]) { if (p.rx_args[0]) {