← Back to Pull requests

bootutil: scramble the first block going backwards on devices without erase #3024

Closed
unknown closed this pull request without merging on Dec 01, 2026 20:42 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 17:51 UTC
Author

On devices without erase, boot_scramble_region() going backwards never wrote the first write block of the range, because the loop condition was tested before the write. swap_scramble_trailer_sectors() scrambles the trailer this way from its start, where status entry 0 lives, so the entry left by the previous swap survived the scramble at the start of a new swap-move or swap-offset upgrade. A reset before the new swap wrote its own first status entry made the resumed swap skip that step, leaving a stale sector in the revert copy.

Fixes #3021

Changes

  • bootutil: keep looping when going backwards, so the existing check inside the loop ends it right after the first block is written (the fix proposed in the issue).

  • sim: add a no-erase feature. It builds MCUboot with only MCUBOOT_SUPPORT_DEV_WITHOUT_ERASE and makes the simulated flash accept writes over any value. Until now the simulator only modelled NOR flash, so the no-erase code paths were never exercised.

  • sim: add upgrade_over_stale_status, a slow test that completes and confirms one upgrade, stages another, and interrupts it at every flash operation. Without the fix it fails for both swap-move and swap-offset in the no-erase mode. It passes on devices with erase.

  • CI: run no-erase swap-move and swap-offset.
  • Notes for review

  • The two status write failure tests are skipped in the no-erase mode. They make writes to the status area fail, and without erase the trailer scramble is itself such a write, so the swap stops with an error before reaching the paths these tests check.

  • Swap-scratch and overwrite-only are left out of the no-erase CI rows. They clear the whole scratch area or slot one write block at a time, up to a few hundred thousand writes per upgrade at 1-byte alignment, which makes the power-fail sweeps impractically long. Their fast tests pass in this mode.

  • Not addressed here: in the no-erase mode with multiimage, perm_with_random_fails fails for all three swap modes. It needs two interruptions, the second a few operations into the resumed boot, and happens with or without this fix. Multiimage is kept out of the new CI rows until that is looked at separately.
  • Diff: 275 lines (+206 / -69) across 3 files Reviewer: nordicjm Review duration: 170m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 275 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.336
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3024"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.6% (MEDIUM) · Higher = larger blast radius
    39.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.6% · Safe to merge
    15.6%