jumpstarter-driver-zephyr

Flash Zephyr firmware to a board attached to a Jumpstarter exporter, while the test runner (twister) stays on the client / CI machine.

This is the flash half of the “server-side twister” workflow: twister runs locally, builds the firmware, and for each test ships only the built image(s) to the exporter. The exporter owns how to flash — the flash command and the board’s probe/target configuration live in this driver’s config, so the client is board-agnostic.

How it fits together

jmp shell --selector <board>
└── j zephyr twister <twister args>
    └── west twister --device-testing \
            --device-serial-pty j,zephyr,console,pipe,-i,--retry-count,... \
            --flash-command jmp_flash_wrapper.sh,--driver,zephyr <twister args>
    └── per testcase:
        ├── j zephyr console pipe -i --retry-count 10 ...
        │     (twister owns the PTY; pipe bridges it to the console)
        └── jmp_flash_wrapper.sh  → j zephyr flash --build-dir <dir>
              ├── (client side) tar zephyr.hex/.bin/.elf → exporter
              └── (exporter side) run flash command
                    (closing the console around it if release_consoles is set)

Everything runs inside one jmp shell lease; both commands attach to that lease via JUMPSTARTER_HOST. j zephyr twister (below) adds the three jumpstarter options and passes everything else to twister unchanged. zephyr here is the driver’s name in the exporter config: whatever it is, j <name> twister passes it to both wrappers.

Installation

$ pip3 install --extra-index-url https://pkg.jumpstarter.dev/simple jumpstarter-driver-zephyr

This installs the Zephyr driver and its j zephyr client commands (flash and twister).

Exporter configuration

The flash command runs with its working directory set to the directory holding the uploaded firmware, so it can reference files by bare name (zephyr.hex) or via the {hex} / {bin} / {elf} / {dir} tokens (absolute paths).

export:
  zephyr:                       # any name; the commands are then `j <name> ...`
    type: jumpstarter_driver_zephyr.driver.Zephyr
    config:
      flash_command: >-
        openocd -f interface/cmsis-dap.cfg -f target/cc13x2_cc26x2.cfg
        -c "program {hex} verify reset exit"
      flash_timeout: 300        # seconds; 0 disables the timeout
    children:
      console:                  # serial used by twister (any name, see below)
        type: jumpstarter_driver_pyserial.driver.PySerial
        config:
          url: /dev/ttyACM0
          baudrate: 115200

If the flash tool opens the same tty as the console (e.g. esptool), set release_consoles: true. While flashing, the driver then closes the tty of every PySerial child, whatever its name, and reopens it afterwards; twister stays attached and sees a [reconnected] line in the output. Leave it off otherwise (e.g. openocd over SWD, as above): whatever the board prints while the tty is closed is lost, including its first output after the reset that ends the flash.

The board must be left reset and running after flashing so twister captures the boot output over serial (e.g. openocd’s reset above).

Configuration reference

Field

Required

Default

Description

flash_command

yes

—

Shell command to flash the board. Supports {hex}/{bin}/{elf}/{dir} tokens.

flash_timeout

no

300

Seconds before the flash command, and everything it started, is stopped. 0 disables.

release_consoles

no

false

Close the PySerial children’s ttys while flashing, for flash tools that open the console’s tty (e.g. esptool).

Usage with twister

j zephyr twister runs west twister in the current directory, passing its arguments through unchanged. Jumpstarter only adds:

  • --device-testing;

  • --device-serial-pty, running j <driver> <console> pipe for the driver’s PySerial child;

  • --flash-command, pointing at the bundled flash wrapper.

jmp shell --selector <board>
# then, with any twister arguments:
j zephyr twister -p <platform> -T <tests>

Twister builds the tests locally and only the images are sent to the exporter. In CI, the build is often done in an earlier step with --build-only. The test step then reuses the same arguments, from the same directory, with --test-only, so twister finds the builds where it left them:

west twister --build-only -p <platform> -T <tests> -O <outdir>
# ... later, in a jmp shell:
j zephyr twister --test-only -p <platform> -T <tests> -O <outdir>

Options that would flash or reach the board some other way are rejected: --flash-command, --device-serial-pty, --device-serial, --hardware-map, --generate-hardware-map, and --west-flash / --west-runner / --west-flash-cmd (twister would ignore them, since --flash-command takes precedence).

Jumpstarter’s own option is --console <child>. It selects the PySerial child twister uses as the board’s serial port and is only needed when the driver has more than one. Jumpstarter’s options must come first: everything from the first other argument on is passed to twister unchanged, including a -- and the arguments after it, which twister hands to the test binary. For example, j zephyr twister --help shows jumpstarter’s help, and j zephyr twister -p <platform> --help shows twister’s.

j zephyr twister exits with twister’s exit code. Twister returns non-zero when any test fails, not only when twister itself fails, so a CI job that collects the reports afterwards should not stop on it (e.g. j zephyr twister ... || rc=$?).

Twister splits --device-serial-pty on spaces and commas without a shell, so the driver and console names must not contain either. Twister also connects that command’s stderr to the PTY, so pipe’s status line, and its error if it cannot attach to the console, show up at the start of each test’s serial output. It retries for a few seconds while the previous test’s connection still holds the console.

Manual use / debugging

Inside a jmp shell you can flash a build directory directly:

jmp shell --selector <board>
# then:
j zephyr flash --build-dir twister-out/<platform>/<test>

It prints one plain line per step (archive received, command being run), then the flash command’s own output as it runs. A failed flash exits non-zero with the reason.

From Python, ZephyrClient is a jumpstarter.client.flasher.StreamingFlasherClient: flash_stream(path) sends a tar of the artifacts (a local path, or an http(s) URL the exporter downloads itself) and yields FlashStatus updates; each output line of the flash command is in the stdout field of a step update. flash(path) returns the final update.

Image contract

The client uploads the fixed-name artifacts found under <build_dir>/zephyr/: zephyr.hex and, when present, zephyr.bin / zephyr.elf. Single-image boards are covered. Multi-image / MCUboot / partitioned flows are a known limitation of the fixed-name convention.

API Reference

class jumpstarter_driver_zephyr.client.ZephyrClient

Client for flashing Zephyr firmware on a remote exporter.

Collects the fixed-name firmware artifacts from a Zephyr build directory and streams them to the exporter, which runs its configured flash command. The client knows nothing about the probe or flash command — that lives in the exporter’s driver config.

Flashing comes from StreamingFlasherClient: flash_stream() sends a tar archive (a local path, or an http(s) URL the exporter downloads itself) and yields FlashStatus updates; flash() does the same and returns the final one.

Designed to back twister’s --flash-command: twister() points twister at jmp_flash_wrapper.sh, which calls j zephyr flash (i.e. flash_build_dir()) against the lease the surrounding jmp shell established.

flash(path: str | PathLike | dict[str, str | PathLike], *, target: str | None = None, compression: Compression | None = None) → FlashStatus

Flash image to DUT

flash_build_dir(build_dir: str, board_id: str | None = None) → Iterator[FlashStatus]

Flash firmware from a local Zephyr build directory.

Collects the fixed-name artifacts (zephyr.hex and, when present, zephyr.bin / zephyr.elf) from <build_dir>/zephyr/, tars them, and streams them to the exporter.

Args:
build_dir: Local Zephyr build directory (the --build-dir twister

passes; artifacts live under its zephyr/ subdir).

board_id: Optional board/probe id (forwarded by twister). Unused for

selector-based leases where one lease maps to one board; accepted so the call signature matches twister’s flash-command contract.

Yields:

Progress updates, in real time. Each output line of the flash command arrives in the stdout field of a STEP update.

Raises:

RuntimeError: The flash failed on the exporter.

flash_stream(path: str | PathLike, *, manifest: Any | None = None, compression: Compression | None = None) → Generator[FlashStatus, None, None]

Flash image to DUT, yielding progress updates.

twister(args: list[str], console: str | None = None) → int

Run twister against the leased board.

Twister runs in the current directory with args passed unchanged, so a CI job can reuse the arguments of its --build-only step and add --test-only. Jumpstarter only adds --device-testing, --device-serial-pty and --flash-command.

Args:
args: Twister arguments, e.g.

["-p", "<platform>", "-T", "tests", "--test-only"]. Options that select another way to flash or reach the board are rejected (see RESERVED_TWISTER_OPTIONS).

console: PySerial child to use as the board’s serial port; required

only when the driver has more than one.

Returns:

Twister’s exit code. It is non-zero when twister itself fails, but also when any test fails, so a CI job that wants to collect the reports must not stop on it.