Merge branch 'rmaker/decouple_rcp_update' into 'master'

esp_rainmaker: decouple esp_rcp_update from esp_rainmaker

See merge request app-frameworks/esp-rainmaker!600
This commit is contained in:
Piyush Shah
2025-12-08 01:56:44 +05:30
8 changed files with 22 additions and 88 deletions

View File

@@ -1,5 +1,5 @@
## IDF Component Manager Manifest File
version: "1.7.9"
version: "1.8.0"
description: ESP RainMaker firmware agent
url: https://github.com/espressif/esp-rainmaker/tree/master/components/esp_rainmaker
repository: https://github.com/espressif/esp-rainmaker.git
@@ -22,8 +22,5 @@ dependencies:
version: "~1.3.2"
espressif/network_provisioning:
version: ">=1.*"
espressif/esp_rcp_update:
# This allows all the minor version updates
version: "^1.2.0"
espressif/cbor:
version: "~0.6"

View File

@@ -21,7 +21,6 @@ extern "C"
#include <esp_err.h>
#include <esp_openthread.h>
#include <esp_rcp_update.h>
/** Enable Thread Border Router
*
@@ -31,13 +30,11 @@ extern "C"
* @note This API should be called after esp_rmaker_node_init() but before esp_rmaker_start().
*
* @param[in] platform_config Platform config for OpenThread
* @param[in] rcp_update_config RCP update config
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t esp_rmaker_thread_br_enable(const esp_openthread_platform_config_t *platform_config,
const esp_rcp_update_config_t *rcp_update_config);
esp_err_t esp_rmaker_thread_br_enable(const esp_openthread_platform_config_t *platform_config);
#ifdef __cplusplus
}

View File

@@ -137,8 +137,7 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
return ESP_OK;
}
esp_err_t esp_rmaker_thread_br_enable(const esp_openthread_platform_config_t *platform_config,
const esp_rcp_update_config_t *rcp_update_config)
esp_err_t esp_rmaker_thread_br_enable(const esp_openthread_platform_config_t *platform_config)
{
if (thread_br_service) {
return ESP_ERR_INVALID_STATE;
@@ -153,7 +152,7 @@ esp_err_t esp_rmaker_thread_br_enable(const esp_openthread_platform_config_t *pl
esp_rmaker_device_delete(thread_br_service);
thread_br_service = NULL;
}
thread_border_router_start(platform_config, rcp_update_config);
thread_border_router_start(platform_config);
return ESP_OK;
}

View File

@@ -27,82 +27,20 @@
#include <mdns.h>
#include <openthread/logging.h>
#include <openthread/thread.h>
#ifdef CONFIG_AUTO_UPDATE_RCP
#include <esp_rcp_update.h>
#endif
#include "esp_rmaker_thread_br_priv.h"
static const char *TAG = "thread_br";
static esp_openthread_platform_config_t s_platform_config;
#ifdef CONFIG_AUTO_UPDATE_RCP
static bool s_rcp_update = false;
#endif
#ifdef CONFIG_AUTO_UPDATE_RCP
#define RCP_VERSION_MAX_SIZE 100
static void update_rcp(void)
{
// Deinit uart to transfer UART to the serial loader
esp_openthread_rcp_deinit();
if (esp_rcp_update() == ESP_OK) {
esp_rcp_mark_image_verified(true);
} else {
esp_rcp_mark_image_verified(false);
}
esp_restart();
}
static void try_update_ot_rcp(const esp_openthread_platform_config_t *config)
{
char internal_rcp_version[RCP_VERSION_MAX_SIZE];
const char *running_rcp_version = otPlatRadioGetVersionString(esp_openthread_get_instance());
if (esp_rcp_load_version_in_storage(internal_rcp_version, sizeof(internal_rcp_version)) == ESP_OK) {
ESP_LOGI(TAG, "Internal RCP Version: %s", internal_rcp_version);
ESP_LOGI(TAG, "Running RCP Version: %s", running_rcp_version);
if (strcmp(internal_rcp_version, running_rcp_version) == 0) {
esp_rcp_mark_image_verified(true);
} else {
update_rcp();
}
} else {
ESP_LOGI(TAG, "RCP firmware not found in storage, will reboot to try next image");
esp_rcp_mark_image_verified(false);
esp_restart();
}
}
#endif // CONFIG_AUTO_UPDATE_RCP
static void rcp_failure_handler(void)
{
#ifdef CONFIG_AUTO_UPDATE_RCP
esp_rcp_mark_image_unusable();
char internal_rcp_version[RCP_VERSION_MAX_SIZE];
if (esp_rcp_load_version_in_storage(internal_rcp_version, sizeof(internal_rcp_version)) == ESP_OK) {
ESP_LOGI(TAG, "Internal RCP Version: %s", internal_rcp_version);
update_rcp();
} else {
ESP_LOGI(TAG, "RCP firmware not found in storage, will reboot to try next image");
esp_rcp_mark_image_verified(false);
esp_restart();
}
#endif // CONFIG_AUTO_UPDATE_RCP
}
static void ot_task_worker(void *aContext)
{
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD();
esp_netif_t *openthread_netif = esp_netif_new(&cfg);
assert(openthread_netif != NULL);
esp_openthread_register_rcp_failure_handler(rcp_failure_handler);
// Initialize the OpenThread stack
ESP_ERROR_CHECK(esp_openthread_init(&s_platform_config));
#ifdef CONFIG_AUTO_UPDATE_RCP
try_update_ot_rcp(&s_platform_config);
#endif
// Initialize border routing features
esp_openthread_lock_acquire(portMAX_DELAY);
ESP_ERROR_CHECK(esp_netif_attach(openthread_netif, esp_openthread_netif_glue_init(&s_platform_config)));
@@ -150,8 +88,7 @@ static void thread_br_event_handler(void* arg, esp_event_base_t event_base, int3
}
}
esp_err_t thread_border_router_start(const esp_openthread_platform_config_t *platform_config,
const esp_rcp_update_config_t *rcp_update_config)
esp_err_t thread_border_router_start(const esp_openthread_platform_config_t *platform_config)
{
static bool thread_br_started = false;
if (thread_br_started) {
@@ -173,12 +110,6 @@ esp_err_t thread_border_router_start(const esp_openthread_platform_config_t *pla
// if hostname is not set we will set it with the rainmaker node id.
ESP_ERROR_CHECK(mdns_hostname_set(esp_rmaker_get_node_id()));
}
#ifdef CONFIG_AUTO_UPDATE_RCP
if (rcp_update_config) {
esp_rcp_update_init(rcp_update_config);
s_rcp_update = true;
}
#endif
#define THREAD_TASK_STACK_SIZE 8192
if (xTaskCreate(ot_task_worker, "ot_br", THREAD_TASK_STACK_SIZE, NULL, 5, NULL) != pdTRUE) {
ESP_LOGE(TAG, "Failed to start openthread task for thread br");

View File

@@ -14,7 +14,6 @@
#pragma once
#include "esp_rcp_update.h"
#include <esp_rmaker_core.h>
#include <esp_openthread.h>
#include <openthread/border_agent.h>
@@ -63,5 +62,4 @@ otDeviceRole thread_br_get_device_role(void);
esp_err_t thread_br_generate_and_commit_new_dataset(void);
esp_err_t thread_border_router_start(const esp_openthread_platform_config_t *platform_config,
const esp_rcp_update_config_t *rcp_update_config);
esp_err_t thread_border_router_start(const esp_openthread_platform_config_t *platform_config);

View File

@@ -31,6 +31,12 @@
#include "m5display.h"
#endif
#ifdef CONFIG_AUTO_UPDATE_RCP
#include <esp_openthread_spinel.h>
#include <esp_ot_rcp_update.h>
#include <esp_rcp_update.h>
#endif // CONFIG_AUTO_UPDATE_RCP
static const char *TAG = "app_main";
esp_rmaker_device_t *thread_br_device;
@@ -95,10 +101,11 @@ void app_main()
};
#ifdef CONFIG_AUTO_UPDATE_RCP
esp_rcp_update_config_t rcp_update_cfg = ESP_OPENTHREAD_RCP_UPDATE_CONFIG();
esp_rmaker_thread_br_enable(&thread_cfg, &rcp_update_cfg);
#else
esp_rmaker_thread_br_enable(&thread_cfg, NULL);
esp_rcp_update_init(&rcp_update_cfg);
esp_ot_register_rcp_handler();
#endif
esp_rmaker_thread_br_enable(&thread_cfg);
/* Enable OTA */
esp_rmaker_ota_enable_default();
@@ -125,6 +132,9 @@ void app_main()
#if CONFIG_M5STACK_THREAD_BR_BOARD
app_register_m5stack_display_event_handler();
#endif
#ifdef CONFIG_AUTO_UPDATE_RCP
esp_ot_update_rcp_if_different();
#endif
/* Start the Wi-Fi.
* If the node is provisioned, it will start connection attempts,

View File

@@ -52,7 +52,7 @@ extern "C" {
#ifdef CONFIG_AUTO_UPDATE_RCP
#define ESP_OPENTHREAD_RCP_UPDATE_CONFIG() \
{ \
.rcp_type = RCP_TYPE_ESP32H2_UART, .uart_rx_pin = CONFIG_PIN_TO_RCP_TX, .uart_tx_pin = CONFIG_PIN_TO_RCP_RX, \
.rcp_type = RCP_TYPE_UART, .uart_rx_pin = CONFIG_PIN_TO_RCP_TX, .uart_tx_pin = CONFIG_PIN_TO_RCP_RX, \
.uart_port = 1, .uart_baudrate = 115200, .reset_pin = CONFIG_PIN_TO_RCP_RESET, \
.boot_pin = CONFIG_PIN_TO_RCP_BOOT, .update_baudrate = 460800, \
.firmware_dir = "/" CONFIG_RCP_PARTITION_NAME "/ot_rcp", .target_chip = ESP32H2_CHIP, \

View File

@@ -14,3 +14,5 @@ dependencies:
espressif/rmaker_app_insights:
version: "*"
override_path: '../../common/rmaker_app_insights/'
espressif/esp_rcp_update:
version: "~1.5.3"