Skip to content

Instantly share code, notes, and snippets.

@vanbwodonk
Last active March 11, 2024 17:41
Show Gist options
  • Save vanbwodonk/6b425a093786e7eaddf535de747118dc to your computer and use it in GitHub Desktop.
Save vanbwodonk/6b425a093786e7eaddf535de747118dc to your computer and use it in GitHub Desktop.
Read stm32 firmware binary with openOCD

read-stm32-firmware

OpenOCD scripts for read STM32 firmware binary

Requirements

Linux

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

Win32

Here is the locaiton prebuild binary can be downloaded from: https://gnutoolchains.com/arm-eabi/openocd/

OPENOCD Command

Read command example

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

Write command example

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment