OpenOCD scripts for read STM32 firmware binary
OpenOCD (Open On-Chip Debugger) is open-source software that interfaces with a hardware debugger's JTAG port. OpenOCD provides debugging and in-system programming for embedded target devices. OpenOCD provides the ability to flash NAND and NOR FLASH memory devices that are attached to the processor on the target system. Flash programming is supported for external CFI compatible flashes (Intel and AMD/Spansion command set) and several internal flashes (LPC2000, AT91SAM7, STR7x, STR9x, LM3 and STM32x).
OpenOCD was originally developed by Dominic Rath at the University of Applied Sciences Augsburg. The OpenOCD source code is now available through the GNU General Public License (GPL).
Under ubuntu 20.04 just install with this:
sudo apt-get install openocd
Under Arch/Manjaro:
sudo pacman -S openocd
Here is the locaiton prebuild binary can be downloaded from: https://gnutoolchains.com/arm-eabi/openocd/
For STM32f103c8 with 64Kbytes Flash. Target is target/stm32f1x.cfg
. Size to read is 0x10000
. Read firmware as firmwareF1.bin
.
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "flash read_bank 0 firmwareF1.bin 0 0x10000" -c "reset" -c shutdown
For STM32f407vg with 1Mbytes Flash. Target is target/stm32f4x.cfg
. Size to read is 0x100000
. Read firmware as firmwareF4.bin
.
openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash read_bank 0 firmwareF4.bin 0 0x100000" -c "reset" -c shutdown
For STM32f103c8 with 64Kbytes Flash. Target is target/stm32f1x.cfg
. Write firmware firmwareF1.bin
to flash.
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "flash write_image erase firmwareF1.bin 0x08000000" -c "reset" -c shutdown
For STM32f407vg with 1Mbytes Flash. Target is target/stm32f4x.cfg
. Write firmware firmwareF4.bin
to flash.
openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase firmwareF4.bin 0x08000000" -c "reset" -c shutdown
It worked to me. Thanks for post these commands.
Below what I did with details.
Apps
Installing openocd on
18.04.1-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux
Running the provided command
Result
After the command is executed with success, the firmware is found in the file
firmwareF1.bin
$ l 907 64 -rw-rw-r-- 1 1000 1000 1000 ? 65536 2024-09-10 03:22:50.554872975 -0300 firmwareF1.bin $ md5sum firmwareF1.bin d2597bb77f754b0cf25ebbba75c89bfc firmwareF1.bin
The extracted firmware file is zipped and base64 to be posted below
Hardware
Interface and board connections
Interface: ST-LINK V2
Board with STM32F103C8T6
Here is the full output with debug level 3
Note: The procedure found here does not work to me