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

[Silabs] [WiFi] Added changes for the 917 Wi-Fi multi-ota feature #37611

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
17c5611
Added changes for the multi ota 917 soc
shgutte Mar 26, 2024
5eef7f6
Added changes for the build errores
shgutte Mar 27, 2024
5b07de3
Added changes for 917 soc
shgutte Apr 7, 2024
ea8c80f
Added changes for the name for 917 NCP
shgutte Apr 8, 2024
ad4dd34
Deleted the 917 NCP file
shgutte Apr 10, 2024
7762e37
Added fixed for 917 SoC build changes
shgutte Apr 10, 2024
5949e9f
Added changes for 917 SOC
shgutte Apr 11, 2024
6e80e03
Added changes for the 917 SOC build error
shgutte Apr 11, 2024
4cfdfd5
Added changes for the 917 SoC ota reset
shgutte Apr 11, 2024
627f9ba
Added changes for OTA 917 SoC script
shgutte Apr 11, 2024
5a7d83b
Added changes for 917 build
shgutte Apr 11, 2024
08bab24
Added debugging logs for the files
shgutte Apr 14, 2024
f4bf610
Removed the duplicate code
shgutte Apr 14, 2024
e6c3a13
Added changes for the SoC Application
shgutte Apr 15, 2024
cdc63ed
Added changes for builkd issue with EFR32 multi OTA
shgutte Apr 16, 2024
593eaf3
Added changes for the OTA 917 NCP
shgutte Apr 16, 2024
14ed08e
Added changes for the OTA tlv
shgutte Apr 16, 2024
479d2a2
Added changes for the comment
shgutte Apr 17, 2024
4cf6b09
Added changes for the process block for WIfi
shgutte Apr 17, 2024
23cea72
Removed the mWriteOffset in firmware processor
shgutte Apr 17, 2024
47d37f0
Removed unessory comment
shgutte Apr 17, 2024
f9934da
Added changes for the ProcessInternal OTA WiFi
shgutte Apr 17, 2024
14bc689
Added changes for WiFi OTA processor
shgutte Apr 19, 2024
d855d64
Removed the unwanted line
shgutte Apr 19, 2024
f799676
Cleanup of the code
shgutte Apr 19, 2024
298adc8
Corrected #ifdef comments
shgutte Apr 19, 2024
a672c7b
Removed unwanted comment
shgutte Apr 19, 2024
ec02a69
Added back the set_logger function
shgutte Apr 19, 2024
d09abe5
Applied suggestion
selissia Apr 19, 2024
d76ef10
Added changes realted to comment
shgutte Apr 22, 2024
cae741a
Discription for input command is updated
shgutte Apr 22, 2024
df781e7
Added changes for build file of 917 SoC
shgutte Apr 24, 2024
a3dd261
Added changes for encryption
shgutte Apr 24, 2024
293f69c
Adds changes for the multi-ota updated
shgutte Feb 24, 2025
66e2d0c
Adds changes for the customProcessor
shgutte Feb 24, 2025
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
4 changes: 4 additions & 0 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ config("siwx917-common-config") {
defines += [ "HEAP_MONITORING" ]
}

if (chip_enable_multi_ota_requestor) {
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_MULTI_OTA_REQUESTOR=1" ]
}

ldflags = [ "-Wl,--no-warn-rwx-segment" ]
}

Expand Down
39 changes: 36 additions & 3 deletions scripts/tools/silabs/ota/ota_multi_image_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from chip.tlv import TLVWriter # noqa: E402 isort:skip
from custom import CertDeclaration, DacCert, DacPKey, PaiCert # noqa: E402 isort:skip
from default import InputArgument # noqa: E402 isort:skip
from generate import set_logger # noqa: E402 isort:skip

OTA_APP_TLV_TEMP = os.path.join(os.path.dirname(__file__), "ota_temp_app_tlv.bin")
OTA_BOOTLOADER_TLV_TEMP = os.path.join(os.path.dirname(__file__), "ota_temp_ssbl_tlv.bin")
Expand All @@ -62,7 +63,9 @@ class TAG:
APPLICATION = 1
BOOTLOADER = 2
FACTORY_DATA = 3

