Skip to content

Commit c7d6bd6

Browse files
committed
[Telink] Zephyr 3.3 backward compatibility support
1 parent c125901 commit c7d6bd6

22 files changed

+1422
-20
lines changed

.github/workflows/examples-telink.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
steps:
4747
- name: Checkout
4848
uses: actions/checkout@v4
49-
5049
- name: Checkout submodules & Bootstrap
5150
uses: ./.github/actions/checkout-submodules-and-bootstrap
5251
with:

config/telink/app/bootloader.conf

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ CONFIG_BOOT_SWAP_USING_SCRATCH=n
2929
# With disabled option the only image magic is validated
3030
CONFIG_BOOT_VALIDATE_SLOT0=y
3131

32+
# Required for Zephyr 3.3 and replased with CONFIG_BOOT_MAX_IMG_SECTORS_AUTO in new versions
33+
# Maximum number of image sectors supported by the bootloader.
34+
# Maximum signed image size: 512 * 4096 = 2M Bytes
35+
CONFIG_BOOT_MAX_IMG_SECTORS=512
36+
3237
# MCUBOOT log levels are:
3338
# - OFF, LOG_LEVEL_ERR_OFF
3439
# - ERROR, LOG_LEVEL_ERR

config/telink/app/bootloader_compress_lzma.conf

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ CONFIG_BOOT_UPGRADE_ONLY=y
2222
# With disabled option the only image magic is validated
2323
CONFIG_BOOT_VALIDATE_SLOT0=y
2424

25+
# Required for Zephyr 3.3 and replased with CONFIG_BOOT_MAX_IMG_SECTORS_AUTO in new versions
26+
# Maximum number of image sectors supported by the bootloader.
27+
# Maximum signed image size: 512 * 4096 = 2M Bytes
28+
CONFIG_BOOT_MAX_IMG_SECTORS=512
29+
2530
# MCUBOOT log levels are:
2631
# - OFF, LOG_LEVEL_ERR_OFF
2732
# - ERROR, LOG_LEVEL_ERR
@@ -38,3 +43,5 @@ CONFIG_SIZE_OPTIMIZATIONS=y
3843

3944
# Enable support LZMA compression
4045
CONFIG_COMPRESS_LZMA=y
46+
47+
CONFIG_PICOLIBC=y

config/telink/chip-module/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ endif()
5656
matter_add_flags(-DNL_ASSERT_USE_FLAGS_DEFAULT=1)
5757

5858
zephyr_include_directories(${CHIP_ROOT}/src/platform/telink/)
59+
zephyr_include_directories(${CHIP_ROOT}/src/platform/telink/wifi/${ZEPHYR_VERSION_STRING})
5960

6061
zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C)
6162
matter_add_cflags("${ZEPHYR_CFLAGS_C}")

config/telink/chip-module/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ config BOOTLOADER_MCUBOOT
4545
bool
4646
select IMG_MANAGER
4747
select STREAM_FLASH
48+
select STREAM_FLASH_ERASE
4849
select TELINK_W91_N22_MATTER_OTA_LAYOUT if BOARD_TLSR9118BDK40D || BOARD_TLSR9118BDK40D_V1
4950

5051
config CHIP_OTA_REQUESTOR_BUFFER_SIZE

config/telink/chip-module/Kconfig.defaults

+28-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ config CHIP_PROJECT_CONFIG
2424
string "Project configuration file for Matter"
2525
default "include/CHIPProjectConfig.h"
2626

27+
config ZEPHYR_VERSION_3_3
28+
bool "Using Zephyr version 3.3"
29+
default n
30+
2731
config LOG
2832
default y
2933

@@ -63,7 +67,7 @@ config POSIX_MAX_FDS
6367
# Application stack size
6468
config MAIN_STACK_SIZE
6569
default 3240 if PM || SOC_RISCV_TELINK_TL321X
66-
default 4608 if SOC_RISCV_TELINK_W91
70+
default 4608 if SOC_RISCV_TELINK_W91 && !ZEPHYR_VERSION_3_3
6771
default 4096
6872

6973
config INIT_STACKS
@@ -81,11 +85,12 @@ config SYSTEM_WORKQUEUE_STACK_SIZE
8185
default 616 if PM
8286

8387
config HEAP_MEM_POOL_SIZE
88+
default 256 if ZEPHYR_VERSION_3_3
8489
default 1280
8590

8691
config COMMON_LIBC_MALLOC_ARENA_SIZE
87-
default 20716 if SOC_SERIES_RISCV_TELINK_B9X_RETENTION
88-
default 16384 if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_TL721X
92+
default 20716 if SOC_SERIES_RISCV_TELINK_B9X_RETENTION || (SOC_RISCV_TELINK_TL321X && ZEPHYR_VERSION_3_3)
93+
default 16384 if SOC_RISCV_TELINK_TL721X || (SOC_RISCV_TELINK_TL321X && !ZEPHYR_VERSION_3_3)
8994
default 12288
9095

9196
config NET_IPV6_MLD
@@ -173,6 +178,7 @@ config BT_DEVICE_NAME_GATT_WRITABLE
173178
if SOC_RISCV_TELINK_B9X || SOC_RISCV_TELINK_TLX
174179

175180
config TL_BLE_CTRL_THREAD_STACK_SIZE
181+
default 648 if ZEPHYR_VERSION_3_3
176182
default 680
177183

178184
config TL_BLE_CTRL_MASTER_MAX_NUM
@@ -188,7 +194,6 @@ config TL_BLE_CTRL_RF_POWER
188194

189195
choice TL_BLE_CTRL_MAC_TYPE
190196
default TL_BLE_CTRL_MAC_TYPE_RANDOM_STATIC
191-
192197
endchoice
193198

194199
endif # SOC_RISCV_TELINK_B9X || SOC_RISCV_TELINK_TLX
@@ -405,10 +410,14 @@ config CHIP_WIFI_CONNECTION_RECOVERY_JITTER
405410
within range [-JITTER; +JITTER].
406411

407412
config NET_MGMT_EVENT_STACK_SIZE
413+
default 1128 if ZEPHYR_VERSION_3_3
408414
default 1250
409415

416+
if !ZEPHYR_VERSION_3_3
410417
config IPC_SERVICE_BACKEND_ICMSG_WQ_STACK_SIZE
418+
int "Size of RX work queue stack"
411419
default 2304 if TELINK_W91_IPC_DISPATCHER
420+
endif
412421

413422
endif # CHIP_WIFI
414423

@@ -423,9 +432,6 @@ config CHIP_ENABLE_PAIRING_AUTOSTART
423432
config MBEDTLS
424433
default y
425434

426-
config MBEDTLS_ENTROPY_POLL_ZEPHYR
427-
default y
428-
429435
config MBEDTLS_CIPHER_AES_ENABLED
430436
default y
431437

@@ -447,18 +453,29 @@ config MBEDTLS_ECDH_C
447453
config MBEDTLS_ECDSA_C
448454
default y
449455

450-
config MBEDTLS_HKDF_C
456+
config MBEDTLS_PKCS5_C
451457
default y
452458

453-
config MBEDTLS_PKCS5_C
459+
config MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
454460
default y
455461

456-
config MBEDTLS_X509_CSR_WRITE_C
462+
if !ZEPHYR_VERSION_3_3
463+
config MBEDTLS_ENTROPY_POLL_ZEPHYR
464+
bool "Provide entropy data to Mbed TLS through entropy driver or random generator"
457465
default y
458466

459-
config MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
467+
config MBEDTLS_HKDF_C
468+
bool "HMAC-based Extract-and-Expand Key Derivation Function"
460469
default y
461470

471+
config MBEDTLS_X509_CSR_WRITE_C
472+
bool "X.509 Certificate Signing Requests writing"
473+
default y
474+
endif # !ZEPHYR_VERSION_3_3
475+
476+
config GETOPT_LONG
477+
default y if ZEPHYR_VERSION_3_3
478+
462479
# Disable not used shell modules
463480

464481
config SHELL_WILDCARD

examples/platform/telink/common.cmake

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Generate Zephyr version files for backward compatibility
17+
file(STRINGS "$ENV{ZEPHYR_BASE}/VERSION" ZEPHYR_VERSION_STRING REGEX "[0-9]+")
18+
string(REGEX REPLACE "[^0-9;]" "" ZEPHYR_VERSION_STRING "${ZEPHYR_VERSION_STRING}")
19+
string(REPLACE ";" "." ZEPHYR_VERSION_STRING "${ZEPHYR_VERSION_STRING}")
20+
file(WRITE "${CMAKE_BINARY_DIR}/modules/chip-module/zephyr_version.gni" "ZEPHYR_VERSION_STRING = \"${ZEPHYR_VERSION_STRING}\"\n")
21+
if(${ZEPHYR_VERSION_STRING} MATCHES "^3\\.3")
22+
set(ZEPHYR_VERSION_OVERLAY_FILE "${CMAKE_BINARY_DIR}/zephyr_version.conf")
23+
file(WRITE ${ZEPHYR_VERSION_OVERLAY_FILE} "CONFIG_ZEPHYR_VERSION_3_3=y\n")
24+
25+
# Add required MbedTLS defines for Zephyr 3.3
26+
add_definitions(-DMBEDTLS_HKDF_C -DMBEDTLS_X509_CREATE_C -DMBEDTLS_X509_CSR_WRITE_C)
27+
endif()
28+
1629
string(REPLACE "_retention" "" BASE_BOARD ${BOARD})
1730
string(REGEX REPLACE "_v[0-9]+" "" BASE_BOARD ${BASE_BOARD})
1831

@@ -117,7 +130,7 @@ else()
117130
endif()
118131

119132
if(NOT CONF_FILE)
120-
set(CONF_FILE ${USB_CONF_OVERLAY_FILE} ${MARS_CONF_OVERLAY_FILE} prj.conf)
133+
set(CONF_FILE ${USB_CONF_OVERLAY_FILE} ${MARS_CONF_OVERLAY_FILE} ${ZEPHYR_VERSION_OVERLAY_FILE} prj.conf)
121134
endif()
122135

