nRF52840 DFU Stuck with a Permanent Slot 1: A Device Lock Caused by Downgrading

This is an English translation of the Japanese original, made with an LLM (Claude Opus 5.5). If anything is unclear, the Japanese version is authoritative. Read the Japanese original

This article was written by an LLM (GitHub Copilot).

With nRF52840 firmware developed on nRF Connect SDK 2.9, I ran into a serious bug: during a DFU (Device Firmware Update) with MCUboot/MCUmgr, the device locked up completely and could no longer accept any DFU. The problem has already been reported in the open source community, but the downgrade-specific case has not been discussed explicitly, so this article shares the details.

The problem

Symptom: the device locks up completely

When firmware with a lower version is sent by DFU, the device locks up completely and cannot accept any further DFU.

The sequence:

1. Primary Slot: v1.0.2.2 (running)
2. Run DFU: upload v1.0.1.1
3. Reboot
4. MCUboot checks versions: 1.0.2.2 > 1.0.1.1 → swap refused
5. Boots with Primary Slot still v1.0.2.2
6. Secondary Slot: v1.0.1.1 remains in the pending state
7. Try the next DFU
8. MCUmgr: "There is no free slot to place the image" error
9. Deadlock → DFU impossible

Conditions to reproduce

It always happens when these three conditions are met:

  1. Downgrade prevention is enabled

    CONFIG_MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER=y
  2. An image with a lower version is sent by DFU

    • Primary: 1.0.2.2
    • DFU: 1.0.1.1 (downgrade)
  3. Written in PERMANENT mode (the nRF Connect app default)

    • Upgrade Mode: "Confirm only"
    • image_ok=SET is set on the secondary slot

Error messages

nRF Connect app:
- "SMP Command Error: There is no free slot to place the image"

mcumgr CLI:
- "Error: 6" (image erase failed)
- Upload: stops at 0.00%

Root cause: MCUboot and MCUmgr decide on different criteria

The essence of this problem is a design "gap" between MCUboot and MCUmgr.

┌──────────────────────────────────────────┐
│ MCUmgr (DFU control)                     │
│ - Checks whether the secondary slot is   │
│   free                                   │
│ - Does not compare versions              │
│ - Treats a pending flag as "in use"      │
└─────────────┬────────────────────────────┘
              │ Gap!
              ▼
┌──────────────────────────────────────────┐
│ MCUboot (swap control at boot)           │
│ - Compares versions                      │
│ - Detects a downgrade → refuses the swap │
│ - Leaves the secondary slot as it is     │
└──────────────────────────────────────────┘

The problem: MCUmgr decides "there is an image in the secondary slot", while MCUboot decides "do not swap". As a result, an image that will never be swapped stays in the secondary slot forever.

MCUmgr's slot check logic

bool is_slot_free(int slot) {
    if (slot == 1) {
        // Check the secondary slot
        if (magic == BOOT_MAGIC_GOOD && pending) {
            return false;  // Treated as in use
        }
        return true;  // Free slot
    }
}

The blind spot: it does not check whether MCUboot will actually swap that image!

This is a known problem

Apache mynewt-mcumgr Issue #157 (November 2021)

URL: https://github.com/apache/mynewt-mcumgr/issues/157

Title: "img_mgmt_erase is too strict, won't allow erasing pending secondary slot"

Status: Open (unresolved)

It was reported as a problem where MCUboot refuses the swap and a pending image remains in the secondary slot. The reporter says "We are now stuck with a device that can only be recovered using a debugger", which is as serious as this case.

Zephyr Issue #58103 (May 2023)

URL: https://github.com/zephyrproject-rtos/zephyr/issues/58103

Title: "mcuboot/mcumgr: board not upgradable after 'Not enough free space to run swap upgrade'"

Status: Closed (merged in PR #64586 - partially resolved)

Assessment by Fabio Baltieri (Zephyr developer):

"Seems pretty serious to me, may lead to devices lost and non upgradable in the field."

It is treated as a priority: medium bug, but the actual impact is very serious.

Symptoms:

$ mcumgr image list
 image=0 slot=1
    flags: pending    # An image that will not be swapped

$ mcumgr image erase
Error: 6              # Erase refused

$ mcumgr image upload zephyr.signed.bin
 0 B / 213.04 KiB [---] 0.00%  # Stops

How this case differs

Existing reports This case In common
Cause: large image size Cause: version downgrade MCUboot refuses the swap
Not enough swap space Downgrade prevention A pending image remains in the secondary slot
Error: 6 "no free slot" New DFU impossible

Key finding: the downgrade-specific case has most likely not been reported explicitly. Development environments often disable CONFIG_MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER, and in normal operation the version always goes up, so it rarely happens.

How to fix it

Immediate recovery (back to a working state)

# Erase the whole secondary slot
nrfjprog --erasepage 0x85000-0xfe000

# Or erase only the image trailer
nrfjprog --erasepage 0xfde00-0xfe000

# Reset
nrfjprog --reset

Effect: the secondary slot is physically erased, and MCUmgr recognizes it as "free".

Method 2: full erase

nrfjprog --eraseall
nrfjprog --program merged.hex --verify
nrfjprog --reset

Method 3: shell command (if available)

mcuboot erase 2

Fundamental measures (preventing recurrence)

Always increase the BUILD number during development:
v1.0.1.1 → v1.0.2.2 → v1.0.2.3 → v1.0.2.4 ...

Never downgrade!

Measure 2: disable downgrade prevention (development only)

prj.conf:

# Ignore the build number during development
# CONFIG_MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER=y
CONFIG_MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER=n

Note: always enable it in production (it matters for security)

Measure 3: make TEST mode the default

nRF Connect app setting:

Upgrade Mode: Test only (not Confirm only)

Effect:

  • Written with image_ok=UNSET
  • Automatically REVERTs if not swapped
  • The secondary slot is cleared automatically

Impact

Severity

Assessment by Fabio Baltieri (Zephyr developer):

"Seems pretty serious to me, may lead to devices lost and non upgradable in the field."

Affected systems

  • All systems that use MCUboot + MCUmgr
  • Environments with downgrade prevention enabled
  • Nordic products such as the nRF52/nRF53/nRF91 series
  • Embedded systems that use Zephyr RTOS

Especially dangerous cases

  1. Devices already deployed in the field

    • No J-Link access
    • Remote DFU only
    • May lock up completely
  2. Devices after mass production

    • Debug port already disabled
    • No physical means of recovery
  3. Critical systems

    • Downtime not acceptable
    • Cases that need urgent fixes

Status in the Zephyr/MCUboot projects

PR #64586 (2023)

  • Stricter build-time check: a build error when the image size is too large
  • Partial erase allowed: erasing a pending image is allowed under certain conditions

Current status (2025)

  • ✅ The image size problem has improved
  • ❌ The lock caused by downgrading is unresolved
  • ⚠️ Workaround: only a forced erase with J-Link

Development:

CONFIG_MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER=n
# + always increase the version

Production:

CONFIG_MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER=y
# + strict version management
# + DFU in TEST mode
# + confirm manually after checking

Summary

The DFU trouble on the nRF52840 came from a design "gap" between MCUboot and MCUmgr: an image that is never swapped stays in the secondary slot, and new DFUs are completely blocked.

This is a known bug reported since 2021. The image size case has been partially resolved, but the downgrade case remains unresolved.

I recommend using CONFIG_MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER=n in development, and combining strict version management with DFU in TEST mode in production.

If this happens on a device already deployed in the field, it cannot be recovered without physical debug access, so take great care when designing operations.

References