Skip to content

Commit

Permalink
[Bouffalolab]improvements related to ota requestor (#26013)
Browse files Browse the repository at this point in the history
* [Bouffalolab]improvements related to ota requestor:
1. init ota requestor after got IPV6 address or thread attached.
2. sync-up ota related API changes in bl_iot_sdk.
3. make the ota auto reboot delay configureable.
4. update bl_iot_sdk, commit id 7ca85fd7.

* Restyled by clang-format

* Restyled by gn

* fix compile error after auto-rebase

* add time unit to the timeout/delay variables

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: wyhong <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Dec 12, 2023
1 parent e8e0c59 commit 1657650
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 22 deletions.
8 changes: 6 additions & 2 deletions examples/lighting-app/bouffalolab/bl602/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ declare_args() {
chip_print_memory_usage = true

# OTA periodic query timeout in seconds
ota_periodic_query_timeout = 86400
ota_periodic_query_timeout_seconds = 86400

# reboot delay in seconds to apply new OTA image
ota_auto_reboot_delay_seconds = 5

enable_heap_monitoring = false

Expand All @@ -66,7 +69,8 @@ bl_iot_sdk("sdk") {
"INCLUDE_xSemaphoreGetMutexHolder=1",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}",
"OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout}",
"OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout_seconds}",
"OTA_AUTO_REBOOT_DELAY=${ota_auto_reboot_delay_seconds}",
"CHIP_UART_BAUDRATE=${baudrate}",
"SYS_AOS_LOOP_ENABLE",
]
Expand Down
8 changes: 6 additions & 2 deletions examples/lighting-app/bouffalolab/bl702/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ declare_args() {
chip_print_memory_usage = true

# OTA periodic query timeout in seconds
ota_periodic_query_timeout = 86400
ota_periodic_query_timeout_seconds = 86400

# reboot delay in seconds to apply new OTA image
ota_auto_reboot_delay_seconds = 5

config_cache_size = 8192

Expand Down Expand Up @@ -69,7 +72,8 @@ bl_iot_sdk("sdk") {
"INCLUDE_xSemaphoreGetMutexHolder=1",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}",
"OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout}",
"OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout_seconds}",
"OTA_AUTO_REBOOT_DELAY=${ota_auto_reboot_delay_seconds}",
"OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY=40",
"PRINT_DEBUG=0",
]
Expand Down
4 changes: 0 additions & 4 deletions examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ SECTIONS
{
*(.rsvd_data)
*(.ble_rsvd_mem)

KEEP(*AppTask.cpp.o(.bss.*appStack*))
KEEP(*main.cpp.o(.bss.*TimerTaskStack*))

} >hbnram

.tcmcode : ALIGN(4)
Expand Down
9 changes: 9 additions & 0 deletions examples/platform/bouffalolab/common/plat/OTAConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ void OTAConfig::Init()
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
// Initialize and interconnect the Requestor and Image Processor objects -- END
}

void OTAConfig::InitOTARequestorHandler(chip::System::Layer * systemLayer, void * appState)
{
if (!chip::GetRequestorInstance())
{
ChipLogProgress(NotSpecified, "Init OTA Requestor");
OTAConfig::Init();
}
}
2 changes: 2 additions & 0 deletions examples/platform/bouffalolab/common/plat/OTAConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class OTAConfig
OTAConfig(){};

static void Init();
static constexpr uint32_t kInitOTARequestorDelaySec = 3;
static void InitOTARequestorHandler(chip::System::Layer * systemLayer, void * appState);
};
17 changes: 9 additions & 8 deletions examples/platform/bouffalolab/common/plat/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
GetAppTask().PostEvent(AppTask::APP_EVENT_SYS_PROVISIONED);
GetAppTask().mIsConnected = true;
#ifdef OTA_ENABLED
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec),
OTAConfig::InitOTARequestorHandler, nullptr);
#endif
}
break;
#endif
Expand Down Expand Up @@ -155,11 +159,14 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
ChipLogProgress(NotSpecified, "Initializing route hook...");
bl_route_hook_init();

#ifdef OTA_ENABLED
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec),
OTAConfig::InitOTARequestorHandler, nullptr);
#endif
}
break;
#endif

break;
default:
break;
}
Expand Down Expand Up @@ -249,12 +256,6 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
PlatformMgr().AddEventHandler(ChipEventHandler, 0);

#ifdef OTA_ENABLED
chip::DeviceLayer::PlatformMgr().LockChipStack();
OTAConfig::Init();
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
#endif // OTA_ENABLED

#if PW_RPC_ENABLED
chip::rpc::Init();
#endif
Expand Down
7 changes: 4 additions & 3 deletions src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
return;
}

if (hosal_ota_finish(1, 0) < 0)
if (hosal_ota_check() < 0)
{
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
ChipLogProgress(SoftwareUpdate, "OTA image verification error");
Expand All @@ -157,8 +157,9 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
return;
}

hosal_ota_apply(0);
DeviceLayer::SystemLayer().StartTimer(
System::Clock::Seconds32(4),
System::Clock::Seconds32(OTA_AUTO_REBOOT_DELAY),
[](Layer *, void *) {
ChipLogProgress(SoftwareUpdate, "Rebooting...");
hal_reboot();
Expand All @@ -174,7 +175,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context)
return;
}

hosal_ota_finish(1, 0);
hosal_ota_abort();

imageProcessor->ReleaseBlock();
}
Expand Down
15 changes: 12 additions & 3 deletions src/platform/bouffalolab/BL702/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern "C" {
#include <hosal_ota.h>
}

using namespace chip::System;

namespace chip {

CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
Expand Down Expand Up @@ -98,7 +100,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
return;
}

if (hosal_ota_finish(1, 0) < 0)
if (hosal_ota_check() < 0)
{
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
ChipLogProgress(SoftwareUpdate, "OTA image verification error");
Expand All @@ -120,7 +122,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
return;
}

hal_reboot();
hosal_ota_apply(0);
DeviceLayer::SystemLayer().StartTimer(
System::Clock::Seconds32(OTA_AUTO_REBOOT_DELAY),
[](Layer *, void *) {
ChipLogProgress(SoftwareUpdate, "Rebooting...");
hal_reboot();
},
nullptr);
}

void OTAImageProcessorImpl::HandleAbort(intptr_t context)
Expand All @@ -131,7 +140,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context)
return;
}

hosal_ota_finish(1, 0);
hosal_ota_abort();

imageProcessor->ReleaseBlock();
}
Expand Down
1 change: 1 addition & 0 deletions third_party/bouffalolab/bl602/bl_iot_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ template("bl_iot_sdk") {
":${sdk_target_name}_config_BSP_Driver",
":${sdk_target_name}_config_freertos",
":${sdk_target_name}_config_utils",
":${sdk_target_name}_config_hosal",
]
public_configs = [
":${sdk_target_name}_config",
Expand Down

0 comments on commit 1657650

Please sign in to comment.