From 6829d71307689789e338bbc355c55ff6c6923ef4 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 18 Feb 2026 09:59:45 -0500 Subject: [PATCH 01/31] [Telink] allow support controlling the log level for telink and default to "progress" for lighting (#43189) * Switch telink to log-progress for lights. * Fix compile ... unsure what broke here... * Fix test file * Update scripts/build/build/targets.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .github/workflows/examples-telink.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update one more build. * Update scripts/build/builders/telink.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/examples-telink.yaml | 22 ++++++++++++++---- config/telink/chip-module/CMakeLists.txt | 23 +++++++++++++++++++ scripts/build/build/targets.py | 6 ++++- scripts/build/builders/telink.py | 23 +++++++++++++++++++ .../build/testdata/all_targets_linux_x64.txt | 2 +- src/platform/telink/OTAImageProcessorImpl.cpp | 7 +++--- 6 files changed, 74 insertions(+), 9 deletions(-) diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index d99f06446cf0..86ab86a6edc2 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -142,12 +142,19 @@ jobs: - name: Build example Telink (W91) Lighting App with OTA, Factory Data # Run test for master and all PRs + # + # TODO: full logging is not enabled here; logging is reduced to progress/error + # (via the *-log-progress target) because with full logging this runs + # out of flash. This is generally NOT expected/intentional. + # At the time this was checked: + # - a 4K flash increase occurred due to the group cast cluster + # - flash runs out by about 1.2K run: | ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9118bdk40d-light-ota-factory-data' build" + "./scripts/build/build_examples.py --target 'telink-tlsr9118bdk40d-light-ota-factory-data-log-progress' build" .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ telink tlsr9118bdk40d lighting-app-ota-factory-data \ - out/telink-tlsr9118bdk40d-light-ota-factory-data/zephyr/zephyr.elf \ + out/telink-tlsr9118bdk40d-light-ota-factory-data-log-progress/zephyr/zephyr.elf \ /tmp/bloat_reports/ - name: clean out build output (keep tools) @@ -194,12 +201,19 @@ jobs: - name: Build example Telink (tl721x) Lighting App with OTA, Shell, Factory Data # Run test for master and all PRs + # + # TODO: full logging is not enabled here; logging is reduced to progress/error + # (via the *-log-progress target) because with full logging this runs + # out of flash. This is generally NOT expected/intentional. + # At the time this was checked: + # - a 4K flash increase occurred due to the group cast cluster + # - flash runs out by about 1.2K run: | ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-light-ota-shell-factory-data' build" + "./scripts/build/build_examples.py --target 'telink-tl7218x-light-ota-shell-factory-data-log-progress' build" .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ telink tl7218x light-app-ota-shell-factory-data \ - out/telink-tl7218x-light-ota-shell-factory-data/zephyr/zephyr.elf \ + out/telink-tl7218x-light-ota-shell-factory-data-log-progress/zephyr/zephyr.elf \ /tmp/bloat_reports/ - name: clean out build output (keep tools) diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index fb2d0606e3b2..459d2a9aae2e 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -132,6 +132,29 @@ if (CONFIG_CHIP_ROTATING_DEVICE_ID) matter_add_gn_arg_bool("chip_enable_additional_data_advertising" TRUE) endif() +if(${TLNK_LOG_LEVEL} MATCHES all) + matter_add_gn_arg_bool("chip_logging" TRUE) + matter_add_gn_arg_bool("chip_error_logging" TRUE) + matter_add_gn_arg_bool("chip_progress_logging" TRUE) + matter_add_gn_arg_bool("chip_detail_logging" TRUE) + matter_add_gn_arg_bool("chip_automation_logging" TRUE) +elseif(${TLNK_LOG_LEVEL} MATCHES progress) + matter_add_gn_arg_bool("chip_logging" TRUE) + matter_add_gn_arg_bool("chip_error_logging" TRUE) + matter_add_gn_arg_bool("chip_progress_logging" TRUE) + matter_add_gn_arg_bool("chip_detail_logging" FALSE) + matter_add_gn_arg_bool("chip_automation_logging" FALSE) +elseif(${TLNK_LOG_LEVEL} MATCHES error) + matter_add_gn_arg_bool("chip_logging" TRUE) + matter_add_gn_arg_bool("chip_error_logging" TRUE) + matter_add_gn_arg_bool("chip_progress_logging" FALSE) + matter_add_gn_arg_bool("chip_detail_logging" FALSE) + matter_add_gn_arg_bool("chip_automation_logging" FALSE) +elseif(${TLNK_LOG_LEVEL} MATCHES none) + matter_add_gn_arg_bool("chip_logging" FALSE) +endif() + + if (CONFIG_WIFI_W91) matter_add_gn_arg_string("chip_mdns" "minimal") elseif (CONFIG_NET_L2_OPENTHREAD) diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 7c54fa1aa2c5..ff7d49c056a2 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -30,7 +30,7 @@ from builders.qpg import QpgApp, QpgBoard, QpgBuilder from builders.realtek import RealtekApp, RealtekBoard, RealtekBuilder from builders.stm32 import stm32App, stm32Board, stm32Builder -from builders.telink import TelinkApp, TelinkBoard, TelinkBuilder +from builders.telink import TelinkApp, TelinkBoard, TelinkBuilder, TelinkLogLevel from builders.ti import TIApp, TIBoard, TIBuilder from builders.tizen import TizenApp, TizenBoard, TizenBuilder @@ -821,6 +821,10 @@ def BuildTelinkTarget(): target.AppendModifier('precompiled-ot', precompiled_ot_config=True) target.AppendModifier('tflm', tflm_config=True) target.AppendModifier('nfc-payload', chip_enable_nfc_onboarding_payload=True) + target.AppendModifier("log-progress", log_level=TelinkLogLevel.PROGRESS).ExceptIfRe("-log-(all|error|none)") + 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)") return target diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index d42c8b08f18e..306159a2b3f3 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -20,6 +20,14 @@ from .builder import Builder, BuilderOutput +class TelinkLogLevel(Enum): + DEFAULT = auto() # default everything + ALL = auto() # enable all logging + PROGRESS = auto() # progress and above + ERROR = auto() # error and above + NONE = auto() # no chip_logging at all + + class TelinkApp(Enum): AIR_QUALITY_SENSOR = auto() ALL_CLUSTERS = auto() @@ -170,6 +178,7 @@ def __init__(self, precompiled_ot_config: bool = False, tflm_config: bool = False, chip_enable_nfc_onboarding_payload: bool = False, + log_level: TelinkLogLevel = TelinkLogLevel.DEFAULT, ): super(TelinkBuilder, self).__init__(root, runner) self.app = app @@ -187,6 +196,7 @@ def __init__(self, self.precompiled_ot_config = precompiled_ot_config self.tflm_config = tflm_config self.chip_enable_nfc_onboarding_payload = chip_enable_nfc_onboarding_payload + self.log_level = log_level def get_cmd_prefixes(self): if not self._runner.dry_run: @@ -249,6 +259,19 @@ def generate(self): if self.options.pregen_dir: flags.append(f"-DCHIP_CODEGEN_PREGEN_DIR={shlex.quote(self.options.pregen_dir)}") + if self.log_level == TelinkLogLevel.DEFAULT: + pass + elif self.log_level == TelinkLogLevel.ALL: + flags.append("-DTLNK_LOG_LEVEL=all") + elif self.log_level == TelinkLogLevel.PROGRESS: + flags.append("-DTLNK_LOG_LEVEL=progress") + elif self.log_level == TelinkLogLevel.ERROR: + flags.append("-DTLNK_LOG_LEVEL=error") + elif self.log_level == TelinkLogLevel.NONE: + flags.append("-DTLNK_LOG_LEVEL=none") + else: + raise Exception("Unknown log level: %r" % self.log_level) + build_flags = " -- " + " ".join(flags) if len(flags) > 0 else "" cmd = self.get_cmd_prefixes() diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 99d7a9ee2a90..ca23b252fc12 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,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][-mars][-nfc-payload][-ota][-precompiled-ot][-rpc][-shell][-tflm][-thread-analyzer][-usb] +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,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] diff --git a/src/platform/telink/OTAImageProcessorImpl.cpp b/src/platform/telink/OTAImageProcessorImpl.cpp index 9f6d02707204..919eaee2f37a 100644 --- a/src/platform/telink/OTAImageProcessorImpl.cpp +++ b/src/platform/telink/OTAImageProcessorImpl.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -215,10 +216,10 @@ CHIP_ERROR OTAImageProcessorImpl::RestoreBytes(ByteSpan & aBlock) // Align to the nearest lower multiple of sector size (4 KB) for Flash erase/write downloadedBytesRestored = ROUND_DOWN(downloadedBytesRestored, 0x1000); ChipLogDetail(SoftwareUpdate, "Restored %u/%u bytes", static_cast(downloadedBytesRestored), - static_cast(mParams.totalFileBytes)) + static_cast(mParams.totalFileBytes)); - // Reinit Flash Stream with offset - ReturnErrorOnFailure(System::MapErrorZephyr(stream_flash_buffered_write(&stream, NULL, 0, true))); + // Reinit Flash Stream with offset + ReturnErrorOnFailure(System::MapErrorZephyr(stream_flash_buffered_write(&stream, NULL, 0, true))); ReturnErrorOnFailure(InitFlashStream(downloadedBytesRestored)); } else From fa25d60467f0126202dd91487fc41d730499cc4a Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Wed, 18 Feb 2026 19:41:19 +0200 Subject: [PATCH 02/31] [Telink] Add lzma overlay selection & Update Telink builds to docker version 185 (#43201) * [Telink] Add lzma overlay selection * [Telink] Add lzma overlays * [Telink] Update builds to docker version 185 --------- Co-authored-by: Andrei Litvin --- .github/workflows/chef.yaml | 2 +- .github/workflows/examples-telink.yaml | 17 +++----- examples/platform/telink/common.cmake | 4 +- .../telink/tl3218x_2m_flash_lzma.overlay | 39 +++++++++++++++++++ ....overlay => tl7218x_2m_flash_lzma.overlay} | 20 ++++++---- .../tlsr9518adk80d_2m_flash_lzma.overlay | 35 +++++++++++++++++ .../telink/tlsr9528a_2m_flash_lzma.overlay | 35 +++++++++++++++++ 7 files changed, 130 insertions(+), 22 deletions(-) create mode 100644 src/platform/telink/tl3218x_2m_flash_lzma.overlay rename src/platform/telink/{tlsr9518adk80d_1m_flash.overlay => tl7218x_2m_flash_lzma.overlay} (51%) create mode 100644 src/platform/telink/tlsr9518adk80d_2m_flash_lzma.overlay create mode 100644 src/platform/telink/tlsr9528a_2m_flash_lzma.overlay diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index f0f84a450cae..affcb901c200 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -145,7 +145,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-telink:181 + image: ghcr.io/project-chip/chip-build-telink:185 volumes: - "/:/runner-root-volume" options: --user root diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 86ab86a6edc2..467893f95fcd 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -39,7 +39,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-telink:181 + image: ghcr.io/project-chip/chip-build-telink:185 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" @@ -199,21 +199,14 @@ jobs: - name: clean out build output (keep tools) run: rm -rf ./out/telink* - - name: Build example Telink (tl721x) Lighting App with OTA, Shell, Factory Data + - name: Build example Telink (tl721x) Lighting App with OTA (LZMA), Shell, Factory Data # Run test for master and all PRs - # - # TODO: full logging is not enabled here; logging is reduced to progress/error - # (via the *-log-progress target) because with full logging this runs - # out of flash. This is generally NOT expected/intentional. - # At the time this was checked: - # - a 4K flash increase occurred due to the group cast cluster - # - flash runs out by about 1.2K run: | ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-light-ota-shell-factory-data-log-progress' build" + "./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-ota-shell-factory-data \ - out/telink-tl7218x-light-ota-shell-factory-data-log-progress/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/examples/platform/telink/common.cmake b/examples/platform/telink/common.cmake index 7b4a23904795..a414c050ba3d 100644 --- a/examples/platform/telink/common.cmake +++ b/examples/platform/telink/common.cmake @@ -128,8 +128,10 @@ endif() if(${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() set(BOOT_CONF_OVERLAY_FILE "${CHIP_ROOT}/config/telink/app/bootloader.conf") + set(FLASH_LAYOUT_SUFFIX "") endif() if(NOT EXISTS "${BOOT_CONF_OVERLAY_FILE}") message(FATAL_ERROR "${BOOT_CONF_OVERLAY_FILE} doesn't exist") @@ -164,7 +166,7 @@ if(NOT EXISTS "${GLOBAL_DTC_OVERLAY_FILE}") unset(GLOBAL_DTC_OVERLAY_FILE) endif() -set(FLASH_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_${FLASH_SIZE}_flash.overlay") +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") unset(FLASH_DTC_OVERLAY_FILE) diff --git a/src/platform/telink/tl3218x_2m_flash_lzma.overlay b/src/platform/telink/tl3218x_2m_flash_lzma.overlay new file mode 100644 index 000000000000..dbb22507b041 --- /dev/null +++ b/src/platform/telink/tl3218x_2m_flash_lzma.overlay @@ -0,0 +1,39 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0xf000>; + }; + slot0_partition: partition@f000 { + label = "image-0"; + reg = <0xf000 0x139000>; + }; + factory_partition: partition@148000 { + label = "factory-data"; + reg = <0x148000 0x800>; + }; + factory_rfu_partition: partition@148800 { + label = "factory-data-rfu"; + reg = <0x148800 0x800>; + }; + storage_partition: partition@149000 { + label = "storage"; + reg = <0x149000 0xc000>; + }; + slot1_partition: partition@155000 { + label = "image-1"; + reg = <0x155000 0xa9000>; + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; + }; + }; +}; diff --git a/src/platform/telink/tlsr9518adk80d_1m_flash.overlay b/src/platform/telink/tl7218x_2m_flash_lzma.overlay similarity index 51% rename from src/platform/telink/tlsr9518adk80d_1m_flash.overlay rename to src/platform/telink/tl7218x_2m_flash_lzma.overlay index 1a49a150cf32..922d7b632726 100644 --- a/src/platform/telink/tlsr9518adk80d_1m_flash.overlay +++ b/src/platform/telink/tl7218x_2m_flash_lzma.overlay @@ -1,5 +1,5 @@ &flash { - reg = <0x20000000 0x100000>; + reg = <0x20000000 0x200000>; /delete-node/ partitions; partitions { @@ -13,19 +13,23 @@ }; slot0_partition: partition@f000 { label = "image-0"; - reg = <0xf000 0xe3000>; + reg = <0xf000 0x139000>; }; - factory_partition: partition@f2000 { + factory_partition: partition@148000 { label = "factory-data"; - reg = <0xf2000 0x1000>; + reg = <0x148000 0x1000>; }; - storage_partition: partition@f3000 { + storage_partition: partition@149000 { label = "storage"; - reg = <0xf3000 0xb000>; + reg = <0x149000 0xc000>; }; - vendor_partition: partition@fe000 { + slot1_partition: partition@155000 { + label = "image-1"; + reg = <0x155000 0xa9000>; + }; + vendor_partition: partition@1fe000 { label = "vendor-data"; - reg = <0xfe000 0x2000>; + reg = <0x1fe000 0x2000>; }; }; }; diff --git a/src/platform/telink/tlsr9518adk80d_2m_flash_lzma.overlay b/src/platform/telink/tlsr9518adk80d_2m_flash_lzma.overlay new file mode 100644 index 000000000000..922d7b632726 --- /dev/null +++ b/src/platform/telink/tlsr9518adk80d_2m_flash_lzma.overlay @@ -0,0 +1,35 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0xf000>; + }; + slot0_partition: partition@f000 { + label = "image-0"; + reg = <0xf000 0x139000>; + }; + factory_partition: partition@148000 { + label = "factory-data"; + reg = <0x148000 0x1000>; + }; + storage_partition: partition@149000 { + label = "storage"; + reg = <0x149000 0xc000>; + }; + slot1_partition: partition@155000 { + label = "image-1"; + reg = <0x155000 0xa9000>; + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; + }; + }; +}; diff --git a/src/platform/telink/tlsr9528a_2m_flash_lzma.overlay b/src/platform/telink/tlsr9528a_2m_flash_lzma.overlay new file mode 100644 index 000000000000..922d7b632726 --- /dev/null +++ b/src/platform/telink/tlsr9528a_2m_flash_lzma.overlay @@ -0,0 +1,35 @@ +&flash { + reg = <0x20000000 0x200000>; + + /delete-node/ partitions; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0xf000>; + }; + slot0_partition: partition@f000 { + label = "image-0"; + reg = <0xf000 0x139000>; + }; + factory_partition: partition@148000 { + label = "factory-data"; + reg = <0x148000 0x1000>; + }; + storage_partition: partition@149000 { + label = "storage"; + reg = <0x149000 0xc000>; + }; + slot1_partition: partition@155000 { + label = "image-1"; + reg = <0x155000 0xa9000>; + }; + vendor_partition: partition@1fe000 { + label = "vendor-data"; + reg = <0x1fe000 0x2000>; + }; + }; +}; From e64fe126288bceac50f595cf850bd69a52b680ae Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Fri, 20 Feb 2026 20:34:19 +0200 Subject: [PATCH 03/31] [Telink] Fix stale DTS on rebuild (#43235) --- scripts/build/builders/telink.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index 306159a2b3f3..186df23599e1 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -213,8 +213,7 @@ def get_cmd_prefixes(self): return cmd def generate(self): - if os.path.exists(self.output_dir): - return + os.makedirs(self.output_dir, exist_ok=True) flags = [] if self.enable_ota: From 949369cb1989382942c7ffa7568f7e5adbf97602 Mon Sep 17 00:00:00 2001 From: Haiwen Xia Date: Wed, 26 Nov 2025 13:26:01 +0800 Subject: [PATCH 04/31] telink: tl3238x: add new soc. - add tl3238x into matter. telink: tl3238x: adjust boot setting . - close bootstrap and bootvalitdate. - adjust rf settings. telink: tl3238x: add partition and dual mode logic. - add 2m partition for customer. - setting different discriminator. - add dual mode logic. - enable ota. telink: tl3238x: enlarge the ble thread stack. - after change the ble controller , the thread need to enlarge in pm mode. telink: tl3238x: open ota and lzma for contact-sensor. - open ota and add lzma. telink: tl3238x: enlarge malloc. - enlarge heap size for tl3238x. telink: tl3238x: enlarge ble thread . - enlarge ble thread stack for jenkins alarm to 100%. Signed-off-by: haiwen.xia Signed-off-by: yinghao.ji --- config/telink/app/bootloader.conf | 4 +- .../telink/app/bootloader_compress_lzma.conf | 2 +- config/telink/chip-module/Kconfig.defaults | 41 +++---- examples/contact-sensor-app/telink/prj.conf | 6 +- examples/light-switch-app/telink/prj.conf | 8 +- examples/lighting-app/telink/prj.conf | 8 +- .../telink/common/include/AppTaskCommon.h | 25 +++++ .../telink/common/src/AppTaskCommon.cpp | 100 +++++++++++++++++- .../telink/project_include/OpenThreadConfig.h | 4 +- scripts/build/build/targets.py | 3 + scripts/build/builders/telink.py | 9 ++ .../build/testdata/all_targets_linux_x64.txt | 2 +- .../telink/CHIPDevicePlatformConfig.h | 3 +- src/platform/telink/CHIPPlatformConfig.h | 6 +- src/platform/telink/SystemPlatformConfig.h | 7 +- src/platform/telink/tl3238x_2m_flash.overlay | 75 +++++++++++++ 16 files changed, 264 insertions(+), 39 deletions(-) create mode 100644 src/platform/telink/tl3238x_2m_flash.overlay diff --git a/config/telink/app/bootloader.conf b/config/telink/app/bootloader.conf index cdc60a11c7a8..a8c3c0c7d8b7 100644 --- a/config/telink/app/bootloader.conf +++ b/config/telink/app/bootloader.conf @@ -16,7 +16,7 @@ # 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,7 @@ 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 # 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. diff --git a/config/telink/app/bootloader_compress_lzma.conf b/config/telink/app/bootloader_compress_lzma.conf index 6cab83229bae..4ee33768e7d6 100644 --- a/config/telink/app/bootloader_compress_lzma.conf +++ b/config/telink/app/bootloader_compress_lzma.conf @@ -20,7 +20,7 @@ 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 # 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. diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index f3e410ade62e..8478e299605e 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -69,17 +69,17 @@ config POSIX_MAX_FDS # Application stack size config MAIN_STACK_SIZE default 4864 if SOC_RISCV_TELINK_W91 - default 3240 if PM || SOC_RISCV_TELINK_TL321X + default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X 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_W91 config ISR_STACK_SIZE - default 800 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_W91 + default 800 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_W91 config SYSTEM_WORKQUEUE_STACK_SIZE default 664 if PM && !SOC_RISCV_TELINK_W91 @@ -90,6 +90,7 @@ config HEAP_MEM_POOL_SIZE config COMMON_LIBC_MALLOC_ARENA_SIZE default 19000 if SOC_RISCV_TELINK_TL321X && !ZEPHYR_VERSION_3_3 + default 20716 if SOC_RISCV_TELINK_TL323X && !ZEPHYR_VERSION_3_3 default 29448 if SOC_RISCV_TELINK_W91 default 20716 @@ -110,20 +111,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_TL323X 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 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 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 default 32 config GPIO @@ -152,15 +153,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 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 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 default 251 config BT_BUF_EVT_RX_COUNT @@ -189,6 +190,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 840 if SOC_RISCV_TELINK_TL323X default 712 config TL_BLE_CTRL_MASTER_MAX_NUM @@ -222,12 +224,12 @@ 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 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 config PWM default n if PM @@ -236,7 +238,7 @@ 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_TL7218X config PWM default y endif @@ -283,7 +285,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 default 2048 if !PM || SOC_RISCV_TELINK_W91 # Set multiplicator of Name Value Storage (NVS) as 1 to reach NVS sector size 4KB @@ -344,7 +346,7 @@ config IEEE802154_TLX_ACTIVE_STAGE_OPTIMIZATION default n if BOARD_TL3218X_RETENTION config OPENTHREAD_THREAD_STACK_SIZE - default 2400 if PM || SOC_RISCV_TELINK_TL321X + default 2400 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X config OPENTHREAD_RADIO_WORKQUEUE_STACK_SIZE default 496 if PM && ZEPHYR_VERSION_3_3 @@ -356,9 +358,10 @@ 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 9 + default 6 if PM + default 11 config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS default 2 if PM @@ -368,11 +371,11 @@ 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 config NET_RX_STACK_SIZE default 2048 if SOC_RISCV_TELINK_W91 - default 664 if PM || SOC_RISCV_TELINK_TL321X + default 664 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X # Disable certain parts of Zephyr IPv6 stack config NET_IPV6_NBR_CACHE diff --git a/examples/contact-sensor-app/telink/prj.conf b/examples/contact-sensor-app/telink/prj.conf index 7e6094d78e2c..5b7ce94f3253 100755 --- a/examples/contact-sensor-app/telink/prj.conf +++ b/examples/contact-sensor-app/telink/prj.conf @@ -29,7 +29,7 @@ CONFIG_CHIP_DEVICE_PRODUCT_ID=32774 CONFIG_BT_DEVICE_NAME="TelinkSensor" # Disable Matter OTA DFU -CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_OTA_REQUESTOR=y CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 # Disable CHIP shell support @@ -42,3 +42,7 @@ CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n # Enable Power Management CONFIG_PM=y + +#compress ota +CONFIG_COMPRESS_LZMA=y +CONFIG_LZMA=y diff --git a/examples/light-switch-app/telink/prj.conf b/examples/light-switch-app/telink/prj.conf index f8bea0d44ace..2ebe31f12964 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -29,7 +29,7 @@ CONFIG_CHIP_DEVICE_PRODUCT_ID=32772 CONFIG_BT_DEVICE_NAME="TelinkSwitch" # Disable Matter OTA DFU -CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_OTA_REQUESTOR=y CONFIG_CHIP_DFU_OVER_BT_SMP=n CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 @@ -42,6 +42,10 @@ 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 + +#compress ota +CONFIG_COMPRESS_LZMA=y +CONFIG_LZMA=y diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index c10b0e182294..28944ffe13b3 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -29,7 +29,7 @@ CONFIG_CHIP_DEVICE_PRODUCT_ID=32773 CONFIG_BT_DEVICE_NAME="TelinkLight" # Disable Matter OTA DFU -CONFIG_CHIP_OTA_REQUESTOR=n +CONFIG_CHIP_OTA_REQUESTOR=y CONFIG_CHIP_DFU_OVER_BT_SMP=n CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 @@ -46,6 +46,10 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n # Enable PWM CONFIG_PWM=y - +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=n + +#compress ota +CONFIG_COMPRESS_LZMA=y +CONFIG_LZMA=y diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index 1867423aecfa..db7d7c99b4cb 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; diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 3f8864692488..0a60aa2c8f2e 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -88,6 +88,60 @@ bool sIsNetworkEnabled = false; bool sIsNetworkAttached = false; bool sHaveBLEConnections = false; +#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(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); + } +} + #if APP_SET_DEVICE_INFO_PROVIDER chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; #endif @@ -173,7 +227,45 @@ class AppFabricTableDelegate : public FabricTable::Delegate { if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) { - k_work_schedule(&sDelayedFactoryResetWork, K_SECONDS(2)); + ChipLogProgress(DeviceLayer, "Erasing settings partition"); + + // TC-OPCREDS-3.6 (device doesn't need to reboot automatically after the last fabric is removed) can't use FactoryReset + void * storage = nullptr; + int status = settings_storage_get(&storage); + + if (!status) + { + status = nvs_clear(static_cast(storage)); + } + + if (!status) + { + status = nvs_mount(static_cast(storage)); + } + + if (status) + { + ChipLogError(DeviceLayer, "Storage clear failed: %d", status); + } +#ifdef CONFIG_TFLM_FEATURE + AppTask::MicroSpeechProcessStop(); +#endif + // Reboot in case of failed commissioning to allow new pairing via BLE + if (sIsCommissioningFailed) + { + ChipLogProgress(DeviceLayer, "Rebooting board"); + sys_reboot(SYS_REBOOT_WARM); + } + else + { +#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 + ChipLogProgress(DeviceLayer, "Do factory_reset and reboot"); + chip::Server::GetInstance().ScheduleFactoryReset(); + } } } }; @@ -572,7 +664,7 @@ void AppTaskCommon::StartBleAdvButtonEventHandler(void) void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) { LOG_INF("StartBleAdvHandler"); - + dual_mode_switch(OPCODE_SWITCH_ZIGBEE); // Disable manual Matter service BLE advertising after device provisioning. if (sIsNetworkProvisioned) { @@ -618,6 +710,7 @@ void AppTaskCommon::FactoryResetHandler(AppEvent * aEvent) sFactoryResetCntr = 0; chip::Server::GetInstance().ScheduleFactoryReset(); + dual_mode_switch(OPCODE_FACTORY_RESET); } } @@ -798,6 +891,9 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* Server::GetInstance().GetFailSafeContext().ForceFailSafeTimerExpiry(); } break; + case DeviceEventType::kCommissioningComplete: + dual_mode_switch(OPCODE_MATTER_PAIRED); + break; #if CHIP_DEVICE_CONFIG_ENABLE_THREAD case DeviceEventType::kDnssdInitialized: #if CONFIG_CHIP_OTA_REQUESTOR diff --git a/examples/platform/telink/project_include/OpenThreadConfig.h b/examples/platform/telink/project_include/OpenThreadConfig.h index 0e23617e28e2..e34698f27717 100644 --- a/examples/platform/telink/project_include/OpenThreadConfig.h +++ b/examples/platform/telink/project_include/OpenThreadConfig.h @@ -27,13 +27,13 @@ /* 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 #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 #undef OPENTHREAD_CONFIG_MLE_MAX_CHILDREN #define OPENTHREAD_CONFIG_MLE_MAX_CHILDREN 5 #endif diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index ff7d49c056a2..a804326b0a38 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -782,6 +782,9 @@ 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_ml3m', board=TelinkBoard.TL3238X_ML3M), + TargetPart('tl3238x_retention', board=TelinkBoard.TL3238X_RETENTION), TargetPart('tl7218x', board=TelinkBoard.TL7218X), TargetPart('tl7218x_ml7g', board=TelinkBoard.TL7218X_ML7G), TargetPart('tl7218x_ml7m', board=TelinkBoard.TL7218X_ML7M), diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index 186df23599e1..720cf0e51a5f 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -127,6 +127,9 @@ class TelinkBoard(Enum): TL3218X = auto() TL3218X_ML3M = auto() TL3218X_RETENTION = auto() + TL3238X = auto() + TL3238X_ML3M = auto() + TL3238X_RETENTION = auto() TL7218X = auto() TL7218X_ML7G = auto() TL7218X_ML7M = auto() @@ -147,6 +150,12 @@ def GnArgName(self): return 'tl3218x_ml3m' if self == TelinkBoard.TL3218X_RETENTION: return 'tl3218x_retention' + if self == TelinkBoard.TL3238X: + return 'tl3238x' + if self == TelinkBoard.TL3238X_ML3M: + return 'tl3238x_ml3m' + if self == TelinkBoard.TL3238X_RETENTION: + return 'tl3238x_retention' if self == TelinkBoard.TL7218X: return 'tl7218x' if self == TelinkBoard.TL7218X_ML7G: diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index ca23b252fc12..180d1e73acc4 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,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,tl7218x,tl7218x_ml7g,tl7218x_ml7m,tl7218x_retention,tlsr9118bdk40d,tlsr9518adk80d,tlsr9528a,tlsr9528a_retention}-{air-quality-sensor,all-clusters,all-clusters-minimal,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][-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/src/platform/telink/CHIPDevicePlatformConfig.h b/src/platform/telink/CHIPDevicePlatformConfig.h index 8229b781a22a..d8365178485a 100644 --- a/src/platform/telink/CHIPDevicePlatformConfig.h +++ b/src/platform/telink/CHIPDevicePlatformConfig.h @@ -108,7 +108,8 @@ #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_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) diff --git a/src/platform/telink/CHIPPlatformConfig.h b/src/platform/telink/CHIPPlatformConfig.h index d7eeaca5d9a0..99db9a5ba829 100644 --- a/src/platform/telink/CHIPPlatformConfig.h +++ b/src/platform/telink/CHIPPlatformConfig.h @@ -62,7 +62,7 @@ #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) #ifndef CHIP_CONFIG_MAX_GROUP_DATA_PEERS #define CHIP_CONFIG_MAX_GROUP_DATA_PEERS 5 @@ -72,9 +72,9 @@ #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) -#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 #ifndef CHIP_CONFIG_MAX_GROUP_DATA_PEERS #define CHIP_CONFIG_MAX_GROUP_DATA_PEERS 7 diff --git a/src/platform/telink/SystemPlatformConfig.h b/src/platform/telink/SystemPlatformConfig.h index d32c260f7e64..37a4bcc5ed3c 100644 --- a/src/platform/telink/SystemPlatformConfig.h +++ b/src/platform/telink/SystemPlatformConfig.h @@ -44,8 +44,8 @@ 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_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 +56,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_W91) #define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 0 #else #define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8 diff --git a/src/platform/telink/tl3238x_2m_flash.overlay b/src/platform/telink/tl3238x_2m_flash.overlay new file mode 100644 index 000000000000..058ff51894dc --- /dev/null +++ b/src/platform/telink/tl3238x_2m_flash.overlay @@ -0,0 +1,75 @@ +&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@16000 { + 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 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + 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. + }; + }; +}; From 010d1666a53fbf67adaaafe29e4fd5872a165226 Mon Sep 17 00:00:00 2001 From: haiwentelink <125550736+haiwentelink@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:26:02 +0800 Subject: [PATCH 05/31] Develop tl3238x develop merge v1.0.1.0 (#417) - Optimized the RAM layout(default IRAM 96k, DRAM 64K). - Optimized the 802.15.4 driver in Zephyr and power consumption in Matter ICD mode. - Implemented retention deep sleep mode drivers for ADC and I2C under Zephyr. - Adjusted the clock speed support under different power mode, default retention deep sleep mode is 48MHz, fully power mode is 96MHz. - Supported TL9268M full power mode. Signed-off-by: haiwen.xia Signed-off-by: Fengtai Xie Signed-off-by: jinmiao.yu Signed-off-by: Jinmiao Yu Signed-off-by: pulin1103 Signed-off-by: Damien Ji Signed-off-by: Hao Wu Co-authored-by: Alex Tsitsiura Co-authored-by: jinmiao.yu Co-authored-by: hao.wu Co-authored-by: Fengtai Xie Co-authored-by: pulin1103 Co-authored-by: Damien Ji --- .github/workflows/examples-telink.yaml | 4 +- .../telink/app/bootloader_compress_lzma.conf | 3 + config/telink/chip-module/CMakeLists.txt | 2 +- config/telink/chip-module/Kconfig | 9 + config/telink/chip-module/Kconfig.defaults | 6 +- .../contact-sensor-app/telink/CMakeLists.txt | 5 + examples/contact-sensor-app/telink/prj.conf | 25 ++- examples/light-switch-app/telink/prj.conf | 25 ++- examples/lighting-app/telink/prj.conf | 24 ++- examples/platform/telink/common.cmake | 8 +- .../telink/common/include/AppTaskCommon.h | 4 +- .../telink/common/src/AppTaskCommon.cpp | 157 +++++++++++++++- .../platform/telink/util/include/DFUOverSMP.h | 10 ++ .../platform/telink/util/src/DFUOverSMP.cpp | 18 ++ scripts/build/build/targets.py | 1 + scripts/build/builders/telink.py | 5 + scripts/tools/telink/mfg_tool.py | 169 +++++++++++++++--- scripts/tools/telink/process_binaries.py | 3 +- .../BasicInformationCluster.cpp | 10 +- .../platform/DeviceInstanceInfoProvider.h | 16 ++ .../GenericConfigurationManagerImpl.ipp | 5 + ...nericThreadStackManagerImpl_OpenThread.hpp | 13 ++ src/platform/telink/BLEManagerImpl.cpp | 45 ++++- src/platform/telink/BLEManagerImpl.h | 5 + .../telink/CHIPDevicePlatformConfig.h | 12 ++ src/platform/telink/FactoryDataParser.c | 117 ++++++++++-- src/platform/telink/FactoryDataParser.h | 15 ++ src/platform/telink/FactoryDataProvider.cpp | 69 ++++++- src/platform/telink/FactoryDataProvider.h | 1 + src/platform/telink/tl3238x_2m_flash.overlay | 2 +- .../telink/tl3238x_2m_flash_backup.overlay | 55 ++++++ .../telink/tl3238x_2m_lzma_flash.overlay | 75 ++++++++ src/platform/telink/tl3238x_4m_flash.overlay | 70 ++++++++ .../telink/tl3238x_4m_lzma_flash.overlay | 70 ++++++++ .../openthread/csma_next_operation.patch | 43 +++++ 35 files changed, 1046 insertions(+), 55 deletions(-) create mode 100644 src/platform/telink/tl3238x_2m_flash_backup.overlay create mode 100644 src/platform/telink/tl3238x_2m_lzma_flash.overlay create mode 100644 src/platform/telink/tl3238x_4m_flash.overlay create mode 100644 src/platform/telink/tl3238x_4m_lzma_flash.overlay create mode 100644 third_party_patches/openthread/csma_next_operation.patch diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 467893f95fcd..053babec6650 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -57,8 +57,8 @@ 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 42f57a7692969193ece78fde32354c6208043c25" - name: Build tools required for Factory Data # Run test for master and all PRs diff --git a/config/telink/app/bootloader_compress_lzma.conf b/config/telink/app/bootloader_compress_lzma.conf index 4ee33768e7d6..429d378279ff 100644 --- a/config/telink/app/bootloader_compress_lzma.conf +++ b/config/telink/app/bootloader_compress_lzma.conf @@ -45,3 +45,6 @@ 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 \ No newline at end of file diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 459d2a9aae2e..6f5326ed1ae5 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -208,7 +208,7 @@ 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_DUAL_MODE=${CONFIG_DUAL_MODE} -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 cp ${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin ${PROJECT_BINARY_DIR}/mcuboot.bin ) diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index ff51f17b19ba..c3aedeb3045f 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -279,3 +279,12 @@ endif config TFLM_FEATURE bool "Enable the TFLM micro speech feature" default n + +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 diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 8478e299605e..b46f9c0bce27 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -337,6 +337,7 @@ config OPENTHREAD_CSMABACKOFF_OPTIMIZATION config IEEE802154_TLX_OPTIMIZATION bool "Optimize 802.15.4 RF performance for TLX SoCs" + default y if PM && SOC_RISCV_TELINK_TL323X default n help Improve RF performance in IEEE 802.15.4 communication on TLX SoCs. @@ -350,6 +351,8 @@ config OPENTHREAD_THREAD_STACK_SIZE config OPENTHREAD_RADIO_WORKQUEUE_STACK_SIZE default 496 if PM && ZEPHYR_VERSION_3_3 + default 608 if PM && SOC_RISCV_TELINK_TL323X + default 608 if SOC_RISCV_TELINK_TL323X default 640 config OPENTHREAD_SLAAC @@ -360,7 +363,8 @@ config OPENTHREAD_MANUAL_START # 6 is the max rf level by Vant config OPENTHREAD_DEFAULT_TX_POWER - default 6 if PM + default 6 if PM && (SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL721X) + default 3 if PM && SOC_RISCV_TELINK_TL323X default 11 config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS diff --git a/examples/contact-sensor-app/telink/CMakeLists.txt b/examples/contact-sensor-app/telink/CMakeLists.txt index 47ec87579425..745f0f4dc3be 100755 --- a/examples/contact-sensor-app/telink/CMakeLists.txt +++ b/examples/contact-sensor-app/telink/CMakeLists.txt @@ -57,3 +57,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/prj.conf b/examples/contact-sensor-app/telink/prj.conf index 5b7ce94f3253..e132e1087b9e 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=y +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y + CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 # Disable CHIP shell support @@ -39,10 +42,30 @@ 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 #compress ota CONFIG_COMPRESS_LZMA=y CONFIG_LZMA=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 + +#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 + +# 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 \ No newline at end of file diff --git a/examples/light-switch-app/telink/prj.conf b/examples/light-switch-app/telink/prj.conf index 2ebe31f12964..798d760ba99c 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -30,8 +30,8 @@ CONFIG_BT_DEVICE_NAME="TelinkSwitch" # Disable Matter OTA DFU CONFIG_CHIP_OTA_REQUESTOR=y -CONFIG_CHIP_DFU_OVER_BT_SMP=n -CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 # Disable CHIP shell support @@ -42,10 +42,29 @@ 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 +# CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=y #compress ota CONFIG_COMPRESS_LZMA=y CONFIG_LZMA=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 + +#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 + +# 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 diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index 28944ffe13b3..2ff8b12c4e41 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -30,8 +30,8 @@ CONFIG_BT_DEVICE_NAME="TelinkLight" # Disable Matter OTA DFU CONFIG_CHIP_OTA_REQUESTOR=y -CONFIG_CHIP_DFU_OVER_BT_SMP=n -CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=n +CONFIG_CHIP_DFU_OVER_BT_SMP=y +CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 CONFIG_TELINK_OTA_BUTTON_TEST=n @@ -44,6 +44,10 @@ 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 @@ -51,5 +55,17 @@ CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 CONFIG_PM=n #compress ota -CONFIG_COMPRESS_LZMA=y -CONFIG_LZMA=y +CONFIG_COMPRESS_LZMA=n +CONFIG_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.should use 4m flash +CONFIG_DUAL_MODE=2 + +# Enable Independent Button +CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE=n + +# Enable CHIP-ID via ble +CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n diff --git a/examples/platform/telink/common.cmake b/examples/platform/telink/common.cmake index a414c050ba3d..148e38cc3f9f 100644 --- a/examples/platform/telink/common.cmake +++ b/examples/platform/telink/common.cmake @@ -126,9 +126,11 @@ else() unset(USB_CONF_OVERLAY_FILE) endif() +set(FIRMWARE_COMPRESS_LZMA "") if(${CONFIG_COMPRESS_LZMA} MATCHES y) set(BOOT_CONF_OVERLAY_FILE "${CHIP_ROOT}/config/telink/app/bootloader_compress_lzma.conf") set(FLASH_LAYOUT_SUFFIX "_lzma") + set(FIRMWARE_COMPRESS_LZMA "lzma_") else() set(BOOT_CONF_OVERLAY_FILE "${CHIP_ROOT}/config/telink/app/bootloader.conf") set(FLASH_LAYOUT_SUFFIX "") @@ -166,7 +168,11 @@ if(NOT EXISTS "${GLOBAL_DTC_OVERLAY_FILE}") unset(GLOBAL_DTC_OVERLAY_FILE) endif() -set(FLASH_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_${FLASH_SIZE}_flash${FLASH_LAYOUT_SUFFIX}.overlay") +if(${BASE_BOARD} MATCHES "tl3238x") + set(FLASH_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_${FLASH_SIZE}_${FIRMWARE_COMPRESS_LZMA}flash.overlay") +else() + set(FLASH_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_${FLASH_SIZE}_flash${FLASH_LAYOUT_SUFFIX}.overlay") +endif() if(NOT EXISTS "${FLASH_DTC_OVERLAY_FILE}") message(STATUS "${FLASH_DTC_OVERLAY_FILE} doesn't exist") unset(FLASH_DTC_OVERLAY_FILE) diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index db7d7c99b4cb..fadd9d0b2349 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -134,7 +134,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); diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 0a60aa2c8f2e..c5e1bf570862 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -88,6 +88,7 @@ bool sIsNetworkEnabled = false; bool sIsNetworkAttached = false; bool sHaveBLEConnections = false; +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE || CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE #include #include #include @@ -111,6 +112,11 @@ bool sHaveBLEConnections = false; // 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 }; @@ -142,6 +148,95 @@ void dual_mode_switch(int32_t op) } } +#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) + +/*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 * flash_para_dev = DUAL_MODE_PARTITION_DEVICE; +const struct device * zb_para_dev = ZB_NVS_PARTITION_DEVICE; +const struct device * matter_nvs_dev = MATTER_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 + #if APP_SET_DEVICE_INFO_PROVIDER chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; #endif @@ -312,6 +407,25 @@ 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 + CHIP_ERROR AppTaskCommon::StartApp(void) { CHIP_ERROR err = GetAppTask().Init(); @@ -322,6 +436,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 @@ -664,7 +787,6 @@ void AppTaskCommon::StartBleAdvButtonEventHandler(void) void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) { LOG_INF("StartBleAdvHandler"); - dual_mode_switch(OPCODE_SWITCH_ZIGBEE); // Disable manual Matter service BLE advertising after device provisioning. if (sIsNetworkProvisioned) { @@ -710,7 +832,9 @@ void AppTaskCommon::FactoryResetHandler(AppEvent * aEvent) sFactoryResetCntr = 0; chip::Server::GetInstance().ScheduleFactoryReset(); + #if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE dual_mode_switch(OPCODE_FACTORY_RESET); + #endif } } @@ -892,8 +1016,32 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* } 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 @@ -906,6 +1054,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: 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/src/DFUOverSMP.cpp b/examples/platform/telink/util/src/DFUOverSMP.cpp index bdbe10aae26c..e408ed123317 100644 --- a/examples/platform/telink/util/src/DFUOverSMP.cpp +++ b/examples/platform/telink/util/src/DFUOverSMP.cpp @@ -36,6 +36,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 +66,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 a804326b0a38..925514732c5e 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -828,6 +828,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 720cf0e51a5f..23549ae8be9f 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -188,6 +188,7 @@ def __init__(self, tflm_config: bool = False, chip_enable_nfc_onboarding_payload: bool = False, log_level: TelinkLogLevel = TelinkLogLevel.DEFAULT, + dual_mode_config: int = 0, ): super(TelinkBuilder, self).__init__(root, runner) self.app = app @@ -206,6 +207,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 def get_cmd_prefixes(self): if not self._runner.dry_run: @@ -264,6 +266,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/tools/telink/mfg_tool.py b/scripts/tools/telink/mfg_tool.py index 7d4baf9998d8..250090960920 100755 --- a/scripts/tools/telink/mfg_tool.py +++ b/scripts/tools/telink/mfg_tool.py @@ -34,6 +34,9 @@ import pyqrcode from intelhex import IntelHex +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from cryptography.hazmat.backends import default_backend + TOOLS = { 'spake2p': None, 'chip-cert': None, @@ -58,7 +61,6 @@ NVS_MEMORY = {} - def nvs_memory_append(key, value): if isinstance(value, str): NVS_MEMORY[key] = value.encode("utf-8") @@ -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 args.secure_programming_verification == False: + 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") @@ -731,20 +850,22 @@ def main(): with open(os.sep.join([out_dir_top, "device_sn.csv"]), "w") as f: f.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') - out_dirs = setup_out_dir(out_dir_top, args, serial_num_str) - add_additional_kv(args, serial_num_str) - generate_passcode(args, out_dirs) - generate_discriminator(args, out_dirs) - 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_json_summary(args, out_dirs, pai_cert, dacs_cert, serial_num_str) + for i in range(args.count): + pai_cert = {} + serial_num_str = format(serial_num_int + i, 'x') + 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) + generate_discriminator(args, out_dirs) + 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, dacs_cert, out_dirs) + generate_json_summary(args, out_dirs, pai_cert, dacs_cert, serial_num_str) + + dev_sn_file.close() if __name__ == "__main__": diff --git a/scripts/tools/telink/process_binaries.py b/scripts/tools/telink/process_binaries.py index 2b36f384f5fd..4faf05196d89 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/src/app/clusters/basic-information/BasicInformationCluster.cpp b/src/app/clusters/basic-information/BasicInformationCluster.cpp index 90e192e22061..3965e8e4a1ff 100644 --- a/src/app/clusters/basic-information/BasicInformationCluster.cpp +++ b/src/app/clusters/basic-information/BasicInformationCluster.cpp @@ -173,9 +173,13 @@ inline CHIP_ERROR ReadManufacturingDate(DeviceInstanceInfoProvider & deviceInfoP uint8_t manufacturingMonth; uint8_t manufacturingDayOfMonth; size_t totalManufacturingDateLen = 0; + +#if defined(CHIP_DEVICE_SECURE_PROGRAMMING) && CHIP_DEVICE_SECURE_PROGRAMMING + CHIP_ERROR status = deviceInfoProvider->GetManufacturingDateString(manufacturingDateString, sizeof(manufacturingDateString)); +#else MutableCharSpan vendorSuffixSpan(manufacturingDateString + kMaxDateLength, sizeof(manufacturingDateString) - kMaxDateLength); CHIP_ERROR status = deviceInfoProvider.GetManufacturingDate(manufacturingYear, manufacturingMonth, manufacturingDayOfMonth); - +#endif // TODO: Remove defaulting once proper runtime defaulting of unimplemented factory data is done if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) { @@ -187,6 +191,9 @@ inline CHIP_ERROR ReadManufacturingDate(DeviceInstanceInfoProvider & deviceInfoP } ReturnErrorOnFailure(status); +#if defined(CHIP_DEVICE_SECURE_PROGRAMMING) && CHIP_DEVICE_SECURE_PROGRAMMING + return aEncoder.Encode(CharSpan(manufacturingDateString, strnlen(manufacturingDateString, kMaxLen))); +#else // Format is YYYYMMDD snprintf(manufacturingDateString, sizeof(manufacturingDateString), "%04u%02u%02u", manufacturingYear, manufacturingMonth, manufacturingDayOfMonth); @@ -201,6 +208,7 @@ inline CHIP_ERROR ReadManufacturingDate(DeviceInstanceInfoProvider & deviceInfoP VerifyOrDie(totalManufacturingDateLen <= kMaxLen); return aEncoder.Encode(CharSpan(manufacturingDateString, totalManufacturingDateLen)); +#endif } inline CHIP_ERROR ReadUniqueID(DeviceLayer::ConfigurationManager & configManager, AttributeValueEncoder & aEncoder) diff --git a/src/include/platform/DeviceInstanceInfoProvider.h b/src/include/platform/DeviceInstanceInfoProvider.h index 23bc9659cd7f..3d29d8eaed20 100644 --- a/src/include/platform/DeviceInstanceInfoProvider.h +++ b/src/include/platform/DeviceInstanceInfoProvider.h @@ -167,6 +167,22 @@ 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. * diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index a8831bd6a4e7..44ced290efc3 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 f8dbe33e3aea..ebfb86bb4aea 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 { @@ -365,6 +369,15 @@ 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/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index 56c3c3add938..3005e837956d 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -87,6 +87,11 @@ 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 + bt_uuid_16 UUID16_CHIPoBLEService = BT_UUID_INIT_16(0xFFF6); _bt_gatt_ccc CHIPoBLEChar_TX_CCC = BT_GATT_CCC_INITIALIZER(nullptr, BLEManagerImpl::HandleTXCCCWrite, nullptr); @@ -110,6 +115,13 @@ 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 }; bt_gatt_service sChipoBleService = BT_GATT_SERVICE(sChipoBleAttributes); @@ -946,8 +958,39 @@ CHIP_ERROR BLEManagerImpl::HandleBleConnectionClosed(const ChipDeviceEvent * eve return CHIP_NO_ERROR; } +#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 + #if CHIP_DEVICE_CONFIG_ENABLE_THREAD -CHIP_ERROR BLEManagerImpl::HandleOperationalNetworkEnabled(const ChipDeviceEvent * event) +CHIP_ERROR +BLEManagerImpl::HandleOperationalNetworkEnabled(const ChipDeviceEvent * event) { ChipLogDetail(DeviceLayer, "HandleOperationalNetworkEnabled"); diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index dff0874fac14..52bfc0948a61 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -172,6 +172,11 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla bool NeedToResetFailSafeTimer(void); void ClearResetFailSafeTimerFlag(void); +#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 + #if CHIP_DEVICE_CONFIG_ENABLE_THREAD // Switch context from BLE to Thread void SwitchToIeee802154(void); diff --git a/src/platform/telink/CHIPDevicePlatformConfig.h b/src/platform/telink/CHIPDevicePlatformConfig.h index d8365178485a..01c36829b748 100644 --- a/src/platform/telink/CHIPDevicePlatformConfig.h +++ b/src/platform/telink/CHIPDevicePlatformConfig.h @@ -121,6 +121,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 + // ========== Platform-specific Configuration ========= // These are configuration options that are unique to Zephyr platforms. diff --git a/src/platform/telink/FactoryDataParser.c b/src/platform/telink/FactoryDataParser.c index a2d4c26ede99..224f99bffd93 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 +#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 + 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..370e60a99785 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/tl3238x_2m_flash.overlay b/src/platform/telink/tl3238x_2m_flash.overlay index 058ff51894dc..9e9886e30976 100644 --- a/src/platform/telink/tl3238x_2m_flash.overlay +++ b/src/platform/telink/tl3238x_2m_flash.overlay @@ -22,7 +22,7 @@ // 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@16000 { + slot0_matter_partition: partition@15000_1 { label = "image-0-matter"; reg = <0x15000 0xe5000>; // suppose matter is 916k (0xe5000) }; diff --git a/src/platform/telink/tl3238x_2m_flash_backup.overlay b/src/platform/telink/tl3238x_2m_flash_backup.overlay new file mode 100644 index 000000000000..2352450cc755 --- /dev/null +++ b/src/platform/telink/tl3238x_2m_flash_backup.overlay @@ -0,0 +1,55 @@ +&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 916k + }; + 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 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + 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_lzma_flash.overlay b/src/platform/telink/tl3238x_2m_lzma_flash.overlay new file mode 100644 index 000000000000..9e9886e30976 --- /dev/null +++ b/src/platform/telink/tl3238x_2m_lzma_flash.overlay @@ -0,0 +1,75 @@ +&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 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + 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..02ead8922059 --- /dev/null +++ b/src/platform/telink/tl3238x_4m_flash.overlay @@ -0,0 +1,70 @@ +&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 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + 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_lzma_flash.overlay b/src/platform/telink/tl3238x_4m_lzma_flash.overlay new file mode 100644 index 000000000000..02ead8922059 --- /dev/null +++ b/src/platform/telink/tl3238x_4m_lzma_flash.overlay @@ -0,0 +1,70 @@ +&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 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + }; + 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/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(); + } + } From 1193f9e566a0c2c3bf12b1b4faaf2baa988e3704 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Wed, 25 Feb 2026 15:55:07 +0200 Subject: [PATCH 06/31] [Telink] add BLE extended advertising (#43277) * [Telink] Add BLE extended advertising * [Telink] Fix DISCOVERY_TIMEOUT * [Telink] Don't enable extended advertising by default * [Telibk] Fix typo --- src/platform/telink/BLEManagerImpl.cpp | 81 +++++++++++++++---- src/platform/telink/BLEManagerImpl.h | 6 +- .../telink/CHIPDevicePlatformConfig.h | 8 +- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index 3005e837956d..4f8e7d94d1e2 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -293,18 +294,40 @@ inline CHIP_ERROR BLEManagerImpl::PrepareAdvertisingRequest(void) Encoding::LittleEndian::Put16(serviceData.uuid, UUID16_CHIPoBLEService.val); ReturnErrorOnFailure(ConfigurationMgr().GetBLEDeviceIdentificationInfo(serviceData.deviceIdInfo)); +#if CHIP_DEVICE_CONFIG_EXT_ADVERTISING + if (mFlags.Has(Flags::kExtendedAdvertisingEnabled)) + { + serviceData.deviceIdInfo.SetVendorId(DEVICE_HANDLE_NULL); + serviceData.deviceIdInfo.SetProductId(DEVICE_HANDLE_NULL); + serviceData.deviceIdInfo.SetExtendedAnnouncementFlag(true); + } +#endif + advertisingData[0] = BT_DATA(BT_DATA_FLAGS, &kAdvertisingFlags, sizeof(kAdvertisingFlags)); advertisingData[1] = BT_DATA(BT_DATA_SVC_DATA16, &serviceData, sizeof(serviceData)); scanResponseData[0] = BT_DATA(BT_DATA_NAME_COMPLETE, name, nameSize); - mAdvertisingRequest.priority = CHIP_DEVICE_BLE_ADVERTISING_PRIORITY; - mAdvertisingRequest.options = kAdvertisingOptions; - mAdvertisingRequest.minInterval = mFlags.Has(Flags::kFastAdvertisingEnabled) - ? CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN - : CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN; - mAdvertisingRequest.maxInterval = mFlags.Has(Flags::kFastAdvertisingEnabled) - ? CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MAX - : CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX; + mAdvertisingRequest.priority = CHIP_DEVICE_BLE_ADVERTISING_PRIORITY; + mAdvertisingRequest.options = kAdvertisingOptions; + + if (mFlags.Has(Flags::kFastAdvertisingEnabled)) + { + mAdvertisingRequest.minInterval = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN; + mAdvertisingRequest.maxInterval = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MAX; + } +#if CHIP_DEVICE_CONFIG_EXT_ADVERTISING + else if (mFlags.Has(Flags::kExtendedAdvertisingEnabled)) + { + mAdvertisingRequest.minInterval = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN; + mAdvertisingRequest.maxInterval = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX; + } +#endif + else + { + mAdvertisingRequest.minInterval = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN; + mAdvertisingRequest.maxInterval = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX; + } + mAdvertisingRequest.advertisingData = Span(advertisingData); mAdvertisingRequest.scanResponseData = nameSize ? Span(scanResponseData) : Span{}; @@ -408,10 +431,17 @@ CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) if (mFlags.Has(Flags::kFastAdvertisingEnabled)) { - // Start timer to change advertising interval. + // Start timer to change advertising interval from fast to slow. TEMPORARY_RETURN_IGNORED DeviceLayer::SystemLayer().StartTimer( System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME), - HandleBLEAdvertisementIntervalChange, this); + HandleSlowBLEAdvertisementInterval, this); + +#if CHIP_DEVICE_CONFIG_EXT_ADVERTISING + // Start timer to schedule start of the extended advertising + TEMPORARY_RETURN_IGNORED DeviceLayer::SystemLayer().StartTimer( + System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS), + HandleExtendedBLEAdvertisementInterval, this); +#endif } } @@ -437,6 +467,10 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) mFlags.Clear(Flags::kAdvertising); mFlags.Set(Flags::kFastAdvertisingEnabled, true); +#if CHIP_DEVICE_CONFIG_EXT_ADVERTISING + mFlags.Clear(Flags::kExtendedAdvertisingEnabled); +#endif + ChipLogProgress(DeviceLayer, "CHIPoBLE advertising stopped"); // Post a CHIPoBLEAdvertisingChange(Stopped) event. @@ -448,7 +482,8 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) } // Cancel timer event changing CHIPoBLE advertisement interval - DeviceLayer::SystemLayer().CancelTimer(HandleBLEAdvertisementIntervalChange, this); + DeviceLayer::SystemLayer().CancelTimer(HandleSlowBLEAdvertisementInterval, this); + DeviceLayer::SystemLayer().CancelTimer(HandleExtendedBLEAdvertisementInterval, this); } return CHIP_NO_ERROR; @@ -461,6 +496,9 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) ChipLogDetail(DeviceLayer, "CHIPoBLE advertising set to %s", val ? "on" : "off"); mFlags.Set(Flags::kAdvertisingEnabled, val); + // Ensure that each enabling/disabling of the general advertising clears + // the extended mode, to make sure we always start fresh in the regular mode + mFlags.Set(Flags::kExtendedAdvertisingEnabled, false); TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0); } @@ -473,8 +511,14 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode) { case BLEAdvertisingMode::kFastAdvertising: mFlags.Set(Flags::kFastAdvertisingEnabled, true); + mFlags.Set(Flags::kExtendedAdvertisingEnabled, false); break; case BLEAdvertisingMode::kSlowAdvertising: + mFlags.Set(Flags::kFastAdvertisingEnabled, false); + mFlags.Set(Flags::kExtendedAdvertisingEnabled, false); + break; + case BLEAdvertisingMode::kExtendedAdvertising: + mFlags.Set(Flags::kExtendedAdvertisingEnabled, true); mFlags.Set(Flags::kFastAdvertisingEnabled, false); break; default: @@ -669,12 +713,18 @@ CHIP_ERROR BLEManagerImpl::PrepareC3CharData(void) } #endif -void BLEManagerImpl::HandleBLEAdvertisementIntervalChange(System::Layer * layer, void * param) +void BLEManagerImpl::HandleSlowBLEAdvertisementInterval(System::Layer * layer, void * param) { TEMPORARY_RETURN_IGNORED BLEMgr().SetAdvertisingMode(BLEAdvertisingMode::kSlowAdvertising); ChipLogProgress(DeviceLayer, "CHIPoBLE advertising mode changed to slow"); } +void BLEManagerImpl::HandleExtendedBLEAdvertisementInterval(System::Layer * layer, void * param) +{ + TEMPORARY_RETURN_IGNORED BLEMgr().SetAdvertisingMode(BLEAdvertisingMode::kExtendedAdvertising); + ChipLogProgress(DeviceLayer, "CHIPoBLE advertising mode changed to extended"); +} + void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -774,7 +824,8 @@ CHIP_ERROR BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const Chi params->attr = &sChipoBleAttributes[kCHIPoBLE_CCC_AttributeIndex]; params->func = HandleTXIndicated; params->data = pBuf->Start(); - params->len = pBuf->DataLength(); + VerifyOrExit(CanCastTo(pBuf->DataLength()), err = CHIP_ERROR_MESSAGE_TOO_LONG); + params->len = static_cast(pBuf->DataLength()); status = bt_gatt_indicate(conId, params); VerifyOrExit(status == 0, err = MapErrorZephyr(status)); @@ -933,8 +984,10 @@ ssize_t BLEManagerImpl::HandleC3Read(struct bt_conn * conId, const struct bt_gat return 0; } + // For BLE, the max payload size is limited to UINT16_MAX since the length + // field is 2 bytes long. So, the cast to uint16_t should be fine. return bt_gatt_attr_read(conId, attr, buf, len, offset, sInstance.c3CharDataBufferHandle->Start(), - sInstance.c3CharDataBufferHandle->DataLength()); + static_cast(sInstance.c3CharDataBufferHandle->DataLength())); } #endif diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index 52bfc0948a61..3596e2eb633c 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2022-2024 Project CHIP Authors + * Copyright (c) 2022-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. @@ -92,6 +92,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla kAdvertisingRefreshNeeded = 0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */ kChipoBleGattServiceRegister = 0x0020, /**< The system has currently CHIPoBLE GATT service registered. */ + kExtendedAdvertisingEnabled = 0x0040, /**< The application has enabled extended advertising. */ }; struct ServiceData; @@ -150,7 +151,8 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla static void HandleTXIndicated(bt_conn * conn, bt_gatt_indicate_params * attr, uint8_t err); static void HandleConnect(bt_conn * conn, uint8_t err); static void HandleDisconnect(bt_conn * conn, uint8_t reason); - static void HandleBLEAdvertisementIntervalChange(System::Layer * layer, void * param); + static void HandleSlowBLEAdvertisementInterval(System::Layer * layer, void * param); + static void HandleExtendedBLEAdvertisementInterval(System::Layer * layer, void * param); // ===== Members for internal use by the following friends. diff --git a/src/platform/telink/CHIPDevicePlatformConfig.h b/src/platform/telink/CHIPDevicePlatformConfig.h index 01c36829b748..6530ee0598bf 100644 --- a/src/platform/telink/CHIPDevicePlatformConfig.h +++ b/src/platform/telink/CHIPDevicePlatformConfig.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2022-2024 Project CHIP Authors + * Copyright (c) 2022-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. @@ -263,6 +263,12 @@ #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 #endif // CONFIG_CHIP_EXTENDED_DISCOVERY +#ifdef CONFIG_CHIP_BLE_EXT_ADVERTISING +#define CHIP_DEVICE_CONFIG_EXT_ADVERTISING 1 +#endif // CONFIG_CHIP_BLE_EXT_ADVERTISING + +#define CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS (CONFIG_CHIP_BLE_ADVERTISING_DURATION * 60) + #ifndef CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL #ifdef CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL #define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL) From 06615ab73668654bb68bc846dfbca2ff9d29df8f Mon Sep 17 00:00:00 2001 From: "haiwen.xia" Date: Wed, 18 Mar 2026 17:57:36 +0800 Subject: [PATCH 07/31] telink: tl3238x: release descriptor space for users. - lowdown the secure partition and add user config partition for user. telink: tl3238x: add and fix some config - Open CONFIG_ADC in lighting-app/light-switch-app/contact-sensor-app . - Fix the compilation will fail when CONFIG_LOG=n . telink: tl3238x: reduce fc time - Accelerate factory_reset run time . telink: tl3238x: enlarge ble stack. - after change the ble lib , the ble stack need to enlarge 256. Signed-off-by: Fengtai Xie Signed-off-by: haiwen.xia --- config/telink/chip-module/Kconfig.defaults | 2 +- examples/contact-sensor-app/telink/prj.conf | 10 ++++++---- examples/light-switch-app/telink/prj.conf | 8 +++++--- examples/lighting-app/telink/prj.conf | 6 ++++-- src/platform/telink/ThreadStackManagerImpl.cpp | 2 +- src/platform/telink/tl3238x_2m_flash.overlay | 6 +++++- src/platform/telink/tl3238x_2m_flash_backup.overlay | 6 +++++- src/platform/telink/tl3238x_2m_lzma_flash.overlay | 6 +++++- src/platform/telink/tl3238x_4m_flash.overlay | 6 +++++- src/platform/telink/tl3238x_4m_lzma_flash.overlay | 6 +++++- 10 files changed, 42 insertions(+), 16 deletions(-) diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index b46f9c0bce27..cfd0377cac17 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -190,7 +190,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 840 if SOC_RISCV_TELINK_TL323X + default 1096 if SOC_RISCV_TELINK_TL323X default 712 config TL_BLE_CTRL_MASTER_MAX_NUM diff --git a/examples/contact-sensor-app/telink/prj.conf b/examples/contact-sensor-app/telink/prj.conf index e132e1087b9e..146538c14625 100755 --- a/examples/contact-sensor-app/telink/prj.conf +++ b/examples/contact-sensor-app/telink/prj.conf @@ -46,26 +46,28 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n # CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=y +# Enable ADC +CONFIG_ADC=y #compress ota CONFIG_COMPRESS_LZMA=y CONFIG_LZMA=y #ICD SETTING INFO -CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 +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 -#matter switch mode +#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 # open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE -# init should be n +# init should be n CONFIG_SECURE_PROGRAMMING=n # Enable CHIP-ID via ble -CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n \ No newline at end of file +CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n diff --git a/examples/light-switch-app/telink/prj.conf b/examples/light-switch-app/telink/prj.conf index 798d760ba99c..8bb7d139bd65 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -45,25 +45,27 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n # CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=y +# Enable ADC +CONFIG_ADC=y #compress ota CONFIG_COMPRESS_LZMA=y CONFIG_LZMA=y #ICD SETTING INFO -CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 +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 -#matter switch mode +#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 # open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE -# init should be n +# init should be n CONFIG_SECURE_PROGRAMMING=n # Enable CHIP-ID via ble diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index 2ff8b12c4e41..4c1fcfa4e322 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -45,7 +45,7 @@ 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 +# init should be n CONFIG_SECURE_PROGRAMMING=n # Enable PWM @@ -53,12 +53,14 @@ CONFIG_PWM=y CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=n +# Enable ADC +CONFIG_ADC=y #compress ota CONFIG_COMPRESS_LZMA=n CONFIG_LZMA=n -# matter switch mode +# 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.should use 4m flash diff --git a/src/platform/telink/ThreadStackManagerImpl.cpp b/src/platform/telink/ThreadStackManagerImpl.cpp index 455a9af6e571..c8fd77e449c0 100644 --- a/src/platform/telink/ThreadStackManagerImpl.cpp +++ b/src/platform/telink/ThreadStackManagerImpl.cpp @@ -73,7 +73,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/tl3238x_2m_flash.overlay b/src/platform/telink/tl3238x_2m_flash.overlay index 9e9886e30976..249608848d98 100644 --- a/src/platform/telink/tl3238x_2m_flash.overlay +++ b/src/platform/telink/tl3238x_2m_flash.overlay @@ -53,7 +53,11 @@ }; secure_partition: partition@1f8000 { label = "secure"; - reg = <0x1f8000 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + 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"; diff --git a/src/platform/telink/tl3238x_2m_flash_backup.overlay b/src/platform/telink/tl3238x_2m_flash_backup.overlay index 2352450cc755..2fe5cafe183c 100644 --- a/src/platform/telink/tl3238x_2m_flash_backup.overlay +++ b/src/platform/telink/tl3238x_2m_flash_backup.overlay @@ -33,7 +33,11 @@ }; secure_partition: partition@1f8000 { label = "secure"; - reg = <0x1f8000 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + 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"; diff --git a/src/platform/telink/tl3238x_2m_lzma_flash.overlay b/src/platform/telink/tl3238x_2m_lzma_flash.overlay index 9e9886e30976..249608848d98 100644 --- a/src/platform/telink/tl3238x_2m_lzma_flash.overlay +++ b/src/platform/telink/tl3238x_2m_lzma_flash.overlay @@ -53,7 +53,11 @@ }; secure_partition: partition@1f8000 { label = "secure"; - reg = <0x1f8000 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + 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"; diff --git a/src/platform/telink/tl3238x_4m_flash.overlay b/src/platform/telink/tl3238x_4m_flash.overlay index 02ead8922059..fa0284405499 100644 --- a/src/platform/telink/tl3238x_4m_flash.overlay +++ b/src/platform/telink/tl3238x_4m_flash.overlay @@ -48,7 +48,11 @@ }; secure_partition: partition@3f8000 { label = "secure"; - reg = <0x3f8000 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + 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"; diff --git a/src/platform/telink/tl3238x_4m_lzma_flash.overlay b/src/platform/telink/tl3238x_4m_lzma_flash.overlay index 02ead8922059..fa0284405499 100644 --- a/src/platform/telink/tl3238x_4m_lzma_flash.overlay +++ b/src/platform/telink/tl3238x_4m_lzma_flash.overlay @@ -48,7 +48,11 @@ }; secure_partition: partition@3f8000 { label = "secure"; - reg = <0x3f8000 0x2000>; // secure info ,reserved for secure boot .if not use , can beused by other way . + 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"; From f8ee8cf05f4a5f8943a59effd67d9522beff04a4 Mon Sep 17 00:00:00 2001 From: 0x0023 Date: Fri, 27 Mar 2026 18:58:39 +0800 Subject: [PATCH 08/31] tl323x: Merge SBoot or ZB FW (#428) * Merge SBoot or ZB FW - Add commands to merge Secure Boot or Zigbee FW if exits - Enable BOOT_VALIDATE_SLOT0 but disable BOOT_BANNER to output chip_id Signed-off-by: Damien Ji * Enable BOOT_VALIDATE_SLOT0_ONCE to validate slot0 for only once. Signed-off-by: Damien Ji * update boot signature key file - CONFIG_BOOT_SIGNATURE_KEY_FILE - CONFIG_MCUBOOT_SIGNATURE_KEY_FILE Signed-off-by: Damien Ji * Extend Boot Signature Key File in More Apps - add CONFIG_MCUBOOT_SIGNATURE_KEY_FILE in contact-sensor-app, light-switch-app, lighting-app, and lock-app - Disable CONFIG_BOOT_SIGNATURE_KEY_FILE and CONFIG_MCUBOOT_SIGNATURE_KEY_FILE in configuration files Signed-off-by: Damien Ji --------- Signed-off-by: Damien Ji --- config/telink/app/bootloader.conf | 8 ++ .../telink/app/bootloader_compress_lzma.conf | 9 +- config/telink/chip-module/CMakeLists.txt | 84 ++++++++++++++++++- examples/contact-sensor-app/telink/prj.conf | 2 + examples/light-switch-app/telink/prj.conf | 2 + examples/lighting-app/telink/prj.conf | 2 + examples/lock-app/telink/prj.conf | 25 ++++++ 7 files changed, 128 insertions(+), 4 deletions(-) diff --git a/config/telink/app/bootloader.conf b/config/telink/app/bootloader.conf index a8c3c0c7d8b7..522ddd663bec 100644 --- a/config/telink/app/bootloader.conf +++ b/config/telink/app/bootloader.conf @@ -28,6 +28,7 @@ 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=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. @@ -43,3 +44,10 @@ CONFIG_BOOT_MAX_IMG_SECTORS=512 CONFIG_MCUBOOT_LOG_LEVEL_INF=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_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 429d378279ff..e370e753eb87 100644 --- a/config/telink/app/bootloader_compress_lzma.conf +++ b/config/telink/app/bootloader_compress_lzma.conf @@ -21,6 +21,7 @@ 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=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. @@ -46,5 +47,9 @@ 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 \ No newline at end of file +# Disabling the banner is to allow cmd tool to better parse the chip ID, avoid interface. +CONFIG_BOOT_BANNER=n + +# 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 6f5326ed1ae5..8ce0ca3b85c9 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -193,12 +193,45 @@ endif() # Define 'process_binaries' target for collecting final binary to flash # ============================================================================== +set(BLOCK_SIZE "1024") + +if(CONFIG_SOC_RISCV_TELINK_TL323X) +set(SOC "TL323X") + +# 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}") + +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}") + +set(ZB_FILE_PATH "${ZEPHYR_BASE}/${SOC}_FW/ZB/Zigbee-SampleDemo.bin") + +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}") + +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(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 @@ -210,8 +243,55 @@ if (CONFIG_BOOTLOADER_MCUBOOT AND (CONFIG_SOC_RISCV_TELINK_B9X OR CONFIG_SOC_RIS west build -b ${BASE_BOARD} -d build_mcuboot ${ZEPHYR_BASE}/../bootloader/mcuboot/boot/zephyr -- -DCONFIG_DUAL_MODE=${CONFIG_DUAL_MODE} -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 - cp ${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin ${PROJECT_BINARY_DIR}/mcuboot.bin + 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 ) + 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 (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_OFFSETZB_FW_OFFSET} | 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() + message(WARNING "File ${ZB_FILE_PATH} does not exist. merge_zigbee target will not be created.") + endif() endif() # ============================================================================== diff --git a/examples/contact-sensor-app/telink/prj.conf b/examples/contact-sensor-app/telink/prj.conf index 146538c14625..178dd1d40e4e 100755 --- a/examples/contact-sensor-app/telink/prj.conf +++ b/examples/contact-sensor-app/telink/prj.conf @@ -71,3 +71,5 @@ CONFIG_SECURE_PROGRAMMING=n # Enable CHIP-ID via ble CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" diff --git a/examples/light-switch-app/telink/prj.conf b/examples/light-switch-app/telink/prj.conf index 8bb7d139bd65..0def5f29710b 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -70,3 +70,5 @@ CONFIG_SECURE_PROGRAMMING=n # Enable CHIP-ID via ble CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index 4c1fcfa4e322..6005936739e6 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -71,3 +71,5 @@ CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE=n # Enable CHIP-ID via ble CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" diff --git a/examples/lock-app/telink/prj.conf b/examples/lock-app/telink/prj.conf index 7e9df11e659a..6231058a107e 100755 --- a/examples/lock-app/telink/prj.conf +++ b/examples/lock-app/telink/prj.conf @@ -42,3 +42,28 @@ CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n # Enable Power Management CONFIG_PM=y + +#compress ota +CONFIG_COMPRESS_LZMA=y +CONFIG_LZMA=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 + +#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 + +# 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 + +# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" From a945af7dcc7491055adfa9c32627525dcd4a43c1 Mon Sep 17 00:00:00 2001 From: fenton1609 Date: Wed, 15 Apr 2026 08:52:18 +0800 Subject: [PATCH 09/31] telink: tl3238x: update multiple operation lists for mass production (#438) - Add ota event callback . - Add deferred storage attributes for provider . - Increase maximum group number per fabric . - Apply HW Hash and set BOOT_IMG_HASH_DIRECTLY_ON_STORAGE . - Increase the ISR_STACK_SIZE to 1024 . - Increase the SYSTEM_WORKQUEUE_STACK_SIZE to 2048 . - Increase the HEAP_MEM_POOL_SIZE to 1280 . - Increase the COMMON_LIBC_MALLOC_ARENA_SIZE to 20716 . - Increase the NET_IF_MCAST_IPV6_ADDR_COUNT to 47 . - Increase the TL_BLE_CTRL_THREAD_STACK_SIZE to 1536 . - Increase the OPENTHREAD_THREAD_STACK_SIZE to 4096 . - Increase the OPENTHREAD_RADIO_WORKQUEUE_STACK_SIZE to 2048 . - Increase the OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS to 40 . - Increase the NET_RX_STACK_SIZE to 2048 . Signed-off-by: Fengtai Xie Co-authored-by: Damien Ji --- .github/workflows/examples-telink.yaml | 2 +- config/telink/app/bootloader.conf | 2 + .../telink/app/bootloader_compress_lzma.conf | 2 + config/telink/chip-module/Kconfig | 4 ++ config/telink/chip-module/Kconfig.defaults | 20 +++--- .../contact-sensor-app/telink/CMakeLists.txt | 1 + examples/contact-sensor-app/telink/prj.conf | 3 + .../light-switch-app/telink/CMakeLists.txt | 1 + examples/light-switch-app/telink/prj.conf | 3 + examples/lighting-app/telink/CMakeLists.txt | 1 + examples/lighting-app/telink/prj.conf | 3 + examples/lock-app/telink/CMakeLists.txt | 1 + examples/lock-app/telink/prj.conf | 9 ++- .../telink/common/include/AppTaskCommon.h | 2 + .../telink/common/src/AppTaskCommon.cpp | 72 +++++++++++++++++++ src/platform/telink/CHIPPlatformConfig.h | 8 +++ 16 files changed, 121 insertions(+), 13 deletions(-) diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 053babec6650..d4914bd6177c 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -58,7 +58,7 @@ jobs: 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 42f57a7692969193ece78fde32354c6208043c25" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py d31d26afcd55cea3b43df82dbd51ecefeedf8993" - name: Build tools required for Factory Data # Run test for master and all PRs diff --git a/config/telink/app/bootloader.conf b/config/telink/app/bootloader.conf index 522ddd663bec..00f04d04ab78 100644 --- a/config/telink/app/bootloader.conf +++ b/config/telink/app/bootloader.conf @@ -48,6 +48,8 @@ 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 e370e753eb87..e2fb166e9ef2 100644 --- a/config/telink/app/bootloader_compress_lzma.conf +++ b/config/telink/app/bootloader_compress_lzma.conf @@ -50,6 +50,8 @@ 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/Kconfig b/config/telink/chip-module/Kconfig index c3aedeb3045f..428339265f00 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -288,3 +288,7 @@ config SECURE_PROGRAMMING 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 cfd0377cac17..deb582d0758f 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -79,19 +79,21 @@ config IDLE_STACK_SIZE default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_W91 config ISR_STACK_SIZE - default 800 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_W91 + default 1024 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_W91 config SYSTEM_WORKQUEUE_STACK_SIZE - default 664 if PM && !SOC_RISCV_TELINK_W91 + default 2048 if PM && !SOC_RISCV_TELINK_W91 config HEAP_MEM_POOL_SIZE default 256 if ZEPHYR_VERSION_3_3 + default 1796 if SOC_RISCV_TELINK_TL323X default 1280 config COMMON_LIBC_MALLOC_ARENA_SIZE default 19000 if SOC_RISCV_TELINK_TL321X && !ZEPHYR_VERSION_3_3 default 20716 if SOC_RISCV_TELINK_TL323X && !ZEPHYR_VERSION_3_3 default 29448 if SOC_RISCV_TELINK_W91 + default 26584 if SOC_RISCV_TELINK_TL323X default 20716 config NET_IPV6_MLD @@ -102,7 +104,7 @@ config NET_IF_UNICAST_IPV6_ADDR_COUNT default 6 config NET_IF_MCAST_IPV6_ADDR_COUNT - default 8 if PM + default 47 if PM || SOC_RISCV_TELINK_TL323X default 15 config NET_IF_IPV6_PREFIX_COUNT @@ -190,7 +192,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 1096 if SOC_RISCV_TELINK_TL323X + default 1536 if SOC_RISCV_TELINK_TL323X default 712 config TL_BLE_CTRL_MASTER_MAX_NUM @@ -285,7 +287,7 @@ config NVS_LOOKUP_CACHE default y config NVS_LOOKUP_CACHE_SIZE - default 400 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 400 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X default 2048 if !PM || SOC_RISCV_TELINK_W91 # Set multiplicator of Name Value Storage (NVS) as 1 to reach NVS sector size 4KB @@ -347,11 +349,11 @@ config IEEE802154_TLX_ACTIVE_STAGE_OPTIMIZATION default n if BOARD_TL3218X_RETENTION config OPENTHREAD_THREAD_STACK_SIZE - default 2400 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 4096 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X config OPENTHREAD_RADIO_WORKQUEUE_STACK_SIZE default 496 if PM && ZEPHYR_VERSION_3_3 - default 608 if PM && SOC_RISCV_TELINK_TL323X + default 2048 if PM && SOC_RISCV_TELINK_TL323X default 608 if SOC_RISCV_TELINK_TL323X default 640 @@ -368,7 +370,7 @@ config OPENTHREAD_DEFAULT_TX_POWER default 11 config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS - default 2 if PM + default 40 if PM || SOC_RISCV_TELINK_TL323X default 8 endif # NET_L2_OPENTHREAD @@ -379,7 +381,7 @@ config NET_TX_STACK_SIZE config NET_RX_STACK_SIZE default 2048 if SOC_RISCV_TELINK_W91 - default 664 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 2048 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X # Disable certain parts of Zephyr IPv6 stack config NET_IPV6_NBR_CACHE diff --git a/examples/contact-sensor-app/telink/CMakeLists.txt b/examples/contact-sensor-app/telink/CMakeLists.txt index 745f0f4dc3be..72959d768a95 100755 --- a/examples/contact-sensor-app/telink/CMakeLists.txt +++ b/examples/contact-sensor-app/telink/CMakeLists.txt @@ -38,6 +38,7 @@ target_sources(app PRIVATE src/AppTask.cpp src/ContactSensorManager.cpp src/ZclCallbacks.cpp + ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp diff --git a/examples/contact-sensor-app/telink/prj.conf b/examples/contact-sensor-app/telink/prj.conf index 178dd1d40e4e..294b8666a2cd 100755 --- a/examples/contact-sensor-app/telink/prj.conf +++ b/examples/contact-sensor-app/telink/prj.conf @@ -72,4 +72,7 @@ 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/CMakeLists.txt b/examples/light-switch-app/telink/CMakeLists.txt index dde7205b38b0..6ae1d14fc9fb 100755 --- a/examples/light-switch-app/telink/CMakeLists.txt +++ b/examples/light-switch-app/telink/CMakeLists.txt @@ -39,6 +39,7 @@ target_sources(app PRIVATE src/AppTask.cpp src/ZclCallbacks.cpp src/binding-handler.cpp + ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp diff --git a/examples/light-switch-app/telink/prj.conf b/examples/light-switch-app/telink/prj.conf index 0def5f29710b..0e30c8d8fc8d 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -71,4 +71,7 @@ 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/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index dbdef1d38393..d182edb230a9 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -51,6 +51,7 @@ endif() target_sources(app PRIVATE src/AppTask.cpp src/ZclCallbacks.cpp + ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index 6005936739e6..ec2e848855f6 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -72,4 +72,7 @@ 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/CMakeLists.txt b/examples/lock-app/telink/CMakeLists.txt index 384dbdfc288f..059a279b310d 100755 --- a/examples/lock-app/telink/CMakeLists.txt +++ b/examples/lock-app/telink/CMakeLists.txt @@ -40,6 +40,7 @@ target_sources(app PRIVATE src/ZclCallbacks.cpp src/LockManager.cpp src/LockSettingsStorage.cpp + ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp diff --git a/examples/lock-app/telink/prj.conf b/examples/lock-app/telink/prj.conf index 6231058a107e..2b72c8f89c23 100755 --- a/examples/lock-app/telink/prj.conf +++ b/examples/lock-app/telink/prj.conf @@ -48,22 +48,25 @@ CONFIG_COMPRESS_LZMA=y CONFIG_LZMA=y #ICD SETTING INFO -CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 +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 -#matter switch mode +#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 # open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE -# init should be n +# 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/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index fadd9d0b2349..f81e497a0173 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -167,6 +167,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 c5e1bf570862..cfa5ddcd9836 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -34,6 +34,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -88,6 +92,37 @@ bool sIsNetworkEnabled = false; bool sIsNetworkAttached = false; bool sHaveBLEConnections = false; +/** + * @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)); + #if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE || CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE #include #include @@ -541,6 +576,7 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR); #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); + VerifyOrDie(gSimpleAttributePersistence.Init(initParams.persistentStorageDelegate) == CHIP_NO_ERROR); #if APP_SET_DEVICE_INFO_PROVIDER gExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); @@ -550,6 +586,9 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); + /* Add deferred storage attribute for provider */ + app::SetAttributePersistenceProvider(&gDeferredAttributePersister); + ConfigurationMgr().LogDeviceConfig(); PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); @@ -982,6 +1021,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) @@ -1099,6 +1168,9 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* UpdateStatusLED(); #endif break; + case DeviceEventType::kOtaStateChanged: + AppTaskCommon::OtaEventsHandler(event); + break; default: break; } diff --git a/src/platform/telink/CHIPPlatformConfig.h b/src/platform/telink/CHIPPlatformConfig.h index 99db9a5ba829..ad857237e67f 100644 --- a/src/platform/telink/CHIPPlatformConfig.h +++ b/src/platform/telink/CHIPPlatformConfig.h @@ -114,6 +114,14 @@ #endif // 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 From f077c7fae4b237128559a4a1f799035b9080ed6a Mon Sep 17 00:00:00 2001 From: Fengtai Xie Date: Fri, 10 Apr 2026 11:47:26 +0800 Subject: [PATCH 10/31] telink: tl3238x: ota resume optimization for non-supporting ecosystems - Add OTA resume watchdog to avoid the question . telink: 3238x: improve the speed of factory_reset. - change the logic from the ScheduleFactoryReset() to earse NVS [Telink] Fix CNET 4.12 thread switching Restyled by clang-format Signed-off-by: Fengtai Xie Signed-off-by: haiwen.xia --- .../telink/common/src/AppTaskCommon.cpp | 25 ++++++++++++------- src/platform/telink/BLEManagerImpl.cpp | 11 ++++++-- src/platform/telink/OTAImageProcessorImpl.cpp | 14 ++++++++++- src/platform/telink/OTAImageProcessorImpl.h | 9 ++++--- .../telink/ThreadStackManagerImpl.cpp | 16 +++++++++++- src/platform/telink/ThreadStackManagerImpl.h | 1 + 6 files changed, 60 insertions(+), 16 deletions(-) diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index cfa5ddcd9836..5893d3ebf830 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -122,12 +122,19 @@ DefaultAttributePersistenceProvider gSimpleAttributePersistence; DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttributePersistence, Span(gPersisters, ATTRIBUTES_ARRAY_SIZE), System::Clock::Milliseconds32(DEFERRED_STORAGE_TIME)); - -#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE || CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE #include #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. @@ -204,15 +211,10 @@ user_para_t user_para; #define ZB_NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(ZB_NVS_PARTITION) #define ZB_NVS_START_ADR FIXED_PARTITION_OFFSET(ZB_NVS_PARTITION) -/*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 * flash_para_dev = DUAL_MODE_PARTITION_DEVICE; const struct device * zb_para_dev = ZB_NVS_PARTITION_DEVICE; -const struct device * matter_nvs_dev = MATTER_NVS_PARTITION_DEVICE; + constexpr int kDnssTimeout = 60000; #if !CONFIG_MCUMGR_TRANSPORT_BT @@ -870,10 +872,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); } } diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index 4f8e7d94d1e2..8e84961322d3 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -1048,6 +1048,14 @@ BLEManagerImpl::HandleOperationalNetworkEnabled(const ChipDeviceEvent * event) ChipLogDetail(DeviceLayer, "HandleOperationalNetworkEnabled"); CHIP_ERROR error = CHIP_NO_ERROR; + if (!ThreadStackMgrImpl().IsReadyToAttach()) + { + // Ignore operational-network notifications once the one-time BLE->Thread + // handoff is complete. Pure Thread-to-Thread switches should be handled + // by the Thread stack directly. + return CHIP_NO_ERROR; + } + /* On first commissioning BLE disconnects before switching to Thread operational network. All subsequent Thread operational network changes are handled in a bit different way */ if (!mReadyToAttachThread) @@ -1070,8 +1078,6 @@ BLEManagerImpl::HandleOperationalNetworkEnabled(const ChipDeviceEvent * event) error = PlatformMgr().PostEvent(&attachEvent); VerifyOrExit(error == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "PostEvent err: %" CHIP_ERROR_FORMAT, error.Format())); - - TEMPORARY_RETURN_IGNORED ThreadStackMgrImpl().CommitConfiguration(); } exit: @@ -1105,6 +1111,7 @@ void BLEManagerImpl::SwitchToIeee802154(void) // Init Thread ThreadStackMgrImpl().SetRadioBlocked(false); TEMPORARY_RETURN_IGNORED ThreadStackMgrImpl().SetThreadEnabled(true); + ThreadStackMgrImpl().SetReadyToAttach(false); } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/telink/OTAImageProcessorImpl.cpp b/src/platform/telink/OTAImageProcessorImpl.cpp index 919eaee2f37a..c2d401171377 100644 --- a/src/platform/telink/OTAImageProcessorImpl.cpp +++ b/src/platform/telink/OTAImageProcessorImpl.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -142,6 +141,16 @@ CHIP_ERROR OTAImageProcessorImpl::Apply() #endif } +void OTAImageProcessorImpl::ResumeWatchdogHandler(System::Layer * systemLayer, void * context) +{ + auto * self = static_cast(context); + ChipLogError(SoftwareUpdate, "Resume not supported by OTA provider"); + + LogErrorOnFailure(KeyValueStoreMgr().Delete(kDownloadedBytes)); + LogErrorOnFailure(KeyValueStoreMgr().Delete(kImageDigest)); + self->mDownloader->EndDownload(CHIP_ERROR_NOT_IMPLEMENTED); +} + CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock) { VerifyOrReturnError(mDownloader != nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -172,9 +181,12 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock) { TEMPORARY_RETURN_IGNORED mDownloader->SkipData(downloadedBytesRestored - aBlock.size()); downloadedBytesRestored = 0; + TEMPORARY_RETURN_IGNORED SystemLayer().StartTimer( + System::Clock::Milliseconds32(kResumeWatchdogTimeoutMs), ResumeWatchdogHandler, this); } else { + TEMPORARY_RETURN_IGNORED DeviceLayer::SystemLayer().CancelTimer(ResumeWatchdogHandler, this); TEMPORARY_RETURN_IGNORED mDownloader->FetchNextData(); } } diff --git a/src/platform/telink/OTAImageProcessorImpl.h b/src/platform/telink/OTAImageProcessorImpl.h index 19ebb291fa98..cb1eb3e41f61 100644 --- a/src/platform/telink/OTAImageProcessorImpl.h +++ b/src/platform/telink/OTAImageProcessorImpl.h @@ -18,6 +18,7 @@ #include #include +#include #include namespace chip { @@ -46,15 +47,17 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface CHIP_ERROR ProcessHeader(ByteSpan & aBlock); CHIP_ERROR InitFlashStream(size_t offset); CHIP_ERROR RestoreBytes(ByteSpan & aBlock); + static void ResumeWatchdogHandler(System::Layer * systemLayer, void * context); OTADownloader * mDownloader = nullptr; OTAImageHeaderParser mHeaderParser; uint8_t mBuffer[kBufferSize]; // Define non-volatile storage keys for DownloadedBytes and ImageDigest. - static constexpr char kDownloadedBytes[] = "DownloadedBytes"; - static constexpr char kImageDigest[] = "ImageDigest"; - uint64_t downloadedBytesRestored = 0; + static constexpr char kDownloadedBytes[] = "DownloadedBytes"; + static constexpr char kImageDigest[] = "ImageDigest"; + static constexpr uint16_t kResumeWatchdogTimeoutMs = 6000; + uint64_t downloadedBytesRestored = 0; }; } // namespace DeviceLayer diff --git a/src/platform/telink/ThreadStackManagerImpl.cpp b/src/platform/telink/ThreadStackManagerImpl.cpp index c8fd77e449c0..509bc044a11f 100644 --- a/src/platform/telink/ThreadStackManagerImpl.cpp +++ b/src/platform/telink/ThreadStackManagerImpl.cpp @@ -103,6 +103,17 @@ ThreadStackManagerImpl::_AttachToThreadNetwork(const Thread::OperationalDataset if (dataset.AsByteSpan().data_equal(current_dataset.AsByteSpan()) && callback == nullptr) return CHIP_NO_ERROR; + if (dataset.IsCommissioned() && current_dataset.IsCommissioned() && + !dataset.AsByteSpan().data_equal(current_dataset.AsByteSpan()) && IsThreadEnabled()) + { + result = SetThreadProvision(dataset.AsByteSpan()); + if (result == CHIP_NO_ERROR && callback != nullptr) + { + callback->OnResult(NetworkCommissioning::Status::kSuccess, CharSpan(), 0); + } + return result; + } + if (mRadioBlocked || mReadyToAttach) { /* On Telink platform it's not possible to rise Thread network when its used by BLE, @@ -111,7 +122,10 @@ ThreadStackManagerImpl::_AttachToThreadNetwork(const Thread::OperationalDataset if (result == CHIP_NO_ERROR) { mReadyToAttach = true; - callback->OnResult(NetworkCommissioning::Status::kSuccess, CharSpan(), 0); + if (callback != nullptr) + { + callback->OnResult(NetworkCommissioning::Status::kSuccess, CharSpan(), 0); + } } } else diff --git a/src/platform/telink/ThreadStackManagerImpl.h b/src/platform/telink/ThreadStackManagerImpl.h index 84f7a0755739..983a2df24524 100644 --- a/src/platform/telink/ThreadStackManagerImpl.h +++ b/src/platform/telink/ThreadStackManagerImpl.h @@ -60,6 +60,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager, // ===== Methods that implement the ThreadStackManager abstract interface. CHIP_ERROR _InitThreadStack(); void SetRadioBlocked(bool state) { mRadioBlocked = state; } + void SetReadyToAttach(bool state) { mReadyToAttach = state; } bool IsReadyToAttach(void) const { return mReadyToAttach; } void Finalize(void); CHIP_ERROR CommitConfiguration(void); From 2abddf61f89fa469622e73bd0e04981050d2cadc Mon Sep 17 00:00:00 2001 From: Damien Ji Date: Wed, 29 Apr 2026 17:59:10 +0800 Subject: [PATCH 11/31] [Telink] Update build environment and steps - remove zephyr_3_3 in examples-telink - adjust CMakeLists for more SoCs - disable persistent subscriptions exclude tl3238x and b92 - adjust DUAL_MODE by board in examples - add boards/.conf to select DUAL_MODE for tl3238x - move kconfig from example prj.conf to board.conf - reduce CHIP MAIN_STACK_SIZE and OT message buffer size for tl3218x_retention - move DeferredAttributePersistenceProvider from example to CHIP data model - include ext_pm.h for tl323x - restyled by cland-format - update zephyr to 95b2c5ae4d1a9006366d952b34d8d5f1c77b696c - update tl_ble_sdk to 200420569e5588abdd0c3d92f9e3e518e1fc8778 - disable reduntant CI actions Signed-off-by: Damien Ji --- .../{build.yaml => build.yaml.disabled} | 0 .github/workflows/chef.yaml | 3 + ...-tests.yaml => darwin-tests.yaml.disabled} | 0 .../{doxygen.yaml => doxygen.yaml.disabled} | 0 ...> example-tv-casting-darwin.yaml.disabled} | 0 ...meba.yaml => examples-ameba.yaml.disabled} | 0 ...es-asr.yaml => examples-asr.yaml.disabled} | 0 ...aml => examples-bouffalolab.yaml.disabled} | 0 ...aml => examples-cc13xx_26xx.yaml.disabled} | 0 ...2xx.yaml => examples-cc32xx.yaml.disabled} | 0 ...fr32.yaml => examples-efr32.yaml.disabled} | 0 ...sp32.yaml => examples-esp32.yaml.disabled} | 1 + ...n.yaml => examples-infineon.yaml.disabled} | 0 ....yaml => examples-linux-arm.yaml.disalbed} | 0 ....yaml => examples-linux-imx.yaml.disabled} | 0 ...> examples-linux-standalone.yaml.disabled} | 0 ...amples-linux-tv-casting-app.yaml.disabled} | 0 ...yaml => examples-nrfconnect.yaml.dsiabled} | 0 ...uttx.yaml => examples-nuttx.yaml.disabled} | 0 ...es-nxp.yaml => examples-nxp.yaml.disabled} | 0 ...es-qpg.yaml => examples-qpg.yaml.disabled} | 0 ...ek.yaml => examples-realtek.yaml.disabled} | 0 ...tm32.yaml => examples-stm32.yaml.disabled} | 0 .github/workflows/examples-telink.yaml | 282 ++---------------- ...izen.yaml => examples-tizen.yaml.disabled} | 0 ...ndroid.yaml => full-android.yaml.disabled} | 0 ...va-tests.yaml => java-tests.yaml.disabled} | 0 .../{qemu.yaml => qemu.yaml.disabled} | 0 .../{tests.yaml => tests.yaml.disabled} | 0 ...ml => unit_integration_test.yaml.disabled} | 0 .gitignore | 6 + config/telink/app/bootloader.conf | 3 + config/telink/chip-module/CMakeLists.txt | 62 ++-- config/telink/chip-module/Kconfig | 8 +- config/telink/chip-module/Kconfig.defaults | 43 ++- .../contact-sensor-app/telink/CMakeLists.txt | 1 - .../telink/boards/tl3238x_retention.conf | 17 ++ examples/contact-sensor-app/telink/prj.conf | 18 +- .../light-switch-app/telink/CMakeLists.txt | 1 - .../telink/boards/tl3238x_retention.conf | 17 ++ examples/light-switch-app/telink/prj.conf | 18 +- examples/lighting-app/telink/CMakeLists.txt | 1 - .../lighting-app/telink/boards/tl3238x.conf | 17 ++ examples/lighting-app/telink/prj.conf | 18 +- examples/lock-app/telink/CMakeLists.txt | 1 - .../telink/boards/tl3238x_retention.conf | 9 + examples/lock-app/telink/prj.conf | 10 - examples/platform/telink/common.cmake | 8 +- .../telink/common/src/AppTaskCommon.cpp | 69 +++-- .../platform/telink/util/src/DFUOverSMP.cpp | 5 +- .../build/testdata/all_targets_linux_x64.txt | 2 +- scripts/tools/telink/mfg_tool.py | 61 ++-- scripts/tools/telink/update_zephyr.py | 147 +++++++-- src/app/chip_data_model.cmake | 1 + .../platform/DeviceInstanceInfoProvider.h | 5 +- src/platform/telink/FactoryDataParser.c | 21 +- src/platform/telink/FactoryDataParser.h | 2 +- src/platform/telink/FactoryDataProvider.cpp | 3 +- src/platform/telink/OTAImageProcessorImpl.cpp | 4 +- 59 files changed, 427 insertions(+), 437 deletions(-) rename .github/workflows/{build.yaml => build.yaml.disabled} (100%) rename .github/workflows/{darwin-tests.yaml => darwin-tests.yaml.disabled} (100%) rename .github/workflows/{doxygen.yaml => doxygen.yaml.disabled} (100%) rename .github/workflows/{example-tv-casting-darwin.yaml => example-tv-casting-darwin.yaml.disabled} (100%) rename .github/workflows/{examples-ameba.yaml => examples-ameba.yaml.disabled} (100%) rename .github/workflows/{examples-asr.yaml => examples-asr.yaml.disabled} (100%) rename .github/workflows/{examples-bouffalolab.yaml => examples-bouffalolab.yaml.disabled} (100%) rename .github/workflows/{examples-cc13xx_26xx.yaml => examples-cc13xx_26xx.yaml.disabled} (100%) rename .github/workflows/{examples-cc32xx.yaml => examples-cc32xx.yaml.disabled} (100%) rename .github/workflows/{examples-efr32.yaml => examples-efr32.yaml.disabled} (100%) rename .github/workflows/{examples-esp32.yaml => examples-esp32.yaml.disabled} (99%) rename .github/workflows/{examples-infineon.yaml => examples-infineon.yaml.disabled} (100%) rename .github/workflows/{examples-linux-arm.yaml => examples-linux-arm.yaml.disalbed} (100%) rename .github/workflows/{examples-linux-imx.yaml => examples-linux-imx.yaml.disabled} (100%) rename .github/workflows/{examples-linux-standalone.yaml => examples-linux-standalone.yaml.disabled} (100%) rename .github/workflows/{examples-linux-tv-casting-app.yaml => examples-linux-tv-casting-app.yaml.disabled} (100%) rename .github/workflows/{examples-nrfconnect.yaml => examples-nrfconnect.yaml.dsiabled} (100%) rename .github/workflows/{examples-nuttx.yaml => examples-nuttx.yaml.disabled} (100%) rename .github/workflows/{examples-nxp.yaml => examples-nxp.yaml.disabled} (100%) rename .github/workflows/{examples-qpg.yaml => examples-qpg.yaml.disabled} (100%) rename .github/workflows/{examples-realtek.yaml => examples-realtek.yaml.disabled} (100%) rename .github/workflows/{examples-stm32.yaml => examples-stm32.yaml.disabled} (100%) rename .github/workflows/{examples-tizen.yaml => examples-tizen.yaml.disabled} (100%) rename .github/workflows/{full-android.yaml => full-android.yaml.disabled} (100%) rename .github/workflows/{java-tests.yaml => java-tests.yaml.disabled} (100%) rename .github/workflows/{qemu.yaml => qemu.yaml.disabled} (100%) rename .github/workflows/{tests.yaml => tests.yaml.disabled} (100%) rename .github/workflows/{unit_integration_test.yaml => unit_integration_test.yaml.disabled} (100%) create mode 100644 examples/contact-sensor-app/telink/boards/tl3238x_retention.conf create mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention.conf create mode 100644 examples/lighting-app/telink/boards/tl3238x.conf create mode 100644 examples/lock-app/telink/boards/tl3238x_retention.conf diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml.disabled similarity index 100% rename from .github/workflows/build.yaml rename to .github/workflows/build.yaml.disabled diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index affcb901c200..178b8211a0c2 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -31,6 +31,7 @@ env: jobs: chef_linux_all_devices: + if:false name: Chef - Linux CI Examples (All chef devices) timeout-minutes: 120 runs-on: ubuntu-latest @@ -55,6 +56,7 @@ jobs: ./scripts/run_in_build_env.sh "./examples/chef/chef.py --ci_linux" chef_device_functional_test: + if:false name: Chef - Device functional tests (Linux) if: github.actor != 'restyled-io[bot]' timeout-minutes: 90 @@ -93,6 +95,7 @@ jobs: scripts/run_in_python_env.sh out/python_env './scripts/tests/run_python_test.py --app examples/chef/linux/out/rootnode_dimmablelight_bCwGYSDpoe --factory-reset --script ./examples/chef/tests/dimmablelight_test.py --script-args "--commissioning-method on-network --discriminator 3840 --passcode 20202021" --app-stdin-pipe /tmp/chef_stdin.txt' chef_esp32: + if:false name: Chef - ESP32 CI Examples runs-on: ubuntu-latest if: github.actor != 'restyled-io[bot]' diff --git a/.github/workflows/darwin-tests.yaml b/.github/workflows/darwin-tests.yaml.disabled similarity index 100% rename from .github/workflows/darwin-tests.yaml rename to .github/workflows/darwin-tests.yaml.disabled diff --git a/.github/workflows/doxygen.yaml b/.github/workflows/doxygen.yaml.disabled similarity index 100% rename from .github/workflows/doxygen.yaml rename to .github/workflows/doxygen.yaml.disabled diff --git a/.github/workflows/example-tv-casting-darwin.yaml b/.github/workflows/example-tv-casting-darwin.yaml.disabled similarity index 100% rename from .github/workflows/example-tv-casting-darwin.yaml rename to .github/workflows/example-tv-casting-darwin.yaml.disabled diff --git a/.github/workflows/examples-ameba.yaml b/.github/workflows/examples-ameba.yaml.disabled similarity index 100% rename from .github/workflows/examples-ameba.yaml rename to .github/workflows/examples-ameba.yaml.disabled diff --git a/.github/workflows/examples-asr.yaml b/.github/workflows/examples-asr.yaml.disabled similarity index 100% rename from .github/workflows/examples-asr.yaml rename to .github/workflows/examples-asr.yaml.disabled diff --git a/.github/workflows/examples-bouffalolab.yaml b/.github/workflows/examples-bouffalolab.yaml.disabled similarity index 100% rename from .github/workflows/examples-bouffalolab.yaml rename to .github/workflows/examples-bouffalolab.yaml.disabled diff --git a/.github/workflows/examples-cc13xx_26xx.yaml b/.github/workflows/examples-cc13xx_26xx.yaml.disabled similarity index 100% rename from .github/workflows/examples-cc13xx_26xx.yaml rename to .github/workflows/examples-cc13xx_26xx.yaml.disabled diff --git a/.github/workflows/examples-cc32xx.yaml b/.github/workflows/examples-cc32xx.yaml.disabled similarity index 100% rename from .github/workflows/examples-cc32xx.yaml rename to .github/workflows/examples-cc32xx.yaml.disabled diff --git a/.github/workflows/examples-efr32.yaml b/.github/workflows/examples-efr32.yaml.disabled similarity index 100% rename from .github/workflows/examples-efr32.yaml rename to .github/workflows/examples-efr32.yaml.disabled diff --git a/.github/workflows/examples-esp32.yaml b/.github/workflows/examples-esp32.yaml.disabled similarity index 99% rename from .github/workflows/examples-esp32.yaml rename to .github/workflows/examples-esp32.yaml.disabled index 51d186dc7014..762e911d1321 100644 --- a/.github/workflows/examples-esp32.yaml +++ b/.github/workflows/examples-esp32.yaml.disabled @@ -181,6 +181,7 @@ jobs: platform-name: ESP32 esp32_1: + if:false name: ESP32_1 runs-on: ubuntu-latest diff --git a/.github/workflows/examples-infineon.yaml b/.github/workflows/examples-infineon.yaml.disabled similarity index 100% rename from .github/workflows/examples-infineon.yaml rename to .github/workflows/examples-infineon.yaml.disabled diff --git a/.github/workflows/examples-linux-arm.yaml b/.github/workflows/examples-linux-arm.yaml.disalbed similarity index 100% rename from .github/workflows/examples-linux-arm.yaml rename to .github/workflows/examples-linux-arm.yaml.disalbed diff --git a/.github/workflows/examples-linux-imx.yaml b/.github/workflows/examples-linux-imx.yaml.disabled similarity index 100% rename from .github/workflows/examples-linux-imx.yaml rename to .github/workflows/examples-linux-imx.yaml.disabled diff --git a/.github/workflows/examples-linux-standalone.yaml b/.github/workflows/examples-linux-standalone.yaml.disabled similarity index 100% rename from .github/workflows/examples-linux-standalone.yaml rename to .github/workflows/examples-linux-standalone.yaml.disabled diff --git a/.github/workflows/examples-linux-tv-casting-app.yaml b/.github/workflows/examples-linux-tv-casting-app.yaml.disabled similarity index 100% rename from .github/workflows/examples-linux-tv-casting-app.yaml rename to .github/workflows/examples-linux-tv-casting-app.yaml.disabled diff --git a/.github/workflows/examples-nrfconnect.yaml b/.github/workflows/examples-nrfconnect.yaml.dsiabled similarity index 100% rename from .github/workflows/examples-nrfconnect.yaml rename to .github/workflows/examples-nrfconnect.yaml.dsiabled diff --git a/.github/workflows/examples-nuttx.yaml b/.github/workflows/examples-nuttx.yaml.disabled similarity index 100% rename from .github/workflows/examples-nuttx.yaml rename to .github/workflows/examples-nuttx.yaml.disabled diff --git a/.github/workflows/examples-nxp.yaml b/.github/workflows/examples-nxp.yaml.disabled similarity index 100% rename from .github/workflows/examples-nxp.yaml rename to .github/workflows/examples-nxp.yaml.disabled diff --git a/.github/workflows/examples-qpg.yaml b/.github/workflows/examples-qpg.yaml.disabled similarity index 100% rename from .github/workflows/examples-qpg.yaml rename to .github/workflows/examples-qpg.yaml.disabled diff --git a/.github/workflows/examples-realtek.yaml b/.github/workflows/examples-realtek.yaml.disabled similarity index 100% rename from .github/workflows/examples-realtek.yaml rename to .github/workflows/examples-realtek.yaml.disabled diff --git a/.github/workflows/examples-stm32.yaml b/.github/workflows/examples-stm32.yaml.disabled similarity index 100% rename from .github/workflows/examples-stm32.yaml rename to .github/workflows/examples-stm32.yaml.disabled diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index d4914bd6177c..21cb332fd06c 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -58,7 +58,8 @@ jobs: 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 d31d26afcd55cea3b43df82dbd51ecefeedf8993" + run: + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git 95b2c5ae4d1a9006366d952b34d8d5f1c77b696c --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 200420569e5588abdd0c3d92f9e3e518e1fc8778" - name: Build tools required for Factory Data # Run test for master and all PRs @@ -199,6 +200,32 @@ jobs: - name: clean out build output (keep tools) run: rm -rf ./out/telink* + - name: Build example Telink (tl323x) 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-tl3238x-light-ota-factory-data-4mb' build" + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + telink tl3238x light-app-ota-factory-data-4mb \ + out/telink-tl3238x-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 (tl323x_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-tl3238x_retention-light-switch-ota-compress-lzma-factory-data' build" + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + telink tl3238x_retention light-switch-app-ota-compress-lzma-factory-data \ + out/telink-tl3238x_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: | @@ -383,256 +410,3 @@ jobs: if: ${{ !env.ACT }} with: platform-name: Telink - - zephyr_3_3: - name: Telink (Zephyr 3.3) - env: - BUILD_TYPE: telink - - runs-on: ubuntu-latest - if: github.actor != 'restyled-io[bot]' - - container: - image: ghcr.io/project-chip/chip-build-telink-zephyr_3_3:181 - volumes: - - "/tmp/bloat_reports:/tmp/bloat_reports" - - steps: - - name: Checkout - uses: actions/checkout@v6 - - name: Checkout submodules & Bootstrap - uses: ./.github/actions/checkout-submodules-and-bootstrap - with: - platform: telink - - - name: Set up environment for size reports - uses: ./.github/actions/setup-size-reports - if: ${{ !env.ACT }} - with: - gh-context: ${{ toJson(github) }} - - # - name: Update Zephyr version 3.3.0 (develop_3.3) to specific revision (for developers purpose) - # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py a5be7391771c64062e0cbd7fd6f7ef6e05d27a8b" - - - name: Build tools required for Factory Data - # Run test for master and all PRs - run: | - ./scripts/checkout_submodules.py --allow-changing-global-git-config --shallow --platform linux - ./scripts/build/gn_gen.sh - ./scripts/run_in_build_env.sh "ninja -C ./out/$BUILD_TYPE chip-cert chip-tool spake2p" - mv ./out/$BUILD_TYPE/chip-cert ./out/$BUILD_TYPE/chip-tool ./out/$BUILD_TYPE/spake2p ./out - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B92 retention) Air Quality Sensor App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9528a_retention-air-quality-sensor' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (W91) All Clusters App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9118bdk40d-all-clusters' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B92) All Clusters Minimal App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9528a-all-clusters-minimal' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl721x) Bridge App - # Run test for master and s07641069 PRs - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-bridge' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B92 retention) Contact Sensor App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9528a_retention-contact-sensor' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (W91) Lighting 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-tlsr9118bdk40d-light-ota-factory-data' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B91) Lighting App with OTA, RPC, 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-tlsr9518adk80d-light-ota-rpc-factory-data-4mb' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl321x) 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-tl3218x-light-ota-compress-lzma-shell-factory-data' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl321x_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-tl3218x_retention-light-switch-ota-factory-data' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl721x) Lighting App with OTA, 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-shell-factory-data' build" - - - 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' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-light-tflm' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl721x retention) Light Switch App with OTA (LZMA), Factory Data - # Run test for master and all PRs - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x_retention-light-switch-ota-compress-lzma-factory-data' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B92) Light Switch 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-tlsr9528a-light-switch-ota-compress-lzma-shell-factory-data' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B92) Lock App with DFU over BLE SMP - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9528a-lock-dfu-smp' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl321x) OTA Requestor App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl3218x-ota-requestor' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B91 USB) Pump App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9518adk80d-pump-usb' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B91) Pump Controller App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9518adk80d-pump-controller' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B91) Shell App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9518adk80d-shell' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B92 retention) Smoke CO Alarm App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9528a_retention-smoke-co-alarm' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (B92) lighting with precompiled OpenThread library - # Run test for s07641069 PRs - if: github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9528a-light-precompiled-ot' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (w91) Thermostat App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9118bdk40d-thermostat' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl721x) Window Covering App - # Run test for master and s07641069 PRs - if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-window-covering' build" - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* diff --git a/.github/workflows/examples-tizen.yaml b/.github/workflows/examples-tizen.yaml.disabled similarity index 100% rename from .github/workflows/examples-tizen.yaml rename to .github/workflows/examples-tizen.yaml.disabled diff --git a/.github/workflows/full-android.yaml b/.github/workflows/full-android.yaml.disabled similarity index 100% rename from .github/workflows/full-android.yaml rename to .github/workflows/full-android.yaml.disabled diff --git a/.github/workflows/java-tests.yaml b/.github/workflows/java-tests.yaml.disabled similarity index 100% rename from .github/workflows/java-tests.yaml rename to .github/workflows/java-tests.yaml.disabled diff --git a/.github/workflows/qemu.yaml b/.github/workflows/qemu.yaml.disabled similarity index 100% rename from .github/workflows/qemu.yaml rename to .github/workflows/qemu.yaml.disabled diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml.disabled similarity index 100% rename from .github/workflows/tests.yaml rename to .github/workflows/tests.yaml.disabled diff --git a/.github/workflows/unit_integration_test.yaml b/.github/workflows/unit_integration_test.yaml.disabled similarity index 100% rename from .github/workflows/unit_integration_test.yaml rename to .github/workflows/unit_integration_test.yaml.disabled diff --git a/.gitignore b/.gitignore index 1940bfe121eb..046255494e5e 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,9 @@ imgui.ini # Joint Fabric test harness output file admin_storage.json + +# ignore build output directories +build-* +build_* +factory_data* +*.patch \ No newline at end of file diff --git a/config/telink/app/bootloader.conf b/config/telink/app/bootloader.conf index 00f04d04ab78..e1d945741abc 100644 --- a/config/telink/app/bootloader.conf +++ b/config/telink/app/bootloader.conf @@ -43,6 +43,9 @@ 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. diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 8ce0ca3b85c9..7382d29fa1e5 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -194,32 +194,54 @@ endif() # ============================================================================== 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_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() -if(CONFIG_SOC_RISCV_TELINK_TL323X) -set(SOC "TL323X") +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}") - -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}") - -set(ZB_FILE_PATH "${ZEPHYR_BASE}/${SOC}_FW/ZB/Zigbee-SampleDemo.bin") - -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 ${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() + message(WARNING "File ${ZB_FILE_PATH} does not exist. ZB_FW_OFFSET_DECIMAL will be set to 0.") + set(ZB_FW_OFFSET_DECIMAL 0) endif() add_custom_target( @@ -241,13 +263,15 @@ 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 - -- -DCONFIG_DUAL_MODE=${CONFIG_DUAL_MODE} -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}/mcuboot_for_sign.bin ${PROJECT_BINARY_DIR}/mcuboot.bin ) message(STATUS "mcuboot_for_sign.bin is for external signing.") diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index 428339265f00..c81d33ac3051 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 diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index deb582d0758f..0da2c633b694 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -69,6 +69,7 @@ config POSIX_MAX_FDS # Application stack size config MAIN_STACK_SIZE default 4864 if SOC_RISCV_TELINK_W91 + default 3072 if PM && SOC_RISCV_TELINK_TL321X default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X default 4096 @@ -79,10 +80,12 @@ config IDLE_STACK_SIZE default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_W91 config ISR_STACK_SIZE - default 1024 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_W91 + default 800 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_W91 + default 1024 if SOC_RISCV_TELINK_TL323X config SYSTEM_WORKQUEUE_STACK_SIZE - default 2048 if PM && !SOC_RISCV_TELINK_W91 + default 664 if PM && !SOC_RISCV_TELINK_W91 + default 2048 if SOC_RISCV_TELINK_TL323X config HEAP_MEM_POOL_SIZE default 256 if ZEPHYR_VERSION_3_3 @@ -91,9 +94,8 @@ config HEAP_MEM_POOL_SIZE config COMMON_LIBC_MALLOC_ARENA_SIZE default 19000 if SOC_RISCV_TELINK_TL321X && !ZEPHYR_VERSION_3_3 - default 20716 if SOC_RISCV_TELINK_TL323X && !ZEPHYR_VERSION_3_3 + default 26584 if SOC_RISCV_TELINK_TL323X && !ZEPHYR_VERSION_3_3 default 29448 if SOC_RISCV_TELINK_W91 - default 26584 if SOC_RISCV_TELINK_TL323X default 20716 config NET_IPV6_MLD @@ -104,7 +106,8 @@ config NET_IF_UNICAST_IPV6_ADDR_COUNT default 6 config NET_IF_MCAST_IPV6_ADDR_COUNT - default 47 if PM || SOC_RISCV_TELINK_TL323X + default 47 if SOC_RISCV_TELINK_TL323X + default 8 if PM default 15 config NET_IF_IPV6_PREFIX_COUNT @@ -287,7 +290,8 @@ config NVS_LOOKUP_CACHE default y config NVS_LOOKUP_CACHE_SIZE - default 400 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 400 if SOC_RISCV_TELINK_TL321X + default 400 if SOC_RISCV_TELINK_TL323X default 2048 if !PM || SOC_RISCV_TELINK_W91 # Set multiplicator of Name Value Storage (NVS) as 1 to reach NVS sector size 4KB @@ -349,7 +353,8 @@ config IEEE802154_TLX_ACTIVE_STAGE_OPTIMIZATION default n if BOARD_TL3218X_RETENTION config OPENTHREAD_THREAD_STACK_SIZE - default 4096 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 2400 if PM || SOC_RISCV_TELINK_TL321X + default 4096 if SOC_RISCV_TELINK_TL323X config OPENTHREAD_RADIO_WORKQUEUE_STACK_SIZE default 496 if PM && ZEPHYR_VERSION_3_3 @@ -367,21 +372,29 @@ config OPENTHREAD_MANUAL_START config OPENTHREAD_DEFAULT_TX_POWER default 6 if PM && (SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL721X) default 3 if PM && SOC_RISCV_TELINK_TL323X - default 11 + default 11 if SOC_RISCV_TELINK_TL323X + default 9 config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS - default 40 if PM || SOC_RISCV_TELINK_TL323X + default 40 if SOC_RISCV_TELINK_TL323X + default 2 if PM default 8 +# 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 || SOC_RISCV_TELINK_TL323X + default 600 if PM || SOC_RISCV_TELINK_TL321X + default 600 if SOC_RISCV_TELINK_TL323X config NET_RX_STACK_SIZE default 2048 if SOC_RISCV_TELINK_W91 - default 2048 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 664 if PM || SOC_RISCV_TELINK_TL321X + default 2048 if SOC_RISCV_TELINK_TL323X # Disable certain parts of Zephyr IPv6 stack config NET_IPV6_NBR_CACHE @@ -508,6 +521,14 @@ config MBEDTLS_PSA_CRYPTO_C bool "MBEDTLS_PSA_CRYPTO_C" default n +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/examples/contact-sensor-app/telink/CMakeLists.txt b/examples/contact-sensor-app/telink/CMakeLists.txt index 72959d768a95..745f0f4dc3be 100755 --- a/examples/contact-sensor-app/telink/CMakeLists.txt +++ b/examples/contact-sensor-app/telink/CMakeLists.txt @@ -38,7 +38,6 @@ target_sources(app PRIVATE src/AppTask.cpp src/ContactSensorManager.cpp src/ZclCallbacks.cpp - ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp 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..d41f37a61a36 --- /dev/null +++ b/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf @@ -0,0 +1,17 @@ +# 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=1 diff --git a/examples/contact-sensor-app/telink/prj.conf b/examples/contact-sensor-app/telink/prj.conf index 294b8666a2cd..5a475802cdcb 100755 --- a/examples/contact-sensor-app/telink/prj.conf +++ b/examples/contact-sensor-app/telink/prj.conf @@ -29,9 +29,9 @@ CONFIG_CHIP_DEVICE_PRODUCT_ID=32774 CONFIG_BT_DEVICE_NAME="TelinkSensor" # Disable Matter OTA DFU -CONFIG_CHIP_OTA_REQUESTOR=y -CONFIG_CHIP_DFU_OVER_BT_SMP=y -CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y +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 @@ -46,12 +46,6 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n # CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=y -# Enable ADC -CONFIG_ADC=y - -#compress ota -CONFIG_COMPRESS_LZMA=y -CONFIG_LZMA=y #ICD SETTING INFO CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 @@ -59,12 +53,6 @@ CONFIG_CHIP_ICD_FAST_POLLING_INTERVAL=200 CONFIG_CHIP_ICD_ACTIVE_MODE_THRESHOLD=300 CONFIG_CHIP_ICD_IDLE_MODE_DURATION=900 -#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 - # open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE # init should be n CONFIG_SECURE_PROGRAMMING=n diff --git a/examples/light-switch-app/telink/CMakeLists.txt b/examples/light-switch-app/telink/CMakeLists.txt index 6ae1d14fc9fb..dde7205b38b0 100755 --- a/examples/light-switch-app/telink/CMakeLists.txt +++ b/examples/light-switch-app/telink/CMakeLists.txt @@ -39,7 +39,6 @@ target_sources(app PRIVATE src/AppTask.cpp src/ZclCallbacks.cpp src/binding-handler.cpp - ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp 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..2568dbd6c4f7 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention.conf @@ -0,0 +1,17 @@ +# 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/prj.conf b/examples/light-switch-app/telink/prj.conf index 0e30c8d8fc8d..251add4ae242 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -29,9 +29,9 @@ CONFIG_CHIP_DEVICE_PRODUCT_ID=32772 CONFIG_BT_DEVICE_NAME="TelinkSwitch" # Disable Matter OTA DFU -CONFIG_CHIP_OTA_REQUESTOR=y -CONFIG_CHIP_DFU_OVER_BT_SMP=y -CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y +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 @@ -45,12 +45,6 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n # CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=y -# Enable ADC -CONFIG_ADC=y - -#compress ota -CONFIG_COMPRESS_LZMA=y -CONFIG_LZMA=y #ICD SETTING INFO CONFIG_CHIP_ICD_SLOW_POLL_INTERVAL=7500 @@ -58,12 +52,6 @@ CONFIG_CHIP_ICD_FAST_POLLING_INTERVAL=200 CONFIG_CHIP_ICD_ACTIVE_MODE_THRESHOLD=300 CONFIG_CHIP_ICD_IDLE_MODE_DURATION=900 -#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 - # open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE # init should be n CONFIG_SECURE_PROGRAMMING=n diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index d182edb230a9..dbdef1d38393 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -51,7 +51,6 @@ endif() target_sources(app PRIVATE src/AppTask.cpp src/ZclCallbacks.cpp - ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp diff --git a/examples/lighting-app/telink/boards/tl3238x.conf b/examples/lighting-app/telink/boards/tl3238x.conf new file mode 100644 index 000000000000..566b8844ee34 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x.conf @@ -0,0 +1,17 @@ +# 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 +# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code.should use 4m flash +CONFIG_DUAL_MODE=2 diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf index ec2e848855f6..41c5b18ee445 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -29,9 +29,9 @@ CONFIG_CHIP_DEVICE_PRODUCT_ID=32773 CONFIG_BT_DEVICE_NAME="TelinkLight" # Disable Matter OTA DFU -CONFIG_CHIP_OTA_REQUESTOR=y -CONFIG_CHIP_DFU_OVER_BT_SMP=y -CONFIG_CHIP_DFU_OVER_BT_SMP_BUILD=y +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_TELINK_OTA_BUTTON_TEST=n @@ -53,18 +53,6 @@ CONFIG_PWM=y CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xF00 # Enable Power Management CONFIG_PM=n -# Enable ADC -CONFIG_ADC=y - -#compress ota -CONFIG_COMPRESS_LZMA=n -CONFIG_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.should use 4m flash -CONFIG_DUAL_MODE=2 # Enable Independent Button CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE=n diff --git a/examples/lock-app/telink/CMakeLists.txt b/examples/lock-app/telink/CMakeLists.txt index 059a279b310d..384dbdfc288f 100755 --- a/examples/lock-app/telink/CMakeLists.txt +++ b/examples/lock-app/telink/CMakeLists.txt @@ -40,7 +40,6 @@ target_sources(app PRIVATE src/ZclCallbacks.cpp src/LockManager.cpp src/LockSettingsStorage.cpp - ${CHIP_ROOT}/src/app/persistence/DeferredAttributePersistenceProvider.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp diff --git a/examples/lock-app/telink/boards/tl3238x_retention.conf b/examples/lock-app/telink/boards/tl3238x_retention.conf new file mode 100644 index 000000000000..73253ec165ec --- /dev/null +++ b/examples/lock-app/telink/boards/tl3238x_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 2b72c8f89c23..c6c17032f91e 100755 --- a/examples/lock-app/telink/prj.conf +++ b/examples/lock-app/telink/prj.conf @@ -43,22 +43,12 @@ CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n # Enable Power Management CONFIG_PM=y -#compress ota -CONFIG_COMPRESS_LZMA=y -CONFIG_LZMA=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 -#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 - # open seucre programming , need to open CONFIG_CHIP_FACTORY_DATA and CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE # init should be n CONFIG_SECURE_PROGRAMMING=n diff --git a/examples/platform/telink/common.cmake b/examples/platform/telink/common.cmake index 148e38cc3f9f..7e6a3799850c 100644 --- a/examples/platform/telink/common.cmake +++ b/examples/platform/telink/common.cmake @@ -156,6 +156,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") @@ -188,7 +194,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/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 5893d3ebf830..6868f0c5132d 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -34,10 +34,11 @@ #include #include #include +#if CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS #include #include #include -#include +#endif #include #include #include @@ -92,6 +93,7 @@ bool sIsNetworkEnabled = false; bool sIsNetworkAttached = false; bool sHaveBLEConnections = false; +#if CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS /** * @brief Set deferred attributes storage * @@ -122,7 +124,13 @@ DefaultAttributePersistenceProvider gSimpleAttributePersistence; DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttributePersistence, Span(gPersisters, ATTRIBUTES_ARRAY_SIZE), System::Clock::Milliseconds32(DEFERRED_STORAGE_TIME)); + +#endif + +#if CONFIG_SOC_RISCV_TELINK_TL323X #include +#endif /* CONFIG_SOC_RISCV_TELINK_TL323X */ + #include #include #include @@ -131,11 +139,10 @@ DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttribut #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; +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 @@ -192,12 +199,13 @@ void dual_mode_switch(int32_t op) #elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE -//#include +// #include #define USER_MATTER_BACK_ZB 0xa0 // only commisiion fail will back to zb #define USER_ZB_SW_VAL 0xaa -typedef struct{ +typedef struct +{ uint8_t val; uint8_t on_net; } user_para_t; @@ -211,12 +219,10 @@ user_para_t user_para; #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 */ @@ -232,16 +238,19 @@ void FactoryResetExtHandler(void) 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){ + if (user_para.val == USER_ZB_SW_VAL) + { return 1; - }else{ + } + else + { return 0; } } void dual_mode_auto_switch(int32_t op) { - uint8_t boot_flag = 0xff; + 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); @@ -262,17 +271,17 @@ void dual_mode_auto_switch(int32_t op) 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 + // 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 +#endif /* CONFIG_DUAL_MODE */ #if APP_SET_DEVICE_INFO_PROVIDER chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; @@ -349,6 +358,16 @@ static void DoDelayedFactoryReset(struct k_work * work) ChipLogProgress(DeviceLayer, "Rebooting board"); sys_reboot(SYS_REBOOT_WARM); } + else + { +#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 + ChipLogProgress(DeviceLayer, "Do factory_reset and reboot"); + chip::Server::GetInstance().ScheduleFactoryReset(); + } } static k_work_delayable sDelayedFactoryResetWork = Z_WORK_DELAYABLE_INITIALIZER(DoDelayedFactoryReset); @@ -474,7 +493,8 @@ CHIP_ERROR AppTaskCommon::StartApp(void) } #if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE - if(dual_mode_switch_from_zb()){ + 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); @@ -578,7 +598,11 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR); #endif (void) 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); @@ -588,8 +612,10 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; 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)); @@ -872,11 +898,11 @@ void AppTaskCommon::FactoryResetHandler(AppEvent * aEvent) k_timer_stop(&sFactoryResetTimer); sFactoryResetCntr = 0; - #if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE dual_mode_switch(OPCODE_FACTORY_RESET); - #elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE +#elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE dual_mode_auto_switch(OPCODE_FACTORY_RESET); - #endif +#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); @@ -1092,13 +1118,13 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* } break; case DeviceEventType::kCommissioningComplete: - #if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE +#if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE dual_mode_switch(OPCODE_MATTER_PAIRED); - #elif CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE +#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 +#endif printk("Commissioning complete; Matter commissioned flag set.\n"); break; @@ -1117,7 +1143,6 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* } break; - #if CHIP_DEVICE_CONFIG_ENABLE_THREAD case DeviceEventType::kDnssdInitialized: #if CONFIG_CHIP_OTA_REQUESTOR diff --git a/examples/platform/telink/util/src/DFUOverSMP.cpp b/examples/platform/telink/util/src/DFUOverSMP.cpp index e408ed123317..85666f1fbb8f 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 @@ -67,7 +69,8 @@ int UploadProgressHandler(uint32_t event, int32_t rc, bool * abort_more, void * { #if CONFIG_DUAL_MODE == CONFIG_AUTO_SWITCH_DUAL_MODE - if (!canlTimerFlag) { + if (!canlTimerFlag) + { k_timer_stop(&sDnssTimer); canlTimerFlag = true; LOG_INF("[Telink] DnssTimer stopped; DFU-OTA Handler.\n"); diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 180d1e73acc4..21fe379567a0 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,tl3238x,tl3238x_ml3m,tl3238x_retention,tl7218x,tl7218x_ml7g,tl7218x_ml7m,tl7218x_retention,tlsr9118bdk40d,tlsr9518adk80d,tlsr9528a,tlsr9528a_retention}-{air-quality-sensor,all-clusters,all-clusters-minimal,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][-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,tl7218x,tl7218x_ml7g,tl7218x_ml7m,tl7218x_retention,tlsr9118bdk40d,tlsr9518adk80d,tlsr9528a,tlsr9528a_retention}-{air-quality-sensor,all-clusters,all-clusters-minimal,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/mfg_tool.py b/scripts/tools/telink/mfg_tool.py index 250090960920..a7b395c2b947 100755 --- a/scripts/tools/telink/mfg_tool.py +++ b/scripts/tools/telink/mfg_tool.py @@ -32,10 +32,9 @@ import cryptography.hazmat.backends import cryptography.x509 import pyqrcode -from intelhex import IntelHex - -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from intelhex import IntelHex TOOLS = { 'spake2p': None, @@ -61,6 +60,7 @@ NVS_MEMORY = {} + def nvs_memory_append(key, value): if isinstance(value, str): NVS_MEMORY[key] = value.encode("utf-8") @@ -457,10 +457,10 @@ 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 args.secure_programming_verification == False: + if not args.secure_programming_verification: nvs_memory_append('dac_cert', dac_cert_storage) nvs_memory_append('dac_key', dac_key_storage) else: @@ -478,6 +478,7 @@ 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." @@ -487,12 +488,13 @@ def aes_encrypt(key, data): 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]) @@ -513,6 +515,7 @@ def save_dac_cert_and_keys(dac_cert, dac_key, chip_id, file_path): 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) @@ -635,7 +638,7 @@ def add_additional_kv(args, serial_num): # Add the serial-num if args.disable_serial_num_storage: - log.info("Secure programming verification enabled; skipping serial-num") + log.info("Secure programming verification enabled; skipping serial-num") else: nvs_memory_append('sn', serial_num) @@ -740,11 +743,11 @@ def base64_str(s): return base64.b64decode(s) 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("--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.") + secure_args.add_argument("--disable_serial_num_storage", action="store_true", + help="Disable storage of serial-num in factorydata.") args = parser.parse_args() @@ -847,25 +850,23 @@ 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) - - for i in range(args.count): - pai_cert = {} - serial_num_str = format(serial_num_int + i, 'x') - 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) - generate_discriminator(args, out_dirs) - 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, dacs_cert, out_dirs) - generate_json_summary(args, out_dirs, pai_cert, dacs_cert, serial_num_str) - - dev_sn_file.close() + 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 {}".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) + generate_discriminator(args, out_dirs) + 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, dacs_cert, out_dirs) + generate_json_summary(args, out_dirs, pai_cert, dacs_cert, serial_num_str) if __name__ == "__main__": diff --git a/scripts/tools/telink/update_zephyr.py b/scripts/tools/telink/update_zephyr.py index fe735df0ccaa..58b198b28601 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,146 @@ 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 + print(f"Fetching from remote: {remote_name}") + command = ['git', '-C', zephyr_base, 'fetch', remote_name] + subprocess.run(command, check=True) + + # Hard reset to specified commit + print(f"Resetting to commit: {commit_hash}") + command = ['git', '-C', zephyr_base, 'reset', commit_hash, '--hard'] + subprocess.run(command, check=True) + + # Update west modules + print("Updating west modules...") + command = ['west', 'update', '-o=--depth=1', '-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="af03f86610f3de8b1f2c12215bbb21f5decf97e3", + 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.") - - parser = argparse.ArgumentParser( - description='Script helping to update Telink Zephyr to specific revision.') - parser.add_argument("hash", help="Update Telink Zephyr to specific revision.") - - args = parser.parse_args() - - command = ['git', '-C', zephyr_base, 'fetch'] - subprocess.run(command, check=True) + "No ZEPHYR_BASE or TELINK_ZEPHYR_BASE environment variable found. " + "Please set to a zephyr repository path." + ) - command = ['git', '-C', zephyr_base, 'reset', args.hash, '--hard'] - subprocess.run(command, check=True) + # Update Zephyr repository + print("=" * 60) + print("Step 1: Updating Zephyr repository...") + print("=" * 60) + update_zephyr(args.remote, args.hash) - command = ['west', 'update', '-o=--depth=1', '-n', '-f', 'smart'] - subprocess.run(command, check=True) + # 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 = ['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 a14645bbe249..83db46e99587 100644 --- a/src/app/chip_data_model.cmake +++ b/src/app/chip_data_model.cmake @@ -170,6 +170,7 @@ function(chip_configure_data_model APP_TARGET) ${CHIP_APP_BASE_DIR}/util/util.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/include/platform/DeviceInstanceInfoProvider.h b/src/include/platform/DeviceInstanceInfoProvider.h index 3d29d8eaed20..47e018e7c05e 100644 --- a/src/include/platform/DeviceInstanceInfoProvider.h +++ b/src/include/platform/DeviceInstanceInfoProvider.h @@ -178,10 +178,7 @@ class DeviceInstanceInfoProvider * @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; - } + 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. diff --git a/src/platform/telink/FactoryDataParser.c b/src/platform/telink/FactoryDataParser.c index 224f99bffd93..6d42135e8fd1 100644 --- a/src/platform/telink/FactoryDataParser.c +++ b/src/platform/telink/FactoryDataParser.c @@ -118,8 +118,8 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData } // 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])) + 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'; @@ -219,17 +219,18 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData #include "aes.h" #endif -bool LoadDACCertAndKey(uint8_t * base_buffer , struct FactoryData * factoryData) +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 }; + 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}; + 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 = 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) @@ -265,7 +266,7 @@ bool LoadDACCertAndKey(uint8_t * base_buffer , struct FactoryData * factoryData) } size_t dac_cert_len = 0; - flash_read(mFlashDevice, FIXED_PARTITION_OFFSET(dac_keypair_partition)+100, buffer, 2); + 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; @@ -273,7 +274,9 @@ bool LoadDACCertAndKey(uint8_t * base_buffer , struct FactoryData * factoryData) { return false; } - factoryData->dac_cert.data =(uint8_t *) (0x20000000 + FIXED_PARTITION_OFFSET(dac_keypair_partition) + 102); + + /* CONFIG_FLASH_BASE_ADDRESS 0x20000000 */ + 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"); diff --git a/src/platform/telink/FactoryDataParser.h b/src/platform/telink/FactoryDataParser.h index 2b780027bcbd..892808981f35 100644 --- a/src/platform/telink/FactoryDataParser.h +++ b/src/platform/telink/FactoryDataParser.h @@ -84,7 +84,7 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData /** * @brief Inject dac cert and dac private key into the factory data structure. * - * @param[in] . base_buffer malloc buffer for factory data + * @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. diff --git a/src/platform/telink/FactoryDataProvider.cpp b/src/platform/telink/FactoryDataProvider.cpp index 370e60a99785..d5326cc7af92 100644 --- a/src/platform/telink/FactoryDataProvider.cpp +++ b/src/platform/telink/FactoryDataProvider.cpp @@ -110,7 +110,6 @@ CHIP_ERROR FactoryDataProvider::Init() return error; } - #if CHIP_DEVICE_SECURE_PROGRAMMING if (!ParseFactoryData(factoryData + kFactoryDataOffset, factoryDataSize - kFactoryDataOffset, &mFactoryData)) #else @@ -129,7 +128,7 @@ CHIP_ERROR FactoryDataProvider::Init() LOG_HEXDUMP_INF(mFactoryData.dac_cert.data, mFactoryData.dac_cert.len, "DAC CERT"); #if CHIP_DEVICE_SECURE_PROGRAMMING - if (!LoadDACCertAndKey(mFactoryDataBuffer , &mFactoryData)) + if (!LoadDACCertAndKey(mFactoryDataBuffer, &mFactoryData)) { ChipLogError(DeviceLayer, "Failed to inject dac data"); free(ptr); // Only free on failure diff --git a/src/platform/telink/OTAImageProcessorImpl.cpp b/src/platform/telink/OTAImageProcessorImpl.cpp index c2d401171377..4234e00243ee 100644 --- a/src/platform/telink/OTAImageProcessorImpl.cpp +++ b/src/platform/telink/OTAImageProcessorImpl.cpp @@ -181,8 +181,8 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock) { TEMPORARY_RETURN_IGNORED mDownloader->SkipData(downloadedBytesRestored - aBlock.size()); downloadedBytesRestored = 0; - TEMPORARY_RETURN_IGNORED SystemLayer().StartTimer( - System::Clock::Milliseconds32(kResumeWatchdogTimeoutMs), ResumeWatchdogHandler, this); + TEMPORARY_RETURN_IGNORED SystemLayer().StartTimer(System::Clock::Milliseconds32(kResumeWatchdogTimeoutMs), + ResumeWatchdogHandler, this); } else { From 59b455cac10fc12dff1890148b591d4acb5eecad Mon Sep 17 00:00:00 2001 From: 0x0023 Date: Mon, 1 Jun 2026 16:47:28 +0800 Subject: [PATCH 12/31] Fix OpenThread path selection based on CONFIG_OPENTHREAD_TELINK_LIBRARY (#3) * Update Telink OpenThread Path Selection fixes the incorrect OpenThread repository selection logic in Telink platform builds: - Explicitly set ZEPHYR_OPENTHREAD_MODULE_DIR to use standard openthread path when CONFIG_OPENTHREAD_TELINK_LIBRARY is not enabled - Replace the directory-existence check with CONFIG_OPENTHREAD_TELINK_LIBRARY based path selection - Ensures build logs always print the correct git revision information matching the actually used OpenThread repository Now builds correctly distinguish between: - CONFIG_OPENTHREAD_TELINK_LIBRARY=y: uses modules/lib/openthread_telink_lib - CONFIG_OPENTHREAD_TELINK_LIBRARY=n: uses modules/lib/openthread Signed-off-by: Damien Ji * Restyled by clang-format - update zephyr revision to f243cd36e52a5bb370f0b6accaa1da29a825b842 Signed-off-by: Damien Ji --------- Signed-off-by: Damien Ji Co-authored-by: Restyled.io --- .github/workflows/examples-telink.yaml | 2 +- config/telink/chip-module/CMakeLists.txt | 3 + examples/platform/telink/build_info.cmake | 70 +++++++++++++++++++ .../telink/common/src/AppTaskCommon.cpp | 9 +++ 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 21cb332fd06c..21461c3545c5 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -59,7 +59,7 @@ jobs: - 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 95b2c5ae4d1a9006366d952b34d8d5f1c77b696c --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 200420569e5588abdd0c3d92f9e3e518e1fc8778" + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git f243cd36e52a5bb370f0b6accaa1da29a825b842 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 200420569e5588abdd0c3d92f9e3e518e1fc8778" - name: Build tools required for Factory Data # Run test for master and all PRs diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 7382d29fa1e5..d2541df8b6c6 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) 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/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 6868f0c5132d..4d9974d41b75 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -548,6 +548,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 } CHIP_ERROR AppTaskCommon::InitCommonParts(void) From e679ecccca45066cafa5f3facd6b2445dde54951 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Wed, 11 Feb 2026 15:38:52 +0200 Subject: [PATCH 13/31] [Telink] Fix TC-OPCREDS-3.6 test (#43028) * [Telink] Fix TC-OPCREDS-3.6 test * Restyled by clang-format * [Telink] Decrease CHIP_MAX_FABRICS for BOARD_TL3218X_RETENTION. * [Telink] Fix default value for BOARD_TL3218X_RETENTION --------- telink: 3238x: fix incorrect factory reset logic for commissioned device. - fix incorrect factory reset logic for commissioned device when fabric is 0. Signed-off-by: Alex Tsitsiura Signed-off-by: Damien Ji Signed-off-by: Hao Wu Co-authored-by: Restyled.io --- .../telink/common/src/AppTaskCommon.cpp | 40 +------------------ 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 4d9974d41b75..cd2cbd6089a7 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -378,45 +378,7 @@ class AppFabricTableDelegate : public FabricTable::Delegate { if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) { - ChipLogProgress(DeviceLayer, "Erasing settings partition"); - - // TC-OPCREDS-3.6 (device doesn't need to reboot automatically after the last fabric is removed) can't use FactoryReset - void * storage = nullptr; - int status = settings_storage_get(&storage); - - if (!status) - { - status = nvs_clear(static_cast(storage)); - } - - if (!status) - { - status = nvs_mount(static_cast(storage)); - } - - if (status) - { - ChipLogError(DeviceLayer, "Storage clear failed: %d", status); - } -#ifdef CONFIG_TFLM_FEATURE - AppTask::MicroSpeechProcessStop(); -#endif - // Reboot in case of failed commissioning to allow new pairing via BLE - if (sIsCommissioningFailed) - { - ChipLogProgress(DeviceLayer, "Rebooting board"); - sys_reboot(SYS_REBOOT_WARM); - } - else - { -#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 - ChipLogProgress(DeviceLayer, "Do factory_reset and reboot"); - chip::Server::GetInstance().ScheduleFactoryReset(); - } + k_work_schedule(&sDelayedFactoryResetWork, K_SECONDS(2)); } } }; From 9950e5e0cff79cb7545908a7e1645f58e714a26b Mon Sep 17 00:00:00 2001 From: dinabenamar <108664279+dinabenamar@users.noreply.github.com> Date: Wed, 8 Apr 2026 21:50:57 +0200 Subject: [PATCH 14/31] [common][platform][openthread] Fix race condition during Thread stack initialization (observed on NXP Zephyr platform) (#71368) * [common][platform][openthread] Add OT mutex lock when calling OT api to avoid race condition during initialization * The mutex lock is necessary for Zephyr because the openthread thread is initialized by the kernel init, and therefore it runs before the Matter initialization * so when we InitThreadStack, we must ensure that the OT api calls are protected with a mutex lock to avoid concurrent access to OT shared resources Signed-off-by: Dina Benamar * Restyled by whitespace * [common][platform][openthread] Add comment to explain why the LockThreadStack() is required Signed-off-by: Dina Benamar --------- Signed-off-by: Dina Benamar Co-authored-by: Restyled.io --- .../OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index ebfb86bb4aea..7d4ab233ec51 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -707,6 +707,10 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::ConfigureThreadS mOTInst = otInst; + // Lock the OpenThread stack to prevent race conditions with OpenThread's internal operations. + // On some platforms (e.g., Zephyr), OpenThread may already be running before Matter initialization completes. + Impl()->LockThreadStack(); + // Arrange for OpenThread to call the OnOpenThreadStateChange method whenever a // state change occurs. Note that we reference the OnOpenThreadStateChange method // on the concrete implementation class so that that class can override the default @@ -742,6 +746,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::ConfigureThreadS exit: + Impl()->UnlockThreadStack(); ChipLogProgress(DeviceLayer, "OpenThread started: %s", otThreadErrorToString(otErr)); return err; } From 3af0f2acf0aa4eb12a7c236ee7fd8b2038d5389f Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Wed, 13 May 2026 17:18:39 +0300 Subject: [PATCH 15/31] [Telink] Fix OTA_EXTRA_ARGS config apply (#72034) --- config/zephyr/ota-image.cmake | 4 ++-- config/zephyr/ota-image_sysbuild.cmake | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/zephyr/ota-image.cmake b/config/zephyr/ota-image.cmake index 0d0108aa7579..bfb1f9dfc0f8 100644 --- a/config/zephyr/ota-image.cmake +++ b/config/zephyr/ota-image.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2021 Project CHIP Authors +# Copyright (c) 2021-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. @@ -59,7 +59,7 @@ function(chip_ota_image TARGET_NAME) ) endif() - separate_arguments(OTA_EXTRA_ARGS NATIVE_COMMAND "${CHIP_OTA_IMAGE_EXTRA_ARGS}") + separate_arguments(OTA_EXTRA_ARGS NATIVE_COMMAND "${CONFIG_CHIP_OTA_IMAGE_EXTRA_ARGS}") list(APPEND OTA_ARGS ${OTA_EXTRA_ARGS}) list(APPEND OTA_ARGS ${ARG_INPUT_FILES}) diff --git a/config/zephyr/ota-image_sysbuild.cmake b/config/zephyr/ota-image_sysbuild.cmake index 88968ba15ecb..6a3703107e3d 100644 --- a/config/zephyr/ota-image_sysbuild.cmake +++ b/config/zephyr/ota-image_sysbuild.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2021 Project CHIP Authors +# Copyright (c) 2021-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. @@ -82,7 +82,7 @@ function(chip_ota_image TARGET_NAME) ) endif() - separate_arguments(OTA_EXTRA_ARGS NATIVE_COMMAND "${CHIP_OTA_IMAGE_EXTRA_ARGS}") + separate_arguments(OTA_EXTRA_ARGS NATIVE_COMMAND "${CONFIG_CHIP_OTA_IMAGE_EXTRA_ARGS}") list(APPEND OTA_ARGS ${OTA_EXTRA_ARGS}) list(APPEND OTA_ARGS ${ARG_INPUT_FILES}) From 7c08c60ba8f349c68d82a4090545768a311f1ac9 Mon Sep 17 00:00:00 2001 From: Damien Ji Date: Tue, 2 Jun 2026 16:37:21 +0800 Subject: [PATCH 16/31] [Telink] Update Telink Zephyr and BLE SDK and add OTA Manual Process Script 1. SDK updates: - update zephyr from f243cd36e52a5bb370f0b6accaa1da29a825b842 to 30c10f8e319254d3771ab18bfb929019a2a7e38d - update ble sdk from 200420569e5588abdd0c3d92f9e3e518e1fc8778 to f50d422d780efb73af939650ef7b8c6bf5a0b99b 2. Fixes: - revert incorrect modifications to pwm_b9x, pwm_tlx 3. Add OTA manual process tool: - Add scripts/tools/telink/manual_process.py to manually generate Telink Matter OTA FW - supports all SoC families (2/4MB) with chip-specific LZMA compression pipelines - implements flexible input modes: .config parsing, manual parameters, --already-signed, --only-lzma - path-agnostic design with hardcoded tool paths for re-use in other environment Restyled by autopep8 Restyled by isort --- .github/workflows/examples-telink.yaml | 2 +- scripts/tools/telink/manual_process.py | 701 +++++++++++++++++++++++++ 2 files changed, 702 insertions(+), 1 deletion(-) create mode 100755 scripts/tools/telink/manual_process.py diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 21461c3545c5..6c6077fa1d03 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -59,7 +59,7 @@ jobs: - 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 f243cd36e52a5bb370f0b6accaa1da29a825b842 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 200420569e5588abdd0c3d92f9e3e518e1fc8778" + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git 5a8e0e948faa5fbc0edbf1770d9e7a7d27d70999 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash f50d422d780efb73af939650ef7b8c6bf5a0b99b" - name: Build tools required for Factory Data # Run test for master and all PRs diff --git a/scripts/tools/telink/manual_process.py b/scripts/tools/telink/manual_process.py new file mode 100755 index 000000000000..4fae4cfb9f04 --- /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) From 11ac2f6bc492e1eddaf1a5ee89ec84e41caa8357 Mon Sep 17 00:00:00 2001 From: haiwentelink <125550736+haiwentelink@users.noreply.github.com> Date: Wed, 17 Jun 2026 16:39:13 +0800 Subject: [PATCH 17/31] Tl develop v1.5.1 fix tercel (#5) telink: TL721X: fix tl721x and change setting. - adopt the same setting as tl3238x . - add config for openthread(put some code into ramcode) . - add normal partition and lzma partition. - update matter ci. Signed-off-by: Haiwen Xia --- .github/workflows/examples-telink.yaml | 16 +---- config/telink/chip-module/Kconfig.defaults | 61 +++++++++------- .../telink/project_include/OpenThreadConfig.h | 2 +- .../telink/CHIPDevicePlatformConfig.h | 2 +- src/platform/telink/CHIPPlatformConfig.h | 5 +- src/platform/telink/SystemPlatformConfig.h | 5 +- src/platform/telink/tl7218x_2m_flash.overlay | 52 ++++++++++---- .../telink/tl7218x_2m_flash_lzma.overlay | 70 +++++++++++++++---- 8 files changed, 138 insertions(+), 75 deletions(-) diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 6c6077fa1d03..2884be5d2367 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -59,7 +59,7 @@ jobs: - 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 5a8e0e948faa5fbc0edbf1770d9e7a7d27d70999 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash f50d422d780efb73af939650ef7b8c6bf5a0b99b" + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git dee4cad05c07db5be9ccc094fbd2e56f3e528ee3 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash c4fdeaa0f3387543b9ec5f351ed74b3047988d00" - name: Build tools required for Factory Data # Run test for master and all PRs @@ -239,20 +239,6 @@ jobs: - 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' - run: | - ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tl7218x-light-tflm' 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 \ - /tmp/bloat_reports/ - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - name: Build example Telink (tl721x retention) Light Switch App with OTA (LZMA), Factory Data # Run test for master and all PRs run: | diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 0da2c633b694..7f869630ac61 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -70,31 +70,31 @@ config POSIX_MAX_FDS config MAIN_STACK_SIZE default 4864 if SOC_RISCV_TELINK_W91 default 3072 if PM && SOC_RISCV_TELINK_TL321X - default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || 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_TL323X || SOC_RISCV_TELINK_W91 + default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || 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 SOC_RISCV_TELINK_TL323X + default 1024 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X config SYSTEM_WORKQUEUE_STACK_SIZE default 664 if PM && !SOC_RISCV_TELINK_W91 - default 2048 if SOC_RISCV_TELINK_TL323X + default 2048 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X config HEAP_MEM_POOL_SIZE default 256 if ZEPHYR_VERSION_3_3 - default 1796 if SOC_RISCV_TELINK_TL323X + default 1796 if SOC_RISCV_TELINK_TL323X || 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 && !ZEPHYR_VERSION_3_3 + default 26584 if (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X) && !ZEPHYR_VERSION_3_3 default 29448 if SOC_RISCV_TELINK_W91 default 20716 @@ -106,7 +106,7 @@ config NET_IF_UNICAST_IPV6_ADDR_COUNT default 6 config NET_IF_MCAST_IPV6_ADDR_COUNT - default 47 if SOC_RISCV_TELINK_TL323X + default 47 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 8 if PM default 15 @@ -116,20 +116,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 || SOC_RISCV_TELINK_TL323X + default 4 if PM || SOC_RISCV_TELINK_TL321X || 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 || SOC_RISCV_TELINK_TL323X + default 4 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 8 config NET_BUF_RX_COUNT - default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 32 config NET_BUF_TX_COUNT - default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 32 config GPIO @@ -158,15 +158,15 @@ config BT_MAX_CONN default 1 config BT_L2CAP_TX_MTU - default 103 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 103 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 247 config BT_BUF_ACL_RX_SIZE - default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 251 config BT_BUF_ACL_TX_SIZE - default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X + default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 251 config BT_BUF_EVT_RX_COUNT @@ -194,8 +194,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 + default 1536 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 712 config TL_BLE_CTRL_MASTER_MAX_NUM @@ -291,7 +290,7 @@ config NVS_LOOKUP_CACHE config NVS_LOOKUP_CACHE_SIZE default 400 if SOC_RISCV_TELINK_TL321X - default 400 if SOC_RISCV_TELINK_TL323X + default 400 if SOC_RISCV_TELINK_TL323X || 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 @@ -341,9 +340,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 + default y if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X) default n help Improve RF performance in IEEE 802.15.4 communication on TLX SoCs. @@ -354,12 +361,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 + default 4096 if SOC_RISCV_TELINK_TL323X || 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 - default 608 if SOC_RISCV_TELINK_TL323X + default 2048 if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X) + default 608 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 640 config OPENTHREAD_SLAAC @@ -370,13 +377,13 @@ config OPENTHREAD_MANUAL_START # 6 is the max rf level by Vant config OPENTHREAD_DEFAULT_TX_POWER - default 6 if PM && (SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL721X) - default 3 if PM && SOC_RISCV_TELINK_TL323X - default 11 if SOC_RISCV_TELINK_TL323X + default 6 if PM && (SOC_RISCV_TELINK_TL321X) + default 3 if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X) + default 11 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 9 config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS - default 40 if SOC_RISCV_TELINK_TL323X + default 40 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X default 2 if PM default 8 @@ -389,12 +396,12 @@ 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 SOC_RISCV_TELINK_TL323X + default 600 if SOC_RISCV_TELINK_TL323X || 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 + default 2048 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X # Disable certain parts of Zephyr IPv6 stack config NET_IPV6_NBR_CACHE diff --git a/examples/platform/telink/project_include/OpenThreadConfig.h b/examples/platform/telink/project_include/OpenThreadConfig.h index e34698f27717..e95dd632e70a 100644 --- a/examples/platform/telink/project_include/OpenThreadConfig.h +++ b/examples/platform/telink/project_include/OpenThreadConfig.h @@ -27,7 +27,7 @@ /* Number of message buffers reduced to save RAM */ #undef OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS -#if CONFIG_PM || CONFIG_SOC_RISCV_TELINK_TL321X || CONFIG_SOC_RISCV_TELINK_TL323X +#if CONFIG_PM || CONFIG_SOC_RISCV_TELINK_TL321X || CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL721X #define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 22 #else #define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 44 diff --git a/src/platform/telink/CHIPDevicePlatformConfig.h b/src/platform/telink/CHIPDevicePlatformConfig.h index 6530ee0598bf..fb828da6023c 100644 --- a/src/platform/telink/CHIPDevicePlatformConfig.h +++ b/src/platform/telink/CHIPDevicePlatformConfig.h @@ -109,7 +109,7 @@ #endif // CHIP_DEVICE_CONFIG_ENABLE_ETHERNET #if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ - defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION) + defined(CONFIG_SOC_RISCV_TELINK_TL721X) || 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) diff --git a/src/platform/telink/CHIPPlatformConfig.h b/src/platform/telink/CHIPPlatformConfig.h index ad857237e67f..e7a192876748 100644 --- a/src/platform/telink/CHIPPlatformConfig.h +++ b/src/platform/telink/CHIPPlatformConfig.h @@ -62,7 +62,7 @@ #define CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS 1 #endif // CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS -#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) +#if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || defined(CONFIG_SOC_RISCV_TELINK_TL721X) #ifndef CHIP_CONFIG_MAX_GROUP_DATA_PEERS #define CHIP_CONFIG_MAX_GROUP_DATA_PEERS 5 @@ -74,7 +74,8 @@ #endif // defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) -#if defined CONFIG_PM || defined CONFIG_SOC_RISCV_TELINK_TL321X || defined CONFIG_SOC_RISCV_TELINK_TL323X +#if defined CONFIG_PM || defined CONFIG_SOC_RISCV_TELINK_TL321X || defined CONFIG_SOC_RISCV_TELINK_TL323X || \ + defined CONFIG_SOC_RISCV_TELINK_TL721X #ifndef CHIP_CONFIG_MAX_GROUP_DATA_PEERS #define CHIP_CONFIG_MAX_GROUP_DATA_PEERS 7 diff --git a/src/platform/telink/SystemPlatformConfig.h b/src/platform/telink/SystemPlatformConfig.h index 37a4bcc5ed3c..14216b8dc62f 100644 --- a/src/platform/telink/SystemPlatformConfig.h +++ b/src/platform/telink/SystemPlatformConfig.h @@ -45,7 +45,8 @@ struct ChipDeviceEvent; #endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS #if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ - defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION) || defined(CONFIG_SOC_RISCV_TELINK_W91) + defined(CONFIG_SOC_RISCV_TELINK_TL721X) || 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 @@ -57,7 +58,7 @@ struct ChipDeviceEvent; // 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_TL323X) || \ - defined(CONFIG_SOC_RISCV_TELINK_W91) + defined(CONFIG_SOC_RISCV_TELINK_TL721X) || 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/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. }; }; }; From 51f2f88c8e530abfbcffd7c43fcfcacff723ba2e Mon Sep 17 00:00:00 2001 From: Damien Ji Date: Thu, 18 Jun 2026 20:23:35 +0800 Subject: [PATCH 18/31] telink: add dual mode configs and TL3238C-EVK40D board overlay - Add TL3238C-EVK40D overlay for lighting-app 4MB dual mode - Add tl3238x_4m_flash_dual_mode.conf (lighting-app, DUAL_MODE=2) - Add tl3238x_retention_dual_mode.conf (light-switch-app, DUAL_MODE=1) - Default single-mode configs to DUAL_MODE=0 with LZMA enabled - Guard Zigbee merge with CONFIG_DUAL_MODE in CMakeLists.txt - Add build guide READMEs for both apps - Set device serial numbers in board configs - Update Zephyr revision in CI workflow Signed-off-by: Damien Ji --- .github/workflows/examples-telink.yaml | 2 +- config/telink/chip-module/CMakeLists.txt | 20 +++-- .../telink/boards/tl3238x_retention.conf | 4 +- .../boards/tl3238x_retention_README.txt | 45 ++++++++++ .../boards/tl3238x_retention_dual_mode.conf | 19 ++++ examples/light-switch-app/telink/prj.conf | 3 +- .../lighting-app/telink/boards/tl3238x.conf | 12 +-- .../boards/tl3238x_4m_flash_dual_mode.conf | 19 ++++ .../telink/boards/tl3238x_README.txt | 50 +++++++++++ .../boards/tl3238x_for_TL3238C-EVK40D.overlay | 89 +++++++++++++++++++ examples/lighting-app/telink/prj.conf | 1 + .../telink/common/src/AppTaskCommon.cpp | 4 + .../telink/tl3238x_2m_flash_backup.overlay | 2 +- 13 files changed, 255 insertions(+), 15 deletions(-) create mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention_README.txt create mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode.conf create mode 100644 examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode.conf create mode 100644 examples/lighting-app/telink/boards/tl3238x_README.txt create mode 100644 examples/lighting-app/telink/boards/tl3238x_for_TL3238C-EVK40D.overlay diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 2884be5d2367..3ae793b68039 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -59,7 +59,7 @@ jobs: - 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 dee4cad05c07db5be9ccc094fbd2e56f3e528ee3 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash c4fdeaa0f3387543b9ec5f351ed74b3047988d00" + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git 80af1985c571efb046373220498e78fa50114ee4 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash c4fdeaa0f3387543b9ec5f351ed74b3047988d00" - name: Build tools required for Factory Data # Run test for master and all PRs diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index d2541df8b6c6..3ba7fd186087 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -235,7 +235,7 @@ 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 (EXISTS ${ZB_FILE_PATH}) +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}") @@ -243,7 +243,11 @@ if (EXISTS ${ZB_FILE_PATH}) 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() - message(WARNING "File ${ZB_FILE_PATH} does not exist. ZB_FW_OFFSET_DECIMAL will be set to 0.") + 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() @@ -252,7 +256,7 @@ add_custom_target( COMMAND ${Python3_EXECUTABLE} ${CHIP_ROOT}/scripts/tools/telink/process_binaries.py WORKING_DIRECTORY ${PROJECT_BINARY_DIR} ) -if(EXISTS ${ZB_FILE_PATH} AND CONFIG_BOOTLOADER_MCUBOOT AND (CONFIG_SOC_RISCV_TELINK_B9X OR CONFIG_SOC_RISCV_TELINK_TLX)) +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}) @@ -295,12 +299,12 @@ if (CONFIG_BOOTLOADER_MCUBOOT AND (CONFIG_SOC_RISCV_TELINK_B9X OR CONFIG_SOC_RIS message(WARNING "File ${SBOOT_FILE_PATH} does not exist. merge_sboot target will not be created.") endif() - if (EXISTS ${ZB_FILE_PATH}) + 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_OFFSETZB_FW_OFFSET} | tr '\\000' '\\377' > ${PROJECT_BINARY_DIR}/dm_merged.bin + 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 @@ -317,7 +321,11 @@ if (CONFIG_BOOTLOADER_MCUBOOT AND (CONFIG_SOC_RISCV_TELINK_B9X OR CONFIG_SOC_RIS add_dependencies(merge_zigbee ${ZEPHYR_FINAL_EXECUTABLE}) add_dependencies(west_sign merge_zigbee) else() - message(WARNING "File ${ZB_FILE_PATH} does not exist. merge_zigbee target will not be created.") + 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/examples/light-switch-app/telink/boards/tl3238x_retention.conf b/examples/light-switch-app/telink/boards/tl3238x_retention.conf index 2568dbd6c4f7..a63fcaf504cf 100644 --- a/examples/light-switch-app/telink/boards/tl3238x_retention.conf +++ b/examples/light-switch-app/telink/boards/tl3238x_retention.conf @@ -1,3 +1,5 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch-tl3238c" + # Disable Matter OTA DFU CONFIG_CHIP_OTA_REQUESTOR=y CONFIG_CHIP_DFU_OVER_BT_SMP=y @@ -14,4 +16,4 @@ CONFIG_COMPRESS_LZMA=y # 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 +CONFIG_DUAL_MODE=0 diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt b/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt new file mode 100644 index 000000000000..5e2312fe9360 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt @@ -0,0 +1,45 @@ +TL3238X Retention Light-Switch App Build Guide +================================================= + +1. Matter only (LZMA compressed) +--------------------------------- + +Config: boards/tl3238x_retention.conf + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=0 + +Overlay: src/platform/telink/tl3238x_2m_flash.overlay + - slot0: 0x15000, size 0x120000 (1152KB) + - slot1: 0x135000, size 0xAB000 (684KB) + +Build: + west build -p -b tl3238x_retention -d build_tl3238x_retention > build_tl3238x_retention.log + +Output: + build_tl3238x_retention/zephyr/merged.bin -> flash this + build_tl3238x_retention/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP + build_tl3238x_retention/zephyr/matter.ota -> OTA upgrade + + +2. Matter + Zigbee dual mode (LZMA compressed) +------------------------------------------------ + +Prerequisite: copy Zigbee firmware + cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin + +Config: boards/tl3238x_retention_dual_mode.conf + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=1 (action switch mode) + +Overlay: src/platform/telink/tl3238x_2m_flash.overlay + - 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.conf" > build_tl3238x_retention_dual_mode.log + +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 diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode.conf b/examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode.conf new file mode 100644 index 000000000000..2e4f4304701a --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode.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/prj.conf b/examples/light-switch-app/telink/prj.conf index 251add4ae242..79711e31d4f3 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -26,13 +26,14 @@ CONFIG_STD_CPP17=y CONFIG_CHIP_DEVICE_PRODUCT_ID=32772 # Bluetooth Low Energy configuration -CONFIG_BT_DEVICE_NAME="TelinkSwitch" +# CONFIG_BT_DEVICE_NAME="TelinkSwitch" # 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 +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLightSwitch" # Disable CHIP shell support CONFIG_CHIP_LIB_SHELL=n diff --git a/examples/lighting-app/telink/boards/tl3238x.conf b/examples/lighting-app/telink/boards/tl3238x.conf index 566b8844ee34..28e3510f9917 100644 --- a/examples/lighting-app/telink/boards/tl3238x.conf +++ b/examples/lighting-app/telink/boards/tl3238x.conf @@ -1,17 +1,19 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-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 #compress ota -CONFIG_LZMA=n -CONFIG_COMPRESS_LZMA=n +CONFIG_LZMA=y +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 -# AUTO_SWITCH_DUAL_MODE 2 matter auto-switch mode ,such as by scan QR code.should use 4m flash -CONFIG_DUAL_MODE=2 +# 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.conf b/examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode.conf new file mode 100644 index 000000000000..06f102ad2c5e --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode.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.txt b/examples/lighting-app/telink/boards/tl3238x_README.txt new file mode 100644 index 000000000000..3c8e13a5e371 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_README.txt @@ -0,0 +1,50 @@ +TL3238X Lighting App Build Guide +================================= + +1. 2MB Flash (Matter only, LZMA compressed) +------------------------------------------- + +Config: boards/tl3238x.conf + - CONFIG_LZMA=y, CONFIG_COMPRESS_LZMA=y + - CONFIG_DUAL_MODE=0 + +Overlay: src/platform/telink/tl3238x_2m_lzma_flash.overlay + - slot0: 0x15000, size 0x120000 (1152KB) + - slot1: 0x135000, size 0xAB000 (684KB) + +Build: + west build -p -b tl3238x -d build_tl3238x_2m > build_tl3238x_2m.log + +Output: + build_tl3238x_2m/zephyr/merged.bin -> flash this + build_tl3238x_2m/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP + build_tl3238x_2m/zephyr/matter.ota -> OTA upgrade + + +2. 4MB Flash (Matter + Zigbee dual mode, no LZMA) +--------------------------------------------------- + +Prerequisite: copy Zigbee firmware + cp .bin ${ZEPHYR_BASE}/TL323X_FW/ZB/Zigbee-SampleDemo.bin + +Config: boards/tl3238x_4m_flash_dual_mode.conf + - CONFIG_LZMA=n, CONFIG_COMPRESS_LZMA=n + - CONFIG_DUAL_MODE=2 (auto-switch mode) + +Overlay: src/platform/telink/tl3238x_4m_flash.overlay + - slot0: 0x16000, size 0x1E5000 (1940KB) + - slot1: 0x1FB000, size 0x1E5000 (1940KB) + +Board overlay: boards/tl3238x_for_TL3238C-EVK40D.overlay + - LED/Key definitions for TL3238C-EVK40D board + +Build: + west build -p -b tl3238x -d build_tl3238x_4m_dual_mode -- \ + -DFLASH_SIZE=4m \ + -DCONF_FILE="prj.conf boards/tl3238x_4m_flash_dual_mode.conf" \ + -DDTC_OVERLAY_FILE="boards/tl3238x_for_TL3238C-EVK40D.overlay" > build_tl3238x_4m_dual_mode.log + +Output: + 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 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..f6cb6b51b0c9 --- /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>; /* 保持原有DFU按键配置 */ + }; + }; + + 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/prj.conf b/examples/lighting-app/telink/prj.conf index 41c5b18ee445..73df01b9e101 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 diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index cd2cbd6089a7..ac719226f1aa 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -824,6 +824,10 @@ void AppTaskCommon::StartBleAdvButtonEventHandler(void) void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) { + // for action dual mode, press button to switch to zigbee mode + // #if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE + // dual_mode_switch(OPCODE_SWITCH_ZIGBEE); + // #endif LOG_INF("StartBleAdvHandler"); // Disable manual Matter service BLE advertising after device provisioning. if (sIsNetworkProvisioned) diff --git a/src/platform/telink/tl3238x_2m_flash_backup.overlay b/src/platform/telink/tl3238x_2m_flash_backup.overlay index 2fe5cafe183c..3f4e5c226de1 100644 --- a/src/platform/telink/tl3238x_2m_flash_backup.overlay +++ b/src/platform/telink/tl3238x_2m_flash_backup.overlay @@ -17,7 +17,7 @@ }; slot1_partition: partition@fa000 { label = "image-1"; - reg = <0xfa000 0xe6000>; // total slot1 is 916k + reg = <0xfa000 0xe6000>; // total slot1 is 920k }; user_rfu_partition: partition@1e0000 { label = "user_rfu"; From 84ae3a79ab67a3c81e6b17c5b485e92bb9909fce Mon Sep 17 00:00:00 2001 From: fenton1609 Date: Wed, 17 Jun 2026 16:57:55 +0800 Subject: [PATCH 19/31] [Telink] Check matter network state when power-on (#469) * [Telink] Check if the thread dataset and fabirc were successfully written. Signed-off-by: Fengtai Xie --- .../telink/common/src/AppTaskCommon.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index ac719226f1aa..a6d4eb8e22d6 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -26,6 +26,7 @@ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include "ThreadUtil.h" +#include #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI #include #include @@ -444,6 +445,28 @@ void AppTaskCommon::DnssTimerTimeoutCallback(k_timer * timer) } #endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +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(); @@ -623,6 +646,11 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) return err; } +#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; } From b4c04e3c1816fc242a100e305047ac1350457d17 Mon Sep 17 00:00:00 2001 From: Damien Ji Date: Sun, 5 Jul 2026 12:12:55 +0800 Subject: [PATCH 20/31] Telink: update and feature integration for tl323x/tl721x - set isComissioningStarted to false in OnCommissioningSessionEstablishmentError to fix commissioning session state error. This is a quick fix from https://github.com/project-chip/connectedhomeip/pull/72700. - add dual mode configs for tl323x and TL3238C-EVK40D board overlay - update Telink BLE SDK revision from c4fdeaa0f3387543b9ec5f351ed74b3047988d00 to 46322e5b570e2a68373b18d4f08811acadd1266c - update hal_telink to improve flash protection for 4MB flash on TL323X. - update zephyr revision to e08fc42546e58d808bfd39f35c8df296f5617a44 - adjust and unify telink boards *.conf/*.overlay process flow for TL323X/721X - add TL323X/721X build README files and clarify TL721X does NOT support dual mode yet Signed-off-by: Damien Ji --- .github/workflows/examples-telink.yaml | 2 +- .../telink/boards/tl3238x_retention.conf | 4 +- .../boards/tl3238x_retention_README.txt | 107 ++++++++++++++++++ ...tl3238x_retention_dual_mode_ota_lzma.conf} | 0 .../telink/boards/tl3238x_retention_ota.conf | 20 ++++ .../boards/tl3238x_retention_ota_lzma.conf | 20 ++++ .../telink/boards/tl7218x_retention.conf | 22 ++++ .../boards/tl7218x_retention_README.txt | 78 +++++++++++++ .../telink/boards/tl7218x_retention_ota.conf | 20 ++++ .../boards/tl7218x_retention_ota_lzma.conf | 20 ++++ .../telink/boards/tl3238x_retention.conf | 13 ++- .../boards/tl3238x_retention_README.txt | 92 ++++++++++++--- .../tl3238x_retention_dual_mode_ota_lzma.conf | 19 ++++ .../telink/boards/tl3238x_retention_ota.conf | 20 ++++ .../boards/tl3238x_retention_ota_lzma.conf | 20 ++++ .../telink/boards/tl7218x_retention.conf | 22 ++++ .../boards/tl7218x_retention_README.txt | 78 +++++++++++++ .../tl7218x_retention_dual_mode_ota_lzma.conf | 19 ++++ .../telink/boards/tl7218x_retention_ota.conf | 20 ++++ .../boards/tl7218x_retention_ota_lzma.conf | 20 ++++ examples/light-switch-app/telink/prj.conf | 2 +- .../lighting-app/telink/boards/tl3238x.conf | 15 ++- .../boards/tl3238x_2m_flash_ota_lzma.conf | 22 ++++ ...nf => tl3238x_4m_flash_dual_mode_ota.conf} | 0 .../telink/boards/tl3238x_README.txt | 90 ++++++++++++--- .../boards/tl3238x_for_TL3238C-EVK40D.overlay | 2 +- .../telink/boards/tl3238x_ota.conf | 22 ++++ .../lighting-app/telink/boards/tl7218x.conf | 22 ++++ .../boards/tl7218x_2m_flash_ota_lzma.conf | 22 ++++ .../telink/boards/tl7218x_README.txt | 78 +++++++++++++ .../telink/boards/tl7218x_ota.conf | 22 ++++ examples/platform/telink/common.cmake | 18 +-- .../telink/common/src/AppTaskCommon.cpp | 35 ++++-- scripts/tools/telink/update_zephyr.py | 2 +- src/platform/telink/tl3238x_2m_flash.overlay | 26 +---- ....overlay => tl3238x_2m_flash_lzma.overlay} | 0 ....overlay => tl3238x_4m_flash_lzma.overlay} | 0 ..._backup.overlay => tl3238x_simple.overlay} | 30 ++--- 38 files changed, 916 insertions(+), 108 deletions(-) create mode 100644 examples/contact-sensor-app/telink/boards/tl3238x_retention_README.txt rename examples/{light-switch-app/telink/boards/tl3238x_retention_dual_mode.conf => contact-sensor-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf} (100%) create mode 100644 examples/contact-sensor-app/telink/boards/tl3238x_retention_ota.conf create mode 100644 examples/contact-sensor-app/telink/boards/tl3238x_retention_ota_lzma.conf create mode 100644 examples/contact-sensor-app/telink/boards/tl7218x_retention.conf create mode 100644 examples/contact-sensor-app/telink/boards/tl7218x_retention_README.txt create mode 100644 examples/contact-sensor-app/telink/boards/tl7218x_retention_ota.conf create mode 100644 examples/contact-sensor-app/telink/boards/tl7218x_retention_ota_lzma.conf create mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf create mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention_ota.conf create mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention_ota_lzma.conf create mode 100644 examples/light-switch-app/telink/boards/tl7218x_retention.conf create mode 100644 examples/light-switch-app/telink/boards/tl7218x_retention_README.txt create mode 100644 examples/light-switch-app/telink/boards/tl7218x_retention_dual_mode_ota_lzma.conf create mode 100644 examples/light-switch-app/telink/boards/tl7218x_retention_ota.conf create mode 100644 examples/light-switch-app/telink/boards/tl7218x_retention_ota_lzma.conf create mode 100644 examples/lighting-app/telink/boards/tl3238x_2m_flash_ota_lzma.conf rename examples/lighting-app/telink/boards/{tl3238x_4m_flash_dual_mode.conf => tl3238x_4m_flash_dual_mode_ota.conf} (100%) create mode 100644 examples/lighting-app/telink/boards/tl3238x_ota.conf create mode 100644 examples/lighting-app/telink/boards/tl7218x.conf create mode 100644 examples/lighting-app/telink/boards/tl7218x_2m_flash_ota_lzma.conf create mode 100644 examples/lighting-app/telink/boards/tl7218x_README.txt create mode 100644 examples/lighting-app/telink/boards/tl7218x_ota.conf rename src/platform/telink/{tl3238x_2m_lzma_flash.overlay => tl3238x_2m_flash_lzma.overlay} (100%) rename src/platform/telink/{tl3238x_4m_lzma_flash.overlay => tl3238x_4m_flash_lzma.overlay} (100%) rename src/platform/telink/{tl3238x_2m_flash_backup.overlay => tl3238x_simple.overlay} (50%) diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 3ae793b68039..46de7d8eea7c 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -59,7 +59,7 @@ jobs: - 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 80af1985c571efb046373220498e78fa50114ee4 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash c4fdeaa0f3387543b9ec5f351ed74b3047988d00" + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git e08fc42546e58d808bfd39f35c8df296f5617a44 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 46322e5b570e2a68373b18d4f08811acadd1266c" - name: Build tools required for Factory Data # Run test for master and all PRs diff --git a/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf b/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf index d41f37a61a36..da22e9960618 100644 --- a/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf +++ b/examples/contact-sensor-app/telink/boards/tl3238x_retention.conf @@ -1,3 +1,5 @@ +# CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkContactSensor-tl3238x" + # Disable Matter OTA DFU CONFIG_CHIP_OTA_REQUESTOR=y CONFIG_CHIP_DFU_OVER_BT_SMP=y @@ -14,4 +16,4 @@ CONFIG_LZMA=y # 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 +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/light-switch-app/telink/boards/tl3238x_retention_dual_mode.conf b/examples/contact-sensor-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf similarity index 100% rename from examples/light-switch-app/telink/boards/tl3238x_retention_dual_mode.conf rename to examples/contact-sensor-app/telink/boards/tl3238x_retention_dual_mode_ota_lzma.conf 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/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/light-switch-app/telink/boards/tl3238x_retention.conf b/examples/light-switch-app/telink/boards/tl3238x_retention.conf index a63fcaf504cf..8238e59aae6e 100644 --- a/examples/light-switch-app/telink/boards/tl3238x_retention.conf +++ b/examples/light-switch-app/telink/boards/tl3238x_retention.conf @@ -1,16 +1,17 @@ # 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 +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 -#compress ota -CONFIG_LZMA=y -CONFIG_COMPRESS_LZMA=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 diff --git a/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt b/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt index 5e2312fe9360..f5e8f614e622 100644 --- a/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt +++ b/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt @@ -1,45 +1,107 @@ TL3238X Retention Light-Switch App Build Guide ================================================= -1. Matter only (LZMA compressed) ---------------------------------- +1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) +------------------------------------------- -Config: boards/tl3238x_retention.conf +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 -Overlay: src/platform/telink/tl3238x_2m_flash.overlay +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 > build_tl3238x_retention.log +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) -Output: - build_tl3238x_retention/zephyr/merged.bin -> flash this - build_tl3238x_retention/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP - build_tl3238x_retention/zephyr/matter.ota -> OTA upgrade +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 -2. Matter + Zigbee dual mode (LZMA compressed) ------------------------------------------------- +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. -Config: boards/tl3238x_retention_dual_mode.conf +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) -Overlay: src/platform/telink/tl3238x_2m_flash.overlay +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.conf" > build_tl3238x_retention_dual_mode.log + -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/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/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.txt b/examples/light-switch-app/telink/boards/tl7218x_retention_README.txt new file mode 100644 index 000000000000..7ceb70937d57 --- /dev/null +++ b/examples/light-switch-app/telink/boards/tl7218x_retention_README.txt @@ -0,0 +1,78 @@ +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: + 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/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 79711e31d4f3..1d2a1212aeb6 100755 --- a/examples/light-switch-app/telink/prj.conf +++ b/examples/light-switch-app/telink/prj.conf @@ -26,7 +26,7 @@ CONFIG_STD_CPP17=y CONFIG_CHIP_DEVICE_PRODUCT_ID=32772 # Bluetooth Low Energy configuration -# CONFIG_BT_DEVICE_NAME="TelinkSwitch" +CONFIG_BT_DEVICE_NAME="TelinkSwitch" # Disable Matter OTA DFU CONFIG_CHIP_OTA_REQUESTOR=n diff --git a/examples/lighting-app/telink/boards/tl3238x.conf b/examples/lighting-app/telink/boards/tl3238x.conf index 28e3510f9917..a3c7a2c90444 100644 --- a/examples/lighting-app/telink/boards/tl3238x.conf +++ b/examples/lighting-app/telink/boards/tl3238x.conf @@ -1,13 +1,16 @@ # CONFIG_CHIP_DEVICE_SERIAL_NUMBER="TelinkLight-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 +CONFIG_CHIP_OTA_REQUESTOR=n -#compress ota -CONFIG_LZMA=y -CONFIG_COMPRESS_LZMA=y +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 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.conf b/examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode_ota.conf similarity index 100% rename from examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode.conf rename to examples/lighting-app/telink/boards/tl3238x_4m_flash_dual_mode_ota.conf diff --git a/examples/lighting-app/telink/boards/tl3238x_README.txt b/examples/lighting-app/telink/boards/tl3238x_README.txt index 3c8e13a5e371..fe80179e104f 100644 --- a/examples/lighting-app/telink/boards/tl3238x_README.txt +++ b/examples/lighting-app/telink/boards/tl3238x_README.txt @@ -1,50 +1,110 @@ TL3238X Lighting App Build Guide ================================= -1. 2MB Flash (Matter only, LZMA compressed) +1. 2MB Flash (Matter only, NO OTA/MCUBoot, NO LZMA) ------------------------------------------- -Config: boards/tl3238x.conf +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: + 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: + 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 -Overlay: src/platform/telink/tl3238x_2m_lzma_flash.overlay +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 -d build_tl3238x_2m > build_tl3238x_2m.log +Build Software Version 1: + 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) -Output: - build_tl3238x_2m/zephyr/merged.bin -> flash this - build_tl3238x_2m/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP - build_tl3238x_2m/zephyr/matter.ota -> OTA upgrade +Build Software Version 2: + 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: + 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 -2. 4MB Flash (Matter + Zigbee dual mode, no LZMA) +3. 4MB Flash (Matter + Zigbee dual mode, no LZMA) --------------------------------------------------- Prerequisite: copy Zigbee firmware 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 -Config: boards/tl3238x_4m_flash_dual_mode.conf +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) -Overlay: src/platform/telink/tl3238x_4m_flash.overlay +DTS Overlay: src/platform/telink/tl3238x_4m_flash.overlay (default) - slot0: 0x16000, size 0x1E5000 (1940KB) - slot1: 0x1FB000, size 0x1E5000 (1940KB) -Board overlay: boards/tl3238x_for_TL3238C-EVK40D.overlay +Board DTS Overlay: boards/tl3238x_for_TL3238C-EVK40D.overlay (explicitly specified) - LED/Key definitions for TL3238C-EVK40D board Build: west build -p -b tl3238x -d build_tl3238x_4m_dual_mode -- \ -DFLASH_SIZE=4m \ - -DCONF_FILE="prj.conf boards/tl3238x_4m_flash_dual_mode.conf" \ - -DDTC_OVERLAY_FILE="boards/tl3238x_for_TL3238C-EVK40D.overlay" > build_tl3238x_4m_dual_mode.log + -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: 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 index f6cb6b51b0c9..73e34f91940c 100644 --- a/examples/lighting-app/telink/boards/tl3238x_for_TL3238C-EVK40D.overlay +++ b/examples/lighting-app/telink/boards/tl3238x_for_TL3238C-EVK40D.overlay @@ -59,7 +59,7 @@ }; key_dfu: button_dfu { label = "USB DFU"; - gpios = <&gpioa 0 32>; /* 保持原有DFU按键配置 */ + gpios = <&gpioa 0 32>; /* keep previous DFU button set-up */ }; }; 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/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.txt b/examples/lighting-app/telink/boards/tl7218x_README.txt new file mode 100644 index 000000000000..52e54893bbf4 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_README.txt @@ -0,0 +1,78 @@ +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: + 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: + 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: + 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: + 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: + 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/platform/telink/common.cmake b/examples/platform/telink/common.cmake index 7e6a3799850c..4f2860ca40f1 100644 --- a/examples/platform/telink/common.cmake +++ b/examples/platform/telink/common.cmake @@ -126,11 +126,10 @@ else() unset(USB_CONF_OVERLAY_FILE) endif() -set(FIRMWARE_COMPRESS_LZMA "") -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") - set(FIRMWARE_COMPRESS_LZMA "lzma_") else() set(BOOT_CONF_OVERLAY_FILE "${CHIP_ROOT}/config/telink/app/bootloader.conf") set(FLASH_LAYOUT_SUFFIX "") @@ -174,11 +173,16 @@ if(NOT EXISTS "${GLOBAL_DTC_OVERLAY_FILE}") unset(GLOBAL_DTC_OVERLAY_FILE) endif() -if(${BASE_BOARD} MATCHES "tl3238x") - set(FLASH_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_${FLASH_SIZE}_${FIRMWARE_COMPRESS_LZMA}flash.overlay") -else() - set(FLASH_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_${FLASH_SIZE}_flash${FLASH_LAYOUT_SUFFIX}.overlay") +# Special check for tl3238x and tl7218x: 2MB flash with OTA requires LZMA compression +if(${BASE_BOARD} MATCHES "tl3238x" 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") unset(FLASH_DTC_OVERLAY_FILE) diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index a6d4eb8e22d6..34d392170243 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -315,7 +315,11 @@ class AppCallbacks : public AppDelegate void OnCommissioningSessionEstablishmentStarted() override { sIsCommissioningFailed = false; } void OnCommissioningSessionStarted() override { isComissioningStarted = true; } void OnCommissioningSessionStopped() override { isComissioningStarted = false; } - void OnCommissioningSessionEstablishmentError(CHIP_ERROR err) override { sIsCommissioningFailed = true; } + void OnCommissioningSessionEstablishmentError(CHIP_ERROR err) override + { + sIsCommissioningFailed = true; + isComissioningStarted = false; + } #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE void OnCommissioningWindowClosed() override { @@ -449,18 +453,25 @@ void AppTaskCommon::DnssTimerTimeoutCallback(k_timer * timer) static void PowerOnNetworkCheck(void) { Thread::OperationalDataset curDataset; - CHIP_ERROR err = DeviceLayer::ThreadStackMgrImpl().GetThreadProvision(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 + if (!hasDataset && fabricNum == 0) + { // New device return; - } else if (hasDataset && fabricNum > 0) { // Device successfully commissioned + } + else if (hasDataset && fabricNum > 0) + { // Device successfully commissioned return; - } else if (hasDataset && fabricNum == 0) { + } + else if (hasDataset && fabricNum == 0) + { ChipLogProgress(DeviceLayer, "Thread dataset exists, but matter uncommissioned\n"); - } else { + } + else + { return; } k_work_schedule(&sDelayedFactoryResetWork, K_SECONDS(2)); @@ -852,10 +863,14 @@ void AppTaskCommon::StartBleAdvButtonEventHandler(void) void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) { - // for action dual mode, press button to switch to zigbee mode - // #if CONFIG_DUAL_MODE == CONFIG_ACTION_DUAL_MODE - // dual_mode_switch(OPCODE_SWITCH_ZIGBEE); - // #endif + // 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. if (sIsNetworkProvisioned) diff --git a/scripts/tools/telink/update_zephyr.py b/scripts/tools/telink/update_zephyr.py index 58b198b28601..2dd6552f5c65 100755 --- a/scripts/tools/telink/update_zephyr.py +++ b/scripts/tools/telink/update_zephyr.py @@ -119,7 +119,7 @@ def main(): 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="af03f86610f3de8b1f2c12215bbb21f5decf97e3", + default="f50d422d780efb73af939650ef7b8c6bf5a0b99b", help="Specific commit hash for BLE SDK") parser.add_argument("--skip-sdk", action="store_true", diff --git a/src/platform/telink/tl3238x_2m_flash.overlay b/src/platform/telink/tl3238x_2m_flash.overlay index 249608848d98..3f4e5c226de1 100644 --- a/src/platform/telink/tl3238x_2m_flash.overlay +++ b/src/platform/telink/tl3238x_2m_flash.overlay @@ -11,33 +11,13 @@ 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 + reg = <0x15000 0xe5000>; // total slot0 is 916k }; -// 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 { + slot1_partition: partition@fa000 { label = "image-1"; - reg = <0x135000 0xab000>; + reg = <0xfa000 0xe6000>; // total slot1 is 920k }; user_rfu_partition: partition@1e0000 { label = "user_rfu"; diff --git a/src/platform/telink/tl3238x_2m_lzma_flash.overlay b/src/platform/telink/tl3238x_2m_flash_lzma.overlay similarity index 100% rename from src/platform/telink/tl3238x_2m_lzma_flash.overlay rename to src/platform/telink/tl3238x_2m_flash_lzma.overlay diff --git a/src/platform/telink/tl3238x_4m_lzma_flash.overlay b/src/platform/telink/tl3238x_4m_flash_lzma.overlay similarity index 100% rename from src/platform/telink/tl3238x_4m_lzma_flash.overlay rename to src/platform/telink/tl3238x_4m_flash_lzma.overlay diff --git a/src/platform/telink/tl3238x_2m_flash_backup.overlay b/src/platform/telink/tl3238x_simple.overlay similarity index 50% rename from src/platform/telink/tl3238x_2m_flash_backup.overlay rename to src/platform/telink/tl3238x_simple.overlay index 3f4e5c226de1..e75c9bdcdd4e 100644 --- a/src/platform/telink/tl3238x_2m_flash_backup.overlay +++ b/src/platform/telink/tl3238x_simple.overlay @@ -13,35 +13,23 @@ }; slot0_partition: partition@15000 { label = "image-0"; - reg = <0x15000 0xe5000>; // total slot0 is 916k + reg = <0x15000 0xee000>; // total slot0 is 952k (4k aligned) }; - slot1_partition: partition@fa000 { + slot1_partition: partition@103000 { label = "image-1"; - reg = <0xfa000 0xe6000>; // total slot1 is 920k + reg = <0x103000 0xef000>; // total slot1 is 956k (4k aligned) }; - user_rfu_partition: partition@1e0000 { + user_rfu_partition: partition@1f2000 { label = "user_rfu"; - reg = <0x1e0000 0x4000>; + reg = <0x1f2000 0x1000>; }; - storage_partition: partition@1e4000 { + storage_partition: partition@1f3000 { label = "matter-nvs"; - reg = <0x1e4000 0x8000>; // matter nvs part , total is 32k. + reg = <0x1f3000 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 { + secure_partition: partition@1fb000 { 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 + 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"; From b28202629d6022a32aa430d66116965a949f4c84 Mon Sep 17 00:00:00 2001 From: 0x0023 Date: Mon, 13 Jul 2026 16:41:25 +0800 Subject: [PATCH 21/31] Telink: add drafts of SDK release note, version file, Getting Started guide and reorganize READMEs (#8) * Telink: add SDK release note, version file and reorganize READMEs Establish the Telink Matter SDK documentation baseline for release preparation: - Add TELINK_VERSION (1.0.1.0) to identify the Telink SDK release paired with the upstream Matter master f4a8cf9. - Add tl_matter_sdk_release_node.md with supported boards, build targets and resource usage (RAM/ROM/firmware size) for the TL323X and TL721X Matter (OTA + LZMA) configurations. - Rename the upstream README to MATTER_README and promote the Telink README to README.md, so GitHub shows the Telink SDK docs on the repository landing page; add a cross-link to the upstream README. No source code changes. Signed-off-by: Damien Ji * Restyled by prettier-markdown * add telink technical words into github wordlist Signed-off-by: Damien Ji * change *readme.txt to *readme.md Signed-off-by: Damien Ji * Restyled by prettier-markdown * Restyled by prettier-markdown * Telink: add platform docs structure, Getting Started guide and firmware packaging script - Add docs/platforms/telink/ (index + Getting Started) following the per-vendor layout of other Matter platforms; register in docs/platforms/index.md. - Move tl_matter_sdk_release_note.md to docs/platforms/telink/releases/telink_release_notes.md (working copy) and add a versioned snapshot keyed to the tl_v1.0.1-beta-v1.5.1.0 tag. - Add scripts/tools/telink/package_telink_firmware.sh for TL3238X/TL7218X build/extract/readme/zip; it snapshots the release note into telink_release_notes_.md from the nearest git tag. - Update README.md links to the new doc locations. No source code changes. Signed-off-by: Damien Ji * Restyled by prettier-markdown * Restyled by shellharden * Restyled by shfmt * docs: add missing mis-spelling word - devicetree Signed-off-by: Damien Ji --------- Signed-off-by: Damien Ji Co-authored-by: Restyled.io --- .github/.wordlist.txt | 9 + MATTER_README.md | 229 ++++ README.md | 368 +++--- TELINK_VERSION | 5 + docs/platforms/index.md | 2 + docs/platforms/telink/index.md | 12 + .../telink/releases/README_BUILD_SCRIPT.md | 188 +++ .../telink/releases/telink_release_notes.md | 290 +++++ ...k_release_notes_tl_v1.0.1-beta-v1.5.1.0.md | 290 +++++ .../telink/telink_getting_started.md | 357 ++++++ .../telink/boards/tl3238x_retention_README.md | 143 +++ .../boards/tl3238x_retention_README.txt | 107 -- .../telink/boards/tl7218x_retention_README.md | 103 ++ .../boards/tl7218x_retention_README.txt | 78 -- .../telink/boards/tl3238x_README.md | 146 +++ .../telink/boards/tl3238x_README.txt | 110 -- .../telink/boards/tl7218x_README.md | 103 ++ .../telink/boards/tl7218x_README.txt | 78 -- .../tools/telink/package_telink_firmware.sh | 1026 +++++++++++++++++ 19 files changed, 3082 insertions(+), 562 deletions(-) create mode 100644 MATTER_README.md create mode 100644 TELINK_VERSION create mode 100644 docs/platforms/telink/index.md create mode 100644 docs/platforms/telink/releases/README_BUILD_SCRIPT.md create mode 100644 docs/platforms/telink/releases/telink_release_notes.md create mode 100644 docs/platforms/telink/releases/telink_release_notes_tl_v1.0.1-beta-v1.5.1.0.md create mode 100644 docs/platforms/telink/telink_getting_started.md create mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention_README.md delete mode 100644 examples/light-switch-app/telink/boards/tl3238x_retention_README.txt create mode 100644 examples/light-switch-app/telink/boards/tl7218x_retention_README.md delete mode 100644 examples/light-switch-app/telink/boards/tl7218x_retention_README.txt create mode 100644 examples/lighting-app/telink/boards/tl3238x_README.md delete mode 100644 examples/lighting-app/telink/boards/tl3238x_README.txt create mode 100644 examples/lighting-app/telink/boards/tl7218x_README.md delete mode 100644 examples/lighting-app/telink/boards/tl7218x_README.txt create mode 100755 scripts/tools/telink/package_telink_firmware.sh diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index b0a6eb9925e9..d3ca04f97f5f 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -1719,3 +1719,12 @@ Zigbee zigbeealliance zigbeethread zsdk +bdk +Changelog +changelog +devicetree +DLM +downloaders +ILM +tlk +udev 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 07b959115615..e83e60cd494f 100644 --- a/README.md +++ b/README.md @@ -1,229 +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/) +[![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](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) +## 📖 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. +## 🔧 Environment Setup -# Project Overview +### Prerequisites -## Development Goals +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. -Matter is developed with the following goals and principles in mind: +#### Dependency Overview -**Unifying:** Matter is built with and on top of market-tested, existing -technologies. +| 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` | ✅ | -**Interoperable:** The specification permits communication between any -Matter-certified device, subject to users’ permission. +#### Setup Steps -**Secure:** The specification leverages modern security practices and protocols. +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: -**User Control:** The end user controls authorization for interaction with -devices. +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`. -**Federated:** No single entity serves as a throttle or a single point of -failure for root of trust. +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. -**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. +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. -## Architecture Overview +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. -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) +5. **Get the Telink Matter SDK (this repo)** — clone the `dev-tlk_v1.5` branch + of this repository next to the Zephyr SDK. -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: +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. -![Matter Stack Architecture](docs/images/Matter_Layered_Arch.png) +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. -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. +> 💡 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. -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. +### Building Examples -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. +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.). -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. +Refer to the board README for the app + board combination you want to build: -# Current Status of Matter +#### Lighting App (TL3238X / TL7218X) -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. +- 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) -# 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). +#### 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/docs/platforms/index.md b/docs/platforms/index.md index bc345d2ff8d5..f98107797434 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/) - [Silabs](./silabs/) - [STM32](./stm32/) +- [Telink](./telink/) - [TI](./ti/) 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/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_README.txt b/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt deleted file mode 100644 index f5e8f614e622..000000000000 --- a/examples/light-switch-app/telink/boards/tl3238x_retention_README.txt +++ /dev/null @@ -1,107 +0,0 @@ -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: - 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/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_README.txt b/examples/light-switch-app/telink/boards/tl7218x_retention_README.txt deleted file mode 100644 index 7ceb70937d57..000000000000 --- a/examples/light-switch-app/telink/boards/tl7218x_retention_README.txt +++ /dev/null @@ -1,78 +0,0 @@ -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: - 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/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_README.txt b/examples/lighting-app/telink/boards/tl3238x_README.txt deleted file mode 100644 index fe80179e104f..000000000000 --- a/examples/lighting-app/telink/boards/tl3238x_README.txt +++ /dev/null @@ -1,110 +0,0 @@ -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: - 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: - 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: - 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: - 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: - 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 - 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: - 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: - 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/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_README.txt b/examples/lighting-app/telink/boards/tl7218x_README.txt deleted file mode 100644 index 52e54893bbf4..000000000000 --- a/examples/lighting-app/telink/boards/tl7218x_README.txt +++ /dev/null @@ -1,78 +0,0 @@ -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: - 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: - 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: - 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: - 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: - 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/scripts/tools/telink/package_telink_firmware.sh b/scripts/tools/telink/package_telink_firmware.sh new file mode 100755 index 000000000000..0508a59614d3 --- /dev/null +++ b/scripts/tools/telink/package_telink_firmware.sh @@ -0,0 +1,1026 @@ +#!/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] [--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 +# +# 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_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 + ;; + --tl7218x) + GENERATE_TL7218X=true + shift + ;; + build_tl3238x* | build_tl7218x*) + TARGETS+=("$1") + shift + ;; + *) + echo "Unknown option: $1" + echo "Usage: $0 [--build] [--extract] [--readme] [--zip] [--all] [--lighting] [--switch] [--contact] [--tl3238x] [--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_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_tl7218x_* ]]; then + GENERATE_LIGHTING=true + fi + if [[ "$target" == build_tl3238x_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_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_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_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-TL7218X-Matter-DUT-firmware-images-$DATE" + mkdir -p "$PKG_DIR/feature-test/light-switch/tl3238x" + mkdir -p "$PKG_DIR/feature-test/light-switch/tl7218x" + mkdir -p "$PKG_DIR/feature-test/lighting/tl3238x" + 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/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") + + # 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_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 (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 (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 (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" </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!" From 80cce91408705359ac95b14acd1a37554264cbec Mon Sep 17 00:00:00 2001 From: 0x0023 Date: Wed, 22 Jul 2026 09:54:05 +0800 Subject: [PATCH 22/31] telink: add TL5218X platform support and update CI (#12) Add TL5218X (TL521X) SoC platform support to the Matter Telink platform, including build configurations, flash overlays, packaging scripts, and CI workflow updates. Platform support: - Add TL5218X platform config headers (CHIPDevicePlatformConfig.h, CHIPPlatformConfig.h, SystemPlatformConfig.h) with memory and thread stack size adjustments. - Add flash overlays for 2MB and 4MB flash variants, including LZMA compression and backup overlays. - Add FactoryDataParser/Provider updates and suppress sensitive DAC key/certificate debug logs to avoid leaking cryptographic material. Build configurations: - Add lighting-app and lock-app board configs for tl5218x and tl5218x_retention, including OTA, dual-mode OTA, and LZMA variants. - Update config/telink Kconfig.defaults and CMakeLists.txt for TL5218X. - Add README documentation for tl5218x lighting-app and retention builds. - Note that tl5218x_retention porting is not complete Build system: - Update scripts/build/builders/telink.py and targets.py to recognize TL5218X build targets. - Update package_telink_firmware.sh with TL5218X packaging support. - Update update_zephyr.py to support Zephyr PR ref fetching. CI: - Update examples-telink.yaml with TL5218X build targets and BLE SDK revision (2488b5b8bd5122f68d087ba2cd5a8f0c74572b8f). - Update Zephyr revision reference for TL521X builds. Signed-off-by: Hao Wu Signed-off-by: Damien Ji Co-authored-by: Hao Wu --- .github/workflows/examples-telink.yaml | 29 +- config/telink/chip-module/CMakeLists.txt | 3 + config/telink/chip-module/Kconfig.defaults | 55 ++-- .../telink/boards/tl5218x_retention.conf | 19 ++ .../boards/tl5218x_retention_README.txt | 107 +++++++ .../tl5218x_retention_dual_mode_ota_lzma.conf | 19 ++ .../telink/boards/tl5218x_retention_ota.conf | 20 ++ .../boards/tl5218x_retention_ota_lzma.conf | 20 ++ .../telink/boards/tl5218x_retention.conf | 20 ++ .../telink/boards/tl5218x_retention_README.md | 143 +++++++++ .../tl5218x_retention_dual_mode_ota_lzma.conf | 19 ++ .../telink/boards/tl5218x_retention_ota.conf | 20 ++ .../boards/tl5218x_retention_ota_lzma.conf | 20 ++ .../lighting-app/telink/boards/tl5218x.conf | 22 ++ .../boards/tl5218x_2m_flash_ota_lzma.conf | 22 ++ .../tl5218x_4m_flash_dual_mode_ota.conf | 19 ++ .../telink/boards/tl5218x_README.md | 140 ++++++++ .../telink/boards/tl5218x_ota.conf | 22 ++ .../telink/boards/tl5218x_retention.conf | 9 + examples/platform/telink/common.cmake | 2 +- .../telink/common/src/AppTaskCommon.cpp | 4 +- .../telink/project_include/OpenThreadConfig.h | 5 +- scripts/build/build/targets.py | 3 +- scripts/build/builders/telink.py | 9 +- .../build/testdata/all_targets_linux_x64.txt | 2 +- .../tools/telink/package_telink_firmware.sh | 301 +++++++++++++++++- scripts/tools/telink/update_zephyr.py | 27 +- .../telink/CHIPDevicePlatformConfig.h | 3 +- src/platform/telink/CHIPPlatformConfig.h | 13 +- src/platform/telink/FactoryDataParser.c | 10 +- src/platform/telink/FactoryDataProvider.cpp | 36 +-- src/platform/telink/SystemPlatformConfig.h | 6 +- src/platform/telink/tl5218x_2m_flash.overlay | 60 ++++ .../telink/tl5218x_2m_flash_backup.overlay | 59 ++++ .../telink/tl5218x_2m_flash_lzma.overlay | 79 +++++ src/platform/telink/tl5218x_4m_flash.overlay | 74 +++++ .../telink/tl5218x_4m_flash_lzma.overlay | 74 +++++ 37 files changed, 1409 insertions(+), 86 deletions(-) create mode 100644 examples/contact-sensor-app/telink/boards/tl5218x_retention.conf create mode 100644 examples/contact-sensor-app/telink/boards/tl5218x_retention_README.txt create mode 100644 examples/contact-sensor-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf create mode 100644 examples/contact-sensor-app/telink/boards/tl5218x_retention_ota.conf create mode 100644 examples/contact-sensor-app/telink/boards/tl5218x_retention_ota_lzma.conf create mode 100644 examples/light-switch-app/telink/boards/tl5218x_retention.conf create mode 100644 examples/light-switch-app/telink/boards/tl5218x_retention_README.md create mode 100644 examples/light-switch-app/telink/boards/tl5218x_retention_dual_mode_ota_lzma.conf create mode 100644 examples/light-switch-app/telink/boards/tl5218x_retention_ota.conf create mode 100644 examples/light-switch-app/telink/boards/tl5218x_retention_ota_lzma.conf create mode 100644 examples/lighting-app/telink/boards/tl5218x.conf create mode 100644 examples/lighting-app/telink/boards/tl5218x_2m_flash_ota_lzma.conf create mode 100644 examples/lighting-app/telink/boards/tl5218x_4m_flash_dual_mode_ota.conf create mode 100644 examples/lighting-app/telink/boards/tl5218x_README.md create mode 100644 examples/lighting-app/telink/boards/tl5218x_ota.conf create mode 100644 examples/lock-app/telink/boards/tl5218x_retention.conf create mode 100644 src/platform/telink/tl5218x_2m_flash.overlay create mode 100644 src/platform/telink/tl5218x_2m_flash_backup.overlay create mode 100644 src/platform/telink/tl5218x_2m_flash_lzma.overlay create mode 100644 src/platform/telink/tl5218x_4m_flash.overlay create mode 100644 src/platform/telink/tl5218x_4m_flash_lzma.overlay diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 46de7d8eea7c..6e89e87de10b 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -59,7 +59,7 @@ jobs: - 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 e08fc42546e58d808bfd39f35c8df296f5617a44 --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 46322e5b570e2a68373b18d4f08811acadd1266c" + 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: Build tools required for Factory Data # Run test for master and all PRs @@ -226,6 +226,33 @@ jobs: - name: clean out build output (keep tools) run: rm -rf ./out/telink* + - 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-tl5218x-light-ota-factory-data-4mb' build" + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + 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* + + # 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-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: | diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 3ba7fd186087..0576d28a8e56 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -206,6 +206,9 @@ elseif(CONFIG_SOC_RISCV_TELINK_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) diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 7f869630ac61..5577cc3cb11b 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -70,31 +70,31 @@ config POSIX_MAX_FDS config MAIN_STACK_SIZE default 4864 if SOC_RISCV_TELINK_W91 default 3072 if PM && SOC_RISCV_TELINK_TL321X - default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 4096 config INIT_STACKS default y config IDLE_STACK_SIZE - default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_W91 + default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_W91 || SOC_RISCV_TELINK_TL521X config ISR_STACK_SIZE default 800 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_W91 - default 1024 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 1024 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X config SYSTEM_WORKQUEUE_STACK_SIZE default 664 if PM && !SOC_RISCV_TELINK_W91 - default 2048 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 2048 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X config HEAP_MEM_POOL_SIZE default 256 if ZEPHYR_VERSION_3_3 - default 1796 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 1796 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X 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_TL721X) && !ZEPHYR_VERSION_3_3 + default 26584 if (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X) && !ZEPHYR_VERSION_3_3 default 29448 if SOC_RISCV_TELINK_W91 default 20716 @@ -106,7 +106,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_TL721X + default 47 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 8 if PM default 15 @@ -116,20 +116,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 || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 4 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 8 config NET_PKT_TX_COUNT default 16 if SOC_RISCV_TELINK_W91 - default 4 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 4 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 8 config NET_BUF_RX_COUNT - default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 32 config NET_BUF_TX_COUNT - default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 12 if (PM && !SOC_RISCV_TELINK_W91) || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 32 config GPIO @@ -158,15 +158,15 @@ config BT_MAX_CONN default 1 config BT_L2CAP_TX_MTU - default 103 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 103 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 247 config BT_BUF_ACL_RX_SIZE - default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 251 config BT_BUF_ACL_TX_SIZE - default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 107 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 251 config BT_BUF_EVT_RX_COUNT @@ -194,7 +194,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 1536 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 1536 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 712 config TL_BLE_CTRL_MASTER_MAX_NUM @@ -228,12 +228,14 @@ config PWM endif -if BOARD_TL7218X_RETENTION || BOARD_TL3218X_RETENTION || BOARD_TL3218X || BOARD_TL3238X_RETENTION || BOARD_TL3238X +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 || BOARD_TL3238X + default y if PM || BOARD_TL3218X || BOARD_TL3238X || BOARD_TL5218X config PWM default n if PM @@ -242,7 +244,8 @@ endif # Board non-retention config if BOARD_TLSR9118BDK40D || BOARD_TLSR9118BDK40D_V1 || \ - BOARD_TLSR9528A || BOARD_TLSR9518ADK80D || BOARD_TL3218X || BOARD_TL3238X || BOARD_TL7218X + BOARD_TLSR9528A || BOARD_TLSR9518ADK80D || BOARD_TL3218X || \ + BOARD_TL3238X || BOARD_TL5218X || BOARD_TL7218X config PWM default y endif @@ -290,7 +293,7 @@ config NVS_LOOKUP_CACHE config NVS_LOOKUP_CACHE_SIZE default 400 if SOC_RISCV_TELINK_TL321X - default 400 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 400 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 2048 if !PM || SOC_RISCV_TELINK_W91 # Set multiplicator of Name Value Storage (NVS) as 1 to reach NVS sector size 4KB @@ -350,7 +353,7 @@ config OPENTHREAD_SED_RAM_CODE 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_TL721X) + default y if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X) default n help Improve RF performance in IEEE 802.15.4 communication on TLX SoCs. @@ -361,12 +364,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_TL721X + default 4096 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X 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_TL721X) - default 608 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 2048 if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X) + default 608 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 640 config OPENTHREAD_SLAAC @@ -378,8 +381,8 @@ config OPENTHREAD_MANUAL_START # 6 is the max rf level by Vant config OPENTHREAD_DEFAULT_TX_POWER default 6 if PM && (SOC_RISCV_TELINK_TL321X) - default 3 if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X) - default 11 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 3 if PM && (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X) + default 11 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X default 9 config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS @@ -396,7 +399,7 @@ 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 SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X + default 600 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X config NET_RX_STACK_SIZE default 2048 if SOC_RISCV_TELINK_W91 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/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/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/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/platform/telink/common.cmake b/examples/platform/telink/common.cmake index 4f2860ca40f1..57cd47fd38f7 100644 --- a/examples/platform/telink/common.cmake +++ b/examples/platform/telink/common.cmake @@ -174,7 +174,7 @@ if(NOT EXISTS "${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 "tl7218x") +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...") diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 34d392170243..c45a5e010feb 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -128,9 +128,9 @@ DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttribut #endif -#if CONFIG_SOC_RISCV_TELINK_TL323X +#if CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL521X #include -#endif /* CONFIG_SOC_RISCV_TELINK_TL323X */ +#endif /* CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL521X */ #include #include diff --git a/examples/platform/telink/project_include/OpenThreadConfig.h b/examples/platform/telink/project_include/OpenThreadConfig.h index e95dd632e70a..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 || CONFIG_SOC_RISCV_TELINK_TL323X || CONFIG_SOC_RISCV_TELINK_TL721X +#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 || CONFIG_SOC_RISCV_TELINK_TL323X +#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/scripts/build/build/targets.py b/scripts/build/build/targets.py index 925514732c5e..798644983624 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -783,8 +783,9 @@ def BuildTelinkTarget(): TargetPart('tl3218x_ml3m', board=TelinkBoard.TL3218X_ML3M), TargetPart('tl3218x_retention', board=TelinkBoard.TL3218X_RETENTION), TargetPart('tl3238x', board=TelinkBoard.TL3238X), - TargetPart('tl3238x_ml3m', board=TelinkBoard.TL3238X_ML3M), 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), diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index 23549ae8be9f..f9181bb1903f 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -128,8 +128,9 @@ class TelinkBoard(Enum): TL3218X_ML3M = auto() TL3218X_RETENTION = auto() TL3238X = auto() - TL3238X_ML3M = auto() TL3238X_RETENTION = auto() + TL5218X = auto() + TL5218X_RETENTION = auto() TL7218X = auto() TL7218X_ML7G = auto() TL7218X_ML7M = auto() @@ -152,10 +153,12 @@ def GnArgName(self): return 'tl3218x_retention' if self == TelinkBoard.TL3238X: return 'tl3238x' - if self == TelinkBoard.TL3238X_ML3M: - return 'tl3238x_ml3m' 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: diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 21fe379567a0..28fa022c7d7a 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,tl3238x,tl3238x_ml3m,tl3238x_retention,tl7218x,tl7218x_ml7g,tl7218x_ml7m,tl7218x_retention,tlsr9118bdk40d,tlsr9518adk80d,tlsr9528a,tlsr9528a_retention}-{air-quality-sensor,all-clusters,all-clusters-minimal,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] +telink-{tl3218x,tl3218x_ml3m,tl3218x_retention,tl3238x,tl3238x_retention,tl5218x,tl5218x_retention,tl7218x,tl7218x_ml7g,tl7218x_ml7m,tl7218x_retention,tlsr9118bdk40d,tlsr9518adk80d,tlsr9528a,tlsr9528a_retention}-{air-quality-sensor,all-clusters,all-clusters-minimal,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/package_telink_firmware.sh b/scripts/tools/telink/package_telink_firmware.sh index 0508a59614d3..b7fe62a3b285 100755 --- a/scripts/tools/telink/package_telink_firmware.sh +++ b/scripts/tools/telink/package_telink_firmware.sh @@ -20,7 +20,7 @@ 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] [--tl7218x] [target1 target2...] +# 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 @@ -53,6 +53,25 @@ set -e # - 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 @@ -91,6 +110,7 @@ GENERATE_LIGHTING=false GENERATE_SWITCH=false GENERATE_CONTACT=false GENERATE_TL3238X=false +GENERATE_TL5218X=false GENERATE_TL7218X=false TARGETS=() @@ -135,17 +155,21 @@ while [ $# -gt 0 ]; do GENERATE_TL3238X=true shift ;; + --tl5218x) + GENERATE_TL5218X=true + shift + ;; --tl7218x) GENERATE_TL7218X=true shift ;; - build_tl3238x* | build_tl7218x*) + 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] [--tl7218x] [target1 target2...]" + echo "Usage: $0 [--build] [--extract] [--readme] [--zip] [--all] [--lighting] [--switch] [--contact] [--tl3238x] [--tl5218x] [--tl7218x] [target1 target2...]" exit 1 ;; esac @@ -165,14 +189,15 @@ if [ "$DO_BUILD" = true ] && [ ${#TARGETS[@]} -eq 0 ]; then 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_tl7218x_* ]]; then + if [[ "$target" == build_tl3238x_* ]] || [[ "$target" == build_tl5218x_* ]] || [[ "$target" == build_tl7218x_* ]]; then GENERATE_LIGHTING=true fi - if [[ "$target" == build_tl3238x_retention* ]] || [[ "$target" == build_tl7218x_retention* ]]; then + 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 @@ -183,6 +208,9 @@ elif [ "$DO_BUILD" = true ]; then 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 @@ -318,6 +346,57 @@ generate_lighting_app() { 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" @@ -411,6 +490,59 @@ generate_light_switch() { 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" @@ -481,12 +613,15 @@ extract_firmware() { 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-TL7218X-Matter-DUT-firmware-images-$DATE" + 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" @@ -507,6 +642,22 @@ extract_firmware() { 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") @@ -528,6 +679,10 @@ extract_firmware() { "$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" \ @@ -561,6 +716,29 @@ extract_firmware() { 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 @@ -603,6 +781,29 @@ extract_firmware() { 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 @@ -649,6 +850,33 @@ extract_firmware() { 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 @@ -751,7 +979,7 @@ generate_readme() { 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" <dac_priv_key.data = dac_key_decrypt; } else diff --git a/src/platform/telink/FactoryDataProvider.cpp b/src/platform/telink/FactoryDataProvider.cpp index d5326cc7af92..64d0ecbbdc1d 100644 --- a/src/platform/telink/FactoryDataProvider.cpp +++ b/src/platform/telink/FactoryDataProvider.cpp @@ -121,11 +121,11 @@ CHIP_ERROR FactoryDataProvider::Init() 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 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"); + // 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)) @@ -135,11 +135,11 @@ CHIP_ERROR FactoryDataProvider::Init() 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 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"); + // 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 @@ -240,19 +240,19 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(c 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"); + // 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"); + // 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"); + // 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) @@ -277,9 +277,9 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(c 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"); + // 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), diff --git a/src/platform/telink/SystemPlatformConfig.h b/src/platform/telink/SystemPlatformConfig.h index 14216b8dc62f..c62e8b55bfcc 100644 --- a/src/platform/telink/SystemPlatformConfig.h +++ b/src/platform/telink/SystemPlatformConfig.h @@ -45,8 +45,8 @@ struct ChipDeviceEvent; #endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS #if defined(CONFIG_SOC_RISCV_TELINK_TL321X) || defined(CONFIG_SOC_RISCV_TELINK_TL323X) || \ - defined(CONFIG_SOC_RISCV_TELINK_TL721X) || defined(CONFIG_SOC_SERIES_RISCV_TELINK_B9X_RETENTION) || \ - defined(CONFIG_SOC_RISCV_TELINK_W91) + 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 @@ -58,7 +58,7 @@ struct ChipDeviceEvent; // 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_TL323X) || \ - defined(CONFIG_SOC_RISCV_TELINK_TL721X) || defined(CONFIG_SOC_RISCV_TELINK_W91) + 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/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. + }; + }; +}; From 50cae34e79ecbd5af5644eb60f6aa564f6c48ab4 Mon Sep 17 00:00:00 2001 From: 0x0023 Date: Thu, 6 Aug 2026 16:10:56 +0800 Subject: [PATCH 23/31] telink: add BLE/Thread concurrent mode and Channel Sounding reflector (#16) Add support for running BLE concurrently with an active Thread network on TL7218X and TL3238X, and integrate a Channel Sounding (CS) RAS reflector for TL7218X. Introduces CHIP_CONCURRENT_MODE Kconfig option that keeps the BLE controller alive after Thread commissioning. Key additions: - BLE idle mode and tl_dual_mode_start coordination for TLX RF coexistence - CS reflector implementation (CsReflector) for TL7218X - Concurrent board configs for TL3238X and TL7218X with README docs - CI: bump Zephyr to 8e3ccc0, BLE SDK to 088fca4 - Disable Cirque workflow (otbr-agent/ot-rcp upstream mismatch) Depends on Zephyr PR telink-semi/zephyr#789. CI (examples-telink.yaml) passed. --------- Signed-off-by: Hao Wu Signed-off-by: Damien Ji Co-authored-by: Hao Wu Co-authored-by: Restyled.io --- .github/.wordlist.txt | 1 + .../{cirque.yaml => cirque.yaml.disabled} | 0 .github/workflows/examples-telink.yaml | 34 +- config/telink/chip-module/Kconfig | 23 + config/telink/chip-module/Kconfig.defaults | 19 +- examples/chef/telink/src/AppTask.cpp | 2 +- examples/lighting-app/telink/CMakeLists.txt | 4 + .../telink/boards/tl3238x_README.md | 77 ++ .../telink/boards/tl3238x_concurrent.conf | 32 + .../boards/tl3238x_concurrent_ota_lzma.conf | 31 + .../telink/boards/tl7218x_README.md | 153 ++++ .../telink/boards/tl7218x_concurrent.conf | 9 + .../telink/boards/tl7218x_concurrent_cs.conf | 52 ++ .../tl7218x_concurrent_cs_ota_lzma.conf | 74 ++ .../boards/tl7218x_concurrent_ota_lzma.conf | 31 + examples/lighting-app/telink/prj.conf | 5 + .../telink/common/include/AppTaskCommon.h | 4 +- .../telink/common/src/AppTaskCommon.cpp | 28 +- src/app/server/Server.cpp | 11 + src/platform/telink/BLEManagerImpl.cpp | 144 +++- src/platform/telink/BLEManagerImpl.h | 25 + src/platform/telink/BUILD.gn | 7 + src/platform/telink/CsReflector.cpp | 699 ++++++++++++++++++ src/platform/telink/CsReflector.h | 71 ++ .../telink/ThreadStackManagerImpl.cpp | 18 +- src/platform/telink/ThreadStackManagerImpl.h | 8 + src/platform/telink/args.gni | 3 + 27 files changed, 1511 insertions(+), 54 deletions(-) rename .github/workflows/{cirque.yaml => cirque.yaml.disabled} (100%) create mode 100644 examples/lighting-app/telink/boards/tl3238x_concurrent.conf create mode 100644 examples/lighting-app/telink/boards/tl3238x_concurrent_ota_lzma.conf create mode 100644 examples/lighting-app/telink/boards/tl7218x_concurrent.conf create mode 100644 examples/lighting-app/telink/boards/tl7218x_concurrent_cs.conf create mode 100644 examples/lighting-app/telink/boards/tl7218x_concurrent_cs_ota_lzma.conf create mode 100644 examples/lighting-app/telink/boards/tl7218x_concurrent_ota_lzma.conf create mode 100644 src/platform/telink/CsReflector.cpp create mode 100644 src/platform/telink/CsReflector.h diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index d3ca04f97f5f..8a59eaae2c40 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -1727,4 +1727,5 @@ DLM downloaders ILM tlk +TLX udev diff --git a/.github/workflows/cirque.yaml b/.github/workflows/cirque.yaml.disabled similarity index 100% rename from .github/workflows/cirque.yaml rename to .github/workflows/cirque.yaml.disabled diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 6e89e87de10b..1e7c71c79306 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -59,7 +59,7 @@ jobs: - 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" + scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py https://github.com/telink-semi/zephyr.git 8e3ccc07900692fe5a9990cd517203de61b2eefc --sdk-repo https://github.com/telink-semi/tl_ble_sdk_zephyr.git --sdk-hash 53eb98b32ea79ed7ab38f5daabde0a78a7880cd9" - name: Build tools required for Factory Data # Run test for master and all PRs @@ -174,32 +174,6 @@ jobs: - name: clean out build output (keep tools) run: rm -rf ./out/telink* - - name: Build example Telink (tl321x) 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-tl3218x-light-ota-compress-lzma-shell-factory-data' build" - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - telink tl3218x light-app-ota-compress-lzma-shell-factory-data \ - out/telink-tl3218x-light-ota-compress-lzma-shell-factory-data/zephyr/zephyr.elf \ - /tmp/bloat_reports/ - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - - name: Build example Telink (tl321x_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-tl3218x_retention-light-switch-ota-factory-data' build" - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - telink tl3218x_retention light-switch-app-ota-factory-data \ - out/telink-tl3218x_retention-light-switch-ota-factory-data/zephyr/zephyr.elf \ - /tmp/bloat_reports/ - - - name: clean out build output (keep tools) - run: rm -rf ./out/telink* - - name: Build example Telink (tl323x) Lighting App with Factory Data, 4Mb flash # Run test for master and all PRs run: | @@ -306,15 +280,15 @@ jobs: - name: clean out build output (keep tools) run: rm -rf ./out/telink* - - name: Build example Telink (tl321x) OTA Requestor App + - name: Build example Telink (tl323x) OTA Requestor App # Run test for master and s07641069 PRs if: github.event.pull_request.number == null || github.event.pull_request.head.repo.full_name == 's07641069/connectedhomeip' run: | ./scripts/run_in_build_env.sh \ "./scripts/build/build_examples.py --target 'telink-tl3218x-ota-requestor' build" .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - telink tl3218x ota-requestor-app \ - out/telink-tl3218x-ota-requestor/zephyr/zephyr.elf \ + telink tl3238x ota-requestor-app \ + out/telink-tl3238x-ota-requestor/zephyr/zephyr.elf \ /tmp/bloat_reports/ - name: clean out build output (keep tools) diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index c81d33ac3051..c966f2cedef6 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -214,6 +214,29 @@ config CHIP_ENABLE_PM_DURING_BLE help Enable PM during BLE operation. +config CHIP_CONCURRENT_MODE + bool "Keep BLE active while Thread is running" + depends on IEEE802154_TLX_BLE_COEXIST + default n + help + Allow BLE and Thread to run simultaneously on TLX SoCs. Without this + option, BLE is disabled once Thread is commissioned. With it enabled, + BLE stays available for connection or Channel Sounding alongside + an active Thread network. + +config CHIP_CONCURRENT_BLE_IDLE + bool "Keep BLE idle after Thread commissioning in concurrent mode" + depends on CHIP_CONCURRENT_MODE + default n + help + When enabled, BLE advertising is not automatically re-enabled after + Thread commissioning completes or after a commissioned device reboots. + The BLE stack stays initialized but idle, and advertising must be + started manually (e.g. via a button press). This saves power while + still allowing on-demand BLE access alongside an active Thread network. + Use this together with a button handler that calls + SetBLEAdvertisingEnabled(true) when BLE is needed. + config SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE default 255 if SHELL_BACKEND_SERIAL diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 5577cc3cb11b..7e35e0cbd2cc 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -70,18 +70,26 @@ config POSIX_MAX_FDS config MAIN_STACK_SIZE default 4864 if SOC_RISCV_TELINK_W91 default 3072 if PM && SOC_RISCV_TELINK_TL321X - default 3240 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X + default 3240 if PM || SOC_RISCV_TELINK_TL321X + default 3240 if SOC_RISCV_TELINK_TL323X + default 3240 if SOC_RISCV_TELINK_TL521X + default 3240 if 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_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_W91 || SOC_RISCV_TELINK_TL521X + default 560 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_W91 + default 560 if SOC_RISCV_TELINK_TL323X + default 560 if SOC_RISCV_TELINK_TL521X + default 560 if SOC_RISCV_TELINK_TL721X config ISR_STACK_SIZE default 800 if PM || SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_W91 - default 1024 if SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X + default 1024 if SOC_RISCV_TELINK_TL323X + default 1024 if SOC_RISCV_TELINK_TL521X + default 1024 if SOC_RISCV_TELINK_TL721X config SYSTEM_WORKQUEUE_STACK_SIZE default 664 if PM && !SOC_RISCV_TELINK_W91 @@ -93,6 +101,7 @@ config HEAP_MEM_POOL_SIZE default 1280 config COMMON_LIBC_MALLOC_ARENA_SIZE + default 30720 if (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X) && CHIP_CONCURRENT_MODE && !ZEPHYR_VERSION_3_3 default 19000 if SOC_RISCV_TELINK_TL321X && !ZEPHYR_VERSION_3_3 default 26584 if (SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X) && !ZEPHYR_VERSION_3_3 default 29448 if SOC_RISCV_TELINK_W91 @@ -399,7 +408,9 @@ 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 SOC_RISCV_TELINK_TL323X || SOC_RISCV_TELINK_TL721X || SOC_RISCV_TELINK_TL521X + default 600 if SOC_RISCV_TELINK_TL323X + default 600 if SOC_RISCV_TELINK_TL521X + default 600 if SOC_RISCV_TELINK_TL721X config NET_RX_STACK_SIZE default 2048 if SOC_RISCV_TELINK_W91 diff --git a/examples/chef/telink/src/AppTask.cpp b/examples/chef/telink/src/AppTask.cpp index 4b3116d4fd67..95813e8bac14 100644 --- a/examples/chef/telink/src/AppTask.cpp +++ b/examples/chef/telink/src/AppTask.cpp @@ -55,5 +55,5 @@ void AppTask::LinkButtons(ButtonManager & buttonManager) { buttonManager.addCallback(FactoryResetButtonEventHandler, 0, true); buttonManager.addCallback(ExampleActionButtonEventHandler, 1, true); - buttonManager.addCallback(StartBleAdvButtonEventHandler, 2, true); + buttonManager.addCallback(ToggleBleAdvButtonEventHandler, 2, true); } diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index dbdef1d38393..c2b7db32aae0 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -99,3 +99,7 @@ endif() if (CONFIG_CHIP_PW_RPC) include(${TELINK_COMMON}/Rpc.cmake) endif(CONFIG_CHIP_PW_RPC) + +if(CONFIG_BT_CHANNEL_SOUNDING) + target_sources(app PRIVATE ${CHIP_ROOT}/src/platform/telink/CsReflector.cpp) +endif() diff --git a/examples/lighting-app/telink/boards/tl3238x_README.md b/examples/lighting-app/telink/boards/tl3238x_README.md index 681555c904e8..a40dead1de9e 100644 --- a/examples/lighting-app/telink/boards/tl3238x_README.md +++ b/examples/lighting-app/telink/boards/tl3238x_README.md @@ -144,3 +144,80 @@ time.** partition limit. **Solution**: Use the LZMA-enabled configuration (target #2) instead. + +## 5. Concurrent Mode (Matter over Thread + BLE coexistence, NO OTA) + +**Kconfig:** boards/tl3238x_concurrent.conf (explicitly specified) + +- CONFIG_CHIP_CONCURRENT_MODE=y +- CONFIG_IEEE802154_TLX_BLE_COEXIST=y +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration enables BLE + 802.15.4 coexistence for Matter over +Thread with BLE advertising. OTA is disabled. + +**DTS Overlay:** src/platform/telink/tl3238x_2m_flash.overlay (default) + +**Build:** + +```bash +west build -p -b tl3238x -d build_tl3238x_concurrent -- \ +-DCONF_FILE="prj.conf boards/tl3238x_concurrent.conf" > build_tl3238x_concurrent.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_concurrent.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl3238x_concurrent/zephyr/zephyr.bin -> flash this +``` + +**Note**: TL3238X does NOT support Channel Sounding. Use TL7218X for concurrent +mode + Channel Sounding (see boards/tl7218x_concurrent_cs.conf). + +## 6. Concurrent Mode (Matter over Thread + BLE coexistence, with OTA) + +**Kconfig:** boards/tl3238x_concurrent_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_CONCURRENT_MODE=y +- CONFIG_IEEE802154_TLX_BLE_COEXIST=y +- 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 + +**Note**: This configuration enables BLE + 802.15.4 coexistence for Matter over +Thread with BLE advertising and OTA support. LZMA compression is required for +2MB flash with OTA. + +**DTS Overlay:** src/platform/telink/tl3238x_2m_flash_lzma.overlay (default) + +**Build Software Version 1:** + +```bash +west build -p -b tl3238x -d build_tl3238x_concurrent_ota_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl3238x_concurrent_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl3238x_concurrent_ota_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_concurrent_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_concurrent_ota_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl3238x_concurrent_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl3238x_concurrent_ota_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl3238x_concurrent_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl3238x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl3238x_concurrent_ota_lzma_v1/zephyr/merged.bin -> flash this +build_tl3238x_concurrent_ota_lzma_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl3238x_concurrent_ota_lzma_v2/zephyr/matter.ota -> OTA upgrade +``` diff --git a/examples/lighting-app/telink/boards/tl3238x_concurrent.conf b/examples/lighting-app/telink/boards/tl3238x_concurrent.conf new file mode 100644 index 000000000000..3734bb2c92ab --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_concurrent.conf @@ -0,0 +1,32 @@ +# TL3238X Concurrent Mode (Matter over Thread + BLE coexistence) +# This config enables BLE + 802.15.4 coexistence mode. +# Usage: +# west build -p -b tl3238x -d build_tl3238x_concurrent -- \ +# -DCONF_FILE="prj.conf boards/tl3238x_concurrent.conf" > build_tl3238x_concurrent.log + +# Enable concurrent mode (Matter over Thread + BLE) +CONFIG_CHIP_CONCURRENT_MODE=y +CONFIG_IEEE802154_TLX_BLE_COEXIST=y + +# 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_concurrent_ota_lzma.conf b/examples/lighting-app/telink/boards/tl3238x_concurrent_ota_lzma.conf new file mode 100644 index 000000000000..eb35ec292688 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl3238x_concurrent_ota_lzma.conf @@ -0,0 +1,31 @@ +# TL3238X Concurrent Mode (Matter over Thread + BLE coexistence) with OTA +# This config enables BLE + 802.15.4 coexistence mode with OTA support. +# Usage: +# west build -p -b tl3238x -d build_tl3238x_concurrent_ota_v1 -- \ +# -DCONF_FILE="prj.conf boards/tl3238x_concurrent_ota.conf" \ +# -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl3238x_concurrent_ota_v1.log + +# Enable concurrent mode (Matter over Thread + BLE) +CONFIG_CHIP_CONCURRENT_MODE=y +CONFIG_IEEE802154_TLX_BLE_COEXIST=y + +# 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 +CONFIG_LZMA=y +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/tl7218x_README.md b/examples/lighting-app/telink/boards/tl7218x_README.md index c536fa1a058f..ae3daf83ad9b 100644 --- a/examples/lighting-app/telink/boards/tl7218x_README.md +++ b/examples/lighting-app/telink/boards/tl7218x_README.md @@ -101,3 +101,156 @@ partition limit. **Important Note**: TL7218X does NOT support dual_mode (Matter + Zigbee) configuration. + +## 4. Concurrent Mode (Matter over Thread + BLE coexistence, NO OTA) + +**Kconfig:** boards/tl7218x_concurrent.conf (explicitly specified) + +- CONFIG_CHIP_CONCURRENT_MODE=y +- CONFIG_IEEE802154_TLX_BLE_COEXIST=y +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration enables BLE + 802.15.4 coexistence for Matter over +Thread with BLE advertising. OTA is disabled. + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash.overlay (default) + +**Build:** + +```bash +west build -p -b tl7218x -d build_tl7218x_concurrent -- \ +-DCONF_FILE="prj.conf boards/tl7218x_concurrent.conf" > build_tl7218x_concurrent.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_concurrent.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl7218x_concurrent/zephyr/zephyr.bin -> flash this +``` + +## 5. Concurrent Mode + Channel Sounding (Matter over Thread + BLE + CS, NO OTA) + +**Kconfig:** boards/tl7218x_concurrent_cs.conf (explicitly specified) + +- CONFIG_CHIP_CONCURRENT_MODE=y +- CONFIG_IEEE802154_TLX_BLE_COEXIST=y +- CONFIG_BT_CHANNEL_SOUNDING=y, CONFIG_BT_TLX_CHANNEL_SOUNDING=y +- CONFIG_BT_SMP=y (unauthenticated pairing, LE Security Mode 1 Level 2) +- CONFIG_CHIP_OTA_REQUESTOR=n +- CONFIG_DUAL_MODE=0 + +**Note**: This configuration enables BLE + 802.15.4 coexistence with Channel +Sounding (RAS Reflector) support. BLE buffers, SMP bonding, and stack sizes are +tuned for CS + OT coexistence. OTA is disabled. + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash.overlay (default) + +**Build:** + +```bash +west build -p -b tl7218x -d build_tl7218x_concurrent_cs -- \ +-DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs.conf" > build_tl7218x_concurrent_cs.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash.overlay) +``` + +**Output:** + +```bash +build_tl7218x_concurrent_cs/zephyr/zephyr.bin -> flash this +``` + +## 6. Concurrent Mode (Matter over Thread + BLE coexistence, with OTA) + +**Kconfig:** boards/tl7218x_concurrent_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_CONCURRENT_MODE=y +- CONFIG_IEEE802154_TLX_BLE_COEXIST=y +- 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 + +**Note**: This configuration enables BLE + 802.15.4 coexistence for Matter over +Thread with BLE advertising and OTA support. LZMA compression is required for +2MB flash with OTA. + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash_lzma.overlay (default) + +**Build Software Version 1:** + +```bash +west build -p -b tl7218x -d build_tl7218x_concurrent_ota_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_concurrent_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl7218x_concurrent_ota_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_concurrent_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_concurrent_ota_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_concurrent_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl7218x_concurrent_ota_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_concurrent_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl7218x_concurrent_ota_v1/zephyr/merged.bin -> flash this +build_tl7218x_concurrent_ota_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl7218x_concurrent_ota_v2/zephyr/matter.ota -> OTA upgrade +``` + +## 7. Concurrent Mode + Channel Sounding (Matter over Thread + BLE + CS, with OTA) + +**Kconfig:** boards/tl7218x_concurrent_cs_ota_lzma.conf (explicitly specified) + +- CONFIG_CHIP_CONCURRENT_MODE=y +- CONFIG_IEEE802154_TLX_BLE_COEXIST=y +- CONFIG_BT_CHANNEL_SOUNDING=y, CONFIG_BT_TLX_CHANNEL_SOUNDING=y +- CONFIG_BT_SMP=y (unauthenticated pairing, LE Security Mode 1 Level 2) +- 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 + +**Note**: This configuration enables BLE + 802.15.4 coexistence with Channel +Sounding (RAS Reflector) and OTA support. LZMA compression is required for 2MB +flash with OTA. + +**DTS Overlay:** src/platform/telink/tl7218x_2m_flash_lzma.overlay (default) + +**Build Software Version 1:** + +```bash +west build -p -b tl7218x -d build_tl7218x_concurrent_cs_ota_lzma_v1 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl7218x_concurrent_cs_ota_lzma_v1.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs_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_concurrent_cs_ota_lzma_v2 -- \ +-DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs_ota_lzma.conf" \ +-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 > build_tl7218x_concurrent_cs_ota_lzma_v2.log +# Kconfig: explicitly specified (-DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs_ota_lzma.conf") +# DTS Overlay: default (src/platform/telink/tl7218x_2m_flash_lzma.overlay) +``` + +**Output:** + +```bash +build_tl7218x_concurrent_cs_ota_v1/zephyr/merged.bin -> flash this +build_tl7218x_concurrent_cs_ota_v2/zephyr/merged_dfu.lzma.bin -> DFU over BLE SMP +build_tl7218x_concurrent_cs_ota_v2/zephyr/matter.ota -> OTA upgrade +``` diff --git a/examples/lighting-app/telink/boards/tl7218x_concurrent.conf b/examples/lighting-app/telink/boards/tl7218x_concurrent.conf new file mode 100644 index 000000000000..9240b436a1d5 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_concurrent.conf @@ -0,0 +1,9 @@ +# TL7218X Concurrent Mode (Matter over Thread + BLE coexistence) +# This config enables BLE + 802.15.4 coexistence mode. +# Usage: +# west build -p -b tl7218x -d build_tl7218x_concurrent -- \ +# -DCONF_FILE="prj.conf boards/tl7218x_concurrent.conf" > build_tl7218x_concurrent.log + +# Enable concurrent mode (Matter over Thread + BLE) +CONFIG_CHIP_CONCURRENT_MODE=y +CONFIG_IEEE802154_TLX_BLE_COEXIST=y diff --git a/examples/lighting-app/telink/boards/tl7218x_concurrent_cs.conf b/examples/lighting-app/telink/boards/tl7218x_concurrent_cs.conf new file mode 100644 index 000000000000..2c9a3093446c --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_concurrent_cs.conf @@ -0,0 +1,52 @@ +# TL7218X Concurrent Mode + Channel Sounding (RAS Reflector) +# This config enables BLE + 802.15.4 coexistence mode with Channel Sounding support. +# Usage: +# west build -p -b tl7218x -d build_tl7218x_concurrent_cs -- \ +# -DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs.conf" > build_tl7218x_concurrent_cs.log + +# Enable concurrent mode (Matter over Thread + BLE) +CONFIG_CHIP_CONCURRENT_MODE=y +CONFIG_IEEE802154_TLX_BLE_COEXIST=y + +# Channel Sounding (RAS Reflector) +CONFIG_BT_CHANNEL_SOUNDING=y +CONFIG_BT_TLX_CHANNEL_SOUNDING=y +CONFIG_BT_GATT_DYNAMIC_DB=y +CONFIG_BT_GATT_CLIENT=y + +# BLE buffers for RAS data transfer (reduced for OT coexistence) +CONFIG_BT_BUF_ACL_RX_SIZE=251 +CONFIG_BT_BUF_ACL_TX_SIZE=251 +CONFIG_BT_BUF_ACL_TX_COUNT=4 +CONFIG_BT_BUF_EVT_RX_COUNT=6 +CONFIG_BT_L2CAP_TX_BUF_COUNT=4 +CONFIG_BT_L2CAP_TX_MTU=247 +CONFIG_BT_ATT_TX_COUNT=4 + +# SMP: Unauthenticated Pairing with Encryption (LE Security Mode 1 Level 2) +CONFIG_BT_SMP=y +# BT_HOST_CRYPTO satisfies BT_RPA dependency; PRNG=n avoids PSA bt_rand conflict +CONFIG_BT_HOST_CRYPTO=y +CONFIG_BT_HOST_CRYPTO_PRNG=n +# CRITICAL: Disable PSA in PK/MD/Cipher modules, otherwise CSR generation fails +# with MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE (-0x3980) +CONFIG_MBEDTLS_USE_PSA_CRYPTO=n +CONFIG_BT_SMP_SC_PAIR_ONLY=n +CONFIG_BT_SMP_ENFORCE_MITM=n +CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y +CONFIG_BT_KEYS_OVERWRITE_OLDEST=y + +# Bonding: persist pairing keys in flash +CONFIG_BT_SETTINGS=y +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_SETTINGS=y + +# Stack sizes for CS + BLE + Thread coexistence +CONFIG_MAIN_STACK_SIZE=4096 +CONFIG_ISR_STACK_SIZE=2048 +CONFIG_IDLE_STACK_SIZE=1536 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 +CONFIG_BT_RX_STACK_SIZE=2048 +CONFIG_TL_BLE_CTRL_THREAD_STACK_SIZE=8192 +CONFIG_NET_TX_STACK_SIZE=1200 diff --git a/examples/lighting-app/telink/boards/tl7218x_concurrent_cs_ota_lzma.conf b/examples/lighting-app/telink/boards/tl7218x_concurrent_cs_ota_lzma.conf new file mode 100644 index 000000000000..8fd639ab6ec6 --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_concurrent_cs_ota_lzma.conf @@ -0,0 +1,74 @@ +# TL7218X Concurrent Mode + Channel Sounding (RAS Reflector) with OTA +# This config enables BLE + 802.15.4 coexistence mode with Channel Sounding and OTA support. +# Usage: +# west build -p -b tl7218x -d build_tl7218x_concurrent_cs_ota_v1 -- \ +# -DCONF_FILE="prj.conf boards/tl7218x_concurrent_cs_ota.conf" \ +# -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl7218x_concurrent_cs_ota_v1.log + +# Enable concurrent mode (Matter over Thread + BLE) +CONFIG_CHIP_CONCURRENT_MODE=y +CONFIG_IEEE802154_TLX_BLE_COEXIST=y + +# Channel Sounding (RAS Reflector) +CONFIG_BT_CHANNEL_SOUNDING=y +CONFIG_BT_TLX_CHANNEL_SOUNDING=y +CONFIG_BT_GATT_DYNAMIC_DB=y +CONFIG_BT_GATT_CLIENT=y + +# BLE buffers for RAS data transfer (reduced for OT coexistence) +CONFIG_BT_BUF_ACL_RX_SIZE=251 +CONFIG_BT_BUF_ACL_TX_SIZE=251 +CONFIG_BT_BUF_ACL_TX_COUNT=4 +CONFIG_BT_BUF_EVT_RX_COUNT=6 +CONFIG_BT_L2CAP_TX_BUF_COUNT=4 +CONFIG_BT_L2CAP_TX_MTU=247 +CONFIG_BT_ATT_TX_COUNT=4 + +# SMP: Unauthenticated Pairing with Encryption (LE Security Mode 1 Level 2) +CONFIG_BT_SMP=y +# BT_HOST_CRYPTO satisfies BT_RPA dependency; PRNG=n avoids PSA bt_rand conflict +CONFIG_BT_HOST_CRYPTO=y +CONFIG_BT_HOST_CRYPTO_PRNG=n +# CRITICAL: Disable PSA in PK/MD/Cipher modules, otherwise CSR generation fails +# with MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE (-0x3980) +CONFIG_MBEDTLS_USE_PSA_CRYPTO=n +CONFIG_BT_SMP_SC_PAIR_ONLY=n +CONFIG_BT_SMP_ENFORCE_MITM=n +CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y +CONFIG_BT_KEYS_OVERWRITE_OLDEST=y + +# Bonding: persist pairing keys in flash +CONFIG_BT_SETTINGS=y +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_SETTINGS=y + +# Stack sizes for CS + BLE + Thread coexistence +CONFIG_MAIN_STACK_SIZE=4096 +CONFIG_ISR_STACK_SIZE=2048 +CONFIG_IDLE_STACK_SIZE=1536 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 +CONFIG_BT_RX_STACK_SIZE=2048 +CONFIG_TL_BLE_CTRL_THREAD_STACK_SIZE=8192 +CONFIG_NET_TX_STACK_SIZE=1200 + +# 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 +CONFIG_LZMA=y +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_concurrent_ota_lzma.conf b/examples/lighting-app/telink/boards/tl7218x_concurrent_ota_lzma.conf new file mode 100644 index 000000000000..a1ed502a68ba --- /dev/null +++ b/examples/lighting-app/telink/boards/tl7218x_concurrent_ota_lzma.conf @@ -0,0 +1,31 @@ +# TL7218X Concurrent Mode (Matter over Thread + BLE coexistence) with OTA +# This config enables BLE + 802.15.4 coexistence mode with OTA support. +# Usage: +# west build -p -b tl7218x -d build_tl7218x_concurrent_ota_v1 -- \ +# -DCONF_FILE="prj.conf boards/tl7218x_concurrent_ota.conf" \ +# -DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=1 > build_tl7218x_concurrent_ota_v1.log + +# Enable concurrent mode (Matter over Thread + BLE) +CONFIG_CHIP_CONCURRENT_MODE=y +CONFIG_IEEE802154_TLX_BLE_COEXIST=y + +# 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 +CONFIG_LZMA=y +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/prj.conf b/examples/lighting-app/telink/prj.conf index 73df01b9e101..3d9854cb2b67 100644 --- a/examples/lighting-app/telink/prj.conf +++ b/examples/lighting-app/telink/prj.conf @@ -65,3 +65,8 @@ CONFIG_EXPOSE_CHIP_ID_VIA_BLE=n CONFIG_DEFERRED_ATTR_STORAGE=n # CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/ecdsa_private_key.pem" + +# Concurrent mode and Channel Sounding configs are split into board-specific +# files. See boards/*_README.md for usage: +# - boards/tl7218x_concurrent.conf -> BLE and Thread concurrent mode +# - boards/tl7218x_concurrent_cs.conf -> concurrent mode + channel sounding diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index f81e497a0173..e7b3de19da1a 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -142,8 +142,8 @@ class AppTaskCommon static void FactoryResetButtonEventHandler(void); static void FactoryResetHandler(AppEvent * aEvent); - static void StartBleAdvButtonEventHandler(void); - static void StartBleAdvHandler(AppEvent * aEvent); + static void ToggleBleAdvButtonEventHandler(void); + static void ToggleBleAdvHandler(AppEvent * aEvent); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD static void StartThreadButtonEventHandler(void); diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index c45a5e010feb..abaa584513ec 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -715,7 +715,7 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) break; #endif case kButtonId_StartBleAdv: - StartBleAdvButtonEventHandler(); + ToggleBleAdvButtonEventHandler(); break; } } @@ -788,7 +788,7 @@ void AppTaskCommon::LinkButtons(ButtonManager & buttonManager) #if CONFIG_TELINK_OTA_BUTTON_TEST buttonManager.addCallback(TestOTAButtonEventHandler, 2, true); #else - buttonManager.addCallback(StartBleAdvButtonEventHandler, 2, true); + buttonManager.addCallback(ToggleBleAdvButtonEventHandler, 2, true); #endif #if CHIP_DEVICE_CONFIG_ENABLE_THREAD buttonManager.addCallback(StartThreadButtonEventHandler, 3, true); @@ -851,17 +851,17 @@ void AppTaskCommon::IdentifyEffectHandler(Clusters::Identify::EffectIdentifierEn } } -void AppTaskCommon::StartBleAdvButtonEventHandler(void) +void AppTaskCommon::ToggleBleAdvButtonEventHandler(void) { AppEvent event; event.Type = AppEvent::kEventType_Button; event.ButtonEvent.Action = kButtonPushEvent; - event.Handler = StartBleAdvHandler; + event.Handler = ToggleBleAdvHandler; GetAppTask().PostEvent(&event); } -void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) +void AppTaskCommon::ToggleBleAdvHandler(AppEvent * aEvent) { // This will change the function of the start BLE adv button // to manually switch to Zigbee firmware and run another firmware, @@ -871,11 +871,25 @@ void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) dual_mode_switch(OPCODE_SWITCH_ZIGBEE); #endif - LOG_INF("StartBleAdvHandler"); + LOG_INF("ToggleBleAdvHandler"); // Disable manual Matter service BLE advertising after device provisioning. if (sIsNetworkProvisioned) { LOG_INF("Device already commissioned"); +#if defined(CONFIG_CHIP_CONCURRENT_MODE) && defined(CONFIG_CHIP_CONCURRENT_BLE_IDLE) + // Concurrent idle mode: toggle BLE advertising on demand so that + // BLE (e.g. Channel Sounding) becomes accessible on button press. + if (ConnectivityMgr().IsBLEAdvertisingEnabled()) + { + LOG_INF("Disabling BLE adv"); + ConnectivityMgr().SetBLEAdvertisingEnabled(false); + } + else + { + LOG_INF("Enabling BLE adv"); + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + } +#endif return; } @@ -990,8 +1004,10 @@ void AppTaskCommon::StartThreadHandler(AppEvent * aEvent) { // Switch context from BLE to Thread #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#ifndef CONFIG_CHIP_CONCURRENT_MODE Internal::BLEManagerImpl sInstance; sInstance.SwitchToIeee802154(); +#endif // !CONFIG_CHIP_CONCURRENT_MODE #else ThreadStackMgrImpl().SetRadioBlocked(false); ThreadStackMgrImpl().SetThreadEnabled(true); diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index cc53727f0d12..4cda9d700576 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -543,9 +543,20 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) if (GetFabricTable().FabricCount() != 0) { #if CONFIG_NETWORK_LAYER_BLE +#ifdef CONFIG_CHIP_CONCURRENT_BLE_IDLE + // Concurrent mode with idle BLE: leave BLE stack initialized but + // do not auto-start advertising. The user can start it later (e.g. via button). + // BLE_IDLE implies CONCURRENT_MODE, so this branch must come first. + ChipLogProgress(AppServer, "Fabric already commissioned. BLE idle in concurrent mode"); +#elif defined(CONFIG_CHIP_CONCURRENT_MODE) + // Concurrent mode: keep BLE advertising enabled for Channel Sounding. + ChipLogProgress(AppServer, "Fabric already commissioned. Enabling BLE advertisement for concurrent mode"); + TEMPORARY_RETURN_IGNORED DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true); +#else // The device is already commissioned, proactively disable BLE advertisement. ChipLogProgress(AppServer, "Fabric already commissioned. Disabling BLE advertisement"); TEMPORARY_RETURN_IGNORED DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(false); +#endif #endif } else if (initParams.advertiseCommissionableIfNoFabrics) diff --git a/src/platform/telink/BLEManagerImpl.cpp b/src/platform/telink/BLEManagerImpl.cpp index 8e84961322d3..05a0c7645ee8 100644 --- a/src/platform/telink/BLEManagerImpl.cpp +++ b/src/platform/telink/BLEManagerImpl.cpp @@ -27,6 +27,10 @@ #include +#if defined(CONFIG_BT_CHANNEL_SOUNDING) +#include "CsReflector.h" +#endif + #include #include #include @@ -34,6 +38,8 @@ #include #include #include + +#include #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING #include #endif @@ -55,6 +61,7 @@ extern "C" { extern __attribute__((noinline)) int b9x_bt_blc_mac_init(uint8_t * bt_mac); #elif defined(CONFIG_BT_TLX) extern __attribute__((noinline)) int tlx_bt_blc_mac_init(uint8_t * bt_mac); +extern __attribute__((noinline)) void tlx_bt_802154_dual_mode_start(); #elif defined(CONFIG_BT_W91) extern __attribute__((noinline)) void telink_bt_blc_mac_init(uint8_t * bt_mac); #endif @@ -172,10 +179,18 @@ BLEManagerImpl BLEManagerImpl::sInstance; CHIP_ERROR BLEManagerImpl::_Init(void) { - mBLERadioInitialized = false; + mBLERadioInitialized = false; +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: mReadyToAttachThread is not used. +#else mReadyToAttachThread = false; - mconId = NULL; +#endif + mconId = NULL; +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: InternalScanCallback is not used. +#else mInternalScanCallback = new InternalScanCallback(this); +#endif mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART); @@ -185,8 +200,43 @@ CHIP_ERROR BLEManagerImpl::_Init(void) memset(mSubscribedConns, 0, sizeof(mSubscribedConns)); ReturnErrorOnFailure(InitBLEMACAddress()); + +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: BLE and Thread can coexist, init BLE stack immediately. + int err = bt_enable(NULL); + VerifyOrReturnError(err == 0, MapErrorZephyr(err)); + mBLERadioInitialized = true; + +#if defined(CONFIG_BT_CHANNEL_SOUNDING) + settings_load(); +#endif + + // Start a minimal BLE advertisement so that tlx_bt_802154_dual_mode_start() + // can successfully insert the BLE task before Thread auto-starts. + // Without this, Thread's tlx_start_radio() will block forever on + // ieee802154_task_ready_sem because tlksdk_thd_checkIsInsertTask1() returns 0. + // The real CHIPoBLE advertisement will replace this minimal one later in + // StartAdvertisingProcess(). + { + static const struct bt_data minimal_ad[] = { + BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR), + }; + const struct bt_le_adv_param params = + BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONN, BT_GAP_ADV_FAST_INT_MIN_1, BT_GAP_ADV_FAST_INT_MAX_1, NULL); + err = bt_le_adv_start(¶ms, minimal_ad, ARRAY_SIZE(minimal_ad), NULL, 0); + if (err != 0) + { + ChipLogError(DeviceLayer, "Failed to start minimal BLE advertisement: %d", err); + } + } + + tlx_bt_802154_dual_mode_start(); + +#else + // Non-concurrent mode: defer BLE init until after Thread scan. // int err = bt_enable(NULL); // Can't init BLE stack here due to abscense of non-cuncurrent mode // VerifyOrReturnError(err == 0, MapErrorZephyr(err)); +#endif memset(&mConnCallbacks, 0, sizeof(mConnCallbacks)); mConnCallbacks.connected = HandleConnect; @@ -216,6 +266,17 @@ void BLEManagerImpl::DriveBLEState(intptr_t arg) BLEMgrImpl().DriveBLEState(); } +#if defined(CONFIG_CHIP_CONCURRENT_MODE) && !defined(CONFIG_CHIP_CONCURRENT_BLE_IDLE) +void BLEManagerImpl::HandleConcurrentModeReAdv(intptr_t arg) +{ + // Runs after CommissioningWindowManager::Cleanup() has disabled BLE advertising. + // Re-enable it so that BLE (e.g. Channel Sounding) remains available alongside Thread. + ChipLogProgress(AppServer, "Fabric already commissioned. Enabling BLE advertisement for concurrent mode"); + VerifyOrReturn(BLEMgrImpl()._SetAdvertisingEnabled(true) == CHIP_NO_ERROR, + ChipLogError(DeviceLayer, "Failed to re-enable BLE advertising")); +} +#endif + void BLEManagerImpl::DriveBLEState() { CHIP_ERROR err = CHIP_NO_ERROR; @@ -339,6 +400,11 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) CHIP_ERROR err = CHIP_NO_ERROR; #if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: BLE and Thread can coexist, always allow advertising + // even when Thread is already provisioned (e.g. for Channel Sounding). + err = StartAdvertisingProcess(); +#else if (ConnectivityMgr().IsThreadProvisioned()) { ChipLogProgress(DeviceLayer, "Device provisioned, can't StartAdvertising"); @@ -347,13 +413,19 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) } else if (!mBLERadioInitialized) { + // Non-concurrent mode: scan Thread networks first, then switch radio to BLE. TEMPORARY_RETURN_IGNORED ThreadStackMgrImpl().StartThreadScan(mInternalScanCallback); } else -#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD { err = StartAdvertisingProcess(); } +#endif // CONFIG_CHIP_CONCURRENT_MODE +#else + { + err = StartAdvertisingProcess(); + } +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD return err; } @@ -364,11 +436,15 @@ CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) if (!mBLERadioInitialized) { +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: keep Thread running and share the radio with BLE. +#else #if CHIP_DEVICE_CONFIG_ENABLE_THREAD - // Deinit Thread + // Non-concurrent mode: disable Thread and block radio before enabling BLE. TEMPORARY_RETURN_IGNORED ThreadStackMgrImpl().SetThreadEnabled(false); ThreadStackMgrImpl().SetRadioBlocked(true); #endif +#endif // CONFIG_CHIP_CONCURRENT_MODE if (!BleLayer::IsInitialized()) { @@ -402,6 +478,15 @@ CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) mFlags.Set(Flags::kChipoBleGattServiceRegister); } +#if defined(CONFIG_BT_CHANNEL_SOUNDING) + // Register RAS GATT service (must be after settings load) + if (!mFlags.Has(Flags::kRasGattServiceRegistered)) + { + CsReflector::Init(); + mFlags.Set(Flags::kRasGattServiceRegistered); + } +#endif + // Initialize C3 characteristic data #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING ReturnErrorOnFailure(PrepareC3CharData()); @@ -450,14 +535,14 @@ CHIP_ERROR BLEManagerImpl::StartAdvertisingProcess(void) CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && !defined(CONFIG_CHIP_CONCURRENT_MODE) if (ConnectivityMgr().IsThreadProvisioned()) { ChipLogProgress(DeviceLayer, "Device provisioned, StopAdvertising done"); return CHIP_ERROR_INCORRECT_STATE; } -#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD && !defined(CONFIG_CHIP_CONCURRENT_MODE) ReturnErrorOnFailure(System::MapErrorZephyr(bt_le_adv_stop())); @@ -604,6 +689,17 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event) // Unref bt_conn before scheduling DriveBLEState. bt_conn_unref(connEvent->BtConn); +#if defined(CONFIG_CHIP_CONCURRENT_MODE) && defined(CONFIG_CHIP_CONCURRENT_BLE_IDLE) + // On Telink TLSR, bt_conn_unref() may trigger bt_le_adv_resume() (see + // conn.c: bt_conn_unref -> bt_le_adv_resume) which bypasses the BT_ADV_PERSIST + // and BT_ADV_ENABLED checks. In BLE idle mode, force-stop advertising to keep + // BLE idle after disconnection. + if (!mFlags.Has(Flags::kAdvertisingEnabled)) + { + bt_le_adv_stop(); + } +#endif + ChipLogProgress(DeviceLayer, "Current number of connections: %u/%u", NumConnections(), CONFIG_BT_MAX_CONN); ChipDeviceEvent disconnectEvent; @@ -755,6 +851,20 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) err = HandleBleConnectionClosed(event); break; +#if defined(CONFIG_CHIP_CONCURRENT_MODE) && !defined(CONFIG_CHIP_CONCURRENT_BLE_IDLE) + case DeviceEventType::kCommissioningComplete: + // Concurrent mode: re-enable BLE advertising after commissioning completes. + // ScheduleWork defers this until after CommissioningWindowManager::Cleanup() + // (which runs later in the application layer) has called SetBLEAdvertisingEnabled(false), + // so the re-enable is not immediately overridden. + VerifyOrReturn(PlatformMgr().ScheduleWork(HandleConcurrentModeReAdv, 0) == CHIP_NO_ERROR, + ChipLogError(DeviceLayer, "Failed to schedule BLE re-advertising")); + break; +#endif + +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: no Thread state change events are forwarded to BLE. +#else #if CHIP_DEVICE_CONFIG_ENABLE_THREAD case DeviceEventType::kThreadStateChange: err = HandleThreadStateChange(event); @@ -764,6 +874,7 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) err = HandleOperationalNetworkEnabled(event); break; #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD +#endif // CONFIG_CHIP_CONCURRENT_MODE default: break; @@ -941,6 +1052,10 @@ void BLEManagerImpl::HandleConnect(struct bt_conn * conId, uint8_t err) PlatformMgr().LockChipStack(); +#if defined(CONFIG_BT_CHANNEL_SOUNDING) + CsReflector::OnConnected(conId, err); +#endif + // Don't handle BLE connecting events when it is not related to CHIPoBLE VerifyOrExit(sInstance.mFlags.Has(Flags::kChipoBleGattServiceRegister), ); @@ -960,6 +1075,10 @@ void BLEManagerImpl::HandleDisconnect(struct bt_conn * conId, uint8_t reason) PlatformMgr().LockChipStack(); +#if defined(CONFIG_BT_CHANNEL_SOUNDING) + CsReflector::OnDisconnected(conId); +#endif + // Don't handle BLE disconnecting events when it is not related to CHIPoBLE VerifyOrExit(sInstance.mFlags.Has(Flags::kChipoBleGattServiceRegister), ); @@ -993,6 +1112,12 @@ ssize_t BLEManagerImpl::HandleC3Read(struct bt_conn * conId, const struct bt_gat CHIP_ERROR BLEManagerImpl::HandleBleConnectionClosed(const ChipDeviceEvent * event) { +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: BLE and Thread share the radio hardware. + // Do NOT call bt_disable() here, as it would tear down the shared radio + // controller and corrupt Thread's OpenThread state. + // The BLE stack remains initialized; only the connection is closed. +#else // Deinit BLE bt_disable(); mBLERadioInitialized = false; @@ -1007,6 +1132,7 @@ CHIP_ERROR BLEManagerImpl::HandleBleConnectionClosed(const ChipDeviceEvent * eve SwitchToIeee802154(); } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD +#endif // CONFIG_CHIP_CONCURRENT_MODE return CHIP_NO_ERROR; } @@ -1041,7 +1167,7 @@ ssize_t BLEManagerImpl::HandleChipIDRead(struct bt_conn * conId, const struct bt } #endif -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && !defined(CONFIG_CHIP_CONCURRENT_MODE) CHIP_ERROR BLEManagerImpl::HandleOperationalNetworkEnabled(const ChipDeviceEvent * event) { @@ -1113,13 +1239,13 @@ void BLEManagerImpl::SwitchToIeee802154(void) TEMPORARY_RETURN_IGNORED ThreadStackMgrImpl().SetThreadEnabled(true); ThreadStackMgrImpl().SetReadyToAttach(false); } -#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD && !defined(CONFIG_CHIP_CONCURRENT_MODE) } // namespace Internal } // namespace DeviceLayer } // namespace chip -#if !defined(CONFIG_ZEPHYR_VERSION_3_3) +#if !defined(CONFIG_ZEPHYR_VERSION_3_3) && !defined(CONFIG_BT_HOST_CRYPTO) // Implementation for Zephyr Bluetooth host. int bt_rand(void * buf, size_t len) { diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h index 3596e2eb633c..e76de4a9a2f1 100644 --- a/src/platform/telink/BLEManagerImpl.h +++ b/src/platform/telink/BLEManagerImpl.h @@ -39,7 +39,11 @@ namespace Internal { using namespace chip::Ble; +#ifdef CONFIG_CHIP_CONCURRENT_MODE +// Concurrent mode: InternalScanCallback is not used. +#else class InternalScanCallback; +#endif /** * Concrete implementation of the BLEManager singleton object for the Zephyr platforms. @@ -92,6 +96,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla kAdvertisingRefreshNeeded = 0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */ kChipoBleGattServiceRegister = 0x0020, /**< The system has currently CHIPoBLE GATT service registered. */ + kRasGattServiceRegistered = 0x0080, /**< The system has currently RAS GATT service registered. */ kExtendedAdvertisingEnabled = 0x0040, /**< The application has enabled extended advertising. */ }; @@ -109,7 +114,11 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla PacketBufferHandle c3CharDataBufferHandle; #endif bool mBLERadioInitialized; +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: mReadyToAttachThread is not used. +#else bool mReadyToAttachThread; +#endif bool mNeedToResetFailSafeTimer; void DriveBLEState(void); @@ -123,6 +132,10 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla CHIP_ERROR HandleTXCharComplete(const ChipDeviceEvent * event); CHIP_ERROR HandleBleConnectionClosed(const ChipDeviceEvent * event); +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: Thread stays active alongside BLE, so the + // non-concurrent workaround handlers below are not needed. +#else /* WORKAROUND: Due to abscense of non-cuncurrent mode in Matter we are emulating connection to Thread with this events and manually @@ -136,6 +149,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD InternalScanCallback * mInternalScanCallback; +#endif // CONFIG_CHIP_CONCURRENT_MODE #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING CHIP_ERROR PrepareC3CharData(void); @@ -146,6 +160,9 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla uint32_t GetAdvertisingInterval(); static void DriveBLEState(intptr_t arg); +#if defined(CONFIG_CHIP_CONCURRENT_MODE) && !defined(CONFIG_CHIP_CONCURRENT_BLE_IDLE) + static void HandleConcurrentModeReAdv(intptr_t arg); +#endif // Below callbacks run from the system workqueue context and have a limited stack capacity. static void HandleTXIndicated(bt_conn * conn, bt_gatt_indicate_params * attr, uint8_t err); @@ -179,14 +196,21 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla uint16_t offset); #endif +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: radio is shared, no explicit BLE->Thread switch needed. +#else #if CHIP_DEVICE_CONFIG_ENABLE_THREAD // Switch context from BLE to Thread void SwitchToIeee802154(void); #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD +#endif // CONFIG_CHIP_CONCURRENT_MODE CHIP_ERROR StartAdvertisingProcess(void); }; +#ifdef CONFIG_CHIP_CONCURRENT_MODE +// Concurrent mode: InternalScanCallback is not needed. +#else class InternalScanCallback : public DeviceLayer::NetworkCommissioning::ThreadDriver::ScanCallback { public: @@ -200,6 +224,7 @@ class InternalScanCallback : public DeviceLayer::NetworkCommissioning::ThreadDri private: BLEManagerImpl * mBLEManagerImpl; }; +#endif // CONFIG_CHIP_CONCURRENT_MODE /** * Returns a reference to the public interface of the BLEManager singleton object. diff --git a/src/platform/telink/BUILD.gn b/src/platform/telink/BUILD.gn index d06b69c1033e..ae7aef4229ac 100644 --- a/src/platform/telink/BUILD.gn +++ b/src/platform/telink/BUILD.gn @@ -124,6 +124,13 @@ static_library("telink") { "OTAImageProcessorImpl.h", ] } + + if (chip_enable_cs) { + sources += [ + "CsReflector.cpp", + "CsReflector.h", + ] + } } source_set("logging") { diff --git a/src/platform/telink/CsReflector.cpp b/src/platform/telink/CsReflector.cpp new file mode 100644 index 000000000000..f05b5e95bec6 --- /dev/null +++ b/src/platform/telink/CsReflector.cpp @@ -0,0 +1,699 @@ +/* + * Channel Sounding RAS Reflector for Matter (Telink). + * Adapted from samples/net/openthread/ot_ble_test/src/cs_reflector.c + * + * Copyright (c) 2026 Telink Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "CsReflector.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +using namespace chip::Logging; + +/* ── RAS Service UUIDs ─────────────────────────────────────────────── */ +#define BT_UUID_RAS_SERVICE_VAL 0x185B +#define BT_UUID_RAS_FEATURE_VAL 0x2C14 +#define BT_UUID_RAS_REAL_TIME_DATA_VAL 0x2C15 +#define BT_UUID_RAS_ON_DEMAND_DATA_VAL 0x2C16 +#define BT_UUID_RAS_CONTROL_POINT_VAL 0x2C17 +#define BT_UUID_RAS_DATA_READY_VAL 0x2C18 +#define BT_UUID_RAS_DATA_OVERWRITTEN_VAL 0x2C19 + +#define BT_UUID_RAS_SERVICE BT_UUID_DECLARE_16(BT_UUID_RAS_SERVICE_VAL) +#define BT_UUID_RAS_FEATURE BT_UUID_DECLARE_16(BT_UUID_RAS_FEATURE_VAL) +#define BT_UUID_RAS_REAL_TIME_DATA BT_UUID_DECLARE_16(BT_UUID_RAS_REAL_TIME_DATA_VAL) +#define BT_UUID_RAS_ON_DEMAND_DATA BT_UUID_DECLARE_16(BT_UUID_RAS_ON_DEMAND_DATA_VAL) +#define BT_UUID_RAS_CONTROL_POINT BT_UUID_DECLARE_16(BT_UUID_RAS_CONTROL_POINT_VAL) +#define BT_UUID_RAS_DATA_READY BT_UUID_DECLARE_16(BT_UUID_RAS_DATA_READY_VAL) +#define BT_UUID_RAS_DATA_OVERWRITTEN BT_UUID_DECLARE_16(BT_UUID_RAS_DATA_OVERWRITTEN_VAL) + +/* ── RAS GATT attribute indices ────────────────────────────────────── */ +enum : uint8_t +{ + kRasIdxSvc, + kRasIdxFeatureChar, + kRasIdxFeatureVal, + kRasIdxRtDataChar, + kRasIdxRtDataVal, + kRasIdxRtDataCcc, + kRasIdxOdDataChar, + kRasIdxOdDataVal, + kRasIdxOdDataCcc, + kRasIdxCpChar, + kRasIdxCpVal, + kRasIdxCpCcc, + kRasIdxDrChar, + kRasIdxDrVal, + kRasIdxDrCcc, + kRasIdxDoChar, + kRasIdxDoVal, + kRasIdxDoCcc, + kRasIdxMax, +}; + +/* ── Constants ─────────────────────────────────────────────────────── */ +#define CS_CONFIG_ID 0 +#define NUM_MODE_0_STEPS 1 + +#define RAS_RANGING_HEADER_LEN 4 +#define RAS_SUBEVENT_HEADER_LEN 8 +#define RAS_SEG_HEADER_LEN 1 + +#define RAS_PROCEDURE_MAX_SIZE 1000 +#define RAS_PROCEDURE_SLOTS 1 + +#define MAX_RAS_DATA_SIZE 1000 +#define RAS_CHUNK_BUF_SIZE 248 + +/* ── RAS feature bitmask (Core Spec v6.0 Vol 3B 7.3) ───────────────── */ +static uint8_t sRasFeature = (1 << 0) | (1 << 1) | (1 << 2); + +/* ── CCC enable flags ──────────────────────────────────────────────── */ +static uint16_t sRasRealtimeCcc; +static uint16_t sRasOndemandCcc; +static uint16_t sRasControlpointCcc; +static uint16_t sRasDatareadyCcc; +static uint16_t sRasDataoverwrittenCcc; + +/* ── Latest procedure counter ──────────────────────────────────────── */ +static uint16_t sLatestProcedureCounter; + +/* ── Connection ────────────────────────────────────────────────────── */ +static struct bt_conn * sConnection; + +/* ── RAS Procedure Slot ────────────────────────────────────────────── */ +struct RasProcedureSlot +{ + uint8_t data[RAS_PROCEDURE_MAX_SIZE]; + uint16_t len; + uint16_t procedureCounter; + uint8_t configId; + bool inUse; +}; + +static RasProcedureSlot sRasProcSlots[RAS_PROCEDURE_SLOTS]; +static int sRasCurrentSlot; +static uint16_t sRasCurrentProcedureCounter; +static bool sRasFirstSubevent; + +static int8_t sRasSelectedTxPower; +static uint8_t sRasSegCounter; + +/* ── RAS work queue data ───────────────────────────────────────────── */ +static uint8_t sRasWorkBuf[MAX_RAS_DATA_SIZE]; +static uint16_t sRasWorkLen; +static const struct bt_gatt_attr * sRasWorkAttr; +static struct bt_conn * sRasWorkConn; +static bool sRasWorkIsFirst; +static bool sRasWorkIsLast; +static uint8_t sRasWorkSegStart; +static volatile bool sRasSending; + +static K_WORK_DEFINE(sRasSendWork, CsReflector::RasSendWorkHandler); +static uint8_t sRasChunkBuf[RAS_CHUNK_BUF_SIZE]; + +static K_WORK_DEFINE(sCsSetDefaultSettingsWork, CsReflector::CsSetDefaultSettingsWorkHandler); + +/* ── RAS GATT service definition ───────────────────────────────────── */ +static struct bt_gatt_attr sRasAttrs[] = { + BT_GATT_PRIMARY_SERVICE(BT_UUID_RAS_SERVICE), + + BT_GATT_CHARACTERISTIC(BT_UUID_RAS_FEATURE, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, CsReflector::RasGattRead, NULL, NULL), + + BT_GATT_CHARACTERISTIC(BT_UUID_RAS_REAL_TIME_DATA, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, + CsReflector::RasGattRead, NULL, NULL), + BT_GATT_CCC(CsReflector::RasGattCccCfgChanged, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + + BT_GATT_CHARACTERISTIC(BT_UUID_RAS_ON_DEMAND_DATA, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, + CsReflector::RasGattRead, NULL, NULL), + BT_GATT_CCC(CsReflector::RasGattCccCfgChanged, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + + BT_GATT_CHARACTERISTIC(BT_UUID_RAS_CONTROL_POINT, BT_GATT_CHRC_WRITE | BT_GATT_CHRC_INDICATE, BT_GATT_PERM_WRITE, NULL, + CsReflector::RasGattCpWrite, NULL), + BT_GATT_CCC(CsReflector::RasGattCccCfgChanged, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + + BT_GATT_CHARACTERISTIC(BT_UUID_RAS_DATA_READY, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, + CsReflector::RasGattRead, NULL, NULL), + BT_GATT_CCC(CsReflector::RasGattCccCfgChanged, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + + BT_GATT_CHARACTERISTIC(BT_UUID_RAS_DATA_OVERWRITTEN, BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_NONE, NULL, NULL, NULL), + BT_GATT_CCC(CsReflector::RasGattCccCfgChanged, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), +}; + +static struct bt_gatt_service sRasService = BT_GATT_SERVICE(sRasAttrs); + +/* ── GATT callbacks ────────────────────────────────────────────────── */ +static struct bt_gatt_cb sGattCallbacks = { + .att_mtu_updated = CsReflector::MtuUpdatedCb, +}; + +/* ── Auth info callbacks ───────────────────────────────────────────── */ +static struct bt_conn_auth_info_cb sConnAuthInfoCallbacks = { + .pairing_complete = CsReflector::PairingCompleteCb, + .pairing_failed = CsReflector::PairingFailedCb, +}; + +/* ── CS connection callbacks ───────────────────────────────────────── */ +BT_CONN_CB_DEFINE(sConnCsCallbacks) = { +#if defined(CONFIG_BT_SMP) + .security_changed = CsReflector::SecurityChangedCb, +#endif + .le_cs_remote_capabilities_available = CsReflector::RemoteCapabilitiesCb, + .le_cs_config_created = CsReflector::ConfigCreatedCb, + .le_cs_subevent_data_available = CsReflector::SubeventResultCb, + .le_cs_security_enabled = CsReflector::SecurityEnabledCb, + .le_cs_procedure_enabled = CsReflector::ProcedureEnabledCb, +}; + +/* ════════════════════════════════════════════════════════════════════ + * RAS Helpers + * ════════════════════════════════════════════════════════════════════ */ + +uint8_t CsReflector::RasBuildSegHeader(bool firstSeg, bool lastSeg, uint8_t segIdx) +{ + uint8_t hdr = 0; + + if (firstSeg) + hdr |= (1 << 0); + if (lastSeg) + hdr |= (1 << 1); + hdr |= ((segIdx & 0x3F) << 2); + return hdr; +} + +void CsReflector::RasBuildRangingHeader(uint8_t * buf, uint16_t procedureCounter, uint8_t configId, int8_t txPower, + uint8_t numAntennaPaths) +{ + uint16_t word0 = (procedureCounter & 0x0FFF) | ((configId & 0x0F) << 12); + + buf[0] = static_cast(word0 >> 0); + buf[1] = static_cast(word0 >> 8); + buf[2] = static_cast(txPower); + + buf[3] = 0; + for (uint8_t i = 0; i < numAntennaPaths && i < 4; i++) + { + buf[3] |= (1 << i); + } +} + +void CsReflector::RasBuildSubeventHeader(uint8_t * buf, struct bt_conn_le_cs_subevent_result * result) +{ + buf[0] = (result->header.start_acl_conn_event >> 0) & 0xFF; + buf[1] = (result->header.start_acl_conn_event >> 8) & 0xFF; + + buf[2] = (result->header.frequency_compensation >> 0) & 0xFF; + buf[3] = (result->header.frequency_compensation >> 8) & 0xFF; + + buf[4] = ((result->header.procedure_done_status & 0x0F) << 0) | ((result->header.subevent_done_status & 0x0F) << 4); + + buf[5] = ((result->header.procedure_abort_reason & 0x0F) << 0) | ((result->header.subevent_abort_reason & 0x0F) << 4); + + buf[6] = static_cast(result->header.reference_power_level); + + buf[7] = result->header.num_steps_reported; +} + +uint16_t CsReflector::RasConvertStepData(uint8_t * buf, struct bt_conn_le_cs_subevent_result * result) +{ + struct net_buf_simple * sbuf = result->step_data_buf; + uint8_t numSteps = result->header.num_steps_reported; + bool subeventAborted = (result->header.subevent_done_status == BT_CONN_LE_CS_SUBEVENT_ABORTED); + uint8_t abortStep = result->header.abort_step; + uint8_t * wptr = buf; + uint16_t offset = 0; + + if (!sbuf || sbuf->len == 0 || numSteps == 0) + return 0; + + for (uint8_t i = 0; i < numSteps; i++) + { + bool stepAborted = subeventAborted && (i >= abortStep); + + if (offset + 3 > sbuf->len) + { + *wptr++ = 0x80; + break; + } + + uint8_t stepMode = sbuf->data[offset]; + uint8_t stepDataLen = sbuf->data[offset + 2]; + + *wptr++ = (stepMode & 0x03) | (stepAborted ? 0x80 : 0x00); + + offset += 3; + + if (!stepAborted && stepDataLen > 0) + { + if (offset + stepDataLen <= sbuf->len) + { + memcpy(wptr, &sbuf->data[offset], stepDataLen); + wptr += stepDataLen; + } + offset += stepDataLen; + } + else if (stepDataLen > 0) + { + offset += stepDataLen; + } + } + + return static_cast(wptr - buf); +} + +uint16_t CsReflector::RasBuildSubeventData(uint8_t * buf, struct bt_conn_le_cs_subevent_result * result, bool isFirst) +{ + uint8_t * wptr = buf; + + if (isFirst) + { + RasBuildRangingHeader(wptr, result->header.procedure_counter, result->header.config_id, sRasSelectedTxPower, + result->header.num_antenna_paths); + wptr += RAS_RANGING_HEADER_LEN; + } + + RasBuildSubeventHeader(wptr, result); + wptr += RAS_SUBEVENT_HEADER_LEN; + + if (result->step_data_buf && result->step_data_buf->len > 0) + { + wptr += RasConvertStepData(wptr, result); + } + + return static_cast(wptr - buf); +} + +void CsReflector::RasNotifyWithFrag(struct bt_conn * conn, const struct bt_gatt_attr * attr, const void * data, uint16_t len, + bool isProcFirst, bool isProcLast) +{ + if (sRasSending) + { + ChipLogDetail(DeviceLayer, "CS: RAS send busy, dropping data"); + return; + } + + if (len > MAX_RAS_DATA_SIZE) + { + ChipLogDetail(DeviceLayer, "CS: RAS data too large %u > %u, truncating", len, MAX_RAS_DATA_SIZE); + len = MAX_RAS_DATA_SIZE; + } + + memcpy(sRasWorkBuf, data, len); + sRasWorkLen = len; + sRasWorkAttr = attr; + sRasWorkConn = bt_conn_ref(conn); + sRasWorkIsFirst = isProcFirst; + sRasWorkIsLast = isProcLast; + sRasWorkSegStart = sRasSegCounter; + sRasSending = true; + + ChipLogDetail(DeviceLayer, "CS: RAS submit work %u bytes first=%d last=%d", len, isProcFirst, isProcLast); + + k_work_submit(&sRasSendWork); +} + +/* ════════════════════════════════════════════════════════════════════ + * Work Handlers + * ════════════════════════════════════════════════════════════════════ */ + +void CsReflector::RasSendWorkHandler(struct k_work * /*work*/) +{ + uint16_t mtu = bt_gatt_get_mtu(sRasWorkConn); + uint16_t maxPayload = (mtu > 3) ? (mtu - 3) : 20; + uint16_t offset = 0; + uint8_t segIdx = sRasWorkSegStart; + + maxPayload -= RAS_SEG_HEADER_LEN; + + while (offset < sRasWorkLen) + { + uint16_t remaining = sRasWorkLen - offset; + uint16_t chunkLen = (remaining < maxPayload) ? remaining : maxPayload; + bool firstSeg = (sRasWorkIsFirst && offset == 0); + bool lastSeg = (sRasWorkIsLast && offset + chunkLen >= sRasWorkLen); + uint8_t segHdr = RasBuildSegHeader(firstSeg, lastSeg, segIdx); + + sRasChunkBuf[0] = segHdr; + memcpy(&sRasChunkBuf[1], &sRasWorkBuf[offset], chunkLen); + + int err = bt_gatt_notify(sRasWorkConn, sRasWorkAttr, sRasChunkBuf, 1 + chunkLen); + if (err) + { + ChipLogDetail(DeviceLayer, "CS: RAS chunk fail err=%d seg=%u", err, segIdx); + break; + } + + ChipLogDetail(DeviceLayer, "CS: RAS chunk ok seg=%u first=%d last=%d off=%u len=%u", segIdx, firstSeg, lastSeg, offset, + chunkLen); + + offset += chunkLen; + segIdx = (segIdx + 1) & 0x3F; + } + + sRasSegCounter = segIdx; + ChipLogDetail(DeviceLayer, "CS: RAS send done, total=%u seg_counter=%u", sRasWorkLen, sRasSegCounter); + + bt_conn_unref(sRasWorkConn); + sRasWorkConn = nullptr; + sRasSending = false; +} + +void CsReflector::CsSetDefaultSettingsWorkHandler(struct k_work * /*work*/) +{ + const struct bt_le_cs_set_default_settings_param defaultSettings = { + .enable_initiator_role = false, + .enable_reflector_role = true, + .cs_sync_antenna_selection = BT_LE_CS_ANTENNA_SELECTION_OPT_REPETITIVE, + .max_tx_power = BT_HCI_OP_LE_CS_MAX_MAX_TX_POWER, + }; + + if (!sConnection) + { + ChipLogProgress(DeviceLayer, "CS: no connection, skip default settings"); + return; + } + + int err = bt_le_cs_set_default_settings(sConnection, &defaultSettings); + if (err) + { + ChipLogProgress(DeviceLayer, "CS: failed to configure default CS settings (err %d)", err); + } + else + { + ChipLogProgress(DeviceLayer, "CS: default settings configured (reflector role)"); + } +} + +/* ════════════════════════════════════════════════════════════════════ + * CS Subevent Result + * ════════════════════════════════════════════════════════════════════ */ + +static uint8_t sRasSubeventBuf[1000]; + +void CsReflector::SubeventResultCb(struct bt_conn * conn, struct bt_conn_le_cs_subevent_result * result) +{ + uint16_t procCounter = result->header.procedure_counter; + + ChipLogDetail(DeviceLayer, "CS: subevent proc=%u cfg=%u steps=%u AP=%u done=%u", procCounter, result->header.config_id, + result->header.num_steps_reported, result->header.num_antenna_paths, result->header.procedure_done_status); + + if (!sRasFirstSubevent || procCounter != sRasCurrentProcedureCounter) + { + sRasCurrentProcedureCounter = procCounter; + sRasFirstSubevent = true; + sRasSegCounter = 0; + + sRasCurrentSlot = -1; + for (int i = 0; i < RAS_PROCEDURE_SLOTS; i++) + { + if (!sRasProcSlots[i].inUse) + { + sRasCurrentSlot = i; + break; + } + } + if (sRasCurrentSlot < 0) + { + sRasCurrentSlot = 0; + ChipLogDetail(DeviceLayer, "CS: RAS overwriting oldest slot"); + } + + sRasProcSlots[sRasCurrentSlot].inUse = true; + sRasProcSlots[sRasCurrentSlot].len = 0; + sRasProcSlots[sRasCurrentSlot].procedureCounter = procCounter; + sRasProcSlots[sRasCurrentSlot].configId = result->header.config_id; + + ChipLogDetail(DeviceLayer, "CS: RAS new procedure %u, slot %d", procCounter, sRasCurrentSlot); + } + + bool isFirst = sRasFirstSubevent; + sRasFirstSubevent = false; + + uint16_t subeventLen = RasBuildSubeventData(sRasSubeventBuf, result, isFirst); + + if (sRasCurrentSlot >= 0) + { + RasProcedureSlot * slot = &sRasProcSlots[sRasCurrentSlot]; + uint16_t newLen = slot->len + subeventLen; + + if (newLen <= RAS_PROCEDURE_MAX_SIZE) + { + memcpy(&slot->data[slot->len], sRasSubeventBuf, subeventLen); + slot->len = newLen; + } + else + { + ChipLogDetail(DeviceLayer, "CS: RAS slot %d overflow, dropping subevent", sRasCurrentSlot); + } + } + + if (sRasRealtimeCcc & BT_GATT_CCC_NOTIFY) + { + bool isProcLast = (result->header.procedure_done_status == BT_CONN_LE_CS_PROCEDURE_COMPLETE); + + RasNotifyWithFrag(conn, &sRasAttrs[kRasIdxRtDataVal], sRasSubeventBuf, subeventLen, isFirst, isProcLast); + } + + sLatestProcedureCounter = procCounter; + + if (result->header.procedure_done_status == BT_CONN_LE_CS_PROCEDURE_COMPLETE) + { + ChipLogProgress(DeviceLayer, "CS: RAS procedure %u complete, %u bytes in slot %d", procCounter, + sRasProcSlots[sRasCurrentSlot].len, sRasCurrentSlot); + + if (sRasDatareadyCcc & BT_GATT_CCC_NOTIFY) + { + uint8_t drData[2]; + sys_put_le16(sLatestProcedureCounter & 0x0FFF, drData); + bt_gatt_notify(conn, &sRasAttrs[kRasIdxDrVal], drData, sizeof(drData)); + ChipLogDetail(DeviceLayer, "CS: RAS notified Data Ready procedure=%u", sLatestProcedureCounter); + } + } +} + +/* ════════════════════════════════════════════════════════════════════ + * RAS GATT Callbacks + * ════════════════════════════════════════════════════════════════════ */ + +ssize_t CsReflector::RasGattRead(struct bt_conn * conn, const struct bt_gatt_attr * attr, void * buf, uint16_t len, uint16_t offset) +{ + if (attr == &sRasAttrs[kRasIdxFeatureVal]) + { + return bt_gatt_attr_read(conn, attr, buf, len, offset, &sRasFeature, sizeof(sRasFeature)); + } + ChipLogDetail(DeviceLayer, "CS: RAS GATT read: handle 0x%x len=%u offset=%u", attr->handle, len, offset); + return 0; +} + +void CsReflector::RasGattCccCfgChanged(const struct bt_gatt_attr * attr, uint16_t value) +{ + ChipLogDetail(DeviceLayer, "CS: RAS CCC changed: handle 0x%x val=0x%04x", attr->handle, value); + + if (attr == &sRasAttrs[kRasIdxRtDataCcc]) + sRasRealtimeCcc = value; + else if (attr == &sRasAttrs[kRasIdxOdDataCcc]) + sRasOndemandCcc = value; + else if (attr == &sRasAttrs[kRasIdxCpCcc]) + sRasControlpointCcc = value; + else if (attr == &sRasAttrs[kRasIdxDrCcc]) + sRasDatareadyCcc = value; + else if (attr == &sRasAttrs[kRasIdxDoCcc]) + sRasDataoverwrittenCcc = value; +} + +ssize_t CsReflector::RasGattCpWrite(struct bt_conn * conn, const struct bt_gatt_attr * attr, const void * buf, uint16_t len, + uint16_t offset, uint8_t flags) +{ + const uint8_t * data = static_cast(buf); + uint8_t opcode = data[0]; + static uint8_t cpRsp[3]; + + ChipLogDetail(DeviceLayer, "CS: RAS Control Point: opcode=0x%02x len=%u", opcode, len); + + switch (opcode) + { + case 0x01: + ChipLogDetail(DeviceLayer, "CS: => Set RAS Configuration"); + break; + case 0x02: + ChipLogDetail(DeviceLayer, "CS: => RAS Control Point Command"); + break; + case 0x03: + ChipLogDetail(DeviceLayer, "CS: => Get Procedure Data"); + break; + case 0x04: + ChipLogDetail(DeviceLayer, "CS: => Abort RAS Procedure"); + break; + default: + ChipLogDetail(DeviceLayer, "CS: => Unknown opcode"); + break; + } + + if (sRasControlpointCcc & BT_GATT_CCC_INDICATE) + { + static struct bt_gatt_indicate_params indParams; + + cpRsp[0] = opcode; + cpRsp[1] = 0x00; /* success */ + cpRsp[2] = 0x00; + + indParams.attr = const_cast(attr); + indParams.data = cpRsp; + indParams.len = sizeof(cpRsp); + indParams.func = nullptr; + indParams.destroy = nullptr; + + bt_gatt_indicate(conn, &indParams); + ChipLogDetail(DeviceLayer, "CS: => Indication sent"); + } + return len; +} + +/* ════════════════════════════════════════════════════════════════════ + * CS Connection Callbacks + * ════════════════════════════════════════════════════════════════════ */ + +void CsReflector::SecurityChangedCb(struct bt_conn * conn, bt_security_t level, enum bt_security_err err) +{ + if (err) + { + ChipLogProgress(DeviceLayer, "CS: security failed: level %u err %d", level, err); + return; + } + ChipLogProgress(DeviceLayer, "CS: security changed: level %u", level); +} + +void CsReflector::RemoteCapabilitiesCb(struct bt_conn * conn, struct bt_conn_le_cs_capabilities * params) +{ + (void) params; + ChipLogProgress(DeviceLayer, "CS: capability exchange completed"); +} + +void CsReflector::ConfigCreatedCb(struct bt_conn * conn, struct bt_conn_le_cs_config * config) +{ + ChipLogProgress(DeviceLayer, "CS: config creation complete. ID: %d", config->id); +} + +void CsReflector::SecurityEnabledCb(struct bt_conn * conn) +{ + ChipLogProgress(DeviceLayer, "CS: security enabled"); + k_work_submit(&sCsSetDefaultSettingsWork); +} + +void CsReflector::ProcedureEnabledCb(struct bt_conn * conn, struct bt_conn_le_cs_procedure_enable_complete * params) +{ + ChipLogProgress(DeviceLayer, "CS: procedures %s, selected_tx_power=%d dBm", params->state ? "enabled" : "disabled", + params->selected_tx_power); + + if (params->selected_tx_power != 0x7F) + sRasSelectedTxPower = params->selected_tx_power; + else + sRasSelectedTxPower = 0; +} + +/* ════════════════════════════════════════════════════════════════════ + * Auth Info Callbacks + * ════════════════════════════════════════════════════════════════════ */ + +void CsReflector::PairingCompleteCb(struct bt_conn * conn, bool bonded) +{ + ChipLogProgress(DeviceLayer, "CS: pairing complete: %s", bonded ? "bonded" : "not bonded"); +} + +void CsReflector::PairingFailedCb(struct bt_conn * conn, enum bt_security_err reason) +{ + ChipLogProgress(DeviceLayer, "CS: pairing failed: reason %d", reason); +} + +/* ════════════════════════════════════════════════════════════════════ + * GATT / MTU Callbacks + * ════════════════════════════════════════════════════════════════════ */ + +void CsReflector::MtuExchangeCb(struct bt_conn * conn, uint8_t err, struct bt_gatt_exchange_params * params) +{ + ChipLogProgress(DeviceLayer, "CS: MTU exchange %s (%u)", err == 0U ? "success" : "failed", bt_gatt_get_mtu(conn)); +} + +void CsReflector::MtuUpdatedCb(struct bt_conn * conn, uint16_t tx, uint16_t rx) +{ + ChipLogProgress(DeviceLayer, "CS: MTU updated: TX=%u RX=%u", tx, rx); +} + +/* ════════════════════════════════════════════════════════════════════ + * Public API + * ════════════════════════════════════════════════════════════════════ */ + +void CsReflector::Init(void) +{ + ChipLogProgress(DeviceLayer, "CS: RAS Reflector init"); + + bt_conn_auth_info_cb_register(&sConnAuthInfoCallbacks); + bt_gatt_cb_register(&sGattCallbacks); + + int err = bt_gatt_service_register(&sRasService); + if (err) + { + ChipLogError(DeviceLayer, "CS: RAS service register failed (err %d)", err); + return; + } + ChipLogProgress(DeviceLayer, "CS: RAS service registered"); +} + +void CsReflector::OnConnected(struct bt_conn * conn, uint8_t err) +{ + if (err) + return; + + if (sConnection) + { + bt_conn_unref(sConnection); + sConnection = nullptr; + } + + sConnection = bt_conn_ref(conn); + + static struct bt_gatt_exchange_params mtuExchangeParams; + mtuExchangeParams.func = MtuExchangeCb; + int mtuErr = bt_gatt_exchange_mtu(sConnection, &mtuExchangeParams); + if (mtuErr) + { + ChipLogProgress(DeviceLayer, "CS: MTU exchange failed (err %d)", mtuErr); + } + + /* int secErr = bt_conn_set_security(sConnection, BT_SECURITY_L2); + if (secErr) + { + ChipLogProgress(DeviceLayer, "CS: failed to request security (err %d)", secErr); + } */ +} + +void CsReflector::OnDisconnected(struct bt_conn * conn) +{ + if (sConnection) + { + bt_conn_unref(sConnection); + sConnection = nullptr; + } + sRasFirstSubevent = false; + sRasSending = false; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/telink/CsReflector.h b/src/platform/telink/CsReflector.h new file mode 100644 index 000000000000..9afa40855501 --- /dev/null +++ b/src/platform/telink/CsReflector.h @@ -0,0 +1,71 @@ +/* + * Channel Sounding RAS Reflector for Matter (Telink). + * Adapted from samples/net/openthread/ot_ble_test/src/cs_reflector.c + * + * Copyright (c) 2026 Telink Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +/** + * Channel Sounding RAS (Ranging Service) Reflector. + * + * Provides Bluetooth 5.4/6.0 Channel Sounding distance measurement + * capabilities via the standard RAS GATT service (UUID 0x185B). + * + * Usage: + * CsReflector::Init(); // once at boot + * CsReflector::OnConnected(conn, err); // on each BLE connection + * CsReflector::OnDisconnected(conn); // on each BLE disconnection + */ +class CsReflector +{ +public: + static void Init(void); + static void OnConnected(struct bt_conn * conn, uint8_t err); + static void OnDisconnected(struct bt_conn * conn); + + /* ── Callbacks exposed for C callback structs ───────────────── */ + static ssize_t RasGattRead(struct bt_conn * conn, const struct bt_gatt_attr * attr, void * buf, uint16_t len, uint16_t offset); + static void RasGattCccCfgChanged(const struct bt_gatt_attr * attr, uint16_t value); + static ssize_t RasGattCpWrite(struct bt_conn * conn, const struct bt_gatt_attr * attr, const void * buf, uint16_t len, + uint16_t offset, uint8_t flags); + static void SecurityChangedCb(struct bt_conn * conn, bt_security_t level, enum bt_security_err err); + static void RemoteCapabilitiesCb(struct bt_conn * conn, struct bt_conn_le_cs_capabilities * params); + static void ConfigCreatedCb(struct bt_conn * conn, struct bt_conn_le_cs_config * config); + static void SecurityEnabledCb(struct bt_conn * conn); + static void ProcedureEnabledCb(struct bt_conn * conn, struct bt_conn_le_cs_procedure_enable_complete * params); + static void SubeventResultCb(struct bt_conn * conn, struct bt_conn_le_cs_subevent_result * result); + static void PairingCompleteCb(struct bt_conn * conn, bool bonded); + static void PairingFailedCb(struct bt_conn * conn, enum bt_security_err reason); + static void MtuExchangeCb(struct bt_conn * conn, uint8_t err, struct bt_gatt_exchange_params * params); + static void MtuUpdatedCb(struct bt_conn * conn, uint16_t tx, uint16_t rx); + static void RasSendWorkHandler(struct k_work * work); + static void CsSetDefaultSettingsWorkHandler(struct k_work * work); + +private: + /* ── RAS helpers ────────────────────────────────────────────── */ + static uint8_t RasBuildSegHeader(bool firstSeg, bool lastSeg, uint8_t segIdx); + static void RasBuildRangingHeader(uint8_t * buf, uint16_t procedureCounter, uint8_t configId, int8_t txPower, + uint8_t numAntennaPaths); + static void RasBuildSubeventHeader(uint8_t * buf, struct bt_conn_le_cs_subevent_result * result); + static uint16_t RasConvertStepData(uint8_t * buf, struct bt_conn_le_cs_subevent_result * result); + static uint16_t RasBuildSubeventData(uint8_t * buf, struct bt_conn_le_cs_subevent_result * result, bool isFirst); + static void RasNotifyWithFrag(struct bt_conn * conn, const struct bt_gatt_attr * attr, const void * data, uint16_t len, + bool isProcFirst, bool isProcLast); +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/telink/ThreadStackManagerImpl.cpp b/src/platform/telink/ThreadStackManagerImpl.cpp index 509bc044a11f..5b87b1e98802 100644 --- a/src/platform/telink/ThreadStackManagerImpl.cpp +++ b/src/platform/telink/ThreadStackManagerImpl.cpp @@ -41,8 +41,12 @@ ThreadStackManagerImpl ThreadStackManagerImpl::sInstance; CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack() { - mRadioBlocked = false; - mReadyToAttach = false; +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: mRadioBlocked / mReadyToAttach are not used. +#else + mRadioBlocked = false; + mReadyToAttach = false; +#endif otInstance * const instance = openthread_get_default_instance(); ReturnErrorOnFailure(GenericThreadStackManagerImpl_OpenThread::DoInit(instance)); @@ -114,6 +118,10 @@ ThreadStackManagerImpl::_AttachToThreadNetwork(const Thread::OperationalDataset return result; } +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: Thread is always available, attach directly. + result = Internal::GenericThreadStackManagerImpl_OpenThread::_AttachToThreadNetwork(dataset, callback); +#else if (mRadioBlocked || mReadyToAttach) { /* On Telink platform it's not possible to rise Thread network when its used by BLE, @@ -133,6 +141,7 @@ ThreadStackManagerImpl::_AttachToThreadNetwork(const Thread::OperationalDataset result = Internal::GenericThreadStackManagerImpl_OpenThread::_AttachToThreadNetwork(dataset, callback); } +#endif // CONFIG_CHIP_CONCURRENT_MODE return result; } @@ -140,6 +149,10 @@ CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(NetworkCommissioning::Thread { mpScanCallback = callback; +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: Thread is always available, perform real OT scan directly. + return Internal::GenericThreadStackManagerImpl_OpenThread::_StartThreadScan(mpScanCallback); +#else /* On Telink platform it's not possible to rise Thread network when its used by BLE, so Thread networks scanning performed before start BLE and also available after switch into Thread */ if (mRadioBlocked) @@ -158,6 +171,7 @@ CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(NetworkCommissioning::Thread } return CHIP_NO_ERROR; +#endif // CONFIG_CHIP_CONCURRENT_MODE } void ThreadStackManagerImpl::Finalize(void) diff --git a/src/platform/telink/ThreadStackManagerImpl.h b/src/platform/telink/ThreadStackManagerImpl.h index 983a2df24524..3653230b090f 100644 --- a/src/platform/telink/ThreadStackManagerImpl.h +++ b/src/platform/telink/ThreadStackManagerImpl.h @@ -59,9 +59,13 @@ class ThreadStackManagerImpl final : public ThreadStackManager, public: // ===== Methods that implement the ThreadStackManager abstract interface. CHIP_ERROR _InitThreadStack(); +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: radio stays unblocked; these setters are not needed. +#else void SetRadioBlocked(bool state) { mRadioBlocked = state; } void SetReadyToAttach(bool state) { mReadyToAttach = state; } bool IsReadyToAttach(void) const { return mReadyToAttach; } +#endif void Finalize(void); CHIP_ERROR CommitConfiguration(void); @@ -94,9 +98,13 @@ class ThreadStackManagerImpl final : public ThreadStackManager, static ThreadStackManagerImpl sInstance; +#ifdef CONFIG_CHIP_CONCURRENT_MODE + // Concurrent mode: radio blocking state is not tracked. +#else // ===== Private members for use by this class only. bool mRadioBlocked; bool mReadyToAttach; +#endif #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT k_sem mSrpClearAllSemaphore; diff --git a/src/platform/telink/args.gni b/src/platform/telink/args.gni index 23d446dd82bc..51db1a6b4fce 100644 --- a/src/platform/telink/args.gni +++ b/src/platform/telink/args.gni @@ -15,4 +15,7 @@ declare_args() { # Enable factory data support chip_enable_factory_data = false + + # Enable Channel Sounding (RAS Reflector) + chip_enable_cs = false } From 3ba0d7ed132fd4d1b5a4c0fed5d86d53e97009a3 Mon Sep 17 00:00:00 2001 From: wuhaoTelink Date: Mon, 10 Aug 2026 08:10:34 +0800 Subject: [PATCH 24/31] [telink] Update v1.2.0 release notes with latest build data, add TL521X and concurrent/CS targets (#21) * docs(telink): update release notes for v1.2.0-alpha, clean up legacy platforms - Update TL323X/TL721X resource usage tables with latest build data - Add TL521X 4M flash dual-mode lighting-app data - Add concurrent mode and concurrent+CS targets for TL323X/TL721X - Remove legacy platforms (B91/B92/W91/TL321X) from all docs - Rename build_and_update_matter_notes.py to generate_and_update_matter_notes.py - Update README.md, README_BUILD_SCRIPT.md and release notes accordingly - Restyled by prettier-markdown - Restyled by ruff - Restyled by isort - fix py scripts - update fetch ble sdk --------- Signed-off-by: Hao Wu Co-authored-by: Restyled.io --- README.md | 41 +- .../telink/releases/README_BUILD_SCRIPT.md | 50 +- .../generate_and_update_matter_notes.py | 607 ++++++++++++++++++ .../telink/releases/telink_release_notes.md | 228 +++---- ..._release_notes_tl_v1.2.0-alpha-v1.5.1.0.md | 306 +++++++++ 5 files changed, 1078 insertions(+), 154 deletions(-) create mode 100755 docs/platforms/telink/releases/generate_and_update_matter_notes.py create mode 100644 docs/platforms/telink/releases/telink_release_notes_tl_v1.2.0-alpha-v1.5.1.0.md diff --git a/README.md b/README.md index e83e60cd494f..a8208dd8c89a 100644 --- a/README.md +++ b/README.md @@ -117,19 +117,14 @@ the high-level steps are: [Matter Developer Guide](https://doc.telink-semi.cn/doc/en/software/res/sdk/matter/telink_matter_developer_guide_en/) for the exact `west` commands. -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. - -5. **Get the Telink Matter SDK (this repo)** — clone the `dev-tlk_v1.5` branch +4. **Get the Telink Matter SDK (this repo)** — clone the `dev-tlk_v1.5` branch of this repository next to the Zephyr SDK. -6. **Point the Matter SDK at the Zephyr SDK** — export `TELINK_ZEPHYR_BASE` so +5. **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. -7. **Bootstrap & activate the Matter build environment** — run the Matter +6. **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. @@ -148,10 +143,12 @@ MB flash, Software Version 2 for DFU/OTA images, etc.). Refer to the board README for the app + board combination you want to build: -#### Lighting App (TL3238X / TL7218X) +#### Lighting App (TL3238X / TL521X / TL7218X) - TL3238X: [`examples/lighting-app/telink/boards/tl3238x_README.md`](examples/lighting-app/telink/boards/tl3238x_README.md) +- TL5218X: + [`examples/lighting-app/telink/boards/tl5218x_README.md`](examples/lighting-app/telink/boards/tl5218x_README.md) - TL7218X: [`examples/lighting-app/telink/boards/tl7218x_README.md`](examples/lighting-app/telink/boards/tl7218x_README.md) @@ -162,11 +159,20 @@ Refer to the board README for the app + board combination you want to build: - TL7218X Retention: [`examples/light-switch-app/telink/boards/tl7218x_retention_README.md`](examples/light-switch-app/telink/boards/tl7218x_retention_README.md) +#### Concurrent Mode (TL3238X / TL7218X) + +- TL3238X BLE + Thread Concurrent: + [`examples/lighting-app/telink/boards/tl3238x_concurrent_README.md`](examples/lighting-app/telink/boards/tl3238x_concurrent_README.md) +- TL7218X BLE + Thread Concurrent: + [`examples/lighting-app/telink/boards/tl7218x_concurrent_README.md`](examples/lighting-app/telink/boards/tl7218x_concurrent_README.md) +- TL7218X BLE + Thread Concurrent + Channel Sounding: + [`examples/lighting-app/telink/boards/tl7218x_concurrent_cs_README.md`](examples/lighting-app/telink/boards/tl7218x_concurrent_cs_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. +> `*_README.md` files also cover dual-mode (Matter + Zigbee), BLE + Thread +> concurrent mode, Channel Sounding (CS), and 4 MB flash configurations. ### Flashing Firmware @@ -178,14 +184,11 @@ our ## 📱 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 | +| Board | Chip Family | Series | Status | +| ------- | ----------- | ------ | -------------------- | +| tl3238x | TL323X | - | Telink Zephyr HAL_V2 | +| tl5218x | TL521X | - | Telink Zephyr HAL_V2 | +| tl7218x | TL721X | - | Telink Zephyr HAL_V2 | --- diff --git a/docs/platforms/telink/releases/README_BUILD_SCRIPT.md b/docs/platforms/telink/releases/README_BUILD_SCRIPT.md index 4659ebe19238..cfeff8c8f3e6 100644 --- a/docs/platforms/telink/releases/README_BUILD_SCRIPT.md +++ b/docs/platforms/telink/releases/README_BUILD_SCRIPT.md @@ -2,7 +2,7 @@ ## Overview -The script `docs/platforms/telink/releases/build_and_update_matter_notes.py` +The script `docs/platforms/telink/releases/generate_and_update_matter_notes.py` can: 1. Build all Telink board Matter sample applications (using `build_examples.py`) @@ -16,7 +16,7 @@ can: ## Files -- `docs/platforms/telink/releases/build_and_update_matter_notes.py` - main +- `docs/platforms/telink/releases/generate_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 @@ -51,7 +51,7 @@ source ./scripts/activate.sh -p all,telink ```bash cd /home/ubuntu/zephyrproject/connectedhomeip -python3 docs/platforms/telink/releases/build_and_update_matter_notes.py +python3 docs/platforms/telink/releases/generate_and_update_matter_notes.py ``` This will: @@ -97,31 +97,18 @@ Each board's zip archive contains: ## Supported boards -1. tlsr9518adk80d (TLSR951X/B91) -2. tlsr9528a (TLSR952X/B92) -3. tlsr9118bdk40d (TLSR911X/W91) -4. tl3218x (TL321X) -5. tl3238x (TL323X) -6. tl7218x (TL721X) +1. tl3238x (TL323X) +2. tl5218x (TL521X) +3. 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 | +| Application | Description | +| ---------------- | ------------------------------------------------------------------------- | +| lighting-app | Lighting application (supports OTA, Factory Data, LZMA, Shell, Dual-Mode) | +| light-switch-app | Light switch application (supports OTA, LZMA, Factory Data, Retention) | +| bridge-app | Bridge application | +| window-app | Window covering application | ## Script features @@ -170,10 +157,18 @@ 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-tl3238x-light-ota-compress-lzma-factory-data-dual-mode` - TL3238X + lighting application with OTA, LZMA, Factory Data, BLE + Thread concurrent + mode - `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 +- `telink-tl7218x-light-ota-compress-lzma-factory-data-dual-mode` - TL7218X + lighting application with OTA, LZMA, Factory Data, BLE + Thread concurrent + mode +- `telink-tl5218x-light-ota-factory-data-4mb` - TL521X lighting application + with OTA, Factory Data, 4MB Flash +- `telink-tl5218x-light-ota-factory-data-4mb` - TL521X lighting application + with OTA, Factory Data, 4MB Flash, Dual-Mode Available options: @@ -186,3 +181,4 @@ Available options: - `4mb` - 4MB Flash - `log-progress` - reduce log output (progress and errors only) - `nfc-payload` - NFC Payload support +- `dual-mode` - enable BLE + Thread concurrent mode (TL323X, TL721X) diff --git a/docs/platforms/telink/releases/generate_and_update_matter_notes.py b/docs/platforms/telink/releases/generate_and_update_matter_notes.py new file mode 100755 index 000000000000..7b67f41f1a02 --- /dev/null +++ b/docs/platforms/telink/releases/generate_and_update_matter_notes.py @@ -0,0 +1,607 @@ +#!/usr/bin/env python3 +# +# 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. +# + +""" +Telink Matter SDK - Generate and Release Notes Update Script + +This script: + 1. Builds all Telink Matter examples for supported boards using build_examples.py + 2. Captures build logs and extracts memory usage information (RAM/ROM) + 3. Updates the Release Note working copy + (docs/platforms/telink/releases/telink_release_notes.md) in-place, + using table format for the Resource Usage section + 4. Collects firmware files (zephyr.bin/.elf/.hex, .config, zephyr.dts) and + creates per-board zip archives + +Usage (run from the connectedhomeip repo root): + python3 docs/platforms/telink/releases/generate_and_update_matter_notes.py # full run + python3 docs/platforms/telink/releases/generate_and_update_matter_notes.py --skip-build # skip building + python3 docs/platforms/telink/releases/generate_and_update_matter_notes.py --skip-firmware # skip firmware packaging +""" + +import re +import shutil +import subprocess +from pathlib import Path +from typing import Dict, List, Optional, Tuple + + +class TelinkMatterBuildManager: + """Manages building Telink Matter examples and generating release notes.""" + + def __init__(self, repo_root: Optional[Path] = None): + # This script lives in docs/platforms/telink/releases/. Detect the repo + # root by walking up from the script's location looking for the `.git` + # marker, so the script works regardless of where it is invoked from. + if repo_root is not None: + self.repo_root = repo_root + else: + candidate = Path(__file__).resolve().parent + while candidate != candidate.parent: + if (candidate / ".git").exists(): + break + candidate = candidate.parent + self.repo_root = candidate + + # Output directories + self.release_dir = self.repo_root / "build_for_release" + self.release_dir.mkdir(exist_ok=True) + + self.build_logs_dir = self.release_dir / "build_logs" + self.build_logs_dir.mkdir(exist_ok=True) + + self.firmware_output_dir = self.release_dir / "firmware" + self.firmware_output_dir.mkdir(exist_ok=True) + + # Release Note working copy (read and write in-place; only the + # Resource Usage section is regenerated, the rest is hand-maintained). + # The working copy lives next to this script in + # docs/platforms/telink/releases/. A versioned snapshot + # (telink_release_notes_.md) is produced by + # scripts/tools/telink/package_telink_firmware.sh at release time. + self.output_path = Path(__file__).resolve().parent / "telink_release_notes.md" + + # Board family mapping (board -> chip family) + self.board_family = { + "tlsr9518adk80d": "TLSR951X", + "tlsr9528a": "TLSR952X", + "tlsr9528a_retention": "TLSR952X", + "tlsr9118bdk40d": "TLSR911X", + "tl3218x": "TL321X", + "tl3218x_ml3m": "TL321X", + "tl3218x_retention": "TL321X", + "tl3238x": "TL323X", + "tl3238x_retention": "TL323X", + "tl7218x": "TL721X", + "tl7218x_retention": "TL721X", + } + + # Display order for boards in the release note + self.board_order = [ + ("tlsr9518adk80d", "TLSR951X/B91"), + ("tlsr9528a", "TLSR952X/B92"), + ("tl3218x", "TL321X"), + ("tl3238x", "TL323X"), + ("tl7218x", "TL721X"), + ("tlsr9118bdk40d", "TLSR911X/W91"), + ] + + # Define all build targets (board, app, target_string) + # target_string is the full build_examples.py target (without the 'telink-' prefix) + self.build_targets = self._get_build_targets() + + def _get_build_targets(self) -> List[Tuple[str, str, str]]: + """Define all Matter build targets for Telink platforms. + + Returns a list of (board, app_name, target_suffix) tuples where: + - board: the board identifier (without 'telink-' prefix) + - app_name: human-readable app name for display + - target_suffix: the full target string passed to build_examples.py + (e.g. 'tl3238x-light-ota-factory-data-4mb') + """ + targets = [] + + # -------------------------- TL323X -------------------------- + targets.extend([ + ("tl3238x", "lighting-app", "tl3238x-light-ota-factory-data-4mb"), + ("tl3238x_retention", "light-switch-app", "tl3238x_retention-light-switch-ota-compress-lzma-factory-data"), + ]) + + # -------------------------- TL721X -------------------------- + targets.extend([ + ("tl7218x", "lighting-app", "tl7218x-light-ota-compress-lzma-shell-factory-data"), + ("tl7218x", "bridge-app", "tl7218x-bridge"), + ("tl7218x", "window-app", "tl7218x-window-covering"), + ("tl7218x_retention", "light-switch-app", "tl7218x_retention-light-switch-ota-compress-lzma-factory-data"), + ]) + + # -------------------------- TLSR952X/B92 -------------------------- + targets.extend([ + ("tlsr9528a", "air-quality-sensor-app", "tlsr9528a_retention-air-quality-sensor"), + ("tlsr9528a", "all-clusters-minimal-app", "tlsr9528a-all-clusters-minimal-nfc-payload"), + ("tlsr9528a", "contact-sensor-app", "tlsr9528a_retention-contact-sensor"), + ("tlsr9528a", "light-switch-app", "tlsr9528a-light-switch-ota-compress-lzma-shell-factory-data"), + ("tlsr9528a", "lock-app", "tlsr9528a-lock-dfu-smp"), + ("tlsr9528a", "smoke-co-alarm-app", "tlsr9528a_retention-smoke-co-alarm"), + ]) + + # -------------------------- TLSR911X/W91 -------------------------- + targets.extend([ + ("tlsr9118bdk40d", "lighting-app", "tlsr9118bdk40d-light-ota-factory-data-log-progress"), + ("tlsr9118bdk40d", "all-clusters-app", "tlsr9118bdk40d-all-clusters"), + ("tlsr9118bdk40d", "thermostat", "tlsr9118bdk40d-thermostat"), + ]) + + # -------------------------- TLSR951X/B91 -------------------------- + targets.extend([ + ("tlsr9518adk80d", "lighting-app", "tlsr9518adk80d-light-ota-rpc-factory-data-4mb"), + ("tlsr9518adk80d", "pump-controller-app", "tlsr9518adk80d-pump-controller"), + ("tlsr9518adk80d", "shell", "tlsr9518adk80d-shell"), + ]) + + # -------------------------- TL321X -------------------------- + targets.extend([ + ("tl3218x", "lighting-app", "tl3218x-light-ota-compress-lzma-shell-factory-data"), + ("tl3218x", "ota-requestor-app", "tl3218x-ota-requestor"), + ("tl3218x_retention", "light-switch-app", "tl3218x_retention-light-switch-ota-factory-data"), + ]) + + return targets + + def build_all(self): + """Build all Telink Matter examples using build_examples.py.""" + print("=" * 80) + print("Building all Telink Matter examples...") + print("=" * 80) + print() + + success_count = 0 + fail_count = 0 + + for board, app_name, target_suffix in self.build_targets: + full_target = f"telink-{target_suffix}" + # build_examples.py outputs to out/ + log_filename = f"build_{target_suffix}.log" + log_file = self.build_logs_dir / log_filename + + print(f" Building {full_target}...") + print(f" App: {app_name} Board: {board}") + + # The build is run via scripts/build/build_examples.py + cmd = [ + "./scripts/build/build_examples.py", + "--target", full_target, + "build", + ] + + print(f" Command: {' '.join(cmd)}") + + # Run inside the build environment wrapper if available + run_in_build_env = self.repo_root / "scripts" / "run_in_build_env.sh" + if run_in_build_env.exists(): + cmd = [str(run_in_build_env), " ".join(cmd)] + + result = subprocess.run( + cmd, + capture_output=True, + text=True, + cwd=str(self.repo_root), + check=False, + ) + + # Write log file + with open(log_file, "w", encoding="utf-8") as f: + f.write(f"Target: {full_target}\n") + f.write(f"Board: {board}\n") + f.write(f"App: {app_name}\n\n") + f.write(f"Command: {' '.join(cmd)}\n\n") + f.write(f"STDOUT:\n{result.stdout}\n\n") + f.write(f"STDERR:\n{result.stderr}\n\n") + f.write(f"Return code: {result.returncode}\n") + + if result.returncode == 0: + print(f" Success! Log written to {log_file}") + success_count += 1 + else: + print(f" Failed! Log written to {log_file}") + fail_count += 1 + + print() + + print("=" * 80) + print(f"Build complete! {success_count} succeeded, {fail_count} failed.") + print("=" * 80) + + def extract_memory_info(self) -> Dict[str, Dict[str, List[Dict]]]: + """Extract memory usage information from build logs. + + Returns a nested dict: {family: {board: [{name, memory: [{name,used,size,percent}]}}]} + """ + data: Dict[str, Dict[str, List[Dict]]] = {} + + print() + print("=" * 80) + print("Extracting memory usage information from logs...") + print("=" * 80) + print() + + for log_file in self.build_logs_dir.glob("build_*.log"): + filename = log_file.name + # filename: build_.log + target_suffix = filename[len("build_"):-len(".log")] + + # Identify the board from the target suffix + board = None + app_name = None + for b in sorted(self.board_family.keys(), key=lambda x: -len(x)): + if target_suffix.startswith(b): + board = b + rest = target_suffix[len(b):] + if rest.startswith("-"): + rest = rest[1:] + # The app name is the segment up to the next '-