# sayooj-aerlync/mcuboot architecture

> Architecture diagram of the GitHub repository sayooj-aerlync/mcuboot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sayooj-aerlync/mcuboot
- Repository: https://github.com/sayooj-aerlync/mcuboot

## Overview

##### Main architectural layers and components
a. Core Bootloader (bootutil)
- Description: Portable, OS-agnostic C library providing image validation, swap, fault-injection hardening, crypto-abstraction.
- Location: boot/bootutil/src & include.
b. Bootloader Extensions
- Serial-upgrade support (boot_serial).
- Description: In-loader image upload over UART.
- Location: boot/boot_serial.
c. Porting Layers (per OS / SoC)
- Zephyr (boot/zephyr)
- Apache Mynewt (boot/mynewt)
- Apache NuttX (boot/nuttx)
- Mbed OS (boot/mbed)
- Espressif SoCs (boot/espressif)
- Cypress/Infineon (boot/cypress)
- For each: hardware-abstraction, OS hooks, board config, linker scripts.
d. External Cryptographic Backends (ext/)
- tinycrypt, mbedTLS-ASN1, fiat-crypto, nRF CC310 glue.
- Used by core and port layers via abstraction.
e. Image-Signing & Management Tools
- imgtool (Python CLI + lib)
- ptest (Rust/C testing harness)
- scripts/imgtool, scripts/tests.
f. Simulation & Testing Harness
- sim (Rust crates + C support via mcuboot-sys)
- simflash (Rust library simulating flash)
- sim/src: test vectors, API.
g. Continuous Integration & Sample Projects
- CI workflows (.github/workflows, ci/)
- samples/ (Zephyr, compression test, runtime-source).
- testplan/ (Mynewt test plans).

##### Relationships and data flows
- imgtool → Generates signed firmware images → Flashed into device or simulator.
- Device Bootloader (core+port) → Reads Flash → Performs image validation using crypto backends → If valid, swaps/boots new image.
- Boot_serial extension ↔ Host PC via UART for image upload.
- Simulation harness calls Bootloader core APIs to emulate flash operations and verify logic.
- CI pipelines invoke build scripts for each port, run imgtool, sim, ptest, and sample-apps.

##### Architectural patterns & design principles
- Layered architecture:
- Core functional layer (bootutil) separated from platform specifics.
- Porting‐layer/HAL abstracts RTOS and SoC.
- External libs provide pluggable crypto implementations.
- Modular code organization: monorepo with submodules, each port or extension lives in its own directory.
- Code reuse via pkg.yml/CMakeLists for each target.
- Multi‐language tooling: C for core & ports, Python for CLI, Rust for simulation.

