# georgik/esp32-graphical-bootloader architecture

> Architecture diagram of the GitHub repository georgik/esp32-graphical-bootloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/georgik/esp32-graphical-bootloader
- Repository: https://github.com/georgik/esp32-graphical-bootloader

## Overview

##### Project type and purpose
- This is an embedded firmware project for ESP32 devices, centered on a third-stage graphical OTA bootloader that lets users pick one of several applications stored in different OTA partitions.

##### File structure
- Top-level:
– CMakeLists.txt, Bootloader.cmake – orchestrate building the bootloader and all apps.
– .github/workflows/build.yml – CI pipeline for building & testing.
– boards/ – board-specific .cfg files.
– partitions.csv – base partition layout.
– resources/images – UI assets for the bootloader.
- main/ – source (graphical_bootloader_main.c, bootloader_ui.c) and idf_component.yml for the bootloader.
- apps/ – five separate ESP-IDF apps (calculator, game_of_life, synth_piano, tic_tac_toe, wifi_list), each with its own CMakeLists.txt, sdkconfig.defaults, idf_component.yml, source file, and partition placement.

##### Extract architecture insights from the README
- The bootloader lives in the “factory” partition and renders a graphical menu on boots.
- Each app is flashed into a distinct OTA partition (ota_0…ota_4) at fixed offsets.
- Upon user selection, the bootloader sets the chosen partition as the next boot partition and reboots.
- Each app, on startup, runs fallback code (esp_ota_set_boot_partition(factory)) so that a subsequent restart returns to the bootloader.
- Build flow: can build all apps at once via Bootloader.cmake or individually with idf.py and esptool/espflash.
- A final merge step combines bootloader, partition table, OTA data, and app binaries into one flashable image.

##### Components
a. Hardware layer
b. Bootloader layer
– Factory partition containing graphical_bootloader_main.c, bootloader_ui.c, image resources.
– Bootloader.cmake orchestrates the build and merging process.
c. Partition management
– partitions.csv defines factory, partition_table, ota_data_initial, ota_0…ota_4.
– OTA manager (esp_ota_ops) sets next-boot partition.
d. Application layer
– Five individual ESP-IDF apps, each in its own ota_X partition:
· tic_tac_toe, wifi_list, calculator, synth_piano, game_of_life
– Each app’s main.c + idf_component.yml + sdkconfig.defaults
– Fallback code to factory partition on startup.
e. Build & deployment pipeline
– CMake (CMakeLists.txt + Bootloader.cmake) and idf.py for configuration & build.
– esptool.py or espflash for flashing binaries to specific addresses.
– .github workflows for CI.
f. Simulation & documentation

##### Relationships & data flows
1. Power-on → bootloader in factory partition reads partitions.csv → renders menu from resources/images.
2. User selects app → bootloader calls esp_ota_set_boot_partition(partition_of_selected_app) → system reset.
3. Device boots into selected app partition → app’s fallback code sets boot partition back to factory → system reset.
4. Device returns to bootloader.
5. Build pipeline ingests board .cfg → generates build artifacts → flash to each partition → optional merge into one combined.bin.

