← 返回命令列表

Linux command

openocd 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Start with interface and target config files

openocd -f [interface/stlink.cfg] -f [target/stm32f4x.cfg]

Program flash with verify and reset

openocd -f [interface.cfg] -f [target.cfg] -c "program [firmware.elf] verify reset exit"

Program a hex file at a specific address

openocd -f [interface.cfg] -f [target.cfg] -c "program [firmware.hex] 0x08000000 verify reset exit"

Start with a board config (includes interface and target)

openocd -f [board/stm32f4discovery.cfg]

Start and connect GDB server on a custom port

openocd -f [config.cfg] -c "gdb_port [4444]"

Dump flash memory to a binary file

openocd -f [config.cfg] -c "init" -c "dump_image [output.bin] 0x08000000 0x10000" -c "exit"

Erase entire flash memory

openocd -f [interface.cfg] -f [target.cfg] -c "init" -c "reset halt" -c "flash erase_sector 0 0 last" -c "exit"

Enable verbose debug output

openocd -d3 -f [interface.cfg] -f [target.cfg]

说明

openocd (Open On-Chip Debugger) provides debugging, in-system programming, and boundary-scan testing for embedded systems. It interfaces with JTAG, SWD, and other debug adapters to access microcontrollers and FPGAs. Configuration files define the debug adapter (interface) and target device. Many boards and adapters have predefined configurations in the installation. Programming mode flashes firmware to microcontrollers. Verify confirms the write succeeded. Reset starts the new firmware. When running as a server, OpenOCD provides GDB server (port 3333) and telnet interface (port 4444). GDB connects for source-level debugging. The telnet interface allows direct commands: halt, resume, step, memory read/write, register access, and breakpoint management. Multiple targets can be debugged simultaneously. JTAG chains with several devices are supported.

参数

-f _FILE_
Configuration file.
-c _CMD_
Run command.
-s _DIR_
Search directory.
-d _LEVEL_
Debug level (0-4, default 2). Higher values produce more output.
-l _FILE_
Log output to file instead of stderr.
-p, --pipe
Use pipes for GDB communication instead of TCP.
--version
Show version.
--help
Show help.

FAQ

What is the openocd command used for?

openocd (Open On-Chip Debugger) provides debugging, in-system programming, and boundary-scan testing for embedded systems. It interfaces with JTAG, SWD, and other debug adapters to access microcontrollers and FPGAs. Configuration files define the debug adapter (interface) and target device. Many boards and adapters have predefined configurations in the installation. Programming mode flashes firmware to microcontrollers. Verify confirms the write succeeded. Reset starts the new firmware. When running as a server, OpenOCD provides GDB server (port 3333) and telnet interface (port 4444). GDB connects for source-level debugging. The telnet interface allows direct commands: halt, resume, step, memory read/write, register access, and breakpoint management. Multiple targets can be debugged simultaneously. JTAG chains with several devices are supported.

How do I run a basic openocd example?

Run `openocd -f [interface/stlink.cfg] -f [target/stm32f4x.cfg]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -f _FILE_ do in openocd?

Configuration file.