Skip to content

Commit

Permalink
[Telink] Fix OTA tests (project-chip#29725)
Browse files Browse the repository at this point in the history
* [Telink] Set default value of COMMON_LIBC_MALLOC_ARENA_SIZE

* [Telink] InitBasicOTARequestor after kDnssdInitialized

* [Telink] Move OTAUtil into lib

* [Telink] restyled
  • Loading branch information
s07641069 authored Oct 12, 2023
1 parent 4b84c2f commit f900f46
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 106 deletions.
1 change: 1 addition & 0 deletions config/telink/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions config/telink/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/telink/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions examples/air-quality-sensor-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/all-clusters-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/all-clusters-minimal-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/bridge-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 0 additions & 5 deletions examples/chef/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions examples/contact-sensor-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/light-switch-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions examples/lock-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/ota-requestor-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
42 changes: 9 additions & 33 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@
#include <app/util/attribute-storage.h>

#if CONFIG_CHIP_OTA_REQUESTOR
#include "OTAUtil.h"
#endif

#ifdef CONFIG_BOOTLOADER_MCUBOOT
#include <app/clusters/ota-requestor/OTARequestorInterface.h>
#include <zephyr/dfu/mcuboot.h>
#endif /* CONFIG_BOOTLOADER_MCUBOOT */
#endif

#include <zephyr/fs/nvs.h>
#include <zephyr/settings/settings.h>
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions examples/pump-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/pump-controller-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/resource-monitoring-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/smoke-co-alarm-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/temperature-measurement-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/thermostat/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 0 additions & 4 deletions examples/window-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions src/platform/telink/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>

#ifdef CONFIG_BOOTLOADER_MCUBOOT
#include "OTAUtil.h"
#endif /* CONFIG_BOOTLOADER_MCUBOOT */

namespace chip {
namespace DeviceLayer {
namespace Internal {
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/platform/telink/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -91,4 +91,11 @@ static_library("telink") {
"OTAImageProcessorImpl.h",
]
}

if (chip_enable_bootloader_mcuboot) {
sources += [
"OTAUtil.cpp",
"OTAUtil.h",
]
}
}
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -15,16 +15,25 @@
* limitations under the License.
*/

#ifdef CONFIG_CHIP_OTA_REQUESTOR
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <app/server/Server.h>
#include <platform/telink/OTAImageProcessorImpl.h>
#endif

#if CONFIG_BOOTLOADER_MCUBOOT
#include <app/server/Server.h>
#include <zephyr/dfu/mcuboot.h>
#endif

using namespace chip;
using namespace chip::DeviceLayer;

#ifdef CONFIG_CHIP_OTA_REQUESTOR

namespace {

DefaultOTARequestorStorage sOTARequestorStorage;
Expand All @@ -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");
}
}
}
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -17,6 +17,7 @@

#pragma once

#ifdef CONFIG_CHIP_OTA_REQUESTOR
#include <platform/telink/OTAImageProcessorImpl.h>

namespace chip {
Expand All @@ -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();
5 changes: 4 additions & 1 deletion src/platform/telink/args.gni
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
}

0 comments on commit f900f46

Please sign in to comment.