[Telink] Add BootReason implementation to pass TC-SU-2.6 (#39155)
* [Telink] Add BootReason implementation to pass TC-SU-2.6
* [Telink] add settings_subsys_init for early operations
* [Telink] Update image
---------
Co-authored-by: Andrei Litvin <andy314@gmail.com>
diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml
index 15c19b6..350419b 100644
--- a/.github/workflows/chef.yaml
+++ b/.github/workflows/chef.yaml
@@ -133,7 +133,7 @@
platform: telink
# - name: Update Zephyr to specific revision (for developers purpose)
# shell: bash
- # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ed037d7de7c23eb14c908453d2d481cdf782796a"
+ # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 8f0b3c350ff99dce5569bf4879d322d3aa0a84fd"
- name: CI Examples Telink
shell: bash
run: |
diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml
index f50f1b3..2f28dd7 100644
--- a/.github/workflows/examples-telink.yaml
+++ b/.github/workflows/examples-telink.yaml
@@ -58,8 +58,7 @@
gh-context: ${{ toJson(github) }}
# - name: Update Zephyr version 3.7.0 (develop) to specific revision (for developers purpose)
- # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py deb9deef8014c14dff216ec80da7c79d9d6204d3"
-
+ # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 8f0b3c350ff99dce5569bf4879d322d3aa0a84fd"
- name: Build example Telink (B92 retention) Air Quality Sensor App
# Run test for master and s07641069 PRs
if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip'
@@ -392,8 +391,7 @@
gh-context: ${{ toJson(github) }}
# - name: Update Zephyr version 3.3.0 (develop_3.3) to specific revision (for developers purpose)
- # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 0457e76f4b5f66ba7fb3ba13d1f90204e4da8b7e"
-
+ # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py dc28389d22e984b61715ea3c965605c247854cab"
- name: Build example Telink (B92 retention) Air Quality Sensor App
# Run test for master and s07641069 PRs
if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip'
diff --git a/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp b/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
index 06936d1..405fde7 100644
--- a/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
+++ b/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2022,2024 Project CHIP Authors
+ * Copyright (c) 2022-2025 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.
@@ -34,6 +34,8 @@
#if CHIP_DEVICE_LAYER_TARGET_NRFCONNECT
#include <platform/nrfconnect/Reboot.h>
+#elif CHIP_DEVICE_LAYER_TARGET_TELINK
+#include <platform/telink/Reboot.h>
#elif defined(CONFIG_MCUBOOT_IMG_MANAGER)
#include <zephyr/dfu/mcuboot.h>
#endif
@@ -123,7 +125,7 @@
if (reason & RESET_SOFTWARE)
{
-#if CHIP_DEVICE_LAYER_TARGET_NRFCONNECT
+#if CHIP_DEVICE_LAYER_TARGET_NRFCONNECT || CHIP_DEVICE_LAYER_TARGET_TELINK
if (GetSoftwareRebootReason() == SoftwareRebootReason::kSoftwareUpdate)
{
return BootReasonType::kSoftwareUpdateCompleted;
diff --git a/src/platform/telink/BUILD.gn b/src/platform/telink/BUILD.gn
index e65a44c..bd3e797 100644
--- a/src/platform/telink/BUILD.gn
+++ b/src/platform/telink/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2021-2024 Project CHIP Authors
+# Copyright (c) 2021-2025 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.
@@ -46,6 +46,8 @@
"InetPlatformConfig.h",
"KeyValueStoreManagerImpl.h",
"PlatformManagerImpl.h",
+ "Reboot.cpp",
+ "Reboot.h",
"SystemPlatformConfig.h",
]
diff --git a/src/platform/telink/OTAImageProcessorImpl.cpp b/src/platform/telink/OTAImageProcessorImpl.cpp
index d3bcff3..1a08fc8 100644
--- a/src/platform/telink/OTAImageProcessorImpl.cpp
+++ b/src/platform/telink/OTAImageProcessorImpl.cpp
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2022 Project CHIP Authors
+ * Copyright (c) 2022-2025 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.
@@ -17,6 +17,8 @@
#include "OTAImageProcessorImpl.h"
+#include "Reboot.h"
+
#include <app/clusters/ota-requestor/OTADownloader.h>
#include <app/clusters/ota-requestor/OTARequestorInterface.h>
#include <platform/CHIPDeviceLayer.h>
@@ -123,7 +125,7 @@
[](System::Layer *, void * /* context */) {
PlatformMgr().HandleServerShuttingDown();
k_msleep(CHIP_DEVICE_CONFIG_SERVER_SHUTDOWN_ACTIONS_SLEEP_MS);
- sys_reboot(SYS_REBOOT_WARM);
+ Reboot(SoftwareRebootReason::kSoftwareUpdate);
},
nullptr /* context */);
}
diff --git a/src/platform/telink/Reboot.cpp b/src/platform/telink/Reboot.cpp
new file mode 100644
index 0000000..2e6d3c1
--- /dev/null
+++ b/src/platform/telink/Reboot.cpp
@@ -0,0 +1,55 @@
+/*
+ *
+ * Copyright (c) 2025 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.
+ * 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 "Reboot.h"
+
+#include <platform/KeyValueStoreManager.h>
+
+#include <zephyr/settings/settings.h>
+#include <zephyr/sys/reboot.h>
+
+using namespace ::chip::DeviceLayer::PersistedStorage;
+
+namespace chip {
+namespace DeviceLayer {
+
+// Define non-volatile storage key for RebootReason.
+static constexpr char kRebootReason[] = "RebootReason";
+
+void Reboot(SoftwareRebootReason reason)
+{
+ KeyValueStoreMgr().Put(kRebootReason, &reason, sizeof(reason));
+
+ sys_reboot(SYS_REBOOT_WARM);
+}
+
+SoftwareRebootReason GetSoftwareRebootReason()
+{
+ SoftwareRebootReason reason = SoftwareRebootReason::kOther;
+
+ settings_subsys_init();
+
+ if (KeyValueStoreMgr().Get(kRebootReason, &reason, sizeof(reason)) == CHIP_NO_ERROR)
+ {
+ KeyValueStoreMgr().Delete(kRebootReason);
+ }
+
+ return reason;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/telink/Reboot.h b/src/platform/telink/Reboot.h
new file mode 100644
index 0000000..5678176
--- /dev/null
+++ b/src/platform/telink/Reboot.h
@@ -0,0 +1,35 @@
+/*
+ *
+ * Copyright (c) 2025 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.
+ * 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 <cstdint>
+
+namespace chip {
+namespace DeviceLayer {
+
+enum class SoftwareRebootReason : uint8_t
+{
+ kSoftwareUpdate,
+ kOther
+};
+
+[[noreturn]] void Reboot(SoftwareRebootReason reason);
+SoftwareRebootReason GetSoftwareRebootReason();
+
+} // namespace DeviceLayer
+} // namespace chip