123136
# Load NCS/Zephyr build system

src/platform/Zephyr/InetUtils.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include <platform/ConfigurationManager.h>
19+
1820
#include "InetUtils.h"
1921

2022
#include <zephyr/net/net_if.h>
@@ -38,10 +40,18 @@ net_if * GetInterface(Inet::InterfaceId ifaceId)
3840
return ifaceId.IsPresent() ? net_if_get_by_index(ifaceId.GetPlatformInterface()) : net_if_get_default();
3941
}
4042

43+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
4144
net_if * GetWiFiInterface()
4245
{
46+
// TODO: Remove dependency after Telink Zephyr 3.3 support is removed
47+
// net_if_get_first_wifi() is not available in Zephyr 3.3
48+
#if defined(CONFIG_SOC_RISCV_TELINK_W91) && defined(CONFIG_ZEPHYR_VERSION_3_3)
49+
return GetInterface();
50+
#else
4351
return net_if_get_first_wifi();
52+
#endif
4453
}
54+
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
4555

4656
} // namespace InetUtils
4757
} // namespace DeviceLayer

src/platform/telink/BLEManagerImpl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
#include <zephyr/bluetooth/addr.h>
4141
#include <zephyr/bluetooth/gatt.h>
4242
#include <zephyr/drivers/flash.h>
43+
#if defined(CONFIG_ZEPHYR_VERSION_3_3)
44+
#include <zephyr/random/rand32.h>
45+
#else
4346
#include <zephyr/random/random.h>
47+
#endif
4448
#include <zephyr/storage/flash_map.h>
4549
#include <zephyr/sys/byteorder.h>
4650
#include <zephyr/sys/util.h>

src/platform/telink/BUILD.gn

+5-4
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,15 @@ static_library("telink") {
9696
}
9797

9898
if (chip_enable_wifi) {
99+
import("$root_build_dir/zephyr_version.gni")
99100
sources += [
100101
"OTAImageProcessorImplWiFi.h",
101-
"wifi/ConnectivityManagerImplWiFi.cpp",
102+
"wifi/" + ZEPHYR_VERSION_STRING + "/ConnectivityManagerImplWiFi.cpp",
102103
"wifi/ConnectivityManagerImplWiFi.h",
103-
"wifi/TelinkWiFiDriver.cpp",
104+
"wifi/" + ZEPHYR_VERSION_STRING + "/TelinkWiFiDriver.cpp",
104105
"wifi/TelinkWiFiDriver.h",
105-
"wifi/WiFiManager.cpp",
106-
"wifi/WiFiManager.h",
106+
"wifi/" + ZEPHYR_VERSION_STRING + "/WiFiManager.cpp",
107+
"wifi/" + ZEPHYR_VERSION_STRING + "/WiFiManager.h",
107108
]
108109
}
109110

src/platform/telink/ConnectivityManagerImpl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ CHIP_ERROR JoinLeaveMulticastGroup(net_if * iface, const Inet::IPAddress & addre
7777

7878
if (maddr && !net_if_ipv6_maddr_is_joined(maddr))
7979
{
80+
#if defined(CONFIG_ZEPHYR_VERSION_3_3)
81+
net_if_ipv6_maddr_join(maddr);
82+
#else
8083
net_if_ipv6_maddr_join(iface, maddr);
84+
#endif
8185
}
8286
}
8387
else if (operation == UDPEndPointImplSockets::MulticastOperation::kLeave)

src/platform/telink/FactoryDataParser.c

+4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ static inline bool uint16_decode(zcbor_state_t * states, uint16_t * value)
4343
bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData * factoryData)
4444
{
4545
memset(factoryData, 0, sizeof(*factoryData));
46+
#if defined(CONFIG_ZEPHYR_VERSION_3_3)
47+
ZCBOR_STATE_D(states, MAX_FACTORY_DATA_NESTING_LEVEL, buffer, bufferSize, 1);
48+
#else
4649
ZCBOR_STATE_D(states, MAX_FACTORY_DATA_NESTING_LEVEL, buffer, bufferSize, 1, 0);
50+
#endif
4751

4852
bool res = zcbor_map_start_decode(states);
4953
struct zcbor_string currentString;

src/platform/telink/SystemPlatformConfig.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct ChipDeviceEvent;
5555
#define CHIP_SYSTEM_CONFIG_USE_SOCKETS 1
5656

5757
// Reduce packet buffer pool size (default 15) to reduce ram consumption
58-
#if defined CONFIG_PM || defined CONFIG_SOC_RISCV_TELINK_TL321X
58+
#if defined(CONFIG_PM) || defined(CONFIG_SOC_RISCV_TELINK_TL321X)
5959
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 0
6060
#else
6161
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8
@@ -64,4 +64,6 @@ struct ChipDeviceEvent;
6464
// ========== Platform-specific Configuration Overrides =========
6565

6666
// Disable Zephyr Socket extensions module, as the Zephyr RTOS now implements recvmsg()
67+
#if !defined(CONFIG_ZEPHYR_VERSION_3_3)
6768
#define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKET_EXTENSIONS 0
69+
#endif

0 commit comments

Comments
 (0)