diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index 3b510c05237b..3d8db2c7a382 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -1789,3 +1789,12 @@ zigbeealliance zigbeethread zsdk ZXing +bdk +Changelog +changelog +devicetree +DLM +downloaders +ILM +tlk +udev \ No newline at end of file diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 551d50c5c03f..fdc601917e5c 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -92,8 +92,9 @@ jobs: with: gh-context: ${{ toJson(github) }} - # - name: Update Zephyr version 4.1.0 (develop) to specific revision (for developers purpose) - # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 1f4804a19fe7ba792bfc315948043d5515e74cd2" + - name: Update Zephyr version 4.1.0 (develop) to specific revision (for developers purpose) + run: + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git d3a2a90f44f5e85868e91ff577636e02460c574b --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 2488b5b8bd5122f68d087ba2cd5a8f0c74572b8f" - name: Download Factory Data tools uses: actions/download-artifact@v8 @@ -258,28 +259,41 @@ jobs: - name: clean out build output (keep tools) run: rm -rf ./out/telink* - - name: Build example Telink (tl721x) Lighting App with OTA (LZMA), Shell, Factory Data + - name: Build example Telink (tl521x) Lighting App with Factory Data, 4Mb flash # Run test for master and all PRs run: | ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-light-ota-compress-lzma-shell-factory-data' build" + "./scripts/build/build_examples.py --target 'telink-tl5218x-light-ota-factory-data-4mb' build" .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - telink tl7218x light-app-ota-compress-lzma-shell-factory-data \ - out/telink-tl7218x-light-ota-compress-lzma-shell-factory-data/zephyr/zephyr.elf \ + telink tl5218x light-app-ota-factory-data-4mb \ + out/telink-tl5218x-light-ota-factory-data-4mb/zephyr/zephyr.elf \ /tmp/bloat_reports/ - name: clean out build output (keep tools) run: rm -rf ./out/telink* - - name: Build example Telink (tl721x) Lighting App with TFLM - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' + # TODO: tl521x_retention light switch app can build but may not run normally, need further porting. + - name: Build example Telink (tl521x_retention) Light Switch App with OTA, Factory Data + # Run test for master and all PRs run: | ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-light-tflm' build" + "./scripts/build/build_examples.py --target 'telink-tl5218x_retention-light-switch-ota-compress-lzma-factory-data' build" + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + telink tl5218x_retention light-switch-app-ota-compress-lzma-factory-data \ + out/telink-tl5218x_retention-light-switch-ota-compress-lzma-factory-data/zephyr/zephyr.elf \ + /tmp/bloat_reports/ + + - name: clean out build output (keep tools) + run: rm -rf ./out/telink* + + - name: Build example Telink (tl721x) Lighting App with OTA (LZMA), Shell, Factory Data + # Run test for master and all PRs + run: | + ./scripts/run_in_build_env.sh \ + "./scripts/build/build_examples.py --target 'telink-tl7218x-light-ota-compress-lzma-shell-factory-data' build" .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - telink tl7218x light-app-tflm \ - out/telink-tl7218x-light-tflm/zephyr/zephyr.elf \ + telink tl7218x light-app-ota-compress-lzma-shell-factory-data \ + out/telink-tl7218x-light-ota-compress-lzma-shell-factory-data/zephyr/zephyr.elf \ /tmp/bloat_reports/ - name: clean out build output (keep tools) diff --git a/.gitignore b/.gitignore index dbee6b8b5d2f..b083ec1d0e83 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,9 @@ imgui.ini # Joint Fabric test harness output file admin_storage.json + +# ignore build output directories +build-* +build_* +factory_data* +*.patch diff --git a/MATTER_README.md b/MATTER_README.md new file mode 100644 index 000000000000..07b959115615 --- /dev/null +++ b/MATTER_README.md @@ -0,0 +1,229 @@ +# Documentation links + +- [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/project-chip/connectedhomeip) +- [Matter SDK documentation page](https://project-chip.github.io/connectedhomeip-doc/index.html) +- [Matter SDK Coverage Report](https://matter-build-automation.ue.r.appspot.com/) + +# Matter + +[![Builds](https://github.com/project-chip/connectedhomeip/workflows/Builds/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/build.yaml) + +**Builds** + +[![Android](https://github.com/project-chip/connectedhomeip/workflows/Android/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/android.yaml) +[![Ameba](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Ameba/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-ameba.yaml) +[![ASR](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20ASR/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-asr.yaml) +[![BouffaloLab](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20BouffaloLab/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-bouffalolab.yaml) +[![Darwin](https://github.com/project-chip/connectedhomeip/workflows/Darwin/badge.svg)](https://github.com/project-chip/connectedhomeip/blob/master/.github/workflows/darwin.yaml) +[![TI CC26X2X7](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20TI%20CC13XX_26XX/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-cc13xx_26xx.yaml) +[![TI CC32XX](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20TI%20CC32XX/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-cc32xx.yaml) +[![EFR32](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20EFR32/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-efr32.yaml) +[![ESP32](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20ESP32/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-esp32.yaml) +[![Infineon](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-infineon.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-infineon.yaml) +[![i.MX Linux](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20i.MX%20Linux/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-linux-imx.yaml) +[![NXP FreeRTOS/Zephyr](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-nxp.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-nxp.yaml) +[![Linux ARM](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Linux%20ARM/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-linux-arm.yaml) +[![Linux Standalone](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Linux%20Standalone/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-linux-standalone.yaml) +[![nRF Connect SDK](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20nRF%20Connect%20SDK/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-nrfconnect.yaml) +[![QPG](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20QPG/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-qpg.yaml) +[![STM32](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20stm32/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-stm32.yaml) +[![Telink](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Telink/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-telink.yaml) +[![Tizen](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Tizen/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-tizen.yaml) + +**Tests** + +[![Tests](https://github.com/project-chip/connectedhomeip/actions/workflows/tests.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/tests.yaml) +[![Unit / Integration Tests](https://github.com/project-chip/connectedhomeip/workflows/Unit%20/%20Integration%20Tests/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/unit_integration_test.yaml) +[![Cirque](https://github.com/project-chip/connectedhomeip/workflows/Cirque/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/cirque.yaml) +[![QEMU](https://github.com/project-chip/connectedhomeip/workflows/QEMU/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/qemu.yaml) + +**Tools** + +[![ZAP Templates](https://github.com/project-chip/connectedhomeip/workflows/ZAP/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/zap_templates.yaml) + +**Documentation** + +[![Documentation Build](https://github.com/project-chip/connectedhomeip/actions/workflows/docbuild.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/docbuild.yaml) + +# About + +Matter (formerly Project CHIP) creates more connections between more objects, +simplifying development for manufacturers and increasing compatibility for +consumers, guided by the Connectivity Standards Alliance. + +# What is Matter? + +Matter is a unified, open-source application-layer connectivity standard built +to enable developers and device manufacturers to connect and build reliable, and +secure ecosystems and increase compatibility among connected home devices. It is +built with market-proven technologies using Internet Protocol (IP) and is +compatible with Thread and Wi-Fi network transports. Matter was developed by a +Working Group within the Connectivity Standards Alliance (Alliance). This +Working Group develops and promotes the adoption of the Matter standard, a +royalty-free connectivity standard to increase compatibility among smart home +products, with security as a fundamental design tenet. The vision that led major +industry players to come together to build Matter is that smart connectivity +should be simple, reliable, and interoperable. + +Matter simplifies development for manufacturers and increases compatibility for +consumers. + +The standard was built around a shared belief that smart home devices should be +secure, reliable, and seamless to use. By building upon Internet Protocol (IP), +Matter enables communication across smart home devices, mobile apps, and cloud +services and defines a specific set of IP-based networking technologies for +device certification. + +The Matter specification details everything necessary to implement a Matter +application and transport layer stack. It is intended to be used by implementers +as a complete specification. + +The Alliance officially opened the Matter Working Group on January 17, 2020, and +the specification is +[available](https://csa-iot.org/developer-resource/specifications-download-request/) +for adoption now. + +Visit [buildwithmatter.com](https://buildwithmatter.com) to learn more and read +the latest news and updates about the project. + +# Project Overview + +## Development Goals + +Matter is developed with the following goals and principles in mind: + +**Unifying:** Matter is built with and on top of market-tested, existing +technologies. + +**Interoperable:** The specification permits communication between any +Matter-certified device, subject to users’ permission. + +**Secure:** The specification leverages modern security practices and protocols. + +**User Control:** The end user controls authorization for interaction with +devices. + +**Federated:** No single entity serves as a throttle or a single point of +failure for root of trust. + +**Robust:** The set of protocols specifies a complete lifecycle of a device — +starting with the seamless out-of-box experience, through operational protocols, +to device and system management specifications required for proper function in +the presence of change. + +**Low Overhead:** The protocols are practically implementable on low +compute-resource devices, such as MCUs. + +**Pervasive:** The protocols are broadly deployable and accessible, by +leveraging IP and being implementable on low-capability devices. + +**Ecosystem-Flexible:** The protocol is flexible enough to accommodate +deployment in ecosystems with differing policies. + +**Easy to Use:** The protocol provides smooth, cohesive, integrated provisioning +and out-of-box experience. + +**Open:** The Project’s design and technical processes are open and transparent +to the general public, including non-members wherever possible. + +## Architecture Overview + +Matter aims to build a universal IPv6-based communication protocol for smart +home devices. The protocol defines the application layer that will be deployed +on devices and the different link layers to help maintain interoperability. The +following diagram illustrates the normal operational mode of the stack: +![Matter Architecture Overview](docs/images/Matter_Arch_Overview.png) + +The architecture is divided into layers to help separate the different +responsibilities and introduce a good level of encapsulation among the various +pieces of the protocol stack. The vast majority of interactions flow through the +stack captured in the following Figure: + +![Matter Stack Architecture](docs/images/Matter_Layered_Arch.png) + +1. **Application:** High-order business logic of a device. For example, an + application that is focused on lighting might contain logic to handle turning + on/off the bulb as well as its color characteristics. + +2) **Data Model:** The data layer corresponds to the data and verb elements that + help support the functionality of the application. The Application operates + on these data structures when there is an intent to interact with the device. + +3. **Interaction Model:** The Interaction Model layer defines a set of + interactions that can be performed between a client and server device. For + example, reading or writing attributes on a server device would correspond to + application behavior on the device. These interactions operate on the + elements defined at the data model layer. + +4) **Action Framing:** Once an action is constructed using the Interaction + Model, it is serialized into a prescribed packed binary format to encode for + network transmission. + +5. **Security:** An encoded action frame is then sent down to the Security Layer + to encrypt and sign the payload to ensure that data is secured and + authenticated by both sender and receiver of a packet. + +6. **Message Framing & Routing:** With an interaction encrypted and signed, the + Message Layer constructs the payload format with required and optional header + fields; which specify the message's properties and some routing information. + +7) **IP Framing & Transport Management:** After the final payload has been + constructed, it is sent to the underlying transport protocol for IP + management of the data. + +# Current Status of Matter + +Matter’s design and technical processes are intended to be open and transparent +to the general public, including to Working Group non-members wherever possible. +The availability of this GitHub repository and its source code under an Apache +v2 license is an important and demonstrable step to achieving this commitment. +Matter endeavors to bring together the best aspects of market-tested +technologies and redeploy them as a unified and cohesive whole-system solution. +The overall goal of this approach is to bring the benefits of Matter to +consumers and manufacturers as quickly as possible. As a result, what you +observe in this repository is an implementation-first approach to the technical +specification, vetting integrations in practice. The Matter repository is +growing and evolving to implement the overall architecture. The repository +currently contains the security foundations, message framing and dispatch, and +an implementation of the interaction model and data model. The code examples +show simple interactions, and are supported on multiple transports -- Wi-Fi and +Thread -- starting with resource-constrained (i.e., memory, processing) silicon +platforms to help ensure Matter’s scalability. + +# How to Contribute + +We welcome your contributions to Matter. Read our contribution guidelines +[here](./CONTRIBUTING.md). + +# Building and Developing in Matter + +Instructions about how to build Matter can be found [here](./docs/README.md) . + +# Directory Structure + +The Matter repository is structured as follows: + +| File/Folder | Content | +| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | +| build | Build system support content and built output directories | +| build_overrides | Build system parameter customization for different platforms | +| config | Project configurations | +| credentials | Development and test credentials | +| docs | Documentation, including guides. Visit the [Matter SDK documentation page](https://project-chip.github.io/connectedhomeip-doc/index.html) to read it. | +| examples | Example firmware applications that demonstrate use of Matter | +| integrations | 3rd party integrations | +| scripts | Scripts needed to work with the Matter repository | +| src | Implementation of Matter | +| third_party | 3rd party code used by Matter | +| zzz_generated | ZAP generated template code - Revolving around cluster information | +| BUILD.gn | Build file for the GN build system | +| CODE_OF_CONDUCT.md | Code of conduct for Matter and contribution to it | +| CONTRIBUTING.md | Guidelines for contributing to Matter | +| LICENSE | Matter license file | +| REVIEWERS.md | PR reviewers | +| gn_build.sh | Build script for specific projects such as Android, EFR32, etc. | +| README.md | This file | + +# License + +Matter is released under the [Apache 2.0 license](./LICENSE). diff --git a/README.md b/README.md index 3eb5e2715d83..e83e60cd494f 100644 --- a/README.md +++ b/README.md @@ -1,233 +1,219 @@ -# Documentation links +# Telink Matter SDK -- [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/project-chip/connectedhomeip) -- [Matter SDK documentation page](https://project-chip.github.io/connectedhomeip-doc/index.html) -- [Matter SDK Coverage Report](https://matter-build-automation.ue.r.appspot.com/) -- [CI REPL Tests Dashboard](https://project-chip.github.io/connectedhomeip/allure-report/ci_tests/) -- [Nightly Tests Dashboard](https://project-chip.github.io/connectedhomeip/allure-report/nightly/) +[![Telink Website](https://img.shields.io/badge/Website-Telink-blue?style=flat-square)](https://www.telink-semi.com/) +[![Forum](https://img.shields.io/badge/Forum-Telink-green?style=flat-square)](https://forum.telink-semi.cn/) +[![License](https://img.shields.io/badge/License-Apache%202.0-red?style=flat-square)](LICENSE) +[![Matter](https://img.shields.io/badge/Matter-v1.5-green?style=flat-square)](https://github.com/project-chip/connectedhomeip) -# Matter +--- -[![Builds](https://github.com/project-chip/connectedhomeip/workflows/Builds/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/build.yaml) +> 📖 This is the README for the **Telink Matter SDK** (fork). For the upstream +> Matter (Project CHIP) README, see [MATTER_README.md](MATTER_README.md). -**Builds** +**A Matter protocol implementation for Telink RISC-V SoC platforms based on the +Connected Home over IP (CHIP) project** -[![Android](https://github.com/project-chip/connectedhomeip/workflows/Android/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/android.yaml) -[![Ameba](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Ameba/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-ameba.yaml) -[![ASR](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20ASR/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-asr.yaml) -[![BouffaloLab](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20BouffaloLab/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-bouffalolab.yaml) -[![Darwin](https://github.com/project-chip/connectedhomeip/workflows/Darwin/badge.svg)](https://github.com/project-chip/connectedhomeip/blob/master/.github/workflows/darwin.yaml) -[![TI CC26X2X7](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20TI%20CC13XX_26XX/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-cc13xx_26xx.yaml) -[![TI CC32XX](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20TI%20CC32XX/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-cc32xx.yaml) -[![EFR32](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20EFR32/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-efr32.yaml) -[![ESP32](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20ESP32/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-esp32.yaml) -[![Infineon](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-infineon.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-infineon.yaml) -[![i.MX Linux](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20i.MX%20Linux/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-linux-imx.yaml) -[![NXP FreeRTOS/Zephyr](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-nxp.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-nxp.yaml) -[![Linux ARM](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Linux%20ARM/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-linux-arm.yaml) -[![Linux Standalone](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Linux%20Standalone/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-linux-standalone.yaml) -[![nRF Connect SDK](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20nRF%20Connect%20SDK/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-nrfconnect.yaml) -[![QPG](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20QPG/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-qpg.yaml) -[![STM32](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20stm32/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-stm32.yaml) -[![Telink](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Telink/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-telink.yaml) -[![Tizen](https://github.com/project-chip/connectedhomeip/workflows/Build%20example%20-%20Tizen/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/examples-tizen.yaml) +- For development environment setup, SDK acquisition, and quick-start + instructions, refer to the + [Telink Matter Getting Started Guide](docs/platforms/telink/telink_getting_started.md). +- For a deeper walkthrough, see the online + [Telink Matter Developer Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/) + (Chapter **Obtaining Matter Source Code** covers the initial setup). +- For a detailed list of supported devices and resource usage, refer to the + [Release Note](docs/platforms/telink/releases/telink_release_notes.md) -**Tests** +--- -[![Tests-Master](https://github.com/project-chip/connectedhomeip/actions/workflows/tests.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/tests.yaml) -[![Tests-LTS](https://github.com/project-chip/connectedhomeip/actions/workflows/tests.yaml/badge.svg?branch=v1.4.2-branch)](https://github.com/project-chip/connectedhomeip/actions/workflows/tests.yaml?query=branch:v1.4.2-branch) -[![Unit / Integration Tests](https://github.com/project-chip/connectedhomeip/workflows/Unit%20/%20Integration%20Tests/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/unit_integration_test.yaml) -[![Cirque](https://github.com/project-chip/connectedhomeip/workflows/Cirque/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/cirque.yaml) -[![QEMU](https://github.com/project-chip/connectedhomeip/workflows/QEMU/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/qemu.yaml) -[![Nightly Run](https://github.com/project-chip/connectedhomeip/actions/workflows/nightly.yaml/badge.svg?branch=master)](https://github.com/project-chip/connectedhomeip/actions/workflows/nightly.yaml) +## 📖 SDK Introduction -**Tools** +Telink Matter SDK is a software development platform that implements the Matter +protocol on Telink RISC-V SoC platforms. It is built on top of the Connected +Home over IP (CHIP) project and integrates with the Telink Zephyr SDK to provide +complete Matter-over-Thread support for Telink chips. -[![ZAP Templates](https://github.com/project-chip/connectedhomeip/workflows/ZAP/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/zap_templates.yaml) +### What's Included -**Documentation** +- ✅ Matter 1.5.1 protocol stack +- ✅ Telink Zephyr RTOS integration +- ✅ Thread networking via OpenThread +- ✅ BLE commissioning support +- ✅ OTA firmware update support +- ✅ Factory data provisioning +- ✅ Power management with retention RAM +- ✅ MCUboot bootloader integration +- ✅ Multiple sample applications -[![Documentation Build](https://github.com/project-chip/connectedhomeip/actions/workflows/docbuild.yaml/badge.svg)](https://github.com/project-chip/connectedhomeip/actions/workflows/docbuild.yaml) +### Supported Examples -# About +| Example Type | Description | +| ---------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| **Matter over Thread** | Lights, switches, locks, sensors, thermostats, bridges, Smoke/CO alarms, pumps, air quality sensors, window coverings, etc. | +| **Development Tools** | Shell, OTA requestor, all-clusters test apps | -Matter (formerly Project CHIP) creates more connections between more objects, -simplifying development for manufacturers and increasing compatibility for -consumers, guided by the Connectivity Standards Alliance. +--- -# What is Matter? +## 🚀 Quick Reference -Matter is a unified, open-source application-layer connectivity standard built -to enable developers and device manufacturers to connect and build reliable, and -secure ecosystems and increase compatibility among connected home devices. It is -built with market-proven technologies using Internet Protocol (IP) and is -compatible with Thread and Wi-Fi network transports. Matter was developed by a -Working Group within the Connectivity Standards Alliance (Alliance). This -Working Group develops and promotes the adoption of the Matter standard, a -royalty-free connectivity standard to increase compatibility among smart home -products, with security as a fundamental design tenet. The vision that led major -industry players to come together to build Matter is that smart connectivity -should be simple, reliable, and interoperable. +| Resource | Description | Link | +| --------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | +| **Release Note** | Telink Matter SDK Changelog & New Features | [Telink Matter SDK Release Note](docs/platforms/telink/releases/telink_release_notes.md) | +| **Get Started Guide** | SDK Quick Start Guide | [Telink Matter Getting Started](docs/platforms/telink/telink_getting_started.md) | +| **Developer Guide** | Telink Matter Developer Guide (online) | [Telink Matter Developer Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/) | +| **Examples** | Matter Sample Applications | See [examples](examples/) (filter by `telink`) | +| **Dependency** | Telink Zephyr SDK | [Telink Zephyr SDK](https://github.com/telink-semi/zephyr/blob/dev-tlk_v4.1/README.md) | -Matter simplifies development for manufacturers and increases compatibility for -consumers. +--- -The standard was built around a shared belief that smart home devices should be -secure, reliable, and seamless to use. By building upon Internet Protocol (IP), -Matter enables communication across smart home devices, mobile apps, and cloud -services and defines a specific set of IP-based networking technologies for -device certification. +## 📚 Additional Resources -The Matter specification details everything necessary to implement a Matter -application and transport layer stack. It is intended to be used by implementers -as a complete specification. +| Type | Resource | +| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | +| 🌐 **Telink Official Website** | [Telink - Chips for a Smarter IoT](https://www.telink-semi.com/) | +| 💬 **Telink Forum** | [Telink Technical Support](https://forum.telink-semi.cn/) | +| 📖 **Documentation** | [Telink Matter Developer Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/) | +| 📦 **Matter Community Project** | [Connected Home over IP](https://github.com/project-chip/connectedhomeip) | -The Alliance officially opened the Matter Working Group on January 17, 2020, and -the specification is -[available](https://csa-iot.org/developer-resource/specifications-download-request/) -for adoption now. +--- -Visit [buildwithmatter.com](https://buildwithmatter.com) to learn more and read -the latest news and updates about the project. - -# Project Overview - -## Development Goals - -Matter is developed with the following goals and principles in mind: +## 🔧 Environment Setup -**Unifying:** Matter is built with and on top of market-tested, existing -technologies. +### Prerequisites -**Interoperable:** The specification permits communication between any -Matter-certified device, subject to users’ permission. +The Telink Matter SDK is built **on top of** the Telink Zephyr SDK. They are +tightly coupled and must be installed as a matched pair. Set up the Telink +Zephyr SDK **before** the Matter SDK. -**Secure:** The specification leverages modern security practices and protocols. +#### Dependency Overview -**User Control:** The end user controls authorization for interaction with -devices. +| Component | Role | Required | +| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | :------: | +| **Telink Zephyr SDK** (`dev-tlk_v4.1` branch) | Provides the Zephyr RTOS core, Telink HAL, BLE stack, MCUBoot, OpenThread, the WEST tool and build toolchain | ✅ | +| **Telink Matter SDK** (`dev-tlk_v1.5` branch, this repo) | Provides Matter protocol stack and Telink Matter examples; consumes the Telink Zephyr SDK via `TELINK_ZEPHYR_BASE` | ✅ | -**Federated:** No single entity serves as a throttle or a single point of -failure for root of trust. +#### Setup Steps -**Robust:** The set of protocols specifies a complete lifecycle of a device — -starting with the seamless out-of-box experience, through operational protocols, -to device and system management specifications required for proper function in -the presence of change. - -**Low Overhead:** The protocols are practically implementable on low -compute-resource devices, such as MCUs. - -**Pervasive:** The protocols are broadly deployable and accessible, by -leveraging IP and being implementable on low-capability devices. - -**Ecosystem-Flexible:** The protocol is flexible enough to accommodate -deployment in ecosystems with differing policies. - -**Easy to Use:** The protocol provides smooth, cohesive, integrated provisioning -and out-of-box experience. - -**Open:** The Project’s design and technical processes are open and transparent -to the general public, including non-members wherever possible. +The setup follows the standard Zephyr "Environment Setup (Manual)" flow, +tailored for Telink. A full walkthrough (with host package versions and +screenshots) is in Chapter **Environment Setup (Manual)** of the +[Telink Matter Developer Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/); +the high-level steps are: -## Architecture Overview +1. **Set up the host (Ubuntu 24.04 LTS)** — install the OS packages required by + Zephyr and the Matter build: `git`, `python3` + `pip` + `venv`, `make`, + `gcc`, `g++`, `cmake`, `dfu-util`, `device-tree-compiler`, `libssl-dev`, + `libffi-dev`, `libudev-dev`, `usbutils` and the `curl`/`wget` downloaders. + Add the user to the `dialout`/`plugdev` groups and install the Telink USB + udev rules so the programmer is reachable without `sudo`. -Matter aims to build a universal IPv6-based communication protocol for smart -home devices. The protocol defines the application layer that will be deployed -on devices and the different link layers to help maintain interoperability. The -following diagram illustrates the normal operational mode of the stack: -![Matter Architecture Overview](docs/images/Matter_Arch_Overview.png) +2. **Install `west`** — Zephyr's multi-repository meta-tool. It is pulled in as + a Python package and must be available on `PATH` before any `west` command is + used. -The architecture is divided into layers to help separate the different -responsibilities and introduce a good level of encapsulation among the various -pieces of the protocol stack. The vast majority of interactions flow through the -stack captured in the following Figure: +3. **Get the Telink Zephyr SDK** — `west init` the Zephyr manifest repository + and then check out Telink SDK (branch `dev-tlk_v4.1`) . Run `west update` to + fetch Zephyr itself, the Telink HAL, OpenThread, MCUBoot. Download and + install Zephyr SDK toolchain (which provides the `riscv64-zephyr-elf` GCC + cross-compiler). See Chapter **Install Zephyr Project Environment** in the + [Matter Developer Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/) + for the exact `west` commands. -![Matter Stack Architecture](docs/images/Matter_Layered_Arch.png) +4. **Fetch the Telink BLE SDK binary** — `west update` does **not** fetch + `tl_ble_sdk` automatically (Zephyr CI disallows binary modules). Run + `./hal_v2/fetch_sdk.sh` inside `modules/hal/telink/` of the Zephyr SDK to + download the pre-built BLE stack. -1. **Application:** High-order business logic of a device. For example, an - application that is focused on lighting might contain logic to handle turning - on/off the bulb as well as its color characteristics. +5. **Get the Telink Matter SDK (this repo)** — clone the `dev-tlk_v1.5` branch + of this repository next to the Zephyr SDK. -2) **Data Model:** The data layer corresponds to the data and verb elements that - help support the functionality of the application. The Application operates - on these data structures when there is an intent to interact with the device. - -3. **Interaction Model:** The Interaction Model layer defines a set of - interactions that can be performed between a client and server device. For - example, reading or writing attributes on a server device would correspond to - application behavior on the device. These interactions operate on the - elements defined at the data model layer. - -4) **Action Framing:** Once an action is constructed using the Interaction - Model, it is serialized into a prescribed packed binary format to encode for - network transmission. - -5. **Security:** An encoded action frame is then sent down to the Security Layer - to encrypt and sign the payload to ensure that data is secured and - authenticated by both sender and receiver of a packet. +6. **Point the Matter SDK at the Zephyr SDK** — export `TELINK_ZEPHYR_BASE` so + the Matter build system can find Zephyr, the Telink HAL and the toolchain. + This variable must be set in every shell used for Matter builds. -6. **Message Framing & Routing:** With an interaction encrypted and signed, the - Message Layer constructs the payload format with required and optional header - fields; which specify the message's properties and some routing information. +7. **Bootstrap & activate the Matter build environment** — run the Matter + `scripts/activate.sh` bootstrap once to install `gn`, `ninja`, `pigweed` and + the Python dependencies, then source it in every new shell before building. -7) **IP Framing & Transport Management:** After the final payload has been - constructed, it is sent to the underlying transport protocol for IP - management of the data. +> 💡 The exact shell commands for each step (apt/pip/west/git/export) are listed +> in the **Environment Setup (Manual)** chapter of the +> [Telink Matter Developer Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/). +> Follow that guide to avoid version mismatches. -# Current Status of Matter +### Building Examples -Matter’s design and technical processes are intended to be open and transparent -to the general public, including to Working Group non-members wherever possible. -The availability of this GitHub repository and its source code under an Apache -v2 license is an important and demonstrable step to achieving this commitment. -Matter endeavors to bring together the best aspects of market-tested -technologies and redeploy them as a unified and cohesive whole-system solution. -The overall goal of this approach is to bring the benefits of Matter to -consumers and manufacturers as quickly as possible. As a result, what you -observe in this repository is an implementation-first approach to the technical -specification, vetting integrations in practice. The Matter repository is -growing and evolving to implement the overall architecture. The repository -currently contains the security foundations, message framing and dispatch, and -an implementation of the interaction model and data model. The code examples -show simple interactions, and are supported on multiple transports -- Wi-Fi and -Thread -- starting with resource-constrained (i.e., memory, processing) silicon -platforms to help ensure Matter’s scalability. +Matter builds use `west build` directly from each example's `telink` directory. +Each supported board ships a dedicated `*_README.md` under +`examples//telink/boards/` that lists the exact build commands for every +configuration of that board (default, OTA + LZMA, dual-mode Matter + Zigbee, 4 +MB flash, Software Version 2 for DFU/OTA images, etc.). -# How to Contribute - -We welcome your contributions to Matter. Read our contribution guidelines -[here](./CONTRIBUTING.md). - -# Building and Developing in Matter - -Instructions about how to build Matter can be found [here](./docs/README.md) . - -# Directory Structure - -The Matter repository is structured as follows: - -| File/Folder | Content | -| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -| build | Build system support content and built output directories | -| build_overrides | Build system parameter customization for different platforms | -| config | Project configurations | -| credentials | Development and test credentials | -| docs | Documentation, including guides. Visit the [Matter SDK documentation page](https://project-chip.github.io/connectedhomeip-doc/index.html) to read it. | -| examples | Example firmware applications that demonstrate use of Matter | -| integrations | 3rd party integrations | -| scripts | Scripts needed to work with the Matter repository | -| src | Implementation of Matter | -| third_party | 3rd party code used by Matter | -| zzz_generated | ZAP generated template code - Revolving around cluster information | -| BUILD.gn | Build file for the GN build system | -| CODE_OF_CONDUCT.md | Code of conduct for Matter and contribution to it | -| CONTRIBUTING.md | Guidelines for contributing to Matter | -| LICENSE | Matter license file | -| REVIEWERS.md | PR reviewers | -| gn_build.sh | Build script for specific projects such as Android, EFR32, etc. | -| README.md | This file | - -# License - -Matter is released under the [Apache 2.0 license](./LICENSE). +Refer to the board README for the app + board combination you want to build: + +#### Lighting App (TL3238X / TL7218X) + +- TL3238X: + [`examples/lighting-app/telink/boards/tl3238x_README.md`](examples/lighting-app/telink/boards/tl3238x_README.md) +- TL7218X: + [`examples/lighting-app/telink/boards/tl7218x_README.md`](examples/lighting-app/telink/boards/tl7218x_README.md) + +#### Light Switch App (TL3238X Retention / TL7218X Retention) + +- TL3238X Retention: + [`examples/light-switch-app/telink/boards/tl3238x_retention_README.md`](examples/light-switch-app/telink/boards/tl3238x_retention_README.md) +- TL7218X Retention: + [`examples/light-switch-app/telink/boards/tl7218x_retention_README.md`](examples/light-switch-app/telink/boards/tl7218x_retention_README.md) + +> **Note:** LZMA compression is **required** for 2 MB flash with OTA. Build +> Software Version 2 (via the flag documented in each `*_README.md`) to generate +> the DFU/OTA upgrade images (`merged_dfu.lzma.bin`, `matter.ota`). The same +> `*_README.md` files also cover dual-mode (Matter + Zigbee) and 4 MB flash +> configurations. + +### Flashing Firmware + +For developing and testing purposes, refer to Chapter **Firmware Burning** in +our +[Matter Develop Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/?h=bdt#experience-the-implementation-and-function-of-matter). + +--- + +## 📱 Supported Boards + +| Board | Chip Family | Series | Status | +| -------------- | ----------- | ------ | -------------------- | +| tlsr9518adk80d | TLSR951X | B91 | Telink Zephyr HAL_V1 | +| tlsr9528a | TLSR952X | B92 | Telink Zephyr HAL_V1 | +| tlsr9118bdk40d | TLSR911X | W91 | - | +| tl3218x | TL321X | - | Telink Zephyr HAL_V1 | +| tl3238x | TL323X | - | Telink Zephyr HAL_V2 | +| tl7218x | TL721X | - | Telink Zephyr HAL_V2 | + +--- + +## 📝 Release Information + +For version history and detailed changelog, refer to the +[Release Note](docs/platforms/telink/releases/telink_release_notes.md). + +--- + +## 📄 License + +``` +Apache License, Version 2.0 + +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. +``` + +--- + +Made by Telink Semiconductor diff --git a/TELINK_VERSION b/TELINK_VERSION new file mode 100644 index 000000000000..9aaceb605a92 --- /dev/null +++ b/TELINK_VERSION @@ -0,0 +1,5 @@ +VERSION_MAJOR = 1 +VERSION_MINOR = 0 +PATCHLEVEL = 1 +VERSION_TWEAK = 0 +EXTRAVERSION = diff --git a/config/telink/app/bootloader.conf b/config/telink/app/bootloader.conf index cdc60a11c7a8..ad7a81f8c507 100644 --- a/config/telink/app/bootloader.conf +++ b/config/telink/app/bootloader.conf @@ -14,9 +14,9 @@ # limitations under the License. # -# Enable this option in case if restoring the slot0 partition is expected from slot1 +# Enable this option in case if restoring the slot0 partition is expected from slot1 # partition in case if slot0 is not bootable or damaged -CONFIG_BOOT_BOOTSTRAP=y +CONFIG_BOOT_BOOTSTRAP=n # Enable this option in case if SWAP_MOVE logic need to be used CONFIG_BOOT_SWAP_USING_MOVE=y @@ -27,7 +27,8 @@ CONFIG_BOOT_SWAP_USING_SCRATCH=n # Enable this option in case if the whole slot0 image need to be validated # With disabled option the only image magic is validated -CONFIG_BOOT_VALIDATE_SLOT0=y +CONFIG_BOOT_VALIDATE_SLOT0=n +CONFIG_BOOT_VALIDATE_SLOT0_ONCE=y # Required for Zephyr 3.3 and replased with CONFIG_BOOT_MAX_IMG_SECTORS_AUTO in new versions # Maximum number of image sectors supported by the bootloader. @@ -42,4 +43,16 @@ CONFIG_BOOT_MAX_IMG_SECTORS=512 # - DEBUG, LOG_LEVEL_DBG CONFIG_MCUBOOT_LOG_LEVEL_INF=y +# Enable support LZMA compression +CONFIG_COMPRESS_LZMA=n + CONFIG_PICOLIBC=y + +# Disabling the banner is to allow cmd tool to better parse the chip ID, avoid interface. +CONFIG_BOOT_BANNER=n + +CONFIG_BOOT_IMG_HASH_DIRECTLY_ON_STORAGE=y + +# CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y +# CONFIG_BOOT_SIGNATURE_KEY_FILE="ecdsa_private_key.pem" +# CONFIG_BOOT_SIGNATURE_KEY_FILE="" diff --git a/config/telink/app/bootloader_compress_lzma.conf b/config/telink/app/bootloader_compress_lzma.conf index 6cab83229bae..e2fb166e9ef2 100644 --- a/config/telink/app/bootloader_compress_lzma.conf +++ b/config/telink/app/bootloader_compress_lzma.conf @@ -20,7 +20,8 @@ CONFIG_BOOT_UPGRADE_ONLY=y # Enable this option in case if the whole slot0 image need to be validated # With disabled option the only image magic is validated -CONFIG_BOOT_VALIDATE_SLOT0=y +CONFIG_BOOT_VALIDATE_SLOT0=n +CONFIG_BOOT_VALIDATE_SLOT0_ONCE=y # Required for Zephyr 3.3 and replased with CONFIG_BOOT_MAX_IMG_SECTORS_AUTO in new versions # Maximum number of image sectors supported by the bootloader. @@ -45,3 +46,12 @@ CONFIG_SIZE_OPTIMIZATIONS=y CONFIG_COMPRESS_LZMA=y CONFIG_PICOLIBC=y + +# Disabling the banner is to allow cmd tool to better parse the chip ID, avoid interface. +CONFIG_BOOT_BANNER=n + +CONFIG_BOOT_IMG_HASH_DIRECTLY_ON_STORAGE=y + +# CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y +# CONFIG_BOOT_SIGNATURE_KEY_FILE="ecdsa_private_key.pem" +# CONFIG_BOOT_SIGNATURE_KEY_FILE="" diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 449f646a04b8..4a0206caebf4 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -72,6 +72,9 @@ matter_add_flags(-DMBEDTLS_USER_CONFIG_FILE=<${CONFIG_MBEDTLS_CFG_FILE}>) if (CONFIG_OPENTHREAD_TELINK_LIBRARY) set(ZEPHYR_OPENTHREAD_MODULE_DIR ${ZEPHYR_BASE}/../modules/lib/openthread_telink_lib CACHE STRING INTERNAL) message(STATUS "OpenThread used as precompiled Telink library, path: ${ZEPHYR_OPENTHREAD_MODULE_DIR}") +else() + set(ZEPHYR_OPENTHREAD_MODULE_DIR ${ZEPHYR_BASE}/../modules/lib/openthread CACHE STRING INTERNAL) + message(STATUS "OpenThread used from source, path: ${ZEPHYR_OPENTHREAD_MODULE_DIR}") endif() if (CONFIG_CHIP_OPENTHREAD_CONFIG) @@ -194,12 +197,77 @@ endif() # Define 'process_binaries' target for collecting final binary to flash # ============================================================================== +set(BLOCK_SIZE "1024") +set(CONFIG_DUAL_MODE_ARG 0) + +if(CONFIG_SOC_RISCV_TELINK_TL321X) + set(SOC "TL321X") +elseif(CONFIG_SOC_RISCV_TELINK_TL322X) + set(SOC "TL322X") +elseif(CONFIG_SOC_RISCV_TELINK_TL323X) + set(SOC "TL323X") + set(CONFIG_DUAL_MODE_ARG ${CONFIG_DUAL_MODE}) +elseif(CONFIG_SOC_RISCV_TELINK_TL521X) + set(SOC "TL521X") + set(CONFIG_DUAL_MODE_ARG ${CONFIG_DUAL_MODE}) +elseif(CONFIG_SOC_RISCV_TELINK_TL721X) + set(SOC "TL721X") +elseif(CONFIG_SOC_RISCV_TELINK_B91) + set(SOC "TLSR9518") +elseif(CONFIG_SOC_RISCV_TELINK_B92) + set(SOC "TLSR9528") +elseif(CONFIG_SOC_RISCV_TELINK_W91) + set(SOC "TLSR9118") +endif() + +set(SBOOT_FILE_PATH "${ZEPHYR_BASE}/${SOC}_FW/SBOOT/Secure_Bootloader.bin") +math(EXPR SKIP_BYTES_DECIMAL "${CONFIG_MCUBOOT_START_OFFSET} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL) +message(STATUS "SKIP_BYTES_DECIMAL: ${SKIP_BYTES_DECIMAL}") +if (EXISTS ${SBOOT_FILE_PATH}) + message(STATUS "Will merge sboot and mcuboot with offset ${CONFIG_MCUBOOT_START_OFFSET} bytes.") + set(MCUBOOT_START_OFFSET_ARG "${CONFIG_MCUBOOT_START_OFFSET}") + else() + message(WARNING "File ${SBOOT_FILE_PATH} does not exist. Set SKIP_BYTES_DECIMAL to 0, MCUBOOT will be built without offset.") + set(SKIP_BYTES_DECIMAL 0) + set(MCUBOOT_START_OFFSET_ARG "0") +endif() + +set(ZB_FILE_PATH "${ZEPHYR_BASE}/${SOC}_FW/ZB/Zigbee-SampleDemo.bin") +# Calculate the offset of zigbee partition relative to slot0 start +dt_nodelabel(slot0_partition_path NODELABEL "slot0_partition") +dt_reg_addr(slot0_start PATH ${slot0_partition_path}) +dt_reg_size(slot0_size PATH ${slot0_partition_path}) +message(STATUS "slot0_start: ${slot0_start}") +message(STATUS "slot0_size: ${slot0_size}") + +if (CONFIG_DUAL_MODE AND EXISTS ${ZB_FILE_PATH}) +dt_nodelabel(zb_partition_path NODELABEL "slot0_zb_partition") +dt_reg_addr(zb_start PATH ${zb_partition_path}) +message(STATUS "zb_start: ${zb_start}") + +math(EXPR zb_offset_bytes "${zb_start} - ${slot0_start}" OUTPUT_FORMAT DECIMAL) + +math(EXPR ZB_FW_OFFSET_DECIMAL "${zb_offset_bytes} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL) +message(STATUS "ZB_FW_OFFSET_DECIMAL: ${ZB_FW_OFFSET_DECIMAL}") +else() +if (NOT CONFIG_DUAL_MODE) + message(STATUS "CONFIG_DUAL_MODE is 0, skipping Zigbee merge setup") +else() + message(WARNING "File ${ZB_FILE_PATH} does not exist. ZB_FW_OFFSET_DECIMAL will be set to 0.") +endif() +set(ZB_FW_OFFSET_DECIMAL 0) +endif() + add_custom_target( process_binaries ALL COMMAND ${Python3_EXECUTABLE} ${CHIP_ROOT}/scripts/tools/telink/process_binaries.py WORKING_DIRECTORY ${PROJECT_BINARY_DIR} ) -add_dependencies(process_binaries ${ZEPHYR_FINAL_EXECUTABLE}) +if(CONFIG_DUAL_MODE AND EXISTS ${ZB_FILE_PATH} AND CONFIG_BOOTLOADER_MCUBOOT AND (CONFIG_SOC_RISCV_TELINK_B9X OR CONFIG_SOC_RISCV_TELINK_TLX)) + add_dependencies(process_binaries west_sign) +else() + add_dependencies(process_binaries ${ZEPHYR_FINAL_EXECUTABLE}) +endif() # ============================================================================== # Define 'build_mcuboot' target for building the MCUBoot bootloader @@ -209,10 +277,63 @@ if (CONFIG_BOOTLOADER_MCUBOOT AND (CONFIG_SOC_RISCV_TELINK_B9X OR CONFIG_SOC_RIS add_custom_target(build_mcuboot ALL COMMAND west build -b ${BASE_BOARD} -d build_mcuboot ${ZEPHYR_BASE}/../bootloader/mcuboot/boot/zephyr - -- -DOVERLAY_CONFIG=${GLOBAL_BOOT_CONF_OVERLAY_FILE} -DDTC_OVERLAY_FILE="${GLOBAL_BOOT_DTC_OVERLAY_FILE};${FLASH_DTC_OVERLAY_FILE};${USB_BOOT_DTC_OVERLAY_FILE};${MARS_BOOT_DTC_OVERLAY_FILE}" + -- -DCONFIG_MCUBOOT_START_OFFSET=${MCUBOOT_START_OFFSET_ARG} -DCONFIG_DUAL_MODE=${CONFIG_DUAL_MODE_ARG} -DOVERLAY_CONFIG=${GLOBAL_BOOT_CONF_OVERLAY_FILE} -DDTC_OVERLAY_FILE="${GLOBAL_BOOT_DTC_OVERLAY_FILE};${FLASH_DTC_OVERLAY_FILE};${USB_BOOT_DTC_OVERLAY_FILE};${MARS_BOOT_DTC_OVERLAY_FILE}" + COMMAND + dd if=${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin of=${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/mcuboot_for_sign.bin bs=${BLOCK_SIZE} skip=${SKIP_BYTES_DECIMAL} conv=notrunc + COMMAND + cp ${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/mcuboot_for_sign.bin ${PROJECT_BINARY_DIR}/zephyr.mcuboot.bin + COMMAND + cp ${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/mcuboot_for_sign.bin ${PROJECT_BINARY_DIR}/mcuboot_for_sign.bin COMMAND - cp ${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin ${PROJECT_BINARY_DIR}/mcuboot.bin + cp ${PROJECT_BINARY_DIR}/mcuboot_for_sign.bin ${PROJECT_BINARY_DIR}/mcuboot.bin ) + message(STATUS "mcuboot_for_sign.bin is for external signing.") + + if (EXISTS ${SBOOT_FILE_PATH}) + add_custom_target(merge_sboot ALL + COMMAND + dd if=/dev/zero bs=${BLOCK_SIZE} count=${SKIP_BYTES_DECIMAL} | tr '\\000' '\\377' > ${PROJECT_BINARY_DIR}/bootloader_merged.bin + COMMAND + dd if=${SBOOT_FILE_PATH} of=${PROJECT_BINARY_DIR}/bootloader_merged.bin conv=notrunc + COMMAND + dd if=${PROJECT_BINARY_DIR}/zephyr.mcuboot.bin of=${PROJECT_BINARY_DIR}/bootloader_merged.bin bs=${BLOCK_SIZE} seek=${SKIP_BYTES_DECIMAL} conv=notrunc + COMMAND + cp ${PROJECT_BINARY_DIR}/bootloader_merged.bin ${PROJECT_BINARY_DIR}/mcuboot.bin + ) + add_dependencies(merge_sboot build_mcuboot) + message(WARNING "merged secure boot to mcuboot..") + else() + message(WARNING "File ${SBOOT_FILE_PATH} does not exist. merge_sboot target will not be created.") + endif() + + if (CONFIG_DUAL_MODE AND EXISTS ${ZB_FILE_PATH}) + add_custom_target(merge_zigbee ALL + COMMAND + cp ${PROJECT_BINARY_DIR}/zephyr.bin ${PROJECT_BINARY_DIR}/zephyr.matter.bin # store matter firmware + COMMAND + dd if=/dev/zero bs=${BLOCK_SIZE} count=${ZB_FW_OFFSET_DECIMAL} | tr '\\000' '\\377' > ${PROJECT_BINARY_DIR}/dm_merged.bin + COMMAND + dd if=${PROJECT_BINARY_DIR}/zephyr.matter.bin of=${PROJECT_BINARY_DIR}/dm_merged.bin conv=notrunc + COMMAND + dd if=${ZB_FILE_PATH} of=${PROJECT_BINARY_DIR}/dm_merged.bin bs=${BLOCK_SIZE} seek=${ZB_FW_OFFSET_DECIMAL} conv=notrunc + COMMAND + cp ${PROJECT_BINARY_DIR}/dm_merged.bin ${PROJECT_BINARY_DIR}/zephyr.bin + COMMAND + cp ${PROJECT_BINARY_DIR}/dm_merged.bin ${PROJECT_BINARY_DIR}/unsign_merged.bin # store unsign merged firmware + ) + add_custom_target(west_sign ALL + COMMAND + west sign -t imgtool -p ${ZEPHYR_BASE}/../bootloader/mcuboot/scripts/imgtool.py -d ${PROJECT_BINARY_DIR}/.. -- --key ${ZEPHYR_BASE}/../${CONFIG_MCUBOOT_SIGNATURE_KEY_FILE} --slot-size ${slot0_size} + ) + add_dependencies(merge_zigbee ${ZEPHYR_FINAL_EXECUTABLE}) + add_dependencies(west_sign merge_zigbee) + else() + if (NOT CONFIG_DUAL_MODE) + message(STATUS "CONFIG_DUAL_MODE is 0, skipping merge_zigbee and west_sign targets") + else() + message(WARNING "File ${ZB_FILE_PATH} does not exist. merge_zigbee target will not be created.") + endif() + endif() endif() # ============================================================================== diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index 84bb4daad037..4a1c5b2e58ee 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -84,6 +84,9 @@ config CHIP_DFU_OVER_BT_SMP select MCUMGR_MGMT_NOTIFICATION_HOOKS select MCUMGR_GRP_IMG_UPLOAD_CHECK_HOOK select MCUMGR_GRP_IMG_STATUS_HOOKS + default y if BOARD_TL3238X || BOARD_TL3238X_RETENTION + default y if BOARD_TLSR9528A || BOARD_TLSR9528A_RETENTION + default n help Enables Device Firmware Upgrade over Bluetooth LE with SMP and configures the set of options related to that feature. @@ -233,8 +236,9 @@ config CHIP_USE_MARS_SENSOR default n config CHIP_PERSISTENT_SUBSCRIPTIONS - default n if BOARD_TL3218X_RETENTION - default y + default y if BOARD_TL3238X || BOARD_TL3238X_RETENTION + default y if BOARD_TLSR9528A || BOARD_TLSR9528A_RETENTION + default n # selecting experimental for this feature since there is an issue with multiple controllers. select EXPERIMENTAL @@ -282,7 +286,7 @@ config TFLM_FEATURE choice CHIP_LAST_FABRIC_REMOVED_ACTION prompt "An action to perform after removing the last fabric" - default CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY + default CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT config CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT bool "After removing the last fabric erase NVS and reboot" @@ -326,3 +330,16 @@ config CHIP_LAST_FABRIC_REMOVED_ACTION_DELAY After removing the last fabric the device will wait for the defined time and then perform an action chosen by the CHIP_LAST_FABRIC_REMOVED_ACTION option. This schedule will allow for avoiding race conditions before the device removes non-volatile data. + +config SECURE_PROGRAMMING + bool "Enable reading DAC and keys from the DAC partition" + depends on CHIP_FACTORY_DATA + default n + +config EXPOSE_CHIP_ID_VIA_BLE + bool "Enable CHIP-ID via ble" + default n + +config DEFERRED_ATTR_STORAGE + bool "Defer the storage time of attributes" + default n diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index bd2f846db6fc..c9ff4697c9b1 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -69,27 +69,31 @@ config POSIX_MAX_FDS # Application stack size config MAIN_STACK_SIZE default 4864 if SOC_RISCV_TELINK_W91 || SOC_RISCV_TELINK_B91 - default 3560 if PM || SOC_RISCV_TELINK_TL321X + default 3072 if PM && SOC_RISCV_TELINK_TL321X + default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 4096 config INIT_STACKS default y config IDLE_STACK_SIZE - default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_W91 + default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_W91 config ISR_STACK_SIZE - default 800 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_W91 + default 1024 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_W91 config SYSTEM_WORKQUEUE_STACK_SIZE default 1024 if PM && !SOC_RISCV_TELINK_W91 + default 2048 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X config HEAP_MEM_POOL_SIZE default 256 if ZEPHYR_VERSION_3_3 + default 1796 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 1280 config COMMON_LIBC_MALLOC_ARENA_SIZE default 19000 if SOC_RISCV_TELINK_TL321X && !ZEPHYR_VERSION_3_3 + default 26584 if (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X) && !ZEPHYR_VERSION_3_3 default 29448 if SOC_RISCV_TELINK_W91 default 20716 @@ -101,6 +105,7 @@ config NET_IF_UNICAST_IPV6_ADDR_COUNT default 6 config NET_IF_MCAST_IPV6_ADDR_COUNT + default 47 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 8 if PM default 15 @@ -110,20 +115,20 @@ config NET_IF_IPV6_PREFIX_COUNT # Network buffers config NET_PKT_RX_COUNT default 16 if SOC_RISCV_TELINK_W91 - default 4 if PM || SOC_RISCV_TELINK_TL321X + default 4 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 8 config NET_PKT_TX_COUNT default 16 if SOC_RISCV_TELINK_W91 - default 4 if PM || SOC_RISCV_TELINK_TL321X + default 4 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 8 config NET_BUF_RX_COUNT - default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X + default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 32 config NET_BUF_TX_COUNT - default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X + default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 32 config GPIO @@ -171,15 +176,15 @@ config BT_MAX_CONN default 1 config BT_L2CAP_TX_MTU - default 103 if SOC_RISCV_TELINK_TL321X + default 103 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 247 config BT_BUF_ACL_RX_SIZE - default 107 if SOC_RISCV_TELINK_TL321X + default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 251 config BT_BUF_ACL_TX_SIZE - default 107 if SOC_RISCV_TELINK_TL321X + default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 251 config BT_BUF_EVT_RX_COUNT @@ -207,7 +212,7 @@ if SOC_RISCV_TELINK_B9X || SOC_RISCV_TELINK_TLX config TL_BLE_CTRL_THREAD_STACK_SIZE default 648 if ZEPHYR_VERSION_3_3 - default 768 if SOC_RISCV_TELINK_TL721X + default 1536 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 712 config TL_BLE_CTRL_MASTER_MAX_NUM @@ -241,12 +246,14 @@ config PWM endif -if BOARD_TL7218X_RETENTION || BOARD_TL3218X_RETENTION || BOARD_TL3218X +if BOARD_TL7218X_RETENTION || BOARD_TL3218X_RETENTION || BOARD_TL3218X || \ + BOARD_TL3238X_RETENTION || BOARD_TL3238X || \ + BOARD_TL5218X_RETENTION || BOARD_TL5218X config SOC_SERIES_RISCV_TELINK_TLX_NON_RETENTION_RAM_CODE default n if PM config TELINK_TLX_MATTER_RETENTION_LAYOUT - default y if PM || BOARD_TL3218X + default y if PM || BOARD_TL3218X || BOARD_TL3238X || BOARD_TL5218X config PWM default n if PM @@ -255,7 +262,8 @@ endif # Board non-retention config if BOARD_TLSR9118BDK40D || BOARD_TLSR9118BDK40D_V1 || \ - BOARD_TLSR9528A || BOARD_TLSR9518ADK80D || BOARD_TL3218X || BOARD_TL7218X + BOARD_TLSR9528A || BOARD_TLSR9518ADK80D || BOARD_TL3218X || \ + BOARD_TL3238X || BOARD_TL5218X || BOARD_TL7218X config PWM default y endif @@ -302,7 +310,7 @@ config NVS_LOOKUP_CACHE default y config NVS_LOOKUP_CACHE_SIZE - default 400 if SOC_RISCV_TELINK_TL321X + default 400 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 2048 if !PM || SOC_RISCV_TELINK_W91 # Set multiplicator of Name Value Storage (NVS) as 1 to reach NVS sector size 4KB @@ -352,8 +360,17 @@ config OPENTHREAD_CSMABACKOFF_OPTIMIZATION help Skip the first CSMA backoff period when sending data requests over IEEE 802.15.4. +config OPENTHREAD_SED_RAM_CODE + bool "Place OpenThread SED standby code in RAM" + depends on OPENTHREAD_MTD + default y if PM && SOC_RISCV_TELINK_TL721X + default n + help + Move SED standby critical path code to Retention RAM to reduce wakeup latency and power. + config IEEE802154_TLX_OPTIMIZATION bool "Optimize 802.15.4 RF performance for TLX SoCs" + default y if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X) default n help Improve RF performance in IEEE 802.15.4 communication on TLX SoCs. @@ -364,9 +381,12 @@ config IEEE802154_TLX_ACTIVE_STAGE_OPTIMIZATION config OPENTHREAD_THREAD_STACK_SIZE default 2400 if PM || SOC_RISCV_TELINK_TL321X + default 4096 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X config OPENTHREAD_RADIO_WORKQUEUE_STACK_SIZE default 496 if PM && ZEPHYR_VERSION_3_3 + default 2048 if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X) + default 608 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 640 config OPENTHREAD_SLAAC @@ -375,26 +395,35 @@ config OPENTHREAD_SLAAC config OPENTHREAD_MANUAL_START default y +# 6 is the max rf level by Vant config OPENTHREAD_DEFAULT_TX_POWER - default 3 if PM + default 6 if PM && SOC_RISCV_TELINK_TL321X + default 3 if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X) + default 11 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X default 9 config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS + default 40 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 2 if PM default 8 config CHIP_OPENTHREAD_NETWORK_SWITCH_PATH default y +# Dcrease OT message buffer size to save RAM for tl321x +config OPENTHREAD_MESSAGE_BUFFER_SIZE + default 80 if SOC_RISCV_TELINK_TL321X + endif # NET_L2_OPENTHREAD config NET_TX_STACK_SIZE default 1200 if SOC_RISCV_TELINK_W91 - default 600 if PM || SOC_RISCV_TELINK_TL321X + default 600 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL521X || SOC_RISCV_TELINK_TL721X config NET_RX_STACK_SIZE default 2048 if SOC_RISCV_TELINK_W91 default 664 if PM || SOC_RISCV_TELINK_TL321X + default 2048 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X # Disable certain parts of Zephyr IPv6 stack config NET_IPV6_NBR_CACHE @@ -526,6 +555,14 @@ config TELINK_TLX_SHA_HW_SLOTS default 2 if BOARD_TL3218X_RETENTION default 8 if SOC_RISCV_TELINK_TLX +config TELINK_B9X_MBEDTLS_HW_ACCELERATION + bool "Use Telink B9x platform mbedtls HW acceleration" + default y if SOC_RISCV_TELINK_B9X + +config TELINK_TLX_MBEDTLS_HW_ACCELERATION + bool "Use Telink TLx platform mbedtls HW acceleration" + default y if SOC_RISCV_TELINK_TLX + endif # !ZEPHYR_VERSION_3_3 config GETOPT_LONG diff --git a/docs/platforms/index.md b/docs/platforms/index.md index b9ee8097b45d..4cd6ebbf4c5b 100644 --- a/docs/platforms/index.md +++ b/docs/platforms/index.md @@ -16,6 +16,7 @@ nxp/index openthread/index silabs/index stm32/index +telink/index ti/index ``` @@ -30,4 +31,5 @@ ti/index - [OpenThread](./openthread/index.md) - [Silabs](./silabs/index.md) - [STM32](./stm32/index.md) +- [Telink](./telink/) - [TI](./ti/index.md) diff --git a/docs/platforms/telink/index.md b/docs/platforms/telink/index.md new file mode 100644 index 000000000000..0fe9f84099d1 --- /dev/null +++ b/docs/platforms/telink/index.md @@ -0,0 +1,12 @@ +# Telink + +```{toctree} +:maxdepth: 1 +:hidden: + +telink_getting_started +releases/telink_release_notes +``` + +[Telink - Getting Started](./telink_getting_started.md) +[Telink - Release Notes](./releases/telink_release_notes.md) diff --git a/docs/platforms/telink/releases/README_BUILD_SCRIPT.md b/docs/platforms/telink/releases/README_BUILD_SCRIPT.md new file mode 100644 index 000000000000..4659ebe19238 --- /dev/null +++ b/docs/platforms/telink/releases/README_BUILD_SCRIPT.md @@ -0,0 +1,188 @@ +# Telink Matter Build and Release Notes Update Script + +## Overview + +The script `docs/platforms/telink/releases/build_and_update_matter_notes.py` +can: + +1. Build all Telink board Matter sample applications (using `build_examples.py`) +2. Extract memory usage information (RAM/ROM) from build logs +3. Update the release note file + `docs/platforms/telink/releases/telink_release_notes.md` (the Resource Usage + section uses a table format) +4. Collect all sample firmware files for every board and create a separate zip + archive per board +5. Organize all output under the `build_for_release/` directory + +## Files + +- `docs/platforms/telink/releases/build_and_update_matter_notes.py` - main + build and update script (alongside the release note working copy) +- `docs/platforms/telink/releases/telink_release_notes.md` - release note + working copy (in the same directory as the script; the script reads and + updates it in-place, only replacing the Resource Usage section while + preserving the remaining static content). At release time, + `scripts/tools/telink/package_telink_firmware.sh` snapshots it into a + versioned `telink_release_notes_.md`. +- `README.md` - Telink Matter SDK documentation +- `build_for_release/` - root directory for all output + - `build_logs/` - directory containing all build logs + - `firmware/` - directory containing all board firmware files and zip + archives + +## Usage + +### 0. Prerequisites + +Before running the script, set up the Telink Zephyr SDK path and activate the +build environment: + +```bash +cd /home/ubuntu/zephyrproject/connectedhomeip + +# Set the Telink Zephyr SDK path +export TELINK_ZEPHYR_BASE=/home/ubuntu/zephyrproject/zephyr + +# Activate the Matter build environment +source ./scripts/activate.sh -p all,telink +``` + +### 1. Full run (build + update + firmware packaging) + +```bash +cd /home/ubuntu/zephyrproject/connectedhomeip +python3 docs/platforms/telink/releases/build_and_update_matter_notes.py +``` + +This will: + +- Build all Telink board Matter samples using `build_examples.py` +- Save logs to the `build_for_release/build_logs/` directory +- Extract memory usage information from the logs +- Update the `docs/platforms/telink/releases/telink_release_notes.md` file + (only the Resource Usage section is replaced; the remaining static content + is preserved) +- Collect all firmware files into the `build_for_release/firmware/` directory +- Create a separate firmware zip archive per board + +### 2. Update the release notes only (skip building) + +```bash +python3 docs/platforms/telink/releases/build_and_update_matter_notes.py --skip-build +``` + +Use this command when build logs already exist and you only need to update the +release notes and collect firmware. + +### 3. Skip firmware collection and packaging + +```bash +python3 docs/platforms/telink/releases/build_and_update_matter_notes.py --skip-firmware +``` + +Use this option when firmware collection and packaging are not needed. + +## Firmware zip archive contents + +Each board's zip archive contains: + +- `board_name/sample_name/zephyr.bin` - binary firmware file +- `board_name/sample_name/zephyr.elf` - ELF firmware file +- `board_name/sample_name/zephyr.hex` - Intel HEX firmware file (if present) +- `board_name/sample_name/zephyr.dts` - devicetree file +- `board_name/sample_name/.config` - configuration file +- `board_name/sample_name/zephyr.signed.bin` - signed OTA firmware (if OTA is + enabled) +- `board_name/sample_name/mcuboot.bin` - MCUboot firmware (if present) + +## Supported boards + +1. tlsr9518adk80d (TLSR951X/B91) +2. tlsr9528a (TLSR952X/B92) +3. tlsr9118bdk40d (TLSR911X/W91) +4. tl3218x (TL321X) +5. tl3238x (TL323X) +6. tl7218x (TL721X) + +## Supported sample applications + +| Application | Description | +| ------------------------ | -------------------------------------------------------------- | +| lighting-app | Lighting application (supports OTA, Factory Data, LZMA, Shell) | +| light-switch-app | Light switch application (supports OTA, LZMA, Factory Data) | +| bridge-app | Bridge application | +| window-app | Window covering application | +| air-quality-sensor-app | Air quality sensor application | +| all-clusters-app | All-clusters application | +| all-clusters-minimal-app | Minimal all-clusters application (supports NFC Payload) | +| contact-sensor-app | Contact sensor application | +| lock-app | Door lock application (supports DFU over SMP) | +| smoke-co-alarm-app | Smoke/CO alarm application | +| pump-controller-app | Pump controller application | +| shell | Shell application | +| thermostat | Thermostat application | +| ota-requestor-app | OTA requestor application | + +## Script features + +- Structured class design, easy to maintain and extend +- Built on top of `build_examples.py`, consistent with Matter CI +- Updates the release note file in-place, keeping all static content + consistent +- Resource Usage section uses a table format, clearly showing memory usage of + each sample on each board +- Only the Resource Usage section is updated; other sections are left + unchanged +- Supports adding new boards and sample applications +- Detailed log output +- Build step can be skipped to update directly from existing logs +- Automatically collects firmware files and creates a separate zip archive per + board +- Option to skip firmware collection and packaging + +## Adding a new board or sample + +In the `TelinkMatterBuildManager` class: + +1. Add a new build configuration (board, app_name, target_suffix) in the + `_get_build_targets()` method +2. Add the new board family mapping in the `board_family` dictionary +3. Add the new board display order in the `board_order` list + +For example, to add a new lighting-app build: + +```python +targets.append(("tl3238x", "lighting-app", "tl3238x-light-ota-factory-data")) +``` + +## Updating the release note file + +If you need to update the static content of the release note file (such as +Introduction, Version Information, Additional Notes, etc.), simply edit the +`docs/platforms/telink/releases/telink_release_notes.md` working copy directly. +The script only replaces the Resource Usage section; the remaining static +sections are preserved. At release time, `package_telink_firmware.sh` snapshots +it into a versioned archive file based on the git tag. + +## Build target format + +The build target format is `telink--[-]`, for example: + +- `telink-tl3238x-light-ota-factory-data-4mb` - TL3238X lighting application + with OTA, Factory Data, 4MB Flash +- `telink-tl7218x_retention-light-switch-ota-compress-lzma-factory-data` - + TL7218X Retention light switch application +- `telink-tlsr9518adk80d-light-ota-rpc-factory-data-4mb` - B91 lighting + application with RPC, OTA, Factory Data + +Available options: + +- `ota` - enable OTA support +- `factory-data` - enable Factory Data support +- `compress-lzma` - enable LZMA compression +- `shell` - enable Shell +- `rpc` - enable Pigweed RPC +- `dfu-smp` - enable DFU over SMP +- `4mb` - 4MB Flash +- `log-progress` - reduce log output (progress and errors only) +- `nfc-payload` - NFC Payload support diff --git a/docs/platforms/telink/releases/telink_release_notes.md b/docs/platforms/telink/releases/telink_release_notes.md new file mode 100644 index 000000000000..58eddda01508 --- /dev/null +++ b/docs/platforms/telink/releases/telink_release_notes.md @@ -0,0 +1,290 @@ +# Telink Matter SDK Release Note + +[![Version](https://img.shields.io/badge/Version-tl_v1.0.1--beta--v1.5.1.0-blue?style=flat-square)](https://github.com/telink-semi/connectedhomeip/releases/tag/tl_v1.0.1-beta-v1.5.1.0) +[![License](https://img.shields.io/badge/License-Apache%202.0-red?style=flat-square)](LICENSE) +[![Matter](https://img.shields.io/badge/Matter-v1.5-green?style=flat-square)](https://github.com/project-chip/connectedhomeip/commit/f4a8cf98ada4ad4f439b45e360800693cc5f1391) + +--- + +- **Release Type:** Pre-Release (Beta) +- **Branch:** + [dev-tlk_v1.5](https://github.com/telink-semi/connectedhomeip/tree/dev-tlk_v1.5) +- **Tag Version:** + [tl_v1.0.1-beta-v1.5.1.0](https://github.com/telink-semi/connectedhomeip/releases/tag/tl_v1.0.1-beta-v1.5.1.0) +- **Target Commit:** + [b4c04e3](https://github.com/telink-semi/connectedhomeip/commit/b4c04e3c1816fc242a100e305047ac1350457d17) + +--- + +## 📖 Introduction + +This release is based on the latest commit of `dev-tlk_v1.5` branch, providing +Matter protocol support for Telink RISC-V SoC platforms. It integrates the +Matter SDK with the Telink Zephyr SDK to enable Matter-over-Thread devices on +Telink chips including TLSR9 Series, TL321X, TL323X, and TL721X. + +--- + +## ✨ Highlights + +| Category | Details | +| ------------------- | ------------------------------------------------------ | +| **Matter Support** | Matter 1.5.1 protocol stack | +| **Supported Chips** | TLSR951X, TLSR952X, TLSR911X, TL321X, TL323X, TL721X | +| **Sample Apps** | Lighting, Light Switch, Lock, Bridge, Thermostat, etc. | +| **OTA** | OTA requestor and compress-LZMA support | +| **Factory Data** | Factory data provisioning support | + +--- + +## 🆕 New Features + +- ✅ Matter 1.5.1 protocol support for Telink platforms +- ✅ Full support for TL323X series chips in Matter +- ✅ Support for TL721X series chips in Matter +- ✅ LZMA compression support for OTA images +- ✅ Factory data provisioning support +- ✅ Dual-mode configuration support for TL3238X +- ✅ Power management with retention RAM support +- ✅ NFC payload support for all-clusters-minimal-app +- ✅ DFU over SMP support for lock-app + +--- + +## 🐛 Bug Fixes + +| Issue | Description | +| ----------------- | ----------------------------------------------------------------------------- | +| **Network State** | Check Matter network state when power-on to ensure correct commissioning flow | +| **TL721X HAL V2** | Update hal_v1 to hal_v2 for TL721X | +| **PM Stability** | Improve power management stability on retention RAM configurations | +| **OTA Recovery** | Fix OTA recovery flow on TL323X series | + +--- + +## 📦 Updates + +- Updated Telink BLE SDK for improved RF performance + ([commit:46322e5b570e2a68373b18d4f08811acadd1266c](https://github.com/telink-semi/tl_ble_sdk_zephyr/commit/46322e5b570e2a68373b18d4f08811acadd1266c)) +- Updated Telink HAL Zephyr to support TL721X + hal_v2([commit:14c6149f6cc466c49d81e3b2f7f1e4d8ff6fbbb5](https://github.com/telink-semi/hal_telink/commit/14c6149f6cc466c49d81e3b2f7f1e4d8ff6fbbb5)) +- Updated MCUBoot with Telink-specific flash operation + ([commit:ce0da85c39c749df49b0ec62b33d2ecdea24c927](https://github.com/telink-semi/mcuboot/commit/ce0da85c39c749df49b0ec62b33d2ecdea24c927)) +- Updated OpenThread Telink source code + ([commit:542aaab44e1308e1a8a24573dfbd413fade342ee](https://github.com/telink-semi/openthread/commit/542aaab44e1308e1a8a24573dfbd413fade342ee)) +- Updated OpenThread Telink library + ([commit:308dae2f80084f87073cfd4fbd30f1be0799be7b](https://github.com/telink-semi/openthread_telink_lib/commit/308dae2f80084f87073cfd4fbd30f1be0799be7b)) +- Updated Telink Zephyr SDK to support TL323X and TL721X hal_v2 + ([commit:e08fc42546e58d808bfd39f35c8df296f5617a44](https://github.com/telink-semi/zephyr/commit/e08fc42546e58d808bfd39f35c8df296f5617a44)) + +--- + +## ⚠️ Important Notes + +**This is a BETA pre-release version for demonstration and testing purposes. Not +recommended for production use.** + +### Telink Matter ↔ Telink Zephyr Dependency + +The Telink Matter SDK is built **on top of** the Telink Zephyr SDK, and the two +are tightly coupled — they must be used as a matched pair. + +The Telink Zephyr SDK provides the foundational layers required to bring up a +Matter device on Telink silicon: the Zephyr RTOS core, the Telink hardware +abstraction layer (HAL), the BLE stack, MCUBoot bootloader, OpenThread +networking stack, the WEST tool and build toolchain. + +The Telink Matter SDK (this repository) builds upon that foundation to deliver +the Matter protocol stack itself together with a set of Telink Matter example +applications. Both components are required: the Matter SDK cannot be built +without the Zephyr SDK, and the Zephyr SDK alone does not provide Matter +support. + +> ⚠️ **Version pairing:** This Telink Matter release is validated against a +> specific Telink Zephyr SDK tag (see the +> [Version Information](#version-information) table below). Using a different +> Zephyr revision may cause build failures or runtime issues. + +--- + +## 📋 Version Information + +### Matter SDK & Toolchain + +| Component | Version | +| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **Matter SDK Version** | Telink Matter v1.5.1.0 | +| **Matter Branch** | master | +| **Commit** | [f4a8cf9](https://github.com/project-chip/connectedhomeip/commit/f4a8cf98ada4ad4f439b45e360800693cc5f1391) (the previous one of [15a68d7](https://github.com/project-chip/connectedhomeip/commit/15a68d7026b1cd34a0d4cf35dadc7558e503d2cb) that community upgraded Matter version to 1.6) | +| **Toolchain** | Zephyr SDK v0.17.0 riscv64-zephyr-elf | + +### Telink Matter SDK + +| Property | Version | +| ----------------- | -------------------------------------------------------------------------------------------------------------- | +| **Branch** | [dev-tlk_v1.5](https://github.com/telink-semi/connectedhomeip/tree/dev-tlk_v1.5) | +| **Target Commit** | [b4c04e3](https://github.com/telink-semi/connectedhomeip/commit/b4c04e3c1816fc242a100e305047ac1350457d17) | +| **Tag Name** | [tl_v1.0.1-beta-v1.5.1.0](https://github.com/telink-semi/connectedhomeip/releases/tag/tl_v1.0.1-beta-v1.5.1.0) | +| **Release Type** | Pre-Release (Beta) | + +### Chip & Hardware Versions + +📦 **Chip Versions** + +| Chip Family | Versions | +| ---------------------- | -------- | +| TLSR921X/TLSR951X(B91) | A2 | +| TLSR922X/TLSR952X(B92) | A3/A4 | +| TLSR911X(W91) | A2 | +| TL721X | A2/A3 | +| TL321X | A1/A2/A3 | +| TL323X | A0 | + +🔧 **Hardware EVK Versions** + +| Chip | EVK Version | +| -------- | ----------------------------- | +| TLSR921X | C1T213A20_V1.3 | +| TLSR952X | C1T266A20_V1.3 | +| TLSR911X | C1T301A20_V2.1 | +| TL721X | C1T315A20_V1.2 | +| TL321X | C1T331A20_V1.0/C1T335A20_V1.3 | +| TL323X | C1T388A20_V1.1 | + +--- + +## 📱 Matter Community Examples + +This release provides Telink platform ports for the following Matter community +example applications. Each example is located under +`examples//telink/` in the repository. The table below summarizes each +example and the Telink chip platforms that support it (see +[Telink Examples YAML file](.github/workflows/examples-telink.yaml)). + +> ✅ = Supported and Tested    🟡 = Supported but Untested +>    · = Untested + +| Example | Description | B91 (TLSR951X) | B92 (TLSR952X) | W91 (TLSR911X) | TL321X | TL323X | TL721X | +| ------------------------ | ---------------------------------------------------------- | :------------: | :------------: | :------------: | :----: | :----: | :----: | +| lighting-app | Lighting (On/Off, Level, Color Control) | 🟡 | · | 🟡 | 🟡 | ✅ | ✅ | +| light-switch-app | Light Switch (controller, switches a bound lighting-app) | · | 🟡 | · | 🟡 | ✅ | ✅ | +| bridge-app | Bridge / Aggregator (bridges non-Matter devices to Matter) | · | · | · | · | · | 🟡 | +| window-app | Window Covering (shades, blinds) | · | · | · | · | · | 🟡 | +| air-quality-sensor-app | Air Quality Sensor | · | 🟡 | · | · | · | · | +| all-clusters-app | All Clusters (full-featured test app) | · | · | 🟡 | · | · | · | +| all-clusters-minimal-app | All Clusters Minimal (lightweight test app, NFC payload) | · | 🟡 | · | · | · | · | +| contact-sensor-app | Contact Sensor (stateless contact sensing) | · | 🟡 | · | · | · | · | +| lock-app | Door Lock (supports DFU over BLE SMP) | · | 🟡 | · | · | · | · | +| smoke-co-alarm-app | Smoke & CO Alarm | · | 🟡 | · | · | · | · | +| pump-controller-app | Pump Controller | 🟡 | · | · | · | · | · | +| shell | Shell (debug console) | 🟡 | · | · | · | · | · | +| thermostat | Thermostat | · | · | 🟡 | · | · | · | +| ota-requestor-app | OTA Requestor (handles OTA image download) | · | · | · | 🟡 | · | · | + +### Notes on Platform Support + +- **Tested combinations (✅):** Only TL323X and TL721X with lighting-app and + light-switch-app have been fully tested in this release. +- **Supported but untested (🟡):** All other build targets listed in the table + are compiled successfully but have not been functionally validated in this + release. Use with caution. +- **Untested (·):** Combinations not listed are not built or validated in this + release. +- **B91 (TLSR951X)** and **W91 (TLSR911X)** are legacy platforms with broad + sample coverage (lighting, pump-controller, shell, thermostat, + all-clusters). +- **B92 (TLSR952X)** targets sensors and small appliances (air-quality, + contact-sensor, smoke-co-alarm, lock, light-switch, all-clusters-minimal). +- **TL321X / TL323X / TL721X** are the latest Telink RISC-V SoC families. + Lighting and light-switch apps are supported across all three; TL721X + additionally supports bridge-app and window-app. +- The light-switch-app on TL321X/TL323X/TL721X uses the `*_retention` board + target (power management with retention RAM). +- For build commands per board/app, refer to the per-board `*_README.md` files + inside each example's `boards/` directory. + +--- + +## 📊 Resource Usage (Code Size) + +This section shows the RAM and ROM usage for various Matter examples on Telink +platforms, built with the Matter SDK and Zephyr RTOS. + +### Supported Boards + +| Board | Chip Family | +| -------------- | ------------ | +| tlsr9518adk80d | TLSR951X/B91 | +| tlsr9528a | TLSR952X/B92 | +| tl3218x | TL321X | +| tl3238x | TL323X | +| tl7218x | TL721X | +| tlsr9118bdk40d | TLSR911X/W91 | + +### TL323X/TL721X Matter (OTA + LZMA) Code Size + +The tables below list the **Supported and Tested** Matter build targets for +TL323X and TL721X, built with OTA + BT DFU + LZMA compression enabled (2MB +Flash, Software Version 1). Memory usage data is extracted from the linker +output (`Memory region` summary) of the build logs. + +> 📌 **Memory Regions:** TL323X exposes `RAM_ILM_N` (instruction RAM, 64 KB) + +> `RAM` (data RAM, 96 KB); TL7218X exposes `RAMILM` (unified, 256 KB) or +> `RAM_ILM_N` (128 KB) + `RAM_DLM` (256 KB) depending on the board target. `ROM` +> is the application slot0 partition (1152 KB with LZMA overlay). + +#### TL323X (tl3238x) + +📈 **Resource Usage Details** + +| App | Build Target | RAM_ILM_N | ROM | RAM | Firmware (merged.bin) | +| -------------------- | --------------------------------- | ------------------------- | ---------------------------- | ------------------------- | --------------------- | +| **lighting-app** | `build_tl3238x_2m_flash_lzma_v1` | 51788 B (79.02% of 64 KB) | 960663 B (81.44% of 1152 KB) | 92552 B (94.15% of 96 KB) | 1047015 B | +| **light-switch-app** | `build_tl3238x_retention_lzma_v1` | 61558 B (93.93% of 64 KB) | 905054 B (76.72% of 1152 KB) | 86608 B (88.10% of 96 KB) | 991406 B | + +#### TL721X (tl7218x) + +📈 **Resource Usage Details** + +| App | Build Target | RAMILM / RAM_ILM_N | RAM_DLM | ROM | RAM | Firmware (merged.bin) | +| -------------------- | --------------------------------- | -------------------------- | ------------------------- | ---------------------------- | --------------------------- | --------------------- | +| **lighting-app** | `build_tl7218x_2m_flash_lzma_v1` | 96432 B (36.79% of 256 KB) | — | 942294 B (79.88% of 1152 KB) | 55936 B (21.34% of 256 KB) | 1028646 B | +| **light-switch-app** | `build_tl7218x_retention_lzma_v1` | 46834 B (35.73% of 128 KB) | 10026 B (3.82% of 256 KB) | 886204 B (75.12% of 1152 KB) | 104616 B (79.82% of 128 KB) | 972556 B | + +> 📌 **Notes:** +> +> - **Firmware (merged.bin)** = MCUBoot (at offset 0) + gap padding + slot0 +> application image (`zephyr.signed.bin`). This is the file flashed to the +> device. +> - All four targets fit within the slot0 partition (1152 KB) with LZMA +> compression enabled. +> - The LZMA-compressed DFU image (`merged_dfu.lzma.bin`) is smaller than the +> signed image (e.g. 942630 B → 547530 B for TL7218X lighting). +> - For a detailed RAM/ROM symbol breakdown, run `west build -t ram_report` / +> `west build -t rom_report` in the build directory. + +--- + +### 📝 Additional Notes + +- **Memory Regions:** May vary between chip variants; check individual board + configurations +- **Build Config:** Matter builds use `west build` directly from each + example's `telink` directory; CI builds use the Matter `build_examples.py` + system with Telink targets +- **Production Optimizations:** For production builds, disable debug logging + and enable appropriate optimizations to reduce RAM/ROM usage +- **Bluetooth & OpenThread:** Matter uses OpenThread for Thread networking + and BLE for commissioning +- **OTA Images:** Signed OTA images (`zephyr.signed.bin`) are generated when + OTA is enabled + +--- + +--- + +Made by Telink Semiconductor + +- [Website](https://www.telink-semi.com/) +- [Forum](https://forum.telink-semi.cn/) +- [Documentation](https://doc.telink-semi.cn/) diff --git a/docs/platforms/telink/releases/telink_release_notes_tl_v1.0.1-beta-v1.5.1.0.md b/docs/platforms/telink/releases/telink_release_notes_tl_v1.0.1-beta-v1.5.1.0.md new file mode 100644 index 000000000000..58eddda01508 --- /dev/null +++ b/docs/platforms/telink/releases/telink_release_notes_tl_v1.0.1-beta-v1.5.1.0.md @@ -0,0 +1,290 @@ +# Telink Matter SDK Release Note + +[![Version](https://img.shields.io/badge/Version-tl_v1.0.1--beta--v1.5.1.0-blue?style=flat-square)](https://github.com/telink-semi/connectedhomeip/releases/tag/tl_v1.0.1-beta-v1.5.1.0) +[![License](https://img.shields.io/badge/License-Apache%202.0-red?style=flat-square)](LICENSE) +[![Matter](https://img.shields.io/badge/Matter-v1.5-green?style=flat-square)](https://github.com/project-chip/connectedhomeip/commit/f4a8cf98ada4ad4f439b45e360800693cc5f1391) + +--- + +- **Release Type:** Pre-Release (Beta) +- **Branch:** + [dev-tlk_v1.5](https://github.com/telink-semi/connectedhomeip/tree/dev-tlk_v1.5) +- **Tag Version:** + [tl_v1.0.1-beta-v1.5.1.0](https://github.com/telink-semi/connectedhomeip/releases/tag/tl_v1.0.1-beta-v1.5.1.0) +- **Target Commit:** + [b4c04e3](https://github.com/telink-semi/connectedhomeip/commit/b4c04e3c1816fc242a100e305047ac1350457d17) + +--- + +## 📖 Introduction + +This release is based on the latest commit of `dev-tlk_v1.5` branch, providing +Matter protocol support for Telink RISC-V SoC platforms. It integrates the +Matter SDK with the Telink Zephyr SDK to enable Matter-over-Thread devices on +Telink chips including TLSR9 Series, TL321X, TL323X, and TL721X. + +--- + +## ✨ Highlights + +| Category | Details | +| ------------------- | ------------------------------------------------------ | +| **Matter Support** | Matter 1.5.1 protocol stack | +| **Supported Chips** | TLSR951X, TLSR952X, TLSR911X, TL321X, TL323X, TL721X | +| **Sample Apps** | Lighting, Light Switch, Lock, Bridge, Thermostat, etc. | +| **OTA** | OTA requestor and compress-LZMA support | +| **Factory Data** | Factory data provisioning support | + +--- + +## 🆕 New Features + +- ✅ Matter 1.5.1 protocol support for Telink platforms +- ✅ Full support for TL323X series chips in Matter +- ✅ Support for TL721X series chips in Matter +- ✅ LZMA compression support for OTA images +- ✅ Factory data provisioning support +- ✅ Dual-mode configuration support for TL3238X +- ✅ Power management with retention RAM support +- ✅ NFC payload support for all-clusters-minimal-app +- ✅ DFU over SMP support for lock-app + +--- + +## 🐛 Bug Fixes + +| Issue | Description | +| ----------------- | ----------------------------------------------------------------------------- | +| **Network State** | Check Matter network state when power-on to ensure correct commissioning flow | +| **TL721X HAL V2** | Update hal_v1 to hal_v2 for TL721X | +| **PM Stability** | Improve power management stability on retention RAM configurations | +| **OTA Recovery** | Fix OTA recovery flow on TL323X series | + +--- + +## 📦 Updates + +- Updated Telink BLE SDK for improved RF performance + ([commit:46322e5b570e2a68373b18d4f08811acadd1266c](https://github.com/telink-semi/tl_ble_sdk_zephyr/commit/46322e5b570e2a68373b18d4f08811acadd1266c)) +- Updated Telink HAL Zephyr to support TL721X + hal_v2([commit:14c6149f6cc466c49d81e3b2f7f1e4d8ff6fbbb5](https://github.com/telink-semi/hal_telink/commit/14c6149f6cc466c49d81e3b2f7f1e4d8ff6fbbb5)) +- Updated MCUBoot with Telink-specific flash operation + ([commit:ce0da85c39c749df49b0ec62b33d2ecdea24c927](https://github.com/telink-semi/mcuboot/commit/ce0da85c39c749df49b0ec62b33d2ecdea24c927)) +- Updated OpenThread Telink source code + ([commit:542aaab44e1308e1a8a24573dfbd413fade342ee](https://github.com/telink-semi/openthread/commit/542aaab44e1308e1a8a24573dfbd413fade342ee)) +- Updated OpenThread Telink library + ([commit:308dae2f80084f87073cfd4fbd30f1be0799be7b](https://github.com/telink-semi/openthread_telink_lib/commit/308dae2f80084f87073cfd4fbd30f1be0799be7b)) +- Updated Telink Zephyr SDK to support TL323X and TL721X hal_v2 + ([commit:e08fc42546e58d808bfd39f35c8df296f5617a44](https://github.com/telink-semi/zephyr/commit/e08fc42546e58d808bfd39f35c8df296f5617a44)) + +--- + +## ⚠️ Important Notes + +**This is a BETA pre-release version for demonstration and testing purposes. Not +recommended for production use.** + +### Telink Matter ↔ Telink Zephyr Dependency + +The Telink Matter SDK is built **on top of** the Telink Zephyr SDK, and the two +are tightly coupled — they must be used as a matched pair. + +The Telink Zephyr SDK provides the foundational layers required to bring up a +Matter device on Telink silicon: the Zephyr RTOS core, the Telink hardware +abstraction layer (HAL), the BLE stack, MCUBoot bootloader, OpenThread +networking stack, the WEST tool and build toolchain. + +The Telink Matter SDK (this repository) builds upon that foundation to deliver +the Matter protocol stack itself together with a set of Telink Matter example +applications. Both components are required: the Matter SDK cannot be built +without the Zephyr SDK, and the Zephyr SDK alone does not provide Matter +support. + +> ⚠️ **Version pairing:** This Telink Matter release is validated against a +> specific Telink Zephyr SDK tag (see the +> [Version Information](#version-information) table below). Using a different +> Zephyr revision may cause build failures or runtime issues. + +--- + +## 📋 Version Information + +### Matter SDK & Toolchain + +| Component | Version | +| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **Matter SDK Version** | Telink Matter v1.5.1.0 | +| **Matter Branch** | master | +| **Commit** | [f4a8cf9](https://github.com/project-chip/connectedhomeip/commit/f4a8cf98ada4ad4f439b45e360800693cc5f1391) (the previous one of [15a68d7](https://github.com/project-chip/connectedhomeip/commit/15a68d7026b1cd34a0d4cf35dadc7558e503d2cb) that community upgraded Matter version to 1.6) | +| **Toolchain** | Zephyr SDK v0.17.0 riscv64-zephyr-elf | + +### Telink Matter SDK + +| Property | Version | +| ----------------- | -------------------------------------------------------------------------------------------------------------- | +| **Branch** | [dev-tlk_v1.5](https://github.com/telink-semi/connectedhomeip/tree/dev-tlk_v1.5) | +| **Target Commit** | [b4c04e3](https://github.com/telink-semi/connectedhomeip/commit/b4c04e3c1816fc242a100e305047ac1350457d17) | +| **Tag Name** | [tl_v1.0.1-beta-v1.5.1.0](https://github.com/telink-semi/connectedhomeip/releases/tag/tl_v1.0.1-beta-v1.5.1.0) | +| **Release Type** | Pre-Release (Beta) | + +### Chip & Hardware Versions + +📦 **Chip Versions** + +| Chip Family | Versions | +| ---------------------- | -------- | +| TLSR921X/TLSR951X(B91) | A2 | +| TLSR922X/TLSR952X(B92) | A3/A4 | +| TLSR911X(W91) | A2 | +| TL721X | A2/A3 | +| TL321X | A1/A2/A3 | +| TL323X | A0 | + +🔧 **Hardware EVK Versions** + +| Chip | EVK Version | +| -------- | ----------------------------- | +| TLSR921X | C1T213A20_V1.3 | +| TLSR952X | C1T266A20_V1.3 | +| TLSR911X | C1T301A20_V2.1 | +| TL721X | C1T315A20_V1.2 | +| TL321X | C1T331A20_V1.0/C1T335A20_V1.3 | +| TL323X | C1T388A20_V1.1 | + +--- + +## 📱 Matter Community Examples + +This release provides Telink platform ports for the following Matter community +example applications. Each example is located under +`examples//telink/` in the repository. The table below summarizes each +example and the Telink chip platforms that support it (see +[Telink Examples YAML file](.github/workflows/examples-telink.yaml)). + +> ✅ = Supported and Tested    🟡 = Supported but Untested +>    · = Untested + +| Example | Description | B91 (TLSR951X) | B92 (TLSR952X) | W91 (TLSR911X) | TL321X | TL323X | TL721X | +| ------------------------ | ---------------------------------------------------------- | :------------: | :------------: | :------------: | :----: | :----: | :----: | +| lighting-app | Lighting (On/Off, Level, Color Control) | 🟡 | · | 🟡 | 🟡 | ✅ | ✅ | +| light-switch-app | Light Switch (controller, switches a bound lighting-app) | · | 🟡 | · | 🟡 | ✅ | ✅ | +| bridge-app | Bridge / Aggregator (bridges non-Matter devices to Matter) | · | · | · | · | · | 🟡 | +| window-app | Window Covering (shades, blinds) | · | · | · | · | · | 🟡 | +| air-quality-sensor-app | Air Quality Sensor | · | 🟡 | · | · | · | · | +| all-clusters-app | All Clusters (full-featured test app) | · | · | 🟡 | · | · | · | +| all-clusters-minimal-app | All Clusters Minimal (lightweight test app, NFC payload) | · | 🟡 | · | · | · | · | +| contact-sensor-app | Contact Sensor (stateless contact sensing) | · | 🟡 | · | · | · | · | +| lock-app | Door Lock (supports DFU over BLE SMP) | · | 🟡 | · | · | · | · | +| smoke-co-alarm-app | Smoke & CO Alarm | · | 🟡 | · | · | · | · | +| pump-controller-app | Pump Controller | 🟡 | · | · | · | · | · | +| shell | Shell (debug console) | 🟡 | · | · | · | · | · | +| thermostat | Thermostat | · | · | 🟡 | · | · | · | +| ota-requestor-app | OTA Requestor (handles OTA image download) | · | · | · | 🟡 | · | · | + +### Notes on Platform Support + +- **Tested combinations (✅):** Only TL323X and TL721X with lighting-app and + light-switch-app have been fully tested in this release. +- **Supported but untested (🟡):** All other build targets listed in the table + are compiled successfully but have not been functionally validated in this + release. Use with caution. +- **Untested (·):** Combinations not listed are not built or validated in this + release. +- **B91 (TLSR951X)** and **W91 (TLSR911X)** are legacy platforms with broad + sample coverage (lighting, pump-controller, shell, thermostat, + all-clusters). +- **B92 (TLSR952X)** targets sensors and small appliances (air-quality, + contact-sensor, smoke-co-alarm, lock, light-switch, all-clusters-minimal). +- **TL321X / TL323X / TL721X** are the latest Telink RISC-V SoC families. + Lighting and light-switch apps are supported across all three; TL721X + additionally supports bridge-app and window-app. +- The light-switch-app on TL321X/TL323X/TL721X uses the `*_retention` board + target (power management with retention RAM). +- For build commands per board/app, refer to the per-board `*_README.md` files + inside each example's `boards/` directory. + +--- + +## 📊 Resource Usage (Code Size) + +This section shows the RAM and ROM usage for various Matter examples on Telink +platforms, built with the Matter SDK and Zephyr RTOS. + +### Supported Boards + +| Board | Chip Family | +| -------------- | ------------ | +| tlsr9518adk80d | TLSR951X/B91 | +| tlsr9528a | TLSR952X/B92 | +| tl3218x | TL321X | +| tl3238x | TL323X | +| tl7218x | TL721X | +| tlsr9118bdk40d | TLSR911X/W91 | + +### TL323X/TL721X Matter (OTA + LZMA) Code Size + +The tables below list the **Supported and Tested** Matter build targets for +TL323X and TL721X, built with OTA + BT DFU + LZMA compression enabled (2MB +Flash, Software Version 1). Memory usage data is extracted from the linker +output (`Memory region` summary) of the build logs. + +> 📌 **Memory Regions:** TL323X exposes `RAM_ILM_N` (instruction RAM, 64 KB) + +> `RAM` (data RAM, 96 KB); TL7218X exposes `RAMILM` (unified, 256 KB) or +> `RAM_ILM_N` (128 KB) + `RAM_DLM` (256 KB) depending on the board target. `ROM` +> is the application slot0 partition (1152 KB with LZMA overlay). + +#### TL323X (tl3238x) + +📈 **Resource Usage Details** + +| App | Build Target | RAM_ILM_N | ROM | RAM | Firmware (merged.bin) | +| -------------------- | --------------------------------- | ------------------------- | ---------------------------- | ------------------------- | --------------------- | +| **lighting-app** | `build_tl3238x_2m_flash_lzma_v1` | 51788 B (79.02% of 64 KB) | 960663 B (81.44% of 1152 KB) | 92552 B (94.15% of 96 KB) | 1047015 B | +| **light-switch-app** | `build_tl3238x_retention_lzma_v1` | 61558 B (93.93% of 64 KB) | 905054 B (76.72% of 1152 KB) | 86608 B (88.10% of 96 KB) | 991406 B | + +#### TL721X (tl7218x) + +📈 **Resource Usage Details** + +| App | Build Target | RAMILM / RAM_ILM_N | RAM_DLM | ROM | RAM | Firmware (merged.bin) | +| -------------------- | --------------------------------- | -------------------------- | ------------------------- | ---------------------------- | --------------------------- | --------------------- | +| **lighting-app** | `build_tl7218x_2m_flash_lzma_v1` | 96432 B (36.79% of 256 KB) | — | 942294 B (79.88% of 1152 KB) | 55936 B (21.34% of 256 KB) | 1028646 B | +| **light-switch-app** | `build_tl7218x_retention_lzma_v1` | 46834 B (35.73% of 128 KB) | 10026 B (3.82% of 256 KB) | 886204 B (75.12% of 1152 KB) | 104616 B (79.82% of 128 KB) | 972556 B | + +> 📌 **Notes:** +> +> - **Firmware (merged.bin)** = MCUBoot (at offset 0) + gap padding + slot0 +> application image (`zephyr.signed.bin`). This is the file flashed to the +> device. +> - All four targets fit within the slot0 partition (1152 KB) with LZMA +> compression enabled. +> - The LZMA-compressed DFU image (`merged_dfu.lzma.bin`) is smaller than the +> signed image (e.g. 942630 B → 547530 B for TL7218X lighting). +> - For a detailed RAM/ROM symbol breakdown, run `west build -t ram_report` / +> `west build -t rom_report` in the build directory. + +--- + +### 📝 Additional Notes + +- **Memory Regions:** May vary between chip variants; check individual board + configurations +- **Build Config:** Matter builds use `west build` directly from each + example's `telink` directory; CI builds use the Matter `build_examples.py` + system with Telink targets +- **Production Optimizations:** For production builds, disable debug logging + and enable appropriate optimizations to reduce RAM/ROM usage +- **Bluetooth & OpenThread:** Matter uses OpenThread for Thread networking + and BLE for commissioning +- **OTA Images:** Signed OTA images (`zephyr.signed.bin`) are generated when + OTA is enabled + +--- + +--- + +Made by Telink Semiconductor + +- [Website](https://www.telink-semi.com/) +- [Forum](https://forum.telink-semi.cn/) +- [Documentation](https://doc.telink-semi.cn/) diff --git a/docs/platforms/telink/telink_getting_started.md b/docs/platforms/telink/telink_getting_started.md new file mode 100644 index 000000000000..2472fa2b13d8 --- /dev/null +++ b/docs/platforms/telink/telink_getting_started.md @@ -0,0 +1,357 @@ +# Telink Matter Getting Started Guide + +This guide walks you through setting up the build environment, building, +flashing, and commissioning a Matter-over-Thread device on Telink RISC-V SoC +platforms. + +## Prerequisites + +### Supported Chips and Boards + +| Board target | Chip Family | Flash (default) | Notes | +| ---------------- | -------------- | :-------------: | ------------------------------------- | +| `tlsr9518adk80d` | TLSR951X / B91 | 2 MB | Legacy; broad sample coverage | +| `tlsr9528a` | TLSR952X / B92 | 2 MB | `_retention` variant for low-power | +| `tlsr9118bdk40d` | TLSR911X / W91 | 2 MB | Legacy; broad sample coverage | +| `tl3218x` | TL321X | 2 MB | `_retention` variant for low-power | +| `tl3238x` | TL323X | 2 MB | Dual-mode (Matter + Zigbee) supported | +| `tl7218x` | TL721X | 2 MB | `_retention` variant for low-power | + +> See the [Release Notes](./releases/telink_release_notes.md) for the exact chip +> versions, EVK versions, and per-example support matrix validated in each +> release. + +### Telink Matter ↔ Telink Zephyr Dependency + +The Telink Matter SDK is built **on top of** the Telink Zephyr SDK. The two are +tightly coupled and must be used as a matched pair: + +- The **Telink Zephyr SDK** provides Zephyr RTOS, the Telink HAL, the BLE + stack, MCUBoot, OpenThread, and the WEST build toolchain. +- The **Telink Matter SDK** (this repository) builds upon that foundation to + deliver the Matter protocol stack and Telink example applications. + +Both are required — the Matter SDK cannot be built without the Zephyr SDK, and +the Zephyr SDK alone does not provide Matter support. + +> ⚠️ **Version pairing:** Each Telink Matter release is validated against a +> specific Telink Zephyr SDK tag. Using a different Zephyr revision may cause +> build failures or runtime issues. See the +> [Release Notes](./releases/telink_release_notes.md) for the matched pair. + +## Step 1: Set up the Telink Zephyr SDK + +The Telink Matter examples use `west build` and require the Telink Zephyr SDK to +be installed and exported via `TELINK_ZEPHYR_BASE`. + +### 1.1 Install host dependencies + +```bash +sudo apt update && sudo apt upgrade +sudo apt install --no-install-recommends git cmake ninja-build gperf \ + ccache dfu-util device-tree-compiler \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ + make gcc gcc-multilib g++-multilib libsdl2-dev +``` + +Minimum versions: CMake 3.20.0, Python 3.6, devicetree compiler 1.4.6. + +### 1.2 Install west + +```bash +pip3 install --user -U west +echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc +source ~/.bashrc +``` + +### 1.3 Initialize the Zephyr workspace and switch to the Telink fork + +```bash +west init ~/zephyrproject +cd ~/zephyrproject +west update +west blobs fetch hal_telink +west zephyr-export + +cd zephyr +git remote add telink https://github.com/telink-semi/zephyr +git fetch telink +git checkout develop # or the branch matched to your Matter release +cd .. +west update +west blobs fetch hal_telink +``` + +### 1.4 Install the Zephyr SDK toolchain (riscv64) + +Download **Zephyr SDK v0.17.0** and install the riscv64 toolchain: + +```bash +wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.0/zephyr-sdk-0.17.0_linux-x86_64_minimal.tar.xz +tar xvf zephyr-sdk-0.17.0_linux-x86_64_minimal.tar.xz -C ~ +cd ~/zephyr-sdk-0.17.0 +./setup.sh -t riscv64-zephyr-elf -h -c +``` + +### 1.5 Source the Zephyr environment + +```bash +echo "source ~/zephyrproject/zephyr/zephyr-env.sh" >> ~/.bashrc +source ~/.bashrc +``` + +### 1.6 (hal_v2 chips only) Fetch the TL323X BLE SDK + +For **TL322X / TL323X** (hal_v2) chips, additionally fetch the BLE SDK: + +```bash +cd ~/zephyrproject/modules/hal/telink/hal_v2 +chmod +x fetch_sdk.sh +./fetch_sdk.sh +``` + +### 1.7 Verify the Zephyr installation + +Build the Hello World sample to confirm the toolchain works: + +```bash +cd ~/zephyrproject/zephyr +west build -p auto -b tlsr9518adk80d zephyr/samples/hello_world -d build_helloWorld +``` + +For more details, see the +[Telink Zephyr Getting Started guide](https://github.com/telink-semi/zephyr/blob/develop/doc/telink/getting_started/index.md). + +## Step 2: Get the Matter source code + +### 2.1 Install Matter host dependencies + +```bash +sudo apt-get install git gcc g++ pkg-config libssl-dev libdbus-1-dev \ + libglib2.0-dev libavahi-client-dev ninja-build python3-venv python3-dev \ + python3-pip unzip libgirepository1.0-dev libcairo2-dev libreadline-dev +``` + +### 2.2 Clone and set up the Matter repository + +```bash +git clone https://github.com/telink-semi/connectedhomeip.git +cd connectedhomeip +git checkout # e.g. dev-tlk_v1.5 +./scripts/checkout_submodules.py --platform telink,linux +``` + +### 2.3 Bootstrap the Matter build environment + +The first run takes a while as it downloads all pip/gn dependencies: + +```bash +source scripts/bootstrap.sh +``` + +> If you switch commits or branches later, re-run bootstrap after cleaning: +> +> ```bash +> rm -rf .environment +> source scripts/bootstrap.sh +> ``` + +## Step 3: Build a Matter example + +Telink Matter examples live under `examples//telink/`. Each example is +built with `west build` (which invokes the Zephyr build system under the hood). + +### 3.1 Activate the environment + +```bash +cd connectedhomeip +source scripts/activate.sh +``` + +### 3.2 Build with west + +```bash +cd examples/lighting-app/telink +west build -b +``` + +Replace `` with your board, e.g. `tlsr9518adk80d`, `tlsr9528a`, +`tl3218x`, `tl3238x`, `tl7218x`, or `tlsr9118bdk40d`. + +**Example -- A simple build with 2 MB Flash** + +```bash +west build -b tl3238x +``` + +If your board has a flash size other than the default 2 MB, specify it: + +```bash +west build -b tl3238x -- -DFLASH_SIZE=4m +``` + +The built firmware is at `build/zephyr/zephyr.bin`. When MCUBoot + OTA is +enabled, a merged `build/zephyr/merged.bin` (MCUBoot + app) is also generated. + +### 3.3 Build with build_examples.py (CI-style) + +Alternatively, use the Matter build system to build via GN: + +```bash +./scripts/build/build_examples.py --target telink-tl7218x-lighting-compress-lzma build +``` + +List all available Telink targets: + +```bash +./scripts/build/build_examples.py targets | grep telink +``` + +Common target options include `-compress-lzma`, `-ota`, `-dfu-smp`, +`-factory-data`, `-shell`, `-rpcs`, and `-4mb-flash`. + +### 3.4 TL3238X build configurations + +TL3238X supports several configurations depending on flash size and dual-mode +(Matter + Zigbee) needs. Key combinations: + +| Config | Flash | OTA | LZMA | Dual-mode | Conf file | +| --------------------------------- | :---: | :-: | :--: | :-------: | -------------------------------------------- | +| Default (no OTA, no MCUBoot) | 2 MB | No | No | No | `boards/tl3238x.conf` | +| OTA + BT DFU + LZMA | 2 MB | Yes | Yes | No | `boards/tl3238x_2m_flash_ota_lzma.conf` | +| Dual-mode (Matter + Zigbee) + OTA | 4 MB | Yes | No | Yes | `boards/tl3238x_4m_flash_dual_mode_ota.conf` | + +> ⚠️ For 2 MB Flash + OTA, LZMA compression is **required** — a non-LZMA build +> will not fit. + +Example — 2 MB Flash with OTA + LZMA, software version 2: + +```bash +west build -p -b tl3238x -d build_tl3238x_lzma_v1 -- \ + -DCONF_FILE="prj.conf boards/tl3238x_2m_flash_ota_lzma.conf" \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 +``` + +## Step 4: Flash the firmware + +### 4.1 Option A: west flash (recommended for development) + +If your board is connected via a supported debug probe: + +```bash +west flash --erase +``` + +### 4.2 Option B: BDT (Telink flashing tool) + +Telink provides the **BDT** (Burning Debug Tool) for flashing. On Windows use +the BDT GUI (`Telink BDT.exe`); on Linux use the `bdt` CLI. See the +[Telink Zephyr Getting Started — Flash the Firmware](https://github.com/telink-semi/zephyr/blob/develop/doc/telink/getting_started/index.md#flash-the-firmware) +section for the chip-to-BDT name mapping and the unlock/erase/write flow. + +A typical Linux BDT session: + +```bash +./bdt B92 wf 0 -s 2040k -e # erase (replace B92 with your chip name) +./bdt B92 wf 0 -i zephyr.bin # write +./bdt B92 rst # reset +``` + +> For B92 / TL321X / TL721X, run `./bdt ulf` to unlock the flash before +> erasing. For TL322X / TL323X, use the **TGui-BDT** tool (or `sctool` on Linux) +> with the on-board programmer. + +### 4.3 UART console + +Connect UART to view device logs: + +| Name | Pin | +| :--: | :---------------------------- | +| RX | PB0 (pin 17 of J34 connector) | +| TX | PB2 (pin 16 of J34 connector) | +| GND | GND | + +Baud rate: **115200** bits/s. + +## Step 5: Commission and control with chip-tool + +### 5.1 Build chip-tool + +Follow the +[chip-tool guide](../../development_controllers/chip-tool/chip_tool_guide.md) to +build the Matter controller. + +### 5.2 Set up a Thread border router + +Matter-over-Thread devices require a Thread border router to bridge the Thread +network to Wi-Fi/Ethernet. Follow the +[OpenThread border router guide](../openthread/openthread_border_router_pi.md) +to set up a Raspberry Pi border router. + +### 5.3 Pair the device + +```bash +./chip-tool pairing ble-thread ${NODE_ID} hex:${DATASET} ${PIN_CODE} ${DISCRIMINATOR} +``` + +Example: + +```bash +./chip-tool pairing ble-thread 1234 hex:0e080000000000010000000300000f35060004001fffe0020811111111222222220708fd61f77bd3df233e051000112233445566778899aabbccddeeff030e4f70656e54687265616444656d6f010212340410445f2b5ca6f2a93a55ce570a70efeecb0c0402a0fff8 20202021 3840 +``` + +### 5.4 Control the lighting + +```bash +./chip-tool onoff on 1 # switch on +./chip-tool onoff off 1 # switch off +./chip-tool onoff read on-off 1 # read state +./chip-tool levelcontrol move-to-level 32 0 0 0 1 # set brightness +``` + +## Buttons and LEDs + +The on-board buttons and LEDs provide basic control and status feedback: + +| Button | Function | Description | +| :------- | :--------------------- | :------------------------------------------------------------- | +| Button 1 | Factory reset | Press 3 times to forget the commissioned Thread network | +| Button 2 | App control | Manually triggers the application state (e.g. toggle lighting) | +| Button 3 | Thread start | Commission with static credentials and enable Thread | +| Button 4 | Open commission window | Opens the BLE commissioning window | + +**Red LED** — Thread network state: + +| State | Meaning | +| :-------------- | :--------------------------------------- | +| Short pulses | Not commissioned; Thread disabled | +| Frequent pulses | Commissioned; joining the Thread network | +| Wide pulses | Joined to the Thread network as a CHILD | + +**Green LED** — Identify (blinks when the Identify command is received). + +## OTA Firmware Update + +OTA is enabled by default only for the `ota-requestor-app` example. To enable +OTA on other examples, set `CONFIG_CHIP_OTA_REQUESTOR=y` in the example's +`prj.conf`. + +After building with OTA enabled, the following artifacts are generated: + +| File | Purpose | +| --------------------- | ----------------------------------------------------- | +| `merged.bin` | Main binary to flash (MCUBoot + app), for first flash | +| `matter.ota` | OTA image for the OTA Provider | +| `merged_dfu.lzma.bin` | LZMA-compressed DFU image for BLE SMP DFU | + +To test OTA with a Linux OTA Provider, refer to the +[OTA section in the lighting-app README](../../../examples/lighting-app/telink/README.md#ota-with-linux-ota-provider). + +## Next steps + +- [Telink Release Notes](./releases/telink_release_notes.md) — version info, + chip/EVK versions, per-example support matrix, and resource usage tables. +- [Telink Zephyr Getting Started](https://github.com/telink-semi/zephyr/blob/develop/doc/telink/getting_started/index.md) + — Zephyr SDK setup, BDT flashing details, and board overviews. +- Per-example `README.md` files under `examples//telink/` — + example-specific build commands, button/LED mappings, and chip-tool usage. diff --git a/examples/contact-sensor-app/telink/CMakeLists.txt b/examples/contact-sensor-app/telink/CMakeLists.txt index 988921590889..10cccb64b3a9 100755 --- a/examples/contact-sensor-app/telink/CMakeLists.txt +++ b/examples/contact-sensor-app/telink/CMakeLists.txt @@ -58,3 +58,8 @@ chip_configure_data_model(app if(CONFIG_BOOTLOADER_MCUBOOT) target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) endif() + +if(CONFIG_MCUMGR_TRANSPORT_BT) + zephyr_library_link_libraries(MCUBOOT_BOOTUTIL) + target_sources(app PRIVATE ${TELINK_COMMON}/util/src/DFUOverSMP.cpp) +endif() diff --git a/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf b/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf new file mode 100644 index 000000000000..da22e9960618 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl3238x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=y + +#compress ota +CONFIG_COMPRESS_LZMA=y +CONFIG_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl3238x_retention_README.txt b/examples/contact-sensor-app/telink/boards/tl3238x_retention_README.txt new file mode 100644 index 000000000000..f9bc642e2dfb --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl3238x_retention_README.txt @@ -0,0 +1,107 @@ +TL3238X Retention Contact-Sensor App Build Guide +================================================= + +1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) +------------------------------------------- + +Kconfig: boards/tl3238x_retention.conf (default) + - CONFIG_CHIP_OTA_REQUESTOR=n + - CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, + - CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n + - CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be upgraded + +DTS Overlay: src/platform/telink/tl3238x_2m_flash.overlay (default) + - slot0: 0x15000, size 0xe5000 (916KB) + - slot1: 0xfa000, size 0xe6000 (920KB) + +Build: + west build -p -b tl3238x_retention -d build_tl3238x_retention_default -- \ + > build_tl3238x_retention_default.log + # Kconfig: default (boards/tl3238x_retention.conf) + # DTS Overlay: default (src/platform/telink/tl3238x_2m_flash.overlay) + +Output: + build_tl3238x_retention_default/zephyr/zephyr.bin -> flash this + +2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) +------------------------------------------- +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +Kconfig: boards/tl3238x_retention_ota_lzma.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=0 + +DTS Overlay: src/platform/telink/tl3238x_2m_flash_lzma.overlay (default) + - slot0: 0x15000, size 0x120000 (1152KB) + - slot1: 0x135000, size 0xAB000 (684KB) + +Build Software Version 1: + west build -p -b tl3238x_retention -d build_tl3238x_retention_lzma_v1 -- \ + -DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf" \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl3238x_retention_lzma_v1.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) + +Build Software Version 2: + west build -p -b tl3238x_retention -d build_tl3238x_retention_lzma_v2 -- \ + -DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf" \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl3238x_retention_lzma_v2.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) + +Output: + build_tl3238x_retention_lzma_v1/zephyr/merged.bin -> flash this + build_tl3238x_retention_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP + build_tl3238x_retention_lzma_v2/zephyr/matter.ota -> OTA upgrade + +3. 2MB Flash (Matter + Zigbee dual mode, LZMA compressed, enable BT DFU) +----------------------------------------------------------------- + +Prerequisite: copy Zigbee firmware + cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin + e.g. + cp ${ZEPHYR_BASE}/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin + +Note: This dual-mode configuration is for 2MB flash only. LZMA compression is required due to limited partition space. + +Kconfig: boards/tl3238x_retention_dual_mode_ota_lzma.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=1 (action switch mode) + +DTS Overlay: src/platform/telink/tl3238x_2m_flash_lzma.overlay (default) + - slot0: 0x15000, size 0x120000 (1152KB) + - slot1: 0x135000, size 0xAB000 (684KB) + +Build: + west build -p -b tl3238x_retention -d build_tl3238x_retention_dual_mode -- \ + -DCONF_FILE="prj.conf boards/tl3238x_retention_dual_mode_ota_lzma.conf" > build_tl3238x_retention_dual_mode.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_retention_dual_mode_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) + +Output: + build_tl3238x_retention_dual_mode/zephyr/merged.bin -> flash this (sboot+mcuboot+matter+zb) + build_tl3238x_retention_dual_mode/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP + build_tl3238x_retention_dual_mode/zephyr/matter.ota -> OTA upgrade + +4. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) +----------------------------------------------------------- +**This configuration will show a warning during build and may fail at link time.** + +Kconfig: boards/tl3238x_retention_ota.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n + - CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + "tl3238x with 2MB flash and OTA requires LZMA compression. Please use a config with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 916KB (0xe5000) partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. diff --git a/examples/contact-sensor-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf b/examples/contact-sensor-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf new file mode 100644 index 000000000000..2e4f4304701a --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=y + +#compress ota +CONFIG_LZMA=y +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=1 diff --git a/examples/contact-sensor-app/telink/boards/tl3238x_retention_ota.conf b/examples/contact-sensor-app/telink/boards/tl3238x_retention_ota.conf new file mode 100644 index 000000000000..ef9fd725d9da --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl3238x_retention_ota.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=y + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl3238x_retention_ota_lzma.conf b/examples/contact-sensor-app/telink/boards/tl3238x_retention_ota_lzma.conf new file mode 100644 index 000000000000..945826a5e462 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl3238x_retention_ota_lzma.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=y + +# LZMA compression library support +CONFIG_LZMA=y +# Enable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl5218x_retention.conf b/examples/contact-sensor-app/telink/boards/tl5218x_retention.conf new file mode 100644 index 000000000000..864cdbde9d22 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl5218x_retention.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +#compress ota +CONFIG_COMPRESS_LZMA=y +CONFIG_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl5218x_retention_README.txt b/examples/contact-sensor-app/telink/boards/tl5218x_retention_README.txt new file mode 100644 index 000000000000..56ba6f9ec05a --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl5218x_retention_README.txt @@ -0,0 +1,107 @@ +TL5218X Retention Contact-Sensor App Build Guide +================================================= + +1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) +------------------------------------------- + +Kconfig: boards/tl5218x_retention.conf (default) + - CONFIG_CHIP_OTA_REQUESTOR=n + - CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, + - CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n + - CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be upgraded + +DTS Overlay: src/platform/telink/tl5218x_2m_flash.overlay (default) + - slot0: 0x15000, size 0xe7000 (924KB) + - slot1: 0xfc000, size 0xe7000 (924KB) + +Build: + west build -p -b tl5218x_retention -d build_tl5218x_retention_default -- \ + > build_tl5218x_retention_default.log + # Kconfig: default (boards/tl5218x_retention.conf) + # DTS Overlay: default (src/platform/telink/tl5218x_2m_flash.overlay) + +Output: + build_tl5218x_retention_default/zephyr/zephyr.bin -> flash this + +2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) +------------------------------------------- +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +Kconfig: boards/tl5218x_retention_ota_lzma.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=0 + +DTS Overlay: src/platform/telink/tl5218x_2m_flash_lzma.overlay (default) + - slot0: 0x15000, size 0x120000 (1152KB) + - slot1: 0x135000, size 0xAB000 (684KB) + +Build Software Version 1: + west build -p -b tl5218x_retention -d build_tl5218x_retention_lzma_v1 -- \ + -DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf" \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl5218x_retention_lzma_v1.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) + +Build Software Version 2: + west build -p -b tl5218x_retention -d build_tl5218x_retention_lzma_v2 -- \ + -DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf" \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl5218x_retention_lzma_v2.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) + +Output: + build_tl5218x_retention_lzma_v1/zephyr/merged.bin -> flash this + build_tl5218x_retention_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP + build_tl5218x_retention_lzma_v2/zephyr/matter.ota -> OTA upgrade + +3. 2MB Flash (Matter + Zigbee dual mode, LZMA compressed, enable BT DFU) +----------------------------------------------------------------- + +Prerequisite: copy Zigbee firmware + cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin + e.g. + cp ${ZEPHYR_BASE}/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin + +Note: This dual-mode configuration is for 2MB flash only. LZMA compression is required due to limited partition space. + +Kconfig: boards/tl5218x_retention_dual_mode_ota_lzma.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=1 (action switch mode) + +DTS Overlay: src/platform/telink/tl5218x_2m_flash_lzma.overlay (default) + - slot0: 0x15000, size 0x120000 (1152KB) + - slot1: 0x135000, size 0xAB000 (684KB) + +Build: + west build -p -b tl5218x_retention -d build_tl5218x_retention_dual_mode -- \ + -DCONF_FILE="prj.conf boards/tl5218x_retention_dual_mode_ota_lzma.conf" > build_tl5218x_retention_dual_mode.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_retention_dual_mode_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) + +Output: + build_tl5218x_retention_dual_mode/zephyr/merged.bin -> flash this (sboot+mcuboot+matter+zb) + build_tl5218x_retention_dual_mode/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP + build_tl5218x_retention_dual_mode/zephyr/matter.ota -> OTA upgrade + +4. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) +----------------------------------------------------------- +**This configuration will show a warning during build and may fail at link time.** + +Kconfig: boards/tl5218x_retention_ota.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n + - CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + "tl5218x with 2MB flash and OTA requires LZMA compression. Please use a config with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 924KB (0xe7000) partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. diff --git a/examples/contact-sensor-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf b/examples/contact-sensor-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf new file mode 100644 index 000000000000..e71cb0183d93 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +#compress ota +CONFIG_LZMA=y +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=1 diff --git a/examples/contact-sensor-app/telink/boards/tl5218x_retention_ota.conf b/examples/contact-sensor-app/telink/boards/tl5218x_retention_ota.conf new file mode 100644 index 000000000000..beb08f0de001 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl5218x_retention_ota.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl5218x_retention_ota_lzma.conf b/examples/contact-sensor-app/telink/boards/tl5218x_retention_ota_lzma.conf new file mode 100644 index 000000000000..0804c6c94c9f --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl5218x_retention_ota_lzma.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=y +# Enable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl7218x_retention.conf b/examples/contact-sensor-app/telink/boards/tl7218x_retention.conf new file mode 100644 index 000000000000..d2f0cd585770 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl7218x_retention.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl7218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=y +# Disable Telink-specific LZMA firmware decompression for bootloader +# This is not needed since Matter OTA is disabled (CONFIG_CHIP_OTA_REQUESTOR=n) +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl7218x_retention_README.txt b/examples/contact-sensor-app/telink/boards/tl7218x_retention_README.txt new file mode 100644 index 000000000000..b869838ce61e --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl7218x_retention_README.txt @@ -0,0 +1,78 @@ +TL7218X Retention Contact-Sensor App Build Guide +================================================== + +1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) +------------------------------------------- + +Kconfig: boards/tl7218x_retention.conf (default) + - CONFIG_CHIP_OTA_REQUESTOR=n + - CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, + - CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n + - CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be upgraded + +DTS Overlay: src/platform/telink/tl7218x_2m_flash.overlay (default) + - slot0: 0x15000, size 0xe5000 (916KB) + - slot1: 0xfa000, size 0xe6000 (920KB) + +Build: + west build -p -b tl7218x_retention -d build_tl7218x_retention_default -- \ + > build_tl7218x_retention_default.log + # Kconfig: default (boards/tl7218x_retention.conf) + # DTS Overlay: default (src/platform/telink/tl7218x_2m_flash.overlay) + +Output: + build_tl7218x_retention_default/zephyr/zephyr.bin -> flash this + +2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) +------------------------------------------- +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +Kconfig: boards/tl7218x_retention_ota_lzma.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=0 + +DTS Overlay: src/platform/telink/tl7218x_2m_flash_lzma.overlay (default) + - slot0: 0x15000, size 0x120000 (1152KB) + - slot1: 0x135000, size 0xAB000 (684KB) + +Build Software Version 1: + west build -p -b tl7218x_retention -d build_tl7218x_retention_lzma_v1 -- \ + -DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf" \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl7218x_retention_lzma_v1.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) + +Build Software Version 2: + west build -p -b tl7218x_retention -d build_tl7218x_retention_lzma_v2 -- \ + -DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf" \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl7218x_retention_lzma_v2.log + # Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf") + # DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) + +Output: + build_tl7218x_retention_lzma_v1/zephyr/merged.bin -> flash this + build_tl7218x_retention_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP + build_tl7218x_retention_lzma_v2/zephyr/matter.ota -> OTA upgrade + +3. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) +----------------------------------------------------------- +**This configuration will show a warning during build and may fail at link time.** + +Kconfig: boards/tl7218x_retention_ota.conf (explicitly specified) + - CONFIG_CHIP_OTA_REQUESTOR=y + - CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, + - CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n + - CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + "tl7218x with 2MB flash and OTA requires LZMA compression. Please use a config with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 916KB (0xe5000) partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. + +**Important Note**: TL7218X does NOT support dual_mode (Matter + Zigbee) configuration. diff --git a/examples/contact-sensor-app/telink/boards/tl7218x_retention_ota.conf b/examples/contact-sensor-app/telink/boards/tl7218x_retention_ota.conf new file mode 100644 index 000000000000..cbb9b50537cc --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl7218x_retention_ota.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl7218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/boards/tl7218x_retention_ota_lzma.conf b/examples/contact-sensor-app/telink/boards/tl7218x_retention_ota_lzma.conf new file mode 100644 index 000000000000..778728c67926 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl7218x_retention_ota_lzma.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl7218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=y +# Enable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/contact-sensor-app/telink/prj.conf b/examples/contact-sensor-app/telink/prj.conf index cfac50c71874..9b8448afc3ad 100755 --- a/examples/contact-sensor-app/telink/prj.conf +++ b/examples/contact-sensor-app/telink/prj.conf @@ -30,6 +30,9 @@ CONFIG_BT_DEVICE_NAME="TelinkSensor" # Disable Matter OTA DFU CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 # Disable CHIP shell support @@ -39,6 +42,25 @@ CONFIG_CHIP_LIB_SHELL=n CONFIG_CHIP_FACTORY_DATA=n CONFIG_CHIP_FACTORY_DATA_BUILD=n CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n - +CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n +# CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=y + +#ICD SETTING INFO +CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 +CONFIG_CHIP_ICD_FAST_POLLING_INTERVAL=200 +CONFIG_CHIP_ICD_ACTIVE_MODE_THRESHOLD=300 +CONFIG_CHIP_ICD_IDLE_MODE_DURATION=900 + +# open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE +# init should be n +CONFIG_SECURE_PROGRAMMING=n + +# Enable CHIP-ID via ble +CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n + +# Enable Deferred Store Attribute +CONFIG_DEFERRED_ATTR_STORAGE=n + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention.conf b/examples/light-switch-app/telink/boards/tl3238x_retention.conf new file mode 100644 index 000000000000..8238e59aae6e --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + +# Enable ADC +CONFIG_ADC=y + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention_README.md b/examples/light-switch-app/telink/boards/tl3238x_retention_README.md new file mode 100644 index 000000000000..b9c272e1d09f --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention_README.md @@ -0,0 +1,143 @@ +# TL3238X Retention Light-Switch App Build Guide + +## 1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) + +**Kconfig:** boards/tl3238x_retention.conf (default) + +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be +upgraded + +**DTS Overlay:** src/platform/telink/tl3238x_2m_flash.overlay (default) + +- slot0: 0x15000, size 0xe5000 (916KB) +- slot1: 0xfa000, size 0xe6000 (920KB) + +**Build:** + +```bash +west build -p -b tl3238x_retention -d build_tl3238x_retention_default -- \ +> build_tl3238x_retention_default.log +# Kconfig: default (boards/tl3238x_retention.conf) +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl3238x_retention_default/zephyr/zephyr.bin -> flash this +``` + +## 2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) + +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +**Kconfig:** boards/tl3238x_retention_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=0 + +**DTS Overlay:** src/platform/telink/tl3238x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build Software Version 1:** + +```bash +west build -p -b tl3238x_retention -d build_tl3238x_retention_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl3238x_retention_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) +``` + +**Build Software Version 2:** + +```bash +west build -p -b tl3238x_retention -d build_tl3238x_retention_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl3238x_retention_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_retention_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl3238x_retention_lzma_v1/zephyr/merged.bin -> flash this +build_tl3238x_retention_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl3238x_retention_lzma_v2/zephyr/matter.ota -> OTA upgrade +``` + +## 3. 2MB Flash (Matter + Zigbee dual mode, LZMA compressed, enable BT DFU) + +**Prerequisite:** copy Zigbee firmware + +```bash +cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +e.g. +cp ${ZEPHYR_BASE}/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +``` + +**Note:** This dual-mode configuration is for 2MB flash only. LZMA compression +is required due to limited partition space. + +**Kconfig:** boards/tl3238x_retention_dual_mode_ota_lzma.conf (explicitly +specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=1 (action switch mode) + +**DTS Overlay:** src/platform/telink/tl3238x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build:** + +```bash +west build -p -b tl3238x_retention -d build_tl3238x_retention_dual_mode -- \ +-DCONF_FILE="prj.conf boards/tl3238x_retention_dual_mode_ota_lzma.conf" > build_tl3238x_retention_dual_mode.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_retention_dual_mode_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl3238x_retention_dual_mode/zephyr/merged.bin -> flash this (sboot+mcuboot+matter+zb) +build_tl3238x_retention_dual_mode/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl3238x_retention_dual_mode/zephyr/matter.ota -> OTA upgrade +``` + +## 4. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) + +**This configuration will show a warning during build and may fail at link +time.** + +**Kconfig:** boards/tl3238x_retention_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + +> "tl3238x with 2MB flash and OTA requires LZMA compression. Please use a config +> with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation +> anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 916KB (0xe5000) +partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf b/examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf new file mode 100644 index 000000000000..2e4f4304701a --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=y + +#compress ota +CONFIG_LZMA=y +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=1 diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention_ota.conf b/examples/light-switch-app/telink/boards/tl3238x_retention_ota.conf new file mode 100644 index 000000000000..ef9fd725d9da --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention_ota.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=y + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention_ota_lzma.conf b/examples/light-switch-app/telink/boards/tl3238x_retention_ota_lzma.conf new file mode 100644 index 000000000000..945826a5e462 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention_ota_lzma.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=y + +# LZMA compression library support +CONFIG_LZMA=y +# Enable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl5218x_retention.conf b/examples/light-switch-app/telink/boards/tl5218x_retention.conf new file mode 100644 index 000000000000..d2b3a2312965 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl5218x_retention.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl5218x_retention_README.md b/examples/light-switch-app/telink/boards/tl5218x_retention_README.md new file mode 100644 index 000000000000..7f7bef47b9e4 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl5218x_retention_README.md @@ -0,0 +1,143 @@ +# TL5218X Retention Light-Switch App Build Guide + +## 1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) + +**Kconfig:** boards/tl5218x_retention.conf (default) + +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be +upgraded + +**DTS Overlay:** src/platform/telink/tl5218x_2m_flash.overlay (default) + +- slot0: 0x15000, size 0xe7000 (924KB) +- slot1: 0xfc000, size 0xe7000 (924KB) + +**Build:** + +```bash +west build -p -b tl5218x_retention -d build_tl5218x_retention_default -- \ +> build_tl5218x_retention_default.log +# Kconfig: default (boards/tl5218x_retention.conf) +# DTS Overlay: default (src/platform/telink/tl5218x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl5218x_retention_default/zephyr/zephyr.bin -> flash this +``` + +## 2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) + +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +**Kconfig:** boards/tl5218x_retention_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=0 + +**DTS Overlay:** src/platform/telink/tl5218x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build Software Version 1:** + +```bash +west build -p -b tl5218x_retention -d build_tl5218x_retention_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl5218x_retention_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) +``` + +**Build Software Version 2:** + +```bash +west build -p -b tl5218x_retention -d build_tl5218x_retention_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl5218x_retention_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_retention_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl5218x_retention_lzma_v1/zephyr/merged.bin -> flash this +build_tl5218x_retention_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl5218x_retention_lzma_v2/zephyr/matter.ota -> OTA upgrade +``` + +## 3. 2MB Flash (Matter + Zigbee dual mode, LZMA compressed, enable BT DFU) + +**Prerequisite:** copy Zigbee firmware + +```bash +cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +e.g. +cp ${ZEPHYR_BASE}/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +``` + +**Note:** This dual-mode configuration is for 2MB flash only. LZMA compression +is required due to limited partition space. + +**Kconfig:** boards/tl5218x_retention_dual_mode_ota_lzma.conf (explicitly +specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=1 (action switch mode) + +**DTS Overlay:** src/platform/telink/tl5218x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build:** + +```bash +west build -p -b tl5218x_retention -d build_tl5218x_retention_dual_mode -- \ +-DCONF_FILE="prj.conf boards/tl5218x_retention_dual_mode_ota_lzma.conf" > build_tl5218x_retention_dual_mode.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_retention_dual_mode_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl5218x_retention_dual_mode/zephyr/merged.bin -> flash this (sboot+mcuboot+matter+zb) +build_tl5218x_retention_dual_mode/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl5218x_retention_dual_mode/zephyr/matter.ota -> OTA upgrade +``` + +## 4. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) + +**This configuration will show a warning during build and may fail at link +time.** + +**Kconfig:** boards/tl5218x_retention_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + +> "tl5218x with 2MB flash and OTA requires LZMA compression. Please use a config +> with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation +> anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 924KB (0xe7000) +partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. diff --git a/examples/light-switch-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf b/examples/light-switch-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf new file mode 100644 index 000000000000..e1b016bfdd26 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +#compress ota +CONFIG_LZMA=y +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=1 diff --git a/examples/light-switch-app/telink/boards/tl5218x_retention_ota.conf b/examples/light-switch-app/telink/boards/tl5218x_retention_ota.conf new file mode 100644 index 000000000000..a6b5af6a3698 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl5218x_retention_ota.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl5218x_retention_ota_lzma.conf b/examples/light-switch-app/telink/boards/tl5218x_retention_ota_lzma.conf new file mode 100644 index 000000000000..b2c8e7e9835f --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl5218x_retention_ota_lzma.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=y +# Enable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl7218x_retention.conf b/examples/light-switch-app/telink/boards/tl7218x_retention.conf new file mode 100644 index 000000000000..17b09b52504a --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl7218x_retention.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl7218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=y +# Disable Telink-specific LZMA firmware decompression for bootloader +# This is not needed since Matter OTA is disabled (CONFIG_CHIP_OTA_REQUESTOR=n) +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl7218x_retention_README.md b/examples/light-switch-app/telink/boards/tl7218x_retention_README.md new file mode 100644 index 000000000000..b7b54515368d --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl7218x_retention_README.md @@ -0,0 +1,103 @@ +# TL7218X Retention Light-Switch App Build Guide + +## 1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) + +**Kconfig:** boards/tl7218x_retention.conf (default) + +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be +upgraded + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash.overlay (default) + +- slot0: 0x15000, size 0xe5000 (916KB) +- slot1: 0xfa000, size 0xe6000 (920KB) + +**Build:** + +```bash +west build -p -b tl7218x_retention -d build_tl7218x_retention_default -- \ +> build_tl7218x_retention_default.log +# Kconfig: default (boards/tl7218x_retention.conf) +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl7218x_retention_default/zephyr/zephyr.bin -> flash this +``` + +## 2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) + +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +**Kconfig:** boards/tl7218x_retention_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=0 + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build Software Version 1:** + +```bash +west build -p -b tl7218x_retention -d build_tl7218x_retention_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl7218x_retention_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) +``` + +**Build Software Version 2:** + +```bash +west build -p -b tl7218x_retention -d build_tl7218x_retention_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl7218x_retention_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_retention_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl7218x_retention_lzma_v1/zephyr/merged.bin -> flash this +build_tl7218x_retention_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl7218x_retention_lzma_v2/zephyr/matter.ota -> OTA upgrade +``` + +## 3. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) + +**This configuration will show a warning during build and may fail at link +time.** + +**Kconfig:** boards/tl7218x_retention_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + +> "tl7218x with 2MB flash and OTA requires LZMA compression. Please use a config +> with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation +> anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 916KB (0xe5000) +partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. + +**Important Note**: TL7218X does NOT support dual_mode (Matter + Zigbee) +configuration. diff --git a/examples/light-switch-app/telink/boards/tl7218x_retention_dual_mode_ota_lzma.conf b/examples/light-switch-app/telink/boards/tl7218x_retention_dual_mode_ota_lzma.conf new file mode 100644 index 000000000000..7d3312a9066b --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl7218x_retention_dual_mode_ota_lzma.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl7218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +#compress ota +CONFIG_LZMA=y +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=1 diff --git a/examples/light-switch-app/telink/boards/tl7218x_retention_ota.conf b/examples/light-switch-app/telink/boards/tl7218x_retention_ota.conf new file mode 100644 index 000000000000..f93bcb98e047 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl7218x_retention_ota.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl7218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl7218x_retention_ota_lzma.conf b/examples/light-switch-app/telink/boards/tl7218x_retention_ota_lzma.conf new file mode 100644 index 000000000000..7db24c3d5cc1 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl7218x_retention_ota_lzma.conf @@ -0,0 +1,20 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl7218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# Enable ADC +CONFIG_ADC=n + +# LZMA compression library support +CONFIG_LZMA=y +# Enable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/prj.conf b/examples/light-switch-app/telink/prj.conf index eb9ba62ea623..e04110d9c78d 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -33,6 +33,7 @@ CONFIG_CHIP_OTA_REQUESTOR=n CONFIG_CHIP_DFU_OVER_BT_SMP=n CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch" # Disable CHIP shell support CONFIG_CHIP_LIB_SHELL=n @@ -42,6 +43,24 @@ CONFIG_CHIP_FACTORY_DATA=n CONFIG_CHIP_FACTORY_DATA_BUILD=n CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n - +# CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=y + +#ICD SETTING INFO +CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 +CONFIG_CHIP_ICD_FAST_POLLING_INTERVAL=200 +CONFIG_CHIP_ICD_ACTIVE_MODE_THRESHOLD=300 +CONFIG_CHIP_ICD_IDLE_MODE_DURATION=900 + +# open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE +# init should be n +CONFIG_SECURE_PROGRAMMING=n + +# Enable CHIP-ID via ble +CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n + +# Enable Deferred Store Attribute +CONFIG_DEFERRED_ATTR_STORAGE=n + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" diff --git a/examples/lighting-app/telink/boards/tl3238x.conf b/examples/lighting-app/telink/boards/tl3238x.conf new file mode 100644 index 000000000000..a3c7a2c90444 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl3238x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=n + +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=y + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl3238x_2m_flash_ota_lzma.conf b/examples/lighting-app/telink/boards/tl3238x_2m_flash_ota_lzma.conf new file mode 100644 index 000000000000..051581c6238f --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_2m_flash_ota_lzma.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl3238x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y + +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=y +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +# Enable ADC +CONFIG_ADC=y + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode_ota.conf b/examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode_ota.conf new file mode 100644 index 000000000000..06f102ad2c5e --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode_ota.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tlsr9268m" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +#compress ota +CONFIG_LZMA=n +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=y + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=2 diff --git a/examples/lighting-app/telink/boards/tl3238x_README.md b/examples/lighting-app/telink/boards/tl3238x_README.md new file mode 100644 index 000000000000..681555c904e8 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_README.md @@ -0,0 +1,146 @@ +# TL3238X Lighting App Build Guide + +## 1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) + +**Kconfig:** boards/tl3238x.conf (default) + +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be +upgraded + +**DTS Overlay:** src/platform/telink/tl3238x_2m_flash.overlay (default) + +- slot0: 0x15000, size 0xe5000 (916KB) +- slot1: 0xfa000, size 0xe6000 (920KB) + +**Build:** + +```bash +west build -p -b tl3238x -d build_tl3238x_default -- \ +> build_tl3238x_default.log +# Kconfig: default (boards/tl3238x.conf) +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl3238x_default/zephyr/zephyr.bin -> flash this +``` + +## 2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) + +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +**Kconfig:** boards/tl3238x_2m_flash_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=0 + +**DTS Overlay:** src/platform/telink/tl3238x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build Software Version 1:** + +```bash +west build -p -b tl3238x -d build_tl3238x_2m_flash_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl3238x_2m_flash_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl3238x_2m_flash_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_2m_flash_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) +``` + +**Build Software Version 2:** + +```bash +west build -p -b tl3238x -d build_tl3238x_2m_flash_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl3238x_2m_flash_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl3238x_2m_flash_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_2m_flash_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl3238x_2m_flash_lzma_v1/zephyr/merged.bin -> flash this +build_tl3238x_2m_flash_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl3238x_2m_flash_lzma_v2/zephyr/matter.ota -> OTA upgrade +``` + +## 3. 4MB Flash (Matter + Zigbee dual mode, no LZMA) + +**Prerequisite:** copy Zigbee firmware + +```bash +cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +e.g. +cp ${ZEPHYR_BASE}/TL323X_FW/ZB/dual_matter_sampleLight_bleAdv_tl323x.bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +``` + +**Kconfig:** boards/tl3238x_4m_flash_dual_mode_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=2 (auto-switch mode) + +**DTS Overlay:** src/platform/telink/tl3238x_4m_flash.overlay (default) + +- slot0: 0x16000, size 0x1E5000 (1940KB) +- slot1: 0x1FB000, size 0x1E5000 (1940KB) + +**Board DTS Overlay:** boards/tl3238x_for_TL3238C-EVK40D.overlay (explicitly +specified) + +- LED/Key definitions for TL3238C-EVK40D board + +**Build:** + +```bash +west build -p -b tl3238x -d build_tl3238x_4m_dual_mode -- \ +-DFLASH_SIZE=4m \ +-DCONF_FILE="prj.conf boards/tl3238x_4m_flash_dual_mode_ota.conf" \ +-DDTC_OVERLAY_FILE="boards/tl3238x_for_TL3238C-EVK40D.overlay" > build_tl3238x_4m_dual_mode.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_4m_flash_dual_mode_ota.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_4m_flash.overlay) + explicit (boards/tl3238x_for_TL3238C-EVK40D.overlay) +``` + +**Output:** + +```bash +build_tl3238x_4m_dual_mode/zephyr/merged.bin -> flash this (sboot+mcuboot+matter+zb) +build_tl3238x_4m_dual_mode/zephyr/merged_dfu.bin -> DFU over BLE SMP +build_tl3238x_4m_dual_mode/zephyr/matter.ota -> OTA upgrade +``` + +## 4. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) + +**This configuration will show a warning during build and may fail at link +time.** + +**Kconfig:** boards/tl3238x_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + +> "tl3238x with 2MB flash and OTA requires LZMA compression. Please use a config +> with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation +> anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 916KB (0xe5000) +partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. diff --git a/examples/lighting-app/telink/boards/tl3238x_for_TL3238C-EVK40D.overlay b/examples/lighting-app/telink/boards/tl3238x_for_TL3238C-EVK40D.overlay new file mode 100644 index 000000000000..73e34f91940c --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_for_TL3238C-EVK40D.overlay @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2026 Telink Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + led0 = &led_white; + led1 = &led_green; + led2 = &led_red; + led3 = &led_blue; + sw0 = &key_1; + sw1 = &key_2; + sw2 = &key_3; + sw3 = &key_4; + pwm-led0 = &pwm_led_blue; + mcuboot-button0 = &key_dfu; + mcuboot-led0 = &led_blue; + }; + + leds { + compatible = "gpio-leds"; + led_red: led_0 { + gpios = <&gpioa 4 0>; /* LEDR-PA4 */ + label = "LED Red"; + }; + led_blue: led_1 { + gpios = <&gpioa 2 0>; /* LEDB-PA2 */ + label = "LED Blue"; + }; + led_white: led_2 { + gpios = <&gpiob 7 0>; /* LEDW-PB7 */ + label = "LED White"; + }; + led_green: led_3 { + gpios = <&gpioa 3 0>; /* LEDG-PA3 */ + label = "LED Green"; + }; + }; + + keys { + compatible = "gpio-keys"; + key_1: button_1 { + label = "User KEY1"; + gpios = <&gpioc 3 11>; /* KEY1-PC3, GPIO_INPUT | GPIO_PULL_UP */ + }; + key_2: button_2 { + label = "User KEY2"; + gpios = <&gpioc 2 11>; /* KEY2-PC2, GPIO_INPUT | GPIO_PULL_UP */ + }; + key_3: button_3 { + label = "User KEY3"; + gpios = <&gpioc 1 11>; /* KEY3-PC1, GPIO_INPUT | GPIO_PULL_UP */ + }; + key_4: button_4 { + label = "User KEY4"; + gpios = <&gpioc 0 11>; /* KEY4-PC0, GPIO_INPUT | GPIO_PULL_UP */ + }; + key_dfu: button_dfu { + label = "USB DFU"; + gpios = <&gpioa 0 32>; /* keep previous DFU button set-up */ + }; + }; + + key_matrix { + compatible = "gpio-keys"; + col { + gpios = <&gpioc 2 0>, <&gpioc 3 0>; /* COL0-PC2, COL1-PC3 */ + }; + row { + gpios = <&gpioc 0 32>, <&gpioc 1 32>; /* ROW0-PC0, ROW1-PC1, GPIO_INPUT */ + }; + }; + + key_pool { + compatible = "gpio-keys"; + inp { + gpios = <&gpioc 0 11>, <&gpioc 1 11>, <&gpioc 2 11>, <&gpioc 3 11>; + }; + }; + + led_pool { + compatible = "gpio-leds"; + out { + gpios = <&gpiob 7 0>; /* LEDW-PB7 */ + }; + }; +}; \ No newline at end of file diff --git a/examples/lighting-app/telink/boards/tl3238x_ota.conf b/examples/lighting-app/telink/boards/tl3238x_ota.conf new file mode 100644 index 000000000000..6b3990f67630 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_ota.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl3238x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y + +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=y + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl5218x.conf b/examples/lighting-app/telink/boards/tl5218x.conf new file mode 100644 index 000000000000..429d436e4809 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl5218x.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=n + +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=n + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl5218x_2m_flash_ota_lzma.conf b/examples/lighting-app/telink/boards/tl5218x_2m_flash_ota_lzma.conf new file mode 100644 index 000000000000..b66c20bbf175 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl5218x_2m_flash_ota_lzma.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl5218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y + +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=y +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +# Enable ADC +CONFIG_ADC=n + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl5218x_4m_flash_dual_mode_ota.conf b/examples/lighting-app/telink/boards/tl5218x_4m_flash_dual_mode_ota.conf new file mode 100644 index 000000000000..0f7b11e86b64 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl5218x_4m_flash_dual_mode_ota.conf @@ -0,0 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl5218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +#compress ota +CONFIG_LZMA=n +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=n + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=2 diff --git a/examples/lighting-app/telink/boards/tl5218x_README.md b/examples/lighting-app/telink/boards/tl5218x_README.md new file mode 100644 index 000000000000..f1c09ebe5e91 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl5218x_README.md @@ -0,0 +1,140 @@ +# TL5218X Lighting App Build Guide + +## 1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) + +**Kconfig:** boards/tl5218x.conf (default) + +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be +upgraded + +**DTS Overlay:** src/platform/telink/tl5218x_2m_flash.overlay (default) + +- slot0: 0x15000, size 0xe7000 (924KB) +- slot1: 0xfc000, size 0xe7000 (924KB) + +**Build:** + +```bash +west build -p -b tl5218x -d build_tl5218x_default -- \ +> build_tl5218x_default.log +# Kconfig: default (boards/tl5218x.conf) +# DTS Overlay: default (src/platform/telink/tl5218x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl5218x_default/zephyr/zephyr.bin -> flash this +``` + +## 2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) + +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +**Kconfig:** boards/tl5218x_2m_flash_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=0 + +**DTS Overlay:** src/platform/telink/tl5218x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build Software Version 1:** + +```bash +west build -p -b tl5218x -d build_tl5218x_2m_flash_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl5218x_2m_flash_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl5218x_2m_flash_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_2m_flash_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) +``` + +**Build Software Version 2:** + +```bash +west build -p -b tl5218x -d build_tl5218x_2m_flash_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl5218x_2m_flash_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl5218x_2m_flash_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_2m_flash_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl5218x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl5218x_2m_flash_lzma_v1/zephyr/merged.bin -> flash this +build_tl5218x_2m_flash_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl5218x_2m_flash_lzma_v2/zephyr/matter.ota -> OTA upgrade +``` + +## 3. 4MB Flash (Matter + Zigbee dual mode, no LZMA) + +**Prerequisite:** copy Zigbee firmware + +```bash +cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +e.g. +cp ${ZEPHYR_BASE}/TL323X_FW/ZB/dual_matter_sampleLight_bleAdv_tl323x.bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin +``` + +**Kconfig:** boards/tl5218x_4m_flash_dual_mode_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=2 (auto-switch mode) + +**DTS Overlay:** src/platform/telink/tl5218x_4m_flash.overlay (default) + +- slot0: 0x16000, size 0x1E5000 (1940KB) +- slot1: 0x1FB000, size 0x1E5000 (1940KB) + +**Build:** + +```bash +west build -p -b tl5218x -d build_tl5218x_4m_dual_mode -- \ +-DFLASH_SIZE=4m \ +-DCONF_FILE="prj.conf boards/tl5218x_4m_flash_dual_mode_ota.conf" > build_tl5218x_4m_dual_mode.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl5218x_4m_flash_dual_mode_ota.conf") +# DTS Overlay: default (src/platform/telink/tl5218x_4m_flash.overlay) +``` + +**Output:** + +```bash +build_tl5218x_4m_dual_mode/zephyr/merged.bin -> flash this (sboot+mcuboot+matter+zb) +build_tl5218x_4m_dual_mode/zephyr/merged_dfu.bin -> DFU over BLE SMP +build_tl5218x_4m_dual_mode/zephyr/matter.ota -> OTA upgrade +``` + +## 4. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) + +**This configuration will show a warning during build and may fail at link +time.** + +**Kconfig:** boards/tl5218x_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + +> "tl5218x with 2MB flash and OTA requires LZMA compression. Please use a config +> with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation +> anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 924KB (0xe7000) +partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. diff --git a/examples/lighting-app/telink/boards/tl5218x_ota.conf b/examples/lighting-app/telink/boards/tl5218x_ota.conf new file mode 100644 index 000000000000..99490fa52a0c --- /dev/null +++ b/examples/lighting-app/telink/boards/tl5218x_ota.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl5218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y + +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=n + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl7218x.conf b/examples/lighting-app/telink/boards/tl7218x.conf new file mode 100644 index 000000000000..5b1ada1f66b4 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl7218x" + +# Disable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_DFU_OVER_BT_SMP=n +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=y +# Disable Telink-specific LZMA firmware decompression for bootloader +# This is not needed since Matter OTA is disabled (CONFIG_CHIP_OTA_REQUESTOR=n) +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=n + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl7218x_2m_flash_ota_lzma.conf b/examples/lighting-app/telink/boards/tl7218x_2m_flash_ota_lzma.conf new file mode 100644 index 000000000000..f21901de3ec6 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_2m_flash_ota_lzma.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl7218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y + +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=y +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=y + +# Enable ADC +CONFIG_ADC=n + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/boards/tl7218x_README.md b/examples/lighting-app/telink/boards/tl7218x_README.md new file mode 100644 index 000000000000..c536fa1a058f --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_README.md @@ -0,0 +1,103 @@ +# TL7218X Lighting App Build Guide + +## 1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) + +**Kconfig:** boards/tl7218x.conf (default) + +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_CHIP_DFU_OVER_BT_SMP=n, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration disables OTA, does not use MCUBoot, and cannot be +upgraded + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash.overlay (default) + +- slot0: 0x15000, size 0xe5000 (916KB) +- slot1: 0xfa000, size 0xe6000 (920KB) + +**Build:** + +```bash +west build -p -b tl7218x -d build_tl7218x_default -- \ +> build_tl7218x_default.log +# Kconfig: default (boards/tl7218x.conf) +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl7218x_default/zephyr/zephyr.bin -> flash this +``` + +## 2. 2MB Flash (Matter only, enable BT DFU, LZMA compressed, SW - 1 and 2) + +**IMPORTANT**: LZMA compression is REQUIRED for 2MB flash with OTA. + +**Kconfig:** boards/tl7218x_2m_flash_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y +- CONFIG_DUAL_MODE=0 + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash_lzma.overlay (default) + +- slot0: 0x15000, size 0x120000 (1152KB) +- slot1: 0x135000, size 0xAB000 (684KB) + +**Build Software Version 1:** + +```bash +west build -p -b tl7218x -d build_tl7218x_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_2m_flash_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl7218x_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_2m_flash_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) +``` + +**Build Software Version 2:** + +```bash +west build -p -b tl7218x -d build_tl7218x_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_2m_flash_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl7218x_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_2m_flash_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl7218x_lzma_v1/zephyr/merged.bin -> flash this +build_tl7218x_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl7218x_lzma_v2/zephyr/matter.ota -> OTA upgrade +``` + +## 3. WARNING: 2MB Flash with OTA but NO LZMA (NOT RECOMMENDED) + +**This configuration will show a warning during build and may fail at link +time.** + +**Kconfig:** boards/tl7218x_ota.conf (explicitly specified) + +- CONFIG_CHIP_OTA_REQUESTOR=y +- CONFIG_CHIP_DFU_OVER_BT_SMP=y, CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y, +- CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n +- CONFIG_DUAL_MODE=0 + +**WARNING**: Building this configuration will show a warning: + +> "tl7218x with 2MB flash and OTA requires LZMA compression. Please use a config +> with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation +> anyway..." + +**Note**: Build may fail at link time if firmware size exceeds 916KB (0xe5000) +partition limit. + +**Solution**: Use the LZMA-enabled configuration (target #2) instead. + +**Important Note**: TL7218X does NOT support dual_mode (Matter + Zigbee) +configuration. diff --git a/examples/lighting-app/telink/boards/tl7218x_ota.conf b/examples/lighting-app/telink/boards/tl7218x_ota.conf new file mode 100644 index 000000000000..854b59ab008d --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_ota.conf @@ -0,0 +1,22 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-tl7218x" + +# Enable Matter OTA DFU +CONFIG_CHIP_OTA_REQUESTOR=y + +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + +# LZMA compression library support +# Keep LZMA library enabled for potential general compression needs +CONFIG_LZMA=n +# Disable Telink-specific LZMA firmware decompression for bootloader +CONFIG_COMPRESS_LZMA=n + +# Enable ADC +CONFIG_ADC=n + +# matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button, light-switch-app +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as lighting-app by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=0 diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index d54ab61d181d..245b2cbb48dd 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -33,6 +33,7 @@ CONFIG_CHIP_OTA_REQUESTOR=n CONFIG_CHIP_DFU_OVER_BT_SMP=n CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight" CONFIG_TELINK_OTA_BUTTON_TEST=n # Disable CHIP shell support @@ -44,8 +45,23 @@ CONFIG_CHIP_FACTORY_DATA_BUILD=n CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n +# open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE +# init should be n +CONFIG_SECURE_PROGRAMMING=n + # Enable PWM CONFIG_PWM=y - +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=n + +# Enable Independent Button +CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE=n + +# Enable CHIP-ID via ble +CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n + +# Enable Deferred Store Attribute +CONFIG_DEFERRED_ATTR_STORAGE=n + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" diff --git a/examples/lock-app/telink/boards/tl5218x_retention.conf b/examples/lock-app/telink/boards/tl5218x_retention.conf new file mode 100644 index 000000000000..73253ec165ec --- /dev/null +++ b/examples/lock-app/telink/boards/tl5218x_retention.conf @@ -0,0 +1,9 @@ +#compress ota +CONFIG_LZMA=y +CONFIG_COMPRESS_LZMA=y + +#matter switch mode +# config NORMAL_MODE 0 independent matter mode +# ACTION_DUAL_MODE 1 matter action switch mode ,such as by button +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code. +CONFIG_DUAL_MODE=1 diff --git a/examples/lock-app/telink/prj.conf b/examples/lock-app/telink/prj.conf index 0180d1724522..26826848e3c7 100755 --- a/examples/lock-app/telink/prj.conf +++ b/examples/lock-app/telink/prj.conf @@ -42,3 +42,21 @@ CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n # Enable Power Management CONFIG_PM=y + +#ICD SETTING INFO +CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 +CONFIG_CHIP_ICD_FAST_POLLING_INTERVAL=200 +CONFIG_CHIP_ICD_ACTIVE_MODE_THRESHOLD=300 +CONFIG_CHIP_ICD_IDLE_MODE_DURATION=900 + +# open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE +# init should be n +CONFIG_SECURE_PROGRAMMING=n + +# Enable CHIP-ID via ble +CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n + +# Enable Deferred Store Attribute +CONFIG_DEFERRED_ATTR_STORAGE=n + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" diff --git a/examples/platform/telink/build_info.cmake b/examples/platform/telink/build_info.cmake index f6a7ccfaee34..32c695db51f4 100644 --- a/examples/platform/telink/build_info.cmake +++ b/examples/platform/telink/build_info.cmake @@ -109,12 +109,66 @@ else() set(TELINK_HAL_LOCAL_STATUS "") endif() +# OpenThread info +if(CONFIG_OPENTHREAD_TELINK_LIBRARY) + set(OPENTHREAD_PATH "${ZEPHYR_BASE}/../modules/lib/openthread_telink_lib") +else() + set(OPENTHREAD_PATH "${ZEPHYR_BASE}/../modules/lib/openthread") +endif() + +execute_process( + COMMAND git -C ${OPENTHREAD_PATH} rev-parse HEAD + OUTPUT_VARIABLE OT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +execute_process( + COMMAND git -C ${OPENTHREAD_PATH} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE OT_BRANCH_NAME + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +execute_process( + COMMAND git -C ${OPENTHREAD_PATH} show -s --format=%cd --date=format:%Y-%m-%d HEAD + OUTPUT_VARIABLE OT_COMMIT_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +execute_process( + COMMAND bash -c "git -C ${OPENTHREAD_PATH} remote get-url \$(git -C ${OPENTHREAD_PATH} remote | head -n 1)" + OUTPUT_VARIABLE OT_REMOTE_URL + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +execute_process( + COMMAND git -C ${OPENTHREAD_PATH} diff --quiet + RESULT_VARIABLE OT_LOCAL_STATUS + ERROR_QUIET +) + +if(OT_LOCAL_STATUS) + set(OT_LOCAL_STATUS "-dirty") +else() + set(OT_LOCAL_STATUS "") +endif() + execute_process( COMMAND git -C ${ZEPHYR_BASE}/../modules/hal/telink show -s --format=%cd --date=format:%Y-%m-%d OUTPUT_VARIABLE TELINK_HAL_COMMIT_DATE OUTPUT_STRIP_TRAILING_WHITESPACE ) +execute_process( + COMMAND git -C ${OPENTHREAD_PATH} describe --tags --exact-match + OUTPUT_VARIABLE OT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + target_compile_definitions(app PRIVATE MATTER_COMMIT_HASH="${MATTER_COMMIT_HASH}" MATTER_BRANCH="${MATTER_BRANCH_NAME}" @@ -132,6 +186,14 @@ target_compile_definitions(app PRIVATE TELINK_HAL_COMMIT_HASH="${TELINK_HAL_COMMIT_HASH}" TELINK_HAL_LOCAL_STATUS="${TELINK_HAL_LOCAL_STATUS}" TELINK_HAL_COMMIT_DATE="${TELINK_HAL_COMMIT_DATE}" + + OPENTHREAD_PATH="${OPENTHREAD_PATH}" + OT_COMMIT_HASH="${OT_COMMIT_HASH}" + OT_BRANCH="${OT_BRANCH_NAME}" + OT_COMMIT_DATE="${OT_COMMIT_DATE}" + OT_REMOTE_URL="${OT_REMOTE_URL}" + OT_LOCAL_STATUS="${OT_LOCAL_STATUS}" + OT_TAG="${OT_TAG}" ) message(STATUS "Matter revision:") @@ -146,3 +208,11 @@ message(STATUS " remote: ${ZEPHYR_REMOTE_URL}") message(STATUS "HAL revision:") message(STATUS " commit: ${TELINK_HAL_COMMIT_HASH} ${TELINK_HAL_COMMIT_DATE}") + +message(STATUS "OpenThread revision:") +message(STATUS " path: ${OPENTHREAD_PATH}") +message(STATUS " branch: ${OT_BRANCH_NAME} ${OT_COMMIT_HASH} ${OT_COMMIT_DATE}") +if(OT_TAG) + message(STATUS " tag: ${OT_TAG}") +endif() +message(STATUS " remote: ${OT_REMOTE_URL}") diff --git a/examples/platform/telink/common.cmake b/examples/platform/telink/common.cmake index 559e79fd4939..8493c165199d 100644 --- a/examples/platform/telink/common.cmake +++ b/examples/platform/telink/common.cmake @@ -126,7 +126,8 @@ else() unset(USB_CONF_OVERLAY_FILE) endif() -if(${CONFIG_COMPRESS_LZMA} MATCHES y) +# Check if there is any lzma conf file in CONF_FILE,or check CONFIG_COMPRESS_LZMA +if(("${CONF_FILE}" MATCHES "lzma") OR (${CONFIG_COMPRESS_LZMA} MATCHES y)) set(BOOT_CONF_OVERLAY_FILE "${CHIP_ROOT}/config/telink/app/bootloader_compress_lzma.conf") set(FLASH_LAYOUT_SUFFIX "_lzma") else() @@ -154,6 +155,12 @@ if(NOT EXISTS "${LOCAL_DTC_OVERLAY_FILE}") unset(LOCAL_DTC_OVERLAY_FILE) endif() +set(LOCAL_BOARD_CONF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.conf") +if(NOT EXISTS "${LOCAL_BOARD_CONF_FILE}") + message(STATUS "${LOCAL_BOARD_CONF_FILE} doesn't exist") + unset(LOCAL_BOARD_CONF_FILE) +endif() + set(GLOBAL_BOOT_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}.overlay") if(NOT EXISTS "${GLOBAL_BOOT_DTC_OVERLAY_FILE}") message(STATUS "${GLOBAL_BOOT_DTC_OVERLAY_FILE} doesn't exist") @@ -166,6 +173,15 @@ if(NOT EXISTS "${GLOBAL_DTC_OVERLAY_FILE}") unset(GLOBAL_DTC_OVERLAY_FILE) endif() +# Special check for tl3238x and tl7218x: 2MB flash with OTA requires LZMA compression +if(${BASE_BOARD} MATCHES "tl3238x" OR ${BASE_BOARD} MATCHES "tl5218x" OR ${BASE_BOARD} MATCHES "tl7218x") + if("${CONF_FILE}" MATCHES "_ota" AND "${FLASH_SIZE}" STREQUAL "2m" AND "${FLASH_LAYOUT_SUFFIX}" STREQUAL "") + # For 2MB flash with OTA, LZMA compression is required because firmware size may exceed 916KB (0xe5000) + message(WARNING "${BASE_BOARD} with 2MB flash and OTA requires LZMA compression. Please use a config with 'lzma' suffix and set CONFIG_COMPRESS_LZMA=y. Continuing compilation anyway...") + endif() +endif() + +# Always use overlay with FLASH_LAYOUT_SUFFIX, for all boards and configurations set(FLASH_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_${FLASH_SIZE}_flash${FLASH_LAYOUT_SUFFIX}.overlay") if(NOT EXISTS "${FLASH_DTC_OVERLAY_FILE}") message(STATUS "${FLASH_DTC_OVERLAY_FILE} doesn't exist") @@ -182,7 +198,7 @@ else() endif() if(NOT CONF_FILE) - set(CONF_FILE ${USB_CONF_OVERLAY_FILE} ${MARS_CONF_OVERLAY_FILE} ${ZEPHYR_VERSION_OVERLAY_FILE} prj.conf ${TFLM_CONF_OVERLAY_FILE} ${ML_CONF_OVERLAY_FILE}) +set(CONF_FILE ${USB_CONF_OVERLAY_FILE} ${MARS_CONF_OVERLAY_FILE} ${ZEPHYR_VERSION_OVERLAY_FILE} prj.conf ${TFLM_CONF_OVERLAY_FILE} ${ML_CONF_OVERLAY_FILE} ${LOCAL_BOARD_CONF_FILE}) endif() # Load NCS/Zephyr build system diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index 5ae561e522dc..f8d97ed5abd6 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -39,6 +39,31 @@ #include +#include +#include +#include + +#define OPCODE_FACTORY_RESET 0 +#define OPCODE_SWITCH_ZIGBEE 1 // include init state and matter paired state. +#define OPCODE_MATTER_PAIRED 2 + +#define DUAL_MODE_PARTITION dual_mode_partition +#define DUAL_MODE_PARTITION_DEVICE FIXED_PARTITION_DEVICE(DUAL_MODE_PARTITION) +#define DUAL_MODE_PARTITION_OFFSET FIXED_PARTITION_OFFSET(DUAL_MODE_PARTITION) +#define DUAL_MODE_PARTITION_SIZE FIXED_PARTITION_SIZE(DUAL_MODE_PARTITION) +// init mode will jump to matter +#define MODE_VAL_INIT 0xff + +// after matter paired , it will go to matter, only if trigger action. +#define MODE_VAL_MATTER_PAIR 0x55 +#define ACTION_SWITCH_ZIGBEE 0xaa + +// after zb paired , it will go to zb, only if trigger action. +#define MODE_VAL_ZB_PAIR 0xaa +#define ACTION_SWITCH_MATTER 0x55 + +void dual_mode_switch(uint32_t op); + using namespace ::chip; using namespace ::chip::app; using namespace ::chip::Credentials; @@ -112,7 +137,9 @@ class AppTaskCommon virtual void LinkPwms(PwmManager & pwmManager); void InitButtons(void); virtual void LinkButtons(ButtonManager & buttonManager); - +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + static void DnssTimerTimeoutCallback(k_timer * timer); +#endif static void FactoryResetTimerTimeoutCallback(k_timer * timer); static void FactoryResetTimerEventHandler(AppEvent * aEvent); static void FactoryResetButtonEventHandler(void); @@ -143,6 +170,8 @@ class AppTaskCommon static void UpdateStatusLED(void); + static void OtaEventsHandler(const ChipDeviceEvent * event); + #if CONFIG_CHIP_FACTORY_DATA chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; #endif diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 7743fa8262d5..be53597816ef 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -27,6 +27,7 @@ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include "ThreadUtil.h" +#include #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI #include #include @@ -35,6 +36,11 @@ #include #include #include +#if CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS +#include +#include +#include +#endif #include #include #include @@ -61,6 +67,9 @@ bool AppTaskCommon::sIsCommissioningFailed = false; #include "Reboot.h" #include +#include +#include +#include #if defined(CONFIG_PM) && !defined(CONFIG_CHIP_ENABLE_PM_DURING_BLE) #include @@ -97,6 +106,190 @@ bool sIsNetworkEnabled = false; bool sIsNetworkAttached = false; bool sHaveBLEConnections = false; +#if CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS +/** + * @brief Set deferred attributes storage + * + * @see Define a custom attribute persister which makes actual write of the CurrentHue, CurrentSaturation, CurrentLevel attributes + * value to the non-volatile storage only when it has remained constant for 5 seconds. This is to reduce the flash wearout when the + * attribute changes frequently as a result of MoveToLevel command. DeferredAttribute object describes a deferred attribute, but + * also holds a buffer with a value to be written, so it must live so long as the DeferredAttributePersistenceProvider object. + * + * @param ATTRIBUTES_ARRAY_SIZE The lenght of the DeferredAttribute array + * @param DEFERRED_STORAGE_TIME The deferred time(ms) to store attributes + */ +#define ATTRIBUTES_ARRAY_SIZE (3U) +#define DEFERRED_STORAGE_TIME (500U) + +DeferredAttribute gPersisters[] = { +#if CONFIG_DEFERRED_ATTR_STORAGE + DeferredAttribute( + ConcreteAttributePath(kExampleEndpointId, Clusters::ColorControl::Id, Clusters::ColorControl::Attributes::CurrentHue::Id)), + DeferredAttribute(ConcreteAttributePath(kExampleEndpointId, Clusters::ColorControl::Id, + Clusters::ColorControl::Attributes::CurrentSaturation::Id)), + DeferredAttribute( + ConcreteAttributePath(kExampleEndpointId, Clusters::LevelControl::Id, Clusters::LevelControl::Attributes::CurrentLevel::Id)) +#endif // CONFIG_DEFERRED_ATTR_STORAGE +}; + +// Deferred persistence will be auto-initialized as soon as the default persistence is initialized +DefaultAttributePersistenceProvider gSimpleAttributePersistence; +DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttributePersistence, + Span(gPersisters, ATTRIBUTES_ARRAY_SIZE), + System::Clock::Milliseconds32(DEFERRED_STORAGE_TIME)); + +#endif + +#if CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL521X +#include +#endif /* CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL521X */ +#include +#include +#include + +/*MATTER NVS*/ +#define MATTER_NVS_PARTITION storage_partition +#define MATTER_NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(MATTER_NVS_PARTITION) +#define MATTER_NVS_PARTITION_OFFSET FIXED_PARTITION_OFFSET(MATTER_NVS_PARTITION) +#define MATTER_NVS_PARTITION_SIZE FIXED_PARTITION_SIZE(MATTER_NVS_PARTITION) +const struct device * matter_nvs_dev = MATTER_NVS_PARTITION_DEVICE; + +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE || CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE +#define OPCODE_FACTORY_RESET 0 +#define OPCODE_SWITCH_ZIGBEE 1 // include init state and matter paired state. +#define OPCODE_MATTER_PAIRED 2 + +#define DUAL_MODE_PARTITION dual_mode_partition +#define DUAL_MODE_PARTITION_DEVICE FIXED_PARTITION_DEVICE(DUAL_MODE_PARTITION) +#define DUAL_MODE_PARTITION_OFFSET FIXED_PARTITION_OFFSET(DUAL_MODE_PARTITION) +#define DUAL_MODE_PARTITION_SIZE FIXED_PARTITION_SIZE(DUAL_MODE_PARTITION) +// init mode will jump to matter +#define MODE_VAL_INIT 0xff + +// after matter paired , it will go to matter, only if trigger action. +#define MODE_VAL_MATTER_PAIR 0x55 +#define ACTION_SWITCH_ZIGBEE 0xaa + +// after zb paired , it will go to zb, only if trigger action. +#define MODE_VAL_ZB_PAIR 0xaa +#define ACTION_SWITCH_MATTER 0x55 +#endif + +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE +void dual_mode_switch(int32_t op) +{ + uint8_t boot_flag[2] = { 0xff, 0xff }; + const struct device * flash_para_dev = DUAL_MODE_PARTITION_DEVICE; + + flash_read(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, boot_flag, 2); + + if (op == OPCODE_FACTORY_RESET) + { + boot_flag[0] = MODE_VAL_INIT; + boot_flag[1] = MODE_VAL_INIT; + } + else if (op == OPCODE_SWITCH_ZIGBEE) + { + boot_flag[1] = ACTION_SWITCH_ZIGBEE; + } + else if (op == OPCODE_MATTER_PAIRED) + { + boot_flag[0] = MODE_VAL_MATTER_PAIR; + boot_flag[1] = MODE_VAL_INIT; + } + flash_erase(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, 4096); + flash_write(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, boot_flag, sizeof(boot_flag)); + + // need to reboot ,switch to bootloader + if (op == OPCODE_SWITCH_ZIGBEE) + { + sys_reboot(SYS_REBOOT_WARM); + } +} + +#elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE +//#include + +#define USER_MATTER_BACK_ZB 0xa0 // only commisiion fail will back to zb +#define USER_ZB_SW_VAL 0xaa + +typedef struct{ + uint8_t val; + uint8_t on_net; +} user_para_t; + +uint8_t sBoot_zb = 0; +user_para_t user_para; + +#define ZB_NVS_PARTITION zigbee_nvs_partition +#define ZB_NVS_SEC_SIZE FIXED_PARTITION_SIZE(ZB_NVS_PARTITION) + +#define ZB_NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(ZB_NVS_PARTITION) +#define ZB_NVS_START_ADR FIXED_PARTITION_OFFSET(ZB_NVS_PARTITION) + +const struct device * flash_para_dev = DUAL_MODE_PARTITION_DEVICE; +const struct device * zb_para_dev = ZB_NVS_PARTITION_DEVICE; +constexpr int kDnssTimeout = 60000; + +#if !CONFIG_MCUMGR_TRANSPORT_BT +static k_timer sDnssTimer; // create when dfu disable +#endif /* !CONFIG_MCUMGR_TRANSPORT_BT */ + +void FactoryResetExtHandler(void) +{ + // Erase the user parameters partition to reset mode settings + flash_erase(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, DUAL_MODE_PARTITION_SIZE); + // Erase ZigBee NVS data during factory reset + flash_erase(zb_para_dev, ZB_NVS_START_ADR, ZB_NVS_SEC_SIZE); +} + +uint8_t dual_mode_switch_from_zb() +{ + flash_read(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, &user_para, sizeof(user_para)); + if (user_para.val == USER_ZB_SW_VAL) + { + return 1; + } + else + { + return 0; + } +} + +void dual_mode_auto_switch(int32_t op) +{ + uint8_t boot_flag = 0xff; + const struct device * flash_para_dev = DUAL_MODE_PARTITION_DEVICE; + + flash_read(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, &boot_flag, 1); + + if (op == OPCODE_FACTORY_RESET) + { + FactoryResetExtHandler(); + } + else if (op == OPCODE_SWITCH_ZIGBEE) + { + /*if commission fail should keep the state of others , directly write from 0xAA to 0xA0*/ + boot_flag = USER_MATTER_BACK_ZB; + flash_write(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, &boot_flag, sizeof(boot_flag)); + } + else if (op == OPCODE_MATTER_PAIRED) + { + boot_flag = MODE_VAL_MATTER_PAIR; + flash_erase(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, 4096); + flash_write(flash_para_dev, DUAL_MODE_PARTITION_OFFSET, &boot_flag, sizeof(boot_flag)); + } + + // need to reboot ,switch to bootloader + if (op == OPCODE_SWITCH_ZIGBEE) + { + // clear matter nvs for unclean info in matter nvs + flash_erase(matter_nvs_dev, MATTER_NVS_PARTITION_OFFSET, MATTER_NVS_PARTITION_SIZE); + sys_reboot(SYS_REBOOT_WARM); + } +} +#endif /* CONFIG_DUAL_MODE */ + #if APP_SET_DEVICE_INFO_PROVIDER chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; #endif @@ -187,6 +380,62 @@ void AppTaskCommon::PowerOnFactoryReset(void) } #endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */ +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE +void AppTaskCommon::DnssTimerTimeoutCallback(k_timer * timer) +{ + if (!timer) + { + return; + } + /* + * If Dnss initialization takes longer than 60 seconds, + * the device will reboot and revert to Zigbee mode. + */ + if (sBoot_zb) + { + printk("Matter: DnssTimer expired. Rebooting...\n"); + dual_mode_auto_switch(OPCODE_SWITCH_ZIGBEE); + } +} +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +static void DoDelayedFactoryReset(struct k_work * work) +{ + chip::Server::GetInstance().ScheduleFactoryReset(); +}; + +static k_work_delayable sDelayedFactoryResetWork = \ + Z_WORK_DELAYABLE_INITIALIZER(DoDelayedFactoryReset); + +static void PowerOnNetworkCheck(void) +{ + Thread::OperationalDataset curDataset; + CHIP_ERROR err = DeviceLayer::ThreadStackMgrImpl().GetThreadProvision(curDataset); + bool hasDataset = (err == CHIP_NO_ERROR); // Check if stored OpenThread dataset + + uint8_t fabricNum = chip::Server::GetInstance().GetFabricTable().FabricCount(); + + if (!hasDataset && fabricNum == 0) + { // New device + return; + } + else if (hasDataset && fabricNum > 0) + { // Device successfully commissioned + return; + } + else if (hasDataset && fabricNum == 0) + { + ChipLogProgress(DeviceLayer, "Thread dataset exists, but matter uncommissioned\n"); + } + else + { + return; + } + k_work_schedule(&sDelayedFactoryResetWork, K_SECONDS(2)); +} +#endif + CHIP_ERROR AppTaskCommon::StartApp(void) { CHIP_ERROR err = GetAppTask().Init(); @@ -197,6 +446,15 @@ CHIP_ERROR AppTaskCommon::StartApp(void) return err; } +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + if(dual_mode_switch_from_zb()){ + sBoot_zb = 1; + k_timer_init(&sDnssTimer, &DnssTimerTimeoutCallback, nullptr); + k_timer_start(&sDnssTimer, K_MSEC(kDnssTimeout), K_NO_WAIT); + printk("Matter: Started DNS protection timer."); + } +#endif + AppEvent event = {}; #if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE @@ -245,6 +503,15 @@ void AppTaskCommon::PrintFirmwareInfo(void) LOG_DBG("\t branch: %s %.8s%s %s", ZEPHYR_BRANCH, ZEPHYR_COMMIT_HASH, ZEPHYR_LOCAL_STATUS, ZEPHYR_COMMIT_DATE); LOG_DBG("\t remote: %s", ZEPHYR_REMOTE_URL); LOG_DBG("\t HAL commit: %.8s%s %s", TELINK_HAL_COMMIT_HASH, TELINK_HAL_LOCAL_STATUS, TELINK_HAL_COMMIT_DATE); + + LOG_DBG("OpenThread revision: "); + LOG_DBG("\t path: %s", OPENTHREAD_PATH); + LOG_DBG("\t remote: %s", OT_REMOTE_URL); + if (strlen(OT_TAG) > 0) + { + LOG_DBG("\t tag: %s", OT_TAG); + } + LOG_DBG("\t branch: %s %.8s%s %s", OT_BRANCH, OT_COMMIT_HASH, OT_LOCAL_STATUS, OT_COMMIT_DATE); #endif } @@ -294,6 +561,9 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR); #endif LogErrorOnFailure(initParams.InitializeStaticResourcesBeforeServerInit()); +#if CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS + VerifyOrDie(gSimpleAttributePersistence.Init(initParams.persistentStorageDelegate) == CHIP_NO_ERROR); +#endif #if APP_SET_DEVICE_INFO_PROVIDER gExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); @@ -310,6 +580,11 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); +#if CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS + /* Add deferred storage attribute for provider */ + app::SetAttributePersistenceProvider(&gDeferredAttributePersister); +#endif + ConfigurationMgr().LogDeviceConfig(); PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); @@ -342,6 +617,11 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) // between the main and the CHIP threads. LogErrorOnFailure(PlatformMgr().AddEventHandler(ChipEventHandler, 0)); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + // TODO: Defer this validation until chip::Server is fully initialized to avoid crashes + PowerOnNetworkCheck(); +#endif + return CHIP_NO_ERROR; } @@ -543,6 +823,14 @@ void AppTaskCommon::StartBleAdvButtonEventHandler(void) void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) { + // This will change the function of the start BLE adv button + // to manually switch to Zigbee firmware and run another firmware, + // which overrides the original function. +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE + LOG_INF("switch to Zigbee Mode"); + dual_mode_switch(OPCODE_SWITCH_ZIGBEE); +#endif + LOG_INF("StartBleAdvHandler"); // Disable manual Matter service BLE advertising after device provisioning. @@ -589,7 +877,15 @@ void AppTaskCommon::FactoryResetHandler(AppEvent * aEvent) k_timer_stop(&sFactoryResetTimer); sFactoryResetCntr = 0; - chip::Server::GetInstance().ScheduleFactoryReset(); +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE + dual_mode_switch(OPCODE_FACTORY_RESET); +#elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + dual_mode_auto_switch(OPCODE_FACTORY_RESET); +#endif + /* clear matter nvs for unclean info in matter nvs */ + LOG_INF("Factory Reset TC: Erase matter nvs directly and reboot"); + flash_erase(matter_nvs_dev, MATTER_NVS_PARTITION_OFFSET, MATTER_NVS_PARTITION_SIZE); + sys_reboot(SYS_REBOOT_WARM); } } @@ -730,6 +1026,36 @@ void AppTaskCommon::TriggerMicroSpeechEventHandler(AppEvent * aEvent) } #endif +void AppTaskCommon::OtaEventsHandler(const ChipDeviceEvent * event) +{ + switch (event->OtaStateChanged.newState) + { + case DeviceLayer::kOtaDownloadInProgress: + ChipLogProgress(DeviceLayer, "OTA image download in progress\n"); + break; + case DeviceLayer::kOtaDownloadComplete: + ChipLogProgress(DeviceLayer, "OTA image download complete\n"); + break; + case DeviceLayer::kOtaDownloadFailed: + ChipLogProgress(DeviceLayer, "OTA image download failed\n"); + break; + case DeviceLayer::kOtaDownloadAborted: + ChipLogProgress(DeviceLayer, "OTA image download aborted\n"); + break; + case DeviceLayer::kOtaApplyInProgress: + ChipLogProgress(DeviceLayer, "OTA image apply in progress\n"); + break; + case DeviceLayer::kOtaApplyComplete: + ChipLogProgress(DeviceLayer, "OTA image apply complete\n"); + break; + case DeviceLayer::kOtaApplyFailed: + ChipLogProgress(DeviceLayer, "OTA image apply failed\n"); + break; + default: + break; + } +} + void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* arg */) { switch (event->Type) @@ -797,6 +1123,31 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* #endif } break; + case DeviceEventType::kCommissioningComplete: +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE + dual_mode_switch(OPCODE_MATTER_PAIRED); +#elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + /* clear boot from zigbee after commission*/ + sBoot_zb = 0; + dual_mode_auto_switch(OPCODE_MATTER_PAIRED); +#endif + printk("Commissioning complete; Matter commissioned flag set.\n"); + break; + + case DeviceEventType::kFailSafeTimerExpired: +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + /* Reset to Zigbee mode if commissioning fails */ + if (sBoot_zb) + { + dual_mode_auto_switch(OPCODE_SWITCH_ZIGBEE); + printk("FailSafeTimer expired; Matter commissioning failed. Rebooting to Zigbee mode...\n"); + } + else +#endif + { + printk("FailSafeTimer expired; Matter commissioning failed.\n"); + } + break; #if CHIP_DEVICE_CONFIG_ENABLE_THREAD case DeviceEventType::kDnssdInitialized: #if CONFIG_CHIP_OTA_REQUESTOR @@ -809,6 +1160,13 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* #endif /* CONFIG_BOOTLOADER_MCUBOOT */ #if CONFIG_CHIP_OTA_REQUESTOR } +#endif +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + if (sBoot_zb) + { + k_timer_stop(&sDnssTimer); + printk("DnssTimer stopped; DNS-SD has been initialized.\n"); + } #endif break; case DeviceEventType::kThreadStateChange: @@ -855,6 +1213,9 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* UpdateStatusLED(); #endif break; + case DeviceEventType::kOtaStateChanged: + AppTaskCommon::OtaEventsHandler(event); + break; default: break; } diff --git a/examples/platform/telink/project_include/OpenThreadConfig.h b/examples/platform/telink/project_include/OpenThreadConfig.h index 0e23617e28e2..267106b25c25 100644 --- a/examples/platform/telink/project_include/OpenThreadConfig.h +++ b/examples/platform/telink/project_include/OpenThreadConfig.h @@ -27,13 +27,14 @@ /* Number of message buffers reduced to save RAM */ #undef OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS -#if CONFIG_PM || CONFIG_SOC_RISCV_TELINK_TL321X +#if CONFIG_PM || CONFIG_SOC_RISCV_TELINK_TL321X || CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL721X || \ + CONFIG_SOC_RISCV_TELINK_TL521X #define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 22 #else #define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 44 #endif -#if CONFIG_SOC_RISCV_TELINK_TL321X +#if CONFIG_SOC_RISCV_TELINK_TL321X || CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL521X #undef OPENTHREAD_CONFIG_MLE_MAX_CHILDREN #define OPENTHREAD_CONFIG_MLE_MAX_CHILDREN 5 #endif diff --git a/examples/platform/telink/util/include/DFUOverSMP.h b/examples/platform/telink/util/include/DFUOverSMP.h index cc99422f935e..8293e2ac7db3 100644 --- a/examples/platform/telink/util/include/DFUOverSMP.h +++ b/examples/platform/telink/util/include/DFUOverSMP.h @@ -27,6 +27,16 @@ #include #include +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE +#ifdef __cplusplus +extern "C" { +#endif +extern struct k_timer sDnssTimer; +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* CONFIG_AUTO_SWITCH_DUAL_MODE */ + enum VerificationFailReason : unsigned char { NO_FAIL = 0, diff --git a/examples/platform/telink/util/include/FabricTableDelegate.h b/examples/platform/telink/util/include/FabricTableDelegate.h index 44f78fafb52a..818b3c29a2b7 100644 --- a/examples/platform/telink/util/include/FabricTableDelegate.h +++ b/examples/platform/telink/util/include/FabricTableDelegate.h @@ -57,6 +57,26 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate server.GetCommissioningWindowManager().CloseCommissioningWindow(); } + #define DUAL_MODE_PARTITION dual_mode_partition + #define DUAL_MODE_PARTITION_DEVICE FIXED_PARTITION_DEVICE(DUAL_MODE_PARTITION) + #define DUAL_MODE_PARTITION_OFFSET FIXED_PARTITION_OFFSET(DUAL_MODE_PARTITION) + #define DUAL_MODE_PARTITION_SIZE FIXED_PARTITION_SIZE(DUAL_MODE_PARTITION) + +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE + uint8_t boot_flag[2] = { 0xff, 0xff }; + flash_erase(DUAL_MODE_PARTITION_DEVICE, DUAL_MODE_PARTITION_OFFSET, 4096); + flash_write(DUAL_MODE_PARTITION_DEVICE, DUAL_MODE_PARTITION_OFFSET, boot_flag, sizeof(boot_flag)); +#elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + #define ZB_NVS_PARTITION zigbee_nvs_partition + #define ZB_NVS_SEC_SIZE FIXED_PARTITION_SIZE(ZB_NVS_PARTITION) + #define ZB_NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(ZB_NVS_PARTITION) + #define ZB_NVS_START_ADR FIXED_PARTITION_OFFSET(ZB_NVS_PARTITION) + + // Erase the user parameters partition to reset mode settings + flash_erase(DUAL_MODE_PARTITION_DEVICE, DUAL_MODE_PARTITION_OFFSET, DUAL_MODE_PARTITION_SIZE); + // Erase ZigBee NVS data during factory reset + flash_erase(ZB_NVS_PARTITION_DEVICE, ZB_NVS_START_ADR, ZB_NVS_SEC_SIZE); +#endif k_timer_start(&sFabricRemovedTimer, K_MSEC(CONFIG_CHIP_LAST_FABRIC_REMOVED_ACTION_DELAY), K_NO_WAIT); } #endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE diff --git a/examples/platform/telink/util/src/DFUOverSMP.cpp b/examples/platform/telink/util/src/DFUOverSMP.cpp index a0a5ef2c5a56..0448eb99b3ba 100644 --- a/examples/platform/telink/util/src/DFUOverSMP.cpp +++ b/examples/platform/telink/util/src/DFUOverSMP.cpp @@ -24,6 +24,8 @@ #include "OTAUtil.h" #include "Reboot.h" +#include + #include #include @@ -36,6 +38,17 @@ LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE +#ifdef __cplusplus +extern "C" { +#endif +struct k_timer sDnssTimer; +static volatile bool canlTimerFlag = false; +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* CONFIG_AUTO_SWITCH_DUAL_MODE */ + static void reboot_work_handler(struct k_work * work) { LOG_INF("[DFU] Start reboot!"); @@ -55,6 +68,13 @@ int UploadProgressHandler(uint32_t event, int32_t rc, bool * abort_more, void * #endif { +#if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE + if (!canlTimerFlag) { + k_timer_stop(&sDnssTimer); + canlTimerFlag = true; + LOG_INF("[Telink] DnssTimer stopped; DFU-OTA Handler.\n"); + } +#endif /* CONFIG_AUTO_SWITCH_DUAL_MODE */ const img_mgmt_upload_check & imgData = *static_cast(data); LOG_INF("[DFU] DFU over SMP progress: %u/%u B of image %u", static_cast(imgData.req->off), diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index da113279f7b8..0af3153072ab 100644 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -846,6 +846,10 @@ def BuildTelinkTarget(): TargetPart('tl3218x', board=TelinkBoard.TL3218X), TargetPart('tl3218x_ml3m', board=TelinkBoard.TL3218X_ML3M), TargetPart('tl3218x_retention', board=TelinkBoard.TL3218X_RETENTION), + TargetPart('tl3238x', board=TelinkBoard.TL3238X), + TargetPart('tl3238x_retention', board=TelinkBoard.TL3238X_RETENTION), + TargetPart('tl5218x', board=TelinkBoard.TL5218X), + TargetPart('tl5218x_retention', board=TelinkBoard.TL5218X_RETENTION), TargetPart('tl7218x', board=TelinkBoard.TL7218X), TargetPart('tl7218x_ml7g', board=TelinkBoard.TL7218X_ML7G), TargetPart('tl7218x_ml7m', board=TelinkBoard.TL7218X_ML7M), @@ -900,6 +904,7 @@ def BuildTelinkTarget(): target.AppendModifier("log-error", log_level=TelinkLogLevel.ERROR).ExceptIfRe("-log-(progress|all|none)") target.AppendModifier("log-none", log_level=TelinkLogLevel.NONE).ExceptIfRe("-log-(progress|error|all)") target.AppendModifier("log-all", log_level=TelinkLogLevel.ALL).ExceptIfRe("-log-(progress|error|none)") + target.AppendModifier('dual-mode', dual_mode_config=0) return target diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index 22ea0a37268d..a870133400fb 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -136,6 +136,10 @@ class TelinkBoard(Enum): TL3218X = auto() TL3218X_ML3M = auto() TL3218X_RETENTION = auto() + TL3238X = auto() + TL3238X_RETENTION = auto() + TL5218X = auto() + TL5218X_RETENTION = auto() TL7218X = auto() TL7218X_ML7G = auto() TL7218X_ML7M = auto() @@ -156,6 +160,14 @@ def GnArgName(self): return 'tl3218x_ml3m' if self == TelinkBoard.TL3218X_RETENTION: return 'tl3218x_retention' + if self == TelinkBoard.TL3238X: + return 'tl3238x' + if self == TelinkBoard.TL3238X_RETENTION: + return 'tl3238x_retention' + if self == TelinkBoard.TL5218X: + return 'tl5218x' + if self == TelinkBoard.TL5218X_RETENTION: + return 'tl5218x_retention' if self == TelinkBoard.TL7218X: return 'tl7218x' if self == TelinkBoard.TL7218X_ML7G: @@ -190,6 +202,7 @@ def __init__(self, chip_enable_nfc_onboarding_payload: bool = False, log_level: TelinkLogLevel = TelinkLogLevel.DEFAULT, all_devices_enabled_devices=None, + dual_mode_config: int = 0, ): super().__init__(root, runner, output_dir_lock) self.app = app @@ -208,6 +221,7 @@ def __init__(self, self.tflm_config = tflm_config self.chip_enable_nfc_onboarding_payload = chip_enable_nfc_onboarding_payload self.log_level = log_level + self.dual_mode_config = dual_mode_config self.all_devices_enabled_devices = all_devices_enabled_devices or [] def get_cmd_prefixes(self): @@ -268,6 +282,9 @@ def generate(self): if self.tflm_config: flags.append("-DCONFIG_TFLM_FEATURE=y") + if self.dual_mode_config: + flags.append("-DCONFIG_DUAL_MODE=0") + if self.options.pregen_dir: flags.append(f"-DCHIP_CODEGEN_PREGEN_DIR={shlex.quote(self.options.pregen_dir)}") diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index a30d6ecb4a20..84532dc2006a 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -21,4 +21,4 @@ qpg-qpg6200-{light,light-switch,lock,persistent-storage,shell,thermostat}[-updat realtek-{rtl8777g,rtl87x2g}-{all-clusters,light-switch,lighting,lock,ota-requestor,thermostat,window} stm32-stm32wb5mm-dk-light tizen-{arm,arm64}-{all-clusters,chip-tool,light,tests}[-asan][-coverage][-no-ble][-no-thread][-no-wifi][-ubsan][-with-ui] -telink-{tl3218x,tl3218x_ml3m,tl3218x_retention,tl7218x,tl7218x_ml7g,tl7218x_ml7m,tl7218x_retention,tlsr9118bdk40d,tlsr9518adk80d,tlsr9528a,tlsr9528a_retention}-{air-quality-sensor,all-clusters,all-clusters-minimal,all-devices,all-devices-aggregator,all-devices-air-purifier,all-devices-bridged-node,all-devices-chime,all-devices-contact-sensor,all-devices-cooktop,all-devices-device-energy-management,all-devices-dimmable-light,all-devices-dimmable-plug-in-unit,all-devices-dishwasher,all-devices-extractor-hood,all-devices-fan,all-devices-flow-sensor,all-devices-generic-switch,all-devices-humidity-sensor,all-devices-laundry-dryer,all-devices-laundry-washer,all-devices-light-sensor,all-devices-microwave-oven,all-devices-mounted-dimmable-load-control,all-devices-mounted-on-off-control,all-devices-occupancy-sensor,all-devices-on-off-light,all-devices-on-off-light-switch,all-devices-on-off-plug-in-unit,all-devices-oven,all-devices-power-source,all-devices-pressure-sensor,all-devices-proximity-ranger,all-devices-rain-sensor,all-devices-refrigerator,all-devices-robotic-vacuum-cleaner,all-devices-soil-sensor,all-devices-speaker,all-devices-temperature-sensor,all-devices-water-freeze-detector,all-devices-water-leak-detector,all-devices-water-valve,bridge,contact-sensor,light,light-switch,lock,ota-requestor,pump,pump-controller,shell,smoke-co-alarm,temperature-measurement,thermostat,window-covering}[-4mb][-compress-lzma][-dfu-smp][-factory-data][-log-all][-log-error][-log-none][-log-progress][-mars][-nfc-payload][-ota][-precompiled-ot][-rpc][-shell][-tflm][-thread-analyzer][-usb] +telink-{tl3218x,tl3218x_ml3m,tl3218x_retention,tl3238x,tl3238x_ml3m,tl3238x_retention,tl5218x,tl5218x_ml3m,tl5218x_retention,tl7218x,tl7218x_ml7g,tl7218x_ml7m,tl7218x_retention,tlsr9118bdk40d,tlsr9518adk80d,tlsr9528a,tlsr9528a_retention}-{air-quality-sensor,all-clusters,all-clusters-minimal,all-devices,all-devices-aggregator,all-devices-air-purifier,all-devices-bridged-node,all-devices-chime,all-devices-contact-sensor,all-devices-cooktop,all-devices-device-energy-management,all-devices-dimmable-light,all-devices-dimmable-plug-in-unit,all-devices-dishwasher,all-devices-extractor-hood,all-devices-fan,all-devices-flow-sensor,all-devices-generic-switch,all-devices-humidity-sensor,all-devices-laundry-dryer,all-devices-laundry-washer,all-devices-light-sensor,all-devices-microwave-oven,all-devices-mounted-dimmable-load-control,all-devices-mounted-on-off-control,all-devices-occupancy-sensor,all-devices-on-off-light,all-devices-on-off-light-switch,all-devices-on-off-plug-in-unit,all-devices-oven,all-devices-power-source,all-devices-pressure-sensor,all-devices-proximity-ranger,all-devices-rain-sensor,all-devices-refrigerator,all-devices-robotic-vacuum-cleaner,all-devices-soil-sensor,all-devices-speaker,all-devices-temperature-sensor,all-devices-water-freeze-detector,all-devices-water-leak-detector,all-devices-water-valve,bridge,contact-sensor,light,light-switch,lock,ota-requestor,pump,pump-controller,shell,smoke-co-alarm,temperature-measurement,thermostat,window-covering}[-4mb][-compress-lzma][-dfu][-dfu-smp][-dual-mode][-factory-data][-log-all][-log-error][-log-none][-log-progress][-mars][-nfc-payload][-ota][-precompiled-ot][-rpc][-shell][-tflm][-thread-analyzer][-usb] diff --git a/scripts/tools/telink/manual_process.py b/scripts/tools/telink/manual_process.py new file mode 100644 index 000000000000..970b9bd51320 --- /dev/null +++ b/scripts/tools/telink/manual_process.py @@ -0,0 +1,701 @@ +#!/usr/bin/env python3 +""" +Matter Telink Manual Firmware Processing Tool +Location: scripts/tools/telink/manual_process.py +Co-located with process_binaries.py for consistent project structure + +This script manually executes the complete firmware processing pipeline, +fully reusing existing project logic. All generated files are prefixed +with 'manual_' to avoid conflicts with automated build outputs. + +=== Usage Examples === + +Usage 1 (process raw firmware, full pipeline): + python3 manual_process.py zephyr.bin [--output-dir OUTPUT_DIR] + Example: + python3 manual_process.py \\ + /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/zephyr.bin \\ + /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/.config + +Usage 2 (process already signed firmware, start from compression): + python3 manual_process.py zephyr.signed.bin --already-signed + Example: + python3 manual_process.py \\ + /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/zephyr.signed.bin \\ + /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/.config --already-signed + +Usage 3 (with manual parameters, no .config file needed): + python3 manual_process.py [--output-dir OUTPUT_DIR] \\ + --rom-start-offset 512 --flash-load-size 1179648 \\ + --lzma-dict-size 32768 --signing-key bootloader/mcuboot/root-rsa-2048.pem \\ + --vendor-id 65521 --product-id 32772 [--already-signed] + +Usage 4 (only LZMA compression, single step): + python3 manual_process.py input.signed.bin --only-lzma --output-dir ./output --lzma-dict-size 32768 + +Usage 5 (4MB Flash chips: tlsr9528a/tlsr9268j/tlsr9268m, simplified pipeline): + python3 manual_process.py zephyr.bin --chip-family tlsr9528a + This executes only 2 steps: zephyr.bin -> zephyr.signed.bin -> matter.ota (skips LZMA) + +Processing Steps: +1. Input firmware -> manual_zephyr.signed.bin (First MCUBoot signature) +2. manual_zephyr.signed.bin -> manual_zephyr.signed.lzma.bin (LZMA compression) +3. manual_zephyr.signed.lzma.bin -> manual_zephyr.signed.lzma.signed.bin (Second MCUBoot signature) +4. manual_zephyr.signed.lzma.signed.bin -> manual_matter.ota (Final Matter OTA package) + +Manual step-by-step execution (for debugging): +If you want to manually execute each step of the pipeline, here are the exact commands: + +1. First MCUBoot signature (zephyr.bin -> manual_zephyr.signed.bin): + + python3 /home/ubuntu/zephyrproject/bootloader/mcuboot/scripts/imgtool.py sign \ + --version 0.0.0+0 \ + --align 1 \ + --header-size 512 \ + --slot-size 1179648 \ + --key /home/ubuntu/zephyrproject/bootloader/mcuboot/ecdsa_private_key.pem \ + ./zephyr.bin \ + ./output/manual_zephyr.signed.bin + +2. LZMA compression (manual_zephyr.signed.bin -> manual_zephyr.signed.lzma.bin): + +2.1 Manual method using Python directly + + python3 << 'EOF' + import lzma + import os + + input_file = "./output/manual_zephyr.signed.bin" + output_file = "./output/manual_zephyr.signed.lzma.bin" + + dict_size = 32768 + + with open(input_file, "rb") as f: + data = f.read() + + compressor = lzma.LZMACompressor( + format=lzma.FORMAT_RAW, + filters=[{ + "id": lzma.FILTER_LZMA1, + "dict_size": dict_size, + "lc": 1, + "lp": 2, + "pb": 0, + "mode": lzma.MODE_NORMAL, + "mf": lzma.MF_BT4, + "depth": 0 + }] + ) + + compressed = compressor.compress(data) + compressor.flush() + with open(output_file, "wb") as f: + f.write(compressed) + + original = os.path.getsize(input_file) + compressed_size = os.path.getsize(output_file) + print(f"LZMA compression completed: Original {original} Bytes -> Compressed {compressed_size} Bytes, save {((1-compressed_size/original)*100):.1f}%") + EOF + +2.2 Simple method using manual_process.py + + python3 manual_process.py \ + ./output/manual_zephyr.signed.bin \ + --only-lzma \ + --output-dir ./output \ + --lzma-dict-size 32768 + +3. Second MCUBoot signature for compressed firmware (adds --pad-header 0x200 or 512): + + python3 /home/ubuntu/zephyrproject/bootloader/mcuboot/scripts/imgtool.py sign \ + --pad-header \ + --version 0.0.0+0 \ + --align 1 \ + --header-size 512 \ + --slot-size 1179648 \ + --key /home/ubuntu/zephyrproject/bootloader/mcuboot/ecdsa_private_key.pem \ + ./output/manual_zephyr.signed.lzma.bin \ + ./output/manual_zephyr.signed.lzma.signed.bin + +4. Generate Matter OTA image: + + python3 /home/ubuntu/connectedhomeip/src/app/ota_image_tool.py create \ + --vendor-id 0xfff1 \ + --product-id 0x8004 \ + --version 2 \ + --version-str "2.0.0" \ + --digest-algorithm sha256 \ + ./output/manual_zephyr.signed.lzma.signed.bin \ + ./output/manual_matter.ota +""" + +import argparse +import lzma +import os +import subprocess +import sys + +# Configure tool paths here - edit these to match your environment +CONFIG = { + # Path to MCUBoot imgtool.py + 'imgtool_path': '/home/ubuntu/zephyrproject/bootloader/mcuboot/scripts/imgtool.py', + # Path to Matter ota_image_tool.py + 'ota_tool_path': '/home/ubuntu/connectedhomeip/src/app/ota_image_tool.py', +} + + +def parse_arguments(): + """Parse command line arguments""" + parser = argparse.ArgumentParser( + description='Manual Matter firmware processing tool for Telink platforms' + ) + parser.add_argument( + 'firmware_path', + help='Path to the input firmware file (can be raw zephyr.bin or already signed zephyr.signed.bin)' + ) + parser.add_argument( + 'config_path', + nargs='?', + help='Path to the .config file containing build configuration (optional if manual parameters are provided)' + ) + parser.add_argument( + '--output-dir', + default=None, + help='Directory to write output files (defaults to same directory as input firmware)' + ) + parser.add_argument( + '--already-signed', + action='store_true', + help='Input firmware is already signed (zephyr.signed.bin), skip first MCUBoot signature step' + ) + parser.add_argument( + '--only-lzma', + action='store_true', + help='Only perform LZMA compression: input.signed.bin -> output/manual_input.signed.lzma.bin' + ) + parser.add_argument( + '--chip-family', + choices=['tl3238c', 'tlsr9528a', 'tlsr9268j', 'tlsr9268m'], + default='tl3238c', + help='Chip family to process for: tl3238c (2MB Flash, full pipeline), tlsr9528a/tlsr9268m (4MB Flash, skip LZMA and second signature)' + ) + # Tool path overrides - can override the CONFIG defaults + parser.add_argument( + '--imgtool-path', + help='Override configured path to MCUBoot imgtool.py', + default=None + ) + parser.add_argument( + '--ota-tool-path', + help='Override configured path to Matter ota_image_tool.py', + default=None + ) + # Manual parameters - used if config_path is not provided + + def hex_or_int(value): + try: + return int(value, 0) + except ValueError: + raise argparse.ArgumentTypeError(f"invalid integer value: '{value}'") + + parser.add_argument( + '--rom-start-offset', + type=hex_or_int, + help='ROM start offset (CONFIG_ROM_START_OFFSET), supports decimal or 0x-prefixed hex' + ) + parser.add_argument( + '--flash-load-size', + type=hex_or_int, + help='Flash load size (CONFIG_FLASH_LOAD_SIZE), supports decimal or 0x-prefixed hex' + ) + parser.add_argument( + '--lzma-dict-size', + type=hex_or_int, + help='LZMA dictionary size (CONFIG_COMPRESS_LZMA_DICTIONARY_SIZE), supports decimal or 0x-prefixed hex' + ) + parser.add_argument( + '--signing-key', + help='MCUBoot signing key path (CONFIG_MCUBOOT_SIGNATURE_KEY_FILE)' + ) + parser.add_argument( + '--vendor-id', + type=hex_or_int, + help='Matter device vendor ID (CONFIG_CHIP_DEVICE_VENDOR_ID), supports decimal or 0x-prefixed hex' + ) + parser.add_argument( + '--product-id', + type=hex_or_int, + help='Matter device product ID (CONFIG_CHIP_DEVICE_PRODUCT_ID), supports decimal or 0x-prefixed hex' + ) + parser.add_argument( + '--software-version', + type=int, + default=1, + help='Matter device software version (CONFIG_CHIP_DEVICE_SOFTWARE_VERSION, default: 1)' + ) + parser.add_argument( + '--software-version-str', + default='1.0.0', + help='Matter device software version string (CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING, default: "1.0.0")' + ) + args = parser.parse_args() + + # Override CONFIG paths if command line arguments are provided + if args.imgtool_path: + CONFIG['imgtool_path'] = args.imgtool_path + if args.ota_tool_path: + CONFIG['ota_tool_path'] = args.ota_tool_path + + # Validate that if no config_path is provided, required manual parameters are present + if args.config_path is None: + if args.only_lzma: + # Only LZMA mode only requires lzma-dict-size + required_manual = [args.lzma_dict_size] + if not all(required_manual): + parser.error( + "When using --only-lzma and config_path is not provided, must specify --lzma-dict-size" + ) + else: + # Full pipeline requires all manual parameters + required_manual = [ + args.rom_start_offset, + args.flash_load_size, + args.lzma_dict_size, + args.signing_key, + args.vendor_id, + args.product_id + ] + if not all(required_manual): + parser.error( + "When config_path is not provided, all manual parameters must be specified: " + "--rom-start-offset, --flash-load-size, --lzma-dict-size, --signing-key, " + "--vendor-id, --product-id" + ) + + return args + + +def parse_dotconfig(config_path): + """Parse Kconfig .config file to extract all build configuration parameters""" + config = {} + if not os.path.exists(config_path): + raise FileNotFoundError(f"Config file not found: {config_path}") + + with open(config_path, 'r') as f: + for line in f: + line = line.strip() + if line.startswith('CONFIG_'): + key, value = line.split('=', 1) + # Strip quotes from string values + value = value.strip('"') + # Convert hexadecimal values + if value.startswith('0x'): + config[key] = int(value, 16) + # Convert integer values + elif value.isdigit(): + config[key] = int(value) + # String values remain as strings + else: + config[key] = value + return config + + +def merge_binaries(input_file1, input_file2, output_file, offset): + """Reuse merge_binaries function from the original process_binaries.py""" + with open(output_file, 'r+b' if os.path.exists(output_file) else 'wb') as outfile: + # Merge first input file at offset 0 + with open(input_file1, 'rb') as infile1: + data1 = infile1.read() + outfile.write(data1) + print(f"Merged {len(data1)} bytes from {input_file1} into {output_file} at offset 0") + + # Fill gaps with 0xFF if there's space between the two binaries + current_size = outfile.tell() + if current_size < offset: + gap_size = offset - current_size + outfile.write(bytearray([0xFF] * gap_size)) + print(f"Filled gap of {gap_size} bytes with 0xFF in {output_file}") + + # Merge second input file at the specified offset + with open(input_file2, 'rb') as infile2: + outfile.seek(offset) + data2 = infile2.read() + outfile.write(data2) + print(f"Merged {len(data2)} bytes from {input_file2} into {output_file} at offset {offset}") + + +def compress_lzma_firmware(input_file, output_file, dict_size): + """Reuse compress_lzma_firmware function from the original process_binaries.py""" + if not os.path.exists(input_file): + raise FileNotFoundError(f"Input firmware not found: {input_file}") + + with open(input_file, 'rb') as f: + firmware_data = f.read() + + # LZMA compression parameters (matched to device-side decoder) + lc = 1 # Literal context bits + lp = 2 # Literal position bits + pb = 0 # Position bits + + # Create LZMA compressor with raw format for compatibility with lzma_raw_decoder() + compressor = lzma.LZMACompressor( + format=lzma.FORMAT_RAW, + filters=[ + { + "id": lzma.FILTER_LZMA1, + "dict_size": dict_size, + "lc": lc, + "lp": lp, + "pb": pb, + "mode": lzma.MODE_NORMAL, + "mf": lzma.MF_BT4, + "depth": 0 + } + ] + ) + + # Perform compression + compressed_data = compressor.compress(firmware_data) + compressor.flush() + + # Write compressed binary to output file + with open(output_file, 'wb') as f: + f.write(compressed_data) + + print(f"LZMA compression completed: {input_file} -> {output_file}") + print( + f" Size reduction: {len(firmware_data)} -> {len(compressed_data)} bytes ({(1-len(compressed_data)/len(firmware_data))*100:.1f}% smaller)") + + +def run_imgtool_sign(input_file, output_file, rom_start_offset, flash_load_size, key_path, zephyr_base, pad_header=False): + """Reuse MCUBoot imgtool signing logic from CMakeLists.txt and process_binaries.py""" + if not os.path.exists(input_file): + raise FileNotFoundError(f"File to sign not found: {input_file}") + + # First try configured path, then fallback to auto-discovery + imgtool_path = CONFIG['imgtool_path'] + if not os.path.exists(imgtool_path): + # Fallback to original auto-discovery logic if configured path is invalid + imgtool_candidates = [ + os.path.join(zephyr_base, '../bootloader/mcuboot/scripts/imgtool.py'), + os.path.join(zephyr_base, 'bootloader/mcuboot/scripts/imgtool.py'), + os.path.join(os.getcwd(), 'bootloader/mcuboot/scripts/imgtool.py'), + os.path.join(os.path.dirname(__file__), 'bootloader/mcuboot/scripts/imgtool.py') + ] + for candidate in imgtool_candidates: + if os.path.exists(candidate): + imgtool_path = candidate + break + if not imgtool_path or not os.path.exists(imgtool_path): + raise FileNotFoundError( + f"MCUBoot imgtool not found. Check CONFIG['imgtool_path'] or use --imgtool-path. Last tried: {imgtool_path}") + + # Look for signing key in multiple possible locations + key_candidates = [ + os.path.join(zephyr_base, '../', key_path), + os.path.join(zephyr_base, key_path), + os.path.join(os.getcwd(), key_path), + os.path.join(os.getcwd(), os.path.basename(key_path)), + os.path.join(os.path.dirname(__file__), key_path), + os.path.join(os.path.dirname(__file__), os.path.basename(key_path)) + ] + full_key_path = None + for candidate in key_candidates: + if os.path.exists(candidate): + full_key_path = candidate + break + if not full_key_path: + raise FileNotFoundError(f"Signing key not found in any of: {key_candidates}") + if not os.path.exists(full_key_path): + raise FileNotFoundError(f"Signing key not found: {full_key_path}") + + # Build imgtool command + cmd = [ + sys.executable, imgtool_path, 'sign', + '--version', '0.0.0+0', + '--align', '1', + '--header-size', str(rom_start_offset), + '--slot-size', str(flash_load_size), + '--key', full_key_path + ] + + # Add --pad-header flag when signing compressed firmware + if pad_header: + cmd.append('--pad-header') + + cmd.extend([input_file, output_file]) + + print(f"Executing MCUBoot sign command: {' '.join(cmd)}") + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + print(f"imgtool stdout: {result.stdout}") + print(f"imgtool stderr: {result.stderr}") + raise subprocess.CalledProcessError(result.returncode, cmd) + print(f"MCUBoot signing completed: {input_file} -> {output_file}") + + +def run_ota_image_tool(input_file, output_file, vendor_id, product_id, version, version_str, chip_root): + """Reuse Matter OTA image tool logic from ota-image.cmake""" + if not os.path.exists(input_file): + raise FileNotFoundError(f"Signed firmware not found: {input_file}") + + # First try configured path, then fallback to auto-discovery + ota_tool_path = CONFIG['ota_tool_path'] + if not os.path.exists(ota_tool_path): + # Fallback to original auto-discovery logic if configured path is invalid + ota_tool_candidates = [ + os.path.join(chip_root, 'src/app/ota_image_tool.py'), + os.path.join(os.getcwd(), 'src/app/ota_image_tool.py'), + os.path.join(os.path.dirname(__file__), 'src/app/ota_image_tool.py'), + os.path.join(os.getcwd(), 'ota_image_tool.py'), + os.path.join(os.path.dirname(__file__), 'ota_image_tool.py') + ] + for candidate in ota_tool_candidates: + if os.path.exists(candidate): + ota_tool_path = candidate + break + if not ota_tool_path or not os.path.exists(ota_tool_path): + raise FileNotFoundError( + f"Matter OTA tool not found. Check CONFIG['ota_tool_path'] or use --ota-tool-path. Last tried: {ota_tool_path}") + + # Build Matter OTA image creation command + cmd = [ + sys.executable, ota_tool_path, 'create', + '--vendor-id', str(vendor_id), + '--product-id', str(product_id), + '--version', str(version), + '--version-str', version_str, + '--digest-algorithm', 'sha256', + input_file, + output_file + ] + + print(f"Executing Matter OTA packaging command: {' '.join(cmd)}") + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + print(f"ota_image_tool stdout: {result.stdout}") + print(f"ota_image_tool stderr: {result.stderr}") + raise subprocess.CalledProcessError(result.returncode, cmd) + print(f"Matter OTA packaging completed: {input_file} -> {output_file}") + + +def main(): + # Parse command line arguments + args = parse_arguments() + + # Get project root paths - support both project environment and standalone environment + # In standalone mode, all tools are relative to current working directory + script_dir = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(script_dir, '../../..', 'src/app/ota_image_tool.py')): + # Running from within the connectedhomeip project + chip_root = os.path.abspath(os.path.join(script_dir, '../../..')) + zephyr_base = os.environ.get('ZEPHYR_BASE', '/home/ubuntu/zephyr') + else: + # Running in standalone mode, all tools are in the current directory + chip_root = os.getcwd() + zephyr_base = os.getcwd() + + # Set output directory - default to same directory as input firmware + output_dir = args.output_dir if args.output_dir else os.path.dirname(args.firmware_path) + os.makedirs(output_dir, exist_ok=True) + + # Validate input firmware exists + if not os.path.exists(args.firmware_path): + raise FileNotFoundError(f"Firmware file not found: {args.firmware_path}") + + # Load configuration - either from .config file or manual parameters + config = {} + if args.config_path: + if not os.path.exists(args.config_path): + raise FileNotFoundError(f"Config file not found: {args.config_path}") + print("Parsing build configuration from .config file...") + config = parse_dotconfig(args.config_path) + else: + print("Using manually specified configuration parameters...") + config['CONFIG_ROM_START_OFFSET'] = args.rom_start_offset + config['CONFIG_FLASH_LOAD_SIZE'] = args.flash_load_size + config['CONFIG_COMPRESS_LZMA_DICTIONARY_SIZE'] = args.lzma_dict_size + config['CONFIG_MCUBOOT_SIGNATURE_KEY_FILE'] = args.signing_key + config['CONFIG_CHIP_DEVICE_VENDOR_ID'] = args.vendor_id + config['CONFIG_CHIP_DEVICE_PRODUCT_ID'] = args.product_id + config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION'] = args.software_version + config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING'] = args.software_version_str + + # Display loaded configuration + # Only print full configuration if not in only-lzma mode + if not args.only_lzma: + print("\n=== Loaded Configuration Parameters ===") + print(f"ROM_START_OFFSET: {config['CONFIG_ROM_START_OFFSET']} (0x{config['CONFIG_ROM_START_OFFSET']:x})") + print(f"FLASH_LOAD_SIZE: {config['CONFIG_FLASH_LOAD_SIZE']} (0x{config['CONFIG_FLASH_LOAD_SIZE']:x})") + print(f"LZMA_DICT_SIZE: {config['CONFIG_COMPRESS_LZMA_DICTIONARY_SIZE']}") + print(f"Signature key: {config['CONFIG_MCUBOOT_SIGNATURE_KEY_FILE']}") + print(f"Vendor ID: {config['CONFIG_CHIP_DEVICE_VENDOR_ID']} (0x{config['CONFIG_CHIP_DEVICE_VENDOR_ID']:x})") + print(f"Product ID: {config['CONFIG_CHIP_DEVICE_PRODUCT_ID']} (0x{config['CONFIG_CHIP_DEVICE_PRODUCT_ID']:x})") + print( + f"Software version: {config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION']} - {config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING']}") + print(f"Output directory: {output_dir}") + print("========================================") + else: + # Minimal output for only-lzma mode + print("\n=== LZMA Compression Configuration ===") + print(f"LZMA dictionary size: {config['CONFIG_COMPRESS_LZMA_DICTIONARY_SIZE']}") + print(f"Input file: {args.firmware_path}") + print(f"Output directory: {output_dir}") + print("======================================") + + # Define all output filenames with manual_ prefix + manual_signed_bin = os.path.join(output_dir, 'manual_zephyr.signed.bin') + manual_lzma_bin = os.path.join(output_dir, 'manual_zephyr.signed.lzma.bin') + manual_final_signed = os.path.join(output_dir, 'manual_zephyr.signed.lzma.signed.bin') + manual_matter_ota = os.path.join(output_dir, 'manual_matter.ota') + + # Handle only-lzma mode first + if args.only_lzma: + print("\n=== Only LZMA compression mode activated ===") + # Derive output filename from input to retain original naming prefix + input_filename = os.path.basename(args.firmware_path) + if input_filename.endswith('.bin'): + output_filename = input_filename[:-4] + '.lzma.bin' + else: + output_filename = input_filename + '.lzma.bin' + manual_lzma_bin = os.path.join(output_dir, output_filename) + print(f"Input file: {args.firmware_path}") + print(f"Output file: {manual_lzma_bin}") + compress_lzma_firmware( + input_file=args.firmware_path, + output_file=manual_lzma_bin, + dict_size=config['CONFIG_COMPRESS_LZMA_DICTIONARY_SIZE'] + ) + print("\n=== LZMA compression completed successfully! Generated file: ===") + size = os.path.getsize(manual_lzma_bin) + print(f"{manual_lzma_bin}: {size/1024:.1f} KB") + sys.exit(0) + + # Execute pipeline based on chip family + print(f"\n=== Chip family selected: {args.chip_family} ===") + if args.chip_family in ['tlsr9528a', 'tlsr9268j', 'tlsr9268m']: + # 4MB Flash chips: simplified pipeline - only two steps + print("\n=== Using simplified pipeline for 4MB Flash chips (skip LZMA and second signature) ===") + if args.already_signed: + print("\n=== Note: Input is already signed, skipping first MCUBoot signature step ===") + import shutil + shutil.copy2(args.firmware_path, manual_final_signed) + print(f"Copied signed input to: {manual_final_signed}") + input_for_ota = args.firmware_path + generated_files = [manual_final_signed, manual_matter_ota] + else: + print("\n=== Step 1: Only MCUBoot signature (4MB chips don't need compression) ===") + run_imgtool_sign( + input_file=args.firmware_path, + output_file=manual_final_signed, + rom_start_offset=config['CONFIG_ROM_START_OFFSET'], + flash_load_size=config['CONFIG_FLASH_LOAD_SIZE'], + key_path=config['CONFIG_MCUBOOT_SIGNATURE_KEY_FILE'], + zephyr_base=zephyr_base + ) + input_for_ota = manual_final_signed + generated_files = [manual_final_signed, manual_matter_ota] + + # Only generate OTA image as final step + print("\n=== Step 2: Generate final Matter OTA image ===") + run_ota_image_tool( + input_file=input_for_ota, + output_file=manual_matter_ota, + vendor_id=config['CONFIG_CHIP_DEVICE_VENDOR_ID'], + product_id=config['CONFIG_CHIP_DEVICE_PRODUCT_ID'], + version=config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION'], + version_str=config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING'], + chip_root=chip_root + ) + else: + # tl3238c: original full pipeline with LZMA compression + print("\n=== Using full pipeline for 2MB Flash chips (includes LZMA and dual signatures) ===") + # Determine starting point based on --already-signed flag + if args.already_signed: + # Input is already signed: zephyr.signed.bin -> skip first step + print("\n=== Note: Input is already signed, skipping first MCUBoot signature step ===") + input_for_compression = args.firmware_path + # Copy the already signed file to our manual_ prefix file for consistency + import shutil + shutil.copy2(args.firmware_path, manual_signed_bin) + print(f"Copied signed input to: {manual_signed_bin}") + step_start = 2 + else: + # Step 1: Input firmware -> manual_zephyr.signed.bin (First MCUBoot signature) + print("\n=== Step 1: First MCUBoot signature ===") + run_imgtool_sign( + input_file=args.firmware_path, + output_file=manual_signed_bin, + rom_start_offset=config['CONFIG_ROM_START_OFFSET'], + flash_load_size=config['CONFIG_FLASH_LOAD_SIZE'], + key_path=config['CONFIG_MCUBOOT_SIGNATURE_KEY_FILE'], + zephyr_base=zephyr_base + ) + input_for_compression = manual_signed_bin + step_start = 2 + + # Step 2: manual_zephyr.signed.bin -> manual_zephyr.signed.lzma.bin (LZMA compression) + print(f"\n=== Step {step_start}: LZMA compression ===") + compress_lzma_firmware( + input_file=input_for_compression, + output_file=manual_lzma_bin, + dict_size=config['CONFIG_COMPRESS_LZMA_DICTIONARY_SIZE'] + ) + + # Step 3: manual_zephyr.signed.lzma.bin -> manual_zephyr.signed.lzma.signed.bin (Second MCUBoot signature) + print(f"\n=== Step {step_start + 1}: Second MCUBoot signature (after compression) ===") + run_imgtool_sign( + input_file=manual_lzma_bin, + output_file=manual_final_signed, + rom_start_offset=config['CONFIG_ROM_START_OFFSET'], + flash_load_size=config['CONFIG_FLASH_LOAD_SIZE'], + key_path=config['CONFIG_MCUBOOT_SIGNATURE_KEY_FILE'], + zephyr_base=zephyr_base, + pad_header=True # --pad-header is REQUIRED for compressed firmware + ) + + # Step 4: manual_zephyr.signed.lzma.signed.bin -> manual_matter.ota (Matter OTA packaging) + print(f"\n=== Step {step_start + 2}: Generate final Matter OTA image ===") + run_ota_image_tool( + input_file=manual_final_signed, + output_file=manual_matter_ota, + vendor_id=config['CONFIG_CHIP_DEVICE_VENDOR_ID'], + product_id=config['CONFIG_CHIP_DEVICE_PRODUCT_ID'], + version=config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION'], + version_str=config['CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING'], + chip_root=chip_root + ) + generated_files = [manual_signed_bin, manual_lzma_bin, manual_final_signed, manual_matter_ota] + + print("\n=== All steps completed successfully! Generated files: ===") + for f in generated_files: + if os.path.exists(f): + size = os.path.getsize(f) + print(f"{f}: {size/1024:.1f} KB") + + +if __name__ == '__main__': + print("=== Matter Telink Manual Firmware Processing Tool ===") + print("\nUsage 1 (process raw firmware, full pipeline):") + print(" python3 manual_process.py zephyr.bin [--output-dir OUTPUT_DIR]") + print("Example 1:") + print(" python3 manual_process.py \\") + print(" /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/zephyr.bin \\") + print(" /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/.config\n") + print("Usage 2 (process already signed firmware, start from compression):") + print(" python3 manual_process.py zephyr.signed.bin --already-signed") + print("Example 2:") + print(" python3 manual_process.py \\") + print(" /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/zephyr.signed.bin \\") + print(" /home/ubuntu/connectedhomeip/examples/light-switch-app/telink/build_tl3238x_retention_dual_sw_v1/zephyr/.config --already-signed\n") + print("Usage 3 (with manual parameters):") + print(" python3 manual_process.py [--output-dir OUTPUT_DIR] \\") + print(" --rom-start-offset 512 --flash-load-size 1179648 \\") + print(" --lzma-dict-size 32768 --signing-key bootloader/mcuboot/root-rsa-2048.pem \\") + print(" --vendor-id 65521 --product-id 32772 [--already-signed]\n") + + try: + main() + except Exception as e: + import traceback + traceback.print_exc() + print(f"\nERROR: {str(e)}", file=sys.stderr) + sys.exit(1) \ No newline at end of file diff --git a/scripts/tools/telink/mfg_tool.py b/scripts/tools/telink/mfg_tool.py index 8a92972472f4..ac4e1e565e93 100755 --- a/scripts/tools/telink/mfg_tool.py +++ b/scripts/tools/telink/mfg_tool.py @@ -32,6 +32,8 @@ import cryptography.hazmat.backends import cryptography.x509 import pyqrcode +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from intelhex import IntelHex TOOLS = { @@ -455,10 +457,15 @@ def write_device_unique_data(args, out_dirs, pai_cert): dacs = use_dac_cert_from_args(args, out_dirs) else: dacs = generate_dac_cert(int(row['Index']), args, out_dirs, int(row['Discriminator']), - int(row['PIN Code']), pai_cert['key_pem'], pai_cert['cert_pem']) + int(row['PIN Code']), pai_cert['key_pem'], pai_cert['cert_pem']) + dac_cert_storage = read_der_file(dacs[0]) + dac_key_storage = read_key_bin_file(dacs[1]) + if not args.secure_programming_verification: + nvs_memory_append('dac_cert', dac_cert_storage) + nvs_memory_append('dac_key', dac_key_storage) + else: + log.info("Secure programming verification enabled; DAC and its keys are not stored directly into factory data") - nvs_memory_append('dac_cert', read_der_file(dacs[0])) - nvs_memory_append('dac_key', read_key_bin_file(dacs[1])) nvs_memory_append('pai_cert', read_der_file(pai_cert['cert_der'])) nvs_memory_append('cert_dclrn', read_der_file(args.cert_dclrn)) @@ -471,17 +478,100 @@ def write_device_unique_data(args, out_dirs, pai_cert): return dacs +def aes_encrypt(key, data): + # Ensure data is 16 bytes (AES block size) + assert len(data) == 16, "Data block for AES must be 16 bytes." + assert len(key) == 16, "AES key must be 16 bytes (128 bits)." + + cipher = Cipher(algorithms.AES(key), modes.ECB(), backend=default_backend()) + encryptor = cipher.encryptor() + return encryptor.update(data) + encryptor.finalize() + +def save_dac_cert_and_keys(dac_cert, dac_key, chip_id, file_path): + with open(file_path, 'wb') as f: + # Write DAC private key length (2 bytes, little-endian) + dac_key_len = len(dac_key) + f.write(dac_key_len.to_bytes(2, 'little')) + + # Encrypt DAC private key in two 16-byte segments + encrypted_key_part1 = aes_encrypt(chip_id, dac_key[:16]) + encrypted_key_part2 = aes_encrypt(chip_id, dac_key[16:32]) + + # Write the encrypted DAC private key parts (32 bytes total) + f.write(encrypted_key_part1) + f.write(encrypted_key_part2) + + # Pad the file with 0xFF to reach the 100th byte + f.write(b'\xFF' * (100 - f.tell())) + + # Write DAC certificate length (2 bytes, little-endian) + dac_cert_len = len(dac_cert) + f.write(dac_cert_len.to_bytes(2, 'little')) -def generate_partition(args, out_dirs): - log.info("Generating partition image: offset: 0x%08X size: 0x%08X", args.offset, args.size) + # Write DAC certificate data + f.write(dac_cert) + + print(f"DAC certificate and key have been saved to {file_path}") + +def generate_partition(args, dacs_cert, out_dirs): + log.info('Generating partition image: offset: 0x{:X} size: 0x{:X}'.format(args.offset, args.size)) cbor_data = cbor.dumps(NVS_MEMORY) # Create hex file if len(cbor_data) > args.size: raise ValueError("generated CBOR file exceeds declared maximum partition size! {} > {}".format(len(cbor_data), args.size)) ih = IntelHex() ih.putsz(args.offset, cbor_data) - ih.write_hex_file(os.sep.join([out_dirs['output'], 'factory_data.hex']), True) - ih.tobinfile(os.sep.join([out_dirs['output'], 'factory_data.bin'])) + # ih.write_hex_file(os.sep.join([out_dirs['output'], 'factory_data.hex']), True) + # ih.tobinfile(os.sep.join([out_dirs['output'], 'factory_data.bin'])) + + output_dir = out_dirs['output'] + hex_file_path = os.path.join(output_dir, 'factory_data.hex') + bin_file_path = os.path.join(output_dir, 'factory_data.bin') + ih.write_hex_file(hex_file_path, True) + ih.tobinfile(bin_file_path) + + if args.secure_programming_verification: + dac_cert_key_file_path = os.path.join(output_dir, 'dac_cert_key.bin') + dac_cert_storage = read_der_file(dacs_cert[0]) + log.info("dac_cert_storaget (Hex): {}".format(dac_cert_storage.hex())) + dac_key_storage = read_key_bin_file(dacs_cert[1]) + log.info("dac_key_storage (Hex): {}".format(dac_key_storage.hex())) + chip_id_bytes = bytes.fromhex(args.chip_id) + log.info("chip_id_bytes (Hex): {}".format(chip_id_bytes.hex())) + save_dac_cert_and_keys(dac_cert_storage, dac_key_storage, chip_id_bytes, dac_cert_key_file_path) + log.info(f"DAC certificate and key have been saved to {dac_cert_key_file_path}") + + with open(os.sep.join([out_dirs['output'], 'pin_disc.csv']), 'r') as csvf: + pin_disc_dict = csv.DictReader(csvf) + row = pin_disc_dict.__next__() + + # Extract Discriminator, PID, and VID + discriminator = int(row['Discriminator']) + pid = args.product_id + vid = args.vendor_id + + log.info("Discriminator = {}".format(discriminator)) + log.info("PID = 0x{:X}".format(pid)) + log.info("VID = 0x{:X}".format(vid)) + + # Convert Discriminator, PID, and VID to bytes + discriminator_bytes = discriminator.to_bytes(2, byteorder='little') + pid_bytes = pid.to_bytes(2, byteorder='little') + vid_bytes = vid.to_bytes(2, byteorder='little') + + # Read the existing binary data + with open(bin_file_path, 'rb') as bin_file: + bin_data = bin_file.read() + + # Prepend the hex data to the binary data + extended_data = discriminator_bytes + pid_bytes + vid_bytes + bin_data + + # Write the combined data to a new file + ext_bin_file_path = os.path.join(output_dir, 'factory_data_ext.bin') + with open(ext_bin_file_path, 'wb') as ext_bin_file: + ext_bin_file.write(extended_data) + + log.info(f"Extended binary data written to {ext_bin_file_path}") def generate_json_summary(args, out_dirs, pai_certs, dacs_cert, serial_num: str): @@ -544,7 +634,10 @@ def add_additional_kv(args, serial_num): nvs_memory_append('rd_uid', args.rd_id_uid) # Add the serial-num - nvs_memory_append('sn', serial_num) + if args.disable_serial_num_storage: + log.info("Secure programming verification enabled; skipping serial-num") + else: + nvs_memory_append('sn', serial_num) nvs_memory_append('version', FACTORY_DATA_VERSION) @@ -601,7 +694,7 @@ def base64_str(s): return base64.b64decode(s) help='Commissionable device discovery networking technology. \ 0:WiFi-SoftAP, 1:BLE, 2:On-network. Default is BLE.', choices=[0, 1, 2]) - # Device insrance information + # Device instance information dev_inst_args = parser.add_argument_group('Device instance information options') dev_inst_args.add_argument('-v', '--vendor-id', type=allow_any_int, required=False, help='Vendor id') dev_inst_args.add_argument('--vendor-name', type=str, required=False, help='Vendor name') @@ -646,8 +739,34 @@ def base64_str(s): return base64.b64decode(s) help='Partition offset - an address in devices NVM memory, where factory data will be stored') part_gen_args.add_argument('--size', type=allow_any_int, help='The maximum partition size') + secure_args = parser.add_argument_group('Secure programming verification options') + secure_args.add_argument("--secure-programming-verification", action="store_true", + help="Enable secure programming mode. When set, the script will perform additional steps for secure programming verification.") + secure_args.add_argument("--chip-id", required=False, type=str, help="Chip ID in hex format (32 hex characters).") + secure_args.add_argument("--disable_serial_num_storage", action="store_true", + help="Disable storage of serial-num in factorydata.") + args = parser.parse_args() + if args.secure_programming_verification: + if not args.chip_id: + log.error("--chip-id is required when --secure-programming-verification is enabled.") + sys.exit(1) + + if args.count > 1: + log.error("--count cannot be greater than 1 when --secure-programming-verification is enabled.") + sys.exit(1) + + # Additional validation on chip-id format + if args.chip_id: + try: + chip_id_bytes = bytes.fromhex(args.chip_id) + if len(chip_id_bytes) != 16: + raise ValueError() + except ValueError: + log.error("--chip-id must be a valid 16-byte hex string (32 hex characters).") + sys.exit(1) + # Validate in-tree parameter if args.count > 1 and args.in_tree: log.error("Option --in-tree can not be use together with --count > 1") @@ -728,14 +847,14 @@ def main(): out_dir_top = os.path.realpath(args.output) os.makedirs(out_dir_top, exist_ok=True) - with open(os.sep.join([out_dir_top, "device_sn.csv"]), "w") as f: - f.write(DEV_SN_CSV_HDR) + with open(os.sep.join([out_dir_top, "device_sn.csv"]), "w") as dev_sn_file: + dev_sn_file.write(DEV_SN_CSV_HDR) for i in range(args.count): pai_cert = {} serial_num_str = format(serial_num_int + i, 'x') - log.info("Generating for '%s'", serial_num_str) - f.write(serial_num_str + '\n') + log.info("Generating for {}".format(serial_num_str)) + dev_sn_file.write(serial_num_str + '\n') out_dirs = setup_out_dir(out_dir_top, args, serial_num_str) add_additional_kv(args, serial_num_str) generate_passcode(args, out_dirs) @@ -743,7 +862,7 @@ def main(): if args.paa or args.pai: pai_cert = setup_root_certificates(args, out_dirs) dacs_cert = write_device_unique_data(args, out_dirs, pai_cert) - generate_partition(args, out_dirs) + generate_partition(args, dacs_cert, out_dirs) generate_json_summary(args, out_dirs, pai_cert, dacs_cert, serial_num_str) diff --git a/scripts/tools/telink/package_telink_firmware.sh b/scripts/tools/telink/package_telink_firmware.sh new file mode 100755 index 000000000000..b7fe62a3b285 --- /dev/null +++ b/scripts/tools/telink/package_telink_firmware.sh @@ -0,0 +1,1305 @@ +#!/bin/bash +# +# Copyright (c) 2026 Telink Semiconductor Co., Ltd. +# +# 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. +# + +set -e + +# Unified Package script for Telink TL3238X/TL7218X Matter firmware +# This script combines generate, extract, readme, and zip functionality +# +# Usage: package_telink_firmware.sh [--build] [--extract] [--readme] [--zip] [--all] [--lighting] [--switch] [--tl3238x] [--tl5218x] [--tl7218x] [target1 target2...] +# +# --build : Build firmware targets +# --extract : Extract firmware from build directories +# --readme : Generate README.md +# --zip : Create zip archive +# --all : Perform all steps (build, extract, readme, zip) +# +# In addition to the steps above, a versioned snapshot of the release note +# working copy (docs/platforms/telink/releases/telink_release_notes.md) is +# written to docs/platforms/telink/releases/telink_release_notes_.md +# during the readme/zip steps, using the nearest `tl_v*` git tag as the version. +# +# Available Targets: +# TL3238X: +# Lighting App: +# - build_tl3238x_default +# - build_tl3238x_2m_flash_lzma_v1 +# - build_tl3238x_2m_flash_lzma_v2 +# - build_tl3238x_4m_dual_mode +# +# Light Switch App: +# - build_tl3238x_retention_default +# - build_tl3238x_retention_lzma_v1 +# - build_tl3238x_retention_lzma_v2 +# - build_tl3238x_retention_dual_mode +# +# Contact Sensor App: +# - build_tl3238x_retention_v1 +# - build_tl3238x_retention_v2 +# - build_tl3238x_retention_lzma_v1 +# - build_tl3238x_retention_lzma_v2 +# +# TL5218X: +# Lighting App: +# - build_tl5218x_default +# - build_tl5218x_2m_flash_lzma_v1 +# - build_tl5218x_2m_flash_lzma_v2 +# - build_tl5218x_4m_dual_mode +# +# Light Switch App: +# - build_tl5218x_retention_default +# - build_tl5218x_retention_lzma_v1 +# - build_tl5218x_retention_lzma_v2 +# - build_tl5218x_retention_dual_mode +# +# Contact Sensor App: +# - build_tl5218x_retention_v1 +# - build_tl5218x_retention_v2 +# - build_tl5218x_retention_lzma_v1 +# - build_tl5218x_retention_lzma_v2 +# +# TL7218X: +# Lighting App: +# - build_tl7218x_default +# - build_tl7218x_2m_flash_lzma_v1 +# - build_tl7218x_2m_flash_lzma_v2 +# +# Light Switch App: +# - build_tl7218x_retention_default +# - build_tl7218x_retention_lzma_v1 +# - build_tl7218x_retention_lzma_v2 +# +# Contact Sensor App: +# - build_tl7218x_retention_v1 +# - build_tl7218x_retention_v2 +# - build_tl7218x_retention_lzma_v1 +# - build_tl7218x_retention_lzma_v2 +# +# If no arguments are specified, performs all steps for all targets. + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CONNECTEDHOME_DIR="$(cd "$SCRIPT_DIR/../../.." && pwd)" +ZEPHYR_BASE="$(cd "$CONNECTEDHOME_DIR/../zephyr" && pwd)" +EXAMPLES_DIR="$CONNECTEDHOME_DIR/examples" +LIGHTING_APP_DIR="$EXAMPLES_DIR/lighting-app/telink" +LIGHT_SWITCH_APP_DIR="$EXAMPLES_DIR/light-switch-app/telink" +CONTACT_SENSOR_APP_DIR="$EXAMPLES_DIR/contact-sensor-app/telink" + +DATE=$(date +%Y%m%d_%H%M%S) + +# Parse arguments +DO_BUILD=false +DO_EXTRACT=false +DO_README=false +DO_ZIP=false +GENERATE_LIGHTING=false +GENERATE_SWITCH=false +GENERATE_CONTACT=false +GENERATE_TL3238X=false +GENERATE_TL5218X=false +GENERATE_TL7218X=false +TARGETS=() + +while [ $# -gt 0 ]; do + case "$1" in + --build) + DO_BUILD=true + shift + ;; + --extract) + DO_EXTRACT=true + shift + ;; + --readme) + DO_README=true + shift + ;; + --zip) + DO_ZIP=true + shift + ;; + --all) + DO_BUILD=true + DO_EXTRACT=true + DO_README=true + DO_ZIP=true + shift + ;; + --lighting) + GENERATE_LIGHTING=true + shift + ;; + --switch) + GENERATE_SWITCH=true + shift + ;; + --contact) + GENERATE_CONTACT=true + shift + ;; + --tl3238x) + GENERATE_TL3238X=true + shift + ;; + --tl5218x) + GENERATE_TL5218X=true + shift + ;; + --tl7218x) + GENERATE_TL7218X=true + shift + ;; + build_tl3238x* | build_tl5218x* | build_tl7218x*) + TARGETS+=("$1") + shift + ;; + *) + echo "Unknown option: $1" + echo "Usage: $0 [--build] [--extract] [--readme] [--zip] [--all] [--lighting] [--switch] [--contact] [--tl3238x] [--tl5218x] [--tl7218x] [target1 target2...]" + exit 1 + ;; + esac +done + +# If no operation specified, do all +if [ "$DO_BUILD" = false ] && [ "$DO_EXTRACT" = false ] && [ "$DO_README" = false ] && [ "$DO_ZIP" = false ]; then + DO_BUILD=true + DO_EXTRACT=true + DO_README=true + DO_ZIP=true +fi + +# If no targets specified and building, generate all +if [ "$DO_BUILD" = true ] && [ ${#TARGETS[@]} -eq 0 ]; then + GENERATE_LIGHTING=true + GENERATE_SWITCH=true + GENERATE_CONTACT=true + GENERATE_TL3238X=true + GENERATE_TL5218X=true + GENERATE_TL7218X=true +elif [ "$DO_BUILD" = true ]; then + # Check which apps are needed based on targets + for target in "${TARGETS[@]}"; do + if [[ "$target" == build_tl3238x_* ]] || [[ "$target" == build_tl5218x_* ]] || [[ "$target" == build_tl7218x_* ]]; then + GENERATE_LIGHTING=true + fi + if [[ "$target" == build_tl3238x_retention* ]] || [[ "$target" == build_tl5218x_retention* ]] || [[ "$target" == build_tl7218x_retention* ]]; then + # Check if it's contact sensor or light switch + if [[ "$target" == *contact* ]]; then + GENERATE_CONTACT=true + else + GENERATE_SWITCH=true + fi + fi + if [[ "$target" == build_tl3238x* ]]; then + GENERATE_TL3238X=true + fi + if [[ "$target" == build_tl5218x* ]]; then + GENERATE_TL5218X=true + fi + if [[ "$target" == build_tl7218x* ]]; then + GENERATE_TL7218X=true + fi + done +fi + +echo "Activating Matter SDK environment..." +cd "$CONNECTEDHOME_DIR" +source scripts/activate.sh + +# Function to check if target should be generated +should_generate() { + local target="$1" + if [ ${#TARGETS[@]} -eq 0 ]; then + return 0 # No targets specified, generate all + fi + for arg in "${TARGETS[@]}"; do + if [ "$arg" = "$target" ]; then + return 0 + fi + done + return 1 +} + +# Function to check if target should be packaged +should_package() { + local target="$1" + shift + if [ $# -eq 0 ]; then + return 0 + fi + for arg in "$@"; do + if [ "$arg" = "$target" ]; then + return 0 + fi + done + return 1 +} + +# Function to find the latest build directory for a given prefix +find_latest_build_dir() { + local app_dir="$1" + local prefix="$2" + local latest_dir="" + + for dir in "$app_dir/$prefix"*; do + if [ -d "$dir" ] && [ -f "$dir/zephyr/.config" ]; then + if [ -z "$latest_dir" ] || [ "$dir" -nt "$latest_dir" ]; then + latest_dir="$dir" + fi + fi + done + + if [ -n "$latest_dir" ]; then + echo "$latest_dir" + else + echo "" + fi +} + +get_build_dir() { + local app_dir="$1" + local target="$2" + + if [ -d "$app_dir/$target" ]; then + echo "$app_dir/$target" + return + fi + + local latest_dir="$(find_latest_build_dir "$app_dir" "$target")" + if [ -n "$latest_dir" ]; then + echo "$latest_dir" + else + echo "" + fi +} + +# Function to generate Lighting App +generate_lighting_app() { + echo "" + echo "=== Generating Lighting App ===" + cd "$LIGHTING_APP_DIR" + + if [ "$GENERATE_TL3238X" = true ]; then + if should_generate build_tl3238x_default; then + BUILD_DIR="build_tl3238x_default_$DATE" + echo "" + echo "=== TL3238X: 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl3238x -d "$BUILD_DIR" -- \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl3238x_2m_flash_lzma_v1; then + BUILD_DIR="build_tl3238x_2m_flash_lzma_v1_$DATE" + echo "" + echo "=== TL3238X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v1 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl3238x -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 \ + -DCONF_FILE="prj.conf;boards/tl3238x_2m_flash_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl3238x_2m_flash_lzma_v2; then + BUILD_DIR="build_tl3238x_2m_flash_lzma_v2_$DATE" + echo "" + echo "=== TL3238X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v2 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl3238x -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 \ + -DCONF_FILE="prj.conf;boards/tl3238x_2m_flash_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl3238x_4m_dual_mode; then + BUILD_DIR="build_tl3238x_4m_dual_mode_$DATE" + echo "" + echo "=== TL3238X: 4MB Flash (Matter + Zigbee dual mode, no LZMA) ===" + echo "Generate directory: $BUILD_DIR" + + # Copy lighting app specific Zigbee firmware + if [ -f "$ZEPHYR_BASE/TL323X_FW/ZB/dual_matter_sampleLight_bleAdv_tl323x.bin" ]; then + cp "$ZEPHYR_BASE/TL323X_FW/ZB/dual_matter_sampleLight_bleAdv_tl323x.bin" "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" + echo "Copied dual_matter_sampleLight_bleAdv_tl323x.bin to Zigbee-SampleDemo.bin" + fi + + west build -p -b tl3238x -d "$BUILD_DIR" -- \ + -DFLASH_SIZE=4m \ + -DCONF_FILE="prj.conf;boards/tl3238x_4m_flash_dual_mode_ota.conf" \ + -DDTC_OVERLAY_FILE="boards/tl3238x_for_TL3238C-EVK40D.overlay" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + fi + + if [ "$GENERATE_TL5218X" = true ]; then + if should_generate build_tl5218x_default; then + BUILD_DIR="build_tl5218x_default_$DATE" + echo "" + echo "=== TL5218X: 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl5218x -d "$BUILD_DIR" -- \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl5218x_2m_flash_lzma_v1; then + BUILD_DIR="build_tl5218x_2m_flash_lzma_v1_$DATE" + echo "" + echo "=== TL5218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v1 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl5218x -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 \ + -DCONF_FILE="prj.conf;boards/tl5218x_2m_flash_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl5218x_2m_flash_lzma_v2; then + BUILD_DIR="build_tl5218x_2m_flash_lzma_v2_$DATE" + echo "" + echo "=== TL5218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v2 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl5218x -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 \ + -DCONF_FILE="prj.conf;boards/tl5218x_2m_flash_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl5218x_4m_dual_mode; then + BUILD_DIR="build_tl5218x_4m_dual_mode_$DATE" + echo "" + echo "=== TL5218X: 4MB Flash (Matter + Zigbee dual mode, no LZMA) ===" + echo "Generate directory: $BUILD_DIR" + + # Copy lighting app specific Zigbee firmware + if [ -f "$ZEPHYR_BASE/TL323X_FW/ZB/dual_matter_sampleLight_bleAdv_tl323x.bin" ]; then + cp "$ZEPHYR_BASE/TL323X_FW/ZB/dual_matter_sampleLight_bleAdv_tl323x.bin" "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" + echo "Copied dual_matter_sampleLight_bleAdv_tl323x.bin to Zigbee-SampleDemo.bin" + fi + + west build -p -b tl5218x -d "$BUILD_DIR" -- \ + -DFLASH_SIZE=4m \ + -DCONF_FILE="prj.conf;boards/tl5218x_4m_flash_dual_mode_ota.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + fi + + if [ "$GENERATE_TL7218X" = true ]; then + if should_generate build_tl7218x_default; then + BUILD_DIR="build_tl7218x_default_$DATE" + echo "" + echo "=== TL7218X: 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl7218x -d "$BUILD_DIR" -- \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl7218x_2m_flash_lzma_v1; then + BUILD_DIR="build_tl7218x_2m_flash_lzma_v1_$DATE" + echo "" + echo "=== TL7218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v1 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl7218x -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 \ + -DCONF_FILE="prj.conf;boards/tl7218x_2m_flash_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl7218x_2m_flash_lzma_v2; then + BUILD_DIR="build_tl7218x_2m_flash_lzma_v2_$DATE" + echo "" + echo "=== TL7218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v2 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl7218x -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 \ + -DCONF_FILE="prj.conf;boards/tl7218x_2m_flash_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + fi +} + +# Function to generate Light Switch App +generate_light_switch() { + echo "" + echo "=== Generating Light Switch App ===" + cd "$LIGHT_SWITCH_APP_DIR" + + if [ "$GENERATE_TL3238X" = true ]; then + if should_generate build_tl3238x_retention_default; then + BUILD_DIR="build_tl3238x_retention_default_$DATE" + echo "" + echo "=== TL3238X: 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl3238x_retention -d "$BUILD_DIR" -- \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl3238x_retention_lzma_v1; then + BUILD_DIR="build_tl3238x_retention_lzma_v1_$DATE" + echo "" + echo "=== TL3238X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v1 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl3238x_retention -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 \ + -DCONF_FILE="prj.conf;boards/tl3238x_retention_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl3238x_retention_lzma_v2; then + BUILD_DIR="build_tl3238x_retention_lzma_v2_$DATE" + echo "" + echo "=== TL3238X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v2 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl3238x_retention -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 \ + -DCONF_FILE="prj.conf;boards/tl3238x_retention_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl3238x_retention_dual_mode; then + BUILD_DIR="build_tl3238x_retention_dual_mode_$DATE" + echo "" + echo "=== TL3238X: 2MB Flash (Matter + Zigbee dual mode, LZMA compressed, enable BT DFU) ===" + echo "Generate directory: $BUILD_DIR" + + # Copy light-switch app specific Zigbee firmware + if [ -f "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin" ]; then + cp "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin" "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" + echo "Copied sampleSwitch_tl323x_log.bin to Zigbee-SampleDemo.bin" + elif [ -f "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x-bak.bin" ]; then + cp "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x-bak.bin" "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" + echo "Copied sampleSwitch_tl323x-bak.bin to Zigbee-SampleDemo.bin" + fi + + west build -p -b tl3238x_retention -d "$BUILD_DIR" -- \ + -DCONF_FILE="prj.conf;boards/tl3238x_retention_dual_mode_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + fi + + if [ "$GENERATE_TL5218X" = true ]; then + if should_generate build_tl5218x_retention_default; then + BUILD_DIR="build_tl5218x_retention_default_$DATE" + echo "" + echo "=== TL5218X: 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl5218x_retention -d "$BUILD_DIR" -- \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl5218x_retention_lzma_v1; then + BUILD_DIR="build_tl5218x_retention_lzma_v1_$DATE" + echo "" + echo "=== TL5218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v1 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl5218x_retention -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 \ + -DCONF_FILE="prj.conf;boards/tl5218x_retention_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl5218x_retention_lzma_v2; then + BUILD_DIR="build_tl5218x_retention_lzma_v2_$DATE" + echo "" + echo "=== TL5218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v2 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl5218x_retention -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 \ + -DCONF_FILE="prj.conf;boards/tl5218x_retention_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl5218x_retention_dual_mode; then + BUILD_DIR="build_tl5218x_retention_dual_mode_$DATE" + echo "" + echo "=== TL5218X: 2MB Flash (Matter + Zigbee dual mode, LZMA compressed, enable BT DFU) ===" + echo "Generate directory: $BUILD_DIR" + + # Copy light-switch app specific Zigbee firmware + if [ -f "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin" ]; then + cp "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x_log.bin" "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" + echo "Copied sampleSwitch_tl323x_log.bin to Zigbee-SampleDemo.bin" + elif [ -f "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x-bak.bin" ]; then + cp "$ZEPHYR_BASE/TL323X_FW/ZB/sampleSwitch_tl323x-bak.bin" "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" + echo "Copied sampleSwitch_tl323x-bak.bin to Zigbee-SampleDemo.bin" + fi + + west build -p -b tl5218x_retention -d "$BUILD_DIR" -- \ + -DCONF_FILE="prj.conf;boards/tl5218x_retention_dual_mode_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + fi + + if [ "$GENERATE_TL7218X" = true ]; then + if should_generate build_tl7218x_retention_default; then + BUILD_DIR="build_tl7218x_retention_default_$DATE" + echo "" + echo "=== TL7218X: 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl7218x_retention -d "$BUILD_DIR" -- \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl7218x_retention_lzma_v1; then + BUILD_DIR="build_tl7218x_retention_lzma_v1_$DATE" + echo "" + echo "=== TL7218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v1 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl7218x_retention -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 \ + -DCONF_FILE="prj.conf;boards/tl7218x_retention_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + + if should_generate build_tl7218x_retention_lzma_v2; then + BUILD_DIR="build_tl7218x_retention_lzma_v2_$DATE" + echo "" + echo "=== TL7218X: 2MB Flash (Matter only, enable BT DFU, LZMA compressed) - v2 ===" + echo "Generate directory: $BUILD_DIR" + west build -p -b tl7218x_retention -d "$BUILD_DIR" -- \ + -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 \ + -DCONF_FILE="prj.conf;boards/tl7218x_retention_ota_lzma.conf" \ + 2>&1 | tee "$BUILD_DIR.log" + fi + fi +} + +# Prepare for TL3238X dual-mode build +prepare_dual_mode() { + echo "" + echo "=== Preparing for TL3238X dual-mode build ===" + + # Download and extract TL323X_FW if not exists + if [ ! -d "$ZEPHYR_BASE/TL323X_FW" ]; then + echo "Downloading TL323X_FW..." + wget -q https://doc.telink-semi.cn/Zephyr/binaries/public/tl323x_fw/TL323X_FW.zip -O /tmp/TL323X_FW.zip + unzip -q /tmp/TL323X_FW.zip -d "$ZEPHYR_BASE" + rm -f /tmp/TL323X_FW.zip + echo "TL323X_FW downloaded and extracted successfully" + else + echo "TL323X_FW already exists" + fi +} + +# Cleanup temporary Zigbee-SampleDemo.bin after build +cleanup_zigbee_sample() { + echo "" + echo "=== Cleaning up Zigbee-SampleDemo.bin ===" + if [ -f "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" ]; then + rm -f "$ZEPHYR_BASE/TL323X_FW/ZB/Zigbee-SampleDemo.bin" + echo "Zigbee-SampleDemo.bin deleted" + fi +} + +# Extract firmware function +extract_firmware() { + echo "" + echo "=== Extracting Telink Matter Firmware ===" + + # Create package directory with date and time + PARENT_DIR="$(cd "$CONNECTEDHOME_DIR/.." && pwd)" + BASE_PKG_DIR="$PARENT_DIR/Matter_test_materials" + mkdir -p "$BASE_PKG_DIR" + PKG_DIR="$BASE_PKG_DIR/TL3238X-TL5218X-TL7218X-Matter-DUT-firmware-images-$DATE" + mkdir -p "$PKG_DIR/feature-test/light-switch/tl3238x" + mkdir -p "$PKG_DIR/feature-test/light-switch/tl5218x" + mkdir -p "$PKG_DIR/feature-test/light-switch/tl7218x" + mkdir -p "$PKG_DIR/feature-test/lighting/tl3238x" + mkdir -p "$PKG_DIR/feature-test/lighting/tl5218x" + mkdir -p "$PKG_DIR/feature-test/lighting/tl7218x" + mkdir -p "$PKG_DIR/feature-test/contact-sensor/tl3238x" + mkdir -p "$PKG_DIR/feature-test/contact-sensor/tl5218x" + mkdir -p "$PKG_DIR/feature-test/contact-sensor/tl7218x" + echo "Package directory: $PKG_DIR" + echo "$PKG_DIR" >"$BASE_PKG_DIR/.last_pkg_dir" + + # TL3238X Targets + BUILD_32_DEFAULT=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl3238x_default") + BUILD_32_2M_FLASH_LZMA_V1=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl3238x_2m_flash_lzma_v1") + BUILD_32_2M_FLASH_LZMA_V2=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl3238x_2m_flash_lzma_v2") + BUILD_32_4M_DUAL=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl3238x_4m_dual_mode") + + BUILD_32_RET_DEFAULT=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl3238x_retention_default") + BUILD_32_RET_LZMA_V1=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl3238x_retention_lzma_v1") + BUILD_32_RET_LZMA_V2=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl3238x_retention_lzma_v2") + BUILD_32_RET_DUAL=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl3238x_retention_dual_mode") + + BUILD_32_CS_V1=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl3238x_retention_v1") + BUILD_32_CS_V2=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl3238x_retention_v2") + BUILD_32_CS_LZMA_V1=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl3238x_retention_lzma_v1") + BUILD_32_CS_LZMA_V2=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl3238x_retention_lzma_v2") + + # TL5218X Targets + BUILD_52_DEFAULT=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl5218x_default") + BUILD_52_2M_FLASH_LZMA_V1=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl5218x_2m_flash_lzma_v1") + BUILD_52_2M_FLASH_LZMA_V2=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl5218x_2m_flash_lzma_v2") + BUILD_52_4M_DUAL=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl5218x_4m_dual_mode") + + BUILD_52_RET_DEFAULT=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl5218x_retention_default") + BUILD_52_RET_LZMA_V1=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl5218x_retention_lzma_v1") + BUILD_52_RET_LZMA_V2=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl5218x_retention_lzma_v2") + BUILD_52_RET_DUAL=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl5218x_retention_dual_mode") + + BUILD_52_CS_V1=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl5218x_retention_v1") + BUILD_52_CS_V2=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl5218x_retention_v2") + BUILD_52_CS_LZMA_V1=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl5218x_retention_lzma_v1") + BUILD_52_CS_LZMA_V2=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl5218x_retention_lzma_v2") + + # TL7218X Targets + BUILD_72_DEFAULT=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl7218x_default") + BUILD_72_2M_FLASH_LZMA_V1=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl7218x_2m_flash_lzma_v1") + BUILD_72_2M_FLASH_LZMA_V2=$(get_build_dir "$LIGHTING_APP_DIR" "build_tl7218x_2m_flash_lzma_v2") + + BUILD_72_RET_DEFAULT=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl7218x_retention_default") + BUILD_72_RET_LZMA_V1=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl7218x_retention_lzma_v1") + BUILD_72_RET_LZMA_V2=$(get_build_dir "$LIGHT_SWITCH_APP_DIR" "build_tl7218x_retention_lzma_v2") + + BUILD_72_CS_V1=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl7218x_retention_v1") + BUILD_72_CS_V2=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl7218x_retention_v2") + BUILD_72_CS_LZMA_V1=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl7218x_retention_lzma_v1") + BUILD_72_CS_LZMA_V2=$(get_build_dir "$CONTACT_SENSOR_APP_DIR" "build_tl7218x_retention_lzma_v2") + + echo "" + echo "=== Verifying firmware versions ===" + for dir in \ + "$BUILD_32_DEFAULT" "$BUILD_32_2M_FLASH_LZMA_V1" "$BUILD_32_2M_FLASH_LZMA_V2" \ + "$BUILD_32_4M_DUAL" "$BUILD_32_RET_DEFAULT" "$BUILD_32_RET_LZMA_V1" \ + "$BUILD_32_RET_LZMA_V2" "$BUILD_32_RET_DUAL" "$BUILD_32_CS_V1" \ + "$BUILD_32_CS_V2" "$BUILD_32_CS_LZMA_V1" "$BUILD_32_CS_LZMA_V2" \ + "$BUILD_52_DEFAULT" "$BUILD_52_2M_FLASH_LZMA_V1" \ + "$BUILD_52_2M_FLASH_LZMA_V2" "$BUILD_52_4M_DUAL" "$BUILD_52_RET_DEFAULT" \ + "$BUILD_52_RET_LZMA_V1" "$BUILD_52_RET_LZMA_V2" "$BUILD_52_RET_DUAL" \ + "$BUILD_52_CS_V1" "$BUILD_52_CS_V2" "$BUILD_52_CS_LZMA_V1" "$BUILD_52_CS_LZMA_V2" \ + "$BUILD_72_DEFAULT" "$BUILD_72_2M_FLASH_LZMA_V1" \ + "$BUILD_72_2M_FLASH_LZMA_V2" "$BUILD_72_RET_DEFAULT" "$BUILD_72_RET_LZMA_V1" \ + "$BUILD_72_RET_LZMA_V2" "$BUILD_72_CS_V1" \ + "$BUILD_72_CS_V2" "$BUILD_72_CS_LZMA_V1" "$BUILD_72_CS_LZMA_V2"; do + if [ -d "$dir" ] && [ -f "$dir/zephyr/.config" ]; then + version=$(grep CONFIG_CHIP_DEVICE_SOFTWARE_VERSION "$dir/zephyr/.config" 2>/dev/null | cut -d'=' -f2 || echo "unknown") + echo "$dir: CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=$version" + fi + done + + echo "" + echo "=== Copying Lighting App files (TL3238X) ===" + if [ -n "$BUILD_32_DEFAULT" ] && [ -f "$BUILD_32_DEFAULT/zephyr/merged.bin" ]; then + cp "$BUILD_32_DEFAULT/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_default.bin" + echo "Copied from $BUILD_32_DEFAULT: $PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_default.bin" + fi + if [ -n "$BUILD_32_2M_FLASH_LZMA_V1" ] && [ -f "$BUILD_32_2M_FLASH_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_32_2M_FLASH_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_32_2M_FLASH_LZMA_V1: $PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_32_2M_FLASH_LZMA_V2" ] && [ -f "$BUILD_32_2M_FLASH_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_32_2M_FLASH_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_32_2M_FLASH_LZMA_V2: $PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_32_2M_FLASH_LZMA_V2" ] && [ -f "$BUILD_32_2M_FLASH_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_32_2M_FLASH_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_32_2M_FLASH_LZMA_V2: $PKG_DIR/feature-test/lighting/tl3238x/lighting-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + if [ -n "$BUILD_32_4M_DUAL" ] && [ -f "$BUILD_32_4M_DUAL/zephyr/merged.bin" ]; then + cp "$BUILD_32_4M_DUAL/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl3238x/lighting-app_4m_flash_dual_mode.bin" + echo "Copied from $BUILD_32_4M_DUAL: $PKG_DIR/feature-test/lighting/tl3238x/lighting-app_4m_flash_dual_mode.bin" + fi + + echo "" + echo "=== Copying Lighting App files (TL5218X) ===" + if [ -n "$BUILD_52_DEFAULT" ] && [ -f "$BUILD_52_DEFAULT/zephyr/merged.bin" ]; then + cp "$BUILD_52_DEFAULT/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_default.bin" + echo "Copied from $BUILD_52_DEFAULT: $PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_default.bin" + fi + if [ -n "$BUILD_52_2M_FLASH_LZMA_V1" ] && [ -f "$BUILD_52_2M_FLASH_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_52_2M_FLASH_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_52_2M_FLASH_LZMA_V1: $PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_52_2M_FLASH_LZMA_V2" ] && [ -f "$BUILD_52_2M_FLASH_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_52_2M_FLASH_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_52_2M_FLASH_LZMA_V2: $PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_52_2M_FLASH_LZMA_V2" ] && [ -f "$BUILD_52_2M_FLASH_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_52_2M_FLASH_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_52_2M_FLASH_LZMA_V2: $PKG_DIR/feature-test/lighting/tl5218x/lighting-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + if [ -n "$BUILD_52_4M_DUAL" ] && [ -f "$BUILD_52_4M_DUAL/zephyr/merged.bin" ]; then + cp "$BUILD_52_4M_DUAL/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl5218x/lighting-app_4m_flash_dual_mode.bin" + echo "Copied from $BUILD_52_4M_DUAL: $PKG_DIR/feature-test/lighting/tl5218x/lighting-app_4m_flash_dual_mode.bin" + fi + + echo "" + echo "=== Copying Lighting App files (TL7218X) ===" + if [ -n "$BUILD_72_DEFAULT" ] && [ -f "$BUILD_72_DEFAULT/zephyr/merged.bin" ]; then + cp "$BUILD_72_DEFAULT/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_default.bin" + echo "Copied from $BUILD_72_DEFAULT: $PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_default.bin" + fi + if [ -n "$BUILD_72_2M_FLASH_LZMA_V1" ] && [ -f "$BUILD_72_2M_FLASH_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_72_2M_FLASH_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_72_2M_FLASH_LZMA_V1: $PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_72_2M_FLASH_LZMA_V2" ] && [ -f "$BUILD_72_2M_FLASH_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_72_2M_FLASH_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_72_2M_FLASH_LZMA_V2: $PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_72_2M_FLASH_LZMA_V2" ] && [ -f "$BUILD_72_2M_FLASH_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_72_2M_FLASH_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_72_2M_FLASH_LZMA_V2: $PKG_DIR/feature-test/lighting/tl7218x/lighting-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + + echo "" + echo "=== Copying Light Switch App files (TL3238X) ===" + if [ -n "$BUILD_32_RET_DEFAULT" ] && [ -f "$BUILD_32_RET_DEFAULT/zephyr/merged.bin" ]; then + cp "$BUILD_32_RET_DEFAULT/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_default.bin" + echo "Copied from $BUILD_32_RET_DEFAULT: $PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_default.bin" + fi + if [ -n "$BUILD_32_RET_LZMA_V1" ] && [ -f "$BUILD_32_RET_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_32_RET_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_32_RET_LZMA_V1: $PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_32_RET_LZMA_V2" ] && [ -f "$BUILD_32_RET_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_32_RET_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_32_RET_LZMA_V2: $PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_32_RET_LZMA_V2" ] && [ -f "$BUILD_32_RET_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_32_RET_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_32_RET_LZMA_V2: $PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + if [ -n "$BUILD_32_RET_DUAL" ] && [ -f "$BUILD_32_RET_DUAL/zephyr/merged.bin" ]; then + cp "$BUILD_32_RET_DUAL/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_dual_mode.bin" + echo "Copied from $BUILD_32_RET_DUAL: $PKG_DIR/feature-test/light-switch/tl3238x/light-switch-app_2m_flash_dual_mode.bin" + fi + + echo "" + echo "=== Copying Light Switch App files (TL5218X) ===" + if [ -n "$BUILD_52_RET_DEFAULT" ] && [ -f "$BUILD_52_RET_DEFAULT/zephyr/merged.bin" ]; then + cp "$BUILD_52_RET_DEFAULT/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_default.bin" + echo "Copied from $BUILD_52_RET_DEFAULT: $PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_default.bin" + fi + if [ -n "$BUILD_52_RET_LZMA_V1" ] && [ -f "$BUILD_52_RET_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_52_RET_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_52_RET_LZMA_V1: $PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_52_RET_LZMA_V2" ] && [ -f "$BUILD_52_RET_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_52_RET_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_52_RET_LZMA_V2: $PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_52_RET_LZMA_V2" ] && [ -f "$BUILD_52_RET_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_52_RET_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_52_RET_LZMA_V2: $PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + if [ -n "$BUILD_52_RET_DUAL" ] && [ -f "$BUILD_52_RET_DUAL/zephyr/merged.bin" ]; then + cp "$BUILD_52_RET_DUAL/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_dual_mode.bin" + echo "Copied from $BUILD_52_RET_DUAL: $PKG_DIR/feature-test/light-switch/tl5218x/light-switch-app_2m_flash_dual_mode.bin" + fi + + echo "" + echo "=== Copying Light Switch App files (TL7218X) ===" + if [ -n "$BUILD_72_RET_DEFAULT" ] && [ -f "$BUILD_72_RET_DEFAULT/zephyr/merged.bin" ]; then + cp "$BUILD_72_RET_DEFAULT/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_default.bin" + echo "Copied from $BUILD_72_RET_DEFAULT: $PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_default.bin" + fi + if [ -n "$BUILD_72_RET_LZMA_V1" ] && [ -f "$BUILD_72_RET_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_72_RET_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_72_RET_LZMA_V1: $PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_72_RET_LZMA_V2" ] && [ -f "$BUILD_72_RET_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_72_RET_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_72_RET_LZMA_V2: $PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_72_RET_LZMA_V2" ] && [ -f "$BUILD_72_RET_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_72_RET_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_72_RET_LZMA_V2: $PKG_DIR/feature-test/light-switch/tl7218x/light-switch-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + + echo "" + echo "=== Copying Contact Sensor App files (TL3238X) ===" + if [ -n "$BUILD_32_CS_V1" ] && [ -f "$BUILD_32_CS_V1/zephyr/merged.bin" ]; then + cp "$BUILD_32_CS_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_v1.bin" + echo "Copied from $BUILD_32_CS_V1: $PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_v1.bin" + fi + if [ -n "$BUILD_32_CS_V2" ] && [ -f "$BUILD_32_CS_V2/zephyr/matter.ota" ]; then + cp "$BUILD_32_CS_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_v2_ota.ota" + echo "Copied from $BUILD_32_CS_V2: $PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_v2_ota.ota" + fi + if [ -n "$BUILD_32_CS_V2" ] && [ -f "$BUILD_32_CS_V2/zephyr/merged_dfu.bin" ]; then + cp "$BUILD_32_CS_V2/zephyr/merged_dfu.bin" "$PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_v2_dfu.bin" + echo "Copied from $BUILD_32_CS_V2: $PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_v2_dfu.bin" + fi + if [ -n "$BUILD_32_CS_LZMA_V1" ] && [ -f "$BUILD_32_CS_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_32_CS_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_32_CS_LZMA_V1: $PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_32_CS_LZMA_V2" ] && [ -f "$BUILD_32_CS_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_32_CS_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_32_CS_LZMA_V2: $PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_32_CS_LZMA_V2" ] && [ -f "$BUILD_32_CS_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_32_CS_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_32_CS_LZMA_V2: $PKG_DIR/feature-test/contact-sensor/tl3238x/contact-sensor-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + + echo "" + echo "=== Copying Contact Sensor App files (TL5218X) ===" + if [ -n "$BUILD_52_CS_V1" ] && [ -f "$BUILD_52_CS_V1/zephyr/merged.bin" ]; then + cp "$BUILD_52_CS_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_v1.bin" + echo "Copied from $BUILD_52_CS_V1: $PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_v1.bin" + fi + if [ -n "$BUILD_52_CS_V2" ] && [ -f "$BUILD_52_CS_V2/zephyr/matter.ota" ]; then + cp "$BUILD_52_CS_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_v2_ota.ota" + echo "Copied from $BUILD_52_CS_V2: $PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_v2_ota.ota" + fi + if [ -n "$BUILD_52_CS_V2" ] && [ -f "$BUILD_52_CS_V2/zephyr/merged_dfu.bin" ]; then + cp "$BUILD_52_CS_V2/zephyr/merged_dfu.bin" "$PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_v2_dfu.bin" + echo "Copied from $BUILD_52_CS_V2: $PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_v2_dfu.bin" + fi + if [ -n "$BUILD_52_CS_LZMA_V1" ] && [ -f "$BUILD_52_CS_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_52_CS_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_52_CS_LZMA_V1: $PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_52_CS_LZMA_V2" ] && [ -f "$BUILD_52_CS_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_52_CS_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_52_CS_LZMA_V2: $PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_52_CS_LZMA_V2" ] && [ -f "$BUILD_52_CS_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_52_CS_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_52_CS_LZMA_V2: $PKG_DIR/feature-test/contact-sensor/tl5218x/contact-sensor-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + + echo "" + echo "=== Copying Contact Sensor App files (TL7218X) ===" + if [ -n "$BUILD_72_CS_V1" ] && [ -f "$BUILD_72_CS_V1/zephyr/merged.bin" ]; then + cp "$BUILD_72_CS_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_v1.bin" + echo "Copied from $BUILD_72_CS_V1: $PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_v1.bin" + fi + if [ -n "$BUILD_72_CS_V2" ] && [ -f "$BUILD_72_CS_V2/zephyr/matter.ota" ]; then + cp "$BUILD_72_CS_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_v2_ota.ota" + echo "Copied from $BUILD_72_CS_V2: $PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_v2_ota.ota" + fi + if [ -n "$BUILD_72_CS_V2" ] && [ -f "$BUILD_72_CS_V2/zephyr/merged_dfu.bin" ]; then + cp "$BUILD_72_CS_V2/zephyr/merged_dfu.bin" "$PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_v2_dfu.bin" + echo "Copied from $BUILD_72_CS_V2: $PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_v2_dfu.bin" + fi + if [ -n "$BUILD_72_CS_LZMA_V1" ] && [ -f "$BUILD_72_CS_LZMA_V1/zephyr/merged.bin" ]; then + cp "$BUILD_72_CS_LZMA_V1/zephyr/merged.bin" "$PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_lzma_v1.bin" + echo "Copied from $BUILD_72_CS_LZMA_V1: $PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_lzma_v1.bin" + fi + if [ -n "$BUILD_72_CS_LZMA_V2" ] && [ -f "$BUILD_72_CS_LZMA_V2/zephyr/matter.ota" ]; then + cp "$BUILD_72_CS_LZMA_V2/zephyr/matter.ota" "$PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_lzma_v2_ota.ota" + echo "Copied from $BUILD_72_CS_LZMA_V2: $PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_lzma_v2_ota.ota" + fi + if [ -n "$BUILD_72_CS_LZMA_V2" ] && [ -f "$BUILD_72_CS_LZMA_V2/zephyr/merged_dfu.lzma.bin" ]; then + cp "$BUILD_72_CS_LZMA_V2/zephyr/merged_dfu.lzma.bin" "$PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_lzma_v2_dfu.lzma.bin" + echo "Copied from $BUILD_72_CS_LZMA_V2: $PKG_DIR/feature-test/contact-sensor/tl7218x/contact-sensor-app_2m_flash_lzma_v2_dfu.lzma.bin" + fi + + echo "" + echo "=== Extraction complete! ===" + echo "Package directory: $PKG_DIR" +} + +# Function to add firmware entries to README +add_firmware_entry() { + local file="$1" + local desc="$2" + echo "| $file | $desc |" >>"$PKG_DIR/README.md" +} + +# Generate README function +generate_readme() { + echo "" + echo "=== Generating README.md ===" + + if [ -z "$PKG_DIR" ]; then + # Try to find last package directory + PARENT_DIR="$(cd "$CONNECTEDHOME_DIR/.." && pwd)" + BASE_PKG_DIR="$PARENT_DIR/Matter_test_materials" + if [ -f "$BASE_PKG_DIR/.last_pkg_dir" ]; then + PKG_DIR=$(cat "$BASE_PKG_DIR/.last_pkg_dir") + fi + fi + + if [ -z "$PKG_DIR" ] || [ ! -d "$PKG_DIR" ]; then + echo "Error: Package directory not specified or not found" + return 1 + fi + + # Extract date from directory name + DATE=$(basename "$PKG_DIR" | grep -oE '[0-9]{8}_[0-9]{6}' || date +%Y%m%d_%H%M%S) + + # Function to get git branch from directory + get_git_branch() { + local dir="$1" + if [ -d "$dir/.git" ]; then + git -C "$dir" rev-parse --abbrev-ref HEAD + fi + } + + # Function to get git commit (short) from directory + get_git_commit() { + local dir="$1" + if [ -d "$dir/.git" ]; then + git -C "$dir" rev-parse --short HEAD + fi + } + + # Get repo paths + HAL_TELINK_DIR="$(cd "$CONNECTEDHOME_DIR/../modules/hal/telink" 2>/dev/null && pwd)" + + # Get branch and commit info + MATTER_BRANCH="$(get_git_branch "$CONNECTEDHOME_DIR")" + MATTER_COMMIT="$(get_git_commit "$CONNECTEDHOME_DIR")" + + ZEPHYR_BRANCH="$(get_git_branch "$ZEPHYR_BASE")" + ZEPHYR_COMMIT="$(get_git_commit "$ZEPHYR_BASE")" + + HAL_TELINK_BRANCH="$(get_git_branch "$HAL_TELINK_DIR")" + HAL_TELINK_COMMIT="$(get_git_commit "$HAL_TELINK_DIR")" + + # Handle detached HEAD for display + if [ "$MATTER_BRANCH" = "HEAD" ]; then + MATTER_BRANCH="(detached HEAD)" + fi + if [ "$ZEPHYR_BRANCH" = "HEAD" ]; then + ZEPHYR_BRANCH="(detached HEAD)" + fi + if [ "$HAL_TELINK_BRANCH" = "HEAD" ]; then + HAL_TELINK_BRANCH="(detached HEAD)" + fi + + cat >"$PKG_DIR/README.md" <>"$PKG_DIR/README.md" <>"$PKG_DIR/README.md" <>"$PKG_DIR/README.md" <>"$PKG_DIR/README.md" <>"$PKG_DIR/README.md" <>"$PKG_DIR/README.md" </dev/null | + grep '^tl_v' | head -1 || true) + if [ -z "$version" ]; then + version=$(git -C "$CONNECTEDHOME_DIR" tag --list 'tl_v*' \ + --sort=-creatordate | head -1) + fi + + if [ -z "$version" ]; then + echo "Warning: no $(tl_v*) git tag found; skipping release note snapshot." + echo " Tag the release (e.g. \`git tag tl_v1.0.0\`) to enable snapshotting." + return 0 + fi + + local snapshot="$releases_dir/telink_release_notes_$version.md" + + if [ -f "$snapshot" ]; then + echo "Versioned snapshot already exists, leaving untouched:" + echo " $snapshot" + return 0 + fi + + cp "$working_copy" "$snapshot" + echo "Created versioned release note snapshot:" + echo " $snapshot" + echo " (version: $version)" +} + +# Zip firmware function +zip_firmware() { + echo "" + echo "=== Creating zip archive ===" + + if [ -z "$PKG_DIR" ]; then + # Try to find last package directory + PARENT_DIR="$(cd "$CONNECTEDHOME_DIR/.." && pwd)" + BASE_PKG_DIR="$PARENT_DIR/Matter_test_materials" + if [ -f "$BASE_PKG_DIR/.last_pkg_dir" ]; then + PKG_DIR=$(cat "$BASE_PKG_DIR/.last_pkg_dir") + fi + fi + + if [ -z "$PKG_DIR" ] || [ ! -d "$PKG_DIR" ]; then + echo "Error: Package directory not specified or not found" + return 1 + fi + + PKG_NAME=$(basename "$PKG_DIR") + ZIP_NAME="$BASE_PKG_DIR/$PKG_NAME.zip" + + cd "$BASE_PKG_DIR" + zip -r "$ZIP_NAME" "$PKG_NAME" + cd "$CONNECTEDHOME_DIR" + echo "Created: $ZIP_NAME" + + echo "" + echo "=== Package content ===" + ls -laR "$PKG_DIR" + + echo "" + echo "=== Packaging complete! ===" + echo "Package: $ZIP_NAME" +} + +# Main execution +echo "Starting package process for Telink Matter firmware..." +echo "Timestamp: $DATE" + +if [ "$DO_BUILD" = true ]; then + # Prepare for dual-mode if we need to build dual-mode targets + prepare_dual_mode + + if [ "$GENERATE_LIGHTING" = true ]; then + generate_lighting_app + fi + + if [ "$GENERATE_SWITCH" = true ]; then + generate_light_switch + fi + + echo "" + echo "All generations complete!" + echo "Generate timestamp: $DATE" + + # Cleanup temporary Zigbee-SampleDemo.bin + cleanup_zigbee_sample +fi + +if [ "$DO_EXTRACT" = true ]; then + extract_firmware +fi + +if [ "$DO_README" = true ]; then + generate_readme +fi + +# Snapshot the release note alongside README generation (release documentation +# step). Also runs on --all and --zip so a packaged release always gets a +# versioned release note archive. +if [ "$DO_README" = true ] || [ "$DO_ZIP" = true ]; then + snapshot_release_note +fi + +if [ "$DO_ZIP" = true ]; then + zip_firmware +fi + +echo "" +echo "All tasks complete!" diff --git a/scripts/tools/telink/process_binaries.py b/scripts/tools/telink/process_binaries.py index fd6d05c64bcb..43084d5df0b7 100755 --- a/scripts/tools/telink/process_binaries.py +++ b/scripts/tools/telink/process_binaries.py @@ -179,7 +179,8 @@ def compress_lzma_firmware(input_file, output_file): print(f"Image footer is written to {dfu_output_name}") print("Image for DFU over BLE SMP is ready!") - os.remove('empty.txt') + # to avoid need -p compile every time. + # os.remove('empty.txt') if build_conf.getboolean('CONFIG_TELINK_OTA_BUTTON_TEST'): merge_binaries('merged.bin', build_conf['CONFIG_SIGNED_OTA_IMAGE_FILE_NAME'], diff --git a/scripts/tools/telink/update_zephyr.py b/scripts/tools/telink/update_zephyr.py index fe735df0ccaa..abcb342c6d57 100755 --- a/scripts/tools/telink/update_zephyr.py +++ b/scripts/tools/telink/update_zephyr.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -# Copyright (c) 2023 Project CHIP Authors +# Copyright (c) 2023-2026 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. @@ -22,37 +22,159 @@ import sys +def fetch_telink_ble_sdk(repo_url, commit_hash): + """ + Fetch Telink BLE SDK from specified repository and commit. + + Args: + repo_url: Git repository URL for the BLE SDK + commit_hash: Specific commit hash to checkout + """ + zephyr_base = os.getenv("ZEPHYR_BASE") + if not zephyr_base: + raise RuntimeError("ZEPHYR_BASE environment variable not set") + + # fetch_sdk.sh is located in modules/hal/telink/hal_v2 under ZEPHYR_BASE + sdk_script_dir = os.path.join(zephyr_base, "../modules/hal/telink/hal_v2") + sdk_script = os.path.join(sdk_script_dir, "fetch_sdk.sh") + + print(f"ZEPHYR_BASE: {zephyr_base}") + print(f"Looking for fetch_sdk.sh at: {sdk_script}") + + # Change to the directory containing fetch_sdk.sh + os.chdir(sdk_script_dir) + print(f"Current directory: {os.getcwd()}") + print(f"Directory contents: {os.listdir('.')}") + + # Check if fetch_sdk.sh exists + if not os.path.exists("fetch_sdk.sh"): + raise RuntimeError(f"fetch_sdk.sh not found in {sdk_script_dir}") + + # Execute fetch_sdk.sh + print(f"Fetching Telink BLE SDK with commit {commit_hash}...") + # subprocess.run(["chmod", "+x", "fetch_sdk.sh"], check=True) + subprocess.run(["./fetch_sdk.sh", repo_url, commit_hash], check=True) + + print("Telink BLE SDK fetch completed.") + + +def update_zephyr(remote_url, commit_hash): + """ + Update Zephyr repository to specific commit. + + Args: + remote_url: Git repository URL for Zephyr + commit_hash: Specific commit hash to checkout + """ + zephyr_base = os.getenv("ZEPHYR_BASE") + if not zephyr_base: + raise RuntimeError("ZEPHYR_BASE environment variable not set") + + remote_name = 'custom' + + # Check if remote already exists, if so, update it + result = subprocess.run(['git', '-C', zephyr_base, 'remote', 'get-url', remote_name], + capture_output=True, text=True) + if result.returncode == 0: + # Remote exists, update its URL + print(f"Remote '{remote_name}' already exists, updating URL...") + subprocess.run(['git', '-C', zephyr_base, 'remote', 'set-url', remote_name, remote_url], check=True) + else: + # Remote doesn't exist, add it + print(f"Adding remote: {remote_url}") + subprocess.run(['git', '-C', zephyr_base, 'remote', 'add', remote_name, remote_url], check=True) + + # Fetch updates from remote + # If commit_hash is a PR ref (e.g. pull/782/head), fetch it explicitly + # since it lives under refs/pull/*/head and is not fetched by default. + print(f"Fetching from remote: {remote_name}") + if commit_hash.startswith('pull/') or commit_hash.startswith('refs/pull/'): + ref = commit_hash if commit_hash.startswith('refs/') else f'refs/{commit_hash}' + command = ['git', '-C', zephyr_base, 'fetch', remote_name, ref] + subprocess.run(command, check=True) + # Resolve the fetched ref to a commit hash for checkout + result = subprocess.run(['git', '-C', zephyr_base, 'rev-parse', 'FETCH_HEAD'], + capture_output=True, text=True, check=True) + checkout_target = result.stdout.strip() + else: + command = ['git', '-C', zephyr_base, 'fetch', remote_name] + subprocess.run(command, check=True) + checkout_target = commit_hash + + # Checkout the specified commit in detached HEAD state to avoid + # disrupting any branch the user may currently have checked out. + print(f"Checking out commit: {checkout_target}") + command = ['git', '-C', zephyr_base, 'checkout', '--detach', checkout_target] + subprocess.run(command, check=True) + + # Update west modules + print("Updating west modules...") + command = ['west', 'update', '-n', '-f', 'smart'] + subprocess.run(command, check=True) + + # Fetch blobs + print("Fetching hal_telink blobs...") + command = ['west', 'blobs', 'fetch', 'hal_telink'] + subprocess.run(command, check=True) + + def main(): + """Main entry point for the script.""" + parser = argparse.ArgumentParser( + description='Update Telink Zephyr to specific revision and fetch BLE SDK.' + ) + parser.add_argument("remote", + default="https://github.com/telink-semi/zephyr", + help="New remote URL for the Zephyr repository.") + parser.add_argument("hash", + help="Update Telink Zephyr to specific revision.") + parser.add_argument("--sdk-repo", + default="https://github.com/telink-semi/tl_ble_sdk_zephyr.git", + help="Repository URL for Telink BLE SDK (default: tl_ble_sdk_zephyr.git)") + parser.add_argument("--sdk-hash", + default="f50d422d780efb73af939650ef7b8c6bf5a0b99b", + help="Specific commit hash for BLE SDK") + parser.add_argument("--skip-sdk", + action="store_true", + help="Skip fetching Telink BLE SDK") + + args = parser.parse_args() try: + # Set ZEPHYR_BASE environment variable zephyr_base = os.getenv("ZEPHYR_BASE") if not zephyr_base: zephyr_base = os.getenv("TELINK_ZEPHYR_BASE") - os.environ['ZEPHYR_BASE'] = zephyr_base + if zephyr_base: + os.environ['ZEPHYR_BASE'] = zephyr_base + if not zephyr_base: raise RuntimeError( - "No ZEPHYR_BASE environment variable found, please set ZEPHYR_BASE to a zephyr repository path.") + "No ZEPHYR_BASE or TELINK_ZEPHYR_BASE environment variable found. " + "Please set to a zephyr repository path." + ) - parser = argparse.ArgumentParser( - description='Script helping to update Telink Zephyr to specific revision.') - parser.add_argument("hash", help="Update Telink Zephyr to specific revision.") + # Update Zephyr repository + print("=" * 60) + print("Step 1: Updating Zephyr repository...") + print("=" * 60) + update_zephyr(args.remote, args.hash) - args = parser.parse_args() + # Fetch BLE SDK (unless skipped) + if not args.skip_sdk: + print("\n" + "=" * 60) + print("Step 2: Fetching Telink BLE SDK...") + print("=" * 60) + fetch_telink_ble_sdk(args.sdk_repo, args.sdk_hash) + else: + print("\nSkipping BLE SDK fetch as requested.") - command = ['git', '-C', zephyr_base, 'fetch'] - subprocess.run(command, check=True) - - command = ['git', '-C', zephyr_base, 'reset', args.hash, '--hard'] - subprocess.run(command, check=True) - - command = ['west', 'update', '-o=--depth=1', '-n', '-f', 'smart'] - subprocess.run(command, check=True) - - command = ['west', 'blobs', 'fetch', 'hal_telink'] - subprocess.run(command, check=True) + print("\n" + "=" * 60) + print("All operations completed successfully!") + print("=" * 60) except (RuntimeError, subprocess.CalledProcessError) as e: - print(e) + print(f"\nError: {e}") sys.exit(1) diff --git a/src/app/chip_data_model.cmake b/src/app/chip_data_model.cmake index 75b906771564..77f38cd4ecb1 100644 --- a/src/app/chip_data_model.cmake +++ b/src/app/chip_data_model.cmake @@ -171,6 +171,7 @@ function(chip_configure_data_model APP_TARGET) ${CHIP_APP_BASE_DIR}/persistence/AttributePersistenceMigration.cpp ${CHIP_APP_BASE_DIR}/persistence/AttributePersistenceProviderInstance.cpp ${CHIP_APP_BASE_DIR}/persistence/DefaultAttributePersistenceProvider.cpp + ${CHIP_APP_BASE_DIR}/persistence/DeferredAttributePersistenceProvider.cpp ${CODEGEN_DATA_MODEL_SOURCES} ${APP_GEN_FILES} ${APP_TEMPLATES_GEN_FILES} diff --git a/src/app/clusters/basic-information/DeviceLayerBasicInformationPolicy.h b/src/app/clusters/basic-information/DeviceLayerBasicInformationPolicy.h index 05d93ad6a0aa..199e5051c1c7 100644 --- a/src/app/clusters/basic-information/DeviceLayerBasicInformationPolicy.h +++ b/src/app/clusters/basic-information/DeviceLayerBasicInformationPolicy.h @@ -82,6 +82,13 @@ class DeviceLayerBasicInformationPolicy return mDeviceInstanceInfoProvider.GetManufacturingDate(year, month, day); } +#if CHIP_DEVICE_SECURE_PROGRAMMING + CHIP_ERROR GetManufacturingDateString(char * buf, size_t bufSize) + { + return mDeviceInstanceInfoProvider.GetManufacturingDateString(buf, bufSize); + } +#endif /* CHIP_DEVICE_SECURE_PROGRAMMING */ + CHIP_ERROR GetManufacturingDateSuffix(MutableCharSpan & suffixBuffer) { return mDeviceInstanceInfoProvider.GetManufacturingDateSuffix(suffixBuffer); diff --git a/src/app/clusters/basic-information/PolicyBased.h b/src/app/clusters/basic-information/PolicyBased.h index 09a84a11528b..bc76f5453525 100644 --- a/src/app/clusters/basic-information/PolicyBased.h +++ b/src/app/clusters/basic-information/PolicyBased.h @@ -296,9 +296,14 @@ DataModel::ActionReturnStatus PolicyBased::ReadAttribute(const DataModel uint16_t manufacturingYear; uint8_t manufacturingMonth; uint8_t manufacturingDayOfMonth; + +#if defined(CHIP_DEVICE_SECURE_PROGRAMMING) && CHIP_DEVICE_SECURE_PROGRAMMING + CHIP_ERROR status = mPolicy.GetManufacturingDateString(manufacturingDateString, sizeof(manufacturingDateString)); +#else size_t totalManufacturingDateLen = 0; MutableCharSpan vendorSuffixSpan(manufacturingDateString + kMaxDateLength, kMaxSuffixLength); CHIP_ERROR status = mPolicy.GetManufacturingDate(manufacturingYear, manufacturingMonth, manufacturingDayOfMonth); +#endif /* defined(CHIP_DEVICE_SECURE_PROGRAMMING) && CHIP_DEVICE_SECURE_PROGRAMMING */ if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) { @@ -310,6 +315,9 @@ DataModel::ActionReturnStatus PolicyBased::ReadAttribute(const DataModel } ReturnErrorOnFailure(status); +#if defined(CHIP_DEVICE_SECURE_PROGRAMMING) && CHIP_DEVICE_SECURE_PROGRAMMING + return aEncoder.Encode(CharSpan(manufacturingDateString, strnlen(manufacturingDateString, kMaxLen))); +#else snprintf(manufacturingDateString, sizeof(manufacturingDateString), "%04u%02u%02u", manufacturingYear, manufacturingMonth, manufacturingDayOfMonth); @@ -321,6 +329,7 @@ DataModel::ActionReturnStatus PolicyBased::ReadAttribute(const DataModel } return encoder.Encode(CharSpan(manufacturingDateString, totalManufacturingDateLen)); +#endif /* defined(CHIP_DEVICE_SECURE_PROGRAMMING) && CHIP_DEVICE_SECURE_PROGRAMMING */ } case PartNumber::Id: return ReadConfigurationString([this](char * buf, size_t size) { return mPolicy.GetPartNumber(buf, size); }, encoder); diff --git a/src/include/platform/DeviceInstanceInfoProvider.h b/src/include/platform/DeviceInstanceInfoProvider.h index 23bc9659cd7f..753655caaf72 100644 --- a/src/include/platform/DeviceInstanceInfoProvider.h +++ b/src/include/platform/DeviceInstanceInfoProvider.h @@ -167,6 +167,19 @@ class DeviceInstanceInfoProvider return CHIP_NO_ERROR; } + /** + * @brief Obtain a manufacturing date string from the device's factory data. + * + * @param[in, out] buf Buffer to copy string. + * On CHIP_NO_ERROR return from this function this buffer will be null-terminated. + * On error CHIP_ERROR_BUFFER_TOO_SMALL there is no guarantee that buffer will be null-terminated. + * @param[in] bufSize Size of data, including the null terminator, that can be written to buf. + * This size should be +1 higher than maximum possible string. + * @returns CHIP_NO_ERROR on success, or another CHIP_ERROR from the underlying implementation + * if access fails. + */ + virtual CHIP_ERROR GetManufacturingDateString(char * buf, size_t bufSize) { return CHIP_ERROR_NOT_IMPLEMENTED; } + /** * @brief Obtain a Hardware Version from the device's factory data. * @@ -325,4 +338,4 @@ DeviceInstanceInfoProvider * TestOnlyTryGetDeviceInstanceInfoProvider(); #endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST } // namespace DeviceLayer -} // namespace chip +} // namespace chip \ No newline at end of file diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index ece81909c87d..e1522c97e7ca 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -799,6 +799,11 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() { ChipLogProgress(DeviceLayer, " Manufacturing Date: (not set)"); } + + /* Add print: Modify Manufacturing Date Format. Delete if it is not needed */ + char mfgDate[ConfigurationManager::kMaxManufacturingDateLength + 1]; + err = deviceInstanceInfoProvider->GetManufacturingDateString(mfgDate, sizeof(mfgDate)); + ChipLogProgress(DeviceLayer, " Manufacturing Date String: %s", (err == CHIP_NO_ERROR) ? mfgDate : "(not set)"); } { diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index 0f8e709176e3..8b53ee680fdd 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -72,6 +72,10 @@ extern "C" void otSysProcessDrivers(otInstance * aInstance); extern "C" void otAppCliInit(otInstance * aInstance); #endif +#if defined CONFIG_IEEE802154_TLX_OPTIMIZATION +bool isThreadCommissioned = false; +#endif /* CONFIG_IEEE802154_TLX_OPTIMIZATION */ + namespace chip { namespace DeviceLayer { namespace Internal { @@ -374,6 +378,14 @@ bool GenericThreadStackManagerImpl_OpenThread::_IsThreadAttached() curRole = otThreadGetDeviceRole(mOTInst); Impl()->UnlockThreadStack(); +#if defined CONFIG_IEEE802154_TLX_OPTIMIZATION + if ((curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED)) + { + if (isThreadCommissioned == false) + isThreadCommissioned = true; + } +#endif /* CONFIG_IEEE802154_TLX_OPTIMIZATION */ + return (curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED); } diff --git a/src/platform/Zephyr/BLEManagerImpl.cpp b/src/platform/Zephyr/BLEManagerImpl.cpp index c5a4b5f5825f..50a6dc54961b 100644 --- a/src/platform/Zephyr/BLEManagerImpl.cpp +++ b/src/platform/Zephyr/BLEManagerImpl.cpp @@ -98,6 +98,10 @@ const bt_uuid_128 UUID128_CHIPoBLEChar_TX = const bt_uuid_128 UUID128_CHIPoBLEChar_C3 = BT_UUID_INIT_128(0x04, 0x8F, 0x21, 0x83, 0x8A, 0x74, 0x7D, 0xB8, 0xF2, 0x45, 0x72, 0x87, 0x38, 0x02, 0x63, 0x64); #endif +#if CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE +const bt_uuid_128 UUID128_CHIPoBLEChar_ChipID = + BT_UUID_INIT_128(0x04, 0x8F, 0x21, 0x83, 0x8A, 0x74, 0x7D, 0xB8, 0xF2, 0x45, 0x72, 0x87, 0x38, 0x02, 0xA1, 0x01); +#endif /* CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE */ bt_uuid_16 UUID16_CHIPoBLEService = BT_UUID_INIT_16(0xFFF6); @@ -133,6 +137,12 @@ bt_gatt_attr sChipoBleAttributes[] = { BT_GATT_PERM_READ, BLEManagerImpl::HandleC3Read, nullptr, nullptr), #endif +#if CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE + BT_GATT_CHARACTERISTIC(&UUID128_CHIPoBLEChar_ChipID.uuid, + BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, + BLEManagerImpl::HandleChipIDRead, nullptr, nullptr), +#endif /* CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE */ }; bt_gatt_service sChipoBleService = BT_GATT_SERVICE(sChipoBleAttributes); @@ -1066,6 +1076,36 @@ ssize_t BLEManagerImpl::HandleC3Read(struct bt_conn * conId, const struct bt_gat } #endif +#if CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE +#ifdef __cplusplus +extern "C" { +#endif +#include "efuse.h" +#ifdef __cplusplus +} +#endif +#include +ssize_t BLEManagerImpl::HandleChipIDRead(struct bt_conn * conId, const struct bt_gatt_attr * attr, void * buf, uint16_t len, + uint16_t offset) +{ + // Example chip_id data storage (replace with actual chip_id value) + // uint8_t chip_id[] = { 0x42, 0xe3, 0x03, 0xb4, 0xcf, 0x3c, 0xe6, 0x32, 0x36, 0x37, 0x36, 0x42, 0x50, 0x55, 0x76, 0xce }; + ChipLogDetail(DeviceLayer, "Read request received for CHIPoBLE Chip ID (ConnId 0x%02x)", bt_conn_index(conId)); + + uint8_t chip_id[16] = { 0 }; + uint8_t ieee_addr[8] = { 0 }; + + if (efuse_get_ieee_addr(ieee_addr) != DRV_API_SUCCESS) + { + ChipLogDetail(DeviceLayer, "Failed to get chip ID."); + return 0; + } + + memcpy(chip_id, ieee_addr, 8); + return bt_gatt_attr_read(conId, attr, buf, len, offset, chip_id, sizeof(chip_id)); +} +#endif /* CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE */ + #ifdef CONFIG_CHIP_CUSTOM_BLE_ADV_DATA void BLEManagerImpl::SetCustomAdvertising(Span CustomAdvertising) { diff --git a/src/platform/Zephyr/BLEManagerImpl.h b/src/platform/Zephyr/BLEManagerImpl.h index 5e68d5450801..3c43bb7c17a9 100644 --- a/src/platform/Zephyr/BLEManagerImpl.h +++ b/src/platform/Zephyr/BLEManagerImpl.h @@ -155,6 +155,10 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING static ssize_t HandleC3Read(struct bt_conn * conn, const struct bt_gatt_attr * attr, void * buf, uint16_t len, uint16_t offset); #endif +#if CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE + static ssize_t HandleChipIDRead(struct bt_conn * conn, const struct bt_gatt_attr * attr, void * buf, uint16_t len, + uint16_t offset); +#endif /* CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE */ #ifdef CONFIG_CHIP_CUSTOM_BLE_ADV_DATA void SetCustomAdvertising(Span CustomAdvertising); void SetCustomScanResponse(Span CustomScanResponse); diff --git a/src/platform/Zephyr/ThreadStackManagerImpl.cpp b/src/platform/Zephyr/ThreadStackManagerImpl.cpp index 8a188a795ac3..859dbd1b956a 100644 --- a/src/platform/Zephyr/ThreadStackManagerImpl.cpp +++ b/src/platform/Zephyr/ThreadStackManagerImpl.cpp @@ -106,7 +106,7 @@ void ThreadStackManagerImpl::_UnlockThreadStack() #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT void ThreadStackManagerImpl::_WaitOnSrpClearAllComplete() { - k_sem_take(&mSrpClearAllSemaphore, K_SECONDS(2)); + k_sem_take(&mSrpClearAllSemaphore, K_MSEC(500)); } void ThreadStackManagerImpl::_NotifySrpClearAllComplete() diff --git a/src/platform/telink/CHIPDevicePlatformConfig.h b/src/platform/telink/CHIPDevicePlatformConfig.h index 094770311cef..b9658ed24e4d 100644 --- a/src/platform/telink/CHIPDevicePlatformConfig.h +++ b/src/platform/telink/CHIPDevicePlatformConfig.h @@ -108,7 +108,9 @@ #define CHIP_DEVICE_CONFIG_ENABLE_ETHERNET 0 #endif // CHIP_DEVICE_CONFIG_ENABLE_ETHERNET -#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION) +#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ + defined(CONFIG_SOC_RISCV_TELINK_TL721X) || defined(CONFIG_SOC_RISCV_TELINK_TL521X) || \ + defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION) #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE (256) #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE (256) #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (256) @@ -120,6 +122,18 @@ #define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0 #endif +#ifdef CONFIG_EXPOSE_CHIP_ID_VIA_BLE +#define CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE CONFIG_EXPOSE_CHIP_ID_VIA_BLE +#else +#define CHIP_DEVICE_EXPOSE_CHIP_ID_VIA_BLE 0 +#endif + +#ifdef CONFIG_SECURE_PROGRAMMING +#define CHIP_DEVICE_SECURE_PROGRAMMING CONFIG_SECURE_PROGRAMMING +#else +#define CHIP_DEVICE_SECURE_PROGRAMMING 0 +#endif + #if defined(CONFIG_SOC_RISCV_TELINK_TLX) || defined(CONFIG_SOC_RISCV_TELINK_B9X) #define CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION 0 #endif diff --git a/src/platform/telink/CHIPPlatformConfig.h b/src/platform/telink/CHIPPlatformConfig.h index fbc790667653..9d79ac664220 100644 --- a/src/platform/telink/CHIPPlatformConfig.h +++ b/src/platform/telink/CHIPPlatformConfig.h @@ -62,7 +62,8 @@ #define CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS 1 #endif // CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS -#ifdef CONFIG_SOC_RISCV_TELINK_TL321X +#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ + defined(CONFIG_SOC_RISCV_TELINK_TL721X) || defined(CONFIG_SOC_RISCV_TELINK_TL521X) #ifndef CHIP_CONFIG_MAX_GROUP_DATA_PEERS #define CHIP_CONFIG_MAX_GROUP_DATA_PEERS 5 @@ -72,9 +73,12 @@ #define CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_ENTRIES_PER_FABRIC 4 #endif // CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_ENTRIES_PER_FABRIC -#endif // CONFIG_SOC_RISCV_TELINK_TL321X +#endif /* defined(CONFIG_SOC_RISCV_TELINK_TL321X) || \ + defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ + defined(CONFIG_SOC_RISCV_TELINK_TL521X) */ -#if defined CONFIG_PM || defined CONFIG_SOC_RISCV_TELINK_TL321X +#if defined CONFIG_PM || defined CONFIG_SOC_RISCV_TELINK_TL321X || defined CONFIG_SOC_RISCV_TELINK_TL323X || \ + defined CONFIG_SOC_RISCV_TELINK_TL721X || defined CONFIG_SOC_RISCV_TELINK_TL521X #ifndef CHIP_CONFIG_MAX_GROUP_DATA_PEERS #define CHIP_CONFIG_MAX_GROUP_DATA_PEERS 7 @@ -104,12 +108,22 @@ #define CHIP_CONFIG_DEVICE_MAX_ACTIVE_DEVICES 2 #endif // CHIP_CONFIG_DEVICE_MAX_ACTIVE_DEVICES -#endif // CONFIG_PM || CONFIG_SOC_RISCV_TELINK_TL321X +#endif /* CONFIG_PM || CONFIG_SOC_RISCV_TELINK_TL321X || \ + CONFIG_SOC_RISCV_TELINK_TL323X || \ + CONFIG_SOC_RISCV_TELINK_TL521X */ #ifndef CHIP_CONFIG_MAX_FABRICS #define CHIP_CONFIG_MAX_FABRICS CONFIG_CHIP_MAX_FABRICS #endif // CHIP_CONFIG_MAX_FABRICS +#ifndef CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC +#define CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC 2 +#endif // CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC + +#ifndef CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_SUBJECTS_PER_ENTRY +#define CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_SUBJECTS_PER_ENTRY (4 * CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC) +#endif // CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_SUBJECTS_PER_ENTR + #ifdef CONFIG_CHIP_MAX_ACTIVE_CASE_CLIENTS #define CHIP_CONFIG_DEVICE_MAX_ACTIVE_CASE_CLIENTS CONFIG_CHIP_MAX_ACTIVE_CASE_CLIENTS #endif // CONFIG_CHIP_MAX_ACTIVE_CASE_CLIENTS diff --git a/src/platform/telink/FactoryDataParser.c b/src/platform/telink/FactoryDataParser.c index a2d4c26ede99..1584d7877377 100644 --- a/src/platform/telink/FactoryDataParser.c +++ b/src/platform/telink/FactoryDataParser.c @@ -26,7 +26,9 @@ #define MAX_FACTORY_DATA_NESTING_LEVEL 3 LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL); - +#if CHIP_DEVICE_SECURE_PROGRAMMING +static uint8_t dac_key_decrypt[32] = { 0 }; +#endif static inline bool uint16_decode(zcbor_state_t * states, uint16_t * value) { uint32_t u32; @@ -100,17 +102,29 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData } else if (strncmp("date", (const char *) currentString.value, currentString.len) == 0) { - // Date format is YYYY-MM-DD, so format needs to be validated and string parse to integer parts. - struct zcbor_string date; - res = res && zcbor_bstr_decode(states, &date); - if (date.len == 10 && isdigit(date.value[0]) && isdigit(date.value[1]) && isdigit(date.value[2]) && - isdigit(date.value[3]) && date.value[4] == '-' && isdigit(date.value[5]) && isdigit(date.value[6]) && - date.value[7] == '-' && isdigit(date.value[8]) && isdigit(date.value[9])) + // Format needs to be validated and string parse to integer parts. + struct zcbor_string * date = (struct zcbor_string *) &factoryData->mfg_date_str; + res = res && zcbor_bstr_decode(states, date); + + // First check for YYYY-MM-DD format (10 digits with hyphens) + if (date->len == 10 && isdigit(date->value[0]) && isdigit(date->value[1]) && isdigit(date->value[2]) && + isdigit(date->value[3]) && date->value[4] == '-' && isdigit(date->value[5]) && isdigit(date->value[6]) && + date->value[7] == '-' && isdigit(date->value[8]) && isdigit(date->value[9])) + { + factoryData->date_year = 1000 * (date->value[0] - '0') + 100 * (date->value[1] - '0') + + 10 * (date->value[2] - '0') + date->value[3] - '0'; + factoryData->date_month = 10 * (date->value[5] - '0') + date->value[6] - '0'; + factoryData->date_day = 10 * (date->value[8] - '0') + date->value[9] - '0'; + } + // Then check for YYYYMMDD or extended formats (8-16 digits) + else if ((date->len >= 8 && date->len <= 16) && isdigit(date->value[0]) && isdigit(date->value[1]) && + isdigit(date->value[2]) && isdigit(date->value[3]) && isdigit(date->value[4]) && isdigit(date->value[5]) && + isdigit(date->value[6]) && isdigit(date->value[7])) { - factoryData->date_year = - 1000 * (date.value[0] - '0') + 100 * (date.value[1] - '0') + 10 * (date.value[2] - '0') + date.value[3] - '0'; - factoryData->date_month = 10 * (date.value[5] - '0') + date.value[6] - '0'; - factoryData->date_day = 10 * (date.value[8] - '0') + date.value[9] - '0'; + factoryData->date_year = 1000 * (date->value[0] - '0') + 100 * (date->value[1] - '0') + + 10 * (date->value[2] - '0') + date->value[3] - '0'; + factoryData->date_month = 10 * (date->value[4] - '0') + date->value[5] - '0'; + factoryData->date_day = 10 * (date->value[6] - '0') + date->value[7] - '0'; } else { @@ -125,14 +139,22 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData { res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->rd_uid); } +#if !CHIP_DEVICE_SECURE_PROGRAMMING else if (strncmp("dac_cert", (const char *) currentString.value, currentString.len) == 0) { res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->dac_cert); + // LOG_INF("DAC cert len=%u", currentString.len); + // LOG_HEXDUMP_INF(currentString.value, + // currentString.len, + // "DAC CERT"); } else if (strncmp("dac_key", (const char *) currentString.value, currentString.len) == 0) { res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->dac_priv_key); + // LOG_INF("DAC priv key decrypted, len=%u", currentString.len); + // LOG_HEXDUMP_INF(currentString.value, currentString.len, "DAC PRIV KEY"); } +#endif else if (strncmp("pai_cert", (const char *) currentString.value, currentString.len) == 0) { res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->pai_cert); @@ -185,3 +207,76 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData return res && zcbor_list_map_end_force_decode(states); } + +#if CHIP_DEVICE_SECURE_PROGRAMMING +#if CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL521X +#include "efuse.h" +#include "ske_basic.h" +#include "ske_portable.h" +#include +#include +#else +#include "aes.h" +#endif + +bool LoadDACCertAndKey(uint8_t * base_buffer , struct FactoryData * factoryData) +{ + size_t dac_priv_key_len; + uint8_t ieee_addr[8] = {0}; + uint8_t chip_id[16] = { 0 }; + /* get the dac key pair info form the flash directly*/ + uint8_t buffer[34] = {0}; + const struct device * mFlashDevice = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); + int ret = flash_read(mFlashDevice, FIXED_PARTITION_OFFSET(dac_keypair_partition), buffer, sizeof(buffer)); + + dac_priv_key_len = buffer[0]; + dac_priv_key_len |= (uint16_t) buffer[1] << 8; + factoryData->dac_priv_key.len = dac_priv_key_len; + if (!factoryData->dac_priv_key.len) + { + return false; + } + + if (efuse_get_ieee_addr(ieee_addr) == DRV_API_SUCCESS) + { + LOG_HEXDUMP_INF(ieee_addr, 8, "IEEE address"); + + memcpy(chip_id, ieee_addr, 8); + LOG_HEXDUMP_INF(chip_id, 16, "chip_id with IEEE address and zero padding"); + +#if CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL521X + ske_dig_en(); + aes_decryption_be(chip_id, buffer + 2, dac_key_decrypt); + aes_decryption_be(chip_id, buffer + 18, dac_key_decrypt + 16); +#else + aes_decrypt(chip_id, buffer + 2, dac_key_decrypt); + aes_decrypt(chip_id, buffer + 18, dac_key_decrypt + 16); +#endif + + // LOG_INF("[LoadDACCertAndKey]DAC priv key decrypted, len=%u", dac_priv_key_len); + // LOG_HEXDUMP_INF(buffer + 2, dac_priv_key_len, "[LoadDACCertAndKey]Encrypted DAC PRIV KEY"); + // LOG_HEXDUMP_INF(dac_key_decrypt, dac_priv_key_len, "[LoadDACCertAndKey]DAC PRIV KEY"); + factoryData->dac_priv_key.data = dac_key_decrypt; + } + else + { + LOG_ERR("Failed to get chip ID."); + return false; + } + + size_t dac_cert_len = 0; + flash_read(mFlashDevice, FIXED_PARTITION_OFFSET(dac_keypair_partition)+100, buffer, 2); + dac_cert_len = buffer[0]; + dac_cert_len |= (uint16_t) buffer[1] << 8; + factoryData->dac_cert.len = dac_cert_len; + if (!factoryData->dac_cert.len) + { + return false; + } + factoryData->dac_cert.data =(uint8_t *) (0x20000000 + FIXED_PARTITION_OFFSET(dac_keypair_partition) + 102); + // LOG_INF("[LoadDACCertAndKey]DAC cert len=%u", dac_cert_len); + // LOG_HEXDUMP_INF(factoryData->dac_cert.data, factoryData->dac_cert.len, "DAC CERT"); + + return true; +} +#endif diff --git a/src/platform/telink/FactoryDataParser.h b/src/platform/telink/FactoryDataParser.h index de8f7c72da83..2b780027bcbd 100644 --- a/src/platform/telink/FactoryDataParser.h +++ b/src/platform/telink/FactoryDataParser.h @@ -21,6 +21,8 @@ #include #include +#include "CHIPDevicePlatformConfig.h" + #ifdef __cplusplus extern "C" { #endif @@ -46,6 +48,7 @@ struct FactoryData struct FactoryDataString product_url; struct FactoryDataString product_label; uint16_t hw_ver; + struct FactoryDataString mfg_date_str; struct FactoryDataString hw_ver_str; struct FactoryDataString rd_uid; struct FactoryDataString dac_cert; @@ -77,6 +80,18 @@ struct FactoryData */ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData * factoryData); +#if CHIP_DEVICE_SECURE_PROGRAMMING +/** + * @brief Inject dac cert and dac private key into the factory data structure. + * + * @param[in] . base_buffer malloc buffer for factory data + * @param[out] factoryData address of object to be filled with parsed factory data. + * + * @returns true on success, false otherwise. + */ +bool LoadDACCertAndKey(uint8_t * base_buffer, struct FactoryData * factoryData); +#endif + #ifdef __cplusplus } #endif diff --git a/src/platform/telink/FactoryDataProvider.cpp b/src/platform/telink/FactoryDataProvider.cpp index de375d98a48f..abd9fc7f3667 100644 --- a/src/platform/telink/FactoryDataProvider.cpp +++ b/src/platform/telink/FactoryDataProvider.cpp @@ -27,6 +27,8 @@ #include #include +LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL); + namespace chip { namespace { @@ -62,12 +64,18 @@ CHIP_ERROR GetFactoryDataString(const FactoryDataString & str, char * buf, size_ } // namespace namespace DeviceLayer { - +#if CHIP_DEVICE_SECURE_PROGRAMMING +static constexpr uint32_t kFactoryDataOffset = 6; +#endif template CHIP_ERROR FactoryDataProvider::Init() { uint8_t * factoryData = nullptr; size_t factoryDataSize; +#if CHIP_DEVICE_SECURE_PROGRAMMING + uint8_t * dacData = nullptr; + size_t dacDataSize; +#endif CHIP_ERROR error = mFlashFactoryData.ProtectFactoryDataPartitionAgainstWrite(); @@ -98,15 +106,43 @@ CHIP_ERROR FactoryDataProvider::Init() if (error != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "Failed to read factory data partition"); + free(ptr); // Only free on failure return error; } + +#if CHIP_DEVICE_SECURE_PROGRAMMING + if (!ParseFactoryData(factoryData + kFactoryDataOffset, factoryDataSize - kFactoryDataOffset, &mFactoryData)) +#else if (!ParseFactoryData(factoryData, factoryDataSize, &mFactoryData)) +#endif { ChipLogError(DeviceLayer, "Failed to parse factory data"); + free(ptr); // Only free on failure return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; } + // LOG_INF("[ParseFactoryData - ParseFactoryData] DAC priv key len=%u", mFactoryData.dac_priv_key.len); + // LOG_HEXDUMP_INF(mFactoryData.dac_priv_key.data, mFactoryData.dac_priv_key.len, "DAC PRIV KEY"); + + // LOG_INF("[ParseFactoryData - ParseFactoryData] DAC cert len=%u", mFactoryData.dac_cert.len); + // LOG_HEXDUMP_INF(mFactoryData.dac_cert.data, mFactoryData.dac_cert.len, "DAC CERT"); + +#if CHIP_DEVICE_SECURE_PROGRAMMING + if (!LoadDACCertAndKey(mFactoryDataBuffer , &mFactoryData)) + { + ChipLogError(DeviceLayer, "Failed to inject dac data"); + free(ptr); // Only free on failure + return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + } + + // LOG_INF("[ParseFactoryData-LoadDACCertAndKey] DAC priv key len=%u", mFactoryData.dac_priv_key.len); + // LOG_HEXDUMP_INF(mFactoryData.dac_priv_key.data, mFactoryData.dac_priv_key.len, "DAC PRIV KEY"); + + // LOG_INF("[ParseFactoryData-LoadDACCertAndKey] DAC cert len=%u", mFactoryData.dac_cert.len); + // LOG_HEXDUMP_INF(mFactoryData.dac_cert.data, mFactoryData.dac_cert.len, "DAC CERT"); +#endif + // Release the memory of mFactoryDataBuffer after complete parse free(ptr); @@ -153,7 +189,11 @@ CHIP_ERROR FactoryDataProvider::GetDeviceAttestationCert(Mutab VerifyOrReturnError(outBuffer.size() >= mFactoryData.dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); VerifyOrReturnError(mFactoryData.dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); +#if CHIP_DEVICE_SECURE_PROGRAMMING + memcpy(outBuffer.data(), mFactoryData.dac_cert.data, mFactoryData.dac_cert.len); +#else GetFactoryData(outBuffer.data(), mFactoryData.dac_cert.data, mFactoryData.dac_cert.len); +#endif outBuffer.reduce_size(mFactoryData.dac_cert.len); @@ -195,13 +235,26 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(c return CHIP_ERROR_NO_MEMORY; } +#if CHIP_DEVICE_SECURE_PROGRAMMING + memcpy(P_DACCert, mFactoryData.dac_cert.data, mFactoryData.dac_cert.len); +#else GetFactoryData(P_DACCert, mFactoryData.dac_cert.data, mFactoryData.dac_cert.len); +#endif + + // LOG_INF("[SignWithDeviceAttestationKey] DAC cert len=%u", mFactoryData.dac_cert.len); + // LOG_HEXDUMP_INF(mFactoryData.dac_cert.data, mFactoryData.dac_cert.len, "mFactoryData.dac_cert.data"); + // LOG_HEXDUMP_INF(P_DACCert, mFactoryData.dac_cert.len, "DAC CERT - P_DACCert"); // Extract public key from DAC cert. ByteSpan dacCertSpan{ reinterpret_cast(P_DACCert), mFactoryData.dac_cert.len }; + // LOG_INF("[SignWithDeviceAttestationKey] DAC cert len=%u", dacCertSpan.size()); + // LOG_HEXDUMP_INF(dacCertSpan.data(), dacCertSpan.size(), "DAC CERT"); chip::Crypto::P256PublicKey dacPublicKey; error = chip::Crypto::ExtractPubkeyFromX509Cert(dacCertSpan, dacPublicKey); + // LOG_INF("[SignWithDeviceAttestationKey] DAC pub key len=%u", dacPublicKey.Length()); + // LOG_HEXDUMP_INF(dacPublicKey.Bytes(), dacPublicKey.Length(), "DAC PUB KEY"); + free(P_DACCert); if (error != CHIP_NO_ERROR) { @@ -219,7 +272,15 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(c return CHIP_ERROR_NO_MEMORY; } +#if CHIP_DEVICE_SECURE_PROGRAMMING + memcpy(P_DACPrivKey, mFactoryData.dac_priv_key.data, mFactoryData.dac_priv_key.len); +#else GetFactoryData(P_DACPrivKey, mFactoryData.dac_priv_key.data, mFactoryData.dac_priv_key.len); +#endif + + // LOG_INF("[SignWithDeviceAttestationKey] DAC priv key len=%u", mFactoryData.dac_priv_key.len); + // LOG_HEXDUMP_INF(mFactoryData.dac_priv_key.data, mFactoryData.dac_priv_key.len, "mFactoryData.dac_priv_key.data"); + // LOG_HEXDUMP_INF(P_DACPrivKey, mFactoryData.dac_priv_key.len, "DAC CERT - P_DACPrivKey"); // Load keypair from raw. error = LoadKeypairFromRaw(ByteSpan(reinterpret_cast(P_DACPrivKey), mFactoryData.dac_priv_key.len), @@ -362,6 +423,12 @@ CHIP_ERROR FactoryDataProvider::GetManufacturingDate(uint16_t return CHIP_NO_ERROR; } +template +CHIP_ERROR FactoryDataProvider::GetManufacturingDateString(char * buf, size_t bufSize) +{ + return GetFactoryDataString(mFactoryData.mfg_date_str, buf, bufSize); +} + template CHIP_ERROR FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion) { diff --git a/src/platform/telink/FactoryDataProvider.h b/src/platform/telink/FactoryDataProvider.h index bbfd9c92e049..4cd3d877d1e7 100644 --- a/src/platform/telink/FactoryDataProvider.h +++ b/src/platform/telink/FactoryDataProvider.h @@ -107,6 +107,7 @@ class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentia CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override; CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override; CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override; + CHIP_ERROR GetManufacturingDateString(char * buf, size_t bufSize) override; CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override; CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override; CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override; diff --git a/src/platform/telink/SystemPlatformConfig.h b/src/platform/telink/SystemPlatformConfig.h index d32c260f7e64..c62e8b55bfcc 100644 --- a/src/platform/telink/SystemPlatformConfig.h +++ b/src/platform/telink/SystemPlatformConfig.h @@ -44,8 +44,9 @@ struct ChipDeviceEvent; #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 #endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS -#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION) || \ - defined(CONFIG_SOC_RISCV_TELINK_W91) +#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ + defined(CONFIG_SOC_RISCV_TELINK_TL721X) || defined(CONFIG_SOC_RISCV_TELINK_TL521X) || \ + defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION) || defined(CONFIG_SOC_RISCV_TELINK_W91) #define CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP 1 #define CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL 0 #define CHIP_SYSTEM_CONFIG_POOL_USE_HEAP 1 @@ -56,7 +57,8 @@ struct ChipDeviceEvent; #define CHIP_SYSTEM_CONFIG_USE_SOCKETS 1 // Reduce packet buffer pool size (default 15) to reduce ram consumption -#if defined(CONFIG_PM) || defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_W91) +#if defined(CONFIG_PM) || defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ + defined(CONFIG_SOC_RISCV_TELINK_TL721X) || defined(CONFIG_SOC_RISCV_TELINK_TL521X) || defined(CONFIG_SOC_RISCV_TELINK_W91) #define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 0 #else #define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8 diff --git a/src/platform/telink/ThreadStackManagerImpl.h b/src/platform/telink/ThreadStackManagerImpl.h index 103697c20615..bd4058b0b214 100644 --- a/src/platform/telink/ThreadStackManagerImpl.h +++ b/src/platform/telink/ThreadStackManagerImpl.h @@ -24,4 +24,4 @@ #pragma once -#include +#include \ No newline at end of file diff --git a/src/platform/telink/tl3238x_2m_flash.overlay b/src/platform/telink/tl3238x_2m_flash.overlay new file mode 100644 index 000000000000..3f4e5c226de1 --- /dev/null +++ b/src/platform/telink/tl3238x_2m_flash.overlay @@ -0,0 +1,59 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x15000>; + }; + slot0_partition: partition@15000 { + label = "image-0"; + reg = <0x15000 0xe5000>; // total slot0 is 916k + }; + slot1_partition: partition@fa000 { + label = "image-1"; + reg = <0xfa000 0xe6000>; // total slot1 is 920k + }; + user_rfu_partition: partition@1e0000 { + label = "user_rfu"; + reg = <0x1e0000 0x4000>; + }; + storage_partition: partition@1e4000 { + label = "matter-nvs"; + reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@1ec000 { + label = "zigbee-nvs"; + reg = <0x1ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@1f8000 { + label = "secure"; + reg = <0x1f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@1f9000 { + label = "user_config"; + reg = <0x1f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@1fa000 { + label = "dual-mode"; + reg = <0x1fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl3238x_2m_flash_lzma.overlay b/src/platform/telink/tl3238x_2m_flash_lzma.overlay new file mode 100644 index 000000000000..249608848d98 --- /dev/null +++ b/src/platform/telink/tl3238x_2m_flash_lzma.overlay @@ -0,0 +1,79 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x15000>; + }; +// currently the reset flash is 0x1e0000- 0x15000() = 0x1cb000 = 1836k (the total of slot0,and slot1) +// tralor = 20k +// slot0_fw = (1836-20)/1.6/4*4 = 1132 (suppose as LZMA:60%) +// slot0 area = 1132+20 = 1152(0x120000) + slot0_partition: partition@15000 { + label = "image-0"; + reg = <0x15000 0x120000>; // total slot0 is 1152k + }; +// add information , increase part for matter & zigbee +// suppose the matter application layer is 30k, zigbee is 60k +// currently , basic matter fw is 813k, zigbee is 140k , so just suppose matter is 916k, and zigbee is 216, reserve 20k for matter ota trailor + slot0_matter_partition: partition@15000_1 { + label = "image-0-matter"; + reg = <0x15000 0xe5000>; // suppose matter is 916k (0xe5000) + }; + slot0_zb_partition: partition@fa000 { + label = "image-0-zb"; + reg = <0xfa000 0x36000>; // suppose zigbee is 216k (0x36000) + }; + slot0_trailor_partition: partition@130000 { + label = "image-0-trailor"; + reg = <0x130000 0x5000>; // suppose trailor is 20k + }; +// the total fw area is 1836k, and slot0 cost 1152, so the value is 1836 - 1152 = 684k (0xac000) */ + slot1_partition: partition@135000 { + label = "image-1"; + reg = <0x135000 0xab000>; + }; + user_rfu_partition: partition@1e0000 { + label = "user_rfu"; + reg = <0x1e0000 0x4000>; + }; + storage_partition: partition@1e4000 { + label = "matter-nvs"; + reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@1ec000 { + label = "zigbee-nvs"; + reg = <0x1ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@1f8000 { + label = "secure"; + reg = <0x1f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@1f9000 { + label = "user_config"; + reg = <0x1f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@1fa000 { + label = "dual-mode"; + reg = <0x1fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl3238x_4m_flash.overlay b/src/platform/telink/tl3238x_4m_flash.overlay new file mode 100644 index 000000000000..fa0284405499 --- /dev/null +++ b/src/platform/telink/tl3238x_4m_flash.overlay @@ -0,0 +1,74 @@ +&flash { + reg = <0x20000000 0x400000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x16000>; + }; + slot0_partition: partition@16000 { + label = "image-0"; + reg = <0x16000 0x1e5000>; // total slot0 is 1940k + }; +// add information , increase part for matter & zigbee +// currently , matter slot0 is 1640k, zigbee is 276k ,reserve 20k for matter ota trailor + slot0_matter_partition: partition@16000_1 { + label = "image-0-matter"; + reg = <0x16000 0x19a000>; // suppose matter is 1640k (0x19a000) + }; + slot0_zb_partition: partition@1b0000 { + label = "image-0-zb"; + reg = <0x1b0000 0x46000>; // suppose zigbee is 280k (0x46000) + }; + slot0_trailor_partition: partition@1f6000 { + label = "image-0-trailor"; + reg = <0x1f6000 0x5000>; // suppose trailor is 20k + }; +// the total fw area is 1940k */ + slot1_partition: partition@1fb000 { + label = "image-1"; + reg = <0x1fb000 0x1e5000>; + }; + user_rfu_partition: partition@3e0000 { + label = "user_rfu"; + reg = <0x3e0000 0x4000>; + }; + storage_partition: partition@3e4000 { + label = "matter-nvs"; + reg = <0x3e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@3ec000 { + label = "zigbee-nvs"; + reg = <0x3ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@3f8000 { + label = "secure"; + reg = <0x3f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@3f9000 { + label = "user_config"; + reg = <0x3f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@3fa000 { + label = "dual-mode"; + reg = <0x3fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@3fc000 { + label = "dac-keypair"; + reg = <0x3fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@3fd000 { + label = "factory-data"; + reg = <0x3fd000 0x1000>; // factory data info + }; + vendor_partition: partition@3fe000 { + label = "vendor-data"; + reg = <0x3fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl3238x_4m_flash_lzma.overlay b/src/platform/telink/tl3238x_4m_flash_lzma.overlay new file mode 100644 index 000000000000..fa0284405499 --- /dev/null +++ b/src/platform/telink/tl3238x_4m_flash_lzma.overlay @@ -0,0 +1,74 @@ +&flash { + reg = <0x20000000 0x400000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x16000>; + }; + slot0_partition: partition@16000 { + label = "image-0"; + reg = <0x16000 0x1e5000>; // total slot0 is 1940k + }; +// add information , increase part for matter & zigbee +// currently , matter slot0 is 1640k, zigbee is 276k ,reserve 20k for matter ota trailor + slot0_matter_partition: partition@16000_1 { + label = "image-0-matter"; + reg = <0x16000 0x19a000>; // suppose matter is 1640k (0x19a000) + }; + slot0_zb_partition: partition@1b0000 { + label = "image-0-zb"; + reg = <0x1b0000 0x46000>; // suppose zigbee is 280k (0x46000) + }; + slot0_trailor_partition: partition@1f6000 { + label = "image-0-trailor"; + reg = <0x1f6000 0x5000>; // suppose trailor is 20k + }; +// the total fw area is 1940k */ + slot1_partition: partition@1fb000 { + label = "image-1"; + reg = <0x1fb000 0x1e5000>; + }; + user_rfu_partition: partition@3e0000 { + label = "user_rfu"; + reg = <0x3e0000 0x4000>; + }; + storage_partition: partition@3e4000 { + label = "matter-nvs"; + reg = <0x3e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@3ec000 { + label = "zigbee-nvs"; + reg = <0x3ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@3f8000 { + label = "secure"; + reg = <0x3f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@3f9000 { + label = "user_config"; + reg = <0x3f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@3fa000 { + label = "dual-mode"; + reg = <0x3fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@3fc000 { + label = "dac-keypair"; + reg = <0x3fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@3fd000 { + label = "factory-data"; + reg = <0x3fd000 0x1000>; // factory data info + }; + vendor_partition: partition@3fe000 { + label = "vendor-data"; + reg = <0x3fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl3238x_simple.overlay b/src/platform/telink/tl3238x_simple.overlay new file mode 100644 index 000000000000..e75c9bdcdd4e --- /dev/null +++ b/src/platform/telink/tl3238x_simple.overlay @@ -0,0 +1,47 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x15000>; + }; + slot0_partition: partition@15000 { + label = "image-0"; + reg = <0x15000 0xee000>; // total slot0 is 952k (4k aligned) + }; + slot1_partition: partition@103000 { + label = "image-1"; + reg = <0x103000 0xef000>; // total slot1 is 956k (4k aligned) + }; + user_rfu_partition: partition@1f2000 { + label = "user_rfu"; + reg = <0x1f2000 0x1000>; + }; + storage_partition: partition@1f3000 { + label = "matter-nvs"; + reg = <0x1f3000 0x8000>; // matter nvs part , total is 32k. + }; + secure_partition: partition@1fb000 { + label = "secure"; + reg = <0x1fb000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl5218x_2m_flash.overlay b/src/platform/telink/tl5218x_2m_flash.overlay new file mode 100644 index 000000000000..635ddd708566 --- /dev/null +++ b/src/platform/telink/tl5218x_2m_flash.overlay @@ -0,0 +1,60 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x15000>; + }; + slot0_partition: partition@15000 { + label = "image-0"; + reg = <0x15000 0xe7000>; // total slot0 is 924k + }; +// Image size (0xe3653) + trailer (0x3030), so modify slot1 size to 924k. + slot1_partition: partition@fc000 { + label = "image-1"; + reg = <0xfc000 0xe7000>; // total slot1 is 924k + }; + user_rfu_partition: partition@1e3000 { + label = "user_rfu"; + reg = <0x1e3000 0x1000>; // from 16k to 4k + }; + storage_partition: partition@1e4000 { + label = "matter-nvs"; + reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@1ec000 { + label = "zigbee-nvs"; + reg = <0x1ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@1f8000 { + label = "secure"; + reg = <0x1f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@1f9000 { + label = "user_config"; + reg = <0x1f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@1fa000 { + label = "dual-mode"; + reg = <0x1fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl5218x_2m_flash_backup.overlay b/src/platform/telink/tl5218x_2m_flash_backup.overlay new file mode 100644 index 000000000000..3f4e5c226de1 --- /dev/null +++ b/src/platform/telink/tl5218x_2m_flash_backup.overlay @@ -0,0 +1,59 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x15000>; + }; + slot0_partition: partition@15000 { + label = "image-0"; + reg = <0x15000 0xe5000>; // total slot0 is 916k + }; + slot1_partition: partition@fa000 { + label = "image-1"; + reg = <0xfa000 0xe6000>; // total slot1 is 920k + }; + user_rfu_partition: partition@1e0000 { + label = "user_rfu"; + reg = <0x1e0000 0x4000>; + }; + storage_partition: partition@1e4000 { + label = "matter-nvs"; + reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@1ec000 { + label = "zigbee-nvs"; + reg = <0x1ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@1f8000 { + label = "secure"; + reg = <0x1f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@1f9000 { + label = "user_config"; + reg = <0x1f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@1fa000 { + label = "dual-mode"; + reg = <0x1fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl5218x_2m_flash_lzma.overlay b/src/platform/telink/tl5218x_2m_flash_lzma.overlay new file mode 100644 index 000000000000..249608848d98 --- /dev/null +++ b/src/platform/telink/tl5218x_2m_flash_lzma.overlay @@ -0,0 +1,79 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x15000>; + }; +// currently the reset flash is 0x1e0000- 0x15000() = 0x1cb000 = 1836k (the total of slot0,and slot1) +// tralor = 20k +// slot0_fw = (1836-20)/1.6/4*4 = 1132 (suppose as LZMA:60%) +// slot0 area = 1132+20 = 1152(0x120000) + slot0_partition: partition@15000 { + label = "image-0"; + reg = <0x15000 0x120000>; // total slot0 is 1152k + }; +// add information , increase part for matter & zigbee +// suppose the matter application layer is 30k, zigbee is 60k +// currently , basic matter fw is 813k, zigbee is 140k , so just suppose matter is 916k, and zigbee is 216, reserve 20k for matter ota trailor + slot0_matter_partition: partition@15000_1 { + label = "image-0-matter"; + reg = <0x15000 0xe5000>; // suppose matter is 916k (0xe5000) + }; + slot0_zb_partition: partition@fa000 { + label = "image-0-zb"; + reg = <0xfa000 0x36000>; // suppose zigbee is 216k (0x36000) + }; + slot0_trailor_partition: partition@130000 { + label = "image-0-trailor"; + reg = <0x130000 0x5000>; // suppose trailor is 20k + }; +// the total fw area is 1836k, and slot0 cost 1152, so the value is 1836 - 1152 = 684k (0xac000) */ + slot1_partition: partition@135000 { + label = "image-1"; + reg = <0x135000 0xab000>; + }; + user_rfu_partition: partition@1e0000 { + label = "user_rfu"; + reg = <0x1e0000 0x4000>; + }; + storage_partition: partition@1e4000 { + label = "matter-nvs"; + reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@1ec000 { + label = "zigbee-nvs"; + reg = <0x1ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@1f8000 { + label = "secure"; + reg = <0x1f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@1f9000 { + label = "user_config"; + reg = <0x1f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@1fa000 { + label = "dual-mode"; + reg = <0x1fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl5218x_4m_flash.overlay b/src/platform/telink/tl5218x_4m_flash.overlay new file mode 100644 index 000000000000..fa0284405499 --- /dev/null +++ b/src/platform/telink/tl5218x_4m_flash.overlay @@ -0,0 +1,74 @@ +&flash { + reg = <0x20000000 0x400000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x16000>; + }; + slot0_partition: partition@16000 { + label = "image-0"; + reg = <0x16000 0x1e5000>; // total slot0 is 1940k + }; +// add information , increase part for matter & zigbee +// currently , matter slot0 is 1640k, zigbee is 276k ,reserve 20k for matter ota trailor + slot0_matter_partition: partition@16000_1 { + label = "image-0-matter"; + reg = <0x16000 0x19a000>; // suppose matter is 1640k (0x19a000) + }; + slot0_zb_partition: partition@1b0000 { + label = "image-0-zb"; + reg = <0x1b0000 0x46000>; // suppose zigbee is 280k (0x46000) + }; + slot0_trailor_partition: partition@1f6000 { + label = "image-0-trailor"; + reg = <0x1f6000 0x5000>; // suppose trailor is 20k + }; +// the total fw area is 1940k */ + slot1_partition: partition@1fb000 { + label = "image-1"; + reg = <0x1fb000 0x1e5000>; + }; + user_rfu_partition: partition@3e0000 { + label = "user_rfu"; + reg = <0x3e0000 0x4000>; + }; + storage_partition: partition@3e4000 { + label = "matter-nvs"; + reg = <0x3e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@3ec000 { + label = "zigbee-nvs"; + reg = <0x3ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@3f8000 { + label = "secure"; + reg = <0x3f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@3f9000 { + label = "user_config"; + reg = <0x3f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@3fa000 { + label = "dual-mode"; + reg = <0x3fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@3fc000 { + label = "dac-keypair"; + reg = <0x3fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@3fd000 { + label = "factory-data"; + reg = <0x3fd000 0x1000>; // factory data info + }; + vendor_partition: partition@3fe000 { + label = "vendor-data"; + reg = <0x3fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl5218x_4m_flash_lzma.overlay b/src/platform/telink/tl5218x_4m_flash_lzma.overlay new file mode 100644 index 000000000000..fa0284405499 --- /dev/null +++ b/src/platform/telink/tl5218x_4m_flash_lzma.overlay @@ -0,0 +1,74 @@ +&flash { + reg = <0x20000000 0x400000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x16000>; + }; + slot0_partition: partition@16000 { + label = "image-0"; + reg = <0x16000 0x1e5000>; // total slot0 is 1940k + }; +// add information , increase part for matter & zigbee +// currently , matter slot0 is 1640k, zigbee is 276k ,reserve 20k for matter ota trailor + slot0_matter_partition: partition@16000_1 { + label = "image-0-matter"; + reg = <0x16000 0x19a000>; // suppose matter is 1640k (0x19a000) + }; + slot0_zb_partition: partition@1b0000 { + label = "image-0-zb"; + reg = <0x1b0000 0x46000>; // suppose zigbee is 280k (0x46000) + }; + slot0_trailor_partition: partition@1f6000 { + label = "image-0-trailor"; + reg = <0x1f6000 0x5000>; // suppose trailor is 20k + }; +// the total fw area is 1940k */ + slot1_partition: partition@1fb000 { + label = "image-1"; + reg = <0x1fb000 0x1e5000>; + }; + user_rfu_partition: partition@3e0000 { + label = "user_rfu"; + reg = <0x3e0000 0x4000>; + }; + storage_partition: partition@3e4000 { + label = "matter-nvs"; + reg = <0x3e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@3ec000 { + label = "zigbee-nvs"; + reg = <0x3ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@3f8000 { + label = "secure"; + reg = <0x3f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@3f9000 { + label = "user_config"; + reg = <0x3f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@3fa000 { + label = "dual-mode"; + reg = <0x3fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@3fc000 { + label = "dac-keypair"; + reg = <0x3fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@3fd000 { + label = "factory-data"; + reg = <0x3fd000 0x1000>; // factory data info + }; + vendor_partition: partition@3fe000 { + label = "vendor-data"; + reg = <0x3fe000 0x2000>; // mac and rf info. + }; + }; +}; diff --git a/src/platform/telink/tl7218x_2m_flash.overlay b/src/platform/telink/tl7218x_2m_flash.overlay index d08d0e4ff4a6..8d192858669d 100644 --- a/src/platform/telink/tl7218x_2m_flash.overlay +++ b/src/platform/telink/tl7218x_2m_flash.overlay @@ -6,30 +6,54 @@ compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; - +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 0xf000>; + reg = <0x00000000 0x15000>; }; - slot0_partition: partition@f000 { + slot0_partition: partition@15000 { label = "image-0"; - reg = <0xf000 0xf1000>; + reg = <0x15000 0xe5000>; // total slot0 is 916k }; - factory_partition: partition@100000 { - label = "factory-data"; - reg = <0x100000 0x1000>; + slot1_partition: partition@fa000 { + label = "image-1"; + reg = <0xfa000 0xe6000>; // total slot1 is 916k }; - storage_partition: partition@101000 { - label = "storage"; - reg = <0x101000 0xc000>; + user_rfu_partition: partition@1e0000 { + label = "user_rfu"; + reg = <0x1e0000 0x4000>; + }; + storage_partition: partition@1e4000 { + label = "matter-nvs"; + reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. }; - slot1_partition: partition@10d000 { - label = "image-1"; - reg = <0x10d000 0xf1000>; + user_partition: partition@1ec000 { + label = "user"; + reg = <0x1ec000 0xc000>; // user part , total is 48k. + }; + secure_partition: partition@1f8000 { + label = "secure"; + reg = <0x1f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@1f9000 { + label = "user_config"; + reg = <0x1f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@1fa000 { + label = "dual-mode"; + reg = <0x1fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info }; vendor_partition: partition@1fe000 { label = "vendor-data"; - reg = <0x1fe000 0x2000>; + reg = <0x1fe000 0x2000>; // mac and rf info. }; }; }; diff --git a/src/platform/telink/tl7218x_2m_flash_lzma.overlay b/src/platform/telink/tl7218x_2m_flash_lzma.overlay index 922d7b632726..249608848d98 100644 --- a/src/platform/telink/tl7218x_2m_flash_lzma.overlay +++ b/src/platform/telink/tl7218x_2m_flash_lzma.overlay @@ -6,30 +6,74 @@ compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; - +// reserve 20k for software bootloader , 64k for mcuboot,need to disable log for mcuboot; boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 0xf000>; + reg = <0x00000000 0x15000>; }; - slot0_partition: partition@f000 { +// currently the reset flash is 0x1e0000- 0x15000() = 0x1cb000 = 1836k (the total of slot0,and slot1) +// tralor = 20k +// slot0_fw = (1836-20)/1.6/4*4 = 1132 (suppose as LZMA:60%) +// slot0 area = 1132+20 = 1152(0x120000) + slot0_partition: partition@15000 { label = "image-0"; - reg = <0xf000 0x139000>; + reg = <0x15000 0x120000>; // total slot0 is 1152k }; - factory_partition: partition@148000 { - label = "factory-data"; - reg = <0x148000 0x1000>; +// add information , increase part for matter & zigbee +// suppose the matter application layer is 30k, zigbee is 60k +// currently , basic matter fw is 813k, zigbee is 140k , so just suppose matter is 916k, and zigbee is 216, reserve 20k for matter ota trailor + slot0_matter_partition: partition@15000_1 { + label = "image-0-matter"; + reg = <0x15000 0xe5000>; // suppose matter is 916k (0xe5000) }; - storage_partition: partition@149000 { - label = "storage"; - reg = <0x149000 0xc000>; + slot0_zb_partition: partition@fa000 { + label = "image-0-zb"; + reg = <0xfa000 0x36000>; // suppose zigbee is 216k (0x36000) }; - slot1_partition: partition@155000 { + slot0_trailor_partition: partition@130000 { + label = "image-0-trailor"; + reg = <0x130000 0x5000>; // suppose trailor is 20k + }; +// the total fw area is 1836k, and slot0 cost 1152, so the value is 1836 - 1152 = 684k (0xac000) */ + slot1_partition: partition@135000 { label = "image-1"; - reg = <0x155000 0xa9000>; + reg = <0x135000 0xab000>; + }; + user_rfu_partition: partition@1e0000 { + label = "user_rfu"; + reg = <0x1e0000 0x4000>; + }; + storage_partition: partition@1e4000 { + label = "matter-nvs"; + reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. + }; + zigbee_nvs_partition: partition@1ec000 { + label = "zigbee-nvs"; + reg = <0x1ec000 0xc000>; // zigbee nvs part , total is 48k. + }; + secure_partition: partition@1f8000 { + label = "secure"; + reg = <0x1f8000 0x1000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + user_config_partition: partition@1f9000 { + label = "user_config"; + reg = <0x1f9000 0x1000>; // user_config ,for the secure-boot sign logic changes ,it can release for user . + }; + dual_mode_partition: partition@1fa000 { + label = "dual-mode"; + reg = <0x1fa000 0x2000>; // user:store the mode info and the key info part.same as public area for dual mode + }; + dac_keypair_partition: partition@1fc000 { + label = "dac-keypair"; + reg = <0x1fc000 0x1000>; // store dac and key pair. + }; + factory_partition: partition@1fd000 { + label = "factory-data"; + reg = <0x1fd000 0x1000>; // factory data info }; vendor_partition: partition@1fe000 { label = "vendor-data"; - reg = <0x1fe000 0x2000>; + reg = <0x1fe000 0x2000>; // mac and rf info. }; }; }; diff --git a/third_party_patches/openthread/csma_next_operation.patch b/third_party_patches/openthread/csma_next_operation.patch new file mode 100644 index 000000000000..66db5d5fb2da --- /dev/null +++ b/third_party_patches/openthread/csma_next_operation.patch @@ -0,0 +1,43 @@ +diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp +index 225ad30f5..29b4d7414 100644 +--- a/src/core/mac/mac.cpp ++++ b/src/core/mac/mac.cpp +@@ -40,6 +40,24 @@ + #include "instance/instance.hpp" + #include "utils/static_counter.hpp" + ++ ++#define CONFIG_OPENTHREAD_CSMABACKOFF_OPTIMIZATION 1 ++ ++#if CONFIG_OPENTHREAD_CSMABACKOFF_OPTIMIZATION ++bool get_pm_standby_flag(void) ++{ ++ bool pm_flag; ++ #if CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION ++ extern bool b9x_deep_sleep_retention; ++ pm_flag = b9x_deep_sleep_retention; ++ #elif CONFIG_SOC_SERIES_RISCV_TELINK_TLX_RETENTION ++ extern bool tlx_deep_sleep_retention; ++ pm_flag = tlx_deep_sleep_retention; ++ #endif ++ return pm_flag; ++} ++#endif ++ + namespace ot { + namespace Mac { + +@@ -629,6 +647,13 @@ void Mac::StartOperation(Operation aOperation) + + if (mOperation == kOperationIdle) + { ++#if CONFIG_OPENTHREAD_CSMABACKOFF_OPTIMIZATION ++ bool ot_deep_sleep_flag = !get_pm_standby_flag(); ++ if(ot_deep_sleep_flag){ ++ ot_deep_sleep_flag = false; ++ PerformNextOperation(); ++ }else ++#endif /* CONFIG_OPENTHREAD_CSMABACKOFF_OPTIMIZATION */ + mOperationTask.Post(); + } + }