bootloader-patterns

A knowledge guide to building boot software for STM32, nRF52, and SAM microcontrollers. Boot software runs first when a device starts and decides which application image to load.

In plain words
What is it for?
Use it when designing firmware updates over UART, CAN, or USB, storing a new image in a second memory area, checking its CRC and signature, counting failed starts, and returning to a known-good image.
Why use it?
It helps avoid designing update, image-checking, failure-recovery, and rollback behavior from scratch. These steps reduce the risk of starting an invalid update or leaving a device unusable after an update fails.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/hermeticormus/libreembed-claude-code/bootloader-patterns
Any agent
npx skills add HermeticOrmus/LibreEmbed-Claude-Code --skill bootloader-patterns
Clone the repo
git clone --depth 1 https://github.com/HermeticOrmus/LibreEmbed-Claude-Code

Made for: Claude Code, Codex.

Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,700 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01700
Opus 5 $0.00000 $0.00850
Sonnet 5 $0.00000 $0.00340
Haiku 4.5 $0.00000 $0.00170

Measured 2d ago against content hash 064f54ad27ac, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

bootloader-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/bootloader-design/skills/bootloader-patterns/SKILL.md · 195 lines

How it starts

The opening of the file, as written. The whole thing — 195 lines — stays where its author put it; the contents beside it link to each section on GitHub.

bootloader-patterns

Knowledge Base

Production bootloader patterns for STM32, nRF52, and SAM MCUs.


Pattern 1: Boot Decision Tree

Power-on Reset
    │
    ▼
Read boot flag (RTC backup register or dedicated NVM byte)
    │
    ├── FLAG_UPDATE_PENDING ──► Receive new image via UART/CAN/USB
    │                           │
    │                           ▼
    │                      Write to inactive bank
    │                           │
    │                      Verify CRC + signature
    │                           │
    │                      Set FLAG_BOOT_NEW, reset
    │
    ├── FLAG_BOOT_NEW ──► Validate image at new bank
    │                      │
    │                      ├── OK ─► Clear flag, increment boot counter,
    │                      │         jump to new image
    │                      │
    │                      └── FAIL ─► Increment failure counter
    │                                  │
    │                                  └── > 3 fails ─► Revert to golden
    │
    └── FLAG_NONE ──► Validate active bank image
                       │
                       ├── OK ─► Jump to application
                       │
                       └── FAIL ─► Fall back to recovery UART mode

Pattern 2: RTC Backup Register for Boot Flags

STM32 RTC backup registers survive reset (not power-off). Ideal for bootloader flags.

#define BKP_REG_BOOT_FLAG  RTC->BKP0R
#define BOOT_FLAG_NONE     0x00000000UL
#define BOOT_FLAG_UPDATE   0xA5A5A5A5UL
#define BOOT_FLAG_BOOT_NEW 0x5A5A5A5AUL

void bootflag_set(uint32_t flag)
{
    /* Enable backup domain access */
    RCC->APB1ENR |= RCC_APB1ENR_PWREN;
    PWR->CR |= PWR_CR_DBP;
    BKP_REG_BOOT_FLAG = flag;
    PWR->CR &= ~PWR_CR_DBP;
}

uint32_t bootflag_get(void)
{
    RCC->APB1ENR |= RCC_APB1ENR_PWREN;
    PWR->CR |= PWR_CR_DBP;
    return BKP_REG_BOOT_FLAG;
}

Pattern 3: Dual-Bank Flash Layout (STM32F407, 1MB)

0x08000000 ┌─────────────────────────┐  Sector 0 (16KB)
           │  Primary Bootloader     │  Write-protected
           │  (golden copy)          │
0x08004000 ├─────────────────────────┤  Sector 1 (16KB)
           │  Bootloader config      │
           │  (version NVM, keys)    │
0x08008000 ├─────────────────────────┤  Sectors 2-3 (32KB)
           │  Application Bank A     │  Active
           │  (img_header + app)     │
0x08040000 ├─────────────────────────┤  Sector 6 (128KB)
           │  Application Bank B     │  OTA target
           │  (img_header + app)     │
0x080C0000 ├─────────────────────────┤  Sector 10 (128KB)
           │  Application Data       │
           │  (settings, logs)       │
0x08100000 └─────────────────────────┘

Read the full file on GitHub · 195 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 195 lines · 0 tokens per session scan A 064f54ad27ac

Subscribe to this mod's changes

bootloader-patterns is a skill published in the GitHub repository HermeticOrmus/LibreEmbed-Claude-Code (44 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,700 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

hardware-iot-bus

Low-level I2C and SPI bus peripheral control for embedded Linux boards (Orange Pi, Raspberry Pi, RISC-V).

AbdullahMalik17/malikclaw · 31 tokens

aether-iot-query

Use this skill when the user asks about a live AetherEdge runtime: channels, points, real-time values, history, alarms, rules, models, instances, routing, SHM health, service health, or system status. Use aether CLI commands to answer — do NOT inspect source code, local database files, or config YAMLs to answer…

EvanL1/AetherEdge · 82 tokens

aether-iot

Build, integrate, diagnose, or generate applications for the AetherEdge AI-native edge kernel. Use for AetherEdge onboarding, SDK compositions, device and topology clients, read-only operations UIs, MCP integration, Domain Packs, or governed IoT commands where live-state authority and physical-device safety must be…

EvanL1/AetherEdge · 68 tokens

avr-bare-metal-embedded

Curated Knowledge API for AI Agents — 68 MCP tools, 200+ skill packs, 46K chunks, semantic search over 670K vectors, 5-layer validation pipeline. Works with Claude Code, Cursor, Cline, Windsurf.

MidOSresearch/midos · 6 tokens

smart-product-dev

End-to-end IoT product development orchestration for TuyaOpen projects. Guides from requirements gathering → Tuya Platform product/DP creation → complete embedded firmware generation. State-machine: detects project state and picks up from wherever development currently stands.

tuya/tuyaopen-ide-manifests · 52 tokens

edge-iot

Edge computing, IoT protocols, and embedded systems integration.

miles990/claude-software-skills · 15 tokens