hyderhusainarastu/hardware-mod-toolkit/mcu-safe-backup

Claude Code and agent skill by hyderhusainarastu/hardware-mod-toolkit

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Back up an MCU flash read-only before any modification: find the download-mode window, read ID and partition table, take a two-pass verified dump, establish a tested recovery path. Use before any operation that could write, erase or brick a device, or to audit whether a backup suffices.

Install

npx vskill@latest install hyderhusainarastu/hardware-mod-toolkit/mcu-safe-backup

SKILL.md

The same SKILL.md was published earlier as hyderhusainarastu/hardware-mod-toolkit/mcu-safe-backup.

mcu-safe-backup

The rule "no write until a verified backup and a tested recovery path both exist" is easy to say and hard to operationalise. This skill is the operational half: how to find the window into download mode without a strap pin, how to run a read-only session that cannot accidentally become a write, how to take a dump that is actually verified rather than merely taken, and how to draw the line between "we have a backup" and "we have a recovery path" — they are not the same claim, and treating them as equivalent is the single most common way this kind of project convinces itself it is safer than it is.

The concrete commands below are esptool / Espressif-chip flavored, because that is the worked example this project's process was built against (github.com/hyderhusainarastu/byok-mod). The pattern generalizes to any vendor flashing tool (STM32CubeProgrammer, nrfjprog/nrfutil, a J-Link, a vendor SDK's own flasher): dry-run by default, refuse write/erase arguments at the argument-parsing level and again on the assembled command, verify with two independent reads instead of one, and make the one sanctioned write (if any) a hardcoded constant re-derived from the device's own on-chip map rather than a value trusted from a datasheet or a CLI flag.

Reference implementation: ${CLAUDE_PLUGIN_ROOT}/scripts/mcu-backup-window.sh (plugin install) or scripts/mcu-backup-window.sh (repo checkout) — identify / partition-table / dump subcommands, dry-run by default, argument-level refusal of anything containing write/erase/efuse. Fill-in recovery-ladder template: references/recovery-plan.md in this skill directory.

1. Preconditions — what must be true before a single write is considered

Do not treat any of these as satisfied until it is written down with evidence attached, not asserted from memory:

  • [ ] A verified dump exists. Not "a dump was taken" — verified,

meaning two independent reads were compared and matched (§5). A single read proves nothing: it could be truncated, corrupted in transit, or read from the wrong offset, and a hash of one file confirms nothing about whether that file is what the chip actually holds.

  • [ ] **The partition map (or equivalent flash layout) has been decoded

from the device's own flash, not assumed from a vendor default or a tutorial.** Devices that ship a customized layout routinely relocate the exact region you're about to touch — see the offset trap in §8.

  • [ ] An identified return-to-stock path exists — something that can

put a known-good image back and has actually been exercised, not just described. A stock updater rehearsed once against a spare card/medium counts; a procedure that has only ever been typed into a markdown file does not.

  • [ ] **The owner's go-ahead for this specific write, at this specific

moment, is recorded** — a decision record (see templates/decision-record.md), not a standing policy. "We backed up weeks ago" does not authorize today's write; the backup verifies the device, the go-ahead authorizes the action.

Until every box above is checked, the only sanctioned activity is reading. If a task pushes toward a write before this list is satisfied, the answer is to stop and close the gap, not to proceed carefully.

2. Finding the window

Many small devices hand the shared USB PHY from a debug/download bridge to the running application some fixed time after boot — often a handful of seconds — after which the debug bridge stops enumerating and the normal reset sequence a flashing tool relies on stops working. This matters because it means download mode is not permanently available: it exists in a window, and the window closes on its own even if you do nothing wrong.

How to detect it:

  • Watch the host's device list (ls /dev/cu.* on macOS, dmesg -w /

udevadm monitor on Linux) across a cold boot. If a debug-bridge node (e.g. a USB-CDC/JTAG interface) appears at power-on and later disappears while the device keeps running, that disappearance marks the hand-off; the interval before it is your window.

  • Cross-reference firmware boot logs if you have them (a UART console,

or the same debug bridge before it hands off) for a literal log line about claiming the USB peripheral for the application — that log timestamp, if present, is a more precise window measurement than guessing from dmesg polling.

  • If the flashing tool has its own automatic reset-into-download-mode

sequence (many do, driven by control-line toggling rather than a physical strap pin), it only works while the debug bridge still owns the port — i.e., inside the window. Outside it, the tool's own auto-reset silently fails or the port vanishes entirely.

Entering deliberately vs. by accident. Once you understand the window, you can choose to trigger a reset into it on purpose (a power-cycle immediately followed by the tool's connect attempt) rather than racing an uncontrolled boot. Once the tool's connect sequence lands inside the window, the chip drops into its ROM/bootloader download mode and stays there — the application does not resume — as long as every subsequent command tells the tool not to reset the device again (commonly a --after no-reset / no_reset style flag). This lets you chain identify → partition-table → dump in one download-mode session without re-racing the window for every command.

The multi-MCU reset trap. If the device has more than one microcontroller (a main SoC plus a companion MCU, a separate display controller, etc.), resetting one of them via the debug/download path does not necessarily reset the others. A reset that only touches the main chip can leave a companion MCU or display controller running with stale state — observed on real hardware as visual artifacts, wrong contrast, or unresponsive input until a full power cycle. The reliable way to exit a download-mode session is to unplug the cable and do a full power-off/power-on with the device's own power switch, not a debug-bridge-only reset. Document this exit procedure once and follow it every time; do not assume a "soft reset" flag on the flashing tool resets the whole board.

3. The read-only session

Structure every read-only session the same way, in this order:

  1. Chip identification — a command that reads the chip's ID/revision

without touching flash (e.g. chip-id / chip_id).

  1. Flash identification — the flash die's JEDEC ID and detected

capacity (e.g. flash-id / flash_id). Do not trust a silkscreen or a spec-sheet figure for flash size once you can read it from the die itself — treat the read value as the correct one and promote any prior guess from "indicated" to "confirmed" only once it's read, not before.

  1. Flash status register — a read-only status/protection register

read (e.g. read-flash-status --bytes 3). This is worth doing even though it doesn't authorize anything: on a device where every block-protect bit turns out clear, there is no hardware write-protect standing between the project and a bricked device, and knowing that plainly should raise your own bar for care, not lower it because "the hardware will refuse it anyway."

  1. A small timed probe read (tens of KB) of a region you already

expect to be able to decode (a bootloader header, a known-good region). Time it. This single read tells you the tool's actual measured throughput on this unit — use that number, not a datasheet's theoretical rate, to budget the full dump (§5).

  1. The partition/layout table read and decode, once one exists at a

known offset (which may itself only become known from step 4's probe, or from vendor documentation). Decode it into a table of label/type/offset/size and treat this decoded table, not any assumption, as ground truth for every later step.

Every command gets echoed before it runs — always, dry-run or real. The habit of printing the exact command line before executing it is not cosmetic: it is what lets someone (the owner, a reviewer, your future self reading a log) catch a wrong offset or a wrong flag before it does anything, and it is what makes the session's log file a complete, self-contained record of what actually touched the device.

Nothing executes without an explicit `--yes` (or equivalent). Without it, the script/session prints the full plan — every command it would run, in order — and exits successfully having touched nothing. This is the mechanism that lets you test and review a backup procedure with no device attached at all, and it is the default, not an opt-in safety mode.

4. Defence in depth

A read-only tool should refuse to become a write tool by more than one independent mechanism, because any single check can have a bug:

  • Refuse at the argument level, before anything else runs. Scan every

argument the caller supplied for forbidden substrings — write, erase, efuse (case-insensitive) — and abort immediately if any argument contains one. This catches an operator mistake (a copy-pasted flag, a wrong subcommand name) before any port is even opened.

  • **Refuse again on the fully assembled command line, immediately before

every invocation.** This is not redundant with the argument check: it catches a bug in the script itself that might construct a dangerous command from otherwise-innocent inputs. A read-only tool should have no code path that can ever assemble a write/erase/efuse command — verify this is true by inspection, then add the runtime check as a second line of defence anyway.

  • Detect the installed tool's own syntax rather than hardcoding it.

Flashing tools change CLI spelling across major versions (underscored subcommands becoming dash-separated, a flag being renamed) — often silently, from a version bump alone. Detect which form is installed at runtime (e.g. grep the tool's own --help output for a known verb spelled both ways) and use whichever form is actually present, so the printed and executed commands always match what the installed tool understands. Do not read someone else's transcript and assume your installed version uses the same spelling.

  • **Refuse to write backup files anywhere that isn't confirmed

ignored by version control**, checked immediately before the first byte is written, not assumed from a .gitignore file's presence (rules can be edited, patterns can miss). A flash-derived binary — a bootloader, an NVS/preferences dump, anything read from the device — can carry credentials, tokens, or other device-identifying data and must never land somewhere that could later be committed by a routine git add.

  • Check whether the target port is already open by another process

before touching it (a plain lsof-style check costs nothing and does no device I/O). Two processes racing the same serial node is a way to corrupt an in-progress session for no benefit.

  • **On failure, translate the tool's raw error into a plain-language

hint** (timing miss vs. wrong mode vs. port disappeared) by matching known failure strings in the tool's own output. This is cheap to add and saves real time re-diagnosing the same three failure modes over and over during a session that has already found the window is narrow.

5. The dump — making "verified" a fact, not an adjective

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
1
7-day trend score
3

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/hyderhusainarastu/hardware-mod-toolkit/mcu-safe-backup/badge)](https://verified-skill.com/skills/hyderhusainarastu/hardware-mod-toolkit/mcu-safe-backup)

Something wrong with this skill or its page? Tell us.