Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

161.4. openocd-0.12.0

On-chip debugging and flashing over JTAG or SWD

Version 0.12.0, release 1
Shelf embedded — Microcontroller and bare-metal development: cross toolchains, C libraries, flashers, debug probes and serial consoles
Phase 41_system (System), 461 of 1047 in build order
Licence GPL-2.0-or-later
Homepage https://openocd.org/
Build time 1.7 SBU
Installed size 6.0 MiB in 900 files
Recipe ports/core/embedded/openocd/kpkgbuild

About

OpenOCD is an on-chip debugger: through a JTAG or SWD adapter it halts a microcontroller or an SoC, reads and writes its registers and memory, sets breakpoints, single-steps it and programs its flash, and it serves all of that to gdb as a remote target. Where gdb and the tracers debug a process, OpenOCD debugs a chip with no operating system, which is the way to find out why a board does not boot far enough to print anything. The port names every adapter driver it builds, so that what it supports is decided by the recipe and not by what the build root holds.

Why it is in KDOS

The comment above it in script/phases/41_system/packages.d/embedded.txt:

gdb and the tracers debug a PROCESS; openocd halts a microcontroller through its debug port — the only way to find out why a board does not boot far enough to print anything. Its adapter list and the 70-kdos-*.rules list are the same list on purpose.

Sources

Dependencies

Depends on: autoconf, automake, libtool, pkgconf, libusb, libftdi, hidapi, libjaylink, capstone.

Required by: no port names it.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install openocd'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/embedded/openocd.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/embedded/openocd
echo 'af254788be98861f2bd9103fe6e60a774ec96a8c374744eef9197f6043075afa  openocd-0.12.0.tar.bz2' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/openocd
SRC=$SRC_ROOT/openocd-0.12.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf openocd-0.12.0.tar.bz2 -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

./configure \
	--prefix=/usr \
	--disable-werror \
	--enable-ftdi \
	--enable-stlink \
	--enable-ti-icdi \
	--enable-ulink \
	--enable-usb-blaster-2 \
	--enable-ft232r \
	--enable-vsllink \
	--enable-xds110 \
	--enable-cmsis-dap-v2 \
	--enable-osbdm \
	--enable-opendous \
	--enable-armjtagew \
	--enable-rlink \
	--enable-usbprog \
	--enable-esp-usb-jtag \
	--enable-cmsis-dap \
	--enable-nulink \
	--enable-kitprog \
	--enable-usb-blaster \
	--enable-presto \
	--enable-openjtag \
	--enable-buspirate \
	--enable-jlink \
	--disable-internal-libjaylink \
	--disable-linuxgpiod \
	--enable-jtag_vpi \
	--enable-remote-bitbang \
	--with-capstone \
	--disable-doxygen-html
make
make DESTDIR=$PKG install

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/openocd, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf openocd-0.12.0-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/openocd, and runs the triggers its paths call for.

Contents

Installed programs: openocd.

Installed directories: /usr/share/licenses/openocd, /usr/share/openocd.

Short descriptions

openocd A free and open on-chip debugging, in-system programming and boundary-scan testing tool for ARM and MIPS systems

Notes

The adapters this port enables and the devices fs/etc/udev/rules.d/70-kdos-debug.rules and 70-kdos-serial.rules grant to the dialout group are the same list, by the USB IDs upstream’s contrib/60-openocd.rules gives. Upstream’s own rules are not installed: they grant a plugdev group and set the uaccess tag, and neither exists on KDOS. An adapter that is in neither KDOS file can be opened only by root, and enabling a new driver here means adding its IDs there.