WIFI_917_NCP_TA = 4
WIFI_917_SOC_COMBINED = 5
WIFI_917_NCP_COMBINED = 6

def set_logger():
stdout_handler = logging.StreamHandler(stream=sys.stdout)
Expand All @@ -72,7 +75,6 @@ def set_logger():
handlers=[stdout_handler]
)


def write_to_temp(path: str, payload: bytearray):
with open(path, "wb") as _handle:
_handle.write(payload)
Expand Down Expand Up @@ -163,6 +165,32 @@ def generate_app(args: object):
return [OTA_APP_TLV_TEMP, args.app_input_file]


def generate_wifi_image(args: object):
"""
Generate app payload with descriptor. If a certain option is not specified, use the default values.
"""
logging.info("App descriptor information:")

descriptor = generate_descriptor(args.app_version, args.app_version_str, args.app_build_date)
logging.info(f"App encryption enable: {args.enc_enable}")
if args.enc_enable:
inputFile = open(args.wifi_input_file, "rb")
enc_file = crypto_utils.encryptData(inputFile.read(), args.input_ota_key, INITIALIZATION_VECTOR)
enc_file1 = bytes([ord(x) for x in enc_file])
file_size = len(enc_file1)
payload = generate_header(TAG.WIFI_917_TA_M4, len(descriptor) + file_size) + descriptor + enc_file1
else:
file_size = os.path.getsize(args.wifi_input_file)
logging.info(f"file size: {file_size}")
payload = generate_header(TAG.WIFI_917_TA_M4, len(descriptor) + file_size) + descriptor

write_to_temp(OTA_APP_TLV_TEMP, payload)
if args.enc_enable:
return [OTA_APP_TLV_TEMP]
else:
return [OTA_APP_TLV_TEMP, args.wifi_input_file]


