diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 6946aa64b11498..a4c9d2cbf9bcdf 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -96,6 +96,7 @@ matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHR matter_add_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT) matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4) matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) +matter_add_gn_arg_bool ("chip_enable_bootloader_mcuboot" CONFIG_BOOTLOADER_MCUBOOT) matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) matter_add_gn_arg_bool ("chip_error_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 1) matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 3) diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index 513b2c04306290..b1bd07660937bd 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -36,6 +36,9 @@ config CHIP_APP_LOG_LEVEL config CHIP_OTA_REQUESTOR bool select BOOTLOADER_MCUBOOT + +config BOOTLOADER_MCUBOOT + bool select IMG_MANAGER select STREAM_FLASH select STREAM_FLASH_ERASE diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index d70fff0d50f3fa..f346a2c1eeb807 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -75,6 +75,9 @@ config SYSTEM_WORKQUEUE_STACK_SIZE config HEAP_MEM_POOL_SIZE default 128 if PM +config COMMON_LIBC_MALLOC_ARENA_SIZE + default 12288 + config NET_IPV6_MLD default n diff --git a/examples/air-quality-sensor-app/telink/CMakeLists.txt b/examples/air-quality-sensor-app/telink/CMakeLists.txt index 9900d9bb4b5403..937002d7cee1ba 100644 --- a/examples/air-quality-sensor-app/telink/CMakeLists.txt +++ b/examples/air-quality-sensor-app/telink/CMakeLists.txt @@ -80,7 +80,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../air-quality-sensor-common/air-quality-sensor-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/all-clusters-app/telink/CMakeLists.txt b/examples/all-clusters-app/telink/CMakeLists.txt index fbc0b756eda8c3..9c0da32bce0083 100644 --- a/examples/all-clusters-app/telink/CMakeLists.txt +++ b/examples/all-clusters-app/telink/CMakeLists.txt @@ -89,7 +89,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${ALL_CLUSTERS_COMMON_DIR}/all-clusters-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/all-clusters-minimal-app/telink/CMakeLists.txt b/examples/all-clusters-minimal-app/telink/CMakeLists.txt index ec296891479d16..ea026b2a834bfa 100644 --- a/examples/all-clusters-minimal-app/telink/CMakeLists.txt +++ b/examples/all-clusters-minimal-app/telink/CMakeLists.txt @@ -82,7 +82,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../all-clusters-common/all-clusters-minimal-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/bridge-app/telink/CMakeLists.txt b/examples/bridge-app/telink/CMakeLists.txt index 588b4f7bbdf5b1..7fb0bb6d81f4c9 100644 --- a/examples/bridge-app/telink/CMakeLists.txt +++ b/examples/bridge-app/telink/CMakeLists.txt @@ -82,7 +82,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../bridge-common/bridge-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/chef/telink/CMakeLists.txt b/examples/chef/telink/CMakeLists.txt index 10b2eec74c8961..2886513e7a39e7 100755 --- a/examples/chef/telink/CMakeLists.txt +++ b/examples/chef/telink/CMakeLists.txt @@ -99,11 +99,6 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CHEF}/devices/${SAMPLE_NAME}.zap ) - - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() if (CONFIG_CHIP_PW_RPC) diff --git a/examples/contact-sensor-app/telink/CMakeLists.txt b/examples/contact-sensor-app/telink/CMakeLists.txt index 154cfcc18678dc..8eaba1825577c6 100755 --- a/examples/contact-sensor-app/telink/CMakeLists.txt +++ b/examples/contact-sensor-app/telink/CMakeLists.txt @@ -79,7 +79,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../contact-sensor-common/contact-sensor-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/light-switch-app/telink/CMakeLists.txt b/examples/light-switch-app/telink/CMakeLists.txt index 5312e902907138..32b787a216c279 100755 --- a/examples/light-switch-app/telink/CMakeLists.txt +++ b/examples/light-switch-app/telink/CMakeLists.txt @@ -81,10 +81,6 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../light-switch-common/light-switch-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() - # Fix for unused swap parameter in: zephyr/include/zephyr/arch/riscv/irq.h:70 add_compile_options(-Wno-error=unused-parameter) diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index f4a0edd1636734..6a579b959110e4 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -98,10 +98,6 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../lighting-common/lighting-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() - # Fix for unused swap parameter in: zephyr/include/zephyr/arch/riscv/irq.h:70 add_compile_options(-Wno-error=unused-parameter) diff --git a/examples/lock-app/telink/CMakeLists.txt b/examples/lock-app/telink/CMakeLists.txt index 702648dab2daa0..c89c1695680006 100755 --- a/examples/lock-app/telink/CMakeLists.txt +++ b/examples/lock-app/telink/CMakeLists.txt @@ -80,7 +80,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../lock-common/lock-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/ota-requestor-app/telink/CMakeLists.txt b/examples/ota-requestor-app/telink/CMakeLists.txt index b3558357cc59c8..2ae1595e8ee483 100644 --- a/examples/ota-requestor-app/telink/CMakeLists.txt +++ b/examples/ota-requestor-app/telink/CMakeLists.txt @@ -79,7 +79,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../ota-requestor-common/ota-requestor-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 7a1a537d1110df..0638b64b1e355f 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -31,13 +31,8 @@ #include #if CONFIG_CHIP_OTA_REQUESTOR -#include "OTAUtil.h" -#endif - -#ifdef CONFIG_BOOTLOADER_MCUBOOT #include -#include -#endif /* CONFIG_BOOTLOADER_MCUBOOT */ +#endif #include #include @@ -312,30 +307,6 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); #endif -#if CONFIG_CHIP_OTA_REQUESTOR - InitBasicOTARequestor(); -#endif - -#ifdef CONFIG_BOOTLOADER_MCUBOOT -#if CONFIG_CHIP_OTA_REQUESTOR - if (GetRequestorInstance()->GetCurrentUpdateState() == Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle && - mcuboot_swap_type() == BOOT_SWAP_TYPE_REVERT) -#else - if (mcuboot_swap_type() == BOOT_SWAP_TYPE_REVERT) -#endif - { - int img_confirmation = boot_write_img_confirmed(); - if (img_confirmation) - { - LOG_ERR("Image not confirmed %d. Will be reverted!", img_confirmation); - } - else - { - LOG_INF("Image confirmed"); - } - } -#endif /* CONFIG_BOOTLOADER_MCUBOOT */ - ConfigurationMgr().LogDeviceConfig(); PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); @@ -702,11 +673,16 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* UpdateStatusLED(); #endif break; - case DeviceEventType::kThreadConnectivityChange: + case DeviceEventType::kDnssdInitialized: #if CONFIG_CHIP_OTA_REQUESTOR - if (event->ThreadConnectivityChange.Result == kConnectivity_Established) + InitBasicOTARequestor(); + if (GetRequestorInstance()->GetCurrentUpdateState() == Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle) { - InitBasicOTARequestor(); +#endif +#ifdef CONFIG_BOOTLOADER_MCUBOOT + OtaConfirmNewImage(); +#endif /* CONFIG_BOOTLOADER_MCUBOOT */ +#if CONFIG_CHIP_OTA_REQUESTOR } #endif break; diff --git a/examples/pump-app/telink/CMakeLists.txt b/examples/pump-app/telink/CMakeLists.txt index 1e831ee268d2de..bed10accba40b8 100755 --- a/examples/pump-app/telink/CMakeLists.txt +++ b/examples/pump-app/telink/CMakeLists.txt @@ -79,7 +79,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../pump-common/pump-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/pump-controller-app/telink/CMakeLists.txt b/examples/pump-controller-app/telink/CMakeLists.txt index 32e6f4682e5f2c..ba1298e6e30525 100755 --- a/examples/pump-controller-app/telink/CMakeLists.txt +++ b/examples/pump-controller-app/telink/CMakeLists.txt @@ -79,7 +79,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../pump-controller-common/pump-controller-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/resource-monitoring-app/telink/CMakeLists.txt b/examples/resource-monitoring-app/telink/CMakeLists.txt index 07f4004a6f54a9..92d26f99545850 100644 --- a/examples/resource-monitoring-app/telink/CMakeLists.txt +++ b/examples/resource-monitoring-app/telink/CMakeLists.txt @@ -85,7 +85,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../resource-monitoring-common/resource-monitoring-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/smoke-co-alarm-app/telink/CMakeLists.txt b/examples/smoke-co-alarm-app/telink/CMakeLists.txt index e1d5beec90d1c7..9fa08fbdb436b1 100755 --- a/examples/smoke-co-alarm-app/telink/CMakeLists.txt +++ b/examples/smoke-co-alarm-app/telink/CMakeLists.txt @@ -79,7 +79,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../smoke-co-alarm-common/smoke-co-alarm-app.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/temperature-measurement-app/telink/CMakeLists.txt b/examples/temperature-measurement-app/telink/CMakeLists.txt index 1adc7f29fe00a6..53c2781458cb5c 100644 --- a/examples/temperature-measurement-app/telink/CMakeLists.txt +++ b/examples/temperature-measurement-app/telink/CMakeLists.txt @@ -81,7 +81,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../temperature-measurement-common/temperature-measurement.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/thermostat/telink/CMakeLists.txt b/examples/thermostat/telink/CMakeLists.txt index 7b9dff6ff3e6f8..9abe4bd422a37f 100755 --- a/examples/thermostat/telink/CMakeLists.txt +++ b/examples/thermostat/telink/CMakeLists.txt @@ -81,7 +81,3 @@ chip_configure_data_model(app INCLUDE_SERVER ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../thermostat-common/thermostat.zap ) - -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() diff --git a/examples/window-app/telink/CMakeLists.txt b/examples/window-app/telink/CMakeLists.txt index d9e703db81ae94..5b695943fd3f1b 100644 --- a/examples/window-app/telink/CMakeLists.txt +++ b/examples/window-app/telink/CMakeLists.txt @@ -82,10 +82,6 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../common/window-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR) - target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) -endif() - # Fix for unused swap parameter in: zephyr/include/zephyr/arch/riscv/irq.h:70 add_compile_options(-Wno-error=unused-parameter) diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index 1e1c4c94d67638..63e501eadaae7a 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -33,6 +33,10 @@ #include #include +#ifdef CONFIG_BOOTLOADER_MCUBOOT +#include "OTAUtil.h" +#endif /* CONFIG_BOOTLOADER_MCUBOOT */ + namespace chip { namespace DeviceLayer { namespace Internal { @@ -182,6 +186,9 @@ class InternalScanCallback : public DeviceLayer::NetworkCommissioning::ThreadDri NetworkCommissioning::ThreadScanResponseIterator * networks) { mBLEManagerImpl->StartAdvertisingProcess(); +#ifdef CONFIG_BOOTLOADER_MCUBOOT + OtaConfirmNewImage(); +#endif /* CONFIG_BOOTLOADER_MCUBOOT */ }; private: diff --git a/src/platform/telink/BUILD.gn b/src/platform/telink/BUILD.gn index 9864ae4b5dfd09..3d244ce9191304 100644 --- a/src/platform/telink/BUILD.gn +++ b/src/platform/telink/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Project CHIP Authors +# Copyright (c) 2021-2023 Project CHIP Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -91,4 +91,11 @@ static_library("telink") { "OTAImageProcessorImpl.h", ] } + + if (chip_enable_bootloader_mcuboot) { + sources += [ + "OTAUtil.cpp", + "OTAUtil.h", + ] + } } diff --git a/examples/platform/telink/util/src/OTAUtil.cpp b/src/platform/telink/OTAUtil.cpp similarity index 72% rename from examples/platform/telink/util/src/OTAUtil.cpp rename to src/platform/telink/OTAUtil.cpp index 646cb633973889..5e4bf20916b81c 100755 --- a/examples/platform/telink/util/src/OTAUtil.cpp +++ b/src/platform/telink/OTAUtil.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Project CHIP Authors + * Copyright (c) 2022-2023 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,16 +15,25 @@ * limitations under the License. */ +#ifdef CONFIG_CHIP_OTA_REQUESTOR #include #include #include #include #include #include +#endif + +#if CONFIG_BOOTLOADER_MCUBOOT +#include +#include +#endif using namespace chip; using namespace chip::DeviceLayer; +#ifdef CONFIG_CHIP_OTA_REQUESTOR + namespace { DefaultOTARequestorStorage sOTARequestorStorage; @@ -45,3 +54,21 @@ void InitBasicOTARequestor() chip::SetRequestorInstance(&sOTARequestor); sOTARequestorDriver.Init(&sOTARequestor, &sOTAImageProcessor); } + +#endif + +void OtaConfirmNewImage() +{ + if (mcuboot_swap_type() == BOOT_SWAP_TYPE_REVERT) + { + CHIP_ERROR err = System::MapErrorZephyr(boot_write_img_confirmed()); + if (CHIP_NO_ERROR == err) + { + ChipLogProgress(SoftwareUpdate, "New firmware image confirmed"); + } + else + { + ChipLogError(SoftwareUpdate, "Failed to confirm firmware image, it will be reverted on the next boot"); + } + } +} diff --git a/examples/platform/telink/util/include/OTAUtil.h b/src/platform/telink/OTAUtil.h similarity index 84% rename from examples/platform/telink/util/include/OTAUtil.h rename to src/platform/telink/OTAUtil.h index eb0c4e5bb32d4e..7d37b90cc1ffe9 100755 --- a/examples/platform/telink/util/include/OTAUtil.h +++ b/src/platform/telink/OTAUtil.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Project CHIP Authors + * Copyright (c) 2022-2023 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,7 @@ #pragma once +#ifdef CONFIG_CHIP_OTA_REQUESTOR #include namespace chip { @@ -32,3 +33,10 @@ class OTAImageProcessorImpl; * an update so the confirmation must be done on the OTA provider side. */ void InitBasicOTARequestor(); + +#endif // CONFIG_CHIP_OTA_REQUESTOR + +/** + * Confirm or revert new image in MCUBoot. + */ +void OtaConfirmNewImage(); diff --git a/src/platform/telink/args.gni b/src/platform/telink/args.gni index a8307083a7d217..82197d9cecdbd4 100644 --- a/src/platform/telink/args.gni +++ b/src/platform/telink/args.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Project CHIP Authors +# Copyright (c) 2022-2023 Project CHIP Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,4 +19,7 @@ chip_inet_config_enable_ipv4 = false declare_args() { # Enable factory data support chip_enable_factory_data = false + + # Enable Zephyr application to be booted by MCUboot + chip_enable_bootloader_mcuboot = false }