#pragma once /* ota_self.h — Balance self-OTA (bd-18nb) * * Downloads balance-firmware.bin from Gitea release URL to the inactive * OTA partition, verifies SHA256, sets boot partition, reboots. * Auto-rollback if health check not called within ROLLBACK_WINDOW_S seconds. */ #include #include #define OTA_ROLLBACK_WINDOW_S 30 typedef enum { OTA_SELF_IDLE = 0, OTA_SELF_CHECKING, /* (unused — gitea_ota handles this) */ OTA_SELF_DOWNLOADING, OTA_SELF_VERIFYING, OTA_SELF_APPLYING, OTA_SELF_REBOOTING, OTA_SELF_FAILED, } ota_self_state_t; extern volatile ota_self_state_t g_ota_self_state; extern volatile uint8_t g_ota_self_progress; /* 0-100 % */ /* Trigger a Balance self-update. * Uses g_balance_update (from gitea_ota). Non-blocking: starts in a task. * Returns false if no update available or OTA already in progress. */ bool ota_self_trigger(void); /* Called from app_main after boot to mark the running image as valid. * Must be called within OTA_ROLLBACK_WINDOW_S after boot or rollback fires. */ void ota_self_health_check(void);