# kdt-fibonacci/fota-reprogramming architecture

> Architecture diagram of the GitHub repository kdt-fibonacci/fota-reprogramming, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kdt-fibonacci/fota-reprogramming
- Repository: https://github.com/kdt-fibonacci/fota-reprogramming

## Overview

1. This repo is not a single application; it is a distributed FOTA system with four main deployables: three Infineon AURIX TC375 ECU firmwares, a Linux-based FOTA server, and a Raspberry Pi 4 “master” controller.

2. The three ECU projects are separate firmware trees under `Ecu_Gateway_TC375_LK`, `Ecu_Lighting_TC375_LK`, and `Ecu_Motion_TC375_LK`. They share the same platform structure: `Configurations`, `Basics`, `Libraries`, `Utils`, and `Cpu0_Main.c` / `Cpu1_Main.c` / `Cpu2_Main.c`, which reflects the multicore TriCore startup model.

3. The communication layer is built as an AUTOSAR-like stack. At the bottom are CAN and Ethernet drivers; above them sit `CanIf`, `CanTp`, `PduR`, `SoAd`, `LwIP`, `DoIP`, and `Dcm`. This is the main transport boundary between update control traffic and ECU application logic.

4. Ethernet-specific pieces matter here: the projects include `LwIP` and a DP83825I PHY driver, so the system can carry diagnostics/update traffic over IP/DoIP as well as over CAN. The gateway project is especially important as the bridge between in-vehicle network traffic and Ethernet-facing diagnostics.

5. The lighting and motion ECUs add a dedicated reprogramming subsystem under `Basics/Reprogram`. That layer contains the FOTA orchestration (`FotaHandler`), update engine, swap/diagnostic logic, CRC checking, and flash access. Architecturally, this is the “local update executor” that validates and installs an image after it is delivered by the comm stack.

6. The gateway project is more network-oriented and includes test entry points such as `Tests/Cpu0_Main_Gateway_MockFotaMaster.c` and `Tests/Cpu0_Main_Target_Gw.c`, which suggests it can be built in alternate modes for integration testing or role swapping.

7. The reusable hardware/platform boundary is isolated under `Libraries`. These include Infineon iLLD drivers, SFR/register definitions, compiler abstractions, pin maps, and common service modules. In the diagram, this is the vendor/HAL layer beneath the ECU-specific application code.

8. `Utils` and `Basics/SchM` provide cross-cutting runtime support such as timing, logging/debug configuration, and scheduler management. These are not the business logic; they are the shared runtime scaffolding used by the ECU cores and communication stacks.

9. The Linux server in `FOTA_Linux_Server` is the backend control plane. Its C sources are split into `crypto`, `file`, `logger`, `mqtt_handler`, `ota`, `server`, and `utils`, with a small dashboard UI under `dashboard/`. This node likely handles package intake, storage, authentication/verification, and external command/control.

10. The Raspberry Pi project in `FOTA_Master_RPI4` is the orchestrator/edge gateway. It includes `ota_comm.cpp`, `ota_security.cpp`, and `ota_uds_engine.cpp`, plus an LCD UI and monitor subsystem. It also ships `ecu_versions.json` and `public.pem`, which suggests it tracks ECU firmware versions and performs public-key-based trust or verification.

11. The end-to-end data flow is: operator uploads or manages an artifact through the Linux server/dashboard, the server stores and validates it, the Raspberry Pi master coordinates the update session, and the target ECU receives the image through CAN or Ethernet diagnostics, then performs verify/swap/flash/reboot locally.

12. The README’s state-machine image is important architecturally: update handling is explicitly state-driven rather than a single linear procedure. For a diagram, model the system around states such as idle, prepare, transfer, verify, swap, and restart, with transitions driven by the master/server and completed by the ECU reprogramming layer.

13. A clean diagram would show hard boundaries around: embedded ECU runtime, network/diagnostics transport, local flash/update executor, backend server, and Raspberry Pi orchestrator. The communication paths between those boundaries are the key architecture of this repo.

