From b8d4c4ae92435f07dd26f70b36207c72492a1955 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Thu, 5 Jan 2023 00:46:03 +0800 Subject: [PATCH 1/8] [Bouffalolab] Refactor Bouffalolab SDK gn scripts (#24132) * create bl_iot_sdk.gni * update bl_iot_sdk.gni * remove more 702 specific-name * update bl602 * update bl602 & bl702 * update toolchain path * fix issues for bl602 * fix parition table for bl702 * fix restyle --- build_overrides/bouffalolab_iot_sdk.gni | 6 +- .../bouffalolab/args.gni | 12 +- .../bouffalolab}/toolchain/BUILD.gn | 0 .../toolchain/riscv_toolchain.gni | 0 .../build_overrides/bouffalolab_iot_sdk.gni | 9 +- .../lighting-app/bouffalolab/bl602/BUILD.gn | 12 +- .../bouffalolab/bl602/CHIPProjectConfig.h | 2 + .../lighting-app/bouffalolab/bl602/args.gni | 2 +- .../lighting-app/bouffalolab/bl702/BUILD.gn | 9 +- .../lighting-app/bouffalolab/bl702/args.gni | 2 +- .../bouffalolab/common/AppTask.cpp | 3 +- examples/platform/bouffalolab/bl602/BUILD.gn | 2 +- .../bouffalolab/bl602/FreeRTOSConfig.h | 188 ++-- .../bl602/route_hook/bl_route_hook.c | 1 + examples/platform/bouffalolab/bl702/BUILD.gn | 2 +- .../platform/bouffalolab/common/plat/main.cpp | 3 +- scripts/build/builders/bouffalolab.py | 3 +- scripts/examples/gn_bouffalolab_example.sh | 2 +- src/lwip/BUILD.gn | 10 +- .../bouffalolab/BL602/BL602Config.cpp | 61 +- .../bouffalolab/BL602/CHIPMem-Platform.cpp | 2 +- .../BL602/ConfigurationManagerImpl.cpp | 4 +- .../BL602/ConfigurationManagerImpl.h | 1 - .../BL602/ConnectivityManagerImpl.cpp | 6 +- .../BL602/DiagnosticDataProviderImpl.cpp | 8 +- .../BL602/KeyValueStoreManagerImpl.cpp | 4 +- src/platform/bouffalolab/BL602/Logging.cpp | 10 +- .../BL602/NetworkCommissioningDriver.cpp | 11 +- .../BL602/NetworkCommissioningDriver.h | 2 +- .../BL602/NetworkCommissioningWiFiDriver.cpp | 2 +- .../bouffalolab/BL602/PlatformManagerImpl.cpp | 14 +- .../bouffalolab/BL602/PlatformManagerImpl.h | 10 +- src/platform/bouffalolab/BL602/args.gni | 4 +- .../bouffalolab/BL602/wifi_mgmr_portable.c | 14 +- src/platform/bouffalolab/BL702/BUILD.gn | 6 +- src/platform/bouffalolab/BL702/Logging.cpp | 11 +- .../BL702/ThreadStackManagerImpl.cpp | 64 +- src/platform/bouffalolab/BL702/args.gni | 7 +- .../bouffalolab/BL702/bl702Config.cpp | 1 - third_party/bouffalolab/bl602/BUILD.gn | 12 +- third_party/bouffalolab/bl602/bl602_board.gni | 30 - third_party/bouffalolab/bl602/bl602_sdk.gni | 636 ------------- third_party/bouffalolab/bl602/bl_iot_sdk.gni | 889 ++++++++++++++++++ third_party/bouffalolab/bl702/BUILD.gn | 12 +- .../bouffalolab/bl702/bl702_executable.gni | 72 -- third_party/bouffalolab/bl702/bl702_sdk.gni | 821 ---------------- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 826 ++++++++++++++++ .../bouffalolab_board.gni} | 9 +- .../bouffalolab_executable.gni} | 22 +- .../bl602_riscv.gni => common/rsicv.gni} | 2 - third_party/bouffalolab/repo | 2 +- 51 files changed, 1991 insertions(+), 1852 deletions(-) rename third_party/bouffalolab/bl702/bl702_riscv.gni => config/bouffalolab/args.gni (68%) rename {examples/platform/bouffalolab/common => config/bouffalolab}/toolchain/BUILD.gn (100%) rename {examples/platform/bouffalolab/common => config/bouffalolab}/toolchain/riscv_toolchain.gni (100%) delete mode 100644 third_party/bouffalolab/bl602/bl602_board.gni delete mode 100644 third_party/bouffalolab/bl602/bl602_sdk.gni create mode 100644 third_party/bouffalolab/bl602/bl_iot_sdk.gni delete mode 100644 third_party/bouffalolab/bl702/bl702_executable.gni delete mode 100644 third_party/bouffalolab/bl702/bl702_sdk.gni create mode 100644 third_party/bouffalolab/bl702/bl_iot_sdk.gni rename third_party/bouffalolab/{bl702/bl702_board.gni => common/bouffalolab_board.gni} (78%) rename third_party/bouffalolab/{bl602/bl602_executable.gni => common/bouffalolab_executable.gni} (81%) rename third_party/bouffalolab/{bl602/bl602_riscv.gni => common/rsicv.gni} (96%) diff --git a/build_overrides/bouffalolab_iot_sdk.gni b/build_overrides/bouffalolab_iot_sdk.gni index 77ab3440927271..2a87174c734d84 100644 --- a/build_overrides/bouffalolab_iot_sdk.gni +++ b/build_overrides/bouffalolab_iot_sdk.gni @@ -13,11 +13,7 @@ # limitations under the License. declare_args() { - # Root directory for bl602 SDK build files. - bl602_sdk_build_root = "//third_party/bouffalolab/bl602" - - # Root directory for bl702 SDK build files. - bl702_sdk_build_root = "//third_party/bouffalolab/bl702" + bouffalolab_iot_sdk_build_root = "//third_party/bouffalolab/" bouffalolab_sdk_root = "/opt/bouffalolab_sdk" } diff --git a/third_party/bouffalolab/bl702/bl702_riscv.gni b/config/bouffalolab/args.gni similarity index 68% rename from third_party/bouffalolab/bl702/bl702_riscv.gni rename to config/bouffalolab/args.gni index 2c525322f81cf8..a85d0ea655d0b4 100644 --- a/third_party/bouffalolab/bl702/bl702_riscv.gni +++ b/config/bouffalolab/args.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Project CHIP Authors +# Copyright (c) 2022 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. @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("bl702_board.gni") +# Options from standalone-chip.mk that differ from configure defaults. These +# options are used from examples/. -riscv_arch = "rv32imfc" -riscv_abi = "ilp32f" -# riscv_cpu = "" -# riscv_float_abi = "hard" -# riscv_fpu = "" +custom_toolchain = + "//third_party/connectedhomeip/config/bouffalolab/toolchain:riscv_gcc" diff --git a/examples/platform/bouffalolab/common/toolchain/BUILD.gn b/config/bouffalolab/toolchain/BUILD.gn similarity index 100% rename from examples/platform/bouffalolab/common/toolchain/BUILD.gn rename to config/bouffalolab/toolchain/BUILD.gn diff --git a/examples/platform/bouffalolab/common/toolchain/riscv_toolchain.gni b/config/bouffalolab/toolchain/riscv_toolchain.gni similarity index 100% rename from examples/platform/bouffalolab/common/toolchain/riscv_toolchain.gni rename to config/bouffalolab/toolchain/riscv_toolchain.gni diff --git a/examples/build_overrides/bouffalolab_iot_sdk.gni b/examples/build_overrides/bouffalolab_iot_sdk.gni index 1eb018a7ef2c85..d66989f09abd37 100644 --- a/examples/build_overrides/bouffalolab_iot_sdk.gni +++ b/examples/build_overrides/bouffalolab_iot_sdk.gni @@ -13,13 +13,8 @@ # limitations under the License. declare_args() { - # Root directory for bl602 SDK build files. - bl602_sdk_build_root = - "//third_party/connectedhomeip/third_party/bouffalolab/bl602" - - # Root directory for bl702 SDK build files. - bl702_sdk_build_root = - "//third_party/connectedhomeip/third_party/bouffalolab/bl702" + bouffalolab_iot_sdk_build_root = + "//third_party/connectedhomeip/third_party/bouffalolab" bouffalolab_sdk_root = "/opt/bouffalolab_sdk" } diff --git a/examples/lighting-app/bouffalolab/bl602/BUILD.gn b/examples/lighting-app/bouffalolab/bl602/BUILD.gn index 369b732b02f49b..0b341d50c32675 100644 --- a/examples/lighting-app/bouffalolab/bl602/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl602/BUILD.gn @@ -16,8 +16,8 @@ import("//build_overrides/bouffalolab_iot_sdk.gni") import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -import("${bl602_sdk_build_root}/bl602_executable.gni") -import("${bl602_sdk_build_root}/bl602_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/bl602/bl_iot_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/common/bouffalolab_executable.gni") import("${build_root}/config/defaults.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -51,7 +51,7 @@ declare_args() { baudrate = 2000000 } -bl602_sdk("sdk") { +bl_iot_sdk("sdk") { include_dirs = [ "${chip_root}/src/platform/bouffalolab/BL602", "${example_dir}", @@ -66,6 +66,7 @@ bl602_sdk("sdk") { "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", "OTA_PERIODIC_QUERY_TIMEOUT=${ota_periodic_query_timeout}", "CHIP_UART_BAUDRATE=${baudrate}", + "SYS_AOS_LOOP_ENABLE", ] if (chip_enable_pw_rpc) { @@ -77,7 +78,7 @@ bl602_sdk("sdk") { } } -bl602_executable("lighting_app") { +bouffalolab_executable("lighting_app") { output_name = "chip-bl602-lighting-example.out" defines = [ @@ -85,8 +86,10 @@ bl602_executable("lighting_app") { "CHIP_UART_BAUDRATE=${baudrate}", "BL602_ENABLE", "START_ENTRY=bfl_main", + "SYS_AOS_LOOP_ENABLE", ] + bl_plat_name = "bl602" sources = [ "${examples_plat_dir}/route_hook/bl_route_hook.c", "${examples_plat_dir}/route_hook/bl_route_table.c", @@ -195,6 +198,7 @@ bl602_executable("lighting_app") { sources += [ "${examples_plat_common_dir}/plat/OTAConfig.cpp" ] } + cflags_c = [ "-Wno-sign-compare" ] ldscript = "${examples_plat_dir}/ldscripts/flash_rom.ld" ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ] diff --git a/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h index 22befede6a48c4..9e9934c227c465 100644 --- a/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h @@ -144,3 +144,5 @@ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 + +#define CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE 128 diff --git a/examples/lighting-app/bouffalolab/bl602/args.gni b/examples/lighting-app/bouffalolab/bl602/args.gni index 464b0c63ff827c..1a7e2dd427e021 100644 --- a/examples/lighting-app/bouffalolab/bl602/args.gni +++ b/examples/lighting-app/bouffalolab/bl602/args.gni @@ -17,7 +17,7 @@ import("//build_overrides/pigweed.gni") import("${chip_root}/config/standalone/args.gni") import("${chip_root}/src/platform/bouffalolab/BL602/args.gni") -bl602_sdk_target = get_label_info(":sdk", "label_no_toolchain") +bl_iot_sdk_target = get_label_info(":sdk", "label_no_toolchain") pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" diff --git a/examples/lighting-app/bouffalolab/bl702/BUILD.gn b/examples/lighting-app/bouffalolab/bl702/BUILD.gn index 5872505775bd15..65822676f89e04 100644 --- a/examples/lighting-app/bouffalolab/bl702/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702/BUILD.gn @@ -16,8 +16,8 @@ import("//build_overrides/bouffalolab_iot_sdk.gni") import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -import("${bl702_sdk_build_root}/bl702_executable.gni") -import("${bl702_sdk_build_root}/bl702_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/bl702/bl_iot_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/common/bouffalolab_executable.gni") import("${build_root}/config/defaults.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") @@ -54,7 +54,7 @@ declare_args() { baudrate = 2000000 } -bl702_sdk("sdk") { +bl_iot_sdk("sdk") { include_dirs = [ "${example_dir}", "${example_common_dir}", @@ -88,8 +88,9 @@ bl702_sdk("sdk") { } } -bl702_executable("lighting_app") { +bouffalolab_executable("lighting_app") { output_name = "chip-bl702-lighting-example.out" + bl_plat_name = "bl702" defines = [ "APP_TASK_STACK_SIZE=2044", diff --git a/examples/lighting-app/bouffalolab/bl702/args.gni b/examples/lighting-app/bouffalolab/bl702/args.gni index ecfb7424c6d2e6..c76c3d0f267d17 100644 --- a/examples/lighting-app/bouffalolab/bl702/args.gni +++ b/examples/lighting-app/bouffalolab/bl702/args.gni @@ -17,7 +17,7 @@ import("//build_overrides/pigweed.gni") import("${chip_root}/config/standalone/args.gni") import("${chip_root}/src/platform/bouffalolab/BL702/args.gni") -bl702_sdk_target = get_label_info(":sdk", "label_no_toolchain") +bl_iot_sdk_target = get_label_info(":sdk", "label_no_toolchain") pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" diff --git a/examples/lighting-app/bouffalolab/common/AppTask.cpp b/examples/lighting-app/bouffalolab/common/AppTask.cpp index cae6be58e7dd75..2fe2a403357717 100644 --- a/examples/lighting-app/bouffalolab/common/AppTask.cpp +++ b/examples/lighting-app/bouffalolab/common/AppTask.cpp @@ -417,7 +417,8 @@ void AppTask::ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg) #if CHIP_DEVICE_CONFIG_ENABLE_WIFI case DeviceEventType::kWiFiConnectivityChange: - ChipLogProgress(NotSpecified, "Wi-Fi state changed\r\n", ConnectivityMgr().IsWiFiStationConnected()); + ChipLogProgress(NotSpecified, "Wi-Fi state changed to %s.\r\n", + ConnectivityMgr().IsWiFiStationConnected() ? "connected" : "disconnected"); chip::app::DnssdServer::Instance().StartServer(); NetworkCommissioning::BLWiFiDriver::GetInstance().SaveConfiguration(); diff --git a/examples/platform/bouffalolab/bl602/BUILD.gn b/examples/platform/bouffalolab/bl602/BUILD.gn index d6ca0038a370ee..8e85778ebd1f57 100644 --- a/examples/platform/bouffalolab/bl602/BUILD.gn +++ b/examples/platform/bouffalolab/bl602/BUILD.gn @@ -15,7 +15,7 @@ import("//build_overrides/bouffalolab_iot_sdk.gni") import("//build_overrides/chip.gni") -import("${bl602_sdk_build_root}/bl602_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/bl602/bl_iot_sdk.gni") config("chip_examples_project_config") { include_dirs = [ "project_include" ] diff --git a/examples/platform/bouffalolab/bl602/FreeRTOSConfig.h b/examples/platform/bouffalolab/bl602/FreeRTOSConfig.h index 7d8553139871bb..96379643d791e3 100644 --- a/examples/platform/bouffalolab/bl602/FreeRTOSConfig.h +++ b/examples/platform/bouffalolab/bl602/FreeRTOSConfig.h @@ -97,11 +97,8 @@ 1 tab == 4 spaces! */ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H #include "platform.h" #include @@ -118,116 +115,101 @@ extern "C" { * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -/* Tickless mode is not used. */ - -/* Some of the standard demo test tasks assume a tick rate of 1KHz, even -though that is faster than would normally be warranted by a real -application. */ -#define configTICK_RATE_HZ (1000) - -/* The full demo always has tasks to run so the tick will never be turned -off. The blinky demo will use the default tickless idle implementation to -turn the tick off. */ -#define configUSE_TICKLESS_IDLE (0) +#define configSUPPORT_STATIC_ALLOCATION 1 -/* Hook function related definitions. */ -#define configUSE_TICK_HOOK (0) -#define configCHECK_FOR_STACK_OVERFLOW (2) -#define configUSE_MALLOC_FAILED_HOOK (1) -#define configUSE_IDLE_HOOK (0) - -#define configENERGY_MODE (sleepEM1) - -/* Main functions*/ -/* Run time stats gathering related definitions. */ -#define configGENERATE_RUN_TIME_STATS (0) - -/* Co-routine related definitions. */ -#define configUSE_CO_ROUTINES (0) +#define configCLINT_BASE_ADDRESS CLINT_CTRL_ADDR +#define configCLIC_TIMER_ENABLE_ADDRESS (0x02800407) +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 1 +#define configUSE_TICK_HOOK 0 +#ifndef configUSE_TICKLESS_IDLE +// Maybe Compile flags is passed by command line +#define configUSE_TICKLESS_IDLE 1 +#endif +#define configCPU_CLOCK_HZ (10 * 1000 * 1000) /*QEMU*/ +#define configTICK_RATE_HZ ((TickType_t) 1000) +#define configMAX_PRIORITIES (32) +/* Creating idle task */ +/* -1 -> prvInitialiseNewTask: (subtract 1 to get top of stack) pxTopOfStack = &( pxNewTCB->pxStack[ ulStackDepth - ( uint32_t ) 1 + * ] ); */ +/* -1 -> prvInitialiseNewTask: (subtract 1 in case not matching 8 bytes alignment) pxTopOfStack = ( StackType_t * ) ( ( ( + * portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); */ +/* Running idle task */ +/* -12 -> prvIdleTask: addi sp, sp, -48 */ +/* -16 -> prvIdleTask.xTaskResumeAll: addi sp, sp, -64 */ +/* Here comes an interrupt after prvIdleTask.xTaskResumeAll.vTaskExitCritical */ +/* -30 -> freertos_risc_v_trap_handler: addi sp, sp, -portCONTEXT_SIZE */ +/* -34 -> portasmSAVE_ADDITIONAL_REGISTERS: addi sp, sp, -(portasmADDITIONAL_CONTEXT_SIZE * portWORD_SIZE) */ +/* Checking for stack overflow */ +/* 4 -> taskCHECK_FOR_STACK_OVERFLOW: if( ( pulStack[ 0 ] != ulCheckValue ) || ( pulStack[ 1 ] != ulCheckValue ) || ( pulStack[ 2 + * ] != ulCheckValue ) || ( pulStack[ 3 ] != ulCheckValue ) ) */ +#define configMINIMAL_STACK_SIZE ((unsigned short) 114) /* SIZE-1-1-12-16-30-34>=4 */ +#define configTOTAL_HEAP_SIZE ((size_t) 14100) +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 2 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 1 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 #define configMAX_CO_ROUTINE_PRIORITIES (2) -/* Software timer related definitions. */ -#define configUSE_TIMERS (1) -#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) /* Highest priority */ -#define configTIMER_QUEUE_LENGTH (4) +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) +#define configTIMER_QUEUE_LENGTH 4 #define configTIMER_TASK_STACK_DEPTH (400) -/* Cortex-M specific definitions. */ -#ifdef __NVIC_PRIO_BITS -/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ -#define configPRIO_BITS (__NVIC_PRIO_BITS) -#else -#define configPRIO_BITS 3 /* 7 priority levels */ +/* Task priorities. Allow these to be overridden. */ +#ifndef uartPRIMARY_PRIORITY +#define uartPRIMARY_PRIORITY (configMAX_PRIORITIES - 3) #endif -/* The lowest interrupt priority that can be used in a call to a "set priority" -function. */ -#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY (0x07) - -/* The highest interrupt priority that can be used by any interrupt service -routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL -INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER -PRIORITY THAN THIS! (higher priorities are lower numeric values. */ -#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY (0x03) - -/* Interrupt priorities used by the kernel port layer itself. These are generic -to all Cortex-M ports, and do not rely on any particular library functions. */ -#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) -/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! -See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ -#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) - -/* FreeRTOS MPU specific definitions. */ -#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS (0) - -#define configCPU_CLOCK_HZ (10 * 1000 * 1000) -#define configUSE_PREEMPTION (1) -#define configUSE_TIME_SLICING (1) -#define configUSE_PORT_OPTIMISED_TASK_SELECTION (1) -#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG (1) /* See into vPortSuppressTicksAndSleep source code for explanation */ -#define configMAX_PRIORITIES (32) -#define configMINIMAL_STACK_SIZE ((unsigned short) 112) /* Number of words to use for Idle and Timer stacks */ -#define configMAX_TASK_NAME_LEN (16) -#define configUSE_16_BIT_TICKS (0) -#define configIDLE_SHOULD_YIELD (1) -#define configUSE_MUTEXES (1) -#define configUSE_RECURSIVE_MUTEXES (1) -#define configUSE_COUNTING_SEMAPHORES (1) -#define configQUEUE_REGISTRY_SIZE (8) -// #define configUSE_QUEUE_SETS (0) -// #define configUSE_NEWLIB_REENTRANT (0) -#define configENABLE_BACKWARD_COMPATIBILITY (1) -#define configSUPPORT_STATIC_ALLOCATION (1) - /* Optional functions - most linkers will remove unused functions anyway. */ -#define INCLUDE_vTaskPrioritySet (1) -#define INCLUDE_uxTaskPriorityGet (1) -#define INCLUDE_vTaskDelete (1) -#define INCLUDE_vTaskSuspend (1) -// #define INCLUDE_xResumeFromISR (1) -#define INCLUDE_vTaskDelayUntil (1) -#define INCLUDE_vTaskDelay (1) -#define INCLUDE_xTaskGetSchedulerState (0) -#define INCLUDE_xTaskGetCurrentTaskHandle (0) -#define INCLUDE_uxTaskGetStackHighWaterMark (1) -#define INCLUDE_xTaskGetIdleTaskHandle (0) -// #define INCLUDE_xTimerGetTimerDaemonTaskHandle (1) -// #define INCLUDE_pcTaskGetTaskName (1) -#define INCLUDE_eTaskGetState (1) -// #define INCLUDE_xEventGroupSetBitFromISR (1) -#define INCLUDE_xTimerPendFunctionCall (1) - +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 + +/* Overwrite some of the stack sizes allocated to various test and demo tasks. +Like all task stack sizes, the value is the number of words, not bytes. */ +#define bktBLOCK_TIME_TASK_STACK_SIZE 100 +#define notifyNOTIFIED_TASK_STACK_SIZE 120 +#define priSUSPENDED_RX_TASK_STACK_SIZE 90 +#define tmrTIMER_TEST_TASK_STACK_SIZE 100 +#define ebRENDESVOUS_TEST_TASK_STACK_SIZE 100 +#define ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE 115 +#define genqMUTEX_TEST_TASK_STACK_SIZE 90 +#define genqGENERIC_QUEUE_TEST_TASK_STACK_SIZE 100 +#define recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE 90 + +extern void vAssertCalled(void); /* Stop if an assertion fails. */ #define configASSERT(x) \ if ((x) == 0) \ vAssertCalled() -/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS -standard names. */ -// #define vPortSVCHandler SVC_Handler -// #define xPortPendSVHandler PendSV_Handler -#define xPortSysTickHandler SysTick_Handler +#if (configUSE_TICKLESS_IDLE != 0) +#include "portmacro.h" +extern void vApplicationSleep(TickType_t xExpectedIdleTime); +#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vApplicationSleep(xExpectedIdleTime) +#endif -#ifdef __cplusplus -} #endif diff --git a/examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.c b/examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.c index 230cccadd52657..bcdbcc4edef34a 100644 --- a/examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.c +++ b/examples/platform/bouffalolab/bl602/route_hook/bl_route_hook.c @@ -12,6 +12,7 @@ #include "lwip/prot/ip6.h" #include "lwip/prot/nd6.h" #include "lwip/raw.h" +#include typedef struct bl_route_hook_t { diff --git a/examples/platform/bouffalolab/bl702/BUILD.gn b/examples/platform/bouffalolab/bl702/BUILD.gn index 8dc352bbdf5be2..df3ea0e637521e 100644 --- a/examples/platform/bouffalolab/bl702/BUILD.gn +++ b/examples/platform/bouffalolab/bl702/BUILD.gn @@ -15,7 +15,7 @@ import("//build_overrides/bouffalolab_iot_sdk.gni") import("//build_overrides/chip.gni") -import("${bl702_sdk_build_root}/bl702_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/bl702/bl_iot_sdk.gni") config("chip_examples_project_config") { include_dirs = [ "project_include" ] diff --git a/examples/platform/bouffalolab/common/plat/main.cpp b/examples/platform/bouffalolab/common/plat/main.cpp index 29090ddbb02ee2..8dad0e2a958877 100644 --- a/examples/platform/bouffalolab/common/plat/main.cpp +++ b/examples/platform/bouffalolab/common/plat/main.cpp @@ -31,9 +31,10 @@ #include #include -#include extern "C" { +#include + #ifdef BL702_ENABLE #include #include diff --git a/scripts/build/builders/bouffalolab.py b/scripts/build/builders/bouffalolab.py index ed22de8ad88bb5..52e1e4e01e90d3 100644 --- a/scripts/build/builders/bouffalolab.py +++ b/scripts/build/builders/bouffalolab.py @@ -89,7 +89,8 @@ def __init__(self, self.argsOpt = [] self.chip_name = bouffalo_chip - toolchain = os.path.join(root, '../../examples/platform/bouffalolab/common/toolchain') + + toolchain = os.path.join(root, os.path.split(os.path.realpath(__file__))[0], '../../../config/bouffalolab/toolchain') toolchain = 'custom_toolchain="{}:riscv_gcc"'.format(toolchain) if toolchain: self.argsOpt.append(toolchain) diff --git a/scripts/examples/gn_bouffalolab_example.sh b/scripts/examples/gn_bouffalolab_example.sh index 7c40790619fed4..2b3725e0ab12ba 100755 --- a/scripts/examples/gn_bouffalolab_example.sh +++ b/scripts/examples/gn_bouffalolab_example.sh @@ -90,7 +90,7 @@ else baudrate=2000000 optArgs="" - optArgs=custom_toolchain=\"$MATTER_ROOT/examples/platform/bouffalolab/common/toolchain:riscv_gcc\" + optArgs=custom_toolchain=\"$MATTER_ROOT/config/bouffalolab/toolchain:riscv_gcc\" shift shift diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index 54f6d44372fc37..22f56ffc310769 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -107,11 +107,11 @@ if (current_os == "zephyr" || current_os == "mbed") { public_configs += [ "${psoc6_sdk_build_root}:psoc6_sdk_config" ] } } else if (lwip_platform == "bl702_lwip") { - import("//build_overrides/bl702_sdk.gni") + import("${bouffalolab_iot_sdk_build_root}/bl702/bl_iot_sdk.gni") group("lwip") { public_deps = [ ":lwip_buildconfig" ] - public_deps += [ "${bl702_sdk_build_root}:bl702_sdk" ] + public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" ] } group("all") { @@ -142,7 +142,7 @@ if (current_os == "zephyr" || current_os == "mbed") { } else if (lwip_platform == "bl602") { group("lwip") { public_deps = [ ":lwip_buildconfig" ] - public_deps += [ "${bl602_sdk_build_root}:bl602_sdk" ] + public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl602:bl_iot_sdk" ] } group("all") { @@ -195,9 +195,9 @@ if (current_os == "zephyr" || current_os == "mbed") { } else if (lwip_platform == "cyw30739") { public_deps += [ "${cyw30739_sdk_build_root}:cyw30739_sdk" ] } else if (lwip_platform == "bl602") { - public_deps += [ "${bl602_sdk_build_root}:bl602_sdk" ] + public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl602:bl602_sdk" ] } else if (lwip_platform == "bl702") { - public_deps += [ "${bl702_sdk_build_root}:bl702_sdk" ] + public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" ] } else if (lwip_platform == "mt793x") { public_deps += [ "${mt793x_sdk_build_root}:mt793x_sdk" ] } diff --git a/src/platform/bouffalolab/BL602/BL602Config.cpp b/src/platform/bouffalolab/BL602/BL602Config.cpp index 6f0d93f4b85b89..140b52d5fa0edd 100644 --- a/src/platform/bouffalolab/BL602/BL602Config.cpp +++ b/src/platform/bouffalolab/BL602/BL602Config.cpp @@ -33,7 +33,6 @@ #include #include -#include #include #include @@ -82,97 +81,69 @@ CHIP_ERROR BL602Config::Init() CHIP_ERROR BL602Config::ReadConfigValue(Key key, bool & val) { CHIP_ERROR err = CHIP_NO_ERROR; - bool tmpVal; - size_t ret, valLen; + size_t valLen = 0; - ret = ef_get_env_blob(key.name, &tmpVal, sizeof(tmpVal), &valLen); - if (ret <= 0) + ef_get_env_blob(key.name, &val, 1, &valLen); + if (0 == valLen) { err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } - SuccessOrExit(err); - - val = tmpVal; -exit: return err; } CHIP_ERROR BL602Config::ReadConfigValue(Key key, uint32_t & val) { CHIP_ERROR err = CHIP_NO_ERROR; - uint32_t tmpVal; - size_t ret, valLen; + size_t valLen = 0; - ret = ef_get_env_blob(key.name, &tmpVal, sizeof(tmpVal), &valLen); - if (ret <= 0) + ef_get_env_blob(key.name, &val, sizeof(val), &valLen); + if (0 == valLen) { err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } - SuccessOrExit(err); - val = tmpVal; - -exit: return err; } CHIP_ERROR BL602Config::ReadConfigValue(Key key, uint64_t & val) { CHIP_ERROR err = CHIP_NO_ERROR; - uint64_t tmpVal; - size_t ret, valLen; + size_t valLen = 0; - ret = ef_get_env_blob(key.name, &tmpVal, sizeof(tmpVal), &valLen); - if (ret <= 0) + ef_get_env_blob(key.name, &val, sizeof(val), &valLen); + if (0 == valLen) { err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } - SuccessOrExit(err); - val = tmpVal; -exit: return err; } CHIP_ERROR BL602Config::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) { - CHIP_ERROR err = CHIP_NO_ERROR; - char tmpVal[bufSize] = { 0 }; - size_t ret; + CHIP_ERROR err = CHIP_NO_ERROR; - ret = ef_get_env_blob(key.name, tmpVal, sizeof(tmpVal) - 1, NULL); - if ('\0' == tmpVal[0]) + outLen = 0; + ef_get_env_blob(key.name, buf, bufSize, &outLen); + if (0 == outLen) { err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } - SuccessOrExit(err); - outLen = ret; - Platform::CopyString(buf, outLen, tmpVal); - -exit: return err; } CHIP_ERROR BL602Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) { - CHIP_ERROR err = CHIP_NO_ERROR; - char tmpVal[bufSize] = { 0 }; - size_t ret; - size_t savedLen = 0; + CHIP_ERROR err = CHIP_NO_ERROR; - ret = ef_get_env_blob(key.name, tmpVal, sizeof(tmpVal), &savedLen); - if (0 == savedLen) + ef_get_env_blob(key.name, buf, bufSize, &outLen); + if (0 == outLen) { err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } - SuccessOrExit(err); - outLen = ret; - memcpy(buf, tmpVal, outLen); - -exit: return err; } diff --git a/src/platform/bouffalolab/BL602/CHIPMem-Platform.cpp b/src/platform/bouffalolab/BL602/CHIPMem-Platform.cpp index 5f1f07f97a6a77..3b9b274941bfb8 100644 --- a/src/platform/bouffalolab/BL602/CHIPMem-Platform.cpp +++ b/src/platform/bouffalolab/BL602/CHIPMem-Platform.cpp @@ -52,10 +52,10 @@ #include #include #include +#include extern "C" { #include -#include }; #if CHIP_CONFIG_MEMORY_MGMT_PLATFORM diff --git a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp index f207e295ca882f..5c53153867fbe0 100644 --- a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp @@ -32,9 +32,9 @@ #include extern "C" { -#include #include #include +#include } namespace chip { @@ -213,8 +213,6 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void) void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { - CHIP_ERROR err; - ChipLogProgress(DeviceLayer, "Performing factory reset"); ef_env_set_default(); ChipLogProgress(DeviceLayer, "System restarting"); diff --git a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.h b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.h index e4d231711c473d..0183da4e3a007f 100644 --- a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.h +++ b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.h @@ -33,7 +33,6 @@ #include #endif -#include #include namespace chip { diff --git a/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp b/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp index 02d296c492abd9..56e3ebf522a36b 100644 --- a/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/ConnectivityManagerImpl.cpp @@ -69,7 +69,7 @@ namespace chip { namespace DeviceLayer { ConnectivityManagerImpl ConnectivityManagerImpl::sInstance; -static ConnectivityManager::WiFiStationState ConnectivityManagerImpl::mWiFiStationState = +ConnectivityManager::WiFiStationState ConnectivityManagerImpl::mWiFiStationState = ConnectivityManager::kWiFiStationState_NotConnected; void ConnectivityManagerImpl::WifiStationStateChange(void) @@ -86,8 +86,6 @@ void ConnectivityManagerImpl::WifiStationStateChange(void) void ConnectivityManagerImpl::DriveStationState() { - -exit: return; } @@ -101,7 +99,7 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(WiFiStationMode val) CHIP_ERROR err = CHIP_NO_ERROR; DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); -exit: + return err; } diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index e260e750a51493..9c972071a60631 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -30,11 +30,11 @@ #include extern "C" { -#include #include +#include +#include #include -#include -#include +#include #include } @@ -248,7 +248,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBssId(ByteSpan & BssId) CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(uint8_t & securityType) { - int authmode; + // int authmode; // authmode = mgmr_get_security_type(); // securityType = MapAuthModeToSecurityType(authmode); diff --git a/src/platform/bouffalolab/BL602/KeyValueStoreManagerImpl.cpp b/src/platform/bouffalolab/BL602/KeyValueStoreManagerImpl.cpp index a7036b041b0ea2..dc7aee8708d0f5 100644 --- a/src/platform/bouffalolab/BL602/KeyValueStoreManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/KeyValueStoreManagerImpl.cpp @@ -47,7 +47,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t size_t outlen = 0; BL602Config::Key ckey = { key }; - err = BL602Config::ReadConfigValueBin(ckey, value, value_size, outlen); + err = BL602Config::ReadConfigValueBin(ckey, (uint8_t *) value, value_size, outlen); if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == err) { err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; @@ -69,7 +69,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, CHIP_ERROR err = CHIP_NO_ERROR; BL602Config::Key ckey = { key }; - err = BL602Config::WriteConfigValueBin(ckey, value, value_size); + err = BL602Config::WriteConfigValueBin(ckey, (uint8_t *) value, value_size); if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == err) { err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; diff --git a/src/platform/bouffalolab/BL602/Logging.cpp b/src/platform/bouffalolab/BL602/Logging.cpp index 872fd3c65ce1cf..33397bd520f409 100644 --- a/src/platform/bouffalolab/BL602/Logging.cpp +++ b/src/platform/bouffalolab/BL602/Logging.cpp @@ -6,15 +6,7 @@ #include #include - -// #ifdef LOG_LOCAL_LEVEL -// #undef LOG_LOCAL_LEVEL -// #endif -// #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE - -extern "C" { -#include -} +#include #ifdef PW_RPC_ENABLED #include "PigweedLogger.h" diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index b99b4d212ae739..7cb2bfaad1cc20 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -16,14 +16,14 @@ */ #include +#include +#include #include #include #include +#include #include #include -#include -#include -#include #include #include @@ -47,7 +47,7 @@ constexpr char kWiFiCredentialsKeyName[] = "wifi-pass"; constexpr char blWiFiSSIDKeyName[] = "bl-wifi-ssid"; constexpr char blWiFiCredentialsKeyName[] = "bl-wifi-pass"; -static uint8_t WiFiSSIDStr[DeviceLayer::Internal::kMaxWiFiSSIDLength]; +static char WiFiSSIDStr[DeviceLayer::Internal::kMaxWiFiSSIDLength]; static uint8_t scan_type = 0; } // namespace @@ -184,7 +184,7 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, memcpy(passwd, key, keyLen); wifi_interface_t wifi_interface; wifi_interface = wifi_mgmr_sta_enable(); - wifi_mgmr_sta_connect(wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); + wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled)); @@ -221,7 +221,6 @@ void BLWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback { CHIP_ERROR err = CHIP_NO_ERROR; Status networkingStatus = Status::kSuccess; - static int save = 0; VerifyOrExit(NetworkMatch(mStagingNetwork, networkId), networkingStatus = Status::kNetworkIDNotFound); VerifyOrExit(mpConnectCallback == nullptr, networkingStatus = Status::kUnknownError); diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h index 70090297551aa3..fc08f778e8fbff 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h @@ -16,8 +16,8 @@ */ #pragma once +#include #include -#include namespace chip { namespace DeviceLayer { diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningWiFiDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningWiFiDriver.cpp index c9a35fe40194fe..c469c5a90edb01 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningWiFiDriver.cpp @@ -19,9 +19,9 @@ #include #include #include +#include #include #include -#include #include #include diff --git a/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp b/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp index 2d1e0dc8daf955..16fad1b9ffcf5f 100644 --- a/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp @@ -31,14 +31,14 @@ #include #include +#include #include -#include #include #include #include #include -#include +#include #include extern "C" { @@ -165,13 +165,10 @@ static void WifiStaConnected(void) chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::WiFiConnectionStatus::kConnected)); } } +typedef void (*aos_event_cb)(input_event_t * event, void * private_data); void OnWiFiPlatformEvent(input_event_t * event, void * private_data) { - static char * ssid; - static char * password; - int ret; - switch (event->code) { case CODE_WIFI_ON_INIT_DONE: { @@ -223,7 +220,7 @@ void OnWiFiPlatformEvent(input_event_t * event, void * private_data) CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { - CHIP_ERROR err; + CHIP_ERROR err = CHIP_NO_ERROR; static uint8_t stack_wifi_init = 0; TaskHandle_t backup_eventLoopTask; @@ -238,7 +235,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) if (1 == stack_wifi_init) { log_error("Wi-Fi already initialized!\r\n"); - return; + return CHIP_NO_ERROR; } hal_wifi_start_firmware_task(); @@ -255,6 +252,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) err = Internal::GenericPlatformManagerImpl_FreeRTOS::_InitChipStack(); SuccessOrExit(err); Internal::GenericPlatformManagerImpl_FreeRTOS::mEventLoopTask = backup_eventLoopTask; + exit: return err; } diff --git a/src/platform/bouffalolab/BL602/PlatformManagerImpl.h b/src/platform/bouffalolab/BL602/PlatformManagerImpl.h index f51556099cf911..861e446f0beec3 100644 --- a/src/platform/bouffalolab/BL602/PlatformManagerImpl.h +++ b/src/platform/bouffalolab/BL602/PlatformManagerImpl.h @@ -24,20 +24,12 @@ #pragma once +#include #include namespace chip { namespace DeviceLayer { -typedef struct -{ - uint32_t time; - uint16_t type; - uint16_t code; - unsigned long value; - unsigned long extra; -} input_event_t; - /** * Concrete implementation of the PlatformManager singleton object for the BL602 platform. */ diff --git a/src/platform/bouffalolab/BL602/args.gni b/src/platform/bouffalolab/BL602/args.gni index 384290911e92e5..0f32696fb1c914 100644 --- a/src/platform/bouffalolab/BL602/args.gni +++ b/src/platform/bouffalolab/BL602/args.gni @@ -16,9 +16,9 @@ import("//build_overrides/bouffalolab_iot_sdk.gni") import("//build_overrides/chip.gni") import("${chip_root}/examples/platform/bouffalolab/bl602/args.gni") -riscv_platform_config = "${bl602_sdk_build_root}/bl602_riscv.gni" +riscv_platform_config = "${bouffalolab_iot_sdk_build_root}/common/rsicv.gni" -mbedtls_target = "${bl602_sdk_build_root}:bl602_sdk" +mbedtls_target = "${bouffalolab_iot_sdk_build_root}/bl602:bl_iot_sdk" chip_device_platform = "bl602" diff --git a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c index 244ad2c1074591..c41c3bcc8562cb 100644 --- a/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c +++ b/src/platform/bouffalolab/BL602/wifi_mgmr_portable.c @@ -1,16 +1,10 @@ -#include "wifi_mgmr.h" -#include "wifi_mgmr_api.h" +#include +#include +#include -#include #include #include -BLOG_DECLARE(tcal_power) -BLOG_DECLARE(scan) -#define USER_UNUSED(a) ((void) (a)) - -#define DEBUG_HEADER "[WF][SM] " - int wifi_mgmr_get_bssid(uint8_t * bssid) { int i; @@ -20,7 +14,7 @@ int wifi_mgmr_get_bssid(uint8_t * bssid) bssid[i] = wifiMgmr.wifi_mgmr_stat_info.bssid[i]; } - return; + return 0; } int wifi_mgmr_get_scan_ap_num(void) diff --git a/src/platform/bouffalolab/BL702/BUILD.gn b/src/platform/bouffalolab/BL702/BUILD.gn index 310c721a699d8e..7fde9b5495c34f 100644 --- a/src/platform/bouffalolab/BL702/BUILD.gn +++ b/src/platform/bouffalolab/BL702/BUILD.gn @@ -72,10 +72,10 @@ static_library("BL702") { # needed for MTD/FTD import("//build_overrides/bouffalolab_iot_sdk.gni") - import("${bl702_sdk_build_root}/bl702_sdk.gni") + import("${bouffalolab_iot_sdk_build_root}/bl702/bl_iot_sdk.gni") public_deps += [ - "${bl702_sdk_build_root}:bl702_sdk", - "${bl702_sdk_build_root}:mbedtls", + "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk", + "${bouffalolab_iot_sdk_build_root}/bl702:mbedtls", ] sources += [ diff --git a/src/platform/bouffalolab/BL702/Logging.cpp b/src/platform/bouffalolab/BL702/Logging.cpp index 24193ea434ae28..5bb986d63cb27d 100644 --- a/src/platform/bouffalolab/BL702/Logging.cpp +++ b/src/platform/bouffalolab/BL702/Logging.cpp @@ -14,22 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include #include -#include - -extern "C" { -#include -} - #ifdef PW_RPC_ENABLED #include "PigweedLogger.h" #endif +#include +#include +#include + namespace chip { namespace Logging { namespace Platform { diff --git a/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp index be9d29619aae4f..0fb93c75826058 100644 --- a/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp @@ -49,8 +49,13 @@ CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst) CHIP_ERROR err = CHIP_NO_ERROR; ot_alarmInit(); +#ifdef OT_THREAD_PORT_1_3 + otRadio_opt_t opt; + opt.byte = 0; + ot_radioInit(opt); +#else ot_radioInit(); - +#endif // Initialize the generic implementation base classes. err = GenericThreadStackManagerImpl_FreeRTOS::DoInit(); SuccessOrExit(err); @@ -73,15 +78,18 @@ bool ThreadStackManagerImpl::IsInitialized() using namespace ::chip::DeviceLayer; -ot_system_event_t ot_system_event_var; +ot_system_event_t ot_system_event_var = OT_SYSTEM_EVENT_NONE; void otSysProcessDrivers(otInstance * aInstance) { +#ifdef OT_THREAD_PORT_1_3 + ot_system_event_t sevent = otrGetNotifyEvent(); +#else ot_system_event_t sevent = OT_SYSTEM_EVENT_NONE; - OT_GET_NOTIFY(sevent); +#endif + ot_alarmTask(sevent); - // ot_uartTask(sevent); ot_radioTask(sevent); } @@ -117,3 +125,51 @@ extern "C" void otPlatFree(void * aPtr) { free(aPtr); } + +#ifdef OT_THREAD_PORT_1_3 +extern "C" uint32_t otrEnterCrit(void) +{ + if (xPortIsInsideInterrupt()) + { + return taskENTER_CRITICAL_FROM_ISR(); + } + else + { + taskENTER_CRITICAL(); + return 0; + } +} + +extern "C" void otrExitCrit(uint32_t tag) +{ + if (xPortIsInsideInterrupt()) + { + taskEXIT_CRITICAL_FROM_ISR(tag); + } + else + { + taskEXIT_CRITICAL(); + } +} + +extern "C" ot_system_event_t otrGetNotifyEvent(void) +{ + ot_system_event_t sevent = OT_SYSTEM_EVENT_NONE; + + taskENTER_CRITICAL(); + sevent = ot_system_event_var; + ot_system_event_var = OT_SYSTEM_EVENT_NONE; + taskEXIT_CRITICAL(); + + return sevent; +} + +extern "C" void otrNotifyEvent(ot_system_event_t sevent) +{ + uint32_t tag = otrEnterCrit(); + ot_system_event_var = (ot_system_event_t)(ot_system_event_var | sevent); + otrExitCrit(tag); + + otSysEventSignalPending(); +} +#endif diff --git a/src/platform/bouffalolab/BL702/args.gni b/src/platform/bouffalolab/BL702/args.gni index 77396b3b094c8d..6d7aad914b6a28 100644 --- a/src/platform/bouffalolab/BL702/args.gni +++ b/src/platform/bouffalolab/BL702/args.gni @@ -20,9 +20,9 @@ import("${chip_root}/examples/platform/bouffalolab/bl702/args.gni") chip_device_platform = "bl702" -riscv_platform_config = "${bl702_sdk_build_root}/bl702_riscv.gni" +riscv_platform_config = "${bouffalolab_iot_sdk_build_root}/common/rsicv.gni" -mbedtls_target = "${bl702_sdk_build_root}:mbedtls" +mbedtls_target = "${bouffalolab_iot_sdk_build_root}/bl702:mbedtls" chip_inet_config_enable_ipv4 = false chip_inet_config_enable_tcp_endpoint = false @@ -37,7 +37,8 @@ openthread_core_config_platform_check_file = "bl702-openthread-core-bl-config-check.h" openthread_project_include_dirs = [ "${chip_root}/src/platform/bouffalolab/BL702" ] -openthread_external_platform = "${bl702_sdk_build_root}:bl702_sdk" +openthread_external_platform = + "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" pw_build_LINK_DEPS = [ "$dir_pw_assert:impl", diff --git a/src/platform/bouffalolab/BL702/bl702Config.cpp b/src/platform/bouffalolab/BL702/bl702Config.cpp index d824474b7ad91b..a036a9277afe66 100644 --- a/src/platform/bouffalolab/BL702/bl702Config.cpp +++ b/src/platform/bouffalolab/BL702/bl702Config.cpp @@ -25,7 +25,6 @@ #include #include -// #include #include namespace chip { diff --git a/third_party/bouffalolab/bl602/BUILD.gn b/third_party/bouffalolab/bl602/BUILD.gn index 82413e63efd49c..d358e393114859 100644 --- a/third_party/bouffalolab/bl602/BUILD.gn +++ b/third_party/bouffalolab/bl602/BUILD.gn @@ -13,15 +13,15 @@ # limitations under the License. import("//build_overrides/bouffalolab_iot_sdk.gni") -import("${bl602_sdk_build_root}/bl602_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/bl602/bl_iot_sdk.gni") declare_args() { - # Build target to use for bl602 SDK. Use this to set global SDK defines. - bl602_sdk_target = "" + # Build target to use for Bouffalo Lab IOT SDK. Use this to set global SDK defines. + bl_iot_sdk_target = "" } -assert(bl602_sdk_target != "", "bl602_sdk_target must be specified") +assert(bl_iot_sdk_target != "", "bl_iot_sdk_target must be specified") -group("bl602_sdk") { - public_deps = [ bl602_sdk_target ] +group("bl_iot_sdk") { + public_deps = [ bl_iot_sdk_target ] } diff --git a/third_party/bouffalolab/bl602/bl602_board.gni b/third_party/bouffalolab/bl602/bl602_board.gni deleted file mode 100644 index 123f6ca46c61e5..00000000000000 --- a/third_party/bouffalolab/bl602/bl602_board.gni +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -declare_args() { - # BL602 board used - bl602_board = "BL-HWC-G1" -} - -if (bl602_board == "") { - # bl602_board = getenv("BL602_BOARD") - bl602_board = "BL-HWC-G1" -} - -assert(bl602_board != "", "bl602_board must be specified") - -board_defines = [] -# bl602_mcu = "" -# enable_fem = true -# board_defines += [ "PAL_RTCC_CLOCK_LFRCO" ] diff --git a/third_party/bouffalolab/bl602/bl602_sdk.gni b/third_party/bouffalolab/bl602/bl602_sdk.gni deleted file mode 100644 index fb8a661ef263ae..00000000000000 --- a/third_party/bouffalolab/bl602/bl602_sdk.gni +++ /dev/null @@ -1,636 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import("//args.gni") -import("//build_overrides/bouffalolab_iot_sdk.gni") -import("//build_overrides/chip.gni") -import("//build_overrides/mbedtls.gni") -import("${chip_root}/src/lib/lib.gni") - -import("bl602_board.gni") - -declare_args() { - # Location of the bl602 SDK. - bl602_sdk_root = "${chip_root}/third_party/bouffalolab/repo" -} - -assert(bl602_sdk_root != "", "bl602_sdk_root must be specified") - -# Defines an bl602 SDK build target. -# -# Parameters: -# bl602_sdk_root - The location of the bl602 SDK. -# sources - The sources files to build. -template("bl602_sdk") { - if (defined(invoker.bl602_sdk_root)) { - bl602_sdk_root = invoker.bl602_sdk_root - } - - assert(bl602_sdk_root != "", "bl602_sdk_root must be specified") - - sdk_target_name = target_name - - config("${sdk_target_name}_config") { - include_dirs = [] - libs = [] - if (defined(invoker.include_dirs)) { - include_dirs += invoker.include_dirs - } - - if (defined(invoker.freertos_config)) { - cflags_c = [ - "-include", - rebase_path("${invoker.freertos_config}", root_build_dir), - ] - } - - # Treat these includes as system includes, so warnings in them are not fatal. - _include_dirs = [ - "${bl602_sdk_root}", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/config", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V/chip_specific_extensions/RV32F_float_abi_single", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/panic", - - "${bl602_sdk_root}/components/network/lwip/lwip-port/config", - "${bl602_sdk_root}/components/network/lwip/src/include", - "${bl602_sdk_root}/components/network/lwip/src/include/lwip", - "${bl602_sdk_root}/components/network/lwip/src/include/lwip/apps", - "${bl602_sdk_root}/components/network/lwip/lwip-port", - "${bl602_sdk_root}/components/network/lwip/lwip-port/FreeRTOS", - "${bl602_sdk_root}/components/network/lwip/lwip-port/hook", - "${bl602_sdk_root}/components/network/lwip_mdns", - - #"${bl602_sdk_root}/components/network/lwip_mdns", - - "${bl602_sdk_root}/components/platform/hosal", - "${bl602_sdk_root}/components/platform/hosal/include", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal", - "${bl602_sdk_root}/components/utils/include", - "${bl602_sdk_root}/components/security/blcrypto_suite/priv_inc", - "${bl602_sdk_root}/components/security/blcrypto_suite/inc/blcrypto_suite", - - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Inc", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Device/Bouffalo/BL602/Peripherals", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/RISCV/Device/Bouffalo/BL602/Startup", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/platform_print", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/RISCV/Core/Include", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/soft_crc", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/partition", - - "${bl602_sdk_root}/components/sys/bltime/include", - - "${bl602_sdk_root}/components/stage/easyflash4/inc", - "${bl602_sdk_root}/components/sys/blmtd/include", - "${bl602_sdk_root}/components/stage/blfdt/inc", - - "${bl602_sdk_root}/components/stage/blog", - "${bl602_sdk_root}/components/stage/cli/cli/include", - "${bl602_sdk_root}/components/utils/include", - - "${chip_root}/third_party/mbedtls/repo/include", - - "${bl602_sdk_root}/components/sys/bloop/bloop/include", - "${bl602_sdk_root}/components/sys/bloop/loopset/include", - "${bl602_sdk_root}/components/sys/bloop/looprt/include", - - "${bl602_sdk_root}/components/fs/vfs/include", - "${bl602_sdk_root}/components/stage/yloop/include", - - "${bl602_sdk_root}/components/network/wifi/include", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal", - "${bl602_sdk_root}/components/stage/yloop/include/aos", - "${bl602_sdk_root}/components/stage/yloop/include/aos", - - "${bl602_sdk_root}/components/network/ble/blestack/src/common/include/zephyr", - "${bl602_sdk_root}/components/network/ble/blestack/src/port/include", - "${bl602_sdk_root}/components/network/ble/blestack/src", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/include", - "${bl602_sdk_root}/components/network/ble/blestack/src/include", - "${bl602_sdk_root}/components/network/ble/blestack/src/include/bluetooth", - "${bl602_sdk_root}/components/network/ble/blecontroller/ble_inc", - "${bl602_sdk_root}/components/network/ble/blestack/src/host", - "${bl602_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/include/misc", - "${bl602_sdk_root}/components/network/ble/blestack/src/common", - "${bl602_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/tinycrypt/include/tinycrypt", - - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/include", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver", - "${bl602_sdk_root}/components/network/dns_server/include", - "${bl602_sdk_root}/components/network/rfparam_adapter_tmp/rftlv", - - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Inc", - "${bl602_sdk_root}/components/security/blcrypto_suite/inc/blcrypto_suite", - "${bl602_sdk_root}/components/security/blcrypto_suite/inc", - "${bl602_sdk_root}/components/security/blcrypto_suite/priv_inc", - "${bl602_sdk_root}/components/network/wifi/modules/supplicant/src/sae", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/platform_print", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/ring_buffer", - "${bl602_sdk_root}/components/utils/include", - - "${bl602_sdk_root}/components/stage/cli/cli/include/", - "${bl602_sdk_root}/components/sys/blota/include", - "${bl602_sdk_root}/components/utils/include/", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Inc/", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/", - - #bl602 portable - "${chip_root}/third_party/bouffalolab/bl602/portable", - - # rebase add - "${bl602_sdk_root}/components/network/wifi_hosal/include", - "${bl602_sdk_root}/components/os/bl_os_adapter/bl_os_adapter", - "${bl602_sdk_root}/components/os/bl_os_adapter/bl_os_adapter/include", - "${bl602_sdk_root}/components/os/bl_os_adapter/bl_os_adapter/include/bl_os_adapter", - "${bl602_sdk_root}/components/security/wpa_supplicant/include/bl_supplicant", - - # wpa_supplicant - "${bl602_sdk_root}/components/security/wpa_supplicant/port", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/ap", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/common", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/eap_peer", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/rsn_supp", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/utils", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps", - "${bl602_sdk_root}/components/security/wpa_supplicant/test", - "${bl602_sdk_root}/components/security/wpa_supplicant/port/include", - "${bl602_sdk_root}/components/security/wpa_supplicant/src", - "${bl602_sdk_root}/components/security/wpa_supplicant/include", - - "${bl602_sdk_root}/security/wpa_supplicant/src/", - - # hosal - "${bl602_sdk_root}/components/platform/hosal/sec_common", - ] - - # if (bl602_board == "BL-HWC-G1") { - # _include_dirs += [ "${bl602_sdk_root}/hardware/board/config/bl_hwc_g1" ] - # } - - bl_sdk_ver = getenv("BL_SDK_VER") - defines = [ - "MBEDTLS_CONFIG_FILE=\"bl602-chip-mbedtls-config.h\"", - "__STARTUP_CLEAR_BSS", - "HARD_FAULT_LOG_ENABLE", - "RETARGET_VCOM", - "RETARGET_USART0", - "ARCH_RISCV", - "portasmHANDLE_INTERRUPT=interrupt_entry", - - "SYS_APP_TASK_STACK_SIZE=2048", - "SYS_APP_TASK_PRIORITY=28", - "BL_SDK_VER=\"$bl_sdk_ver\"", - - "SYS_BLOG_ENABLE=1", - "SYS_VFS_ENABLE=1", - "SYS_AOS_LOOP_ENABLE=1", - "BL602_USE_HAL_DRIVER=1", - "BL602=BL602", - - "CFG_TXDESC=2", - "CFG_STA_MAX=1", - "CFG_CHIP_BL602", - - # "SYS_AOS_CLI_ENABLE=1", - - # set CONFIG_RENDEZVOUS_MODE to RENDEZVOUS_MODE_BLE (2) - "CONFIG_RENDEZVOUS_MODE=2", - - # bluetooth - "CONFIG_SET_TX_PWR", - "CFG_BLE_ENABLE", - "BFLB_BLE", - "CFG_BLE", - "CFG_SLEEP", - "OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER", - "CFG_BT_RESET", - "CFG_CON=1", - "CFG_BLE_TX_BUFF_DATA=2", - - # "CONFIG_BLE_TX_BUFF_DATA=2", - "CONFIG_BT_PERIPHERAL=1", - "CONFIG_BT_L2CAP_DYNAMIC_CHANNEL", - "CONFIG_BT_GATT_CLIENT", - "CONFIG_BT_CONN=1", - "CONFIG_BT_GATT_DIS_PNP", - "CONFIG_BT_GATT_DIS_SERIAL_NUMBER", - "CONFIG_BT_GATT_DIS_FW_REV", - "CONFIG_BT_GATT_DIS_HW_REV", - "CONFIG_BT_GATT_DIS_SW_REV", - "CONFIG_BT_ECC", - "CONFIG_BT_GATT_DYNAMIC_DB", - "CONFIG_BT_GATT_SERVICE_CHANGED", - "CONFIG_BT_KEYS_OVERWRITE_OLDEST", - "CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING", - "CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS", - "CONFIG_BT_BONDABLE", - "CONFIG_BT_HCI_VS_EVT_USER", - "CONFIG_BT_ASSERT", - "CONFIG_BT_SETTINGS_CCC_LAZY_LOADING", - "CONFIG_BT_SETTINGS_USE_PRINTK", - "CFG_BLE_STACK_DBG_PRINT", - - #"__FILENAME__=__FILE__", - "__FILENAME__=\"\b\"", - "BL602_LOG_ENABLED=1", - "ENOTSUP=134", - - #dump backtrace - "CONF_ENABLE_FRAME_PTR=1", - "CONF_ENABLE_FUNC_BACKTRACE_ELF=out/bl602-light/chip-bl602-lighting-example.out", - "CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE=128", - - # board defines - "BL_CHIP_NAME=\"BL602\"", - - #include defines - "OS_USING_FREERTOS", - "BL602_MATTER_SUPPORT", - "PBUF_POOL_SIZE=20", - "TD_DIAGNOSIS_STA", - "CONFIG_ENABLE_IPV6_ADDR_CALLBACK", - "CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT", - "CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT", - ] - - defines += board_defines - - libs += [ - "${bl602_sdk_root}/components/network/wifi/lib/libwifi.a", - "${bl602_sdk_root}/components/network/ble/blecontroller_602_m0s1/lib/libblecontroller_602_m0s1.a", - ] - - cflags = [ - "-include", - rebase_path( - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/errno.h", - root_build_dir), - ] - - cflags += [ - "-Wno-maybe-uninitialized", - "-Wno-shadow", - "-Wno-error", - "-fcommon", - "-fno-jump-tables", - ] - - cflags_cc = [ "-fpermissive" ] - - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - - cflags += [ "-save-temps=obj" ] - cflags += [ "-Wno-maybe-uninitialized" ] - - if (defined(invoker.defines)) { - defines += invoker.defines - } - } - - source_set(sdk_target_name) { - sources = [ - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_boot2.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_flash.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_wdt.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hosal_gpio.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hosal_ota.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_mfg_flash.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sf_cfg_ext.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sflash_ext.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_timer.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_xip_sflash_ext.c", - "${bl602_sdk_root}/components/stage/cli/cli/cli.c", - "${bl602_sdk_root}/components/stage/easyflash4/src/easyflash.c", - "${bl602_sdk_root}/components/stage/easyflash4/src/ef_env.c", - "${bl602_sdk_root}/components/stage/easyflash4/src/ef_port.c", - "${bl602_sdk_root}/components/stage/easyflash4/src/ef_utils.c", - "${bl602_sdk_root}/components/sys/blmtd/bl_mtd.c", - "${bl602_sdk_root}/components/sys/blota/bl_sys_ota_cli.c", - "${bl602_sdk_root}/components/utils/src/utils_hex.c", - "${bl602_sdk_root}/components/utils/src/utils_hexdump.c", - "${bl602_sdk_root}/components/utils/src/utils_sha256.c", - "${chip_root}/third_party/mbedtls/repo/library/aes.c", - "${chip_root}/third_party/mbedtls/repo/library/asn1parse.c", - "${chip_root}/third_party/mbedtls/repo/library/asn1write.c", - "${chip_root}/third_party/mbedtls/repo/library/bignum.c", - "${chip_root}/third_party/mbedtls/repo/library/ccm.c", - "${chip_root}/third_party/mbedtls/repo/library/cipher.c", - "${chip_root}/third_party/mbedtls/repo/library/cipher_wrap.c", - "${chip_root}/third_party/mbedtls/repo/library/constant_time.c", - "${chip_root}/third_party/mbedtls/repo/library/ctr_drbg.c", - "${chip_root}/third_party/mbedtls/repo/library/ecdh.c", - "${chip_root}/third_party/mbedtls/repo/library/ecdsa.c", - "${chip_root}/third_party/mbedtls/repo/library/ecp.c", - "${chip_root}/third_party/mbedtls/repo/library/ecp_curves.c", - "${chip_root}/third_party/mbedtls/repo/library/entropy.c", - "${chip_root}/third_party/mbedtls/repo/library/hkdf.c", - "${chip_root}/third_party/mbedtls/repo/library/hmac_drbg.c", - "${chip_root}/third_party/mbedtls/repo/library/md.c", - "${chip_root}/third_party/mbedtls/repo/library/oid.c", - "${chip_root}/third_party/mbedtls/repo/library/pk.c", - "${chip_root}/third_party/mbedtls/repo/library/pk_wrap.c", - "${chip_root}/third_party/mbedtls/repo/library/pkcs5.c", - "${chip_root}/third_party/mbedtls/repo/library/pkwrite.c", - "${chip_root}/third_party/mbedtls/repo/library/platform.c", - "${chip_root}/third_party/mbedtls/repo/library/platform_util.c", - "${chip_root}/third_party/mbedtls/repo/library/sha256.c", - "${chip_root}/third_party/mbedtls/repo/library/sha512.c", - "${chip_root}/third_party/mbedtls/repo/library/x509_create.c", - "${chip_root}/third_party/mbedtls/repo/library/x509write_csr.c", - ] - - sources += [ - "${bl602_sdk_root}/components/fs/vfs/device/vfs_uart.c", - "${bl602_sdk_root}/components/fs/vfs/src/vfs.c", - "${bl602_sdk_root}/components/fs/vfs/src/vfs_file.c", - "${bl602_sdk_root}/components/fs/vfs/src/vfs_inode.c", - "${bl602_sdk_root}/components/fs/vfs/src/vfs_register.c", - "${bl602_sdk_root}/components/libc/newlibc/stdatomic.c", - "${bl602_sdk_root}/components/libc/newlibc/syscalls.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper/bl_hci_wrapper.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/atomic_c.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/buf.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/dec.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/log.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/poll.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/common/work_q.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/hci_onchip/hci_driver.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/att.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/bl_host_assist.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/conn.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/crypto.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/gatt.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/hci_core.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/l2cap.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/settings.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/host/uuid.c", - "${bl602_sdk_root}/components/network/ble/blestack/src/port/bl_port.c", - "${bl602_sdk_root}/components/network/dns_server/src/dns_server.c", - "${bl602_sdk_root}/components/network/dns_server/src/web_server.c", - "${bl602_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/ethernetif.c", - "${bl602_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/sys_arch.c", - "${bl602_sdk_root}/components/network/lwip/src/api/api_lib.c", - "${bl602_sdk_root}/components/network/lwip/src/api/api_msg.c", - "${bl602_sdk_root}/components/network/lwip/src/api/err.c", - "${bl602_sdk_root}/components/network/lwip/src/api/if_api.c", - "${bl602_sdk_root}/components/network/lwip/src/api/netbuf.c", - "${bl602_sdk_root}/components/network/lwip/src/api/netdb.c", - "${bl602_sdk_root}/components/network/lwip/src/api/netifapi.c", - "${bl602_sdk_root}/components/network/lwip/src/api/sockets.c", - "${bl602_sdk_root}/components/network/lwip/src/api/tcpip.c", - "${bl602_sdk_root}/components/network/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c", - "${bl602_sdk_root}/components/network/lwip/src/apps/altcp_tls/altcp_tls_mbedtls_mem.c", - "${bl602_sdk_root}/components/network/lwip/src/core/altcp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/altcp_alloc.c", - "${bl602_sdk_root}/components/network/lwip/src/core/altcp_tcp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/def.c", - "${bl602_sdk_root}/components/network/lwip/src/core/dns.c", - "${bl602_sdk_root}/components/network/lwip/src/core/inet_chksum.c", - "${bl602_sdk_root}/components/network/lwip/src/core/init.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ip.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/autoip.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/dhcp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/etharp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/icmp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/igmp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/ip4.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/ip4_addr.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv4/ip4_frag.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/dhcp6.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/ethip6.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/icmp6.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/inet6.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/ip6.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/ip6_addr.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/ip6_frag.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/mld6.c", - "${bl602_sdk_root}/components/network/lwip/src/core/ipv6/nd6.c", - "${bl602_sdk_root}/components/network/lwip/src/core/mem.c", - "${bl602_sdk_root}/components/network/lwip/src/core/memp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/netif.c", - "${bl602_sdk_root}/components/network/lwip/src/core/pbuf.c", - "${bl602_sdk_root}/components/network/lwip/src/core/raw.c", - "${bl602_sdk_root}/components/network/lwip/src/core/stats.c", - "${bl602_sdk_root}/components/network/lwip/src/core/sys.c", - "${bl602_sdk_root}/components/network/lwip/src/core/tcp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/tcp_in.c", - "${bl602_sdk_root}/components/network/lwip/src/core/tcp_out.c", - "${bl602_sdk_root}/components/network/lwip/src/core/timeouts.c", - "${bl602_sdk_root}/components/network/lwip/src/core/udp.c", - "${bl602_sdk_root}/components/network/lwip/src/core/utils.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/bridgeif.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/bridgeif_fdb.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/ethernet.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/lowpan6.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/lowpan6_ble.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/lowpan6_common.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/slipif.c", - "${bl602_sdk_root}/components/network/lwip/src/netif/zepif.c", - "${bl602_sdk_root}/components/network/lwip_dhcpd/dhcp_server_raw.c", - - #"${bl602_sdk_root}/components/network/lwip_mdns/mdns_server.c", - "${bl602_sdk_root}/components/network/sntp/sntp.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_cmds.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_irqs.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_main.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_mod_params.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_msg_rx.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_msg_tx.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_platform.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_rx.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_tx.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_utils.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/ipc_host.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/stateMachine.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_api.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_cli.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_event.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_ext.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_profile.c", - "${bl602_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_netif.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_chip.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_dma.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_efuse.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_gpio.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_hbn.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_irq.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_pds.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_pm.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_pwm.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_rtc.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_sec.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_sys.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_timer.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_uart.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/bl_wifi.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hal_board.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hal_boot2.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hal_button.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hal_gpio.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hal_hbn.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hal_sys.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hal_wifi.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hosal_dma.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hosal_pwm.c", - "${bl602_sdk_root}/components/platform/hosal/bl602_hal/hosal_uart.c", - "${bl602_sdk_root}/components/platform/hosal/sec_common/bl_sec_sha.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602/evb/src/boot/gcc/start.S", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602/evb/src/debug.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602/evb/src/strntoumax.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/platform_print/platform_device.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_dma.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_ef_ctrl.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_glb.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_hbn.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_mfg_efuse.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_mfg_media.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_pwm.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_romapi.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sec_eng.c", - "${bl602_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_uart.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/event_groups.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/list.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/misaligned/fp_asm.S", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/misaligned/misaligned_ldst.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/panic/panic_c.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V/port.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V/portASM.S", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/MemMang/heap_5.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/queue.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/stream_buffer.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/tasks.c", - "${bl602_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/timers.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_aes.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_bignum.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_ecp.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_ecp_curves.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_export_fw.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_hacc.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_hacc_glue.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_hacc_secp256r1_mul.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_platform_util.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_porting.c", - "${bl602_sdk_root}/components/stage/blfdt/src/fdt.c", - "${bl602_sdk_root}/components/stage/blfdt/src/fdt_ro.c", - "${bl602_sdk_root}/components/stage/blog/blog.c", - "${bl602_sdk_root}/components/stage/yloop/src/aos_freertos.c", - "${bl602_sdk_root}/components/stage/yloop/src/device.c", - "${bl602_sdk_root}/components/stage/yloop/src/local_event.c", - "${bl602_sdk_root}/components/stage/yloop/src/select.c", - "${bl602_sdk_root}/components/stage/yloop/src/yloop.c", - "${bl602_sdk_root}/components/sys/bloop/bloop/src/bloop_base.c", - "${bl602_sdk_root}/components/sys/bloop/bloop/src/bloop_handler_sys.c", - "${bl602_sdk_root}/components/sys/bloop/looprt/src/looprt.c", - "${bl602_sdk_root}/components/sys/bloop/loopset/src/loopset_led.c", - "${bl602_sdk_root}/components/sys/bltime/bl_sys_time.c", - "${bl602_sdk_root}/components/utils/src/utils_crc.c", - "${bl602_sdk_root}/components/utils/src/utils_dns.c", - "${bl602_sdk_root}/components/utils/src/utils_hmac_sha1_fast.c", - "${bl602_sdk_root}/components/utils/src/utils_list.c", - "${bl602_sdk_root}/components/utils/src/utils_log.c", - "${bl602_sdk_root}/components/utils/src/utils_notifier.c", - "${bl602_sdk_root}/components/utils/src/utils_psk_fast.c", - "${bl602_sdk_root}/components/utils/src/utils_rbtree.c", - - #rebase add - "${bl602_sdk_root}/components/network/rfparam_adapter_tmp/rftlv/phy_rftlv.c", - "${bl602_sdk_root}/components/network/wifi_hosal/port/wifi_hosal_bl602.c", - "${bl602_sdk_root}/components/network/wifi_hosal/wifi_hosal.c", - "${bl602_sdk_root}/components/os/bl_os_adapter/bl_os_adapter/bl_os_hal.c", - "${bl602_sdk_root}/components/platform/hosal/sec_common/bl_sec_aes.c", - "${bl602_sdk_root}/components/platform/hosal/sec_common/bl_sec_pka.c", - "${bl602_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_supplicant_api.c", - "${bl602_sdk_root}/components/utils/src/utils_getopt.c", - "${bl602_sdk_root}/components/utils/src/utils_string.c", - "${bl602_sdk_root}/components/utils/src/utils_tlv_bl.c", - - #bl602 portable - # "${chip_root}/third_party/bouffalolab/bl602/portable/async_log.c", - # "${chip_root}/third_party/bouffalolab/bl602/portable/bfl_main.c", - # "${chip_root}/third_party/bouffalolab/bl602/portable/debug.c", - # "${chip_root}/third_party/bouffalolab/bl602/portable/wifi_mgmr_portable.c", - - #wap_supplicant - "${bl602_sdk_root}/components/security/wpa_supplicant/port/os_bl.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/ap/ap_config.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/ap/wpa_auth_ie.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/ap/wpa_auth_rsn_ccmp_only.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_hostap.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wpa3.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wpa_main.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wpas_glue.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wps.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/common/sae.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/common/wpa_common.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-cbc.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-internal-bl.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-omac1.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-unwrap.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-wrap.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/crypto_internal-modexp.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/dh_group5.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/dh_groups.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/md5-internal.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/md5.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/rc4.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/sha1-internal.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/sha1-pbkdf2.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/sha1.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/sha256-internal.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/sha256-prf.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/crypto/sha256.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/eap_peer/eap_common.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/rsn_supp/pmksa_cache.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/rsn_supp/wpa.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/rsn_supp/wpa_ie.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/utils/common.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/utils/wpa_debug.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/utils/wpabuf.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_attr_build.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_attr_parse.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_attr_process.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_common.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_dev_attr.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_enrollee.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_registrar.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/src/wps/wps_validate.c", - "${bl602_sdk_root}/components/security/wpa_supplicant/test/test_crypto-bl.c", - ] - - # } else if (bl_family == "bl706") { - # sources += [ - # ] - # } - - public_deps = [ - # "${segger_rtt_root}:segger_rtt", - # "${segger_rtt_root}:segger_rtt_printf", - # "${segger_rtt_root}:segger_rtt_syscalls", - ] - - if (defined(invoker.sources)) { - sources += invoker.sources - } - - public_configs = [ ":${sdk_target_name}_config" ] - } -} diff --git a/third_party/bouffalolab/bl602/bl_iot_sdk.gni b/third_party/bouffalolab/bl602/bl_iot_sdk.gni new file mode 100644 index 00000000000000..f527f27132f791 --- /dev/null +++ b/third_party/bouffalolab/bl602/bl_iot_sdk.gni @@ -0,0 +1,889 @@ +# Copyright (c) 2021 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//args.gni") +import("//build_overrides/bouffalolab_iot_sdk.gni") +import("//build_overrides/chip.gni") +import("//build_overrides/mbedtls.gni") +import("${chip_root}/src/lib/lib.gni") + +declare_args() { + bl_iot_sdk_root = "${chip_root}/third_party/bouffalolab/repo" +} + +assert(bl_iot_sdk_root != "", "bl_iot_sdk_root must be specified") + +# Defines an Bouffa Lab IOT SDK build target. +# +# Parameters: +# bl_iot_sdk_root - The location of Bouffalo Lab IOT SDK. +# sources - The sources files to build. +template("bl_iot_sdk") { + sdk_target_name = target_name + + config("${sdk_target_name}_config") { + defines = [ + "__FILENAME__=strrchr(__FILE__,'/')?strrchr(__FILE__,'/')+1:__FILE__", + "ARCH_RISCV", + "BL602=BL602", + "BL602_USE_HAL_DRIVER=1", + + "CFG_CHIP_BL602", + + "MBEDTLS_CONFIG_FILE=\"bl602-chip-mbedtls-config.h\"", + + #dump backtrace + "CONF_ENABLE_FRAME_PTR=1", + "CONF_ENABLE_FUNC_BACKTRACE_ELF=out/bl602-light/chip-bl602-lighting-example.out", + ] + + include_dirs = [ "${chip_root}/third_party/mbedtls/repo/include" ] + if (defined(invoker.include_dirs)) { + include_dirs += invoker.include_dirs + } + + if (defined(invoker.defines)) { + defines += invoker.defines + } + + if (defined(invoker.freertos_config)) { + cflags_c = [ + "-include", + rebase_path("${invoker.freertos_config}", root_build_dir), + ] + } + } + + source_set("${sdk_target_name}_code") { + sources = [ + "${chip_root}/third_party/mbedtls/repo/library/aes.c", + "${chip_root}/third_party/mbedtls/repo/library/asn1parse.c", + "${chip_root}/third_party/mbedtls/repo/library/asn1write.c", + "${chip_root}/third_party/mbedtls/repo/library/bignum.c", + "${chip_root}/third_party/mbedtls/repo/library/ccm.c", + "${chip_root}/third_party/mbedtls/repo/library/cipher.c", + "${chip_root}/third_party/mbedtls/repo/library/cipher_wrap.c", + "${chip_root}/third_party/mbedtls/repo/library/constant_time.c", + "${chip_root}/third_party/mbedtls/repo/library/ctr_drbg.c", + "${chip_root}/third_party/mbedtls/repo/library/ecdh.c", + "${chip_root}/third_party/mbedtls/repo/library/ecdsa.c", + "${chip_root}/third_party/mbedtls/repo/library/ecp.c", + "${chip_root}/third_party/mbedtls/repo/library/ecp_curves.c", + "${chip_root}/third_party/mbedtls/repo/library/entropy.c", + "${chip_root}/third_party/mbedtls/repo/library/hkdf.c", + "${chip_root}/third_party/mbedtls/repo/library/hmac_drbg.c", + "${chip_root}/third_party/mbedtls/repo/library/md.c", + "${chip_root}/third_party/mbedtls/repo/library/oid.c", + "${chip_root}/third_party/mbedtls/repo/library/pk.c", + "${chip_root}/third_party/mbedtls/repo/library/pk_wrap.c", + "${chip_root}/third_party/mbedtls/repo/library/pkcs5.c", + "${chip_root}/third_party/mbedtls/repo/library/pkwrite.c", + "${chip_root}/third_party/mbedtls/repo/library/platform.c", + "${chip_root}/third_party/mbedtls/repo/library/platform_util.c", + "${chip_root}/third_party/mbedtls/repo/library/sha256.c", + "${chip_root}/third_party/mbedtls/repo/library/sha512.c", + "${chip_root}/third_party/mbedtls/repo/library/x509_create.c", + "${chip_root}/third_party/mbedtls/repo/library/x509write_csr.c", + ] + configs += [ ":${sdk_target_name}_config_freertos" ] + public_configs = [ ":${sdk_target_name}_config" ] + } + + source_set("${sdk_target_name}_soc") { + defines = [ "BL602_MATTER_SUPPORT" ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602/evb/src/boot/gcc/start.S", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602/evb/src/debug.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602/evb/src/strntoumax.c", + ] + cflags_c = [ "-Wno-format-truncation" ] + } + + config("${sdk_target_name}_config_BSP_Driver") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/RISCV/Device/Bouffalo/BL602/Startup", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/RISCV/Core/Include", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Device/Bouffalo/BL602/Peripherals", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Inc", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/platform_print", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/soft_crc", + ] + } + + source_set("${sdk_target_name}_BSP_Driver") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/ring_buffer", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/partition", + ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/Common/platform_print/platform_device.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_acomp.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_adc.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_aon.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_common.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_common_ext.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_dac.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_dma.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_ef_ctrl.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_glb.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_hbn.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_i2c.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_ir.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_l1c.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_mfg_efuse.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_mfg_flash.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_mfg_media.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_pds.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_pwm.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_romapi.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sdu.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sec_dbg.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sec_eng.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sf_cfg.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sf_cfg_ext.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sf_ctrl.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sflash.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_sflash_ext.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_spi.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_timer.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_tzc_sec.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_uart.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_xip_sflash.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/bl602_std/bl602_std/StdDriver/Src/bl602_xip_sflash_ext.c", + ] + + configs += [ ":${sdk_target_name}_config_freertos" ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_BSP_Driver", + ] + cflags_c = [ + "-Wno-sign-compare", + "-Wno-unused-variable", + ] + } + + config("${sdk_target_name}_config_freertos") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/config", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/panic", + ] + } + + source_set("${sdk_target_name}_bl602_freertos") { + defines = [ "portasmHANDLE_INTERRUPT=interrupt_entry" ] + include_dirs = [ "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V/chip_specific_extensions/RV32F_float_abi_single" ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/event_groups.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/list.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/misaligned/fp_asm.S", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/misaligned/misaligned_ldst.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/panic/panic_c.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V/port.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/GCC/RISC-V/portASM.S", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/portable/MemMang/heap_5.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/queue.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/stream_buffer.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/tasks.c", + "${bl_iot_sdk_root}/components/platform/soc/bl602/freertos_riscv_ram/timers.c", + ] + + cflags_c = [ + "-Wno-sign-compare", + "-Wno-old-style-declaration", + ] + + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_freertos", + ] + } + + config("${sdk_target_name}_config_hosal") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/hosal/include", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/include", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common", + ] + + cflags_cc = [ "-Wno-literal-suffix" ] + } + + source_set("${sdk_target_name}_hosal") { + sources = [ + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_adc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_boot2.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_chip.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_cks.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_clocktree.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_dac_audio.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_dma.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_efuse.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_flash.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_gpio.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_gpio_cli.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_hbn.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_i2c.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_ir.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_irq.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_pds.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_pm.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_pwm.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_rtc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_sec.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_sys.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_sys_cli.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_timer.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_uart.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_wdt.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_wdt_cli.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/bl_wifi.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_board.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_boot2.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_button.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_gpio.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_hbn.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_hbnram.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_hwtimer.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_ir.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_pds.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_sys.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hal_wifi.c", + + # hosal_adc.c is included by the code in wifi module + # "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_adc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_dac.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_dma.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_efuse.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_flash.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_gpio.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_i2c.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_ota.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_pwm.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_rng.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_rtc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_spi.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_timer.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_uart.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl602_hal/hosal_wdg.c", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_aes.c", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_common.c", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_pka.c", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_sha.c", + ] + + cflags_c = [ + "-Wno-sign-compare", + "-Wno-shadow", + "-Wno-unused-but-set-variable", + "-Wno-old-style-declaration", + "-Wno-stringop-overflow", + "-Wno-format-truncation", + ] + configs += [ + ":${sdk_target_name}_config_wifi", + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_stage", + ":${sdk_target_name}_config_sys", + ":${sdk_target_name}_config_fs", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_hosal", + ] + } + + config("${sdk_target_name}_config_fs") { + include_dirs = [ "${bl_iot_sdk_root}/components/fs/vfs/include" ] + } + + source_set("${sdk_target_name}_fs") { + sources = [ + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_adc.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_gpio.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_pwm.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_spi.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_uart.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs_file.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs_inode.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs_register.c", + ] + cflags_c = [ + "-Wno-sign-compare", + "-Wno-builtin-declaration-mismatch", + ] + configs += [ + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_stage", + ":${sdk_target_name}_config_fs", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_fs", + ] + } + + source_set("${sdk_target_name}_libc") { + sources = [ + "${bl_iot_sdk_root}/components/libc/newlibc/assert.c", + "${bl_iot_sdk_root}/components/libc/newlibc/stdatomic.c", + "${bl_iot_sdk_root}/components/libc/newlibc/syscalls.c", + ] + cflags_c = [ "-Wno-builtin-declaration-mismatch" ] + configs += [ ":${sdk_target_name}_config_freertos" ] + public_configs = [ ":${sdk_target_name}_config" ] + } + + config("${sdk_target_name}_config_stage") { + include_dirs = [ + "${bl_iot_sdk_root}/components/stage/easyflash4/inc", + "${bl_iot_sdk_root}/components/stage/yloop/include", + "${bl_iot_sdk_root}/components/stage/blog", + "${bl_iot_sdk_root}/components/stage/yloop/include/aos", + "${bl_iot_sdk_root}/components/stage/blfdt/inc", + "${bl_iot_sdk_root}/components/stage/cli/cli/include", + ] + } + + source_set("${sdk_target_name}_stage") { + sources = [ + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_addresses.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_empty_tree.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_overlay.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_ro.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_rw.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_strerror.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_sw.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_wip.c", + "${bl_iot_sdk_root}/components/stage/blog/blog.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/aos_freertos.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/device.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/local_event.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/select.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/yloop.c", + ] + cflags_c = [ "-Wno-sign-compare" ] + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_freertos", + ":${sdk_target_name}_config_fs", + ":${sdk_target_name}_config_sys", + ":${sdk_target_name}_config_utils", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_stage", + ] + } + + config("${sdk_target_name}_config_sys") { + include_dirs = [ + "${bl_iot_sdk_root}/components/sys/bloop/bloop/include", + "${bl_iot_sdk_root}/components/sys/bloop/looprt/include", + "${bl_iot_sdk_root}/components/sys/bloop/loopset/include", + "${bl_iot_sdk_root}/components/sys/blmtd/include", + ] + } + + source_set("${sdk_target_name}_sys") { + include_dirs = [ "${bl_iot_sdk_root}/components/sys/bltime/include" ] + sources = [ + "${bl_iot_sdk_root}/components/sys/blmtd/bl_mtd.c", + "${bl_iot_sdk_root}/components/sys/bltime/bl_sys_time.c", + ] + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_sys", + ] + } + + config("${sdk_target_name}_config_utils") { + include_dirs = [ "${bl_iot_sdk_root}/components/utils/include/" ] + } + + source_set("${sdk_target_name}_utils") { + sources = [ + "${bl_iot_sdk_root}/components/utils/src/utils_base64.c", + "${bl_iot_sdk_root}/components/utils/src/utils_crc.c", + "${bl_iot_sdk_root}/components/utils/src/utils_dns.c", + "${bl_iot_sdk_root}/components/utils/src/utils_fec.c", + "${bl_iot_sdk_root}/components/utils/src/utils_getopt.c", + "${bl_iot_sdk_root}/components/utils/src/utils_hex.c", + "${bl_iot_sdk_root}/components/utils/src/utils_hexdump.c", + "${bl_iot_sdk_root}/components/utils/src/utils_hmac_sha1_fast.c", + "${bl_iot_sdk_root}/components/utils/src/utils_list.c", + "${bl_iot_sdk_root}/components/utils/src/utils_log.c", + "${bl_iot_sdk_root}/components/utils/src/utils_memp.c", + "${bl_iot_sdk_root}/components/utils/src/utils_notifier.c", + "${bl_iot_sdk_root}/components/utils/src/utils_psk_fast.c", + "${bl_iot_sdk_root}/components/utils/src/utils_rbtree.c", + "${bl_iot_sdk_root}/components/utils/src/utils_sha256.c", + "${bl_iot_sdk_root}/components/utils/src/utils_string.c", + "${bl_iot_sdk_root}/components/utils/src/utils_time.c", + "${bl_iot_sdk_root}/components/utils/src/utils_tlv_bl.c", + ] + + cflags_c = [ + "-Wno-shadow", + "-Wno-sign-compare", + ] + configs += [ + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_utils", + ] + } + + config("${sdk_target_name}_ble_config") { + include_dirs = [ + "${bl_iot_sdk_root}/components/network/ble/blecontroller/ble_inc", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/include", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/include/bluetooth", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/zephyr", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/port/include", + "${bl_iot_sdk_root}/components/network/ble/blestack/src", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host", + ] + + defines = [ + "BFLB_BLE", + "CONFIG_SET_TX_PWR", + "CFG_CON=1", + "CFG_BLE", + "CFG_SLEEP", + "CFG_BT_RESET", + "CONFIG_BT_PERIPHERAL=1", + "CFG_BLE_TX_BUFF_DATA=2", + "CONFIG_BT_GATT_DYNAMIC_DB", + "CONFIG_BT_GATT_SERVICE_CHANGED", + "CONFIG_BT_SETTINGS_CCC_LAZY_LOADING", + "CONFIG_BT_KEYS_OVERWRITE_OLDEST", + "CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS", + "CONFIG_BT_BONDABLE", + "CONFIG_BT_ASSERT", + "CFG_BLE_STACK_DBG_PRINT", + ] + + cflags_cc = [ "-Wno-conversion" ] + } + + source_set("${sdk_target_name}_ble") { + defines = [ + "CONFIG_BT_L2CAP_DYNAMIC_CHANNEL", + "CONFIG_BT_GATT_CLIENT", + "CONFIG_BT_CONN=1", + "CONFIG_BT_GATT_DIS_PNP", + "CONFIG_BT_GATT_DIS_SERIAL_NUMBER", + "CONFIG_BT_GATT_DIS_FW_REV", + "CONFIG_BT_GATT_DIS_HW_REV", + "CONFIG_BT_GATT_DIS_SW_REV", + "CONFIG_BT_ECC", + "CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING", + "CONFIG_BT_HCI_VS_EVT_USER", + "CONFIG_BT_SETTINGS_USE_PRINTK", + ] + + libs = [ "${bl_iot_sdk_root}/components/network/ble/blecontroller_602_m0s1/lib/libblecontroller_602_m0s1.a" ] + + include_dirs = [ + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/tinycrypt/include/tinycrypt", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/misc", + ] + + sources = [ + "${bl_iot_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper/bl_hci_wrapper.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/atomic_c.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/buf.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/dec.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/log.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/poll.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/work_q.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/hci_onchip/hci_driver.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/att.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/bl_host_assist.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/conn.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/crypto.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/gatt.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/hci_core.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/l2cap.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/settings.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/uuid.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/port/bl_port.c", + ] + + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_freertos", + ":${sdk_target_name}_config_utils", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_ble_config", + ] + + cflags_c = [ + "-Wno-sign-compare", + "-Wno-unused-but-set-variable", + "-Wno-misleading-indentation", + "-Wno-format", + "-Wno-format-nonliteral", + "-Wno-format-security", + "-Wno-unused-function", + "-Wno-incompatible-pointer-types", + "-Wno-discarded-qualifiers", + ] + } + + config("${sdk_target_name}_config_blcrypto_suite") { + include_dirs = [ + "${bl_iot_sdk_root}/components/security/blcrypto_suite/inc", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/inc/blcrypto_suite", + ] + } + + source_set("${sdk_target_name}_blcrypto_suite") { + include_dirs = [ + "${bl_iot_sdk_root}/components/security/blcrypto_suite/priv_inc", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/priv_inc", + ] + sources = [ + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_aes.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_bignum.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_ecp.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_ecp_curves.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_export_fw.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_hacc.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_hacc_glue.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_hacc_secp256r1_mul.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_platform_util.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_porting.c", + "${bl_iot_sdk_root}/components/security/blcrypto_suite/src/blcrypto_suite_supplicant_api.c", + ] + + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_blcrypto_suite", + ] + } + + config("${sdk_target_name}_config_wifi") { + defines = [ + "CFG_TXDESC=2", + "CFG_STA_MAX=1", + "BL_CHIP_NAME=\"BL602\"", + "TD_DIAGNOSIS_STA", + "OS_USING_FREERTOS", + ] + include_dirs = [ + "${bl_iot_sdk_root}/components/os/bl_os_adapter/bl_os_adapter/include", + "${bl_iot_sdk_root}/components/os/bl_os_adapter/bl_os_adapter/include/bl_os_adapter", + "${bl_iot_sdk_root}/components/network/wifi/include", + "${bl_iot_sdk_root}/components/network/wifi_hosal/include", + "${bl_iot_sdk_root}/components/network/wifi_manager", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/include", + ] + + cflags_c = [ "-Wno-sign-compare" ] + cflags_cc = [ "-Wno-sign-compare" ] + } + + source_set("${sdk_target_name}_wifi") { + defines = [ "BL602_MATTER_SUPPORT" ] + + include_dirs = [ + "${bl_iot_sdk_root}/components/os/bl_os_adapter/bl_os_adapter", + "${bl_iot_sdk_root}/components/network/dns_server/include", + "${bl_iot_sdk_root}/components/network/dns_server/include", + "${bl_iot_sdk_root}/components/network/rfparam_adapter_tmp/rftlv", + "${bl_iot_sdk_root}/components/network/wifi/modules/supplicant/src/sae", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/include", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/include/bl_supplicant", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/port", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/ap", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/common", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/eap_peer", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/rsn_supp", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/test", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/port/include", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/utils", + ] + + sources = [ "${bl_iot_sdk_root}/components/os/bl_os_adapter/bl_os_adapter/bl_os_hal.c" ] + + sources += [ + "${bl_iot_sdk_root}/components/network/rfparam_adapter_tmp/rftlv/phy_rftlv.c", + "${bl_iot_sdk_root}/components/network/wifi_hosal/port/wifi_hosal_bl602.c", + "${bl_iot_sdk_root}/components/network/wifi_hosal/wifi_hosal.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_cmds.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_irqs.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_main.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_mod_params.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_msg_rx.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_msg_tx.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_platform.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_rx.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_tx.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/bl_utils.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/ipc_host.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/stateMachine.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_api.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_cli.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_event.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_ext.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_profile.c", + "${bl_iot_sdk_root}/components/network/wifi_manager/bl60x_wifi_driver/wifi_netif.c", + + #wap_supplicant + "${bl_iot_sdk_root}/components/network/dns_server/src/dns_server.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/port/os_bl.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/ap/ap_config.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/ap/wpa_auth_ie.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/ap/wpa_auth_rsn_ccmp_only.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_hostap.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wpa3.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wpa_main.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wpas_glue.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/bl_supplicant/bl_wps.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/common/sae.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/common/wpa_common.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-cbc.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-internal-bl.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-omac1.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-unwrap.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/aes-wrap.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/crypto_internal-modexp.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/dh_group5.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/dh_groups.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/md5-internal.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/md5.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/rc4.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/sha1-internal.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/sha1-pbkdf2.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/sha1.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/sha256-internal.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/sha256-prf.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/crypto/sha256.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/eap_peer/eap_common.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/rsn_supp/pmksa_cache.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/rsn_supp/wpa.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/rsn_supp/wpa_ie.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/utils/common.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/utils/wpa_debug.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/utils/wpabuf.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_attr_build.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_attr_parse.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_attr_process.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_common.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_dev_attr.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_enrollee.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_registrar.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/src/wps/wps_validate.c", + "${bl_iot_sdk_root}/components/security/wpa_supplicant/test/test_crypto-bl.c", + ] + + libs = [ "${bl_iot_sdk_root}/components/network/wifi/lib/libwifi.a" ] + + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_stage", + ":${sdk_target_name}_config_lwip", + ":${sdk_target_name}_config_blcrypto_suite", + ":${sdk_target_name}_config_freertos", + ":${sdk_target_name}_config_utils", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_wifi", + ] + + deps = [ ":${sdk_target_name}_hosal" ] + + cflags_c = [ + "-Wno-unused-function", + "-Wno-shadow", + "-Wno-old-style-declaration", + "-Wno-incompatible-pointer-types", + "-Wno-format-security", + "-Wno-format-nonliteral", + "-Wno-unused-but-set-variable", + "-Wno-unused-variable", + "-fcommon", + ] + } + + config("${sdk_target_name}_config_lwip") { + include_dirs = [ + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/config", + "${bl_iot_sdk_root}/components/network/lwip/src/include", + "${bl_iot_sdk_root}/components/network/lwip/src/include/lwip/apps", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/hook", + ] + + defines = [ + "LWIP_IPV6=1", + "LWIP_IPV4=1", + "LWIP_IPV6_DHCP6=1", + "LWIP_IPV6_SCOPES=0", + "LWIP_AUTOIP=1", + "LWIP_IPV6_MLD=1", + "LWIP_ND6_RDNSS_MAX_DNS_SERVERS=1", + "PBUF_POOL_SIZE=20", + "PBUF_POOL_BUFSIZE=(1280+150)", + "CONFIG_ENABLE_IPV6_ADDR_CALLBACK", + "CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT", + "CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT", + ] + } + + source_set("${sdk_target_name}_lwip") { + sources = [ + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/ethernetif.c", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/sys_arch.c", + ] + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/netif/bridgeif.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/bridgeif_fdb.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/ethernet.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/slipif.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/zepif.c", + ] + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/core/def.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/dns.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/inet_chksum.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/init.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ip.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/mem.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/memp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/netif.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/pbuf.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/raw.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/stats.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/sys.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/tcp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/tcp_in.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/tcp_out.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/timeouts.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/udp.c", + ] + + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/autoip.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/dhcp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/etharp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/icmp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/igmp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/ip4.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/ip4_addr.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/ip4_frag.c", + ] + + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/dhcp6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ethip6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/icmp6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/inet6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6_addr.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6_frag.c", + + #"${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6_route_table.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/mld6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/nd6.c", + ] + + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/api/api_lib.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/api_msg.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/err.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/if_api.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/netbuf.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/netifapi.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/sockets.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/tcpip.c", + ] + sources += + [ "${bl_iot_sdk_root}/components/network/lwip/src/apps/mdns/mdns.c" ] + sources += + [ "${bl_iot_sdk_root}/components/network/lwip_dhcpd/dhcp_server_raw.c" ] + + configs += [ ":${sdk_target_name}_config_freertos" ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_lwip", + ] + } + + group(sdk_target_name) { + public_deps = [ + ":${sdk_target_name}_BSP_Driver", + ":${sdk_target_name}_bl602_freertos", + ":${sdk_target_name}_blcrypto_suite", + ":${sdk_target_name}_ble", + ":${sdk_target_name}_code", + ":${sdk_target_name}_fs", + ":${sdk_target_name}_hosal", + ":${sdk_target_name}_libc", + ":${sdk_target_name}_lwip", + ":${sdk_target_name}_soc", + ":${sdk_target_name}_stage", + ":${sdk_target_name}_sys", + ":${sdk_target_name}_utils", + ":${sdk_target_name}_wifi", + ] + } +} diff --git a/third_party/bouffalolab/bl702/BUILD.gn b/third_party/bouffalolab/bl702/BUILD.gn index 9842ba2b23ec24..3fe15787e3e0c8 100644 --- a/third_party/bouffalolab/bl702/BUILD.gn +++ b/third_party/bouffalolab/bl702/BUILD.gn @@ -14,14 +14,14 @@ import("//build_overrides/bouffalolab_iot_sdk.gni") import("//build_overrides/openthread.gni") -import("${bl702_sdk_build_root}/bl702_sdk.gni") +import("${bouffalolab_iot_sdk_build_root}/bl702/bl_iot_sdk.gni") declare_args() { - # Build target to use for bl702 SDK. Use this to set global SDK defines. - bl702_sdk_target = "" + # Build target to use for Bouffalo Lab IOT SDK. Use this to set global SDK defines. + bl_iot_sdk_target = "" } -assert(bl702_sdk_target != "", "bl702_sdk_target must be specified") +assert(bl_iot_sdk_target != "", "bl_iot_sdk_target must be specified") config("bl702_mbedtls_config") { defines = [ "MBEDTLS_CONFIG_FILE=\"bl702-chip-mbedtls-config.h\"" ] @@ -32,6 +32,6 @@ mbedtls_target("mbedtls") { include_dirs = [ "${chip_root}/src/platform/bouffalolab/BL702" ] } -group("bl702_sdk") { - public_deps = [ bl702_sdk_target ] +group("bl_iot_sdk") { + public_deps = [ bl_iot_sdk_target ] } diff --git a/third_party/bouffalolab/bl702/bl702_executable.gni b/third_party/bouffalolab/bl702/bl702_executable.gni deleted file mode 100644 index e50120b0255f24..00000000000000 --- a/third_party/bouffalolab/bl702/bl702_executable.gni +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build_overrides/build.gni") -import("//build_overrides/chip.gni") - -import("//build_overrides/bouffalolab_iot_sdk.gni") -import("${build_root}/toolchain/flashable_executable.gni") - -template("bl702_executable") { - output_base_name = get_path_info(invoker.output_name, "name") - - objcopy_image_name = output_base_name + ".bin" - objcopy_image_format = "binary" - - objcopy = "riscv64-unknown-elf-objcopy" - if ("linux" == host_os) { - objcopy = "${bouffalolab_sdk_root}/toolchain/riscv/Linux/bin/riscv64-unknown-elf-objcopy" - } else if ("mac" == host_os || "darwin" == host_os) { - objcopy = "${bouffalolab_sdk_root}/toolchain/riscv/Darwin/bin/riscv64-unknown-elf-objcopy" - } - - # Copy flashing dependencies to the output directory so that the output - # is collectively self-contained; this allows flashing to work reliably - # even if the build and flashing steps take place on different machines - # or in different containers. - flashing_runtime_target = target_name + ".flashing_runtime" - flashing_script_inputs = [ - "${chip_root}/scripts/flashing/bouffalolab_firmware_utils.py", - "${chip_root}/scripts/flashing/firmware_utils.py", - - "${chip_root}/examples/platform/bouffalolab/bl702/flash_config/partition_cfg_2M.toml", - ] - copy(flashing_runtime_target) { - sources = flashing_script_inputs - outputs = [ "${root_out_dir}/{{source_file_part}}" ] - } - - flashing_script_generator = - "${chip_root}/scripts/flashing/gen_flashing_script.py" - flashing_script_name = output_base_name + ".flash.py" - flashing_options = [ "bouffalolab" ] - flashing_options += [ "--chipname" ] - flashing_options += [ "bl702" ] - flashing_options += [ "--xtal" ] - flashing_options += [ "32M" ] - flashing_options += [ "--pt" ] - flashing_options += - [ rebase_path("partition_cfg_2M.toml", root_out_dir, root_out_dir) ] - flashing_options += [ "--ota" ] - flashing_options += [ "ota_images/" ] - - # set 2000000 baudrate for image download by default - flashing_options += [ "--baudrate" ] - flashing_options += [ "2000000" ] - - flashable_executable(target_name) { - forward_variables_from(invoker, "*") - data_deps = [ ":${flashing_runtime_target}" ] - } -} diff --git a/third_party/bouffalolab/bl702/bl702_sdk.gni b/third_party/bouffalolab/bl702/bl702_sdk.gni deleted file mode 100644 index ebc49817e068e3..00000000000000 --- a/third_party/bouffalolab/bl702/bl702_sdk.gni +++ /dev/null @@ -1,821 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//args.gni") -import("//build_overrides/bouffalolab_iot_sdk.gni") -import("//build_overrides/chip.gni") -import("//build_overrides/mbedtls.gni") -import("//build_overrides/openthread.gni") -import("${chip_root}/src/lib/lib.gni") -import("bl702_board.gni") - -import("${mbedtls_root}/mbedtls.gni") - -declare_args() { - # Location of the bl702 SDK. - bl702_sdk_root = "${chip_root}/third_party/bouffalolab/repo" - - enable_zigbee = false - - enable_cdc_module = false -} - -assert(bl702_sdk_root != "", "bl702_sdk_root must be specified") - -# Defines an bl702 SDK build target. -# -# Parameters: -# bl702_sdk_root - The location of the bl702 SDK. -# sources - The sources files to build. -template("bl702_sdk") { - sdk_target_name = target_name - - if (defined(invoker.bl702_sdk_root)) { - bl702_sdk_root = invoker.bl702_sdk_root - } - - if (defined(invoker.enable_zigbee)) { - enable_zigbee = invoker.enable_zigbee - } - - if (defined(invoker.enable_cdc_module)) { - enable_cdc_module = invoker.enable_cdc_module - } - - config("${sdk_target_name}_config") { - include_dirs = [] - if (defined(invoker.include_dirs)) { - include_dirs += invoker.include_dirs - } - - defines = [ - "CONFIG_RENDEZVOUS_MODE=2", - "CONFIG_ENABLE_PW_RPC=0", - "__FILENAME__=strrchr(__FILE__,'/')?strrchr(__FILE__,'/')+1:__FILE__", - "OT_FREERTOS_ENABLE=1", - ] - - if (defined(invoker.defines)) { - defines += invoker.defines - } - } - - config("${sdk_target_name}_plat_config") { - _include_dirs = [ - "${bl702_sdk_root}", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/config", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V/chip_specific_extensions/RV32F_float_abi_single", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/panic", - - "${bl702_sdk_root}/components/sys/blmtd/include", - "${bl702_sdk_root}/components/utils/include/", - - "${bl702_sdk_root}/components/stage/yloop/include", - "${bl702_sdk_root}/components/stage/blfdt/inc", - "${bl702_sdk_root}/components/stage/blog/", - "${bl702_sdk_root}/components/stage/cli/cli/include", - "${bl702_sdk_root}/components/stage/coredump/inc", - "${bl702_sdk_root}/components/stage/easyflash4/inc", - - "${bl702_sdk_root}/components/fs/vfs/include", - - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Board", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/risc-v/Core/Include", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/regs", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/startup", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/inc", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/soft_crc", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/misc", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/ring_buffer", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/device", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/list", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/memheap", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Common/platform", - - "${bl702_sdk_root}/components/platform/hosal/bl702_hal", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/include", - "${bl702_sdk_root}/components/platform/hosal/include", - "${bl702_sdk_root}/components/platform/hosal/sec_common", - ] - - defines = [ - "ARCH_RISCV", - "bl706_iot=1", - ] - - defines += board_defines - - cflags = [] - cflags_c = [] - if (defined(invoker.freertos_config)) { - cflags_c += [ - "-include", - rebase_path("${invoker.freertos_config}", root_build_dir), - ] - } - - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - - if (defined(invoker.defines)) { - defines += invoker.defines - } - } - - source_set("${sdk_target_name}_drv") { - defines = [ - "BFLB_USE_ROM_DRIVER=1", - "BFLB_USE_HAL_DRIVER=1", - "CFG_USE_XTAL32K=1", - "CFG_BLE_ENABLE=1", - "BL702", - ] - - include_dirs = - [ "${bl702_sdk_root}/components/network/ble/blecontroller/ble_inc/" ] - - sources = [ - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_adc.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_boot2.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_chip.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_cks.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_dma.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_efuse.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_flash.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_gpio.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_hbn.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_irq.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_pds.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_psram.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_pwm.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_rtc.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_sec.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_sys.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_timer.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_uart.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_wdt.c", - - # "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_sec_aes.c", - # "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_sec_sha.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_wireless.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_board.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_boot2.c", - - # "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_tcal.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_button.c", - - # "${bl702_sdk_root}/components/platform/hosal/bl702_hal/bl_emac.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_gpio.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_hbn.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_hwtimer.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_pds.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_sys.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_adc.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_dac.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_dma.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_flash.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_gpio.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_i2c.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_ota.c", - - # "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_spi.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_pwm.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_rng.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_rtc.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_timer.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_uart.c", - "${bl702_sdk_root}/components/platform/hosal/bl702_hal/hosal_wdg.c", - - #"${bl702_sdk_root}/components/platform/hosal/bl702_hal/hal_uart.c", - ] - - sources += [ - "${bl702_sdk_root}/components/platform/hosal/sec_common/bl_sec_aes.c", - "${bl702_sdk_root}/components/platform/hosal/sec_common/bl_sec_pka.c", - - #"${bl702_sdk_root}/components/platform/hosal/sec_common/bl_sec_sha.c", - ] - - libs = [ "${bl702_sdk_root}/components/platform/soc/bl702/bl702_rf/lib/libbl702_rf.a" ] - - cflags_c = [ - "-Wno-unused-variable", - "-Wno-enum-conversion", - "-Wno-sign-compare", - "-Wno-old-style-declaration", - "-Wno-stringop-overflow", - "-Wno-format-truncation", - ] - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ] - } - - source_set("${sdk_target_name}_app") { - sources = [] - if (defined(invoker.sources)) { - sources += invoker.sources - } - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ] - } - - source_set("${sdk_target_name}_cdc") { - include_dirs = [ - "${bl702_sdk_root}/components/fs/vfs/include", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Inc", - ] - - defines = [ - "BFLB_USE_ROM_DRIVER=1", - "BFLB_USE_HAL_DRIVER=1", - ] - - sources = [ - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/bl702_hal_pcd.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/bl702_usb_cdc.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usb_device.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_cdc.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_cdc_if.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_conf.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_core.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_ctlreq.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_desc.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_ioreq.c", - ] - - cflags_c = [ "-Wno-sign-compare" ] - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ] - } - - source_set("${sdk_target_name}_bflb_platform") { - defines = [ - "BFLB_USE_ROM_DRIVER=1", - "BFLB_USE_HAL_DRIVER=1", - ] - - include_dirs = [ "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/hal_drv/inc" ] - - sources = [ - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_acomp.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_adc.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_aon.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_cam.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_clock.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_common.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_dac.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_dma.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_ef_ctrl.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_glb.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_hbn.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_i2c.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_i2s.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_ir.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_l1c.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_mjpeg.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_pds.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_psram.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_pwm.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_qdec.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_romapi.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sec_dbg.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sec_eng.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sf_cfg.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sf_cfg_ext.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sf_ctrl.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sflash.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sflash_ext.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_spi.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_timer.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_uart.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_usb.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_xip_sflash.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_xip_sflash_ext.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/misc/misc.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/ring_buffer/ring_buffer.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/soft_crc/softcrc.c", - ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ] - cflags_c = [ - "-Wno-sign-compare", - "-Wno-unused-variable", - ] - } - - source_set("${sdk_target_name}_plat") { - defines = [ - "portasmHANDLE_INTERRUPT=interrupt_entry", - "CFG_CPP_ENABLE=1", - "BL_SDK_VER=\"1.0\"", - "BFLB_USE_ROM_DRIVER=1", - "BFLB_USE_HAL_DRIVER=1", - ] - - sources = [ - "${bl702_sdk_root}/components/libc/newlibc/assert.c", - "${bl702_sdk_root}/components/libc/newlibc/stdatomic.c", - "${bl702_sdk_root}/components/libc/newlibc/syscalls.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702/evb/src/boot/gcc/start.S", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702/evb/src/debug.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702/evb/src/strntoumax.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702/evb/src/vprint.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/event_groups.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/list.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/misaligned/fp_asm.S", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/misaligned/misaligned_ldst.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/panic/panic_c.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V/port.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V/portASM.S", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/MemMang/heap_5.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/MemMang/heap_5_psram.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/queue.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/stream_buffer.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/tasks.c", - "${bl702_sdk_root}/components/platform/soc/bl702/bl702_freertos/timers.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_addresses.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_empty_tree.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_overlay.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_ro.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_rw.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_strerror.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_sw.c", - "${bl702_sdk_root}/components/stage/blfdt/src/fdt_wip.c", - "${bl702_sdk_root}/components/stage/blog/blog.c", - "${bl702_sdk_root}/components/stage/easyflash4/src/easyflash.c", - "${bl702_sdk_root}/components/stage/easyflash4/src/ef_env.c", - "${bl702_sdk_root}/components/stage/easyflash4/src/ef_port.c", - "${bl702_sdk_root}/components/stage/easyflash4/src/ef_utils.c", - "${bl702_sdk_root}/components/sys/blmtd/bl_mtd.c", - "${bl702_sdk_root}/components/utils/src/utils_list.c", - "${bl702_sdk_root}/components/utils/src/utils_log.c", - "${bl702_sdk_root}/components/utils/src/utils_string.c", - ] - - cflags_c = [ - "-Wno-old-style-declaration", - "-Wno-enum-conversion", - "-Wno-sign-compare", - ] - cflags_c += [ - "-Wno-builtin-declaration-mismatch", - "-Wno-format-truncation", - ] - - sources += [ - "${bl702_sdk_root}/components/fs/vfs/device/vfs_adc.c", - "${bl702_sdk_root}/components/fs/vfs/device/vfs_gpio.c", - "${bl702_sdk_root}/components/fs/vfs/device/vfs_pwm.c", - "${bl702_sdk_root}/components/fs/vfs/device/vfs_spi.c", - "${bl702_sdk_root}/components/fs/vfs/device/vfs_uart.c", - "${bl702_sdk_root}/components/fs/vfs/src/vfs.c", - "${bl702_sdk_root}/components/fs/vfs/src/vfs_file.c", - "${bl702_sdk_root}/components/fs/vfs/src/vfs_inode.c", - "${bl702_sdk_root}/components/fs/vfs/src/vfs_register.c", - "${bl702_sdk_root}/components/stage/yloop/src/aos_freertos.c", - "${bl702_sdk_root}/components/stage/yloop/src/device.c", - "${bl702_sdk_root}/components/stage/yloop/src/local_event.c", - "${bl702_sdk_root}/components/stage/yloop/src/select.c", - "${bl702_sdk_root}/components/stage/yloop/src/yloop.c", - "${bl702_sdk_root}/components/utils/src/utils_base64.c", - "${bl702_sdk_root}/components/utils/src/utils_crc.c", - "${bl702_sdk_root}/components/utils/src/utils_dns.c", - "${bl702_sdk_root}/components/utils/src/utils_fec.c", - "${bl702_sdk_root}/components/utils/src/utils_getopt.c", - "${bl702_sdk_root}/components/utils/src/utils_hex.c", - "${bl702_sdk_root}/components/utils/src/utils_hexdump.c", - "${bl702_sdk_root}/components/utils/src/utils_hmac_sha1_fast.c", - "${bl702_sdk_root}/components/utils/src/utils_memp.c", - "${bl702_sdk_root}/components/utils/src/utils_notifier.c", - "${bl702_sdk_root}/components/utils/src/utils_psk_fast.c", - "${bl702_sdk_root}/components/utils/src/utils_rbtree.c", - "${bl702_sdk_root}/components/utils/src/utils_sha256.c", - "${bl702_sdk_root}/components/utils/src/utils_time.c", - "${bl702_sdk_root}/components/utils/src/utils_tlv_bl.c", - ] - - cflags_c += [ "-Wno-shadow" ] - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ] - } - - config("${sdk_target_name}_ble_config") { - _include_dirs = [ - "${bl702_sdk_root}/components/network/ble/blestack/src/include", - "${bl702_sdk_root}/components/network/ble/blestack/src", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/include", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/include/misc", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/include/zephyr", - "${bl702_sdk_root}/components/network/ble/blestack/src/port/include", - "${bl702_sdk_root}/components/network/ble/blestack/src/include/bluetooth", - "${bl702_sdk_root}/components/network/ble/blecontroller/ble_inc", - "${bl702_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", - "${bl702_sdk_root}/components/network/ble/blestack/src/host", - ] - - defines = [ - "CONFIG_SET_TX_PWR", - "CFG_BLE_ENABLE", - "BFLB_BLE", - "CFG_BLE", - "CFG_SLEEP", - "OPTIMIZE_DATA_EVT_FLOW_FROM_CONTROLLER", - "CFG_BT_RESET", - "CFG_CON=1", - "CFG_BLE_TX_BUFF_DATA=2", - "CONFIG_BT_PERIPHERAL=1", - "CONFIG_BT_L2CAP_DYNAMIC_CHANNEL", - "CONFIG_BT_GATT_CLIENT", - "CONFIG_BT_CONN=1", - "CONFIG_BT_GATT_DIS_PNP", - "CONFIG_BT_GATT_DIS_SERIAL_NUMBER", - "CONFIG_BT_GATT_DIS_FW_REV", - "CONFIG_BT_GATT_DIS_HW_REV", - "CONFIG_BT_GATT_DIS_SW_REV", - "CONFIG_BT_ECC", - "CONFIG_BT_GATT_DYNAMIC_DB", - "CONFIG_BT_GATT_SERVICE_CHANGED", - "CONFIG_BT_KEYS_OVERWRITE_OLDEST", - "CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING", - "CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS", - "CONFIG_BT_BONDABLE", - "CONFIG_BT_HCI_VS_EVT_USER", - "CONFIG_BT_ASSERT", - "CONFIG_BT_SETTINGS_CCC_LAZY_LOADING", - "CONFIG_BT_SETTINGS_USE_PRINTK", - "CFG_BLE_STACK_DBG_PRINT", - ] - - cflags = [] - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - } - - source_set("${sdk_target_name}_ble") { - defines = [ "BL702=1" ] - - include_dirs = [ - "${bl702_sdk_root}/components/network/ble/blestack/src/include", - "${bl702_sdk_root}/components/network/ble/blecontroller/ble_inc", - "${bl702_sdk_root}/components/network/ble/blestack/src/host", - "${bl702_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", - "${bl702_sdk_root}/components/network/ble/blestack/src/common", - "${bl702_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/tinycrypt/include/tinycrypt", - ] - - sources = [ - "${bl702_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper/bl_hci_wrapper.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/atomic_c.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/buf.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/dec.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/log.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/poll.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/common/work_q.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/hci_onchip/hci_driver.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/att.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/bl_host_assist.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/conn.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/crypto.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/gatt.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/hci_core.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/l2cap.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/settings.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/host/uuid.c", - "${bl702_sdk_root}/components/network/ble/blestack/src/port/bl_port.c", - ] - - libs = [ "${bl702_sdk_root}/components/network/ble/blecontroller_702_std/lib/libblecontroller_702_std.a" ] - - configs += [ ":${sdk_target_name}_plat_config" ] - public_configs = [ ":${sdk_target_name}_ble_config" ] - - cflags_c = [ - "-Wno-sign-compare", - "-Wno-unused-but-set-variable", - "-Wno-misleading-indentation", - "-Wno-format", - "-Wno-format-nonliteral", - "-Wno-format-security", - "-Wno-unused-function", - "-Wno-incompatible-pointer-types", - "-Wno-discarded-qualifiers", - ] - } - - config("${sdk_target_name}_otport_config") { - _include_dirs = [ - "${chip_root}/platform/bl702", - "${chip_root}/third_party/openthread/repo/src/core", - "${chip_root}/third_party/openthread/repo/examples/platforms", - "${bl702_sdk_root}/components/network/thread/openthread_port/include", - ] - - cflags = [] - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - } - - source_set("${sdk_target_name}_otport") { - import("//build_overrides/openthread.gni") - - include_dirs = [ - "${bl702_sdk_root}/components/network/lmac154/include", - "${openthread_root}/examples/platforms/utils/", - "${openthread_root}/examples", - ] - - sources = [ - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_alarm.c", - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_diag.c", - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_misc.c", - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_radio.c", - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_settings.c", - "${bl702_sdk_root}/components/network/thread/openthread_port/ot_uart.c", - - # "${bl702_sdk_root}/components/network/thread/openthread_port/ot_system.c", - # "${bl702_sdk_root}/components/network/thread/openthread_port/ot_freertos.c", - # "${bl702_sdk_root}/components/network/thread/openthread_port/ot_memory.c" - ] - - libs = [ "${bl702_sdk_root}/components/network/lmac154/lib/liblmac154.a" ] - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ":${sdk_target_name}_otport_config", - ] - - public_deps = [ - ":${sdk_target_name}_plat", - "${bl702_sdk_build_root}:mbedtls", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", - "${openthread_root}/src/core:libopenthread_core_headers", - ] - } - - config("${sdk_target_name}_lwip_port_config") { - _include_dirs = [ - "${bl702_sdk_root}/components/network/lwip/lwip-port", - "${bl702_sdk_root}/components/network/lwip/lwip-port/config", - "${bl702_sdk_root}/components/stage/virt_net/include", - "${bl702_sdk_root}/components/stage/throughput/bl702/inc", - ] - - defines = [ - "TCPIP_THREAD_PRIO=24", - "CFG_ETHERNET_ENABLE=1", - ] - - cflags = [] - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - - cflags += [ - "-Wno-conversion", - "-Wno-unused-function", - ] - } - - source_set("${sdk_target_name}_lwip_port") { - defines = [ - "SPI_WIFI_RXBUFF_IN_PSRAM=1", - "VIRT_NET_SPI_RX_TASK_PRIORITY=25", - ] - - # include_dirs = [ - # "${bl702_sdk_root}/components/network/lwip/lwip-port/arch", - # "${bl702_sdk_root}/components/network/lwip/lwip-port/FreeRTOS", - # "${bl702_sdk_root}/components/stage/throughput" - # ] - - # sources = [ - # "${bl702_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/ethernetif.c", - # "${bl702_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/sys_arch.c" - # ] - - # sources += [ - # "${bl702_sdk_root}/components/stage/throughput/bl702/src/tp_spi_master.c", - # ] - # sources += [ - # "${bl702_sdk_root}/components/stage/virt_net/src/virt_net.c", - # "${bl702_sdk_root}/components/stage/virt_net/src/virt_net_spi.c", - # ] - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ":${sdk_target_name}_lwip_port_config", - ":${sdk_target_name}_lwip_config", - ] - - cflags = [ "-Wno-sign-compare" ] - } - - config("${sdk_target_name}_lwip_config") { - _include_dirs = [ - "${bl702_sdk_root}/components/network/lwip/src/include", - # "${bl702_sdk_root}/components/network/lwip_mdns", - ] - - defines = [ - "LWIP_IPV6=1", - "LWIP_IPV4=1", - "LWIP_IPV6_DHCP6=1", - "LWIP_IPV6_SCOPES=0", - "PBUF_POOL_SIZE=12", - "PBUF_POOL_BUFSIZE=(1280+150)", - ] - - cflags = [] - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - } - - source_set("${sdk_target_name}_lwip") { - sources = [ - "${bl702_sdk_root}/components/network/lwip/src/api/api_lib.c", - "${bl702_sdk_root}/components/network/lwip/src/api/api_msg.c", - "${bl702_sdk_root}/components/network/lwip/src/api/err.c", - "${bl702_sdk_root}/components/network/lwip/src/api/if_api.c", - "${bl702_sdk_root}/components/network/lwip/src/api/netbuf.c", - "${bl702_sdk_root}/components/network/lwip/src/api/netifapi.c", - "${bl702_sdk_root}/components/network/lwip/src/api/sockets.c", - "${bl702_sdk_root}/components/network/lwip/src/api/tcpip.c", - ] - - sources += [ - "${bl702_sdk_root}/components/network/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c", - "${bl702_sdk_root}/components/network/lwip/src/apps/altcp_tls/altcp_tls_mbedtls_mem.c", - ] - - sources += [ - "${bl702_sdk_root}/components/network/lwip/src/core/def.c", - "${bl702_sdk_root}/components/network/lwip/src/core/dns.c", - "${bl702_sdk_root}/components/network/lwip/src/core/inet_chksum.c", - "${bl702_sdk_root}/components/network/lwip/src/core/init.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ip.c", - "${bl702_sdk_root}/components/network/lwip/src/core/mem.c", - "${bl702_sdk_root}/components/network/lwip/src/core/memp.c", - "${bl702_sdk_root}/components/network/lwip/src/core/netif.c", - "${bl702_sdk_root}/components/network/lwip/src/core/pbuf.c", - "${bl702_sdk_root}/components/network/lwip/src/core/raw.c", - "${bl702_sdk_root}/components/network/lwip/src/core/stats.c", - "${bl702_sdk_root}/components/network/lwip/src/core/sys.c", - "${bl702_sdk_root}/components/network/lwip/src/core/tcp.c", - "${bl702_sdk_root}/components/network/lwip/src/core/tcp_in.c", - "${bl702_sdk_root}/components/network/lwip/src/core/tcp_out.c", - "${bl702_sdk_root}/components/network/lwip/src/core/timeouts.c", - "${bl702_sdk_root}/components/network/lwip/src/core/udp.c", - "${bl702_sdk_root}/components/network/lwip/src/include/lwip/priv/api_msg.h", - "${bl702_sdk_root}/components/network/lwip/src/include/lwip/priv/memp_std.h", - "${bl702_sdk_root}/components/network/lwip/src/include/lwip/priv/nd6_priv.h", - ] - - sources += [ - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/autoip.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/dhcp.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/etharp.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/icmp.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/igmp.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/ip4.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/ip4_addr.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv4/ip4_frag.c", - ] - - sources += [ - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/dhcp6.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/ethip6.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/icmp6.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/inet6.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/ip6.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/ip6_addr.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/ip6_frag.c", - - #"${bl702_sdk_root}/components/network/lwip/src/core/ipv6/ip6_route_table.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/mld6.c", - "${bl702_sdk_root}/components/network/lwip/src/core/ipv6/nd6.c", - ] - - sources += - [ "${bl702_sdk_root}/components/network/lwip/src/netif/slipif.c" ] - sources += - [ "${bl702_sdk_root}/components/network/lwip/src/netif/bridgeif.c" ] - sources += - [ "${bl702_sdk_root}/components/network/lwip/src/netif/bridgeif_fdb.c" ] - sources += - [ "${bl702_sdk_root}/components/network/lwip/src/netif/ethernet.c" ] - sources += [ "${bl702_sdk_root}/components/network/lwip/src/netif/zepif.c" ] - - sources += - [ "${bl702_sdk_root}/components/network/lwip/src/apps/mdns/mdns.c" ] - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ":${sdk_target_name}_lwip_port_config", - ":${sdk_target_name}_lwip_config", - ] - } - - config("${sdk_target_name}_zigbee_config") { - _include_dirs = [ - "${bl702_sdk_root}/components/network/zigbee/zbstack/", - "${bl702_sdk_root}/components/network/zigbee/zbstack/include", - "${bl702_sdk_root}/components/network/zigbee/zbstack/include/core", - "${bl702_sdk_root}/components/network/zigbee/zbstack/include/zcl", - "${bl702_sdk_root}/components/network/zigbee/zbcli/", - ] - - defines = [ "CFG_ZIGBEE_TOUCHLINK=1" ] - - cflags = [] - foreach(include_dir, _include_dirs) { - cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] - } - } - - source_set("${sdk_target_name}_zigbee") { - #sources = [ "${bl702_sdk_root}/components/network/zigbee/zbcli/zb_stack_cli.c" ] - - libs = [ - "${bl702_sdk_root}/components/network/zigbee/zbstack/lib/libzbstack.a", - "${bl702_sdk_root}/components/network/zigbee/zbstack/lib/libzbstackex.a", - ] - - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_plat_config", - ":${sdk_target_name}_zigbee_config", - ] - ldflags = [ "-Wl,--defsym=__LD_CONFIG_FLASH_SIZE=0x100000" ] - cflags = [ - "-Wno-implicit-function-declaration", - "-Wno-incompatible-pointer-types", - "-Wno-unused-variable", - ] - } - - group(sdk_target_name) { - public_deps = [ - ":${sdk_target_name}_bflb_platform", - ":${sdk_target_name}_ble", - ":${sdk_target_name}_drv", - ":${sdk_target_name}_plat", - ] - - if (chip_enable_openthread) { - public_deps += [ ":${sdk_target_name}_otport" ] - } - - if (chip_enable_wifi) { - public_deps += [ ":${sdk_target_name}_lwip_port" ] - public_deps += [ ":${sdk_target_name}_lwip" ] - } - - if (enable_zigbee) { - public_deps += [ ":${sdk_target_name}_zigbee" ] - } - - if (enable_cdc_module) { - public_deps += [ ":${sdk_target_name}_cdc" ] - } - - public_deps += [ ":${sdk_target_name}_app" ] - } -} diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni new file mode 100644 index 00000000000000..9e96105373928a --- /dev/null +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -0,0 +1,826 @@ +# Copyright (c) 2021 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//args.gni") +import("//build_overrides/bouffalolab_iot_sdk.gni") +import("//build_overrides/chip.gni") +import("//build_overrides/mbedtls.gni") +import("//build_overrides/openthread.gni") +import("${chip_root}/src/lib/lib.gni") + +import("${mbedtls_root}/mbedtls.gni") + +declare_args() { + bl_iot_sdk_root = "${chip_root}/third_party/bouffalolab/repo" + + enable_cdc_module = false + + thread_port_1_3 = false +} + +assert(bl_iot_sdk_root != "", "bl_iot_sdk_root must be specified") + +# Defines an Bouffa Lab IOT SDK build target. +# +# Parameters: +# bl_iot_sdk_root - The location of Bouffalo Lab IOT SDK. +# sources - The sources files to build. +template("bl_iot_sdk") { + sdk_target_name = target_name + + if (defined(invoker.enable_zigbee)) { + enable_zigbee = invoker.enable_zigbee + } + + if (defined(invoker.enable_cdc_module)) { + enable_cdc_module = invoker.enable_cdc_module + } + + config("${sdk_target_name}_config") { + defines = [ + "__FILENAME__=strrchr(__FILE__,'/')?strrchr(__FILE__,'/')+1:__FILE__", + "ARCH_RISCV", + "BL702=BL702", + "BFLB_USE_ROM_DRIVER=1", + "BFLB_USE_HAL_DRIVER=1", + ] + + include_dirs = [] + if (defined(invoker.include_dirs)) { + include_dirs += invoker.include_dirs + } + + if (defined(invoker.defines)) { + defines += invoker.defines + } + + if (defined(invoker.freertos_config)) { + cflags_c = [ + "-include", + rebase_path("${invoker.freertos_config}", root_build_dir), + ] + } + } + + config("${sdk_target_name}_config_soc") { + include_dirs = + [ "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_rf/include" ] + } + + source_set("${sdk_target_name}_soc") { + defines = [ "CFG_CPP_ENABLE" ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702/evb/src/boot/gcc/start.S", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702/evb/src/debug.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702/evb/src/strntoumax.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702/evb/src/vprint.c", + ] + + libs = [ "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_rf/lib/libbl702_rf.a" ] + + cflags_c = [ "-Wno-format-truncation" ] + } + + config("${sdk_target_name}_config_BSP_Driver") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/inc", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/regs", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/startup", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/risc-v/Core/Include", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/soft_crc", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/MCU_Common/misc", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Common/platform/", + ] + + defines = [ "bl706_iot" ] + } + + source_set("${sdk_target_name}_BSP_Driver") { + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_acomp.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_adc.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_aon.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_cam.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_clock.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_common.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_dac.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_dma.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_ef_ctrl.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_emac.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_glb.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_hbn.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_i2c.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_i2c_gpio_sim.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_i2s.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_ir.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_kys.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_l1c.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_mjpeg.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_pds.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_psram.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_pwm.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_qdec.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_romapi.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sec_dbg.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sec_eng.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sf_cfg.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sf_cfg_ext.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sf_ctrl.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sflash.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_sflash_ext.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_spi.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_timer.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_uart.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_usb.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_xip_sflash.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_xip_sflash_ext.c", + ] + + configs += [ ":${sdk_target_name}_config_freertos" ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_BSP_Driver", + ] + cflags_c = [ + "-Wno-sign-compare", + "-Wno-unused-variable", + ] + } + + config("${sdk_target_name}_config_freertos") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/config", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/panic", + ] + } + + source_set("${sdk_target_name}_bl702_freertos") { + defines = [ "portasmHANDLE_INTERRUPT=interrupt_entry" ] + include_dirs = [ "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V/chip_specific_extensions/RV32F_float_abi_single" ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/event_groups.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/list.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/misaligned/fp_asm.S", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/misaligned/misaligned_ldst.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/panic/panic_c.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V/port.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/GCC/RISC-V/portASM.S", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/MemMang/heap_5.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/portable/MemMang/heap_5_psram.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/queue.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/stream_buffer.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/tasks.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_freertos/timers.c", + ] + + cflags_c = [ + "-Wno-sign-compare", + "-Wno-old-style-declaration", + ] + + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_freertos", + ] + } + + source_set("${sdk_target_name}_bl702_usb_cdc") { + include_dirs = [ + "${bl_iot_sdk_root}/components/fs/vfs/include", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Inc", + ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/bl702_hal_pcd.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/bl702_usb_cdc.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usb_device.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_cdc.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_cdc_if.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_conf.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_core.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_ctlreq.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_desc.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_usb_cdc/Src/usbd_ioreq.c", + ] + + cflags_c = [ "-Wno-sign-compare" ] + + public_configs = [ ":${sdk_target_name}_config" ] + } + + config("${sdk_target_name}_config_hosal") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/hosal/include", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/include", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common", + ] + + cflags_cc = [ "-Wno-literal-suffix" ] + } + + source_set("${sdk_target_name}_hosal") { + defines = [ "CFG_USE_XTAL32K=1" ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_adc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_boot2.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_chip.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_cks.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_dma.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_efuse.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_emac.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_flash.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_gpio.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_hbn.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_ir.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_irq.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_pds.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_psram.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_pwm.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_rtc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_sec.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_sys.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_timer.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_uart.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_wdt.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/bl_wireless.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_board.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_boot2.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_button.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_gpio.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_hbn.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_hwtimer.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_pds.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_sys.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_tcal.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_adc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_dac.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_dma.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_flash.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_gpio.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_i2c.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_ota.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_pwm.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_rng.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_rtc.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_spi.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_timer.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_uart.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hosal_wdg.c", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_aes.c", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_common.c", + "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_pka.c", + + # need update bl_sec_sha.c to fix compile error + # "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_sha.c", + ] + + cflags_c = [ + "-Wno-unused-variable", + "-Wno-sign-compare", + "-Wno-enum-conversion", + "-Wno-old-style-declaration", + "-Wno-stringop-overflow", + "-Wno-format-truncation", + ] + configs += [ + ":${sdk_target_name}_config_soc", + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_stage", + ":${sdk_target_name}_config_sys", + ":${sdk_target_name}_config_fs", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_hosal", + ] + } + + config("${sdk_target_name}_config_fs") { + include_dirs = [ "${bl_iot_sdk_root}/components/fs/vfs/include" ] + } + + source_set("${sdk_target_name}_fs") { + sources = [ + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_adc.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_gpio.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_pwm.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_spi.c", + "${bl_iot_sdk_root}/components/fs/vfs/device/vfs_uart.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs_file.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs_inode.c", + "${bl_iot_sdk_root}/components/fs/vfs/src/vfs_register.c", + ] + cflags_c = [ + "-Wno-sign-compare", + "-Wno-builtin-declaration-mismatch", + ] + configs += [ + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_stage", + ":${sdk_target_name}_config_fs", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_fs", + ] + } + + source_set("${sdk_target_name}_libc") { + sources = [ + "${bl_iot_sdk_root}/components/libc/newlibc/assert.c", + "${bl_iot_sdk_root}/components/libc/newlibc/stdatomic.c", + "${bl_iot_sdk_root}/components/libc/newlibc/syscalls.c", + ] + cflags_c = [ "-Wno-builtin-declaration-mismatch" ] + configs += [ ":${sdk_target_name}_config_freertos" ] + public_configs = [ ":${sdk_target_name}_config" ] + } + + config("${sdk_target_name}_config_stage") { + include_dirs = [ + "${bl_iot_sdk_root}/components/stage/easyflash4/inc", + "${bl_iot_sdk_root}/components/stage/yloop/include", + "${bl_iot_sdk_root}/components/stage/blog", + "${bl_iot_sdk_root}/components/stage/yloop/include/aos", + "${bl_iot_sdk_root}/components/stage/blfdt/inc", + "${bl_iot_sdk_root}/components/stage/cli/cli/include", + ] + } + + source_set("${sdk_target_name}_stage") { + sources = [ + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_addresses.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_empty_tree.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_overlay.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_ro.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_rw.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_strerror.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_sw.c", + "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_wip.c", + "${bl_iot_sdk_root}/components/stage/blog/blog.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/aos_freertos.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/device.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/local_event.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/select.c", + "${bl_iot_sdk_root}/components/stage/yloop/src/yloop.c", + ] + cflags_c = [ "-Wno-sign-compare" ] + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_freertos", + ":${sdk_target_name}_config_fs", + ":${sdk_target_name}_config_sys", + ":${sdk_target_name}_config_utils", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_stage", + ] + } + + config("${sdk_target_name}_config_sys") { + include_dirs = [ + "${bl_iot_sdk_root}/components/sys/bloop/bloop/include", + "${bl_iot_sdk_root}/components/sys/bloop/looprt/include", + "${bl_iot_sdk_root}/components/sys/bloop/loopset/include", + "${bl_iot_sdk_root}/components/sys/blmtd/include", + ] + } + + source_set("${sdk_target_name}_sys") { + include_dirs = [ "${bl_iot_sdk_root}/components/sys/bltime/include" ] + sources = [ + "${bl_iot_sdk_root}/components/sys/blmtd/bl_mtd.c", + "${bl_iot_sdk_root}/components/sys/bltime/bl_sys_time.c", + ] + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_sys", + ] + } + + config("${sdk_target_name}_config_utils") { + include_dirs = [ "${bl_iot_sdk_root}/components/utils/include/" ] + } + + source_set("${sdk_target_name}_utils") { + sources = [ + "${bl_iot_sdk_root}/components/utils/src/utils_base64.c", + "${bl_iot_sdk_root}/components/utils/src/utils_crc.c", + "${bl_iot_sdk_root}/components/utils/src/utils_dns.c", + "${bl_iot_sdk_root}/components/utils/src/utils_fec.c", + "${bl_iot_sdk_root}/components/utils/src/utils_getopt.c", + "${bl_iot_sdk_root}/components/utils/src/utils_hex.c", + "${bl_iot_sdk_root}/components/utils/src/utils_hexdump.c", + "${bl_iot_sdk_root}/components/utils/src/utils_hmac_sha1_fast.c", + "${bl_iot_sdk_root}/components/utils/src/utils_list.c", + "${bl_iot_sdk_root}/components/utils/src/utils_log.c", + "${bl_iot_sdk_root}/components/utils/src/utils_memp.c", + "${bl_iot_sdk_root}/components/utils/src/utils_notifier.c", + "${bl_iot_sdk_root}/components/utils/src/utils_psk_fast.c", + "${bl_iot_sdk_root}/components/utils/src/utils_rbtree.c", + "${bl_iot_sdk_root}/components/utils/src/utils_sha256.c", + "${bl_iot_sdk_root}/components/utils/src/utils_string.c", + "${bl_iot_sdk_root}/components/utils/src/utils_time.c", + "${bl_iot_sdk_root}/components/utils/src/utils_tlv_bl.c", + ] + + cflags_c = [ + "-Wno-shadow", + "-Wno-sign-compare", + ] + configs += [ + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_utils", + ] + } + + config("${sdk_target_name}_ble_config") { + include_dirs = [ + "${bl_iot_sdk_root}/components/network/ble/blecontroller/ble_inc", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/include", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/include/bluetooth", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/zephyr", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/port/include", + "${bl_iot_sdk_root}/components/network/ble/blestack/src", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host", + ] + + defines = [ + "BFLB_BLE", + "CONFIG_SET_TX_PWR", + "CFG_CON=1", + "CFG_BLE", + "CFG_SLEEP", + "CFG_BT_RESET", + "CONFIG_BT_PERIPHERAL=1", + "CFG_BLE_TX_BUFF_DATA=2", + "CONFIG_BT_GATT_DYNAMIC_DB", + "CONFIG_BT_GATT_SERVICE_CHANGED", + "CONFIG_BT_SETTINGS_CCC_LAZY_LOADING", + "CONFIG_BT_KEYS_OVERWRITE_OLDEST", + "CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS", + "CONFIG_BT_BONDABLE", + "CONFIG_BT_ASSERT", + "CFG_BLE_STACK_DBG_PRINT", + ] + + cflags_cc = [ "-Wno-conversion" ] + } + + source_set("${sdk_target_name}_ble") { + defines = [ + "CONFIG_BT_L2CAP_DYNAMIC_CHANNEL", + "CONFIG_BT_GATT_CLIENT", + "CONFIG_BT_CONN=1", + "CONFIG_BT_GATT_DIS_PNP", + "CONFIG_BT_GATT_DIS_SERIAL_NUMBER", + "CONFIG_BT_GATT_DIS_FW_REV", + "CONFIG_BT_GATT_DIS_HW_REV", + "CONFIG_BT_GATT_DIS_SW_REV", + "CONFIG_BT_ECC", + "CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING", + "CONFIG_BT_HCI_VS_EVT_USER", + "CONFIG_BT_SETTINGS_USE_PRINTK", + ] + + libs = [ "${bl_iot_sdk_root}/components/network/ble/blecontroller_702_std/lib/libblecontroller_702_std.a" ] + + include_dirs = [ + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/tinycrypt/include/tinycrypt", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/misc", + ] + + sources = [ + "${bl_iot_sdk_root}/components/network/ble/blestack/src/bl_hci_wrapper/bl_hci_wrapper.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/atomic_c.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/buf.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/dec.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/log.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/poll.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/work_q.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/hci_onchip/hci_driver.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/att.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/bl_host_assist.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/conn.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/crypto.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/gatt.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/hci_core.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/l2cap.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/settings.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/host/uuid.c", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/port/bl_port.c", + ] + + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_freertos", + ":${sdk_target_name}_config_utils", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_ble_config", + ] + + cflags_c = [ + "-Wno-sign-compare", + "-Wno-unused-but-set-variable", + "-Wno-misleading-indentation", + "-Wno-format", + "-Wno-format-nonliteral", + "-Wno-format-security", + "-Wno-unused-function", + "-Wno-incompatible-pointer-types", + "-Wno-discarded-qualifiers", + ] + } + + config("${sdk_target_name}_config_openthread_port") { + defines = [ "OT_FREERTOS_ENABLE=1" ] + if (thread_port_1_3) { + defines += [ "OT_THREAD_PORT_1_3" ] + } + + include_dirs = [ + "${chip_root}/platform/bl702", + "${chip_root}/third_party/openthread/repo/src/core", + "${chip_root}/third_party/openthread/repo/examples/platforms", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/include", + ] + + if (thread_port_1_3) { + include_dirs += [ + "${bl_iot_sdk_root}/components/network/thread/openthread_utils/include", + ] + } + } + + source_set("${sdk_target_name}_openthread") { + import("//build_overrides/openthread.gni") + + include_dirs = [ + "${bl_iot_sdk_root}/components/network/lmac154/include", + "${bl_iot_sdk_root}/components/network/thread/openthread_port", + "${openthread_root}/examples/platforms/utils/", + "${openthread_root}/examples", + ] + + sources = [ + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_alarm.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_diag.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", + ] + + libs = [ "${bl_iot_sdk_root}/components/network/lmac154/lib/liblmac154.a" ] + + if (thread_port_1_3) { + sources += [ "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c" ] + libs += [ "${bl_iot_sdk_root}/components/network/thread/openthread_utils/lib/libopenthread_utils.a" ] + } + + configs += [ + ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_stage", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_openthread_port", + ] + + public_deps = [ + "${bouffalolab_iot_sdk_build_root}/bl702:mbedtls", + "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", + "${openthread_root}/src/core:libopenthread_core_headers", + ] + } + + config("${sdk_target_name}_config_lwip_port") { + _include_dirs = [ + "${bl_iot_sdk_root}/components/network/lwip/lwip-port", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/config", + "${bl_iot_sdk_root}/components/stage/virt_net/include", + "${bl_iot_sdk_root}/components/stage/throughput/bl702/inc", + ] + + defines = [ + "TCPIP_THREAD_PRIO=24", + "CFG_ETHERNET_ENABLE=1", + ] + + cflags = [] + foreach(include_dir, _include_dirs) { + cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] + } + + cflags += [ + "-Wno-conversion", + "-Wno-unused-function", + ] + } + + source_set("${sdk_target_name}_lwip_port") { + defines = [ + "SPI_WIFI_RXBUFF_IN_PSRAM=1", + "VIRT_NET_SPI_RX_TASK_PRIORITY=25", + ] + + # include_dirs = [ + # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/arch", + # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS", + # "${bl_iot_sdk_root}/components/stage/throughput" + # ] + + # sources = [ + # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/ethernetif.c", + # "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/sys_arch.c" + # ] + + # sources += [ + # "${bl_iot_sdk_root}/components/stage/throughput/bl702/src/tp_spi_master.c", + # ] + # sources += [ + # "${bl_iot_sdk_root}/components/stage/virt_net/src/virt_net.c", + # "${bl_iot_sdk_root}/components/stage/virt_net/src/virt_net_spi.c", + # ] + + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_lwip_port", + ":${sdk_target_name}_config_lwip", + ] + + cflags = [ "-Wno-sign-compare" ] + } + + config("${sdk_target_name}_config_lwip") { + include_dirs = [ + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/config", + "${bl_iot_sdk_root}/components/network/lwip/src/include", + "${bl_iot_sdk_root}/components/network/lwip/src/include/lwip/apps", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/hook", + ] + + defines = [ + "LWIP_IPV6=1", + "LWIP_IPV4=1", + "LWIP_IPV6_DHCP6=1", + "LWIP_IPV6_SCOPES=0", + "PBUF_POOL_SIZE=20", + "PBUF_POOL_BUFSIZE=(1280+150)", + ] + } + + source_set("${sdk_target_name}_lwip") { + sources = [ + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/ethernetif.c", + "${bl_iot_sdk_root}/components/network/lwip/lwip-port/FreeRTOS/sys_arch.c", + ] + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/netif/bridgeif.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/bridgeif_fdb.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/ethernet.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/slipif.c", + "${bl_iot_sdk_root}/components/network/lwip/src/netif/zepif.c", + ] + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/core/def.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/dns.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/inet_chksum.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/init.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ip.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/mem.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/memp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/netif.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/pbuf.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/raw.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/stats.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/sys.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/tcp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/tcp_in.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/tcp_out.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/timeouts.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/udp.c", + ] + + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/autoip.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/dhcp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/etharp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/icmp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/igmp.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/ip4.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/ip4_addr.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/ip4_frag.c", + ] + + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/dhcp6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ethip6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/icmp6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/inet6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6_addr.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6_frag.c", + + #"${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/ip6_route_table.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/mld6.c", + "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv6/nd6.c", + ] + + sources += [ + "${bl_iot_sdk_root}/components/network/lwip/src/api/api_lib.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/api_msg.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/err.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/if_api.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/netbuf.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/netifapi.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/sockets.c", + "${bl_iot_sdk_root}/components/network/lwip/src/api/tcpip.c", + ] + sources += + [ "${bl_iot_sdk_root}/components/network/lwip/src/apps/mdns/mdns.c" ] + + configs += [ ":${sdk_target_name}_config_freertos" ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_lwip", + ] + } + + group(sdk_target_name) { + public_deps = [ + ":${sdk_target_name}_BSP_Driver", + ":${sdk_target_name}_bl702_freertos", + ":${sdk_target_name}_ble", + ":${sdk_target_name}_fs", + ":${sdk_target_name}_hosal", + ":${sdk_target_name}_libc", + ":${sdk_target_name}_soc", + ":${sdk_target_name}_stage", + ":${sdk_target_name}_sys", + ":${sdk_target_name}_utils", + ] + + if (chip_enable_openthread) { + public_deps += [ ":${sdk_target_name}_openthread" ] + } + + if (chip_enable_wifi) { + public_deps += [ ":${sdk_target_name}_lwip_port" ] + public_deps += [ ":${sdk_target_name}_lwip" ] + } + + if (enable_cdc_module) { + public_deps += [ ":${sdk_target_name}_bl702_usb_cdc" ] + } + } +} diff --git a/third_party/bouffalolab/bl702/bl702_board.gni b/third_party/bouffalolab/common/bouffalolab_board.gni similarity index 78% rename from third_party/bouffalolab/bl702/bl702_board.gni rename to third_party/bouffalolab/common/bouffalolab_board.gni index 5aa17fd891eb73..c21e839dbfe372 100644 --- a/third_party/bouffalolab/bl702/bl702_board.gni +++ b/third_party/bouffalolab/common/bouffalolab_board.gni @@ -13,14 +13,13 @@ # limitations under the License. declare_args() { - # BL602 board used - bl702_board = "BL-IOT-DVK" + bouffalolab_bard = "BL-IOT-DVK" } -if (bl702_board == "") { - bl702_board = "BL-IOT-DVK" +if (bouffalolab_bard == "") { + bouffalolab_bard = "BL-IOT-DVK" } -assert(bl702_board != "", "bl702_board must be specified") +assert(bouffalolab_bard != "", "bouffalolab_bard must be specified") board_defines = [] diff --git a/third_party/bouffalolab/bl602/bl602_executable.gni b/third_party/bouffalolab/common/bouffalolab_executable.gni similarity index 81% rename from third_party/bouffalolab/bl602/bl602_executable.gni rename to third_party/bouffalolab/common/bouffalolab_executable.gni index 5c327b0f913540..54f4c031ee263c 100644 --- a/third_party/bouffalolab/bl602/bl602_executable.gni +++ b/third_party/bouffalolab/common/bouffalolab_executable.gni @@ -18,7 +18,7 @@ import("//build_overrides/chip.gni") import("//build_overrides/bouffalolab_iot_sdk.gni") import("${build_root}/toolchain/flashable_executable.gni") -template("bl602_executable") { +template("bouffalolab_executable") { output_base_name = get_path_info(invoker.output_name, "name") objcopy_image_name = output_base_name + ".bin" @@ -40,9 +40,13 @@ template("bl602_executable") { "${chip_root}/scripts/flashing/bouffalolab_firmware_utils.py", "${chip_root}/scripts/flashing/firmware_utils.py", - "${chip_root}/examples/platform/bouffalolab/bl602/flash_config/partition_cfg_2M.toml", - "${chip_root}/examples/platform/bouffalolab/bl602/flash_config/partition_cfg_4M.toml", + "${chip_root}/examples/platform/bouffalolab/${invoker.bl_plat_name}/flash_config/partition_cfg_2M.toml", ] + + if (invoker.bl_plat_name == "bl602") { + flashing_script_inputs += [ "${chip_root}/examples/platform/bouffalolab/${invoker.bl_plat_name}/flash_config/partition_cfg_4M.toml" ] + } + copy(flashing_runtime_target) { sources = flashing_script_inputs outputs = [ "${root_out_dir}/{{source_file_part}}" ] @@ -53,12 +57,16 @@ template("bl602_executable") { flashing_script_name = output_base_name + ".flash.py" flashing_options = [ "bouffalolab" ] flashing_options += [ "--chipname" ] - flashing_options += [ "bl602" ] + flashing_options += [ "${invoker.bl_plat_name}" ] flashing_options += [ "--xtal" ] - flashing_options += [ "40M" ] - flashing_options += [ "--pt" ] + if (invoker.bl_plat_name == "bl602") { + flashing_options += [ "40M" ] + } else if (invoker.bl_plat_name == "bl702") { + flashing_options += [ "32M" ] + } - if (invoker.board == "BL602-IOT-DVK-3S") { + flashing_options += [ "--pt" ] + if (invoker.board == "BL602-IOT-DVK-3S" || invoker.bl_plat_name == "bl702") { flashing_options += [ rebase_path("partition_cfg_2M.toml", root_out_dir, root_out_dir) ] } else { diff --git a/third_party/bouffalolab/bl602/bl602_riscv.gni b/third_party/bouffalolab/common/rsicv.gni similarity index 96% rename from third_party/bouffalolab/bl602/bl602_riscv.gni rename to third_party/bouffalolab/common/rsicv.gni index 3c72c6fdf06fe9..dc75aaa22232d6 100644 --- a/third_party/bouffalolab/bl602/bl602_riscv.gni +++ b/third_party/bouffalolab/common/rsicv.gni @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("bl602_board.gni") - riscv_arch = "rv32imfc" riscv_abi = "ilp32f" # riscv_cpu = "" diff --git a/third_party/bouffalolab/repo b/third_party/bouffalolab/repo index ae0622d85476ed..abf04dcdc4ce5f 160000 --- a/third_party/bouffalolab/repo +++ b/third_party/bouffalolab/repo @@ -1 +1 @@ -Subproject commit ae0622d85476ed838ebc3efde9743c376bc9f96d +Subproject commit abf04dcdc4ce5f94c57b6150d6ba52a22b700880 From def892adb6194f18ffd6fc54417a01471b4bf980 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Thu, 5 Jan 2023 00:51:08 +0800 Subject: [PATCH 2/8] [Ameba] Add Macro to InitBindingHandler (#24186) --- examples/all-clusters-app/ameba/main/chipinterface.cpp | 2 ++ examples/light-switch-app/ameba/main/chipinterface.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/examples/all-clusters-app/ameba/main/chipinterface.cpp b/examples/all-clusters-app/ameba/main/chipinterface.cpp index ad92123d5795e7..e55666d1d6aee2 100644 --- a/examples/all-clusters-app/ameba/main/chipinterface.cpp +++ b/examples/all-clusters-app/ameba/main/chipinterface.cpp @@ -141,7 +141,9 @@ static void InitServer(intptr_t context) PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); } +#if CONFIG_ENABLE_CHIP_SHELL InitBindingHandler(); +#endif } extern "C" void ChipTest(void) diff --git a/examples/light-switch-app/ameba/main/chipinterface.cpp b/examples/light-switch-app/ameba/main/chipinterface.cpp index fcdf8b963fc7bc..24e32a72decf39 100644 --- a/examples/light-switch-app/ameba/main/chipinterface.cpp +++ b/examples/light-switch-app/ameba/main/chipinterface.cpp @@ -116,7 +116,9 @@ static void InitServer(intptr_t context) PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); } +#if CONFIG_ENABLE_CHIP_SHELL InitBindingHandler(); +#endif } extern "C" void ChipTest(void) From e3a3aaad583a5cb11ebf5856ca2b8912d72e347d Mon Sep 17 00:00:00 2001 From: Maciej Bojczuk Date: Wed, 4 Jan 2023 17:54:02 +0100 Subject: [PATCH 3/8] [Telink] Change factory data generator utility (#24213) * [Telink] Manufacturing Partition Generator Utility This tool can be used to generate factory data for more bunch of devices. Signed-off-by: Maciej Bojczuk * [Telink] Add additional python requirements MFG tool require some additional python modules like: * future * pypng * PyQRCode Signed-off-by: Maciej Bojczuk * [Telink] MFG tool integration with build system Use new tool for factory data generation during building when below config is set: CONFIG_CHIP_FACTORY_DATA=y CONFIG_CHIP_FACTORY_DATA_BUILD=y Signed-off-by: Maciej Bojczuk * [Telink] Remove old, not needed scripts Remove old, not needed python scripts for factory data generation. Signed-off-by: Maciej Bojczuk Signed-off-by: Maciej Bojczuk --- config/telink/chip-module/CMakeLists.txt | 2 +- .../chip-module/generate_factory_data.cmake | 159 ++-- scripts/requirements.telink.txt | 3 + scripts/requirements.txt | 3 + .../generate_telink_chip_factory_data.py | 493 ------------ scripts/tools/telink/mfg_tool.py | 755 ++++++++++++++++++ scripts/tools/telink/readme.md | 212 +++++ scripts/tools/telink/requirements.txt | 6 + .../tools/telink/telink_factory_data.schema | 164 ---- .../tools/telink/telink_generate_partition.py | 169 ---- 10 files changed, 1041 insertions(+), 925 deletions(-) create mode 100644 scripts/requirements.telink.txt delete mode 100644 scripts/tools/telink/generate_telink_chip_factory_data.py create mode 100644 scripts/tools/telink/mfg_tool.py create mode 100644 scripts/tools/telink/readme.md create mode 100644 scripts/tools/telink/requirements.txt delete mode 100644 scripts/tools/telink/telink_factory_data.schema delete mode 100644 scripts/tools/telink/telink_generate_partition.py diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 6113325da57f95..2328ef28c13893 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -327,7 +327,7 @@ endif() if (CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE) add_custom_target(merge_factory_data ALL COMMAND - dd if=${PROJECT_BINARY_DIR}/factory_data.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=1024 seek=2000 + dd if=${PROJECT_BINARY_DIR}/factory/factory_data.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=1024 seek=2000 ) if (CONFIG_CHIP_OTA_IMAGE_BUILD) add_dependencies(merge_factory_data merge_mcuboot) diff --git a/config/telink/chip-module/generate_factory_data.cmake b/config/telink/chip-module/generate_factory_data.cmake index a1c9f0ef9780a0..6b7681defc8224 100644 --- a/config/telink/chip-module/generate_factory_data.cmake +++ b/config/telink/chip-module/generate_factory_data.cmake @@ -15,49 +15,63 @@ # -# Create a JSON file based on factory data given via kConfigs. +# Create a binary file with factory data given via kConfigs. # -# This function creates a list of arguments for external script and then run it to write a JSON file. -# Created JSON file can be checked using JSON SCHEMA file if it is provided. +# This function creates a list of arguments for external script and then run it to write a factory data file. # # This script can be manipulated using following kConfigs: # - To merge generated factory data with final zephyr.hex file set kConfig CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=y # - To use default certification paths set CONFIG_CHIP_FACTORY_DATA_USE_DEFAULTS_CERTS_PATH=y # -# During generation process a some file will be created in zephyr's build directory: -# - .json a file containing all factory data written in JSON format. +# During generation process a some file will be created in zephyr's build directory under factory subdirectory: +# - factory_data.bin +# - factory_data.hex +# - DAC_cert.der +# - DAC_cert.pem +# - DAC_key.pem +# - DAC_private_key.bin +# - DAC_public_key.bin +# - pai_cert.der +# - onb_codes.csv +# - pin_disc.csv +# - qrcode.png +# - summary.json # # [Args]: # factory_data_target - a name for target to generate factory_data. # script_path - a path to script that makes a JSON factory data file from given arguments. -# schema_path - a path to JSON schema file which can be used to verify generated factory data JSON file. -# This argument is optional, if you don't want to verify the JSON file put it empty "". # output_path - a path to output directory, where created JSON file will be stored. -function(telink_create_factory_data_json factory_data_target script_path schema_path output_path) +function(telink_create_factory_data_json factory_data_target script_path output_path) # set script args for future purpose set(script_args) ## generate all script arguments -string(APPEND script_args "--sn \"${CONFIG_CHIP_DEVICE_SERIAL_NUMBER}\"\n") -string(APPEND script_args "--date \"${CONFIG_CHIP_DEVICE_MANUFACTURING_DATE}\"\n") -string(APPEND script_args "--vendor_id ${CONFIG_CHIP_DEVICE_VENDOR_ID}\n") -string(APPEND script_args "--product_id ${CONFIG_CHIP_DEVICE_PRODUCT_ID}\n") -string(APPEND script_args "--vendor_name \"${CONFIG_CHIP_DEVICE_VENDOR_NAME}\"\n") -string(APPEND script_args "--product_name \"${CONFIG_CHIP_DEVICE_PRODUCT_NAME}\"\n") -string(APPEND script_args "--hw_ver ${CONFIG_CHIP_DEVICE_HARDWARE_VERSION}\n") -string(APPEND script_args "--hw_ver_str \"${CONFIG_CHIP_DEVICE_HARDWARE_VERSION_STRING}\"\n") +string(APPEND script_args "--serial-num \"${CONFIG_CHIP_DEVICE_SERIAL_NUMBER}\"\n") +string(APPEND script_args "--mfg-date \"${CONFIG_CHIP_DEVICE_MANUFACTURING_DATE}\"\n") +string(APPEND script_args "--vendor-id ${CONFIG_CHIP_DEVICE_VENDOR_ID}\n") +string(APPEND script_args "--product-id ${CONFIG_CHIP_DEVICE_PRODUCT_ID}\n") +string(APPEND script_args "--vendor-name \"${CONFIG_CHIP_DEVICE_VENDOR_NAME}\"\n") +string(APPEND script_args "--product-name \"${CONFIG_CHIP_DEVICE_PRODUCT_NAME}\"\n") +string(APPEND script_args "--hw-ver ${CONFIG_CHIP_DEVICE_HARDWARE_VERSION}\n") +string(APPEND script_args "--hw-ver-str \"${CONFIG_CHIP_DEVICE_HARDWARE_VERSION_STRING}\"\n") +string(APPEND script_args "--overwrite\n") +string(APPEND script_args "--in-tree\n") # check if Rotating Device Id Unique Id should be generated if(NOT CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID) if(NOT DEFINED CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID) message(FATAL_ERROR "CHIP_DEVICE_ROTATING_DEVICE_UID was not provided. To generate it use CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID=y") else() - string(APPEND script_args "--rd_uid \"${CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID}\"\n") + string(APPEND script_args "--rd-id-uid \"${CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID}\"\n") endif() else() - string(APPEND script_args "--generate_rd_uid\n") + string(APPEND script_args "--enable-rotating-device-id\n") endif() +# find chip cert tool +find_program(chip_cert_exe NAMES chip-cert REQUIRED) +string(APPEND script_args "--chip-cert-path ${chip_cert_exe}\n") + # for development purpose user can use default certs instead of generating or providing them if(CONFIG_CHIP_FACTORY_DATA_USE_DEFAULT_CERTS) # convert decimal PID to its hexadecimal representation to find out certification files in repository @@ -66,99 +80,57 @@ if(CONFIG_CHIP_FACTORY_DATA_USE_DEFAULT_CERTS) string(TOUPPER ${raw_pid} raw_pid_upper) # all certs are located in ${CHIP_ROOT}/credentials/development/attestation # it can be used during development without need to generate new certifications - string(APPEND script_args "--dac_cert \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid_upper}-Cert.der\"\n") - string(APPEND script_args "--dac_key \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid_upper}-Key.der\"\n") - string(APPEND script_args "--pai_cert \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-PAI-noPID-Cert.der\"\n") + string(APPEND script_args "--dac-cert \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid_upper}-Cert.pem\"\n") + string(APPEND script_args "--dac-key \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-DAC-${raw_pid_upper}-Key.pem\"\n") + string(APPEND script_args "--cert \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-PAI-noPID-Cert.pem\"\n") + string(APPEND script_args "--key \"${CHIP_ROOT}/credentials/development/attestation/Matter-Development-PAI-noPID-Key.pem\"\n") + string(APPEND script_args "-cd \"${CHIP_ROOT}/credentials/development/cd-certs/Chip-Test-CD-Cert.der\"\n") + string(APPEND script_args "--pai\n") else() - find_program(chip_cert_exe NAMES chip-cert REQUIRED) - string(APPEND script_args "--gen_cd\n") - string(APPEND script_args "--chip_cert_path ${chip_cert_exe}\n") + # generate PAI and DAC certs + string(APPEND script_args "--cert \"${CHIP_ROOT}/credentials/test/attestation/Chip-Test-PAA-NoVID-Cert.pem\"\n") + string(APPEND script_args "--key \"${CHIP_ROOT}/credentials/test/attestation/Chip-Test-PAA-NoVID-Key.pem\"\n") + string(APPEND script_args "-cd \"${CHIP_ROOT}/credentials/development/cd-certs/Chip-Test-CD-Cert.der\"\n") + string(APPEND script_args "--paa\n") endif() +# find chip tool requied for generating QRCode +find_program(chip_tool_exe NAMES chip-tool REQUIRED) +string(APPEND script_args "--chip-tool-path ${chip_tool_exe}\n") + # add Password-Authenticated Key Exchange parameters -string(APPEND script_args "--spake2_it \"${CONFIG_CHIP_DEVICE_SPAKE2_IT}\"\n") -string(APPEND script_args "--spake2_salt \"${CONFIG_CHIP_DEVICE_SPAKE2_SALT}\"\n") +string(APPEND script_args "--spake2-it \"${CONFIG_CHIP_DEVICE_SPAKE2_IT}\"\n") string(APPEND script_args "--discriminator ${CONFIG_CHIP_DEVICE_DISCRIMINATOR}\n") string(APPEND script_args "--passcode ${CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE}\n") -string(APPEND script_args "--include_passcode\n") -string(APPEND script_args "--overwrite\n") -# check if spake2 verifier should be generated using script -if(CONFIG_CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER) - # request script to generate a new spake2_verifier - # by adding an argument to script_args - find_program(spake_exe NAMES spake2p REQUIRED) - string(APPEND script_args "--spake2p_path ${spake_exe}\n") -else() - # Spake2 verifier should be provided using kConfig - string(APPEND script_args "--spake2_verifier \"${CONFIG_CHIP_DEVICE_SPAKE2_TEST_VERIFIER}\"\n") -endif() +# request spake2p to generate a new spake2_verifier +find_program(spake_exe NAMES spake2p REQUIRED) +string(APPEND script_args "--spake2-path ${spake_exe}\n") if(CONFIG_CHIP_DEVICE_ENABLE_KEY) # Add optional EnableKey that triggers user-specific action. -string(APPEND script_args "--enable_key \"${CONFIG_CHIP_DEVICE_ENABLE_KEY}\"\n") +string(APPEND script_args "--enable-key \"${CONFIG_CHIP_DEVICE_ENABLE_KEY}\"\n") endif() -# Set output JSON file and path to SCHEMA file to validate generated factory data -set(factory_data_json ${output_path}/${factory_data_target}.json) -string(APPEND script_args "-o \"${factory_data_json}\"\n") -string(APPEND script_args "-s \"${schema_path}\"\n") +string(APPEND script_args "--output \"${output_path}\"/factory\n") + +set(factory_data_bin ${output_path}/factory/factory_data.bin) -# execute first script to create a JSON file +# execute a script to create a factory data file separate_arguments(separated_script_args NATIVE_COMMAND ${script_args}) add_custom_command( - OUTPUT ${factory_data_json} + OUTPUT ${factory_data_bin} DEPENDS ${FACTORY_DATA_SCRIPT_PATH} COMMAND ${Python3_EXECUTABLE} ${FACTORY_DATA_SCRIPT_PATH} ${separated_script_args} COMMENT "Generating new Factory Data..." ) add_custom_target(${factory_data_target} ALL - DEPENDS ${factory_data_json} + DEPENDS ${factory_data_bin} ) endfunction() -# Create a .hex file with factory data in CBOR format. -# -# This function creates a .hex and .cbor files from given JSON factory data file. -# -# -# During generation process some files will be created in zephyr's build directory: -# - .hex a file containing all factory data in CBOR format. -# - .bin a binary file containing all raw factory data in CBOR format. -# - .cbor a file containing all factory data in CBOR format. -# -# [Args]: -# factory_data_hex_target - a name for target to generate factory data HEX file. -# factory_data_target - a name for target to generate factory data JSON file. -# script_path - a path to script that makes a factory data .hex file from given arguments. -# output_path - a path to output directory, where created JSON file will be stored. -function(telink_create_factory_data_hex_file factory_data_hex_target factory_data_target script_path output_path) - -# Pass the argument list via file -set(cbor_script_args "-i ${output_path}/${factory_data_target}.json\n") -string(APPEND cbor_script_args "-o ${output_path}/${factory_data_target}\n") -# get partition address and offset from partition manager during compilation -string(APPEND cbor_script_args "--offset 0x1f4000\n") -string(APPEND cbor_script_args "--size 0x1000\n") -string(APPEND cbor_script_args "-r\n") - -# execute second script to create a hex file containing factory data in cbor format -separate_arguments(separated_cbor_script_args NATIVE_COMMAND ${cbor_script_args}) -set(factory_data_hex ${output_path}/${factory_data_target}.hex) - -add_custom_command(OUTPUT ${factory_data_hex} - COMMAND ${Python3_EXECUTABLE} ${script_path} ${separated_cbor_script_args} - COMMENT "Generating factory data HEX file..." - DEPENDS ${factory_data_target} ${script_path} - ) -add_custom_target(${factory_data_hex_target} ALL - DEPENDS ${factory_data_hex} - ) - -endfunction() - # Generate factory data partition using given args # # @@ -176,21 +148,12 @@ message(FATAL_ERROR "CHIP_ROOT variable is not set, please add it to CMakeLists. endif() # Localize all scripts needed to generate factory data partition -set(FACTORY_DATA_SCRIPT_PATH ${CHIP_ROOT}/scripts/tools/telink/generate_telink_chip_factory_data.py) -set(GENERATE_CBOR_SCRIPT_PATH ${CHIP_ROOT}/scripts/tools/telink/telink_generate_partition.py) -set(FACTORY_DATA_SCHEMA_PATH ${CHIP_ROOT}/scripts/tools/telink/telink_factory_data.schema) +set(FACTORY_DATA_SCRIPT_PATH ${CHIP_ROOT}/scripts/tools/telink/mfg_tool.py) set(OUTPUT_FILE_PATH ${APPLICATION_BINARY_DIR}/zephyr) -# create a JSON file with all factory data +# create a binary file with all factory data telink_create_factory_data_json(factory_data - ${FACTORY_DATA_SCRIPT_PATH} - ${FACTORY_DATA_SCHEMA_PATH} + ${FACTORY_DATA_SCRIPT_PATH} ${OUTPUT_FILE_PATH}) -# create a .hex file with factory data in CBOR format based on the JSON file created previously -telink_create_factory_data_hex_file(factory_data_hex - factory_data - ${GENERATE_CBOR_SCRIPT_PATH} - ${OUTPUT_FILE_PATH}) - endfunction() diff --git a/scripts/requirements.telink.txt b/scripts/requirements.telink.txt new file mode 100644 index 00000000000000..7d2093551af69c --- /dev/null +++ b/scripts/requirements.telink.txt @@ -0,0 +1,3 @@ +future==0.18.2 +pypng==0.0.21 +PyQRCode==1.2.1 diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 6fec358caf1986..b39ec86833bf6e 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -20,6 +20,9 @@ virtualenv # TI -r requirements.ti.txt +# Telink +-r requirements.telink.txt + # cirque tests requests>=2.24.0 diff --git a/scripts/tools/telink/generate_telink_chip_factory_data.py b/scripts/tools/telink/generate_telink_chip_factory_data.py deleted file mode 100644 index 7605184700461a..00000000000000 --- a/scripts/tools/telink/generate_telink_chip_factory_data.py +++ /dev/null @@ -1,493 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2022 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from os.path import exists -import os -import sys -import json -import jsonschema -import secrets -import argparse -import subprocess -import logging as log -import base64 -from collections import namedtuple -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives.serialization import load_der_private_key - -# A user can not change the factory data version and must be coherent with -# the factory data version set in the Telink platform Kconfig file (CHIP_FACTORY_DATA_VERSION). -FACTORY_DATA_VERSION = 1 - -MATTER_ROOT = os.path.dirname(os.path.realpath(__file__))[:-len("/scripts/tools/telink")] -HEX_PREFIX = "hex:" -PUB_KEY_PREFIX = b'\x04' -INVALID_PASSCODES = [00000000, 11111111, 22222222, 33333333, 44444444, - 55555555, 66666666, 77777777, 88888888, 99999999, 12345678, 87654321] - - -def get_raw_private_key_der(der_file: str, password: str): - """ Split given der file to get separated key pair consisting of public and private keys. - - Args: - der_file (str): Path to .der file containing public and private keys - password (str): Password to decrypt Keys. It can be None, and then KEY is not encrypted. - - Returns: - hex string: return a hex string containing extracted and decrypted private KEY from given .der file. - """ - try: - with open(der_file, 'rb') as file: - key_data = file.read() - if password is None: - log.warning("KEY password has not been provided. It means that DAC key is not encrypted.") - keys = load_der_private_key(key_data, password, backend=default_backend()) - private_key = keys.private_numbers().private_value.to_bytes(32, byteorder='big') - - return private_key - - except IOError or ValueError: - return None - - -def gen_test_certs(chip_cert_exe: str, - output: str, - vendor_id: int, - product_id: int, - device_name: str, - generate_cd: bool = False, - cd_type: int = 1, - paa_cert_path: str = None, - paa_key_path: str = None): - """ - Generate Matter certificates according to given Vendor ID and Product ID using the chip-cert executable. - To use own Product Attestation Authority certificate provide paa_cert_path and paa_key_path arguments. - Without providing these arguments a PAA certificate will be get from /credentials/test/attestation directory - in the Matter repository. - - Args: - chip_cert_exe (str): path to chip-cert executable - output (str): output path to store a newly generated certificates (CD, DAC, PAI) - vendor_id (int): an identification number specific to Vendor - product_id (int): an identification number specific to Product - device_name (str): human-readable device name - generate_cd (bool, optional): Generate Certificate Declaration and store it in thee output directory. Defaults to False. - paa_cert_path (str, optional): provide PAA certification path. Defaults to None - a path will be set to /credentials/test/attestation directory. - paa_key_path (str, optional): provide PAA key path. Defaults to None - a path will be set to /credentials/test/attestation directory. - - Returns: - dictionary: ["PAI_CERT": (str), - "DAC_CERT": (str), - "DAC_KEY": (str)] - """ - - CD_PATH = MATTER_ROOT + "/credentials/test/certification-declaration/Chip-Test-CD-Signing-Cert.pem" - CD_KEY_PATH = MATTER_ROOT + "/credentials/test/certification-declaration/Chip-Test-CD-Signing-Key.pem" - PAA_PATH = paa_cert_path if paa_cert_path != None else MATTER_ROOT + "/credentials/test/attestation/Chip-Test-PAA-NoVID-Cert.pem" - PAA_KEY_PATH = paa_key_path if paa_key_path != None else MATTER_ROOT + "/credentials/test/attestation/Chip-Test-PAA-NoVID-Key.pem" - - attestation_certs = namedtuple("attestation_certs", ["dac_cert", "dac_key", "pai_cert"]) - - log.info("Generating new certificates using chip-cert...") - - if generate_cd: - # generate Certification Declaration - cmd = [chip_cert_exe, "gen-cd", - "--key", CD_KEY_PATH, - "--cert", CD_PATH, - "--out", output + "/CD.der", - "--format-version", "1", - "--vendor-id", hex(vendor_id), - "--product-id", hex(product_id), - "--device-type-id", "0", - "--certificate-id", "FFFFFFFFFFFFFFFFFFF", - "--security-level", "0", - "--security-info", "0", - "--certification-type", str(cd_type), - "--version-number", "0xFFFF", - ] - subprocess.run(cmd) - - new_certificates = {"PAI_CERT": output + "/PAI_cert", - "PAI_KEY": output + "/PAI_key", - "DAC_CERT": output + "/DAC_cert", - "DAC_KEY": output + "/DAC_key" - } - - # generate PAI - cmd = [chip_cert_exe, "gen-att-cert", - "-t", "i", - "-c", device_name, - "-V", hex(vendor_id), - "-C", PAA_PATH, - "-K", PAA_KEY_PATH, - "-o", new_certificates["PAI_CERT"] + ".pem", - "-O", new_certificates["PAI_KEY"] + ".pem", - "-l", str(10000), - ] - subprocess.run(cmd) - - # generate DAC - cmd = [chip_cert_exe, "gen-att-cert", - "-t", "d", - "-c", device_name, - "-V", hex(vendor_id), - "-P", hex(product_id), - "-C", new_certificates["PAI_CERT"] + ".pem", - "-K", new_certificates["PAI_KEY"] + ".pem", - "-o", new_certificates["DAC_CERT"] + ".pem", - "-O", new_certificates["DAC_KEY"] + ".pem", - "-l", str(10000), - ] - subprocess.run(cmd) - - # convert to .der files - for cert_k, cert_v in new_certificates.items(): - action_type = "convert-cert" if cert_k.find("CERT") != -1 else "convert-key" - log.info(cert_v + ".der") - cmd = [chip_cert_exe, action_type, - cert_v + ".pem", - cert_v + ".der", - "--x509-der", - ] - subprocess.run(cmd) - - return attestation_certs(new_certificates["DAC_CERT"] + ".der", - new_certificates["DAC_KEY"] + ".der", - new_certificates["PAI_CERT"] + ".der") - - -def gen_spake2p_verifier(passcode: int, it: int, salt: bytes) -> str: - """ Generate Spake2+ verifier using SPAKE2+ Python Tool - - Args: - passcode (int): Pairing passcode using in Spake2+ - it (int): Iteration counter for Spake2+ verifier generation - salt (str): Salt used to generate Spake2+ verifier - - Returns: - verifier encoded in Base64 - """ - - cmd = [ - os.path.join(MATTER_ROOT, 'scripts/tools/spake2p/spake2p.py'), 'gen-verifier', - '--passcode', str(passcode), - '--salt', base64.b64encode(salt).decode('ascii'), - '--iteration-count', str(it), - ] - return subprocess.check_output(cmd) - - -class FactoryDataGenerator: - """ - Class to generate factory data from given arguments and generate a JSON file - - """ - - def __init__(self, arguments) -> None: - """ - Args: - arguments (any):All input arguments parsed using ArgParse - """ - self._args = arguments - self._factory_data = list() - self._user_data = dict() - - try: - self._validate_args() - except AssertionError as e: - log.error(e) - sys.exit(-1) - - def _validate_args(self): - if self._args.user: - try: - self._user_data = json.loads(self._args.user) - except json.decoder.JSONDecodeError as e: - raise AssertionError("Provided wrong user data, this is not a JSON format! {}".format(e)) - assert self._args.spake2_verifier or self._args.passcode, \ - "Cannot find Spake2+ verifier, to generate a new one please provide passcode (--passcode)" - assert (self._args.chip_cert_path or (self._args.dac_cert and self._args.pai_cert and self._args.dac_key)), \ - "Cannot find paths to DAC or PAI certificates .der files. To generate a new ones please provide a path to chip-cert executable (--chip_cert_path)" - assert self._args.output.endswith(".json"), \ - "Output path doesn't contain .json file path. ({})".format(self._args.output) - assert not (self._args.passcode in INVALID_PASSCODES), \ - "Provided invalid passcode!" - - def generate_json(self): - """ - This function generates JSON data, .json file and validates it. - - To validate generated JSON data a scheme must be provided within script's arguments. - - - In the first part, if the rotating device id unique id has been not provided - as an argument, it will be created. - - If user-provided passcode and Spake2+ verifier have been not provided - as an argument, it will be created using an external script - - Passcode is not stored in JSON by default. To store it for debugging purposes, add --include_passcode argument. - - Validating output JSON is not mandatory, but highly recommended. - - """ - # generate missing data if needed - if not self._args.rd_uid: - if self._args.generate_rd_uid: - rd_uid = self._generate_rotating_device_uid() - else: - # rotating device ID unique ID was not provided, so do not store it in factory data. - rd_uid = None - else: - rd_uid = HEX_PREFIX + self._args.rd_uid - - if not self._args.spake2_verifier: - spake_2_verifier = self._generate_spake2_verifier() - else: - spake_2_verifier = self._args.spake2_verifier - - # convert salt to bytestring to be coherent with Spake2+ verifier type - spake_2_salt = self._args.spake2_salt - - if self._args.chip_cert_path: - certs = gen_test_certs(self._args.chip_cert_path, - self._args.output[:self._args.output.rfind("/")], - self._args.vendor_id, - self._args.product_id, - self._args.vendor_name + "_" + self._args.product_name, - self._args.gen_cd, - self._args.cd_type, - self._args.paa_cert, - self._args.paa_key) - dac_cert = certs.dac_cert - pai_cert = certs.pai_cert - dac_key = certs.dac_key - else: - dac_cert = self._args.dac_cert - dac_key = self._args.dac_key - pai_cert = self._args.pai_cert - - # try to read DAC public and private keys - dac_priv_key = get_raw_private_key_der(dac_key, self._args.dac_key_password) - if dac_priv_key is None: - log.error("Cannot read DAC keys from : {}".format(dac_key)) - sys.exit(-1) - - try: - json_file = open(self._args.output, "w+") - except FileNotFoundError: - print("Cannot create JSON file in this location: {}".format(self._args.output)) - sys.exit(-1) - with json_file: - # serialize data - self._add_entry("version", FACTORY_DATA_VERSION) - self._add_entry("sn", self._args.sn) - self._add_entry("vendor_id", self._args.vendor_id) - self._add_entry("product_id", self._args.product_id) - self._add_entry("vendor_name", self._args.vendor_name) - self._add_entry("product_name", self._args.product_name) - self._add_entry("product_label", self._args.product_label) - self._add_entry("product_url", self._args.product_url) - self._add_entry("part_number", self._args.part_number) - self._add_entry("date", self._args.date) - self._add_entry("hw_ver", self._args.hw_ver) - self._add_entry("hw_ver_str", self._args.hw_ver_str) - self._add_entry("dac_cert", self._process_der(dac_cert)) - self._add_entry("dac_key", dac_priv_key) - self._add_entry("pai_cert", self._process_der(pai_cert)) - if self._args.include_passcode: - self._add_entry("passcode", self._args.passcode) - self._add_entry("spake2_it", self._args.spake2_it) - self._add_entry("spake2_salt", spake_2_salt) - self._add_entry("spake2_verifier", spake_2_verifier) - self._add_entry("discriminator", self._args.discriminator) - if rd_uid: - self._add_entry("rd_uid", rd_uid) - if self._args.enable_key: - self._add_entry("enable_key", HEX_PREFIX + self._args.enable_key) - if self._args.user: - self._add_entry("user", self._args.user) - - factory_data_dict = dict(self._factory_data) - - json_object = json.dumps(factory_data_dict) - is_json_valid = True - - if self._args.schema: - is_json_valid = self._validate_output_json(json_object) - else: - log.warning("JSON Schema file has not been provided, the output file can be wrong. Be aware of that.") - try: - if is_json_valid: - json_file.write(json_object) - except IOError as e: - log.error("Cannot save output file into directory: {}".format(self._args.output)) - - def _add_entry(self, name: str, value: any): - """ Add single entry to list of tuples ("key", "value") """ - if(isinstance(value, bytes) or isinstance(value, bytearray)): - value = HEX_PREFIX + value.hex() - if value or (isinstance(value, int) and value == 0): - log.debug("Adding entry '{}' with size {} and type {}".format(name, sys.getsizeof(value), type(value))) - self._factory_data.append((name, value)) - - def _generate_spake2_verifier(self): - """ If verifier has not been provided in arguments list it should be generated via external script """ - return base64.b64decode(gen_spake2p_verifier(self._args.passcode, self._args.spake2_it, self._args.spake2_salt)) - - def _generate_rotating_device_uid(self): - """ If rotating device unique ID has not been provided it should be generated """ - log.warning("Cannot find rotating device UID in provided arguments list. A new one will be generated.") - rdu = secrets.token_bytes(16) - log.info("\n\nThe new rotate device UID: {}\n".format(rdu.hex())) - return rdu - - def _validate_output_json(self, output_json: str): - """ - Validate output JSON data with provided .scheme file - This function will raise error if JSON does not match schema. - - """ - try: - with open(self._args.schema) as schema_file: - log.info("Validating JSON with schema...") - schema = json.loads(schema_file.read()) - validator = jsonschema.Draft202012Validator(schema=schema) - validator.validate(instance=json.loads(output_json)) - except IOError as e: - log.error("Provided JSON schema file is wrong: {}".format(self._args.schema)) - return False - else: - log.info("Validate OK") - return True - - def _process_der(self, path: str): - log.debug("Processing der file...") - try: - with open(path, 'rb') as f: - data = f.read() - return data - except IOError as e: - log.error(e) - raise e - - -def main(): - parser = argparse.ArgumentParser(description="Telink Factory Data NVS generator tool") - - def allow_any_int(i): return int(i, 0) - def base64_str(s): return base64.b64decode(s) - - mandatory_arguments = parser.add_argument_group("Mandatory keys", "These arguments must be provided to generate JSON file") - optional_arguments = parser.add_argument_group( - "Optional keys", "These arguments are optional and they depend on the user-purpose") - parser.add_argument("-s", "--schema", type=str, - help="JSON schema file to validate JSON output data") - parser.add_argument("-o", "--output", type=str, required=True, - help="Output path to store .json file, e.g. my_dir/output.json") - parser.add_argument("-v", "--verbose", action="store_true", - help="Run this script with DEBUG logging level") - parser.add_argument("--include_passcode", action="store_true", - help="Include passcode in factory data. By default, it is used only for generating Spake2+ verifier.") - parser.add_argument("--overwrite", action="store_true", - help="If output JSON file exist this argument allows to generate new factory data and overwrite it.") - # Json known-keys values - # mandatory keys - mandatory_arguments.add_argument("--sn", type=str, required=True, - help="[ascii string] Serial number of a device which can be used to identify \ - the serial number field in the Matter certificate structure. \ - Maximum length of serial number is 20 bytes. \ - Strings longer than 20 bytes will be declined in script") - mandatory_arguments.add_argument("--vendor_id", type=allow_any_int, - help="[int | hex int] Provide Vendor Identification Number") - mandatory_arguments.add_argument("--product_id", type=allow_any_int, - help="[int | hex int] Provide Product Identification Number") - mandatory_arguments.add_argument("--vendor_name", type=str, - help="[string] provide human-readable vendor name") - mandatory_arguments.add_argument("--product_name", type=str, - help="[string] provide human-readable product name") - mandatory_arguments.add_argument("--date", type=str, required=True, - help="[ascii string] Provide manufacturing date \ - A manufacturing date specifies the date that the Node was manufactured. \ - Used format for providing a manufacturing date is ISO 8601 e.g. YYYY-MM-DD.") - mandatory_arguments.add_argument("--hw_ver", type=allow_any_int, required=True, - help="[int | hex int] Provide hardware version in int format.") - mandatory_arguments.add_argument("--hw_ver_str", type=str, required=True, - help="[ascii string] Provide hardware version in string format.") - mandatory_arguments.add_argument("--spake2_it", type=allow_any_int, required=True, - help="[int | hex int] Provide Spake2+ iteration count.") - mandatory_arguments.add_argument("--spake2_salt", type=base64_str, required=True, - help="[base64 string] Provide Spake2+ salt.") - mandatory_arguments.add_argument("--discriminator", type=allow_any_int, required=True, - help="[int] Provide BLE pairing discriminator. \ - A 12-bit value matching the field of the same name in \ - the setup code. Discriminator is used during a discovery process.") - - # optional keys - optional_arguments.add_argument("--product_url", type=str, - help="[string] provide link to product-specific web page") - optional_arguments.add_argument("--product_label", type=str, - help="[string] provide human-readable product label") - optional_arguments.add_argument("--part_number", type=str, - help="[string] provide human-readable product number") - optional_arguments.add_argument("--chip_cert_path", type=str, - help="Generate DAC and PAI certificates instead giving a path to .der files. This option requires a path to chip-cert executable." - "By default you can find chip-cert in connectedhomeip/src/tools/chip-cert directory and build it there.") - optional_arguments.add_argument("--dac_cert", type=str, - help="[.der] Provide the path to .der file containing DAC certificate.") - optional_arguments.add_argument("--dac_key", type=str, - help="[.der] Provide the path to .der file containing DAC keys.") - optional_arguments.add_argument("--generate_rd_uid", action="store_true", - help="Generate a new rotating device unique ID, print it out to console output and store it in factory data.") - optional_arguments.add_argument("--dac_key_password", type=str, - help="Provide a password to decode dac key. If dac key is not encrypted do not provide this argument.") - optional_arguments.add_argument("--pai_cert", type=str, - help="[.der] Provide the path to .der file containing PAI certificate.") - optional_arguments.add_argument("--rd_uid", type=str, - help="[hex string] [128-bit hex-encoded] Provide the rotating device unique ID. If this argument is not provided a new rotating device id unique id will be generated.") - optional_arguments.add_argument("--passcode", type=allow_any_int, - help="[int | hex] Default PASE session passcode. (This is mandatory to generate Spake2+ verifier).") - optional_arguments.add_argument("--spake2_verifier", type=base64_str, - help="[base64 string] Provide Spake2+ verifier without generating it.") - optional_arguments.add_argument("--enable_key", type=str, - help="[hex string] [128-bit hex-encoded] The Enable Key is a 128-bit value that triggers manufacturer-specific action while invoking the TestEventTrigger Command." - "This value is used during Certification Tests, and should not be present on production devices.") - optional_arguments.add_argument("--user", type=str, - help="[string] Provide additional user-specific keys in JSON format: {'name_1': 'value_1', 'name_2': 'value_2', ... 'name_n', 'value_n'}.") - optional_arguments.add_argument("--gen_cd", action="store_true", default=False, - help="Generate a new Certificate Declaration in .der format according to used Vendor ID and Product ID. This certificate will not be included to the factory data.") - optional_arguments.add_argument("--cd_type", type=int, default=1, - help="[int] Type of generated Certification Declaration: 0 - development, 1 - provisional, 2 - official") - optional_arguments.add_argument("--paa_cert", type=str, - help="Provide a path to the Product Attestation Authority (PAA) certificate to generate the PAI certificate. Without providing it, a testing PAA stored in the Matter repository will be used.") - optional_arguments.add_argument("--paa_key", type=str, - help="Provide a path to the Product Attestation Authority (PAA) key to generate the PAI certificate. Without providing it, a testing PAA key stored in the Matter repository will be used.") - args = parser.parse_args() - - if args.verbose: - log.basicConfig(format='[%(asctime)s][%(levelname)s] %(message)s', level=log.DEBUG) - else: - log.basicConfig(format='[%(levelname)s] %(message)s', level=log.INFO) - - # check if json file already exist - if(exists(args.output) and not args.overwrite): - log.error("Output file: {} already exist, to create a new one add argument '--overwrite'. By default overwriting is disabled".format(args.output)) - return - - generator = FactoryDataGenerator(args) - generator.generate_json() - - -if __name__ == "__main__": - main() diff --git a/scripts/tools/telink/mfg_tool.py b/scripts/tools/telink/mfg_tool.py new file mode 100644 index 00000000000000..2c4390c0d0eed3 --- /dev/null +++ b/scripts/tools/telink/mfg_tool.py @@ -0,0 +1,755 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2022 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import base64 +import binascii +import csv +import json +import os +import random +import shutil +import subprocess +import logging as logger +import sys +import cryptography.hazmat.backends +import cryptography.x509 +import pyqrcode +import cbor2 as cbor +from intelhex import IntelHex + +TOOLS = { + 'spake2p': None, + 'chip-cert': None, + 'chip-tool': None, +} + +INVALID_PASSCODES = [00000000, 11111111, 22222222, 33333333, 44444444, 55555555, + 66666666, 77777777, 88888888, 99999999, 12345678, 87654321] + +FACTORY_DATA_VERSION = 1 +SERIAL_NUMBER_LEN = 32 + +# Lengths for manual pairing codes and qrcode +SHORT_MANUALCODE_LEN = 11 +LONG_MANUALCODE_LEN = 21 +QRCODE_LEN = 22 +ROTATING_DEVICE_ID_UNIQUE_ID_LEN_BITS = 128 +HEX_PREFIX = "hex:" +DEV_SN_CSV_HDR = "Serial Number,\n" + +NVS_MEMORY = dict() + + +def nvs_memory_append(key, value): + if isinstance(value, str): + NVS_MEMORY[key] = value.encode("utf-8") + else: + NVS_MEMORY[key] = value + + +def nvs_memory_update(key, value): + if isinstance(value, str): + NVS_MEMORY.update({key: value.encode("utf-8")}) + else: + NVS_MEMORY.update({key: value}) + + +def check_tools_exists(args): + if args.spake2_path: + TOOLS['spake2p'] = shutil.which(args.spake2_path) + else: + TOOLS['spake2p'] = shutil.which('spake2p') + + if TOOLS['spake2p'] is None: + logger.error('spake2p not found, please specify --spake2-path argument') + sys.exit(1) + # if the certs and keys are not in the generated partitions or the specific dac cert and key are used, + # the chip-cert is not needed. + if args.paa or (args.pai and (args.dac_cert is None and args.dac_key is None)): + if args.chip_cert_path: + TOOLS['chip-cert'] = shutil.which(args.chip_cert_path) + else: + TOOLS['chip-cert'] = shutil.which('chip-cert') + if TOOLS['chip-cert'] is None: + logger.error('chip-cert not found, please specify --chip-cert-path argument') + sys.exit(1) + + if args.chip_tool_path: + TOOLS['chip-tool'] = shutil.which(args.chip_tool_path) + else: + TOOLS['chip-tool'] = shutil.which('chip-tool') + if TOOLS['chip-tool'] is None: + logger.error('chip-tool not found, please specify --chip-tool-path argument') + sys.exit(1) + + logger.debug('Using following tools:') + logger.debug('spake2p: {}'.format(TOOLS['spake2p'])) + logger.debug('chip-cert: {}'.format(TOOLS['chip-cert'])) + logger.debug('chip-tool: {}'.format(TOOLS['chip-tool'])) + + +def execute_cmd(cmd): + logger.debug('Executing Command: {}'.format(cmd)) + status = subprocess.run(cmd, capture_output=True) + + try: + status.check_returncode() + except subprocess.CalledProcessError as e: + if status.stderr: + logger.error('[stderr]: {}'.format(status.stderr.decode('utf-8').strip())) + logger.error('Command failed with error: {}'.format(e)) + sys.exit(1) + + +def check_str_range(s, min_len, max_len, name): + if s and ((len(s) < min_len) or (len(s) > max_len)): + logger.error('%s must be between %d and %d characters', name, min_len, max_len) + sys.exit(1) + + +def check_int_range(value, min_value, max_value, name): + if value and ((value < min_value) or (value > max_value)): + logger.error('%s is out of range, should be in range [%d, %d]', name, min_value, max_value) + sys.exit(1) + + +def vid_pid_str(vid, pid): + return '_'.join([hex(vid)[2:], hex(pid)[2:]]) + + +def read_der_file(path: str): + logger.debug("Reading der file {}...", path) + try: + with open(path, 'rb') as f: + data = f.read() + return data + except IOError as e: + logger.error(e) + raise e + + +def read_key_bin_file(path: str): + try: + with open(path, 'rb') as file: + key_data = file.read() + + return key_data + + except IOError or ValueError: + return None + + +def setup_out_dir(out_dir_top, args, serial: str): + out_dir = os.sep.join([out_dir_top, vid_pid_str(args.vendor_id, args.product_id)]) + + if args.in_tree: + out_dir = out_dir_top + + os.makedirs(out_dir, exist_ok=True) + + dirs = { + 'output': os.sep.join([out_dir, serial]), + 'internal': os.sep.join([out_dir, serial, 'internal']), + } + + if args.in_tree: + dirs['output'] = out_dir + dirs['internal'] = os.sep.join([out_dir, 'internal']) + + os.makedirs(dirs['output'], exist_ok=True) + os.makedirs(dirs['internal'], exist_ok=True) + + return dirs + + +def convert_x509_cert_from_pem_to_der(pem_file, out_der_file): + with open(pem_file, 'rb') as f: + pem_data = f.read() + + pem_cert = cryptography.x509.load_pem_x509_certificate(pem_data, cryptography.hazmat.backends.default_backend()) + der_cert = pem_cert.public_bytes(cryptography.hazmat.primitives.serialization.Encoding.DER) + + with open(out_der_file, 'wb') as f: + f.write(der_cert) + + +def generate_passcode(args, out_dirs): + salt_len_max = 32 + + cmd = [ + TOOLS['spake2p'], 'gen-verifier', + '--iteration-count', str(args.spake2_it), + '--salt-len', str(salt_len_max), + '--out', os.sep.join([out_dirs['output'], 'pin.csv']) + ] + + # If passcode is provided, use it + if (args.passcode): + cmd.extend(['--pin-code', str(args.passcode)]) + + execute_cmd(cmd) + + +def generate_discriminator(args, out_dirs): + # If discriminator is provided, use it + if args.discriminator: + disc = args.discriminator + else: + disc = random.randint(0x0000, 0x0FFF) + # Append discriminator to each line of the passcode file + with open(os.sep.join([out_dirs['output'], 'pin.csv']), 'r') as fd: + lines = fd.readlines() + + lines[0] = ','.join([lines[0].strip(), 'Discriminator']) + for i in range(1, len(lines)): + lines[i] = ','.join([lines[i].strip(), str(disc)]) + + with open(os.sep.join([out_dirs['output'], 'pin_disc.csv']), 'w') as fd: + fd.write('\n'.join(lines) + '\n') + + os.remove(os.sep.join([out_dirs['output'], 'pin.csv'])) + + +def generate_pai_certs(args, ca_key, ca_cert, out_key, out_cert): + cmd = [ + TOOLS['chip-cert'], 'gen-att-cert', + '--type', 'i', + '--subject-cn', '"{} PAI {}"'.format(args.cn_prefix, '00'), + '--out-key', out_key, + '--out', out_cert, + ] + + if args.lifetime: + cmd.extend(['--lifetime', str(args.lifetime)]) + if args.valid_from: + cmd.extend(['--valid-from', str(args.valid_from)]) + + cmd.extend([ + '--subject-vid', hex(args.vendor_id)[2:], + '--subject-pid', hex(args.product_id)[2:], + '--ca-key', ca_key, + '--ca-cert', ca_cert, + ]) + + execute_cmd(cmd) + logger.info('Generated PAI certificate: {}'.format(out_cert)) + logger.info('Generated PAI private key: {}'.format(out_key)) + + +def setup_root_certificates(args, dirs): + pai_cert = { + 'cert_pem': None, + 'cert_der': None, + 'key_pem': None, + } + # If PAA is passed as input, then generate PAI certificate + if args.paa: + # output file names + pai_cert['cert_pem'] = os.sep.join([dirs['internal'], 'pai_cert.pem']) + pai_cert['cert_der'] = os.sep.join([dirs['internal'], 'pai_cert.der']) + pai_cert['key_pem'] = os.sep.join([dirs['internal'], 'pai_key.pem']) + + generate_pai_certs(args, args.key, args.cert, pai_cert['key_pem'], pai_cert['cert_pem']) + convert_x509_cert_from_pem_to_der(pai_cert['cert_pem'], pai_cert['cert_der']) + logger.info('Generated PAI certificate in DER format: {}'.format(pai_cert['cert_der'])) + + # If PAI is passed as input, generate DACs + elif args.pai: + pai_cert['cert_pem'] = args.cert + pai_cert['key_pem'] = args.key + pai_cert['cert_der'] = os.sep.join([dirs['internal'], 'pai_cert.der']) + + convert_x509_cert_from_pem_to_der(pai_cert['cert_pem'], pai_cert['cert_der']) + logger.info('Generated PAI certificate in DER format: {}'.format(pai_cert['cert_der'])) + + return pai_cert + + +# Generate the Public and Private key pair binaries +def generate_keypair_bin(pem_file, out_privkey_bin, out_pubkey_bin): + with open(pem_file, 'rb') as f: + pem_data = f.read() + + key_pem = cryptography.hazmat.primitives.serialization.load_pem_private_key(pem_data, None) + private_number_val = key_pem.private_numbers().private_value + public_number_x = key_pem.public_key().public_numbers().x + public_number_y = key_pem.public_key().public_numbers().y + public_key_first_byte = 0x04 + + with open(out_privkey_bin, 'wb') as f: + f.write(private_number_val.to_bytes(32, byteorder='big')) + + with open(out_pubkey_bin, 'wb') as f: + f.write(public_key_first_byte.to_bytes(1, byteorder='big')) + f.write(public_number_x.to_bytes(32, byteorder='big')) + f.write(public_number_y.to_bytes(32, byteorder='big')) + + +def generate_dac_cert(iteration, args, out_dirs, discriminator, passcode, ca_key, ca_cert): + out_key_pem = os.sep.join([out_dirs['internal'], 'DAC_key.pem']) + out_cert_pem = out_key_pem.replace('key.pem', 'cert.pem') + out_cert_der = out_key_pem.replace('key.pem', 'cert.der') + out_private_key_bin = out_key_pem.replace('key.pem', 'private_key.bin') + out_public_key_bin = out_key_pem.replace('key.pem', 'public_key.bin') + + cmd = [ + TOOLS['chip-cert'], 'gen-att-cert', + '--type', 'd', + '--subject-cn', '"{} DAC {}"'.format(args.cn_prefix, iteration), + '--out-key', out_key_pem, + '--out', out_cert_pem, + ] + + if args.lifetime: + cmd.extend(['--lifetime', str(args.lifetime)]) + if args.valid_from: + cmd.extend(['--valid-from', str(args.valid_from)]) + + cmd.extend(['--subject-vid', hex(args.vendor_id)[2:], + '--subject-pid', hex(args.product_id)[2:], + '--ca-key', ca_key, + '--ca-cert', ca_cert, + ]) + + execute_cmd(cmd) + logger.info('Generated DAC certificate: {}'.format(out_cert_pem)) + logger.info('Generated DAC private key: {}'.format(out_key_pem)) + + convert_x509_cert_from_pem_to_der(out_cert_pem, out_cert_der) + logger.info('Generated DAC certificate in DER format: {}'.format(out_cert_der)) + + generate_keypair_bin(out_key_pem, out_private_key_bin, out_public_key_bin) + logger.info('Generated DAC private key in binary format: {}'.format(out_private_key_bin)) + logger.info('Generated DAC public key in binary format: {}'.format(out_public_key_bin)) + + return out_cert_der, out_private_key_bin, out_public_key_bin + + +def use_dac_cert_from_args(args, out_dirs): + logger.info('Using DAC from command line arguments...') + logger.info('DAC Certificate: {}'.format(args.dac_cert)) + logger.info('DAC Private Key: {}'.format(args.dac_key)) + + # There should be only one UUID in the UUIDs list if DAC is specified + out_cert_der = os.sep.join([out_dirs['internal'], 'DAC_cert.der']) + out_private_key_bin = out_cert_der.replace('cert.der', 'private_key.bin') + out_public_key_bin = out_cert_der.replace('cert.der', 'public_key.bin') + + convert_x509_cert_from_pem_to_der(args.dac_cert, out_cert_der) + logger.info('Generated DAC certificate in DER format: {}'.format(out_cert_der)) + + generate_keypair_bin(args.dac_key, out_private_key_bin, out_public_key_bin) + logger.info('Generated DAC private key in binary format: {}'.format(out_private_key_bin)) + logger.info('Generated DAC public key in binary format: {}'.format(out_public_key_bin)) + + return out_cert_der, out_private_key_bin, out_public_key_bin + + +def get_manualcode_args(vid, pid, flow, discriminator, passcode): + payload_args = list() + payload_args.append('--discriminator') + payload_args.append(str(discriminator)) + payload_args.append('--setup-pin-code') + payload_args.append(str(passcode)) + payload_args.append('--version') + payload_args.append('0') + payload_args.append('--vendor-id') + payload_args.append(str(vid)) + payload_args.append('--product-id') + payload_args.append(str(pid)) + payload_args.append('--commissioning-mode') + payload_args.append(str(flow)) + return payload_args + + +def get_qrcode_args(vid, pid, flow, discriminator, passcode, disc_mode): + payload_args = get_manualcode_args(vid, pid, flow, discriminator, passcode) + payload_args.append('--rendezvous') + payload_args.append(str(1 << disc_mode)) + return payload_args + + +def get_chip_qrcode(chip_tool, vid, pid, flow, discriminator, passcode, disc_mode): + payload_args = get_qrcode_args(vid, pid, flow, discriminator, passcode, disc_mode) + cmd_args = [chip_tool, 'payload', 'generate-qrcode'] + cmd_args.extend(payload_args) + data = subprocess.check_output(cmd_args) + + # Command output is as below: + # \x1b[0;32m[1655386003372] [23483:7823617] CHIP: [TOO] QR Code: MT:Y.K90-WB010E7648G00\x1b[0m + return data.decode('utf-8').split('QR Code: ')[1][:QRCODE_LEN] + + +def get_chip_manualcode(chip_tool, vid, pid, flow, discriminator, passcode): + payload_args = get_manualcode_args(vid, pid, flow, discriminator, passcode) + cmd_args = [chip_tool, 'payload', 'generate-manualcode'] + cmd_args.extend(payload_args) + data = subprocess.check_output(cmd_args) + + # Command output is as below: + # \x1b[0;32m[1655386909774] [24424:7837894] CHIP: [TOO] Manual Code: 749721123365521327689\x1b[0m\n + # OR + # \x1b[0;32m[1655386926028] [24458:7838229] CHIP: [TOO] Manual Code: 34972112338\x1b[0m\n + # Length of manual code depends on the commissioning flow: + # For standard commissioning flow it is 11 digits + # For User-intent and custom commissioning flow it is 21 digits + manual_code_len = LONG_MANUALCODE_LEN if flow else SHORT_MANUALCODE_LEN + return data.decode('utf-8').split('Manual Code: ')[1][:manual_code_len] + + +def generate_onboarding_data(args, out_dirs, discriminator, passcode): + chip_manualcode = get_chip_manualcode(TOOLS['chip-tool'], args.vendor_id, args.product_id, + args.commissioning_flow, discriminator, passcode) + chip_qrcode = get_chip_qrcode(TOOLS['chip-tool'], args.vendor_id, args.product_id, + args.commissioning_flow, discriminator, passcode, args.discovery_mode) + + logger.info('Generated QR code: ' + chip_qrcode) + logger.info('Generated manual code: ' + chip_manualcode) + + csv_data = 'qrcode,manualcode,discriminator,passcode\n' + csv_data += chip_qrcode + ',' + chip_manualcode + ',' + str(discriminator) + ',' + str(passcode) + '\n' + + onboarding_data_file = os.sep.join([out_dirs['output'], 'onb_codes.csv']) + with open(onboarding_data_file, 'w') as f: + f.write(csv_data) + + # Create QR code image as mentioned in the spec + qrcode_file = os.sep.join([out_dirs['output'], 'qrcode.png']) + chip_qr = pyqrcode.create(chip_qrcode, version=2, error='M') + chip_qr.png(qrcode_file, scale=6) + + logger.info('Generated onboarding data and QR Code') + + +# This function generates the DACs, picks the commissionable data from the already present csv file, +# and generates the onboarding payloads, and writes everything to the master csv +def write_device_unique_data(args, out_dirs, pai_cert): + 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__() + + nvs_memory_append('discriminator', int(row['Discriminator'])) + nvs_memory_append('spake2_it', int(row['Iteration Count'])) + nvs_memory_append('spake2_salt', base64.b64decode(row['Salt'])) + nvs_memory_append('spake2_verifier', base64.b64decode(row['Verifier'])) + nvs_memory_append('passcode', int(row['PIN Code'])) + + if args.paa or args.pai: + if args.dac_key is not None and args.dac_cert is not None: + 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']) + + 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)) + + if (args.enable_rotating_device_id is True) and (args.rd_id_uid is None): + nvs_memory_update('rd_uid', binascii.b2a_hex(os.urandom( + int(ROTATING_DEVICE_ID_UNIQUE_ID_LEN_BITS / 8))).decode('utf-8')) + + # Generate onboarding data + generate_onboarding_data(args, out_dirs, int(row['Discriminator']), int(row['PIN Code'])) + + return dacs + + +def generate_partition(args, out_dirs): + logger.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'])) + + +def generate_json_summary(args, out_dirs, pai_certs, dacs_cert, serial_num: str): + json_dict = dict() + + json_dict['serial_num'] = serial_num + + for key, nvs_value in NVS_MEMORY.items(): + if (not isinstance(nvs_value, bytes) and not isinstance(nvs_value, bytearray)): + json_dict[key] = nvs_value + + 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__() + json_dict['passcode'] = row['PIN Code'] + json_dict['spake2_salt'] = row['Salt'] + json_dict['spake2_verifier'] = row['Verifier'] + + with open(os.sep.join([out_dirs['output'], 'onb_codes.csv']), 'r') as csvf: + pin_disc_dict = csv.DictReader(csvf) + row = pin_disc_dict.__next__() + for key, value in row.items(): + json_dict[key] = value + + for key, value in pai_certs.items(): + json_dict[key] = value + + if dacs_cert is not None: + json_dict['dac_cert'] = dacs_cert[0] + json_dict['dac_priv_key'] = dacs_cert[1] + json_dict['dac_pub_key'] = dacs_cert[2] + + json_dict['cert_dclrn'] = args.cert_dclrn + + # Format vid & pid as hex + json_dict['vendor_id'] = hex(json_dict['vendor_id']) + json_dict['product_id'] = hex(json_dict['product_id']) + + with open(os.sep.join([out_dirs['output'], 'summary.json']), 'w') as json_file: + json.dump(json_dict, json_file, indent=4) + + +def add_additional_kv(args, serial_num): + # Device instance information + if args.vendor_id is not None: + nvs_memory_append('vendor_id', args.vendor_id) + if args.vendor_name is not None: + nvs_memory_append('vendor_name', args.vendor_name) + if args.product_id is not None: + nvs_memory_append('product_id', args.product_id) + if args.product_name is not None: + nvs_memory_append('product_name', args.product_name) + if args.hw_ver is not None: + nvs_memory_append('hw_ver', args.hw_ver) + if args.hw_ver_str is not None: + nvs_memory_append('hw_ver_str', args.hw_ver_str) + if args.mfg_date is not None: + nvs_memory_append('date', args.mfg_date) + if args.enable_rotating_device_id: + nvs_memory_append('rd_uid', args.rd_id_uid) + + # Add the serial-num + nvs_memory_append('sn', serial_num) + + nvs_memory_append('version', FACTORY_DATA_VERSION) + + if args.enable_key: + nvs_memory_append('enable_key', args.enable_key) + + # Keys from basic clusters + if args.product_label is not None: + nvs_memory_append('product_label', args.product_label) + if args.product_url is not None: + nvs_memory_append('product_url', args.product_url) + if args.part_number is not None: + nvs_memory_append('part_number', args.part_number) + + +def get_and_validate_args(): + def allow_any_int(i): return int(i, 0) + def base64_str(s): return base64.b64decode(s) + + parser = argparse.ArgumentParser(description='Manufacuring partition generator tool', + formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=50)) + mandatory_args = parser.add_argument_group("Mandatory keys", "These arguments must be provided to generate JSON file") + optional_args = parser.add_argument_group("Optional keys", "These arguments are optional and they depend on the user-purpose") + + # General options + general_args = parser.add_argument_group('General options') + general_args.add_argument('-n', '--count', type=allow_any_int, default=1, + help='The number of manufacturing partition binaries to generate. Default is 1.') + general_args.add_argument("--output", type=str, required=False, default="out", + help="[string] Output path where generated data will be stored.") + general_args.add_argument("--spake2-path", type=str, required=False, + help="[string] Provide Spake2+ tool path") + general_args.add_argument("--chip-tool-path", type=str, required=False, + help="[string] Provide chip-tool path") + general_args.add_argument("--chip-cert-path", type=str, required=False, + help="[string] Provide chip-cert path") + general_args.add_argument("--overwrite", action="store_true", default=False, + help="If output directory exist this argument allows to generate new factory data and overwrite it.") + general_args.add_argument("--in-tree", action="store_true", default=False, + help="Use it only when building factory data from Matter source code.") + general_args.add_argument("--enable-key", type=str, + help="[hex string] [128-bit hex-encoded] The Enable Key is a 128-bit value that triggers manufacturer-specific action while invoking the TestEventTrigger Command." + "This value is used during Certification Tests, and should not be present on production devices.") + # Commissioning options + commissioning_args = parser.add_argument_group('Commisioning options') + commissioning_args.add_argument('--passcode', type=allow_any_int, + help='The passcode for pairing. Randomly generated if not specified.') + commissioning_args.add_argument("--spake2-it", type=allow_any_int, default=1000, + help="[int] Provide Spake2+ iteration count.") + commissioning_args.add_argument('--discriminator', type=allow_any_int, + help='The discriminator for pairing. Randomly generated if not specified.') + commissioning_args.add_argument('-cf', '--commissioning-flow', type=allow_any_int, default=0, + help='Device commissioning flow, 0:Standard, 1:User-Intent, 2:Custom. \ + Default is 0.', choices=[0, 1, 2]) + commissioning_args.add_argument('-dm', '--discovery-mode', type=allow_any_int, default=1, + help='Commissionable device discovery networking technology. \ + 0:WiFi-SoftAP, 1:BLE, 2:On-network. Default is BLE.', choices=[0, 1, 2]) + + # Device insrance 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') + dev_inst_args.add_argument('-p', '--product-id', type=allow_any_int, required=False, help='Product id') + dev_inst_args.add_argument('--product-name', type=str, required=False, help='Product name') + dev_inst_args.add_argument('--hw-ver', type=allow_any_int, required=False, help='Hardware version') + dev_inst_args.add_argument('--hw-ver-str', type=str, required=False, help='Hardware version string') + dev_inst_args.add_argument('--mfg-date', type=str, required=False, help='Manufacturing date in format YYYY-MM-DD') + dev_inst_args.add_argument('--serial-num', type=str, required=False, help='Serial number in hex format') + dev_inst_args.add_argument('--enable-rotating-device-id', action='store_true', + help='Enable Rotating device id in the generated binaries') + dev_inst_args.add_argument('--rd-id-uid', type=str, required=False, + help='128-bit unique identifier for generating rotating device identifier, provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"') + + dac_args = parser.add_argument_group('Device attestation credential options') + # If DAC is present then PAI key is not required, so it is marked as not required here + # but, if DAC is not present then PAI key is required and that case is validated in validate_args() + dac_args.add_argument('-c', '--cert', type=str, required=False, help='The input certificate file in PEM format.') + dac_args.add_argument('-k', '--key', type=str, required=False, help='The input key file in PEM format.') + dac_args.add_argument('-cd', '--cert-dclrn', type=str, required=True, help='The certificate declaration file in DER format.') + dac_args.add_argument('--dac-cert', type=str, help='The input DAC certificate file in PEM format.') + dac_args.add_argument('--dac-key', type=str, help='The input DAC private key file in PEM format.') + dac_args.add_argument('-cn', '--cn-prefix', type=str, default='Telink', + help='The common name prefix of the subject of the generated certificate.') + dac_args.add_argument('-lt', '--lifetime', default=4294967295, type=allow_any_int, + help='Lifetime of the generated certificate. Default is 4294967295 if not specified, \ + this indicate that certificate does not have well defined expiration date.') + dac_args.add_argument('-vf', '--valid-from', type=str, + help='The start date for the certificate validity period in format --
[ :: ]. \ + Default is current date.') + input_cert_group = dac_args.add_mutually_exclusive_group(required=False) + input_cert_group.add_argument('--paa', action='store_true', help='Use input certificate as PAA certificate.') + input_cert_group.add_argument('--pai', action='store_true', help='Use input certificate as PAI certificate.') + + basic_args = parser.add_argument_group('Few more Basic clusters options') + basic_args.add_argument('--product-label', type=str, required=False, help='Product label') + basic_args.add_argument('--product-url', type=str, required=False, help='Product URL') + basic_args.add_argument('--part_number', type=str, required=False, help='Provide human-readable product number') + + part_gen_args = parser.add_argument_group('Partition generator options') + part_gen_args.add_argument('--offset', type=allow_any_int, default=0x1F4000, + 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, default=0x1000, + help='The maximum partition size') + + args = parser.parse_args() + + # Validate in-tree parameter + if args.count > 1 and args.in_tree: + logger.error('Option --in-tree can not be use together with --count > 1') + sys.exit(1) + + # Validate discriminator and passcode + check_int_range(args.discriminator, 0x0000, 0x0FFF, 'Discriminator') + if args.passcode is not None: + if ((args.passcode < 0x0000001 and args.passcode > 0x5F5E0FE) or (args.passcode in INVALID_PASSCODES)): + logger.error('Invalid passcode' + str(args.passcode)) + sys.exit(1) + + # Validate the device instance information + check_int_range(args.product_id, 0x0000, 0xFFFF, 'Product id') + check_int_range(args.vendor_id, 0x0000, 0xFFFF, 'Vendor id') + check_int_range(args.hw_ver, 0x0000, 0xFFFF, 'Hardware version') + check_int_range(args.spake2_it, 1, 10000, 'Spake2+ iteration count') + check_str_range(args.serial_num, 1, SERIAL_NUMBER_LEN, 'Serial number') + check_str_range(args.vendor_name, 1, 32, 'Vendor name') + check_str_range(args.product_name, 1, 32, 'Product name') + check_str_range(args.hw_ver_str, 1, 64, 'Hardware version string') + check_str_range(args.mfg_date, 8, 16, 'Manufacturing date') + check_str_range(args.rd_id_uid, 32, 32, 'Rotating device Unique id') + + # Validates the attestation related arguments + # DAC key and DAC cert both should be present or none + if (args.dac_key is not None) != (args.dac_cert is not None): + logger.error("dac_key and dac_cert should be both present or none") + sys.exit(1) + else: + # Make sure PAI certificate is present if DAC is present + if (args.dac_key is not None) and (args.pai is False): + logger.error('Please provide PAI certificate along with DAC certificate and DAC key') + sys.exit(1) + + # Validate the input certificate type, if DAC is not present + if args.dac_key is None and args.dac_cert is None: + if args.paa: + logger.info('Input Root certificate type PAA') + elif args.pai: + logger.info('Input Root certificate type PAI') + else: + logger.info('Do not include the device attestation certificates and keys in partition binaries') + + # Check if Key and certificate are present + if (args.paa or args.pai) and (args.key is None or args.cert is None): + logger.error('CA key and certificate are required to generate DAC key and certificate') + sys.exit(1) + + check_str_range(args.product_label, 1, 64, 'Product Label') + check_str_range(args.product_url, 1, 256, 'Product URL') + check_str_range(args.part_number, 1, 32, 'Part Number') + + return args + + +def main(): + logger.basicConfig(format='[%(asctime)s] [%(levelname)7s] - %(message)s', level=logger.INFO) + args = get_and_validate_args() + check_tools_exists(args) + + if os.path.exists(args.output): + if args.overwrite: + logger.info("Output directory already exists. All data will be overwritten.") + shutil.rmtree(args.output) + else: + logger.error("Output directory exists! Please use different or remove existing.") + exit(1) + + # If serial number is not passed, then generate one + if args.serial_num is None: + serial_num_int = int(binascii.b2a_hex(os.urandom(SERIAL_NUMBER_LEN)), 16) + logger.info("Serial number not provided. Using generated one: {}".format(hex(serial_num_int))) + else: + serial_num_int = int(args.serial_num, 16) + + out_dir_top = os.path.realpath(args.output) + os.makedirs(out_dir_top, exist_ok=True) + + dev_sn_file = open(os.sep.join([out_dir_top, "device_sn.csv"]), "w") + 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') + logger.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, out_dirs) + generate_json_summary(args, out_dirs, pai_cert, dacs_cert, serial_num_str) + + dev_sn_file.close() + + +if __name__ == "__main__": + main() diff --git a/scripts/tools/telink/readme.md b/scripts/tools/telink/readme.md new file mode 100644 index 00000000000000..d3539b590d3591 --- /dev/null +++ b/scripts/tools/telink/readme.md @@ -0,0 +1,212 @@ +# Manufacturing Partition Generator Utility + +This tool is designed to generate factory partitions for mass production. + +## Dependencies + +Please make sure you have had the following tools before using the generator +tool. + +- [CHIP Certificate Tool](https://github.com/project-chip/connectedhomeip/tree/master/src/tools/chip-cert) + +- [SPAKE2P Parameters Tool](https://github.com/project-chip/connectedhomeip/tree/master/src/tools/spake2p) + +- [chip-tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool) + +### [Build Matter tools](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/BUILDING.md#build-for-the-host-os-linux-or-macos) + +1. Using the following commands to generate chip-tool, spake2p and chip-cert at + `path/to/connectedhomeip/build/out/host`. + + ```shell + cd path/to/connectedhomeip + source scripts/activate.sh + gn gen build/out/host + ninja -C build/out/host + ``` + +2. Add the tools path to \$PATH + + ```shell + export PATH="$PATH:path/to/connectedhomeip/build/out/host" + ``` + +### Install python dependencies + +```shell +cd path/to/connectedhomeip/scripts/tools/telink/ +python3 -m pip install -r requirements.txt +``` + +## Usage + +The following commands generate factory partitions using the default testing PAI +keys, certificates, and CD in Matter project. You can make it using yours +instead in real production. + +### Generate a factory partition + +```shell +python3 mfg_tool.py -v 0xFFF2 -p 0x8001 \ +--serial-num AABBCCDDEEFF11223344556677889900 \ +--vendor-name "Telink Semiconductor" \ +--product-name "not-specified" \ +--mfg-date 2022-12-12 \ +--hw-ver 1 \ +--hw-ver-str "prerelase" \ +--pai \ +--key /path/to/connectedhomeip/credentials/test/attestation/Chip-Test-PAI-FFF2-8001-Key.pem \ +--cert /path/to/connectedhomeip/credentials/test/attestation/Chip-Test-PAI-FFF2-8001-Cert.pem \ +-cd /path/to/connectedhomeip/credentials/test/certification-declaration/Chip-Test-CD-FFF2-8001.der \ +--spake2-path /path/to/spake2p \ +--chip-tool-path /path/to/chip-tool \ +--chip-cert-path /path/to/chip-cert +``` + +### Generate 5 factory partitions [Optional argument : --count] + +```shell +python3 mfg_tool.py --count 5 -v 0xFFF2 -p 0x8001 \ +--serial-num AABBCCDDEEFF11223344556677889900 \ +--vendor-name "Telink Semiconductor" \ +--product-name "not-specified" \ +--mfg-date 2022-02-02 \ +--hw-ver 1 \ +--hw-ver-str "prerelase" \ +--pai \ +--key /path/to/connectedhomeip/credentials/test/attestation/Chip-Test-PAI-FFF2-8001-Key.pem \ +--cert /path/to/connectedhomeip/credentials/test/attestation/Chip-Test-PAI-FFF2-8001-Cert.pem \ +-cd /path/to/connectedhomeip/credentials/test/certification-declaration/Chip-Test-CD-FFF2-8001.der \ +--spake2-path /path/to/spake2p \ +--chip-tool-path /path/to/chip-tool \ +--chip-cert-path /path/to/chip-cert +``` + +## Output files and directory structure + +``` +out +├── device_sn.csv +└── fff2_8001 + ├── aabbccddeeff11223344556677889900 + │   ├── factory_data.bin + │   ├── factory_data.hex + │   ├── internal + │   │   ├── DAC_cert.der + │   │   ├── DAC_cert.pem + │   │   ├── DAC_key.pem + │   │   ├── DAC_private_key.bin + │   │   ├── DAC_public_key.bin + │   │   └── pai_cert.der + │   ├── onb_codes.csv + │   ├── pin_disc.csv + │   ├── qrcode.png + │   └── summary.json + ├── aabbccddeeff11223344556677889901 + │   ├── factory_data.bin + │   ├── factory_data.hex + │   ├── internal + │   │   ├── DAC_cert.der + │   │   ├── DAC_cert.pem + │   │   ├── DAC_key.pem + │   │   ├── DAC_private_key.bin + │   │   ├── DAC_public_key.bin + │   │   └── pai_cert.der + │   ├── onb_codes.csv + │   ├── pin_disc.csv + │   ├── qrcode.png + │   └── summary.json + ├── aabbccddeeff11223344556677889902 + │   ├── factory_data.bin + │   ├── factory_data.hex + │   ├── internal + │   │   ├── DAC_cert.der + │   │   ├── DAC_cert.pem + │   │   ├── DAC_key.pem + │   │   ├── DAC_private_key.bin + │   │   ├── DAC_public_key.bin + │   │   └── pai_cert.der + │   ├── onb_codes.csv + │   ├── pin_disc.csv + │   ├── qrcode.png + │   └── summary.json + └── aabbccddeeff11223344556677889903 + ├── factory_data.bin + ├── factory_data.hex + ├── internal + │   ├── DAC_cert.der + │   ├── DAC_cert.pem + │   ├── DAC_key.pem + │   ├── DAC_private_key.bin + │   ├── DAC_public_key.bin + │   └── pai_cert.der + ├── onb_codes.csv + ├── pin_disc.csv + ├── qrcode.png + └── summary.json +``` + +Tool generates following output files: + +- Partition Binary : `factory_data.bin` and `factory_data.hex` +- Partition JSON : `summary.json` +- Onboarding codes : `onb_codes.csv` +- QR Code image : `qrcode.png` + +Other intermediate files are stored in `internal/` directory: + +- PAI Certificate : `pai_cert.der` +- DAC Certificates : `DAC_cert.der` and `DAC_cert.pem` +- DAC Private Key : `DAC_private_key.bin` +- DAC Public Key : `DAC_public_key.bin` + +Above files are stored at `out//`. Each device is identified with +an unique SN. + +## Flashing the factory partition FW into Matter App + +You can try one of these factory partition FW on developing stage. + +1. Prepare a Matter App FW with empty factory data partition. + + For example, `lighting-app`. Please generate the FW as below: + + ```shell + cd path/to/connectedhomeip/example/ligting-app/telink/ + west build -- -DCONFIG_CHIP_FACTORY_DATA=y + ``` + + The output FW is stored at `./build/zephyr/zephyr.bin`. + +2. Then flash Matter App FW onto B91 board. + +3. Then flash the `factory_data.bin` generated from the generator tool at + specific address: + + > Note: The offset for Matter + > [v1.0-branch](https://github.com/telink-semi/zephyr/blob/telink_matter_v1.0-branch/boards/riscv/tlsr9518adk80d/tlsr9518adk80d.dts) + > is `0xF4000` and for + > [master branch](https://github.com/telink-semi/zephyr/blob/telink_matter/boards/riscv/tlsr9518adk80d/tlsr9518adk80d.dts) + > is `0x1F4000`. You can check the `factory_partition` reg at + > `tlsr9518adk80d.dts` for details. + + For example, the `factory_data_bin` with serial number + `aabbccddeeff11223344556677889900`. Here is the expected output in logging: + + ```shell + ... + I: 947 [DL]Device Configuration: + I: 951 [DL] Serial Number: aabbccddeeff11223344556677889900 + I: 957 [DL] Vendor Id: 65522 (0xFFF2) + I: 961 [DL] Product Id: 32769 (0x8001) + I: 965 [DL] Hardware Version: 1 + I: 969 [DL] Setup Pin Code (0 for UNKNOWN/ERROR): 93320241 + I: 975 [DL] Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3008 (0xBC0) + I: 983 [DL] Manufacturing Date: 2022-02-02 + I: 988 [DL] Device Type: 65535 (0xFFFF) + I: 993 [SVR]SetupQRCode: [MT:634J042C00O-KB7Z-10] + I: 999 [SVR]Copy/paste the below URL in a browser to see the QR Code: + I: 1006 [SVR]https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A634J042C00O-KB7Z-10 + I: 1017 [SVR]Manual pairing code: [26251356956] + ... + ``` diff --git a/scripts/tools/telink/requirements.txt b/scripts/tools/telink/requirements.txt new file mode 100644 index 00000000000000..68323409dd2f6c --- /dev/null +++ b/scripts/tools/telink/requirements.txt @@ -0,0 +1,6 @@ +cryptography==36.0.2 +cffi==1.15.0 +future==0.18.2 +pycparser==2.21 +pypng==0.0.21 +PyQRCode==1.2.1 \ No newline at end of file diff --git a/scripts/tools/telink/telink_factory_data.schema b/scripts/tools/telink/telink_factory_data.schema deleted file mode 100644 index 561bf4d5d72682..00000000000000 --- a/scripts/tools/telink/telink_factory_data.schema +++ /dev/null @@ -1,164 +0,0 @@ -{ - "$id": "Telink_Factory_Data_schema", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "description": "A representation of all factory data used in Matter's Telink device", - "type": "object", - "required": [ - "version", - "sn", - "vendor_id", - "product_id", - "vendor_name", - "product_name", - "date", - "hw_ver", - "hw_ver_str", - "dac_cert", - "dac_key", - "pai_cert", - "spake2_it", - "spake2_salt", - "spake2_verifier", - "discriminator" - ], - "properties": { - "version": { - "description": "Current version of the factory data set", - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "sn": { - "description": "Serial number of device", - "type": "string", - "maxLength": 32 - }, - "vendor_id": { - "description": "Vendor Identifier", - "type": "integer", - "minimum": 0, - "maximum": 65524 - }, - "product_id": { - "description": "Product Identifier", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "vendor_name": { - "description": "human-readable vendor name", - "type": "string", - "maxLength": 32 - }, - "product_name": { - "description": "human-readable product name", - "type": "string", - "maxLength": 32 - }, - "product_label": { - "description": "more user-friendly human-readable product name", - "type": "string", - "maxLength": 64 - }, - "product_url": { - "description": "link to product-specific web page", - "type": "string", - "maxLength": 256 - }, - "part_number": { - "description": "human-readable vendor assigned part number", - "type": "string", - "maxLength": 32 - }, - "date": { - "description": "Manufacturing date according to ISO 8601 in notation YYYY-MM-DD", - "type": "string", - "format": "date", - "minLength": 10, - "maxLength": 10, - "pattern": "^\\d{4}-\\d{2}-\\d{2}$" - }, - "hw_ver": { - "description": "Hardware version - integer", - "type": "integer", - "minimum": 0, - "maximum": 65536 - }, - "hw_ver_str": { - "description": "A string representation of hardware version", - "type": "string", - "minLength": 1, - "maxLength": 64 - }, - "rd_uid": { - "description": "A randomly-generated 128-bit or longer octet string. Length has been expanded with 'hex:' prefix", - "type": "string", - "pattern": "^hex:([0-9A-Fa-f]{2}){16,}$", - "minLength": 20, - "minLength": 36 - }, - "dac_cert": { - "description": "DAC certificate in hex-string format", - "type": "string", - "pattern": "^hex:([0-9A-Fa-f]{2})+$", - "minLength": 6, - "maxLength": 1204 - }, - "dac_key": { - "description": "DAC Private Key in hex-string format", - "type": "string", - "pattern": "^hex:([0-9A-Fa-f]{2}){32}$", - "minLength": 68, - "maxLength": 68 - }, - "pai_cert": { - "description": "PAI certificate in hex-string format", - "type": "string", - "pattern": "^hex:([0-9A-Fa-f]{2})+$", - "minLength": 6, - "maxLength": 1204 - }, - "passcode": { - "description": "A default PASE session passcode", - "type": "integer", - "minimum": 1, - "maximum": 99999998 - }, - "spake2_it": { - "description": "An Iteration counter for the Symmetric Password-Authenticated Key Exchange", - "type": "integer", - "minimum": 1000, - "maximum": 100000 - }, - "spake2_salt": { - "description": "A key-derivation function for the Symmetric Password-Authenticated Key Exchange.", - "type": "string", - "pattern": "^hex:([0-9A-Fa-f]{2})+$", - "minLength": 36, - "maxLength": 68 - }, - "spake2_verifier": { - "description": "A verifier for the Symmetric Password-Authenticated Key Exchange", - "type": "string", - "pattern": "^hex:([0-9A-Fa-f]{2})+$", - "minLength": 97 - }, - "discriminator": { - "description": "The Discriminator value helps to further identify potential devices during the setup process.", - "type": "integer", - "minimum": 0, - "maximum": 4095 - }, - "enable_key": { - "description": "The Enable Key is a 128-bit value that triggers manufacturer-specific action while invoking the TestEventTrigger Command", - "type": "string", - "pattern": "^hex:([0-9A-Fa-f]{2}){16}$", - "minLength": 36, - "maxLength": 36 - }, - "user": { - "description": "A user-specific additional data which should be added to factory data. This should be a Json format.", - "type": "object" - } - } -} diff --git a/scripts/tools/telink/telink_generate_partition.py b/scripts/tools/telink/telink_generate_partition.py deleted file mode 100644 index ddd3b63acc4a7f..00000000000000 --- a/scripts/tools/telink/telink_generate_partition.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2022 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import codecs -import sys -from intelhex import IntelHex -import argparse -import json -import logging as log -import cbor2 as cbor - -HEX_PREFIX = "hex:" - - -class PartitionCreator: - """ - Class to create telink partition containing FactoryData - - :param offset: This is a partition offset where data will be stored in device's flash memory - :param length: This is a maximum partition size - :param input: This is a path to input JSON file - :param output: This is a path to output directory - - """ - - def __init__(self, offset: int, length: int, input: str, output: str) -> None: - self._ih = IntelHex() - self._length = length - self._offset = offset - self._data_ready = False - self._output = output - self._input = input - try: - self.__data_to_save = self._convert_to_dict(self._load_json()) - except IOError: - sys.exit(-1) - - def generate_cbor(self): - """ - Generates .cbor file using cbor2 library. - It generate a CBORTag 55799 which is user-specific tag - - """ - if self.__data_to_save: - # prepare raw data from Json - cbor_data = cbor.dumps(self.__data_to_save) - return cbor_data - - def create_hex(self, data: bytes): - """ - Creates .hex file from CBOR. - This file can be write directly to device. - - """ - if len(data) > self._length: - raise ValueError("generated CBOR file exceeds declared maximum partition size! {} > {}".format(len(data), self._length)) - self._ih.putsz(self._offset, data) - self._ih.write_hex_file(self._output + ".hex", True) - self._data_ready = True - return True - - def create_bin(self): - """ - Creates raw binary data of created previously .hex file - - """ - if not self._data_ready: - log.error("Please create hex file first!") - return False - self._ih.tobinfile(self._output + ".bin") - return True - - @staticmethod - def _convert_to_dict(data): - """ - Converts a list containing tuples ("key_name", "key_value") to a dictionary - - If "key_value" of data entry is a string-type variable and contains a HEX_PREFIX algorithm decodes it - to hex format to be sure that a cbor file will contain proper bytes. - - If "key_value" of data entry is a dictionary, algorithm appends it to the created dictionary. - """ - output_dict = dict() - for entry in data: - if not isinstance(entry, dict): - log.debug("Processing entry {}".format(entry)) - if isinstance(data[entry], str) and data[entry].startswith(HEX_PREFIX): - output_dict[entry] = codecs.decode(data[entry][len(HEX_PREFIX):], "hex") - elif isinstance(data[entry], str): - output_dict[entry] = data[entry].encode("utf-8") - else: - output_dict[entry] = data[entry] - else: - output_dict[entry] = entry - return output_dict - - def _load_json(self): - """ - Loads file containing a JSON data and converts it to JSON format - - :raises IOError: if provided JSON file can not be read out. - """ - try: - with open(self._input, "rb") as json_file: - return json.loads(json_file.read()) - except IOError as e: - log.error("Can not read Json file {}".format(self._input)) - raise e - - -def print_flashing_help(): - print("\nTo flash the generated hex/bin containing factory data, use BDT tool") - - -def main(): - - def allow_any_int(i): return int(i, 0) - - parser = argparse.ArgumentParser(description="Telink Factory Data NVS partition generator tool") - parser.add_argument("-i", "--input", type=str, required=True, - help="Path to input .json file") - parser.add_argument("-o", "--output", type=str, required=True, - help="Prefix for output file paths, e.g. setting dir/output causes creation of the following files: dir/output.hex, and dir/output.bin") - parser.add_argument("--offset", type=allow_any_int, required=True, - help="Partition offset - an address in device's NVM memory, where factory data will be stored") - parser.add_argument("--size", type=allow_any_int, required=True, - help="The maximum partition size") - parser.add_argument("-v", "--verbose", action="store_true", - help="Run this script with DEBUG logging level") - parser.add_argument("-r", "--raw", action="store_true", - help="Do not print flashing help and other logs, only generate a .hex file. It can be useful when the script is used by other script.") - args = parser.parse_args() - - if args.verbose: - log.basicConfig(format='[%(asctime)s][%(levelname)s] %(message)s', level=log.DEBUG) - elif args.raw: - log.basicConfig(format='%(message)s', level=log.ERROR) - else: - log.basicConfig(format='[%(asctime)s] %(message)s', level=log.INFO) - - partition_creator = PartitionCreator(args.offset, args.size, args.input, args.output) - cbor_data = partition_creator.generate_cbor() - try: - if not args.raw: - print("Generating .hex file: {}.hex with offset: {} and size: {}".format(args.output, hex(args.offset), hex(args.size))) - if partition_creator.create_hex(cbor_data) and partition_creator.create_bin(): - if not args.raw: - print_flashing_help() - except ValueError as e: - log.error(e) - sys.exit(-1) - - -if __name__ == "__main__": - main() From 4e63e88509f975792a8a94e97469f1f35d68766d Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2023 12:03:17 -0500 Subject: [PATCH 4/8] Align naming in Power Source cluster with the spec. (#24240) * Align naming in Power Source cluster with the spec. And enable the Power Source events, which were commented out. * Regenerate generated files. --- .../all-clusters-app.matter | 15 ++ .../all-clusters-minimal-app.matter | 15 ++ examples/lock-app/lock-common/lock-app.matter | 15 ++ .../placeholder/linux/apps/app1/config.matter | 15 ++ .../placeholder/linux/apps/app2/config.matter | 15 ++ examples/window-app/common/window-app.matter | 15 ++ .../data-model/chip/power-source-cluster.xml | 23 ++- .../data_model/controller-clusters.matter | 15 ++ .../CHIPEventTLVValueDecoder.cpp | 173 ++++++++++++++++++ .../devicecontroller/ChipEventStructs.java | 75 ++++++++ .../chip/devicecontroller/ChipIdLookup.java | 9 + .../python/chip/clusters/Objects.py | 64 +++++++ .../CHIP/templates/availability.yaml | 27 +++ .../CHIP/zap-generated/MTRBaseClusters.h | 5 +- .../CHIP/zap-generated/MTRClusterConstants.h | 7 + .../zap-generated/MTREventTLVValueDecoder.mm | 159 ++++++++++++++++ .../CHIP/zap-generated/MTRStructsObjc.h | 39 +++- .../CHIP/zap-generated/MTRStructsObjc.mm | 93 ++++++++++ .../zap-generated/cluster-objects.cpp | 123 +++++++++++++ .../zap-generated/cluster-objects.h | 110 +++++++++++ .../app-common/zap-generated/ids/Events.h | 18 ++ .../zap-generated/cluster/Commands.h | 13 +- .../cluster/logging/DataModelLogger.cpp | 93 ++++++++++ .../cluster/logging/DataModelLogger.h | 6 + .../zap-generated/cluster/Commands.h | 3 + 25 files changed, 1126 insertions(+), 19 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 754985f37dd4f4..2999f27a55bdb4 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -862,6 +862,21 @@ server cluster PowerSource = 47 { kReplaceable = 0x8; } + info event WiredFaultChange = 0 { + WiredFault current[] = 0; + WiredFault previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFault current[] = 0; + BatFault previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFault current[] = 0; + BatChargeFault previous[] = 1; + } + readonly attribute PowerSourceStatus status = 0; readonly attribute int8u order = 1; readonly attribute char_string<60> description = 2; diff --git a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter index 58e0c12b20d3e9..0ea0a312a80a70 100644 --- a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter +++ b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter @@ -794,6 +794,21 @@ server cluster PowerSource = 47 { kReplaceable = 0x8; } + info event WiredFaultChange = 0 { + WiredFault current[] = 0; + WiredFault previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFault current[] = 0; + BatFault previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFault current[] = 0; + BatChargeFault previous[] = 1; + } + readonly attribute PowerSourceStatus status = 0; readonly attribute int8u order = 1; readonly attribute char_string<60> description = 2; diff --git a/examples/lock-app/lock-common/lock-app.matter b/examples/lock-app/lock-common/lock-app.matter index 72510069747932..283c91d72fed46 100644 --- a/examples/lock-app/lock-common/lock-app.matter +++ b/examples/lock-app/lock-common/lock-app.matter @@ -455,6 +455,21 @@ server cluster PowerSource = 47 { kReplaceable = 0x8; } + info event WiredFaultChange = 0 { + WiredFault current[] = 0; + WiredFault previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFault current[] = 0; + BatFault previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFault current[] = 0; + BatChargeFault previous[] = 1; + } + readonly attribute PowerSourceStatus status = 0; readonly attribute int8u order = 1; readonly attribute char_string<60> description = 2; diff --git a/examples/placeholder/linux/apps/app1/config.matter b/examples/placeholder/linux/apps/app1/config.matter index 383b1096765494..4ad37a9e6f581b 100644 --- a/examples/placeholder/linux/apps/app1/config.matter +++ b/examples/placeholder/linux/apps/app1/config.matter @@ -627,6 +627,21 @@ server cluster PowerSource = 47 { kReplaceable = 0x8; } + info event WiredFaultChange = 0 { + WiredFault current[] = 0; + WiredFault previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFault current[] = 0; + BatFault previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFault current[] = 0; + BatChargeFault previous[] = 1; + } + readonly attribute PowerSourceStatus status = 0; readonly attribute int8u order = 1; readonly attribute char_string<60> description = 2; diff --git a/examples/placeholder/linux/apps/app2/config.matter b/examples/placeholder/linux/apps/app2/config.matter index 383b1096765494..4ad37a9e6f581b 100644 --- a/examples/placeholder/linux/apps/app2/config.matter +++ b/examples/placeholder/linux/apps/app2/config.matter @@ -627,6 +627,21 @@ server cluster PowerSource = 47 { kReplaceable = 0x8; } + info event WiredFaultChange = 0 { + WiredFault current[] = 0; + WiredFault previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFault current[] = 0; + BatFault previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFault current[] = 0; + BatChargeFault previous[] = 1; + } + readonly attribute PowerSourceStatus status = 0; readonly attribute int8u order = 1; readonly attribute char_string<60> description = 2; diff --git a/examples/window-app/common/window-app.matter b/examples/window-app/common/window-app.matter index 578b658092fabc..cd0a0e789a10de 100644 --- a/examples/window-app/common/window-app.matter +++ b/examples/window-app/common/window-app.matter @@ -617,6 +617,21 @@ server cluster PowerSource = 47 { kReplaceable = 0x8; } + info event WiredFaultChange = 0 { + WiredFault current[] = 0; + WiredFault previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFault current[] = 0; + BatFault previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFault current[] = 0; + BatChargeFault previous[] = 1; + } + readonly attribute PowerSourceStatus status = 0; readonly attribute int8u order = 1; readonly attribute char_string<60> description = 2; diff --git a/src/app/zap-templates/zcl/data-model/chip/power-source-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/power-source-cluster.xml index 28ba55b9f30983..76b350a52bf239 100644 --- a/src/app/zap-templates/zcl/data-model/chip/power-source-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/power-source-cluster.xml @@ -59,22 +59,23 @@ limitations under the License. BatChargingCurrent ActiveBatChargeFaults - @@ -131,7 +132,7 @@ limitations under the License. - + @@ -152,6 +153,8 @@ limitations under the License. + @@ -170,4 +173,4 @@ limitations under the License. - \ No newline at end of file + diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter index d3ce74301608c7..4de517ed5d514e 100644 --- a/src/controller/data_model/controller-clusters.matter +++ b/src/controller/data_model/controller-clusters.matter @@ -995,6 +995,21 @@ client cluster PowerSource = 47 { kReplaceable = 0x8; } + info event WiredFaultChange = 0 { + WiredFault current[] = 0; + WiredFault previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFault current[] = 0; + BatFault previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFault current[] = 0; + BatChargeFault previous[] = 1; + } + readonly attribute PowerSourceStatus status = 0; readonly attribute int8u order = 1; readonly attribute char_string<60> description = 2; diff --git a/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp b/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp index d8b949d64e8a8c..8313fe238777cc 100644 --- a/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp +++ b/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp @@ -967,6 +967,179 @@ jobject DecodeEventValue(const app::ConcreteEventPath & aPath, TLV::TLVReader & using namespace app::Clusters::PowerSource; switch (aPath.mEventId) { + case Events::WiredFaultChange::Id: { + Events::WiredFaultChange::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value_current; + chip::JniReferences::GetInstance().CreateArrayList(value_current); + + auto iter_value_current_0 = cppValue.current.begin(); + while (iter_value_current_0.Next()) + { + auto & entry_0 = iter_value_current_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), static_cast(entry_0), newElement_0); + chip::JniReferences::GetInstance().AddToList(value_current, newElement_0); + } + + jobject value_previous; + chip::JniReferences::GetInstance().CreateArrayList(value_previous); + + auto iter_value_previous_0 = cppValue.previous.begin(); + while (iter_value_previous_0.Next()) + { + auto & entry_0 = iter_value_previous_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), static_cast(entry_0), newElement_0); + chip::JniReferences::GetInstance().AddToList(value_previous, newElement_0); + } + + jclass wiredFaultChangeStructClass; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipEventStructs$PowerSourceClusterWiredFaultChangeEvent", wiredFaultChangeStructClass); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipEventStructs$PowerSourceClusterWiredFaultChangeEvent"); + return nullptr; + } + jmethodID wiredFaultChangeStructCtor = + env->GetMethodID(wiredFaultChangeStructClass, "", "(Ljava/util/ArrayList;Ljava/util/ArrayList;)V"); + if (wiredFaultChangeStructCtor == nullptr) + { + ChipLogError(Zcl, "Could not find ChipEventStructs$PowerSourceClusterWiredFaultChangeEvent constructor"); + return nullptr; + } + + jobject value = env->NewObject(wiredFaultChangeStructClass, wiredFaultChangeStructCtor, value_current, value_previous); + + return value; + } + case Events::BatFaultChange::Id: { + Events::BatFaultChange::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value_current; + chip::JniReferences::GetInstance().CreateArrayList(value_current); + + auto iter_value_current_0 = cppValue.current.begin(); + while (iter_value_current_0.Next()) + { + auto & entry_0 = iter_value_current_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), static_cast(entry_0), newElement_0); + chip::JniReferences::GetInstance().AddToList(value_current, newElement_0); + } + + jobject value_previous; + chip::JniReferences::GetInstance().CreateArrayList(value_previous); + + auto iter_value_previous_0 = cppValue.previous.begin(); + while (iter_value_previous_0.Next()) + { + auto & entry_0 = iter_value_previous_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), static_cast(entry_0), newElement_0); + chip::JniReferences::GetInstance().AddToList(value_previous, newElement_0); + } + + jclass batFaultChangeStructClass; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipEventStructs$PowerSourceClusterBatFaultChangeEvent", batFaultChangeStructClass); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipEventStructs$PowerSourceClusterBatFaultChangeEvent"); + return nullptr; + } + jmethodID batFaultChangeStructCtor = + env->GetMethodID(batFaultChangeStructClass, "", "(Ljava/util/ArrayList;Ljava/util/ArrayList;)V"); + if (batFaultChangeStructCtor == nullptr) + { + ChipLogError(Zcl, "Could not find ChipEventStructs$PowerSourceClusterBatFaultChangeEvent constructor"); + return nullptr; + } + + jobject value = env->NewObject(batFaultChangeStructClass, batFaultChangeStructCtor, value_current, value_previous); + + return value; + } + case Events::BatChargeFaultChange::Id: { + Events::BatChargeFaultChange::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value_current; + chip::JniReferences::GetInstance().CreateArrayList(value_current); + + auto iter_value_current_0 = cppValue.current.begin(); + while (iter_value_current_0.Next()) + { + auto & entry_0 = iter_value_current_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), static_cast(entry_0), newElement_0); + chip::JniReferences::GetInstance().AddToList(value_current, newElement_0); + } + + jobject value_previous; + chip::JniReferences::GetInstance().CreateArrayList(value_previous); + + auto iter_value_previous_0 = cppValue.previous.begin(); + while (iter_value_previous_0.Next()) + { + auto & entry_0 = iter_value_previous_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), static_cast(entry_0), newElement_0); + chip::JniReferences::GetInstance().AddToList(value_previous, newElement_0); + } + + jclass batChargeFaultChangeStructClass; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipEventStructs$PowerSourceClusterBatChargeFaultChangeEvent", + batChargeFaultChangeStructClass); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipEventStructs$PowerSourceClusterBatChargeFaultChangeEvent"); + return nullptr; + } + jmethodID batChargeFaultChangeStructCtor = + env->GetMethodID(batChargeFaultChangeStructClass, "", "(Ljava/util/ArrayList;Ljava/util/ArrayList;)V"); + if (batChargeFaultChangeStructCtor == nullptr) + { + ChipLogError(Zcl, "Could not find ChipEventStructs$PowerSourceClusterBatChargeFaultChangeEvent constructor"); + return nullptr; + } + + jobject value = + env->NewObject(batChargeFaultChangeStructClass, batChargeFaultChangeStructCtor, value_current, value_previous); + + return value; + } default: *aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB; break; diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java index fe77f3667f8c89..2040b030738a89 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipEventStructs.java @@ -347,6 +347,81 @@ public String toString() { } } + public static class PowerSourceClusterWiredFaultChangeEvent { + public ArrayList current; + public ArrayList previous; + + public PowerSourceClusterWiredFaultChangeEvent( + ArrayList current, ArrayList previous) { + this.current = current; + this.previous = previous; + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("PowerSourceClusterWiredFaultChangeEvent {\n"); + output.append("\tcurrent: "); + output.append(current); + output.append("\n"); + output.append("\tprevious: "); + output.append(previous); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } + } + + public static class PowerSourceClusterBatFaultChangeEvent { + public ArrayList current; + public ArrayList previous; + + public PowerSourceClusterBatFaultChangeEvent( + ArrayList current, ArrayList previous) { + this.current = current; + this.previous = previous; + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("PowerSourceClusterBatFaultChangeEvent {\n"); + output.append("\tcurrent: "); + output.append(current); + output.append("\n"); + output.append("\tprevious: "); + output.append(previous); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } + } + + public static class PowerSourceClusterBatChargeFaultChangeEvent { + public ArrayList current; + public ArrayList previous; + + public PowerSourceClusterBatChargeFaultChangeEvent( + ArrayList current, ArrayList previous) { + this.current = current; + this.previous = previous; + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("PowerSourceClusterBatChargeFaultChangeEvent {\n"); + output.append("\tcurrent: "); + output.append(current); + output.append("\n"); + output.append("\tprevious: "); + output.append(previous); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } + } + public static class GeneralDiagnosticsClusterHardwareFaultChangeEvent { public ArrayList current; public ArrayList previous; diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipIdLookup.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipIdLookup.java index 0bcad38c702c69..195215f6e8f56d 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipIdLookup.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipIdLookup.java @@ -3183,6 +3183,15 @@ public static String eventIdToName(long clusterId, long eventId) { return ""; } if (clusterId == 47L) { + if (eventId == 0L) { + return "WiredFaultChange"; + } + if (eventId == 1L) { + return "BatFaultChange"; + } + if (eventId == 2L) { + return "BatChargeFaultChange"; + } return ""; } if (clusterId == 48L) { diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index a72378c2f393b3..6dea0ef9539d5d 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -6171,6 +6171,70 @@ def attribute_type(cls) -> ClusterObjectFieldDescriptor: value: 'uint' = 0 + class Events: + @dataclass + class WiredFaultChange(ClusterEvent): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x002F + + @ChipUtility.classproperty + def event_id(cls) -> int: + return 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields = [ + ClusterObjectFieldDescriptor(Label="current", Tag=0, Type=typing.List[PowerSource.Enums.WiredFault]), + ClusterObjectFieldDescriptor(Label="previous", Tag=1, Type=typing.List[PowerSource.Enums.WiredFault]), + ]) + + current: 'typing.List[PowerSource.Enums.WiredFault]' = field(default_factory=lambda: []) + previous: 'typing.List[PowerSource.Enums.WiredFault]' = field(default_factory=lambda: []) + + @dataclass + class BatFaultChange(ClusterEvent): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x002F + + @ChipUtility.classproperty + def event_id(cls) -> int: + return 0x00000001 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields = [ + ClusterObjectFieldDescriptor(Label="current", Tag=0, Type=typing.List[PowerSource.Enums.BatFault]), + ClusterObjectFieldDescriptor(Label="previous", Tag=1, Type=typing.List[PowerSource.Enums.BatFault]), + ]) + + current: 'typing.List[PowerSource.Enums.BatFault]' = field(default_factory=lambda: []) + previous: 'typing.List[PowerSource.Enums.BatFault]' = field(default_factory=lambda: []) + + @dataclass + class BatChargeFaultChange(ClusterEvent): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x002F + + @ChipUtility.classproperty + def event_id(cls) -> int: + return 0x00000002 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields = [ + ClusterObjectFieldDescriptor(Label="current", Tag=0, Type=typing.List[PowerSource.Enums.BatChargeFault]), + ClusterObjectFieldDescriptor(Label="previous", Tag=1, Type=typing.List[PowerSource.Enums.BatChargeFault]), + ]) + + current: 'typing.List[PowerSource.Enums.BatChargeFault]' = field(default_factory=lambda: []) + previous: 'typing.List[PowerSource.Enums.BatChargeFault]' = field(default_factory=lambda: []) + @dataclass class GeneralCommissioning(Cluster): diff --git a/src/darwin/Framework/CHIP/templates/availability.yaml b/src/darwin/Framework/CHIP/templates/availability.yaml index 010bddd35779d5..bc301ada0ea09e 100644 --- a/src/darwin/Framework/CHIP/templates/availability.yaml +++ b/src/darwin/Framework/CHIP/templates/availability.yaml @@ -5043,6 +5043,10 @@ - ShutDown - Leave - ReachableChanged + PowerSource: + - WiredFaultChange + - BatFaultChange + - BatChargeFaultChange event fields: Switch: MultiPressComplete: @@ -5078,6 +5082,16 @@ - fabricIndex ReachableChanged: - reachableNewValue + PowerSource: + WiredFaultChange: + - current + - previous + BatFaultChange: + - current + - previous + BatChargeFaultChange: + - current + - previous enums: OTASoftwareUpdateProvider: - OTAApplyUpdateAction @@ -5149,6 +5163,9 @@ - PASE - CASE - Group + PowerSource: + BatChargeLevel: + - OK bitmaps: UnitTesting: - Bitmap8MaskMap @@ -5229,6 +5246,10 @@ AccessControl: - AccessControlEntry - ExtensionEntry + PowerSource: + - WiredFaultChangeType + - BatFaultChangeType + - BatChargeFaultChangeType struct fields: Descriptor: DeviceTypeStruct: @@ -5245,6 +5266,9 @@ GeneralCommissioning: CommissioningError: - Ok + PowerSource: + BatChargeLevel: + - Ok apis: - Timed Invoke for server to client commands - Deprecated global attribute names @@ -5320,3 +5344,6 @@ GeneralCommissioning: CommissioningError: OK: Ok + PowerSource: + BatChargeLevel: + OK: Ok diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h index c433a209131c12..7999ed99518178 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h @@ -17416,7 +17416,10 @@ typedef NS_ENUM(uint8_t, MTRPowerSourceBatChargeFault) { } API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); typedef NS_ENUM(uint8_t, MTRPowerSourceBatChargeLevel) { - MTRPowerSourceBatChargeLevelOk API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) = 0x00, + MTRPowerSourceBatChargeLevelOK MTR_NEWLY_AVAILABLE = 0x00, + MTRPowerSourceBatChargeLevelOk API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) + MTR_NEWLY_DEPRECATED("Please use MTRPowerSourceBatChargeLevelOK") + = 0x00, MTRPowerSourceBatChargeLevelWarning API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) = 0x01, MTRPowerSourceBatChargeLevelCritical API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) = 0x02, } API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h b/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h index 53942f6a40012c..bdc6ae0152ada0 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h @@ -6821,6 +6821,13 @@ typedef NS_ENUM(uint32_t, MTREventIDType) { MTREventIDTypeClusterOTASoftwareUpdateRequestorEventVersionAppliedID MTR_NEWLY_AVAILABLE = 0x00000001, MTREventIDTypeClusterOTASoftwareUpdateRequestorEventDownloadErrorID MTR_NEWLY_AVAILABLE = 0x00000002, + // Cluster PowerSource deprecated event names + + // Cluster PowerSource events + MTREventIDTypeClusterPowerSourceEventWiredFaultChangeID MTR_NEWLY_AVAILABLE = 0x00000000, + MTREventIDTypeClusterPowerSourceEventBatFaultChangeID MTR_NEWLY_AVAILABLE = 0x00000001, + MTREventIDTypeClusterPowerSourceEventBatChargeFaultChangeID MTR_NEWLY_AVAILABLE = 0x00000002, + // Cluster GeneralDiagnostics deprecated event names MTRClusterGeneralDiagnosticsEventHardwareFaultChangeID API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) MTR_NEWLY_DEPRECATED("Please use MTREventIDTypeClusterGeneralDiagnosticsEventHardwareFaultChangeID") diff --git a/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm index 8e5f792ae28582..a2fa781704a557 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm @@ -610,6 +610,165 @@ id MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVReader & aRead using namespace Clusters::PowerSource; switch (aPath.mEventId) { + case Events::WiredFaultChange::Id: { + Events::WiredFaultChange::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + + __auto_type * value = [MTRPowerSourceClusterWiredFaultChangeEvent new]; + + do { + NSArray * _Nonnull memberValue; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.current.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + NSNumber * newElement_0; + newElement_0 = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0)]; + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + memberValue = array_0; + } + value.current = memberValue; + } while (0); + do { + NSArray * _Nonnull memberValue; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.previous.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + NSNumber * newElement_0; + newElement_0 = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0)]; + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + memberValue = array_0; + } + value.previous = memberValue; + } while (0); + + return value; + } + + case Events::BatFaultChange::Id: { + Events::BatFaultChange::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + + __auto_type * value = [MTRPowerSourceClusterBatFaultChangeEvent new]; + + do { + NSArray * _Nonnull memberValue; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.current.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + NSNumber * newElement_0; + newElement_0 = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0)]; + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + memberValue = array_0; + } + value.current = memberValue; + } while (0); + do { + NSArray * _Nonnull memberValue; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.previous.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + NSNumber * newElement_0; + newElement_0 = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0)]; + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + memberValue = array_0; + } + value.previous = memberValue; + } while (0); + + return value; + } + + case Events::BatChargeFaultChange::Id: { + Events::BatChargeFaultChange::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + + __auto_type * value = [MTRPowerSourceClusterBatChargeFaultChangeEvent new]; + + do { + NSArray * _Nonnull memberValue; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.current.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + NSNumber * newElement_0; + newElement_0 = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0)]; + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + memberValue = array_0; + } + value.current = memberValue; + } while (0); + do { + NSArray * _Nonnull memberValue; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.previous.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + NSNumber * newElement_0; + newElement_0 = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0)]; + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + memberValue = array_0; + } + value.previous = memberValue; + } while (0); + + return value; + } + default: *aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB; break; diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h index e67a9749c7bda0..9c5aa2ee441931 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h @@ -239,21 +239,48 @@ MTR_NEWLY_DEPRECATED("Please use MTROTASoftwareUpdateRequestorClusterDownloadErr @end API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) +MTR_NEWLY_DEPRECATED("This struct is unused and will be removed") @interface MTRPowerSourceClusterBatChargeFaultChangeType : NSObject -@property (nonatomic, copy) NSArray * _Nonnull current API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); -@property (nonatomic, copy) NSArray * _Nonnull previous API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); +@property (nonatomic, copy) NSArray * _Nonnull current API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) + MTR_NEWLY_DEPRECATED("Please use MTRPowerSourceClusterBatChargeFaultChangeType"); +@property (nonatomic, copy) NSArray * _Nonnull previous API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) + MTR_NEWLY_DEPRECATED("Please use MTRPowerSourceClusterBatChargeFaultChangeType"); @end API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) +MTR_NEWLY_DEPRECATED("This struct is unused and will be removed") @interface MTRPowerSourceClusterBatFaultChangeType : NSObject -@property (nonatomic, copy) NSArray * _Nonnull current API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); -@property (nonatomic, copy) NSArray * _Nonnull previous API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); +@property (nonatomic, copy) NSArray * _Nonnull current API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) + MTR_NEWLY_DEPRECATED("Please use MTRPowerSourceClusterBatFaultChangeType"); +@property (nonatomic, copy) NSArray * _Nonnull previous API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) + MTR_NEWLY_DEPRECATED("Please use MTRPowerSourceClusterBatFaultChangeType"); @end API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) +MTR_NEWLY_DEPRECATED("This struct is unused and will be removed") @interface MTRPowerSourceClusterWiredFaultChangeType : NSObject -@property (nonatomic, copy) NSArray * _Nonnull current API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); -@property (nonatomic, copy) NSArray * _Nonnull previous API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); +@property (nonatomic, copy) NSArray * _Nonnull current API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) + MTR_NEWLY_DEPRECATED("Please use MTRPowerSourceClusterWiredFaultChangeType"); +@property (nonatomic, copy) NSArray * _Nonnull previous API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) + MTR_NEWLY_DEPRECATED("Please use MTRPowerSourceClusterWiredFaultChangeType"); +@end + +MTR_NEWLY_AVAILABLE +@interface MTRPowerSourceClusterWiredFaultChangeEvent : NSObject +@property (nonatomic, copy) NSArray * _Nonnull current MTR_NEWLY_AVAILABLE; +@property (nonatomic, copy) NSArray * _Nonnull previous MTR_NEWLY_AVAILABLE; +@end + +MTR_NEWLY_AVAILABLE +@interface MTRPowerSourceClusterBatFaultChangeEvent : NSObject +@property (nonatomic, copy) NSArray * _Nonnull current MTR_NEWLY_AVAILABLE; +@property (nonatomic, copy) NSArray * _Nonnull previous MTR_NEWLY_AVAILABLE; +@end + +MTR_NEWLY_AVAILABLE +@interface MTRPowerSourceClusterBatChargeFaultChangeEvent : NSObject +@property (nonatomic, copy) NSArray * _Nonnull current MTR_NEWLY_AVAILABLE; +@property (nonatomic, copy) NSArray * _Nonnull previous MTR_NEWLY_AVAILABLE; @end API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm index 178783a5a2d40e..bdb39bf37da445 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm @@ -910,6 +910,99 @@ - (NSString *)description @end +@implementation MTRPowerSourceClusterWiredFaultChangeEvent +- (instancetype)init +{ + if (self = [super init]) { + + _current = [NSArray array]; + + _previous = [NSArray array]; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRPowerSourceClusterWiredFaultChangeEvent alloc] init]; + + other.current = self.current; + other.previous = self.previous; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = + [NSString stringWithFormat:@"<%@: current:%@; previous:%@; >", NSStringFromClass([self class]), _current, _previous]; + return descriptionString; +} + +@end + +@implementation MTRPowerSourceClusterBatFaultChangeEvent +- (instancetype)init +{ + if (self = [super init]) { + + _current = [NSArray array]; + + _previous = [NSArray array]; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRPowerSourceClusterBatFaultChangeEvent alloc] init]; + + other.current = self.current; + other.previous = self.previous; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = + [NSString stringWithFormat:@"<%@: current:%@; previous:%@; >", NSStringFromClass([self class]), _current, _previous]; + return descriptionString; +} + +@end + +@implementation MTRPowerSourceClusterBatChargeFaultChangeEvent +- (instancetype)init +{ + if (self = [super init]) { + + _current = [NSArray array]; + + _previous = [NSArray array]; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRPowerSourceClusterBatChargeFaultChangeEvent alloc] init]; + + other.current = self.current; + other.previous = self.previous; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = + [NSString stringWithFormat:@"<%@: current:%@; previous:%@; >", NSStringFromClass([self class]), _current, _previous]; + return descriptionString; +} + +@end + @implementation MTRGeneralCommissioningClusterBasicCommissioningInfo - (instancetype)init { diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp index 448310efafe87c..2d1476bdf79ff7 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp @@ -5241,6 +5241,129 @@ CHIP_ERROR TypeInfo::DecodableType::Decode(TLV::TLVReader & reader, const Concre } // namespace Attributes namespace Events { +namespace WiredFaultChange { +CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const +{ + TLV::TLVType outer; + ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kCurrent)), current)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kPrevious)), previous)); + ReturnErrorOnFailure(writer.EndContainer(outer)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + TLV::TLVType outer; + VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + ReturnErrorOnFailure(reader.EnterContainer(outer)); + while ((err = reader.Next()) == CHIP_NO_ERROR) + { + if (!TLV::IsContextTag(reader.GetTag())) + { + continue; + } + switch (TLV::TagNumFromTag(reader.GetTag())) + { + case to_underlying(Fields::kCurrent): + ReturnErrorOnFailure(DataModel::Decode(reader, current)); + break; + case to_underlying(Fields::kPrevious): + ReturnErrorOnFailure(DataModel::Decode(reader, previous)); + break; + default: + break; + } + } + + VerifyOrReturnError(err == CHIP_END_OF_TLV, err); + ReturnErrorOnFailure(reader.ExitContainer(outer)); + return CHIP_NO_ERROR; +} +} // namespace WiredFaultChange. +namespace BatFaultChange { +CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const +{ + TLV::TLVType outer; + ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kCurrent)), current)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kPrevious)), previous)); + ReturnErrorOnFailure(writer.EndContainer(outer)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + TLV::TLVType outer; + VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + ReturnErrorOnFailure(reader.EnterContainer(outer)); + while ((err = reader.Next()) == CHIP_NO_ERROR) + { + if (!TLV::IsContextTag(reader.GetTag())) + { + continue; + } + switch (TLV::TagNumFromTag(reader.GetTag())) + { + case to_underlying(Fields::kCurrent): + ReturnErrorOnFailure(DataModel::Decode(reader, current)); + break; + case to_underlying(Fields::kPrevious): + ReturnErrorOnFailure(DataModel::Decode(reader, previous)); + break; + default: + break; + } + } + + VerifyOrReturnError(err == CHIP_END_OF_TLV, err); + ReturnErrorOnFailure(reader.ExitContainer(outer)); + return CHIP_NO_ERROR; +} +} // namespace BatFaultChange. +namespace BatChargeFaultChange { +CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const +{ + TLV::TLVType outer; + ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kCurrent)), current)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kPrevious)), previous)); + ReturnErrorOnFailure(writer.EndContainer(outer)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + TLV::TLVType outer; + VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + ReturnErrorOnFailure(reader.EnterContainer(outer)); + while ((err = reader.Next()) == CHIP_NO_ERROR) + { + if (!TLV::IsContextTag(reader.GetTag())) + { + continue; + } + switch (TLV::TagNumFromTag(reader.GetTag())) + { + case to_underlying(Fields::kCurrent): + ReturnErrorOnFailure(DataModel::Decode(reader, current)); + break; + case to_underlying(Fields::kPrevious): + ReturnErrorOnFailure(DataModel::Decode(reader, previous)); + break; + default: + break; + } + } + + VerifyOrReturnError(err == CHIP_END_OF_TLV, err); + ReturnErrorOnFailure(reader.ExitContainer(outer)); + return CHIP_NO_ERROR; +} +} // namespace BatChargeFaultChange. } // namespace Events } // namespace PowerSource diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index f6707991e0dfed..d9a23bfe1012e6 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -6375,6 +6375,116 @@ struct TypeInfo }; }; } // namespace Attributes +namespace Events { +namespace WiredFaultChange { +static constexpr PriorityLevel kPriorityLevel = PriorityLevel::Info; + +enum class Fields +{ + kCurrent = 0, + kPrevious = 1, +}; + +struct Type +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::WiredFaultChange::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::PowerSource::Id; } + static constexpr bool kIsFabricScoped = false; + + DataModel::List current; + DataModel::List previous; + + CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; +}; + +struct DecodableType +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::WiredFaultChange::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::PowerSource::Id; } + + DataModel::DecodableList current; + DataModel::DecodableList previous; + + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +} // namespace WiredFaultChange +namespace BatFaultChange { +static constexpr PriorityLevel kPriorityLevel = PriorityLevel::Info; + +enum class Fields +{ + kCurrent = 0, + kPrevious = 1, +}; + +struct Type +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::BatFaultChange::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::PowerSource::Id; } + static constexpr bool kIsFabricScoped = false; + + DataModel::List current; + DataModel::List previous; + + CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; +}; + +struct DecodableType +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::BatFaultChange::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::PowerSource::Id; } + + DataModel::DecodableList current; + DataModel::DecodableList previous; + + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +} // namespace BatFaultChange +namespace BatChargeFaultChange { +static constexpr PriorityLevel kPriorityLevel = PriorityLevel::Info; + +enum class Fields +{ + kCurrent = 0, + kPrevious = 1, +}; + +struct Type +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::BatChargeFaultChange::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::PowerSource::Id; } + static constexpr bool kIsFabricScoped = false; + + DataModel::List current; + DataModel::List previous; + + CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; +}; + +struct DecodableType +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::BatChargeFaultChange::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::PowerSource::Id; } + + DataModel::DecodableList current; + DataModel::DecodableList previous; + + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +} // namespace BatChargeFaultChange +} // namespace Events } // namespace PowerSource namespace GeneralCommissioning { namespace Structs { diff --git a/zzz_generated/app-common/app-common/zap-generated/ids/Events.h b/zzz_generated/app-common/app-common/zap-generated/ids/Events.h index 8dbc9ea7a323fb..e885f58360f248 100644 --- a/zzz_generated/app-common/app-common/zap-generated/ids/Events.h +++ b/zzz_generated/app-common/app-common/zap-generated/ids/Events.h @@ -93,6 +93,24 @@ static constexpr EventId Id = 0x00000002; } // namespace Events } // namespace OtaSoftwareUpdateRequestor +namespace PowerSource { +namespace Events { + +namespace WiredFaultChange { +static constexpr EventId Id = 0x00000000; +} // namespace WiredFaultChange + +namespace BatFaultChange { +static constexpr EventId Id = 0x00000001; +} // namespace BatFaultChange + +namespace BatChargeFaultChange { +static constexpr EventId Id = 0x00000002; +} // namespace BatChargeFaultChange + +} // namespace Events +} // namespace PowerSource + namespace GeneralDiagnostics { namespace Events { diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index 845ea56ff454f9..8fbfa60a3baa13 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -2175,6 +2175,9 @@ class OtaSoftwareUpdateRequestorAnnounceOTAProvider : public ClusterCommand | * ClusterRevision | 0xFFFD | |------------------------------------------------------------------------------| | Events: | | +| * WiredFaultChange | 0x0000 | +| * BatFaultChange | 0x0001 | +| * BatChargeFaultChange | 0x0002 | \*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*\ @@ -9402,8 +9405,14 @@ void registerClusterPowerSource(Commands & commands, CredentialIssuerCommands * // // Events // - make_unique(Id, credsIssuerConfig), // - make_unique(Id, credsIssuerConfig), // + make_unique(Id, credsIssuerConfig), // + make_unique(Id, "wired-fault-change", Events::WiredFaultChange::Id, credsIssuerConfig), // + make_unique(Id, "bat-fault-change", Events::BatFaultChange::Id, credsIssuerConfig), // + make_unique(Id, "bat-charge-fault-change", Events::BatChargeFaultChange::Id, credsIssuerConfig), // + make_unique(Id, credsIssuerConfig), // + make_unique(Id, "wired-fault-change", Events::WiredFaultChange::Id, credsIssuerConfig), // + make_unique(Id, "bat-fault-change", Events::BatFaultChange::Id, credsIssuerConfig), // + make_unique(Id, "bat-charge-fault-change", Events::BatChargeFaultChange::Id, credsIssuerConfig), // }; commands.Register(clusterName, clusterCommands); diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp index 15e1dc60dc5ba4..5e4ec741353506 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp @@ -2771,6 +2771,78 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, return CHIP_NO_ERROR; } +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const PowerSource::Events::WiredFaultChange::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = DataModelLogger::LogValue("Current", indent + 1, value.current); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'Current'"); + return err; + } + } + { + CHIP_ERROR err = DataModelLogger::LogValue("Previous", indent + 1, value.previous); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'Previous'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const PowerSource::Events::BatFaultChange::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = DataModelLogger::LogValue("Current", indent + 1, value.current); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'Current'"); + return err; + } + } + { + CHIP_ERROR err = DataModelLogger::LogValue("Previous", indent + 1, value.previous); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'Previous'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const PowerSource::Events::BatChargeFaultChange::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = DataModelLogger::LogValue("Current", indent + 1, value.current); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'Current'"); + return err; + } + } + { + CHIP_ERROR err = DataModelLogger::LogValue("Previous", indent + 1, value.previous); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'Previous'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const GeneralDiagnostics::Events::HardwareFaultChange::DecodableType & value) { @@ -10571,6 +10643,27 @@ CHIP_ERROR DataModelLogger::LogEvent(const chip::app::EventHeader & header, chip } break; } + case PowerSource::Id: { + switch (header.mPath.mEventId) + { + case PowerSource::Events::WiredFaultChange::Id: { + chip::app::Clusters::PowerSource::Events::WiredFaultChange::DecodableType value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("WiredFaultChange", 1, value); + } + case PowerSource::Events::BatFaultChange::Id: { + chip::app::Clusters::PowerSource::Events::BatFaultChange::DecodableType value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("BatFaultChange", 1, value); + } + case PowerSource::Events::BatChargeFaultChange::Id: { + chip::app::Clusters::PowerSource::Events::BatChargeFaultChange::DecodableType value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("BatChargeFaultChange", 1, value); + } + } + break; + } case GeneralDiagnostics::Id: { switch (header.mPath.mEventId) { diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h index 1683e2255b9d41..a3a71f6bc63a46 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h @@ -165,6 +165,12 @@ static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::OtaSoftwareUpdateRequestor::Events::VersionApplied::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::OtaSoftwareUpdateRequestor::Events::DownloadError::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::PowerSource::Events::WiredFaultChange::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::PowerSource::Events::BatFaultChange::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::PowerSource::Events::BatChargeFaultChange::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::GeneralDiagnostics::Events::HardwareFaultChange::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, diff --git a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h index 7bb0ef4746c056..bbe21891c6e607 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h @@ -16338,6 +16338,9 @@ class SubscribeAttributePowerSourceConfigurationClusterRevision : public Subscri | * ClusterRevision | 0xFFFD | |------------------------------------------------------------------------------| | Events: | | +| * WiredFaultChange | 0x0000 | +| * BatFaultChange | 0x0001 | +| * BatChargeFaultChange | 0x0002 | \*----------------------------------------------------------------------------*/ /* From 459908944b475de4c0f24451fe9a88df4be9f2d5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Jan 2023 17:16:54 +0000 Subject: [PATCH 5/8] Bump third_party/pigweed/repo from `ead209d` to `39f7220` (#24226) Bumps [third_party/pigweed/repo](https://github.com/google/pigweed) from `ead209d` to `39f7220`. - [Release notes](https://github.com/google/pigweed/releases) - [Commits](https://github.com/google/pigweed/compare/ead209d3aa09821aa7549fbc8665ae68fe88d16f...39f72204df9c95c23d1ad4ee34274a116e6aedd7) --- updated-dependencies: - dependency-name: third_party/pigweed/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/pigweed/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/pigweed/repo b/third_party/pigweed/repo index ead209d3aa0982..39f72204df9c95 160000 --- a/third_party/pigweed/repo +++ b/third_party/pigweed/repo @@ -1 +1 @@ -Subproject commit ead209d3aa09821aa7549fbc8665ae68fe88d16f +Subproject commit 39f72204df9c95c23d1ad4ee34274a116e6aedd7 From bf6575127637eda365f75e94aaf82c40522f235e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Ba=C5=82ys?= Date: Wed, 4 Jan 2023 18:23:28 +0100 Subject: [PATCH 6/8] [nrfconnect] Added support for user data in Factory Data parser (#24088) * [nrfconnect] Added support for user data in Factory Data parser Factory data parser did not contain methods to obtain user data. - Added two methods: GetUserData to obtain raw user data and GetUserKey to obtain a single key. - Improved the FactoryDataParser to read and manage the user data field. - Improved documentation. * Restyled by prettier-markdown Co-authored-by: Restyled.io --- .../nrfconnect_factory_data_configuration.md | 87 ++++++++++++++++++- .../tests/test_generate_factory_data.py | 20 +++++ src/platform/nrfconnect/FactoryDataParser.c | 75 +++++++++++++++- src/platform/nrfconnect/FactoryDataParser.h | 14 +++ .../nrfconnect/FactoryDataProvider.cpp | 26 ++++++ src/platform/nrfconnect/FactoryDataProvider.h | 22 +++++ 6 files changed, 242 insertions(+), 2 deletions(-) diff --git a/docs/guides/nrfconnect_factory_data_configuration.md b/docs/guides/nrfconnect_factory_data_configuration.md index c05b5a61ebaa16..7826fd6b9d15a8 100644 --- a/docs/guides/nrfconnect_factory_data_configuration.md +++ b/docs/guides/nrfconnect_factory_data_configuration.md @@ -41,6 +41,8 @@ data secure by applying hardware write protection. - [Enabling factory data support](#enabling-factory-data-support) - [Generating factory data](#generating-factory-data) - [Creating factory data JSON file with the first script](#creating-factory-data-json-file-with-the-first-script) + - [How to set user data](#how-to-set-user-data) + - [How to handle user data](#how-to-handle-user-data) - [Verifying using the JSON Schema tool](#verifying-using-the-json-schema-tool) - [Option 1: Using the php-json-schema tool](#option-1-using-the-php-json-schema-tool) - [Option 2: Using a website validator](#option-2-using-a-website-validator) @@ -110,7 +112,7 @@ The following table lists the parameters of a factory data set: | `spake2_verifier` | SPAKE2+ verifier | 97 B | byte string | mandatory | The SPAKE2+ verifier generated using SPAKE2+ salt, iteration counter, and passcode. | | `discriminator` | Discriminator | 2 B | uint16 | mandatory | A 12-bit value matching the field of the same name in the setup code. The discriminator is used during the discovery process. | | `passcode` | SPAKE passcode | 4 B | uint32 | optional | A pairing passcode is a 27-bit unsigned integer which serves as a proof of possession during the commissioning. Its value must be restricted to the values from `0x0000001` to `0x5F5E0FE` (`00000001` to `99999998` in decimal), excluding the following invalid passcode values: `00000000`, `11111111`, `22222222`, `33333333`, `44444444`, `55555555`, `66666666`, `77777777`, `88888888`, `99999999`, `12345678`, `87654321`. | -| `user` | User data | variable | JSON string | max 1024 B | The user data is provided in the JSON format. This parameter is optional and depends on user's or manufacturer's purpose (or both). It is provided as a string from persistent storage and should be parsed in the user application. This data is not used by the Matter stack. | +| `user` | User data | variable | JSON string | max 1024 B | The user data is provided in the JSON format. This parameter is optional and depends on device manufacturer's purpose. It is provided as a CBOR map type from persistent storage and should be parsed in the user application. This data is not used by the Matter stack. To learn how to work with user data, see [How to set user data](#how-to-set-user-data) section. | ### Factory data format @@ -345,6 +347,89 @@ If the script finishes successfully, go to the location you provided with the > location as an existing file. To allow overwriting, add the `--overwrite` > option to the argument list of the Python script. +### How to set user data + +The user data is an optional field provided in the factory data JSON file and +depends on the manufacturer's purpose. The `user` field in a JSON factory data +file is represented by a flat JSON map and it can consist of `string` or `int32` +data types only. On the device side, the `user` data will be available as a CBOR +map containing all defined `string` and `int32` fields. + +To add user data as an argument to the +[generate_nrfconnect_chip_factory_data.py](../../scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py) +script, add the following line to the argument list: + +``` +--user-data {user data JSON} +``` + +As `user data JSON`, provide a flat JSON map with a value file that consists of +`string` or `int32` types. For example, you can use a JSON file that looks like +follows: + +``` +{ + "name": "product_name", + "version": 123, + "revision": "0x123" +} +``` + +When added to the argument line, the final result would look like follows: + +``` +--user-data '{"name": "product_name", "version": 123, "revision": "0x123"}' +``` + +#### How to handle user data + +The user data is not handled anywhere in the Matter stack, so you must handle it +in your application. To do this, you can use the +[Factory Data Provider](../../src/platform/nrfconnect/FactoryDataProvider.h) and +apply one of the following methods: + +- `GetUserData` method to obtain raw data in the CBOR format as a + `MutableByteSpan`. + +- `GetUserKey` method that lets you search along the user data list using a + specific key, and if the key exists in the user data, the method returns its + value. + +If you opt for `GetUserKey`, complete the following steps to set up the search: + +1. Add the `GetUserKey` method to your code. + +2. Given that all integer fields of the `user` Factory Data field are `int32`, + provide a buffer that has a size of at least `4B` or an `int32_t` variable to + `GetUserKey`. To read a string field from user data, the buffer should have a + size of at least the length of the expected string. + +3. Set it up to read all user data fields. + +Only after this setup is complete, can you use all variables in your code and +cast the result to your own purpose. + +The code example of how to read all fields from the JSON example one by one can +look like follows: + + ``` + chip::DeviceLayer::FactoryDataProvider factoryDataProvider; + + factoryDataProvider.Init(); + + uint8_t user_name[12]; + size_t name_len = sizeof(user_name); + factoryDataProvider.GetUserKey("name", user_name, name_len); + + int32_t version; + size_t version_len = sizeof(version); + factoryDataProvider.GetUserKey("version", &version, version_len); + + uint8_t revision[5]; + size_t revision_len = sizeof(revision); + factoryDataProvider.GetUserKey("revision", revision, revision_len); + ``` + ### Verifying using the JSON Schema tool The JSON file that contains factory data can be verified using the diff --git a/scripts/tools/nrfconnect/tests/test_generate_factory_data.py b/scripts/tools/nrfconnect/tests/test_generate_factory_data.py index ea6ccc445f733f..d3fd86f69bf3e5 100755 --- a/scripts/tools/nrfconnect/tests/test_generate_factory_data.py +++ b/scripts/tools/nrfconnect/tests/test_generate_factory_data.py @@ -171,6 +171,7 @@ def test_generate_factory_data_all_specified(self): '--discriminator', '0xFED', '--rd_uid', '91a9c12a7c80700a31ddcfa7fce63e44', '--enable_key', '00112233445566778899aabbccddeeff', + '--user', '{"name": "product_name", "version": 123, "revision": "0x123"}', '-o', os.path.join(outdir, 'fd.json') ]) @@ -199,6 +200,15 @@ def test_generate_factory_data_all_specified(self): self.assertEqual(factory_data.get('passcode'), 13243546) self.assertEqual(factory_data.get('rd_uid'), 'hex:91a9c12a7c80700a31ddcfa7fce63e44') self.assertEqual(factory_data.get('enable_key'), 'hex:00112233445566778899aabbccddeeff') + self.assertEqual(factory_data.get('user'), {'name': 'product_name', 'version': 123, 'revision': '0x123'}) + + subprocess.check_call(['python3', os.path.join(TOOLS_DIR, 'nrfconnect_generate_partition.py'), + '-i', os.path.join(outdir, 'fd.json'), + '-o', os.path.join(outdir, 'fd'), + '--offset', "0xfb000", + '--size', "0x1000", + '--raw' + ]) def test_generate_spake2p_verifier_default(self): with tempfile.TemporaryDirectory() as outdir: @@ -223,6 +233,7 @@ def test_generate_spake2p_verifier_default(self): '--spake2_salt', 'U1BBS0UyUCBLZXkgU2FsdA==', '--passcode', '20202021', '--discriminator', '0xFED', + '--user', '{"name": "product_name", "version": 123, "revision": "0x123"}', '-o', os.path.join(outdir, 'fd.json') ]) @@ -234,6 +245,15 @@ def test_generate_spake2p_verifier_default(self): self.assertEqual(factory_data.get('spake2_it'), 1000) self.assertEqual(factory_data.get('spake2_verifier'), base64_to_json( 'uWFwqugDNGiEck/po7KHwwMwwqZgN10XuyBajPGuyzUEV/iree4lOrao5GuwnlQ65CJzbeUB49s31EH+NEkg0JVI5MGCQGMMT/SRPFNRODm3wH/MBiehuFc6FJ/NH6Rmzw==')) + self.assertEqual(factory_data.get('user'), {'name': 'product_name', 'version': 123, 'revision': '0x123'}) + + subprocess.check_call(['python3', os.path.join(TOOLS_DIR, 'nrfconnect_generate_partition.py'), + '-i', os.path.join(outdir, 'fd.json'), + '-o', os.path.join(outdir, 'fd'), + '--offset', "0xfb000", + '--size', "0x1000", + '--raw' + ]) if __name__ == '__main__': diff --git a/src/platform/nrfconnect/FactoryDataParser.c b/src/platform/nrfconnect/FactoryDataParser.c index 64f412e7562bcd..19601887175bd6 100644 --- a/src/platform/nrfconnect/FactoryDataParser.c +++ b/src/platform/nrfconnect/FactoryDataParser.c @@ -40,6 +40,77 @@ static inline bool uint16_decode(zcbor_state_t * states, uint16_t * value) return false; } +static bool DecodeEntry(zcbor_state_t * states, void * buffer, size_t bufferSize, size_t * outlen) +{ + struct zcbor_string tempString; + int32_t tempInt = 0; + + // Try to decode entry as string + bool res = zcbor_tstr_decode(states, &tempString); + if (res) + { + if (bufferSize < tempString.len) + { + return false; + } + memcpy(buffer, tempString.value, tempString.len); + *outlen = tempString.len; + return res; + } + + // Try to decode entry as int32 + res = zcbor_int32_decode(states, &tempInt); + if (res) + { + if (bufferSize < sizeof(tempInt)) + { + return false; + } + memcpy(buffer, &tempInt, sizeof(tempInt)); + *outlen = sizeof(tempInt); + return res; + } + + return res; +} + +bool FindUserDataEntry(struct FactoryData * factoryData, const char * entry, void * buffer, size_t bufferSize, size_t * outlen) +{ + if ((!factoryData) || (!factoryData->user.data) || (!buffer) || (!outlen)) + { + return false; + } + + ZCBOR_STATE_D(states, MAX_FACTORY_DATA_NESTING_LEVEL - 1, factoryData->user.data, factoryData->user.len, 1); + + bool res = zcbor_map_start_decode(states); + bool keyFound = false; + struct zcbor_string currentString; + + while (res) + { + res = zcbor_tstr_decode(states, ¤tString); + + if (!res) + { + break; + } + + if (strncmp(entry, (const char *) currentString.value, currentString.len) == 0) + { + res = DecodeEntry(states, buffer, bufferSize, outlen); + keyFound = true; + break; + } + else + { + res = res && zcbor_any_skip(states, NULL); + } + } + + return res && keyFound && zcbor_list_map_end_force_decode(states); +} + bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData * factoryData) { memset(factoryData, 0, sizeof(*factoryData)); @@ -167,7 +238,9 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData } else if (strncmp("user", (const char *) currentString.value, currentString.len) == 0) { - res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->user); + factoryData->user.data = (void *) states->payload; + res = res && zcbor_any_skip(states, NULL); + factoryData->user.len = (void *) states->payload - factoryData->user.data; } else { diff --git a/src/platform/nrfconnect/FactoryDataParser.h b/src/platform/nrfconnect/FactoryDataParser.h index 9c87589560d469..b600371dde96ee 100644 --- a/src/platform/nrfconnect/FactoryDataParser.h +++ b/src/platform/nrfconnect/FactoryDataParser.h @@ -76,6 +76,20 @@ struct FactoryData */ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData * factoryData); +/** + * @brief Tries to find an entry within the given factory data user data field. + * The parser parses only the uint32 type of ints. To read int-related objects the buffer size must be aligned to uint32. + * That means, to obtain uint8 or uint16 value users should provide the buffer with size at least sizeof(uint32_t). + * + * @param factoryData An address of object of factory data that contains user field filled. + * @param entry An entry name to be find out. + * @param buffer Output buffer to store found key value. + * @param bufferSize Size of buffer. That size should have size at least equal to expected key value. + * @param outlen Actual size of found user data field. + * @return true on success, false otherwise + */ +bool FindUserDataEntry(struct FactoryData * factoryData, const char * entry, void * buffer, size_t bufferSize, size_t * outlen); + #ifdef __cplusplus } #endif diff --git a/src/platform/nrfconnect/FactoryDataProvider.cpp b/src/platform/nrfconnect/FactoryDataProvider.cpp index ed3fd939bb3f22..cd52046c6de4f8 100644 --- a/src/platform/nrfconnect/FactoryDataProvider.cpp +++ b/src/platform/nrfconnect/FactoryDataProvider.cpp @@ -339,6 +339,32 @@ CHIP_ERROR FactoryDataProvider::GetEnableKey(MutableByteSpan & return CHIP_NO_ERROR; } +template +CHIP_ERROR FactoryDataProvider::GetUserData(MutableByteSpan & userData) +{ + ReturnErrorCodeIf(!mFactoryData.user.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + ReturnErrorCodeIf(userData.size() < mFactoryData.user.len, CHIP_ERROR_BUFFER_TOO_SMALL); + + memcpy(userData.data(), mFactoryData.user.data, mFactoryData.user.len); + + userData.reduce_size(mFactoryData.user.len); + + return CHIP_NO_ERROR; +} + +template +CHIP_ERROR FactoryDataProvider::GetUserKey(const char * userKey, void * buf, size_t & len) +{ + ReturnErrorCodeIf(!mFactoryData.user.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + ReturnErrorCodeIf(!buf, CHIP_ERROR_BUFFER_TOO_SMALL); + + bool success = FindUserDataEntry(&mFactoryData, userKey, buf, len, &len); + + ReturnErrorCodeIf(!success, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + + return CHIP_NO_ERROR; +} + // Fully instantiate the template class in whatever compilation unit includes this file. template class FactoryDataProvider; template class FactoryDataProvider; diff --git a/src/platform/nrfconnect/FactoryDataProvider.h b/src/platform/nrfconnect/FactoryDataProvider.h index a7111acf66ee27..3d46076a5a3669 100644 --- a/src/platform/nrfconnect/FactoryDataProvider.h +++ b/src/platform/nrfconnect/FactoryDataProvider.h @@ -111,6 +111,28 @@ class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentia // ===== Members functions that are platform-specific CHIP_ERROR GetEnableKey(MutableByteSpan & enableKey); + /** + * @brief Get the user data in CBOR format as MutableByteSpan + * + * @param userData MutableByteSpan object to obtain all user data in CBOR format + * @returns + * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if factory data does not contain user field, or the value cannot be read out. + * CHIP_ERROR_BUFFER_TOO_SMALL if provided MutableByteSpan is too small + */ + CHIP_ERROR GetUserData(MutableByteSpan & userData); + + /** + * @brief Try to find user data key and return its value + * + * @param userKey A key name to be found + * @param buf Buffer to store value of found key + * @param len Length of the buffer. This value will be updated to the actual value if the key is read. + * @returns + * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if factory data does not contain user field, or the value cannot be read out. + * CHIP_ERROR_BUFFER_TOO_SMALL if provided buffer length is too small + */ + CHIP_ERROR GetUserKey(const char * userKey, void * buf, size_t & len); + private: static constexpr uint16_t kFactoryDataPartitionSize = PM_FACTORY_DATA_SIZE; static constexpr uint32_t kFactoryDataPartitionAddress = PM_FACTORY_DATA_ADDRESS; From 926fefe0150d4227e65dfcbaa44f8efed6139bac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:24:47 -0500 Subject: [PATCH 7/8] Bump third_party/openthread/repo from `98e644d` to `f2c02df` (#24225) Bumps [third_party/openthread/repo](https://github.com/openthread/openthread) from `98e644d` to `f2c02df`. - [Release notes](https://github.com/openthread/openthread/releases) - [Commits](https://github.com/openthread/openthread/compare/98e644d538ff2c57e96c54bdd6e13df31c7d19ba...f2c02dfd180df84dd8f4f02260cc5e12339ea563) --- updated-dependencies: - dependency-name: third_party/openthread/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/openthread/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/openthread/repo b/third_party/openthread/repo index 98e644d538ff2c..f2c02dfd180df8 160000 --- a/third_party/openthread/repo +++ b/third_party/openthread/repo @@ -1 +1 @@ -Subproject commit 98e644d538ff2c57e96c54bdd6e13df31c7d19ba +Subproject commit f2c02dfd180df84dd8f4f02260cc5e12339ea563 From cf330aefefe6afd1fecb0ef8874adb8bc32f7d75 Mon Sep 17 00:00:00 2001 From: abiradarti <104591549+abiradarti@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:41:59 -0600 Subject: [PATCH 8/8] [TI] Factory Reset updates for CC13X2_26X2 (#23963) * factory reset updates * Restyled by whitespace * Restyled by clang-format * CI fixes * Restyled by clang-format * Restyled by gn * updated 3 keys from factory to counters itemID * Restyled by whitespace * Restyled by clang-format * PR feedback * Restyled by clang-format * removed extern C and log function in DAC file * Restyled by clang-format Co-authored-by: Restyled.io --- examples/platform/cc13x2_26x2/BUILD.gn | 21 +- .../CC13X2_26X2DeviceAttestationCreds.cpp | 258 ++++++++++++++++++ .../CC13X2_26X2DeviceAttestationCreds.h | 36 +++ examples/pump-app/cc13x2x7_26x2x7/BUILD.gn | 1 + .../pump-app/cc13x2x7_26x2x7/main/AppTask.cpp | 12 +- .../cc13x2_26x2/CC13X2_26X2Config.cpp | 175 +++++++----- src/platform/cc13x2_26x2/CC13X2_26X2Config.h | 19 +- .../cc13x2_26x2/ConfigurationManagerImpl.cpp | 4 +- 8 files changed, 447 insertions(+), 79 deletions(-) create mode 100644 examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp create mode 100644 examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.h diff --git a/examples/platform/cc13x2_26x2/BUILD.gn b/examples/platform/cc13x2_26x2/BUILD.gn index a886bd6ee48c63..619ecdfa446dc5 100644 --- a/examples/platform/cc13x2_26x2/BUILD.gn +++ b/examples/platform/cc13x2_26x2/BUILD.gn @@ -14,11 +14,22 @@ import("//build_overrides/chip.gni") -config("chip_examples_project_config") { - include_dirs = [ "project_include" ] +config("attestation-credentials-config") { + include_dirs = [ "${chip_root}" ] + + defines = [ "CC13X2_26X2_ATTESTATION_CREDENTIALS" ] } -source_set("openthread_core_config_cc13x2_26x2_chip_examples") { - sources = [ "project_include/OpenThreadConfig.h" ] - public_configs = [ ":chip_examples_project_config" ] +source_set("cc13x2_26x2-attestation-credentials") { + sources = [ + "CC13X2_26X2DeviceAttestationCreds.cpp", + "CC13X2_26X2DeviceAttestationCreds.h", + ] + + public_deps = [ + "${chip_root}/src/credentials", + "${chip_root}/src/platform:platform_base", + ] + + public_configs = [ ":attestation-credentials-config" ] } diff --git a/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp new file mode 100644 index 00000000000000..9e39a54c263668 --- /dev/null +++ b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp @@ -0,0 +1,258 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "CC13X2_26X2DeviceAttestationCreds.h" +#include +#include +#include +#include +#include +#include + +extern uint32_t __attestation_credentials_base; + +namespace chip { +namespace Credentials { +namespace CC13X2_26X2 { + +namespace { + +typedef struct +{ + const uint32_t len; + uint8_t const * data; +} data_ptr; + +typedef struct +{ + data_ptr dac_priv_key; + data_ptr dac_pub_key; + data_ptr dac_cert; + data_ptr pai_cert; +} factoryData; + +const uint8_t gDacPrivKey[] = { + 0x50, 0x5a, 0x21, 0x1d, 0xbd, 0xa8, 0x71, 0x33, 0x0d, 0x63, 0x5d, 0xa3, 0xb0, 0x7e, 0xb1, 0xc5, + 0x08, 0x8a, 0x8f, 0xc7, 0x01, 0x24, 0xfb, 0xb3, 0x3e, 0x93, 0xd5, 0x06, 0x05, 0x82, 0xc7, 0xc5, +}; +const uint8_t gDacPubKey[] = { + 0x04, 0xc5, 0x65, 0xfd, 0xad, 0xfd, 0x16, 0xdd, 0x62, 0xe4, 0x3f, 0x19, 0x60, 0xb9, 0x93, 0xbb, 0x57, + 0x2c, 0xfd, 0xd8, 0x1f, 0x6d, 0x71, 0x67, 0x67, 0x1b, 0x77, 0x45, 0xdc, 0xbe, 0x6f, 0x65, 0xaf, 0x66, + 0x5a, 0x1d, 0x93, 0x1c, 0x05, 0xb9, 0xf9, 0xa3, 0xe9, 0x45, 0x66, 0x85, 0x60, 0x2c, 0x05, 0xc6, 0x96, + 0x46, 0xb8, 0xf7, 0x59, 0x98, 0xdb, 0xaa, 0x68, 0x7a, 0x5c, 0x56, 0x49, 0x02, 0xda, +}; +const uint8_t gDacCert[] = { + 0x30, 0x82, 0x01, 0xf7, 0x30, 0x82, 0x01, 0x9d, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x46, 0x88, 0xeb, 0x94, 0xad, 0x32, + 0xb2, 0xe4, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x4d, 0x31, 0x1f, 0x30, 0x1d, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x20, 0x50, 0x41, 0x49, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, + 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, + 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x36, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, + 0x32, 0x33, 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, + 0x5a, 0x30, 0x52, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1b, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, + 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x44, 0x41, 0x43, 0x20, 0x30, 0x30, 0x30, 0x30, 0x31, + 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, + 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, + 0x36, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xc5, 0x65, 0xfd, 0xad, 0xfd, 0x16, 0xdd, 0x62, 0xe4, 0x3f, 0x19, 0x60, 0xb9, 0x93, + 0xbb, 0x57, 0x2c, 0xfd, 0xd8, 0x1f, 0x6d, 0x71, 0x67, 0x67, 0x1b, 0x77, 0x45, 0xdc, 0xbe, 0x6f, 0x65, 0xaf, 0x66, 0x5a, 0x1d, + 0x93, 0x1c, 0x05, 0xb9, 0xf9, 0xa3, 0xe9, 0x45, 0x66, 0x85, 0x60, 0x2c, 0x05, 0xc6, 0x96, 0x46, 0xb8, 0xf7, 0x59, 0x98, 0xdb, + 0xaa, 0x68, 0x7a, 0x5c, 0x56, 0x49, 0x02, 0xda, 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, + 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, + 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x9b, 0x40, 0x60, 0x6f, 0x9e, 0x04, 0x7f, 0xb8, 0x60, 0x78, + 0x8e, 0x3d, 0xc1, 0x12, 0xd7, 0x5e, 0x87, 0x95, 0x77, 0x68, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, + 0x80, 0x14, 0x43, 0x34, 0x57, 0x12, 0xba, 0x2c, 0x87, 0xef, 0x25, 0x49, 0x7b, 0x11, 0xd7, 0x98, 0x58, 0x9b, 0x84, 0x35, 0x7f, + 0x88, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, + 0xb9, 0x28, 0xf9, 0x3e, 0xe3, 0x87, 0xef, 0x3e, 0x00, 0x72, 0x88, 0x22, 0x84, 0xbd, 0x8a, 0xdd, 0x5c, 0xd6, 0xd0, 0x55, 0x81, + 0xbf, 0xcc, 0x55, 0x17, 0xcf, 0x9e, 0x9b, 0xcd, 0xd4, 0x37, 0xda, 0x02, 0x20, 0x10, 0x07, 0x9c, 0xcf, 0x7f, 0x1f, 0x2d, 0xda, + 0x46, 0xac, 0xe9, 0x67, 0xae, 0x5b, 0xe9, 0x66, 0xe7, 0xf2, 0x8a, 0xdf, 0xa0, 0x28, 0xb8, 0xf8, 0x7f, 0x93, 0x9e, 0xd4, 0x15, + 0x8d, 0xc0, 0xf8, +}; + +const uint8_t gPaiCert[] = { + 0x30, 0x82, 0x01, 0xdc, 0x30, 0x82, 0x01, 0x81, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x7f, 0x7e, 0xf3, 0xdb, 0x08, 0xa3, + 0x8f, 0x68, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x30, 0x31, 0x18, 0x30, 0x16, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50, 0x41, 0x41, + 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, + 0x31, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, 0x32, 0x33, 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, + 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x4d, 0x31, 0x1f, 0x30, 0x1d, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x6d, + 0x65, 0x6e, 0x74, 0x20, 0x50, 0x41, 0x49, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, + 0x02, 0x01, 0x0c, 0x04, 0x46, 0x46, 0x46, 0x31, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, + 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x38, 0x30, 0x30, 0x36, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x42, 0x93, 0x55, 0x77, 0x35, 0x35, + 0x15, 0xce, 0xfa, 0x8f, 0x0e, 0x30, 0xe2, 0x34, 0x7e, 0x90, 0xee, 0xd6, 0xfd, 0x51, 0x5b, 0xe8, 0x82, 0xd1, 0xbc, 0xba, 0x74, + 0x83, 0xd7, 0xff, 0x6e, 0xf4, 0xde, 0xdf, 0x98, 0xf7, 0xf7, 0x4f, 0x17, 0x42, 0x1d, 0xe5, 0x45, 0x0c, 0xff, 0xfb, 0x3e, 0x7f, + 0x6d, 0x4f, 0x62, 0x28, 0x53, 0x41, 0x14, 0xfb, 0xb8, 0x5c, 0x2d, 0x52, 0xd1, 0x82, 0xb6, 0x6a, 0xa3, 0x66, 0x30, 0x64, 0x30, + 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x0e, + 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, + 0x04, 0x16, 0x04, 0x14, 0x43, 0x34, 0x57, 0x12, 0xba, 0x2c, 0x87, 0xef, 0x25, 0x49, 0x7b, 0x11, 0xd7, 0x98, 0x58, 0x9b, 0x84, + 0x35, 0x7f, 0x88, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x6a, 0xfd, 0x22, 0x77, 0x1f, + 0x51, 0x1f, 0xec, 0xbf, 0x16, 0x41, 0x97, 0x67, 0x10, 0xdc, 0xdc, 0x31, 0xa1, 0x71, 0x7e, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, + 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xff, 0x25, 0xf1, 0xd1, 0x54, 0xc3, 0x13, + 0x7e, 0x0e, 0x08, 0x6d, 0x82, 0xab, 0x0b, 0x11, 0xb5, 0x66, 0x18, 0x39, 0xb7, 0x12, 0xb1, 0x34, 0x2c, 0x6c, 0xde, 0x94, 0xfb, + 0xe3, 0x18, 0xa9, 0x2b, 0x02, 0x21, 0x00, 0x92, 0xe2, 0x81, 0xf9, 0x8a, 0x2f, 0xcc, 0x14, 0xcd, 0xf4, 0x07, 0x50, 0xd2, 0x80, + 0xd7, 0xdf, 0xea, 0x3f, 0x4d, 0xa4, 0x6f, 0x35, 0x7a, 0xfe, 0xac, 0xb8, 0x9b, 0x26, 0x77, 0x06, 0xd2, 0x8a, +}; + +const factoryData gFactoryData = { + .dac_priv_key = { + .len = sizeof(gDacPrivKey), + .data = gDacPrivKey, + }, + .dac_pub_key = { + .len = sizeof(gDacPubKey), + .data = gDacPubKey, + }, + .dac_cert = { + .len = sizeof(gDacCert), + .data = gDacCert, + }, + .pai_cert = { + .len = sizeof(gPaiCert), + .data = gPaiCert, + }, +}; + +CHIP_ERROR LoadKeypairFromRaw(ByteSpan private_key, ByteSpan public_key, Crypto::P256Keypair & keypair) +{ + Crypto::P256SerializedKeypair serialized_keypair; + ReturnErrorOnFailure(serialized_keypair.SetLength(private_key.size() + public_key.size())); + memcpy(serialized_keypair.Bytes(), public_key.data(), public_key.size()); + memcpy(serialized_keypair.Bytes() + public_key.size(), private_key.data(), private_key.size()); + return keypair.Deserialize(serialized_keypair); +} + +class DeviceAttestationCredsCC13X2_26X2 : public DeviceAttestationCredentialsProvider +{ + +public: + CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & out_buffer) override; + CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override; + CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & out_buffer) override; + CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer) override; + CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, MutableByteSpan & out_buffer) override; + +private: + factoryData const * mFactoryData = &gFactoryData; +}; + +CHIP_ERROR DeviceAttestationCredsCC13X2_26X2::GetCertificationDeclaration(MutableByteSpan & out_buffer) +{ + //-> format_version = 1 + //-> vendor_id = 0xFFF1 + //-> product_id_array = [ 0x8000, 0x8001, 0x8002, 0x8003, 0x8004, 0x8005, 0x8006, 0x8007, 0x8008, 0x8009, 0x800A, 0x800B, + // 0x800C, 0x800D, 0x800E, 0x800F, 0x8010, 0x8011, 0x8012, 0x8013, 0x8014, 0x8015, 0x8016, 0x8017, 0x8018, 0x8019, 0x801A, + // 0x801B, 0x801C, 0x801D, 0x801E, 0x801F, 0x8020, 0x8021, 0x8022, 0x8023, 0x8024, 0x8025, 0x8026, 0x8027, 0x8028, 0x8029, + // 0x802A, 0x802B, 0x802C, 0x802D, 0x802E, 0x802F, 0x8030, 0x8031, 0x8032, 0x8033, 0x8034, 0x8035, 0x8036, 0x8037, 0x8038, + // 0x8039, 0x803A, 0x803B, 0x803C, 0x803D, 0x803E, 0x803F, 0x8040, 0x8041, 0x8042, 0x8043, 0x8044, 0x8045, 0x8046, 0x8047, + // 0x8048, 0x8049, 0x804A, 0x804B, 0x804C, 0x804D, 0x804E, 0x804F, 0x8050, 0x8051, 0x8052, 0x8053, 0x8054, 0x8055, 0x8056, + // 0x8057, 0x8058, 0x8059, 0x805A, 0x805B, 0x805C, 0x805D, 0x805E, 0x805F, 0x8060, 0x8061, 0x8062, 0x8063 ] + //-> device_type_id = 0x0016 + //-> certificate_id = "ZIG20142ZB330003-24" + //-> security_level = 0 + //-> security_information = 0 + //-> version_number = 0x2694 + //-> certification_type = 0 + //-> dac_origin_vendor_id is not present + //-> dac_origin_product_id is not present + static const uint8_t kCdForAllExamples[] = { + 0x30, 0x82, 0x02, 0x19, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x02, 0x0a, 0x30, + 0x82, 0x02, 0x06, 0x02, 0x01, 0x03, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, + 0x01, 0x30, 0x82, 0x01, 0x71, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x01, 0x62, + 0x04, 0x82, 0x01, 0x5e, 0x15, 0x24, 0x00, 0x01, 0x25, 0x01, 0xf1, 0xff, 0x36, 0x02, 0x05, 0x00, 0x80, 0x05, 0x01, 0x80, + 0x05, 0x02, 0x80, 0x05, 0x03, 0x80, 0x05, 0x04, 0x80, 0x05, 0x05, 0x80, 0x05, 0x06, 0x80, 0x05, 0x07, 0x80, 0x05, 0x08, + 0x80, 0x05, 0x09, 0x80, 0x05, 0x0a, 0x80, 0x05, 0x0b, 0x80, 0x05, 0x0c, 0x80, 0x05, 0x0d, 0x80, 0x05, 0x0e, 0x80, 0x05, + 0x0f, 0x80, 0x05, 0x10, 0x80, 0x05, 0x11, 0x80, 0x05, 0x12, 0x80, 0x05, 0x13, 0x80, 0x05, 0x14, 0x80, 0x05, 0x15, 0x80, + 0x05, 0x16, 0x80, 0x05, 0x17, 0x80, 0x05, 0x18, 0x80, 0x05, 0x19, 0x80, 0x05, 0x1a, 0x80, 0x05, 0x1b, 0x80, 0x05, 0x1c, + 0x80, 0x05, 0x1d, 0x80, 0x05, 0x1e, 0x80, 0x05, 0x1f, 0x80, 0x05, 0x20, 0x80, 0x05, 0x21, 0x80, 0x05, 0x22, 0x80, 0x05, + 0x23, 0x80, 0x05, 0x24, 0x80, 0x05, 0x25, 0x80, 0x05, 0x26, 0x80, 0x05, 0x27, 0x80, 0x05, 0x28, 0x80, 0x05, 0x29, 0x80, + 0x05, 0x2a, 0x80, 0x05, 0x2b, 0x80, 0x05, 0x2c, 0x80, 0x05, 0x2d, 0x80, 0x05, 0x2e, 0x80, 0x05, 0x2f, 0x80, 0x05, 0x30, + 0x80, 0x05, 0x31, 0x80, 0x05, 0x32, 0x80, 0x05, 0x33, 0x80, 0x05, 0x34, 0x80, 0x05, 0x35, 0x80, 0x05, 0x36, 0x80, 0x05, + 0x37, 0x80, 0x05, 0x38, 0x80, 0x05, 0x39, 0x80, 0x05, 0x3a, 0x80, 0x05, 0x3b, 0x80, 0x05, 0x3c, 0x80, 0x05, 0x3d, 0x80, + 0x05, 0x3e, 0x80, 0x05, 0x3f, 0x80, 0x05, 0x40, 0x80, 0x05, 0x41, 0x80, 0x05, 0x42, 0x80, 0x05, 0x43, 0x80, 0x05, 0x44, + 0x80, 0x05, 0x45, 0x80, 0x05, 0x46, 0x80, 0x05, 0x47, 0x80, 0x05, 0x48, 0x80, 0x05, 0x49, 0x80, 0x05, 0x4a, 0x80, 0x05, + 0x4b, 0x80, 0x05, 0x4c, 0x80, 0x05, 0x4d, 0x80, 0x05, 0x4e, 0x80, 0x05, 0x4f, 0x80, 0x05, 0x50, 0x80, 0x05, 0x51, 0x80, + 0x05, 0x52, 0x80, 0x05, 0x53, 0x80, 0x05, 0x54, 0x80, 0x05, 0x55, 0x80, 0x05, 0x56, 0x80, 0x05, 0x57, 0x80, 0x05, 0x58, + 0x80, 0x05, 0x59, 0x80, 0x05, 0x5a, 0x80, 0x05, 0x5b, 0x80, 0x05, 0x5c, 0x80, 0x05, 0x5d, 0x80, 0x05, 0x5e, 0x80, 0x05, + 0x5f, 0x80, 0x05, 0x60, 0x80, 0x05, 0x61, 0x80, 0x05, 0x62, 0x80, 0x05, 0x63, 0x80, 0x18, 0x24, 0x03, 0x16, 0x2c, 0x04, + 0x13, 0x5a, 0x49, 0x47, 0x32, 0x30, 0x31, 0x34, 0x32, 0x5a, 0x42, 0x33, 0x33, 0x30, 0x30, 0x30, 0x33, 0x2d, 0x32, 0x34, + 0x24, 0x05, 0x00, 0x24, 0x06, 0x00, 0x25, 0x07, 0x94, 0x26, 0x24, 0x08, 0x00, 0x18, 0x31, 0x7d, 0x30, 0x7b, 0x02, 0x01, + 0x03, 0x80, 0x14, 0x62, 0xfa, 0x82, 0x33, 0x59, 0xac, 0xfa, 0xa9, 0x96, 0x3e, 0x1c, 0xfa, 0x14, 0x0a, 0xdd, 0xf5, 0x04, + 0xf3, 0x71, 0x60, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x0a, 0x06, 0x08, + 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x04, 0x47, 0x30, 0x45, 0x02, 0x20, 0x24, 0xe5, 0xd1, 0xf4, 0x7a, 0x7d, + 0x7b, 0x0d, 0x20, 0x6a, 0x26, 0xef, 0x69, 0x9b, 0x7c, 0x97, 0x57, 0xb7, 0x2d, 0x46, 0x90, 0x89, 0xde, 0x31, 0x92, 0xe6, + 0x78, 0xc7, 0x45, 0xe7, 0xf6, 0x0c, 0x02, 0x21, 0x00, 0xf8, 0xaa, 0x2f, 0xa7, 0x11, 0xfc, 0xb7, 0x9b, 0x97, 0xe3, 0x97, + 0xce, 0xda, 0x66, 0x7b, 0xae, 0x46, 0x4e, 0x2b, 0xd3, 0xff, 0xdf, 0xc3, 0xcc, 0xed, 0x7a, 0xa8, 0xca, 0x5f, 0x4c, 0x1a, + 0x7c, + }; + + return CopySpanToMutableSpan(ByteSpan{ kCdForAllExamples }, out_buffer); +} + +CHIP_ERROR DeviceAttestationCredsCC13X2_26X2::GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) +{ + out_firmware_info_buffer.reduce_size(0); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DeviceAttestationCredsCC13X2_26X2::GetDeviceAttestationCert(MutableByteSpan & out_buffer) +{ + ReturnErrorCodeIf(out_buffer.size() < mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + + return CopySpanToMutableSpan(ByteSpan{ mFactoryData->dac_cert.data, mFactoryData->dac_cert.len }, out_buffer); +} + +CHIP_ERROR DeviceAttestationCredsCC13X2_26X2::GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer) +{ + ReturnErrorCodeIf(out_buffer.size() < mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + + return CopySpanToMutableSpan(ByteSpan{ mFactoryData->pai_cert.data, mFactoryData->pai_cert.len }, out_buffer); +} + +CHIP_ERROR DeviceAttestationCredsCC13X2_26X2::SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, + MutableByteSpan & out_buffer) +{ + Crypto::P256ECDSASignature signature; + Crypto::P256Keypair keypair; + + VerifyOrReturnError(IsSpanUsable(out_buffer), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(out_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL); + + // In a non-exemplary implementation, the public key is not needed here. It is used here merely because + // Crypto::P256Keypair is only (currently) constructable from raw keys if both private/public keys are present. + ReturnErrorOnFailure(LoadKeypairFromRaw(ByteSpan(mFactoryData->dac_priv_key.data, mFactoryData->dac_priv_key.len), + ByteSpan(mFactoryData->dac_pub_key.data, mFactoryData->dac_pub_key.len), keypair)); + ReturnErrorOnFailure(keypair.ECDSA_sign_msg(message_to_sign.data(), message_to_sign.size(), signature)); + + return CopySpanToMutableSpan(ByteSpan{ signature.ConstBytes(), signature.Length() }, out_buffer); +} + +} // namespace + +DeviceAttestationCredentialsProvider * GetCC13X2_26X2DacProvider() +{ + static DeviceAttestationCredsCC13X2_26X2 dac_provider; + return &dac_provider; +} + +} // namespace CC13X2_26X2 +} // namespace Credentials +} // namespace chip diff --git a/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.h b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.h new file mode 100644 index 00000000000000..37edd157a228ce --- /dev/null +++ b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.h @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include + +namespace chip { +namespace Credentials { +namespace CC13X2_26X2 { + +/** + * @brief Get implementation of a sample DAC provider to validate device + * attestation procedure. + * + * @returns a singleton DeviceAttestationCredentialsProvider that relies on no + * storage abstractions. + */ +DeviceAttestationCredentialsProvider * GetCC13X2_26X2DacProvider(); + +} // namespace CC13X2_26X2 +} // namespace Credentials +} // namespace chip diff --git a/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn b/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn index 00bd404700ccba..7eadbc73e8c4a9 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn @@ -85,6 +85,7 @@ ti_simplelink_executable("pump_app") { deps = [ ":sdk", ":sysconfig", + "${chip_root}/examples/platform/cc13x2_26x2:cc13x2_26x2-attestation-credentials", "${chip_root}/examples/pump-app/pump-common", "${chip_root}/src/lib", ] diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp index ec04f66a5216f1..62a5e436a58310 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -26,12 +26,12 @@ #include #include "FreeRTOS.h" -#include -#include - #include #include #include +#include +#include +#include #if defined(CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR) #include @@ -221,8 +221,12 @@ int AppTask::Init() (void) initParams.InitializeStaticResourcesBeforeServerInit(); chip::Server::GetInstance().Init(initParams); - // Initialize device attestation config +// Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif ConfigurationMgr().LogDeviceConfig(); diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp index 9a9ea2dcd1268a..70abc0fc6f6812 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp @@ -44,61 +44,89 @@ namespace Internal { /* itemID and subID are limited to 10 bits, even though their types are uint16_t */ // Keys stored in the Chip-factory namespace -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SerialNum = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0001 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceId = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0002 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceCert = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0003 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceICACerts = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0004 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDevicePrivateKey = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0005 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_HardwareVersion = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0006 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ManufacturingDate = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0007 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupPinCode = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0008 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupDiscriminator = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x0009 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pIterationCount = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x000a } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pSalt = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x000b } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pVerifier = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x000c } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_BootCount = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x000d } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_TotalOperationalHours = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x000f } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SerialNum = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0001 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceId = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0002 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceCert = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0003 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceICACerts = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0004 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDevicePrivateKey = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0005 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_HardwareVersion = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0006 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ManufacturingDate = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0007 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupPinCode = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0008 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupDiscriminator = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0009 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pIterationCount = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000a } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pSalt = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000b } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pVerifier = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000c } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LifeTimeCounter = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0010 } +}; + +// Keys stored in the Chip-counters namespace +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_BootCount = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipCounters, .subID = 0x000d } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_TotalOperationalHours = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipCounters, .subID = 0x000f } +}; // Keys stored in the Chip-config namespace -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceConfig = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x0012 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_PairedAccountId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x0013 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x0014 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LastUsedEpochKeyId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x0017 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FailSafeArmed = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x0018 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_WiFiStationSecType = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x0019 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x001a } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x001b } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceConfig = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0012 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_PairedAccountId = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0013 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceId = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0014 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LastUsedEpochKeyId = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00017 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FailSafeArmed = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00018 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_WiFiStationSecType = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00019 } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001a } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001b } +}; // itemID 0x001c is unused (used to be breadcrumb). -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_UniqueId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, - .itemID = 0x001d } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_UniqueId = { + { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001d } +}; /* Internal for the KVS interface. */ -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_key = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x001d } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_value = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, - .itemID = 0x001e } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_key = { { .systemID = kCC13X2_26X2Matter_SysID, + .itemID = kCC13X2_26X2Matter_ItemID_ChipKVS_key } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_value = { { .systemID = kCC13X2_26X2Matter_SysID, + .itemID = kCC13X2_26X2Matter_ItemID_ChipKVS_value } }; /* Static local variables */ static NVINTF_nvFuncts_t sNvoctpFps = { 0 }; @@ -389,43 +417,62 @@ CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void) NVINTF_nvProxy_t nvProxy = { 0 }; uint8_t status = NVINTF_SUCCESS; + // Delete items with the config, counter, kvs_key and kvs_value itemIDs. Items with the factory + // itemIDs are not deleted. + intptr_t key = sNvoctpFps.lockNV(); /* Setup doNext call */ - nvProxy.sysid = kCC13X2_26X2ChipConfig_Sysid; - nvProxy.flag = NVINTF_DOSTART | NVINTF_DOSYSID | NVINTF_DODELETE; + nvProxy.sysid = kCC13X2_26X2Matter_SysID; + nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipConfig; + nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; - /* Lock and wipe all items with sysid TIOP */ + /* Lock and wipe all items with config itemid */ do { status = sNvoctpFps.doNext(&nvProxy); } while (NVINTF_SUCCESS == status); /* check we ran out of elements */ - VerifyOrExit(status != NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); - /* Setup doNext call. Sysid is the same here, but it doesn't necessarily have to be. Matching POSIX impl */ - nvProxy.sysid = kCC13X2_26X2ChipFactory_Sysid; - nvProxy.flag = NVINTF_DOSTART | NVINTF_DOSYSID | NVINTF_DODELETE; + /* Setup doNext call */ + nvProxy.sysid = kCC13X2_26X2Matter_SysID; + nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipCounters; + nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; - /* Lock and wipe all items with sysid TIOP */ + /* Lock and wipe all items with counters itemid */ do { status = sNvoctpFps.doNext(&nvProxy); } while (NVINTF_SUCCESS == status); /* check we ran out of elements */ - VerifyOrExit(status != NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + + /* Setup doNext call */ + nvProxy.sysid = kCC13X2_26X2Matter_SysID; + nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipKVS_key; + nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; - /* Setup doNext call. Sysid is the same here, but it doesn't necessarily have to be. Matching POSIX impl */ - nvProxy.sysid = kCC13X2_26X2ChipCounters_Sysid; - nvProxy.flag = NVINTF_DOSTART | NVINTF_DOSYSID | NVINTF_DODELETE; + /* Lock and wipe all items with kvs_key itemid */ + do + { + status = sNvoctpFps.doNext(&nvProxy); + } while (NVINTF_SUCCESS == status); + /* check we ran out of elements */ + VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + + /* Setup doNext call */ + nvProxy.sysid = kCC13X2_26X2Matter_SysID; + nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipKVS_value; + nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; - /* Lock and wipe all items with sysid TIOP */ + /* Lock and wipe all items with key_value itemid */ do { status = sNvoctpFps.doNext(&nvProxy); } while (NVINTF_SUCCESS == status); /* check we ran out of elements */ - VerifyOrExit(status != NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); exit: sNvoctpFps.unlockNV(key); diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h b/src/platform/cc13x2_26x2/CC13X2_26X2Config.h index 1c4bbfd5059256..f3e8191aeca011 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.h @@ -38,11 +38,21 @@ class CC13X2_26X2Config struct Key; // TODO: Define a proper system ID in upstream driver - static constexpr uint16_t kNvinf_sysid_chip = (13); + static constexpr uint16_t kNvinf_sysid_chip = 13; - static const uint16_t kCC13X2_26X2ChipConfig_Sysid = kNvinf_sysid_chip; - static const uint16_t kCC13X2_26X2ChipFactory_Sysid = kNvinf_sysid_chip; - static const uint16_t kCC13X2_26X2ChipCounters_Sysid = kNvinf_sysid_chip; + static constexpr uint16_t kNVinf_itemid_chipConfig = 1; + static constexpr uint16_t kNVinf_itemid_chipFactory = 2; + static constexpr uint16_t kNVinf_itemid_chipCounters = 3; + static constexpr uint16_t kNVinf_itemid_chipKVS_key = 4; + static constexpr uint16_t kNVinf_itemid_chipKVS_value = 5; + + static const uint16_t kCC13X2_26X2Matter_SysID = kNvinf_sysid_chip; + + static const uint16_t kCC13X2_26X2Matter_ItemID_ChipConfig = kNVinf_itemid_chipConfig; + static const uint16_t kCC13X2_26X2Matter_ItemID_ChipFactory = kNVinf_itemid_chipFactory; + static const uint16_t kCC13X2_26X2Matter_ItemID_ChipCounters = kNVinf_itemid_chipCounters; + static const uint16_t kCC13X2_26X2Matter_ItemID_ChipKVS_key = kNVinf_itemid_chipKVS_key; + static const uint16_t kCC13X2_26X2Matter_ItemID_ChipKVS_value = kNVinf_itemid_chipKVS_value; // Key definitions for well-known keys. static const Key kConfigKey_SerialNum; @@ -70,6 +80,7 @@ class CC13X2_26X2Config static const Key kConfigKey_Spake2pVerifier; static const Key kConfigKey_BootCount; static const Key kConfigKey_TotalOperationalHours; + static const Key kConfigKey_LifeTimeCounter; static CHIP_ERROR Init(void); diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp index 91b6e42f4d4991..7d420bab1c93e2 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp @@ -126,7 +126,7 @@ CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOp CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2ChipCounters_Sysid, key } }; + CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2Matter_SysID, key } }; CHIP_ERROR err = ReadConfigValue(configKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -138,7 +138,7 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2ChipCounters_Sysid, key } }; + CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2Matter_SysID, key } }; return WriteConfigValue(configKey, value); }