The `:feature:firmware` module provides a unified interface for updating Meshtastic devices across different platforms and connection types.
### Supported Platforms & Methods
Meshtastic-Android supports three primary firmware update flows:
#### 1. ESP32 Unified OTA (WiFi & BLE)
Used for modern ESP32 devices (e.g., Heltec V3, T-Beam S3). This method utilizes the **Unified OTA Protocol**, which enables high-speed transfers over TCP (port 3232) or BLE. The BLE transport uses the **Nordic Semiconductor Kotlin-BLE-Library** for architectural consistency with the rest of the application.
**Key Features:**
- **Pre-shared Hash Verification**: The app sends the firmware SHA256 hash in an initial `AdminMessage` trigger. The device stores this in NVS and verifies the incoming stream against it.
- **Connection Retry**: Robust logic to wait for the device to reboot and start the OTA listener.
The standard update method for nRF52-based devices (e.g., RAK4631). It leverages the **Nordic Semiconductor DFU library**.
```mermaid
sequenceDiagram
participant App as Android App
participant Radio as Mesh Node
participant DFU as nRF DFU Bootloader
App->>Radio: Trigger DFU Mode
Radio->>Radio: Reboot into Bootloader
App->>DFU: Connect via BLE
App->>DFU: Initialize DFU Transaction
loop Transfer
App->>DFU: Stream ZIP Segments
DFU-->>App: Progress
end
DFU->>DFU: Verify, Swap & Reboot
```
#### 3. USB / UF2 (RP2040, nRF52, STM32)
For devices supporting USB Mass Storage updates. The app triggers the device into its native bootloader mode, then guides the user to save the UF2 firmware file to the mounted drive.
```mermaid
sequenceDiagram
participant App as Android App
participant Radio as Mesh Node
participant USB as USB Mass Storage
App->>Radio: rebootToDfu()
Radio->>Radio: Mounts as MESH_DRIVE
App->>App: Prompt User to Save UF2
App->>USB: Write firmware.uf2
USB->>USB: Auto-Flash & Reboot
```
### Key Classes
-`UpdateHandler.kt`: Entry point for choosing the correct handler.
-`Esp32OtaUpdateHandler.kt`: Orchestrates the Unified OTA flow.
-`WifiOtaTransport.kt`: Implements the TCP/UDP transport logic for ESP32.
-`BleOtaTransport.kt`: Implements the BLE transport logic for ESP32 using the Nordic BLE library.
-`FirmwareRetriever.kt`: Handles downloading and extracting firmware assets (ZIP/BIN/UF2).