# erdemefe90/avr-secure-bootloader architecture

> Architecture diagram of the GitHub repository erdemefe90/avr-secure-bootloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/erdemefe90/avr-secure-bootloader
- Repository: https://github.com/erdemefe90/avr-secure-bootloader

## Overview

This is an AVR secure-firmware update system: a firmware image is packaged and encrypted, inspected and sent by a desktop flasher, then authenticated, decrypted, and written by the device bootloader before execution passes to the application. The graph preserves the distinct packaging, host-side image handling, serial protocol, device validation/programming, and application stages. README documentation describes capabilities whose implementation was not sampled; those are represented only where the tree supports a source path, and uncertain internal wiring is omitted.

Main entry points: [`Bootloader/bootloader.c`](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Bootloader/bootloader.c) (Bootloader Core), [`Tools/Flasher/main.py`](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/main.py) (Flasher Controller), [`App/app_main.c`](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/app_main.c) (Application Runtime), [`Tools/encrypt_image.py`](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/encrypt_image.py) (Image Encryption)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware Packaging"]
  node_encrypt["Image Encryption<br/>[encrypt_image.py]"]
  node_decrypt_tool["Image Decryption Tool<br/>[decrypt_image.py]"]
end

subgraph group_host["Host Flasher"]
  node_flasher_ui["Flasher Interface<br/>[Flasher_GUI.py]"]
  node_flasher["Flasher Controller<br/>[main.py]"]
  node_image_extract["Image Extraction<br/>[image_extract.py]"]
  node_flasher_utils["Flasher Utilities<br/>[utils.py]"]
end

subgraph group_device["Device Bootloader"]
  node_boot_entry["Boot Entry<br/>[boot_main.c]"]
  node_boot_core["Bootloader Core<br/>[bootloader.c]"]
  node_boot_uart["Boot UART Protocol<br/>[uart.c]"]
  node_crc["CRC16-CCITT<br/>[crc.c]"]
  node_aes["AES Implementation"]
end

subgraph group_application["Application Runtime"]
  node_app_image["Application Image<br/>[app_main.c]"]
  node_image_format["Image Metadata<br/>[image.h]"]
  node_shared_memory[("Shared Boot State<br/>[image.h]")]
  node_app_entry["Application Runtime<br/>[app_main.c]"]
  node_app_uart["Application UART<br/>[uart.c]"]
  node_app_buffer["UART Buffers<br/>[circular_buffer.c]"]
end

node_operator(("Firmware Operator"))
node_serial_port(("Serial Port"))
node_device(("AVR Device"))

node_operator -->|"selects firmware"| node_encrypt
node_app_image -->|"packages image"| node_encrypt
node_image_format -->|"defines header"| node_encrypt
node_encrypt -->|"produces update file"| node_flasher
node_operator -->|"operates"| node_flasher_ui
node_flasher_ui -->|"dispatches actions"| node_flasher
node_flasher -->|"requests image parsing"| node_image_extract
node_image_extract -->|"checks CRC"| node_flasher_utils
node_image_extract -->|"returns update data"| node_flasher
node_decrypt_tool -.->|"reads image metadata"| node_image_format
node_flasher -->|"exchanges packets"| node_serial_port
node_serial_port -->|"transfers packets"| node_boot_uart
node_boot_entry -->|"checks and processes"| node_boot_core
node_boot_core -->|"reads and transmits"| node_boot_uart
node_boot_uart -->|"validates packet CRC"| node_crc
node_boot_core -->|"decrypts payload"| node_aes
node_boot_core -->|"reads and updates"| node_shared_memory
node_boot_core -->|"writes flash or jumps"| node_device
node_device -->|"runs application"| node_app_entry
node_app_entry -->|"defines image header"| node_image_format
node_app_entry -->|"updates boot state"| node_shared_memory
node_app_entry -->|"initializes and uses"| node_app_uart
node_app_uart -->|"buffers serial data"| node_app_buffer

