From 209087c7a5bad1d8490ee62295909b37970aa257 Mon Sep 17 00:00:00 2001 From: Wang Qixiang Date: Mon, 8 Dec 2025 04:26:43 +0800 Subject: [PATCH] esp_rainmaker: decouple esp_rcp_update from esp_rainmaker --- components/esp_rainmaker/idf_component.yml | 5 +- .../include/esp_rmaker_thread_br.h | 5 +- .../src/thread_br/esp_rmaker_thread_br.c | 5 +- .../thread_br/esp_rmaker_thread_br_launcher.c | 71 +------------------ .../src/thread_br/esp_rmaker_thread_br_priv.h | 4 +- examples/thread_br/main/app_main.c | 16 ++++- examples/thread_br/main/app_thread_config.h | 2 +- examples/thread_br/main/idf_component.yml | 2 + 8 files changed, 22 insertions(+), 88 deletions(-) diff --git a/components/esp_rainmaker/idf_component.yml b/components/esp_rainmaker/idf_component.yml index 4c98a66..f17bdfb 100644 --- a/components/esp_rainmaker/idf_component.yml +++ b/components/esp_rainmaker/idf_component.yml @@ -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" diff --git a/components/esp_rainmaker/include/esp_rmaker_thread_br.h b/components/esp_rainmaker/include/esp_rmaker_thread_br.h index 96fdfde..0e5f872 100644 --- a/components/esp_rainmaker/include/esp_rmaker_thread_br.h +++ b/components/esp_rainmaker/include/esp_rmaker_thread_br.h @@ -21,7 +21,6 @@ extern "C" #include #include -#include /** 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 } diff --git a/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br.c b/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br.c index 3d785cd..efa8e22 100644 --- a/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br.c +++ b/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br.c @@ -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; } diff --git a/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_launcher.c b/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_launcher.c index 14a5e31..7cbd50c 100644 --- a/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_launcher.c +++ b/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_launcher.c @@ -27,82 +27,20 @@ #include #include #include -#ifdef CONFIG_AUTO_UPDATE_RCP -#include -#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"); diff --git a/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_priv.h b/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_priv.h index 4a6f94c..e023062 100644 --- a/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_priv.h +++ b/components/esp_rainmaker/src/thread_br/esp_rmaker_thread_br_priv.h @@ -14,7 +14,6 @@ #pragma once -#include "esp_rcp_update.h" #include #include #include @@ -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); diff --git a/examples/thread_br/main/app_main.c b/examples/thread_br/main/app_main.c index cd88420..70d7cb2 100644 --- a/examples/thread_br/main/app_main.c +++ b/examples/thread_br/main/app_main.c @@ -31,6 +31,12 @@ #include "m5display.h" #endif +#ifdef CONFIG_AUTO_UPDATE_RCP +#include +#include +#include +#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, diff --git a/examples/thread_br/main/app_thread_config.h b/examples/thread_br/main/app_thread_config.h index 33511b8..f57031c 100644 --- a/examples/thread_br/main/app_thread_config.h +++ b/examples/thread_br/main/app_thread_config.h @@ -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, \ diff --git a/examples/thread_br/main/idf_component.yml b/examples/thread_br/main/idf_component.yml index 8878e7e..7146e46 100644 --- a/examples/thread_br/main/idf_component.yml +++ b/examples/thread_br/main/idf_component.yml @@ -14,3 +14,5 @@ dependencies: espressif/rmaker_app_insights: version: "*" override_path: '../../common/rmaker_app_insights/' + espressif/esp_rcp_update: + version: "~1.5.3"