Skip to content

Fix/nrf91 modem update commander - #2057

Open
emrenorm wants to merge 2 commits into
pyocd:developfrom
emrenorm:fix/nrf91-modem-update-commander
Open

emrenorm wants to merge 2 commits into
pyocd:developfrom
emrenorm:fix/nrf91-modem-update-commander

Conversation

@emrenorm

Copy link
Copy Markdown

Title: nrf91: fix "wait for events timed out" in modem firmware update; split commander lines once

Problem

On an nRF9151 with a CMSIS-DAP probe (DAPLink), nrf91-update-modem-fw
failed with wait for events timed out although the modem DFU itself works
(ModemUpdater.verify() from the Python API passes every time from a clean
state). Three independent causes all ended in the same misleading message:

  1. The commander split command lines twice. _split_commands() splits
    into words (removing quotes/escapes), then parse_command() split the words
    again. Nordic's DECT NR+ package is named mfw-nr+_nrf91x1_1.0.1.zip; the
    path reached the command as three words, and neither quoting nor \+ helped.
  2. Verify errors were swallowed. except: turned any verify error (here:
    FileNotFoundError) into a programming attempt. The verify had already left
    the modem in its DFU bootloader, so the second attempt timed out.
  3. A second DFU with debug power still requested gets no answer. This hits
    the command's own verify-then-program path (same session) and any pyocd cmd
    run after another one, because the commander keeps the debug port powered on
    exit (resume_on_disconnect=False).

Changes

  • commands: split command lines into words only once + unit test
    (test/unit/test_execution_context.py; fails on the old code for the quoted
    and escaped cases).
  • nrf91: fix modem firmware update failures:
    • power-cycle the debug domain at the start of _setup_device();
    • only checksum mismatch / Error while verifying lead to programming,
      other errors propagate; parse() reports a missing file (hinting at quoting);
    • reset the device when verify/program ends, also after errors, so the modem
      leaves its DFU bootloader.

Testing (nRF9151 LACA A1A, ARM DAPLink on NUCLEO-F103RB, mfw-nr+_nrf91x1_1.0.1.zip)

Each line is a separate pyocd cmd -t nrf91 -c "nrf91-update-modem-fw ..." run:

Case Before After
unquoted path with + timeout after 31 s modem firmware file not found: _nrf91x1_1.0.1.zip (quote paths ...)
quoted path, verify, 4 consecutive runs timeout 4/4 pass (~6 s)
package with altered digest (mismatch -> program, same session) timeout programs, then reports checksum mismatch
-f program + verify — pass (17 s), following verify passes

Measured but not changed: the IPC receive masks. Another tool uses 0xFFFF
for nRF9151; with the existing nRF9160 values (0x4/0x10) all cases above
pass, the modem signalled on channels 2 and 4.

Developed with assistance from Claude (Anthropic); I reviewed the changes and ran all tests on specific hardware.

Emre Gündoğar and others added 2 commits October 14, 2026 10:44
_split_commands() already splits a command line into words and removes
quotes and escapes, but parse_command() split the resulting words again.
Quoted arguments that contain operator characters were therefore broken
up, e.g. the path of Nordic's DECT NR+ modem firmware package,
"mfw-nr+_nrf91x1_1.0.1.zip", reached the command as three words, and
neither quoting nor escaping the '+' helped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`nrf91-update-modem-fw` reported "wait for events timed out" in cases
where the modem was working fine:

- A second modem DFU while debug power had stayed requested since an
  earlier one got no answer from the modem. This broke the
  verify-then-program path of the command (firmware differs -> program in
  the same session) and every `pyocd cmd` run following another one, as
  the commander keeps the debug port powered on exit. The debug domain is
  now power-cycled at the start of the DFU setup.
- Any exception raised while verifying was swallowed and turned into a
  programming attempt, so e.g. a wrong file path showed up as a modem
  timeout. Only a firmware mismatch now leads to programming; other
  errors are reported as they are, and a missing file is reported by
  parse().
- The modem stayed in its DFU bootloader after verify/program, including
  after errors. The device is now reset when the procedure ends.

Tested on an nRF9151 (DAPLink) with mfw-nr+_nrf91x1_1.0.1.zip, each in a
separate `pyocd cmd` run: verify x4; a package with an altered digest
(verify mismatch -> program in the same session -> "checksum mismatch"
reported, no timeout); -f program + verify (17 s); verify.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant