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
openocd-0.12.0.tar.bz2(6.5 MiB)
sha256af254788be98861f2bd9103fe6e60a774ec96a8c374744eef9197f6043075afa
upstream: https://sourceforge.net/projects/openocd/files/openocd/0.12.0/openocd-0.12.0.tar.bz2/download
archive copy: sources-2/embedded--openocd-0.12.0.tar.bz2
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:
--disable-werror— configure turns warnings into errors whenever GCC warnings are on, which is the default; a warning a newer compiler adds would stop the build.--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— The drivers that talk to their adapter through libusb. configure defaults each adapter toauto, which builds the driver when its library is found and drops it without a word when not. Namedyes, a missing library is a configure error, so the set of drivers does not depend on what else the build root holds.--enable-cmsis-dap,--enable-nulink— The HID drivers, CMSIS-DAP v1 and Nuvoton’s Nu-Link, through hidapi;--enable-kitprog, Cypress KitProg, needs both hidapi and libusb.--enable-usb-blaster,--enable-presto,--enable-openjtag— The drivers built on libftdi: Altera’s USB-Blaster, ASIX Presto and OpenJTAG.--enable-buspirate— The Bus Pirate driver, which uses a serial port and no library.--enable-jlink— SEGGER J-Link, through libjaylink.--disable-internal-libjaylink— The release carries its own copy of libjaylink undersrc/jtag/drivers/libjaylink, and configure builds and links that copy unless told not to. With the switch, the J-Link driver links the libjaylink port.--disable-linuxgpiod— Leaves out the driver that bit-bangs JTAG and SWD on Linux GPIO lines through libgpiod. This release’s driver is written against libgpiod’s version 1 interface, and the libgpiod port is version 2, so left to auto-detection the build fails whenever libgpiod happens to be installed first. The switch does not appear inconfigure --help, because a missing comma inconfigure.ac’s adapter list (LIBFTDI_USB1_ADAPTERSbeforeLIBGPIOD_ADAPTERS) keeps the help text from declaring it, but the variable it sets is the one the driver test reads.--enable-jtag_vpi,--enable-remote-bitbang— Two drivers that are off by default and need no library: JTAG VPI talks over TCP to a simulated design, and remote bitbang sends ASCII-encoded bit-bang requests over a UNIX or TCP socket to another process, which drives the JTAG signals, as when the processor being debugged is itself simulated.--with-capstone— Builds the disassembler behindarm disassemble, and OpenOCD’s AArch64 one, on capstone; built without it, the command answers only “capstone disassembly framework required”. By default configure probes for capstone and goes on without it; given, a missing capstone is a configure error.--disable-doxygen-html— Doxygen’s HTML manual of the source code is on by default for thedoxygenmake target, which the port does not run.
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.