Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle [OTA] Implement OTA to all EFR32 examples #14925

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ efr32_executable("lighting_app") {
]
}
}

if (chip_enable_ota_requestor) {
defines += [ "EFR32_OTA_ENABLED" ]
sources += [ "${examples_plat_dir}/OTAConfig.cpp" ]
}

if (use_rs911x) {
sources += rs911x_src_plat

Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import("${chip_root}/src/platform/EFR32/args.gni")

efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")

declare_args() {
chip_enable_ota_requestor = true
}

pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
chip_enable_openthread = true
Expand Down
7 changes: 7 additions & 0 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
#include "sl_system_kernel.h"
#include <app/server/Server.h>

#ifdef EFR32_OTA_ENABLED
#include "OTAConfig.h"
#endif // EFR32_OTA_ENABLED

#ifdef HEAP_MONITORING
#include "MemMonitoring.h"
#endif
Expand Down Expand Up @@ -198,6 +202,9 @@ int main(void)
* starting up a rsi task - which will initialize the SPI interface.
*/
#endif
#ifdef EFR32_OTA_ENABLED
OTAConfig::Init();
#endif // EFR32_OTA_ENABLED

EFR32_LOG("Starting App Task");
ret = GetAppTask().StartAppTask();
Expand Down
6 changes: 6 additions & 0 deletions examples/lock-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ efr32_executable("lock_app") {
]
}
}

if (chip_enable_ota_requestor) {
defines += [ "EFR32_OTA_ENABLED" ]
sources += [ "${examples_plat_dir}/OTAConfig.cpp" ]
}

if (use_rs911x) {
sources += rs911x_src_plat

Expand Down
4 changes: 4 additions & 0 deletions examples/lock-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import("${chip_root}/src/platform/EFR32/args.gni")

efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")

declare_args() {
chip_enable_ota_requestor = true
}

chip_enable_openthread = true
pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
8 changes: 7 additions & 1 deletion examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
#include "matter_shell.h"
#endif

#ifdef EFR32_OTA_ENABLED
#include "OTAConfig.h"
#endif // EFR32_OTA_ENABLED

#include <mbedtls/platform.h>
#if CHIP_ENABLE_OPENTHREAD
#include <openthread/cli.h>
Expand Down Expand Up @@ -187,7 +191,9 @@ int main(void)
wfx_securelink_task_start(); // start securelink key renegotiation task
#endif // SL_WFX_USE_SECURE_LINK
#endif /* WF200_WIFI */

#ifdef EFR32_OTA_ENABLED
OTAConfig::Init();
#endif // EFR32_OTA_ENABLED
EFR32_LOG("Starting App Task");
ret = GetAppTask().StartAppTask();
if (ret != CHIP_NO_ERROR)
Expand Down
86 changes: 86 additions & 0 deletions examples/platform/efr32/OTAConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "OTAConfig.h"

#include "platform/bootloader/api/application_properties.h"
#include <app/server/Server.h>

// Header used for building the image GBL file
#define APP_PROPERTIES_VERSION 1
#define APP_PROPERTIES_ID \
{ \
0 \
}

__attribute__((used)) ApplicationProperties_t sl_app_properties = {
/// @brief Magic value indicating that this is an ApplicationProperties_t
/// Must equal @ref APPLICATION_PROPERTIES_MAGIC
.magic = APPLICATION_PROPERTIES_MAGIC,

/// Version number of this struct
.structVersion = APPLICATION_PROPERTIES_VERSION,

/// Type of signature this application is signed with
.signatureType = APPLICATION_SIGNATURE_NONE,

/// Location of the signature. Typically a pointer to the end of application
.signatureLocation = 0,

/// Information about the application
.app = {

/// Bitfield representing type of application
/// e.g. @ref APPLICATION_TYPE_BLUETOOTH_APP
.type = APPLICATION_TYPE_THREAD,

/// Version number for this application
.version = APP_PROPERTIES_VERSION,

/// Capabilities of this application
.capabilities = 0,

/// Unique ID (e.g. UUID/GUID) for the product this application is built for
.productId = APP_PROPERTIES_ID,
},
};

// Global OTA objects
chip::OTARequestor gRequestorCore;
chip::DeviceLayer::GenericOTARequestorDriver gRequestorUser;
chip::BDXDownloader gDownloader;
chip::OTAImageProcessorImpl gImageProcessor;

void OTAConfig::Init()
{
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);

gRequestorCore.Init(&(chip::Server::GetInstance()), &gRequestorUser, &gDownloader);

gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

chip::OTAImageProcessorParams ipParams;
ipParams.imageFile = chip::CharSpan("test.txt");
gImageProcessor.SetOTAImageProcessorParams(ipParams);
gImageProcessor.SetOTADownloader(&gDownloader);

// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
// Initialize and interconnect the Requestor and Image Processor objects -- END
}
32 changes: 32 additions & 0 deletions examples/platform/efr32/OTAConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "app/clusters/ota-requestor/BDXDownloader.h"
#include "app/clusters/ota-requestor/OTARequestor.h"
#include "platform/EFR32/OTAImageProcessorImpl.h"
#include "platform/GenericOTARequestorDriver.h"

class OTAConfig
{
public:
OTAConfig(){};

static void Init();
};
5 changes: 5 additions & 0 deletions examples/window-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ efr32_executable("window_app") {
"src/main.cpp",
]

if (chip_enable_ota_requestor) {
defines += [ "EFR32_OTA_ENABLED" ]
sources += [ "${examples_plat_dir}/OTAConfig.cpp" ]
}

if (use_rs911x) {
sources += rs911x_src_plat

Expand Down
4 changes: 4 additions & 0 deletions examples/window-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import("${chip_root}/src/platform/EFR32/args.gni")

efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")

declare_args() {
chip_enable_ota_requestor = true
}

pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
chip_enable_openthread = true
8 changes: 7 additions & 1 deletion examples/window-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#include "matter_shell.h"
#endif

#ifdef EFR32_OTA_ENABLED
#include "OTAConfig.h"
#endif // EFR32_OTA_ENABLED

#define BLE_DEV_NAME "EFR32_WINDOW"
using namespace ::chip::DeviceLayer;

Expand Down Expand Up @@ -167,7 +171,9 @@ int main(void)
#ifdef ENABLE_CHIP_SHELL
chip::startShellTask();
#endif

#ifdef EFR32_OTA_ENABLED
OTAConfig::Init();
#endif // EFR32_OTA_ENABLED
WindowApp & app = WindowApp::Instance();

EFR32_LOG("Starting App");
Expand Down