def generate_bootloader(args: object):
"""
Generate SSBL payload with descriptor. If a certain option is not specified, use the default values.
Expand Down Expand Up @@ -257,7 +285,10 @@ def create_image(args: object):
input_files += generate_bootloader(args)

if args.app_input_file:
input_files += generate_app(args)
input_files += generate_app(args)

if args.wifi_input_file:
input_files += generate_wifi_image(args)

if len(input_files) == 0:
print("Please specify an input option.")
Expand Down Expand Up @@ -312,6 +343,8 @@ def any_base_int(s): return int(s, 0)

create_parser.add_argument('-app', "--app-input-file",
help='Path to application input file')
create_parser.add_argument('-wifi', "--wifi-input-file",
help='Path to OTA image for SiWx917 (TA/M4/Combined file)')
create_parser.add_argument('--app-version', type=any_base_int,
help='Application Software version (numeric)')
create_parser.add_argument('--app-version-str', type=str,
Expand Down
14 changes: 11 additions & 3 deletions src/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
# limitations under the License.

import("//build_overrides/chip.gni")

import("${chip_root}/src/platform/device.gni")

import("${chip_root}/build/chip/buildconfig_header.gni")
import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/platform/silabs/wifi/args.gni")
Expand Down Expand Up @@ -77,7 +75,17 @@ static_library("SiWx917") {
"SiWxPlatformInterface.h",
]

if (chip_enable_ota_requestor) {
if (chip_enable_multi_ota_requestor) {
sources += [
"${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.cpp",
"${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.h",
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp",
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.h",
"${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp",
"${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h",
"${silabs_platform_dir}/multi-ota/OTAHooks.cpp",
]
} else if (chip_enable_ota_requestor) {
sources += [
"${silabs_platform_dir}/OTAImageProcessorImpl.h",
"OTAImageProcessorImpl.cpp",
Expand Down
7 changes: 7 additions & 0 deletions src/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ static_library("efr32") {
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp",
"${silabs_platform_dir}/multi-ota/OTATlvProcessor.h",
]

if (chip_enable_wifi) {
sources += [
"${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp",
"${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h",
]
}
} else if (chip_enable_ota_requestor) {
sources += [
"${silabs_platform_dir}/OTAImageProcessorImpl.h",
Expand Down
37 changes: 27 additions & 10 deletions src/platform/silabs/multi-ota/OTAHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,43 @@
#include <app/clusters/ota-requestor/OTARequestorInterface.h>

#include <platform/silabs/multi-ota/OTAFactoryDataProcessor.h>
#ifndef SLI_SI91X_MCU_INTERFACE
#include <platform/silabs/multi-ota/OTAFirmwareProcessor.h>
#endif

#if SL_WIFI
#include <platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h>
#endif

#if OTA_TEST_CUSTOM_TLVS
#include <platform/silabs/multi-ota/OTACustomProcessor.h>
#endif

CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor)
{
#ifndef SLI_SI91X_MCU_INTERFACE
[[maybe_unused]] auto desc = static_cast<chip::OTAFirmwareProcessor::Descriptor *>(descriptor);
ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate);
#endif

#if SL_WIFI
auto descWiFi = static_cast<chip::OTAWiFiFirmwareProcessor::Descriptor *>(descriptor);
ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", descWiFi->version, descWiFi->versionString, descWiFi->buildDate);
#endif

return CHIP_NO_ERROR;
}

CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit()
{
static chip::OTAFirmwareProcessor sApplicationProcessor;
static chip::OTAFactoryDataProcessor sFactoryDataProcessor;

sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor);
sFactoryDataProcessor.RegisterDescriptorCallback(ProcessDescriptor);

auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance();
ReturnErrorOnFailure(
imageProcessor.RegisterProcessor(static_cast<uint32_t>(OTAProcessorTag::kApplicationProcessor), &sApplicationProcessor));
ReturnErrorOnFailure(
imageProcessor.RegisterProcessor(static_cast<uint32_t>(OTAProcessorTag::kFactoryDataProcessor), &sFactoryDataProcessor));

#ifndef SLI_SI91X_MCU_INTERFACE
static chip::OTAFirmwareProcessor sApplicationProcessor;
sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor);
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(APPLICATION, &sApplicationProcessor));
#endif

#if OTA_TEST_CUSTOM_TLVS
static chip::OTACustomProcessor customProcessor1;
Expand All @@ -63,5 +73,12 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit()
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(9, &customProcessor2));
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(10, &customProcessor3));
#endif

#ifdef SL_WIFI
static chip::OTAWiFiFirmwareProcessor sWifiFirmwareProcessor;
sWifiFirmwareProcessor.RegisterDescriptorCallback(ProcessDescriptor);
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast<uint32_t>(OTAProcessorTag::kWiFiProcessor), &sWifiFirmwareProcessor));
#endif

return CHIP_NO_ERROR;
}
}
21 changes: 18 additions & 3 deletions src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <platform/DiagnosticDataProvider.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/GenericConfigurationManagerImpl.h>

#include <platform/silabs/multi-ota/OTAMultiImageProcessorImpl.h>

using namespace chip::DeviceLayer;
Expand All @@ -35,8 +34,18 @@ static chip::OTAMultiImageProcessorImpl gImageProcessor;
#endif // SL_WIFI

extern "C" {
#if SL_BTLCTRL_MUX
#include "btl_interface.h"
#include "sl_core.h"
#endif // SL_BTLCTRL_MUX
#include "em_bus.h" // For CORE_CRITICAL_SECTION
#ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP
#include "spi_multiplex.h"
#include "btl_interface.h"
#endif // SLI_SI91X_MCU_INTERFACE
#ifdef CHIP_9117
#include "spi_multiplex.h"
#endif // CHIP_9117
}

namespace chip {
Expand All @@ -59,7 +68,6 @@ void OTAMultiImageProcessorImpl::Clear()
mParams.totalFileBytes = 0;
mParams.downloadedBytes = 0;
mCurrentProcessor = nullptr;

ReleaseBlock();
}

Expand Down Expand Up @@ -115,7 +123,9 @@ void OTAMultiImageProcessorImpl::HandlePrepareDownload(intptr_t context)

ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started");

#ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP
CORE_CRITICAL_SECTION(bootloader_init();)
#endif

imageProcessor->mParams.downloadedBytes = 0;

Expand Down Expand Up @@ -202,6 +212,8 @@ CHIP_ERROR OTAMultiImageProcessorImpl::SelectProcessor(ByteSpan & block)

CHIP_ERROR OTAMultiImageProcessorImpl::RegisterProcessor(uint32_t tag, OTATlvProcessor * processor)
{

ChipLogDetail(SoftwareUpdate, "RegisterProcessor with tag: %ld", tag);
auto pair = mProcessorMap.find(tag);
if (pair != mProcessorMap.end())
{
Expand Down Expand Up @@ -420,9 +432,12 @@ void OTAMultiImageProcessorImpl::HandleApply(intptr_t context)
imageProcessor->mAccumulator.Clear();

ChipLogProgress(SoftwareUpdate, "HandleApply: Finished");

// This reboots the device
// TODO: check where to put this
#ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP
CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();)
#endif
// ConfigurationManagerImpl().StoreSoftwareUpdateCompleted();
}

CHIP_ERROR OTAMultiImageProcessorImpl::ReleaseBlock()
Expand Down
13 changes: 11 additions & 2 deletions src/platform/silabs/multi-ota/OTATlvProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ using namespace ::chip::DeviceLayer::Internal;

namespace chip {

#ifdef SL_MATTER_ENABLE_OTA_ENCRYPTION
typedef enum
{
APPLICATION,
BOOTLOADER,
FACTORY_DATA,
WIFI_917_NCP_TA,
WIFI_917_SOC_TA, /* This is used as scan result and start */
WIFI_917_NCP_COMBINED
} OTAImageType;

#if SL_MATTER_ENABLE_OTA_ENCRYPTION
constexpr uint8_t au8Iv[] = { 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x00, 0x00, 0x00, 0x00 };
#endif
CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block)
Expand All @@ -57,7 +67,6 @@ CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block)
}
}
}

return status;
}

Expand Down
12 changes: 8 additions & 4 deletions src/platform/silabs/multi-ota/OTATlvProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ struct OTATlvHeader
uint32_t length;
};

// TLV tags synced with ota files generate by scripts/tools/silabs/ota/ota_image_tool.py
// TLV tags synced with ota files generated by scripts/tools/silabs/ota/ota_image_tool.py
enum class OTAProcessorTag
{
kApplicationProcessor = 1,
kBootloaderProcessor = 2,
kFactoryDataProcessor = 3
kApplicationProcessor = 1,
kBootloaderProcessor = 2 ,
kFactoryDataProcessor = 3,
kWiFiProcessor = 4,
kCustomProcessor1 = 8,
kCustomProcessor2 = 9,
kCustomProcessor3 = 10,
};

/**
Expand Down
47 changes: 47 additions & 0 deletions src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Copyright (c) 2023 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 <include/platform/CHIPDeviceLayer.h>
#include <platform/silabs/multi-ota/OTAMultiImageProcessorImpl.h>

#include <app/clusters/ota-requestor/OTARequestorInterface.h>

#include <platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h>
#if OTA_TEST_CUSTOM_TLVS
#include <platform/silabs/multi-ota/OTACustomProcessor.h>
#endif

CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor)
{
auto desc = static_cast<chip::OTAFirmwareProcessor::Descriptor *>(descriptor);
ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate);

return CHIP_NO_ERROR;
}

CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit()
{
static chip::OTAFirmwareProcessor sApplicationProcessor;

sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor);

auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance();
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(1, &sApplicationProcessor));

return CHIP_NO_ERROR;
}
Loading
Loading