This is an automated email from Gerrit. "zapb <d...@zapb.de>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8998
-- gerrit commit aa7d54dd9440ec8b8c792c0065cc715cc464de25 Author: Marc Schink <d...@zapb.de> Date: Mon Jul 14 07:01:58 2025 +0000 flash/nor/stm32lx: Add 'option_load' command Add command to re-load option bytes. Change-Id: I5653f2222a48af1fe0332d4bdc3552e481e375d0 Signed-off-by: Marc Schink <d...@zapb.de> diff --git a/doc/openocd.texi b/doc/openocd.texi index 6d607d697f..fb4664f3db 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -8255,6 +8255,12 @@ data). This is the only way to unlock a protected flash (unless RDP Level is 2 which can't be unlocked at all). The @var{num} parameter is a value shown by @command{flash banks}. @end deffn + +@deffn {Command} {stm32lx option_load} num +Forces a re-load of the option byte registers. +This command will cause a system reset of the device. +The @var{num} parameter is a value shown by @command{flash banks}. +@end deffn @end deffn @deffn {Flash Driver} {stm32l4x} diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c index 1459e942d1..bf283239c0 100644 --- a/src/flash/nor/stm32lx.c +++ b/src/flash/nor/stm32lx.c @@ -90,6 +90,7 @@ static int stm32lx_lock_program_memory(struct flash_bank *bank); static int stm32lx_enable_write_half_page(struct flash_bank *bank); static int stm32lx_erase_sector(struct flash_bank *bank, int sector); static int stm32lx_wait_until_bsy_clear(struct flash_bank *bank); +static int stm32lx_obl_launch(struct flash_bank *bank); static int stm32lx_lock(struct flash_bank *bank); static int stm32lx_unlock(struct flash_bank *bank); static int stm32lx_mass_erase(struct flash_bank *bank); @@ -354,6 +355,26 @@ COMMAND_HANDLER(stm32lx_handle_unlock_command) return retval; } +COMMAND_HANDLER(stm32lx_handle_option_load_command) +{ + if (CMD_ARGC != 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct flash_bank *bank; + int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); + + if (retval != ERROR_OK) + return retval; + + retval = stm32lx_obl_launch(bank); + if (retval != ERROR_OK) { + command_print(CMD, "failed to load option bytes"); + return retval; + } + + return ERROR_OK; +} + static int stm32lx_protect_check(struct flash_bank *bank) { int retval; @@ -921,6 +942,13 @@ static const struct command_registration stm32lx_exec_command_handlers[] = { .usage = "bank_id", .help = "Lower the readout protection from Level 1 to 0.", }, + { + .name = "option_load", + .handler = stm32lx_handle_option_load_command, + .mode = COMMAND_EXEC, + .usage = "bank_id", + .help = "Force re-load of device options (will cause device reset).", + }, COMMAND_REGISTRATION_DONE }; --