Main entry points: [`FOTA_Master_RPI4/main.cpp`](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/main.cpp) (Master core), [`Ecu_Lighting_TC375_LK/Basics/Reprogram`](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/Reprogram) (Reprogramming), [`FOTA_Linux_Server/src`](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/FOTA_Linux_Server/src) (Server app), [`Ecu_Lighting_TC375_LK/Basics/ComStack`](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/ComStack) (Com stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_ecu["ECU firmware"]
  node_n_ecu_shared["Shared ECU core<br/>TC375 platform"]
  node_n_ecu_comm["Com stack<br/>diag transport"]
  node_n_ecu_reprog["Reprogramming<br/>fota executor"]
  node_n_ecu_vendor["Vendor HAL<br/>iLLD/SFR"]
  node_n_ecu_runtime["Runtime support<br/>schm/utils"]
  node_n_ecu_lighting["Lighting ECU<br/>ECU firmware"]
  node_n_ecu_motion["Motion ECU<br/>ECU firmware"]
  node_n_stack_can["CAN layer<br/>bus stack"]
  node_n_stack_eth["Ethernet path<br/>ip stack"]
  node_n_reprog_state(("Update states<br/>state machine<br/>[FotaHandler.c]"))
  node_n_reprog_flash["Flash access<br/>flash/CRC"]
end

subgraph group_grp_gateway["Gateway ECU"]
  node_n_ecu_gateway["Gateway app<br/>network ECU"]
end

subgraph group_grp_backend["Backend control"]
  node_n_server_app["Server app<br/>linux backend"]
  node_n_server_dash["Dashboard<br/>web UI"]
  node_n_server_security["Crypto/files<br/>backend services<br/>[crypto.c]"]
  node_n_server_control["MQTT/server<br/>control plane<br/>[mqtt_handler.c]"]
end

subgraph group_grp_rpi["Edge master"]
  node_n_rpi_core["Master core<br/>rpi orchestrator<br/>[main.cpp]"]
  node_n_rpi_comm["OTA comm<br/>session control<br/>[ota_comm.cpp]"]
  node_n_rpi_security["OTA security<br/>trust/keys<br/>[ota_security.cpp]"]
  node_n_rpi_uds["UDS engine<br/>diag client<br/>[ota_uds_engine.cpp]"]
  node_n_rpi_ui["LCD monitor<br/>edge UI"]
end

node_n_ecu_shared -->|"hosts"| node_n_ecu_comm
node_n_ecu_shared -->|"hosts"| node_n_ecu_reprog
node_n_ecu_shared -->|"depends on"| node_n_ecu_vendor
node_n_ecu_shared -->|"uses"| node_n_ecu_runtime
node_n_ecu_comm -->|"CAN"| node_n_stack_can
node_n_ecu_comm -->|"Ethernet/IP"| node_n_stack_eth
node_n_stack_eth -->|"delivers updates"| node_n_ecu_reprog
node_n_stack_can -->|"delivers updates"| node_n_ecu_reprog
node_n_ecu_reprog -->|"drives"| node_n_reprog_state
node_n_reprog_state -->|"executes"| node_n_reprog_flash
node_n_ecu_gateway -->|"bridges"| node_n_stack_eth
node_n_ecu_gateway -->|"routes"| node_n_stack_can
node_n_ecu_gateway -->|"shares platform"| node_n_ecu_shared
node_n_server_dash -->|"feeds"| node_n_server_app
node_n_server_app -->|"validates"| node_n_server_security
node_n_server_app -->|"orchestrates"| node_n_server_control
node_n_server_app -->|"publishes artifacts"| node_n_rpi_core
node_n_rpi_core -->|"coordinates"| node_n_rpi_comm
node_n_rpi_core -->|"verifies"| node_n_rpi_security
node_n_rpi_core -->|"drives"| node_n_rpi_uds
node_n_rpi_core -->|"reports"| node_n_rpi_ui
node_n_rpi_comm -->|"talks to"| node_n_ecu_comm
node_n_rpi_uds -->|"triggers"| node_n_ecu_reprog
node_n_server_control -->|"commands"| node_n_rpi_core

click node_n_ecu_comm "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/ComStack"
click node_n_ecu_reprog "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/Reprogram"
click node_n_ecu_vendor "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Libraries"
click node_n_ecu_runtime "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/SchM"
click node_n_ecu_gateway "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Gateway_TC375_LK"
click node_n_ecu_lighting "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK"
click node_n_ecu_motion "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Motion_TC375_LK"
click node_n_stack_can "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/ComStack/Can"
click node_n_stack_eth "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/ComStack/DoIP"
click node_n_reprog_state "https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/Ecu_Lighting_TC375_LK/Basics/Reprogram/FotaHandler.c"
click node_n_reprog_flash "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/Reprogram/Flash"
click node_n_server_app "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/FOTA_Linux_Server/src"
click node_n_server_dash "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/FOTA_Linux_Server/dashboard"
click node_n_server_security "https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Linux_Server/src/crypto.c"
click node_n_server_control "https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Linux_Server/src/mqtt_handler.c"
click node_n_rpi_core "https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/main.cpp"
click node_n_rpi_comm "https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/ota_comm.cpp"
click node_n_rpi_security "https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/ota_security.cpp"
click node_n_rpi_uds "https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/ota_uds_engine.cpp"
click node_n_rpi_ui "https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/FOTA_Master_RPI4/lcd"

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_n_ecu_shared,node_n_ecu_comm,node_n_ecu_reprog,node_n_ecu_vendor,node_n_ecu_runtime,node_n_ecu_lighting,node_n_ecu_motion,node_n_stack_can,node_n_stack_eth,node_n_reprog_state,node_n_reprog_flash toneBlue
class node_n_ecu_gateway toneAmber
class node_n_server_app,node_n_server_dash,node_n_server_security,node_n_server_control toneMint
class node_n_rpi_core,node_n_rpi_comm,node_n_rpi_security,node_n_rpi_uds,node_n_rpi_ui toneRose
```

## Components

### ECU firmware

Three AURIX TC375 firmware trees with shared embedded structure.

- **Shared ECU core**: TC375 platform · Common embedded scaffold: configuration, multicore startup, runtime support, and vendor HAL.
- [Com stack](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/ComStack): diag transport · AUTOSAR-like transport stack spanning CAN and Ethernet diagnostics/update traffic. · `Ecu_Lighting_TC375_LK/Basics/ComStack`
- [Reprogramming](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/Reprogram): fota executor · Local update executor that verifies, swaps, flashes, and reboots after delivery. · `Ecu_Lighting_TC375_LK/Basics/Reprogram`
- [Vendor HAL](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Libraries): iLLD/SFR · Reusable hardware boundary with Infineon iLLD, SFRs, compiler abstractions, pin maps, and common services. · `Ecu_Lighting_TC375_LK/Libraries`
- [Runtime support](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/SchM): schm/utils · Cross-cutting timing, logging, debug, and scheduler scaffolding used by ECU cores and stacks. · `Ecu_Lighting_TC375_LK/Basics/SchM`
- [Lighting ECU](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK): ECU firmware · Lighting-target firmware tree with communication stack and local FOTA executor. · `Ecu_Lighting_TC375_LK`
- [Motion ECU](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Motion_TC375_LK): ECU firmware · Motion-target firmware tree with communication stack and local FOTA executor. · `Ecu_Motion_TC375_LK`
- [CAN layer](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/ComStack/Can): bus stack · CAN driver, interface, and transport layers for in-vehicle diagnostics and update traffic. · `Ecu_Lighting_TC375_LK/Basics/ComStack/Can`
- [Ethernet path](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/ComStack/DoIP): ip stack · Ethernet-facing diagnostics path including GETH/PHY, LwIP, SoAd, DoIP, and DCM integration. · `Ecu_Lighting_TC375_LK/Basics/ComStack/DoIP`
- [Update states](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/Ecu_Lighting_TC375_LK/Basics/Reprogram/FotaHandler.c): state machine · State-driven update flow: idle, prepare, transfer, verify, swap, and restart. · `Ecu_Lighting_TC375_LK/Basics/Reprogram/FotaHandler.c`
- [Flash access](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Lighting_TC375_LK/Basics/Reprogram/Flash): flash/CRC · Flash programming, swap diagnostics, CRC validation, and update-core logic. · `Ecu_Lighting_TC375_LK/Basics/Reprogram/Flash`

### Gateway ECU

Network-oriented ECU variant with alternate test entry points.

- [Gateway app](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/Ecu_Gateway_TC375_LK): network ECU · Gateway firmware role and its alternate build/test entry points for integration and role swapping. · `Ecu_Gateway_TC375_LK`

### Backend control

Linux server and dashboard for artifact intake and orchestration.

- [Server app](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/FOTA_Linux_Server/src): linux backend · Linux-based control plane for package intake, storage, validation, and orchestration. · `FOTA_Linux_Server/src`
- [Dashboard](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/FOTA_Linux_Server/dashboard): web UI · Operator UI used to upload and manage firmware artifacts. · `FOTA_Linux_Server/dashboard`
- [Crypto/files](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Linux_Server/src/crypto.c): backend services · Authentication, verification, artifact storage, logging, and utility services. · `FOTA_Linux_Server/src/crypto.c`
- [MQTT/server](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Linux_Server/src/mqtt_handler.c): control plane · External command/control and session coordination surfaces. · `FOTA_Linux_Server/src/mqtt_handler.c`

### Edge master

Raspberry Pi controller that coordinates the update session.

- [Master core](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/main.cpp): rpi orchestrator · Raspberry Pi controller that coordinates the end-to-end OTA session. · `FOTA_Master_RPI4/main.cpp`
- [OTA comm](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/ota_comm.cpp): session control · Edge-side communication layer that drives update sessions toward ECUs. · `FOTA_Master_RPI4/ota_comm.cpp`
- [OTA security](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/ota_security.cpp): trust/keys · Security and trust handling, including public-key material for verification. · `FOTA_Master_RPI4/ota_security.cpp`
- [UDS engine](https://github.com/kdt-fibonacci/fota-reprogramming/blob/main/FOTA_Master_RPI4/ota_uds_engine.cpp): diag client · Diagnostic/update session engine used by the master to talk to targets. · `FOTA_Master_RPI4/ota_uds_engine.cpp`
- [LCD monitor](https://github.com/kdt-fibonacci/fota-reprogramming/tree/main/FOTA_Master_RPI4/lcd): edge UI · LCD UI and monitor subsystem for operator feedback and state display. · `FOTA_Master_RPI4/lcd`

## Connections

- Shared ECU core → Com stack: hosts · Shared ECU runtime embeds the transport stack.
- Shared ECU core → Reprogramming: hosts · Lighting and motion ECUs add local FOTA execution on top of shared runtime.
- Shared ECU core → Vendor HAL: depends on · Common firmware relies on vendor HAL and platform services.
- Shared ECU core → Runtime support: uses · Scheduler, timing, and debug scaffolding underpin the embedded cores.
- Com stack → CAN layer: CAN · Bus diagnostics and update traffic flow through CAN layers.
- Com stack → Ethernet path: Ethernet/IP · DoIP and Ethernet diagnostics flow through the IP path.
- Ethernet path → Reprogramming: delivers updates · Ethernet diagnostics carry image transfer into the local executor.
- CAN layer → Reprogramming: delivers updates · CAN transport can deliver update payloads to the executor.
- Reprogramming → Update states: drives · Update handling is explicitly state-driven.
- Update states → Flash access: executes · State transitions culminate in verify, swap, and flash operations.
- Gateway app → Ethernet path: bridges · Gateway is the main bridge between in-vehicle traffic and Ethernet-facing diagnostics.
- Gateway app → CAN layer: routes · Gateway firmware also participates in CAN-side routing and role swapping.
- Gateway app → Shared ECU core: shares platform · Gateway follows the same multicore/platform structure as other ECUs.
- Dashboard → Server app: feeds · Operator uploads and dashboard actions feed the backend control plane.
- Server app → Crypto/files: validates · Backend applies crypto, file handling, logging, and utility services.
- Server app → MQTT/server: orchestrates · Server exposes control-plane coordination for OTA workflows.
- Server app → Master core: publishes artifacts · Backend supplies versioned firmware packages to the edge master.
- Master core → OTA comm: coordinates · Master core runs the OTA communication session.
- Master core → OTA security: verifies · Master uses local trust material and security routines.
- Master core → UDS engine: drives · Master invokes the UDS engine for diagnostics/update transport.
- Master core → LCD monitor: reports · Master surfaces session state to the LCD monitor/UI.
- OTA comm → Com stack: talks to · Edge master exchanges diagnostics/update traffic with ECU comm stacks.
- UDS engine → Reprogramming: triggers · UDS session commands trigger local prepare/transfer/verify/swap actions.
- MQTT/server → Master core: commands · Backend control plane can initiate or supervise master sessions.