##### Architectural patterns & design principles
- OTA multi-image pattern separating bootloader and applications.
- Partition table for flexible application placement.
- Single-responsibility: bootloader solely manages UI + partition selection; apps focus on their own logic.
- Modular build: common CMake script to build all apps or single apps.
- CI/CD via GitHub Actions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        Board1["esp-box-3.cfg"]:::hardware
        Board2["esp-box.cfg"]:::hardware
        Board3["esp32_p4_function_ev_board.cfg"]:::hardware
        Board4["m5stack_core_s3.cfg"]:::hardware
        HW["ESP32 Device<br/>(Display, Buttons)"]:::hardware
    end

    %% Bootloader Layer
    subgraph "Bootloader Layer"
        BLMain["graphical_bootloader_main.c"]:::bootloader
        BLUI["bootloader_ui.c"]:::bootloader
        BLComp["idf_component.yml"]:::bootloader
        BLRes["resources/images/"]:::bootloader
    end

    %% Partition Management
    subgraph "Partition Management"
        PartTable["partitions.csv"]:::partition
        OTAOps["esp_ota_ops"]:::partition
    end

    %% OTA Partitions
    subgraph "OTA Partitions"
        subgraph "ota_0: tic_tac_toe"
            TT["tic_tac_toe.c"]:::app
            TTComp["apps/tic_tac_toe/main/idf_component.yml"]:::app
            TTCfg["apps/tic_tac_toe/sdkconfig.defaults"]:::app
            TTDiag["apps/tic_tac_toe/diagram.json"]:::simulation
            TTWokwi["apps/tic_tac_toe/wokwi.toml"]:::simulation
        end
        subgraph "ota_1: wifi_list"
            WL["wifi_list.c"]:::app
            WLComp["apps/wifi_list/main/idf_component.yml"]:::app
            WLCfg["apps/wifi_list/sdkconfig.defaults"]:::app
            WLPart["apps/wifi_list/partitions.csv"]:::partition
        end
        subgraph "ota_2: calculator"
            Calc["calculator.c"]:::app
            CalcComp["apps/calculator/main/idf_component.yml"]:::app
            CalcCfg["apps/calculator/sdkconfig.defaults"]:::app
        end
        subgraph "ota_3: synth_piano"
            Synth["synth_piano.c"]:::app
            SynthComp["apps/synth_piano/main/idf_component.yml"]:::app
            SynthCfg["apps/synth_piano/sdkconfig.defaults"]:::app
        end
        subgraph "ota_4: game_of_life"
            GoL["game_of_life.c"]:::app
            GoLComp["apps/game_of_life/main/idf_component.yml"]:::app
            GoLCfg["apps/game_of_life/sdkconfig.defaults"]:::app
        end
    end

    %% Build & Deployment Pipeline
    subgraph "Build & Deployment"
        CI[".github/workflows/build.yml"]:::tool
        CMakeRoot["CMakeLists.txt"]:::tool
        BLcmake["Bootloader.cmake"]:::tool
        IDFPY["idf.py"]:::tool
        Flash["esptool.py / espflash"]:::tool
    end

    %% Simulation & Documentation
    subgraph "Simulation & Documentation"
        SimGlobal["diagram.json / wokwi.toml"]:::simulation
        Doc["doc/esp32-s3-box-3-graphical-bootloader.webp"]:::simulation
    end

    %% Runtime Flow
    HW -->|"Power-On"| BLMain
    BLMain -->|"renders UI"| BLUI
    BLMain -->|"uses table"| PartTable
    BLUI -->|"selects app"| OTAOps
    OTAOps -->|"set next boot"| PartTable
    OTAOps -->|"reset"| HW
    HW -->|"boots into"| TT & WL & Calc & Synth & GoL
    TT & WL & Calc & Synth & GoL -->|"fallback bootloader"| OTAOps
    OTAOps -->|"reset"| HW
    OTAOps --> BLMain

    %% Build Flow
    CI --> CMakeRoot
    CMakeRoot --> BLcmake
    CMakeRoot --> IDFPY
    BLcmake --> Flash
    IDFPY --> Flash
    Flash --> PartTable
    Flash --> TT & WL & Calc & Synth & GoL

    %% Simulation Links
    SimGlobal --> HW
    TTDiag --> TT
    TTWokwi --> TT

    %% Click Events
    click Board1 "https://github.com/georgik/esp32-graphical-bootloader/blob/main/boards/esp-box-3.cfg"
    click Board2 "https://github.com/georgik/esp32-graphical-bootloader/blob/main/boards/esp-box.cfg"
    click Board3 "https://github.com/georgik/esp32-graphical-bootloader/blob/main/boards/esp32_p4_function_ev_board.cfg"
    click Board4 "https://github.com/georgik/esp32-graphical-bootloader/blob/main/boards/m5stack_core_s3.cfg"
    click BLMain "https://github.com/georgik/esp32-graphical-bootloader/blob/main/main/graphical_bootloader_main.c"
    click BLUI "https://github.com/georgik/esp32-graphical-bootloader/blob/main/main/bootloader_ui.c"
    click BLComp "https://github.com/georgik/esp32-graphical-bootloader/blob/main/main/idf_component.yml"
    click BLRes "https://github.com/georgik/esp32-graphical-bootloader/tree/main/resources/images/"
    click PartTable "https://github.com/georgik/esp32-graphical-bootloader/blob/main/partitions.csv"
    click WLPart "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/wifi_list/partitions.csv"
    click TT "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/tic_tac_toe/main/tic_tac_toe.c"
    click TTComp "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/tic_tac_toe/main/idf_component.yml"
    click TTCfg "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/tic_tac_toe/sdkconfig.defaults"
    click WL "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/wifi_list/main/wifi_list.c"
    click WLComp "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/wifi_list/main/idf_component.yml"
    click WLCfg "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/wifi_list/sdkconfig.defaults"
    click Calc "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/calculator/main/calculator.c"
    click CalcComp "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/calculator/main/idf_component.yml"
    click CalcCfg "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/calculator/sdkconfig.defaults"
    click Synth "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/synth_piano/main/synth_piano.c"
    click SynthComp "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/synth_piano/main/idf_component.yml"
    click SynthCfg "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/synth_piano/sdkconfig.defaults"
    click GoL "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/game_of_life/main/game_of_life.c"
    click GoLComp "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/game_of_life/main/idf_component.yml"
    click GoLCfg "https://github.com/georgik/esp32-graphical-bootloader/blob/main/apps/game_of_life/sdkconfig.defaults"
    click CI "https://github.com/georgik/esp32-graphical-bootloader/blob/main/.github/workflows/build.yml"
    click CMakeRoot "https://github.com/georgik/esp32-graphical-bootloader/blob/main/CMakeLists.txt"
    click BLcmake "https://github.com/georgik/esp32-graphical-bootloader/blob/main/Bootloader.cmake"
    click IDFPY "https://github.com/georgik/esp32-graphical-bootloader/blob/main/idf.py"
    click Flash "https://github.com/georgik/esp32-graphical-bootloader/blob/main/esptool.py"
    click SimGlobal "https://github.com/georgik/esp32-graphical-bootloader/blob/main/diagram.json"
    click Doc "https://github.com/georgik/esp32-graphical-bootloader/blob/main/doc/esp32-s3-box-3-graphical-bootloader.webp"

    %% Styles
    classDef hardware fill:#cccccc,stroke:#333,stroke-width:1px
    classDef bootloader fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef partition fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef app fill:#d4edda,stroke:#333,stroke-width:1px
    classDef tool fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef simulation fill:#d1ecf1,stroke:#333,stroke-width:1px
```