##### Must-have elements
- Boundary for device runtime vs. host-side tools vs. CI/test environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Host Tools & CI"
        Imgtool["imgtool: sign_image\nscripts/imgtool/"]:::tools
        ImgtoolTests["imgtool Tests\nscripts/tests/"]:::tools
        PTest["ptest (Rust/C harness)\nptest/src"]:::tools
        CI["CI Workflows\n.github/workflows & ci/"]:::ci
    end

    subgraph "Sample Projects"
        ZephyrSample["Zephyr Samples\nsamples/zephyr/"]:::sample
        Compression["Compression Test\nsamples/compression_test/"]:::sample
        RuntimeSource["Runtime Source\nsamples/runtime-source/zephyr/app\n.../hooks"]:::sample
        ConfigTemplate["Config Template\nsamples/mcuboot_config/"]:::sample
    end

    subgraph "Simulation & Testing Harness"
        MCUSys["mcuboot-sys (C bindings)\nsim/mcuboot-sys/src & csupport"]:::sim
        Simflash["Flash Simulator Library\nsim/simflash/src"]:::sim
        SimApp["Simulation Apps & Tests\nsim/src"]:::sim
    end

    subgraph "Device Runtime"
        Core["Core Bootloader bootutil\nboot/bootutil/src & include"]:::core
        SerialExt["Serial Upgrade Extension\nboot/boot_serial/src & include"]:::extension
        subgraph "Port Layers"
            ZephyrPort["Zephyr Port\nboot/zephyr/"]:::port
            MynewtPort["Mynewt Port\nboot/mynewt/src & include"]:::port
            NuttXPort["NuttX Port\nboot/nuttx/src & include"]:::port
            MbedPort["Mbed OS Port\nboot/mbed/src & include"]:::port
            EspPort["Espressif Port\nboot/espressif/port & hal & include"]:::port
            CypressPort["Cypress/Infineon Port\nboot/cypress/"]:::port
        end
        subgraph "Crypto Backends"
            Tinycrypt["tinycrypt\next/tinycrypt/lib/include & source"]:::crypto
            TinycryptSHA["tinycrypt-sha512\next/tinycrypt-sha512/lib/include & source"]:::crypto
            MbedASN["mbedTLS ASN.1\next/mbedtls-asn1/include & src"]:::crypto
            Fiat["Fiat Crypto\next/fiat/src"]:::crypto
            NRFCC["nRF CC310 Glue\next/nrf/cc310_glue.c & h"]:::crypto
        end
        Flash["Flash Hardware"]:::hw
    end

    %% Data Flows
    Imgtool -->|"generates signed image"| Core
    ImgtoolTests -->|"validates imgtool"| Imgtool
    PTest -->|"tests boot logic via mcuboot-sys"| MCUSys
    MCUSys -->|"binds to"| Core
    SimApp -->|"simulates flash ops"| Simflash
    Simflash -->|"emulates flash"| Core
    SimApp -->|"calls boot APIs"| Core
    Core -->|"validates image using"| Tinycrypt
    Core -->|"validates image using"| TinycryptSHA
    Core -->|"validates image using"| MbedASN
    Core -->|"validates image using"| Fiat
    Core -->|"validates image using"| NRFCC
    Core -->|"invokes serial upload"| SerialExt
    SerialExt -->|"UART upload/download"| Imgtool
    Core -->|"uses HAL"| ZephyrPort
    Core -->|"uses HAL"| MynewtPort
    Core -->|"uses HAL"| NuttXPort
    Core -->|"uses HAL"| MbedPort
    Core -->|"uses HAL"| EspPort
    Core -->|"uses HAL"| CypressPort
    CI -->|"builds & tests"| Imgtool
    CI -->|"builds & tests"| PTest
    CI -->|"runs simulations"| SimApp
    CI -->|"builds ports"| ZephyrPort
    CI -->|"builds ports"| MynewtPort
    CI -->|"builds ports"| NuttXPort
    CI -->|"builds ports"| MbedPort
    CI -->|"builds ports"| EspPort
    CI -->|"builds ports"| CypressPort
    CI -->|"deploys samples"| ZephyrSample
    CI -->|"deploys samples"| Compression
    CI -->|"deploys samples"| RuntimeSource
    CI -->|"deploys samples"| ConfigTemplate

    %% Click Events
    click Core "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/bootutil/src"
    click SerialExt "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/boot_serial/src"
    click ZephyrPort "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/zephyr/"
    click MynewtPort "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/mynewt/src"
    click NuttXPort "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/nuttx/src"
    click MbedPort "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/mbed/src"
    click EspPort "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/espressif/port"
    click CypressPort "https://github.com/sayooj-aerlync/mcuboot/tree/main/boot/cypress/"
    click Tinycrypt "https://github.com/sayooj-aerlync/mcuboot/tree/main/ext/tinycrypt/lib/source"
    click TinycryptSHA "https://github.com/sayooj-aerlync/mcuboot/tree/main/ext/tinycrypt-sha512/lib/source"
    click MbedASN "https://github.com/sayooj-aerlync/mcuboot/tree/main/ext/mbedtls-asn1/src"
    click Fiat "https://github.com/sayooj-aerlync/mcuboot/tree/main/ext/fiat/src"
    click NRFCC "https://github.com/sayooj-aerlync/mcuboot/blob/main/ext/nrf/cc310_glue.c"
    click Imgtool "https://github.com/sayooj-aerlync/mcuboot/tree/main/scripts/imgtool/"
    click ImgtoolTests "https://github.com/sayooj-aerlync/mcuboot/tree/main/scripts/tests/"
    click PTest "https://github.com/sayooj-aerlync/mcuboot/tree/main/ptest/src"
    click MCUSys "https://github.com/sayooj-aerlync/mcuboot/tree/main/sim/mcuboot-sys/src"
    click Simflash "https://github.com/sayooj-aerlync/mcuboot/tree/main/sim/simflash/src"
    click SimApp "https://github.com/sayooj-aerlync/mcuboot/tree/main/sim/src"
    click CI "https://github.com/sayooj-aerlync/mcuboot/tree/main/.github/workflows/"
    click ZephyrSample "https://github.com/sayooj-aerlync/mcuboot/tree/main/samples/zephyr/"
    click Compression "https://github.com/sayooj-aerlync/mcuboot/tree/main/samples/compression_test/"
    click RuntimeSource "https://github.com/sayooj-aerlync/mcuboot/tree/main/samples/runtime-source/zephyr/app"
    click ConfigTemplate "https://github.com/sayooj-aerlync/mcuboot/tree/main/samples/mcuboot_config/"

    %% Styles
    classDef core fill:#a6cee3,stroke:#1f78b4,color:#000;
    classDef extension fill:#b2df8a,stroke:#33a02c,color:#000;
    classDef port fill:#b15928,stroke:#8c510a,color:#fff;
    classDef crypto fill:#ffffb3,stroke:#ff7f00,color:#000;
    classDef tools fill:#fb9a99,stroke:#e31a1c,color:#000;
    classDef sim fill:#fdbf6f,stroke:#ff7f00,color:#000;
    classDef ci fill:#cccccc,stroke:#333333,color:#000;
    classDef sample fill:#d9d9d9,stroke:#636363,color:#000;
    classDef hw fill:#f0f0f0,stroke:#999999,color:#000;
```