click node_app_image "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/app_main.c"
click node_image_format "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Common/image.h"
click node_encrypt "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/encrypt_image.py"
click node_decrypt_tool "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/decrypt_image.py"
click node_flasher_ui "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/Flasher_GUI.py"
click node_flasher "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/main.py"
click node_image_extract "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/image_extract.py"
click node_flasher_utils "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/utils.py"
click node_boot_entry "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Bootloader/boot_main.c"
click node_boot_core "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Bootloader/bootloader.c"
click node_boot_uart "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Bootloader/uart.c"
click node_crc "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Common/crc.c"
click node_aes "https://github.com/erdemefe90/avr-secure-bootloader/tree/main/Bootloader/tiny-AES-c"
click node_shared_memory "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Common/image.h"
click node_app_entry "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/app_main.c"
click node_app_uart "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/uart.c"
click node_app_buffer "https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/circular_buffer.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_encrypt,node_decrypt_tool toneBlue
class node_flasher_ui,node_flasher,node_image_extract,node_flasher_utils toneAmber
class node_boot_entry,node_boot_core,node_boot_uart,node_crc,node_aes toneMint
class node_app_image,node_image_format,node_shared_memory,node_app_entry,node_app_uart,node_app_buffer toneRose
class node_operator,node_serial_port,node_device toneIndigo
```

## Components

### Firmware Packaging

- [Image Encryption](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/encrypt_image.py): `Tools/encrypt_image.py`
- [Image Decryption Tool](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/decrypt_image.py): `Tools/decrypt_image.py`

### Host Flasher

- [Flasher Interface](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/Flasher_GUI.py): `Tools/Flasher/Flasher_GUI.py`
- [Flasher Controller](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/main.py): `Tools/Flasher/main.py`
- [Image Extraction](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/image_extract.py): `Tools/Flasher/image_extract.py`
- [Flasher Utilities](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Tools/Flasher/utils.py): `Tools/Flasher/utils.py`

### Device Bootloader

- [Boot Entry](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Bootloader/boot_main.c): `Bootloader/boot_main.c`
- [Bootloader Core](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Bootloader/bootloader.c): `Bootloader/bootloader.c`
- [Boot UART Protocol](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Bootloader/uart.c): `Bootloader/uart.c`
- [CRC16-CCITT](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Common/crc.c): `Common/crc.c`
- [AES Implementation](https://github.com/erdemefe90/avr-secure-bootloader/tree/main/Bootloader/tiny-AES-c): `Bootloader/tiny-AES-c`

### Application Runtime

- [Application Image](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/app_main.c): `App/app_main.c`
- [Image Metadata](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Common/image.h): `Common/image.h`
- [Shared Boot State](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/Common/image.h): `Common/image.h`
- [Application Runtime](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/app_main.c): `App/app_main.c`
- [Application UART](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/uart.c): `App/uart.c`
- [UART Buffers](https://github.com/erdemefe90/avr-secure-bootloader/blob/main/App/circular_buffer.c): `App/circular_buffer.c`

### Other components

- **Firmware Operator**
- **Serial Port**
- **AVR Device**

## Connections

- Firmware Operator → Image Encryption: selects firmware
- Application Image → Image Encryption: packages image
- Image Metadata → Image Encryption: defines header
- Image Encryption → Flasher Controller: produces update file
- Firmware Operator → Flasher Interface: operates
- Flasher Interface → Flasher Controller: dispatches actions
- Flasher Controller → Image Extraction: requests image parsing
- Image Extraction → Flasher Utilities: checks CRC
- Image Extraction → Flasher Controller: returns update data
- Image Decryption Tool → Image Metadata: reads image metadata
- Flasher Controller → Serial Port: exchanges packets
- Serial Port → Boot UART Protocol: transfers packets
- Boot Entry → Bootloader Core: checks and processes
- Bootloader Core → Boot UART Protocol: reads and transmits
- Boot UART Protocol → CRC16-CCITT: validates packet CRC
- Bootloader Core → AES Implementation: decrypts payload
- Bootloader Core → Shared Boot State: reads and updates
- Bootloader Core → AVR Device: writes flash or jumps
- AVR Device → Application Runtime: runs application
- Application Runtime → Image Metadata: defines image header
- Application Runtime → Shared Boot State: updates boot state
- Application Runtime → Application UART: initializes and uses
- Application UART → UART Buffers: buffers serial data
