scripts: P4-Nano probe app and C6 esp-hosted OTA tools
p4-probe identifies the P4 and its C6 over esp-hosted SDIO. c6-ota holds the C6 coprocessor build and the two host updaters (3.1 and the 2.x one that moved the factory C6 firmware to esp-hosted 3.1). Also the pending graphify output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
edf35e9c71
commit
ba8e160aee
104 files changed
+8674
-204
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# Simple component selection based on Kconfig
|
||||
if(CONFIG_EH_USE_LEGACY_API)
|
||||
set(_main_src "legacy/main.c")
|
||||
else()
|
||||
set(_main_src "main.c")
|
||||
endif()
|
||||
|
||||
# main.c #if-selects the header of the chosen OTA method's component. Kconfig
|
||||
# values are NOT available during component-requirements expansion, so require
|
||||
# all three method components unconditionally — main.c picks the one to use.
|
||||
idf_component_register(SRCS "${_main_src}"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES esp_hosted console esp_timer
|
||||
PRIV_REQUIRES esp_app_format ota_https ota_littlefs ota_partition)
|
||||
@@ -0,0 +1,137 @@
|
||||
menu "ESP-Hosted Coprocessor OTA Config"
|
||||
|
||||
choice OTA_METHOD
|
||||
prompt "Select OTA Method"
|
||||
default OTA_METHOD_HTTPS
|
||||
help
|
||||
Choose the OTA method for updating slave firmware.
|
||||
|
||||
config OTA_METHOD_HTTPS
|
||||
bool "HTTP OTA"
|
||||
help
|
||||
Download firmware from HTTPS URL
|
||||
|
||||
config OTA_METHOD_LITTLEFS
|
||||
bool "LittleFS OTA"
|
||||
help
|
||||
Read firmware from LittleFS filesystem
|
||||
|
||||
config OTA_METHOD_PARTITION
|
||||
bool "Partition OTA"
|
||||
help
|
||||
Read firmware from dedicated partition
|
||||
|
||||
endchoice
|
||||
|
||||
########### OTA with Partition ########
|
||||
config OTA_PARTITION_LABEL
|
||||
string "Partition Label"
|
||||
depends on OTA_METHOD_PARTITION
|
||||
default "slave_fw"
|
||||
help
|
||||
Label of the partition containing firmware
|
||||
|
||||
########### OTA with Littlefs #########
|
||||
config OTA_DELETE_FILE_AFTER_FLASH
|
||||
depends on OTA_METHOD_LITTLEFS
|
||||
bool "Delete OTA file from LittleFS/FatFS etc, once finished"
|
||||
default y
|
||||
|
||||
########### OTA with HTTPS ############
|
||||
menu "WiFi Connection"
|
||||
depends on OTA_METHOD_HTTPS
|
||||
config ESP_WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "MyWiFiSSID"
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
|
||||
config ESP_WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
default "MyWiFiPass@123"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
|
||||
config ESP_MAXIMUM_RETRY
|
||||
int "Maximum retry"
|
||||
default 5
|
||||
help
|
||||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
|
||||
|
||||
endmenu
|
||||
|
||||
menu "HTTPS OTA Configuration"
|
||||
depends on OTA_METHOD_HTTPS
|
||||
|
||||
config OTA_USE_SELF_SIGNED_CERT
|
||||
bool "Use self-signed certificate (Testing Only)"
|
||||
default n
|
||||
help
|
||||
Enable this ONLY for testing with self-signed certificates.
|
||||
Disable for production use with CA-signed certificates.
|
||||
|
||||
When enabled, the component will use an embedded certificate
|
||||
from certs/server_cert.pem for HTTPS validation.
|
||||
|
||||
When disabled, the component will use the ESP32 CA certificate
|
||||
bundle which supports major CAs like Let's Encrypt, DigiCert, etc.
|
||||
|
||||
config OTA_SKIP_CERT_CN_CHECK
|
||||
bool "Skip certificate Common Name check"
|
||||
depends on OTA_USE_SELF_SIGNED_CERT
|
||||
default n
|
||||
help
|
||||
Skip Common Name validation in self-signed certificates.
|
||||
Only enable if you cannot match the CN with your server IP/hostname.
|
||||
|
||||
WARNING: This reduces security. Use only for testing.
|
||||
|
||||
config OTA_HTTPS_TIMEOUT_MS
|
||||
int "HTTPS connection timeout (milliseconds)"
|
||||
default 30000
|
||||
range 5000 120000
|
||||
help
|
||||
Timeout for HTTPS connection and SSL handshake.
|
||||
Increase if you have slow network or server.
|
||||
|
||||
config OTA_SERVER_URL
|
||||
string "OTA Server URL"
|
||||
default "https://192.168.1.3:8443/firmware.bin"
|
||||
help
|
||||
HTTPS URL of the OTA firmware file.
|
||||
Must start with https://
|
||||
|
||||
endmenu
|
||||
|
||||
########### OTA Verification Options ############
|
||||
menu "OTA Verification Options"
|
||||
|
||||
config OTA_VERSION_CHECK_HOST_SLAVE
|
||||
bool "Host-Slave version compatibility check"
|
||||
default y
|
||||
help
|
||||
Check if host and slave firmware have compatible major.minor versions.
|
||||
If host is X.Y.Z and slave is A.B.C, warn if X.Y != A.B.
|
||||
|
||||
This ensures compatible API versions between host and slave.
|
||||
|
||||
config OTA_VERSION_CHECK_SLAVEFW_SLAVE
|
||||
bool "Skip OTA if slave firmware versions match"
|
||||
default y
|
||||
help
|
||||
Compare current running slave firmware version with new firmware version.
|
||||
Skip OTA if versions are identical to avoid unnecessary updates.
|
||||
|
||||
Disable this to force OTA even when versions match.
|
||||
|
||||
endmenu
|
||||
|
||||
config EH_USE_LEGACY_API
|
||||
bool "Use legacy esp_hosted_* compat-surface main"
|
||||
default n
|
||||
help
|
||||
Build the example from main/legacy/main.c (preserves the
|
||||
esp_hosted_* compat surface) instead of main/main.c (which
|
||||
uses native eh_host_* APIs).
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,16 @@
|
||||
dependencies:
|
||||
cmd_nvs:
|
||||
path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_nvs
|
||||
cmd_system:
|
||||
path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_system
|
||||
espressif/esp_hosted:
|
||||
rules:
|
||||
- if: target in [esp32p4, esp32h2]
|
||||
version: '*'
|
||||
espressif/esp_wifi_remote:
|
||||
rules:
|
||||
- if: target in [esp32p4, esp32h2]
|
||||
- if: idf_version <6.1
|
||||
version: '>=1.3.1'
|
||||
joltwallet/littlefs:
|
||||
version: '*'
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* ESP-Hosted Slave OTA Example
|
||||
* ===========================
|
||||
*
|
||||
* This example demonstrates how to perform Over-The-Air (OTA) updates on the
|
||||
* ESP32 slave device (co-processor) from the ESP32 host device.
|
||||
*
|
||||
* SUPPORTED OTA METHODS:
|
||||
* ----------------------
|
||||
* 1. HTTPS OTA: Download firmware from remote HTTPS URL
|
||||
* 2. LittleFS OTA: Flash firmware stored in ESP32's LittleFS filesystem
|
||||
* 3. Partition OTA: Flash firmware stored in dedicated ESP32 partition
|
||||
*
|
||||
* VERSION CHECKING & VERIFICATIONS:
|
||||
* ---------------------------------
|
||||
* - Host-Slave Compatibility Check (optional, CONFIG_OTA_VERSION_CHECK_HOST_SLAVE):
|
||||
* Compares major.minor versions between host and slave ESP-Hosted stacks
|
||||
* Ensures API compatibility to prevent communication issues
|
||||
*
|
||||
* - Slave Firmware Version Check for Activate API:
|
||||
* Checks if slave supports esp_hosted_slave_ota_activate() (requires v2.6.0+)
|
||||
* API availability determined by: (major > 2) || (major == 2 && minor > 5)
|
||||
*
|
||||
* ESP-HOSTED OTA APIs USED:
|
||||
* -------------------------
|
||||
* Slave OTA APIs (embedded in OTA methods):
|
||||
* - esp_hosted_slave_ota_begin() - Initialize OTA session
|
||||
* - esp_hosted_slave_ota_write() - Write firmware chunks
|
||||
* - esp_hosted_slave_ota_end() - Finalize OTA session
|
||||
*
|
||||
* Slave OTA API (called from main.c):
|
||||
* - esp_hosted_slave_ota_activate() - Activate new firmware (only for current slave FW > v2.5.X)
|
||||
*
|
||||
* OTA METHOD API MAPPING:
|
||||
* -----------------------
|
||||
* ota_https_perform() -> Calls: begin() + write() + end()
|
||||
* ota_littlefs_perform() -> Calls: begin() + write() + end()
|
||||
* ota_partition_perform() -> Calls: begin() + write() + end()
|
||||
*
|
||||
* EXECUTION FLOW:
|
||||
* ---------------
|
||||
* 1. Initialize ESP-Hosted connection
|
||||
* 2. Check version compatibility (optional)
|
||||
* 3. Execute selected OTA method
|
||||
* 4. Conditionally activate new firmware
|
||||
* 5. Restart host for resync
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_event.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_hosted.h"
|
||||
#include "esp_hosted_ota.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_app_desc.h"
|
||||
#include "esp_hosted_api_types.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
#if CONFIG_OTA_METHOD_HTTPS
|
||||
#include "ota_https.h"
|
||||
#elif CONFIG_OTA_METHOD_LITTLEFS
|
||||
#include "ota_littlefs.h"
|
||||
#elif CONFIG_OTA_METHOD_PARTITION
|
||||
#include "ota_partition.h"
|
||||
#endif
|
||||
|
||||
static const char *TAG = "host_performs_slave_ota";
|
||||
|
||||
#ifdef CONFIG_OTA_VERSION_CHECK_HOST_SLAVE
|
||||
/**
|
||||
* @brief Compare host and slave firmware versions
|
||||
*
|
||||
* Compares major.minor versions only (ignoring patch level)
|
||||
*
|
||||
* @return 0 if versions match
|
||||
* -1 if host version > slave version (slave needs upgrade)
|
||||
* 1 if host version < slave version (host needs upgrade)
|
||||
*/
|
||||
static int compare_versions(uint32_t slave_version)
|
||||
{
|
||||
uint32_t host_version = ESP_HOSTED_VERSION_VAL(ESP_HOSTED_VERSION_MAJOR_1,
|
||||
ESP_HOSTED_VERSION_MINOR_1,
|
||||
ESP_HOSTED_VERSION_PATCH_1);
|
||||
|
||||
// Compare major.minor only (ignore patch level)
|
||||
slave_version &= 0xFFFFFF00;
|
||||
host_version &= 0xFFFFFF00;
|
||||
|
||||
if (host_version == slave_version) {
|
||||
return 0; // Versions match
|
||||
} else if (host_version > slave_version) {
|
||||
#ifndef CONFIG_ESP_HOSTED_FW_VERSION_MISMATCH_WARNING_SUPPRESS
|
||||
ESP_LOGW(TAG, "Version mismatch: Host [%u.%u.%u] > Co-proc [%u.%u.%u] ==> Upgrade co-proc to avoid RPC timeouts",
|
||||
ESP_HOSTED_VERSION_PRINTF_ARGS(host_version), ESP_HOSTED_VERSION_PRINTF_ARGS(slave_version));
|
||||
#endif
|
||||
return -1; // Host newer, slave needs upgrade
|
||||
} else {
|
||||
#ifndef CONFIG_ESP_HOSTED_FW_VERSION_MISMATCH_WARNING_SUPPRESS
|
||||
ESP_LOGW(TAG, "Version mismatch: Host [%u.%u.%u] < Co-proc [%u.%u.%u] ==> Upgrade host to avoid compatibility issues",
|
||||
ESP_HOSTED_VERSION_PRINTF_ARGS(host_version), ESP_HOSTED_VERSION_PRINTF_ARGS(slave_version));
|
||||
#endif
|
||||
return 1; // Slave newer, host needs upgrade
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if host and slave firmware versions are compatible
|
||||
*
|
||||
* @return 0 if versions are compatible (OTA not needed)
|
||||
* -1 if slave needs upgrade
|
||||
* 1 if host needs upgrade
|
||||
*/
|
||||
static int check_version_compatibility(void)
|
||||
{
|
||||
esp_hosted_coprocessor_fwver_t slave_version = {0};
|
||||
esp_err_t ret = esp_hosted_get_coprocessor_fwversion(&slave_version);
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Could not get slave firmware version (error: %s)", esp_err_to_name(ret));
|
||||
ESP_LOGW(TAG, "Proceeding without version compatibility check");
|
||||
return -1; // Assume upgrade needed
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Host firmware version: %d.%d.%d",
|
||||
ESP_HOSTED_VERSION_MAJOR_1, ESP_HOSTED_VERSION_MINOR_1, ESP_HOSTED_VERSION_PATCH_1);
|
||||
ESP_LOGI(TAG, "Slave firmware version: %" PRIu32 ".%" PRIu32 ".%" PRIu32,
|
||||
slave_version.major1, slave_version.minor1, slave_version.patch1);
|
||||
|
||||
uint32_t slave_ver = ESP_HOSTED_VERSION_VAL(slave_version.major1,
|
||||
slave_version.minor1,
|
||||
slave_version.patch1);
|
||||
return compare_versions(slave_ver);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Execute OTA update based on configured method
|
||||
*
|
||||
* Supports three OTA methods:
|
||||
* - HTTPS: Download firmware from URL
|
||||
* - LittleFS: Flash firmware from filesystem
|
||||
* - Partition: Flash firmware from partition
|
||||
*
|
||||
* @return ESP_HOSTED_SLAVE_OTA_COMPLETED if successful
|
||||
* ESP_HOSTED_SLAVE_OTA_NOT_REQUIRED if not needed
|
||||
* Error code otherwise
|
||||
*/
|
||||
static int perform_slave_ota(void)
|
||||
{
|
||||
#if CONFIG_OTA_METHOD_HTTPS
|
||||
ESP_LOGW(TAG, "Starting OTA via HTTPS");
|
||||
ESP_LOGW(TAG, "URL: %s", CONFIG_OTA_SERVER_URL);
|
||||
return ota_https_perform(CONFIG_OTA_SERVER_URL);
|
||||
|
||||
#elif CONFIG_OTA_METHOD_LITTLEFS
|
||||
uint8_t delete_after_flash = 0;
|
||||
|
||||
ESP_LOGW(TAG, "Starting OTA via LittleFS");
|
||||
#ifdef CONFIG_OTA_DELETE_FILE_AFTER_FLASH
|
||||
delete_after_flash = 1;
|
||||
#endif
|
||||
return ota_littlefs_perform(delete_after_flash);
|
||||
|
||||
#elif CONFIG_OTA_METHOD_PARTITION
|
||||
ESP_LOGW(TAG, "Starting OTA via Partition");
|
||||
ESP_LOGW(TAG, "Partition label: %s", CONFIG_OTA_PARTITION_LABEL);
|
||||
return ota_partition_perform(CONFIG_OTA_PARTITION_LABEL);
|
||||
|
||||
#else
|
||||
ESP_LOGE(TAG, "No OTA method configured!");
|
||||
return ESP_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Activate new firmware and restart host
|
||||
*
|
||||
* Checks if slave firmware supports activate API (v2.6.0+)
|
||||
* If supported, activates the new firmware
|
||||
* Then restarts the host to resync with slave
|
||||
*/
|
||||
static void activate_and_restart(void)
|
||||
{
|
||||
bool activate_supported = false;
|
||||
esp_hosted_coprocessor_fwver_t slave_version = {0};
|
||||
|
||||
// Check if activate API is available (v2.6.0+)
|
||||
if (esp_hosted_get_coprocessor_fwversion(&slave_version) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Slave firmware version: %" PRIu32 ".%" PRIu32 ".%" PRIu32,
|
||||
slave_version.major1, slave_version.minor1, slave_version.patch1);
|
||||
|
||||
if ((slave_version.major1 > 2) ||
|
||||
(slave_version.major1 == 2 && slave_version.minor1 > 5)) {
|
||||
activate_supported = true;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Could not detect slave version");
|
||||
}
|
||||
|
||||
// Activate new firmware if supported
|
||||
if (activate_supported) {
|
||||
esp_err_t ret = esp_hosted_slave_ota_activate();
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGI(TAG, "New firmware activated - slave will reboot");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to activate firmware: %s", esp_err_to_name(ret));
|
||||
}
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Activate API not supported (requires v2.6.0+)");
|
||||
}
|
||||
|
||||
// Restart host to resync with slave
|
||||
ESP_LOGW(TAG, "Restarting host to resync with slave...");
|
||||
|
||||
esp_err_t deinit_rc = esp_hosted_deinit();
|
||||
if (deinit_rc != ESP_OK) {
|
||||
ESP_LOGW(TAG, "esp_hosted_deinit failed before restart: %s",
|
||||
esp_err_to_name(deinit_rc));
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main application entry point
|
||||
*
|
||||
* Flow:
|
||||
* 1. Initialize ESP-Hosted
|
||||
* 2. Check version compatibility (optional)
|
||||
* 3. Perform OTA if needed
|
||||
* 4. Activate and restart
|
||||
*/
|
||||
void app_main(void)
|
||||
{
|
||||
// Step 1: Initialize system
|
||||
ESP_LOGI(TAG, "Initializing ESP-Hosted...");
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(esp_hosted_init());
|
||||
ESP_ERROR_CHECK(esp_hosted_connect_to_slave());
|
||||
ESP_LOGI(TAG, "ESP-Hosted initialized successfully");
|
||||
|
||||
// Step 2: Check version compatibility (if enabled)
|
||||
#ifdef CONFIG_OTA_VERSION_CHECK_HOST_SLAVE
|
||||
int version_check = check_version_compatibility();
|
||||
if (version_check == 0) {
|
||||
ESP_LOGI(TAG, "Versions compatible - OTA not required");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Step 3: Perform OTA update
|
||||
ESP_LOGI(TAG, "Starting slave OTA update...");
|
||||
int ret = perform_slave_ota();
|
||||
|
||||
// Step 4: Handle OTA result
|
||||
if (ret == ESP_HOSTED_SLAVE_OTA_COMPLETED) {
|
||||
ESP_LOGI(TAG, "OTA completed successfully!");
|
||||
activate_and_restart();
|
||||
} else if (ret == ESP_HOSTED_SLAVE_OTA_NOT_REQUIRED) {
|
||||
ESP_LOGI(TAG, "OTA not required - slave firmware is up to date");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "OTA failed with error: %s", esp_err_to_name(ret));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* Native eh_host_* API; legacy compat under main/legacy/main.c. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_event.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_err.h"
|
||||
#include "eh_host.h"
|
||||
#include "eh_host_core.h"
|
||||
#include "eh_host_cp_ota.h"
|
||||
#include "eh_host_api_types.h"
|
||||
#include "eh_host_sys.h"
|
||||
#include "esp_hosted_host_fw_ver.h"
|
||||
#include "esp_hosted_ota.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_app_desc.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
#if CONFIG_OTA_METHOD_HTTPS
|
||||
#include "ota_https.h"
|
||||
#elif CONFIG_OTA_METHOD_LITTLEFS
|
||||
#include "ota_littlefs.h"
|
||||
#elif CONFIG_OTA_METHOD_PARTITION
|
||||
#include "ota_partition.h"
|
||||
#endif
|
||||
|
||||
static const char *TAG = "host_performs_slave_ota";
|
||||
|
||||
#ifdef CONFIG_OTA_VERSION_CHECK_HOST_SLAVE
|
||||
/* 0 = match, -1 = host newer, 1 = slave newer. major.minor only. */
|
||||
static int compare_versions(uint32_t slave_version)
|
||||
{
|
||||
uint32_t host_version = ESP_HOSTED_VERSION_VAL(ESP_HOSTED_VERSION_MAJOR_1,
|
||||
ESP_HOSTED_VERSION_MINOR_1,
|
||||
ESP_HOSTED_VERSION_PATCH_1);
|
||||
|
||||
slave_version &= 0xFFFFFF00;
|
||||
host_version &= 0xFFFFFF00;
|
||||
|
||||
if (host_version == slave_version) {
|
||||
return 0;
|
||||
} else if (host_version > slave_version) {
|
||||
#ifndef CONFIG_ESP_HOSTED_FW_VERSION_MISMATCH_WARNING_SUPPRESS
|
||||
ESP_LOGW(TAG, "Version mismatch: Host [%u.%u.%u] > Co-proc [%u.%u.%u] ==> Upgrade co-proc to avoid RPC timeouts",
|
||||
ESP_HOSTED_VERSION_PRINTF_ARGS(host_version), ESP_HOSTED_VERSION_PRINTF_ARGS(slave_version));
|
||||
#endif
|
||||
return -1;
|
||||
} else {
|
||||
#ifndef CONFIG_ESP_HOSTED_FW_VERSION_MISMATCH_WARNING_SUPPRESS
|
||||
ESP_LOGW(TAG, "Version mismatch: Host [%u.%u.%u] < Co-proc [%u.%u.%u] ==> Upgrade host to avoid compatibility issues",
|
||||
ESP_HOSTED_VERSION_PRINTF_ARGS(host_version), ESP_HOSTED_VERSION_PRINTF_ARGS(slave_version));
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int check_version_compatibility(void)
|
||||
{
|
||||
eh_host_coprocessor_fwver_t slave_version = {0};
|
||||
esp_err_t ret = eh_host_sys_get_cp_fw_version(&slave_version);
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Could not get slave firmware version (error: %s)", esp_err_to_name(ret));
|
||||
ESP_LOGW(TAG, "Proceeding without version compatibility check");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Host firmware version: %d.%d.%d",
|
||||
ESP_HOSTED_VERSION_MAJOR_1, ESP_HOSTED_VERSION_MINOR_1, ESP_HOSTED_VERSION_PATCH_1);
|
||||
ESP_LOGI(TAG, "Slave firmware version: %" PRIu32 ".%" PRIu32 ".%" PRIu32,
|
||||
slave_version.major1, slave_version.minor1, slave_version.patch1);
|
||||
|
||||
uint32_t slave_ver = ESP_HOSTED_VERSION_VAL(slave_version.major1,
|
||||
slave_version.minor1,
|
||||
slave_version.patch1);
|
||||
return compare_versions(slave_ver);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int perform_slave_ota(void)
|
||||
{
|
||||
#if CONFIG_OTA_METHOD_HTTPS
|
||||
ESP_LOGW(TAG, "Starting OTA via HTTPS");
|
||||
ESP_LOGW(TAG, "URL: %s", CONFIG_OTA_SERVER_URL);
|
||||
return ota_https_perform(CONFIG_OTA_SERVER_URL);
|
||||
|
||||
#elif CONFIG_OTA_METHOD_LITTLEFS
|
||||
uint8_t delete_after_flash = 0;
|
||||
|
||||
ESP_LOGW(TAG, "Starting OTA via LittleFS");
|
||||
#ifdef CONFIG_OTA_DELETE_FILE_AFTER_FLASH
|
||||
delete_after_flash = 1;
|
||||
#endif
|
||||
return ota_littlefs_perform(delete_after_flash);
|
||||
|
||||
#elif CONFIG_OTA_METHOD_PARTITION
|
||||
ESP_LOGW(TAG, "Starting OTA via Partition");
|
||||
ESP_LOGW(TAG, "Partition label: %s", CONFIG_OTA_PARTITION_LABEL);
|
||||
return ota_partition_perform(CONFIG_OTA_PARTITION_LABEL);
|
||||
|
||||
#else
|
||||
ESP_LOGE(TAG, "No OTA method configured!");
|
||||
return ESP_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Activates new firmware (slave v2.6.0+) and restarts host to resync. */
|
||||
static void activate_and_restart(void)
|
||||
{
|
||||
bool activate_supported = false;
|
||||
eh_host_coprocessor_fwver_t slave_version = {0};
|
||||
|
||||
if (eh_host_sys_get_cp_fw_version(&slave_version) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Slave firmware version: %" PRIu32 ".%" PRIu32 ".%" PRIu32,
|
||||
slave_version.major1, slave_version.minor1, slave_version.patch1);
|
||||
|
||||
if ((slave_version.major1 > 2) ||
|
||||
(slave_version.major1 == 2 && slave_version.minor1 > 5)) {
|
||||
activate_supported = true;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Could not detect slave version");
|
||||
}
|
||||
|
||||
if (activate_supported) {
|
||||
esp_err_t ret = eh_host_cp_ota_activate();
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGI(TAG, "New firmware activated - slave will reboot");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to activate firmware: %s", esp_err_to_name(ret));
|
||||
}
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Activate API not supported (requires v2.6.0+)");
|
||||
}
|
||||
|
||||
ESP_LOGW(TAG, "Restarting host to resync with slave...");
|
||||
|
||||
esp_err_t deinit_rc = eh_host_deinit();
|
||||
if (deinit_rc != ESP_OK) {
|
||||
ESP_LOGW(TAG, "eh_host_deinit failed before restart: %s",
|
||||
esp_err_to_name(deinit_rc));
|
||||
}
|
||||
|
||||
/* Must outlast the coprocessor's OTA_ACTIVATE_RESTART_TIMEOUT plus its
|
||||
* boot, measured at ~600 ms. Resetting it inside the pending-verify
|
||||
* window makes BOOTLOADER_APP_ROLLBACK revert the update, and the OTA
|
||||
* silently does not stick. */
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing ESP-Hosted...");
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(eh_host_init(NULL));
|
||||
ESP_ERROR_CHECK(eh_host_connect_to_slave());
|
||||
ESP_LOGI(TAG, "ESP-Hosted initialized successfully");
|
||||
|
||||
#ifdef CONFIG_OTA_VERSION_CHECK_HOST_SLAVE
|
||||
int version_check = check_version_compatibility();
|
||||
if (version_check == 0) {
|
||||
ESP_LOGI(TAG, "Versions compatible - OTA not required");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Starting slave OTA update...");
|
||||
int ret = perform_slave_ota();
|
||||
|
||||
if (ret == ESP_HOSTED_SLAVE_OTA_COMPLETED) {
|
||||
ESP_LOGI(TAG, "OTA completed successfully!");
|
||||
activate_and_restart();
|
||||
} else if (ret == ESP_HOSTED_SLAVE_OTA_NOT_REQUIRED) {
|
||||
ESP_LOGI(TAG, "OTA not required - slave firmware is up to date");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "OTA failed with error: %s", esp_err_to_name(ret));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user