diff --git a/docs/guides/ti/images/cc13x2_memmap.png b/docs/guides/ti/images/cc13x2_memmap.png new file mode 100644 index 00000000000000..a89aee7837e3aa Binary files /dev/null and b/docs/guides/ti/images/cc13x2_memmap.png differ diff --git a/docs/guides/ti/images/cc13x4_memmap.png b/docs/guides/ti/images/cc13x4_memmap.png new file mode 100644 index 00000000000000..4442c6352efbc9 Binary files /dev/null and b/docs/guides/ti/images/cc13x4_memmap.png differ diff --git a/docs/guides/ti/images/factory_data_overview.png b/docs/guides/ti/images/factory_data_overview.png new file mode 100644 index 00000000000000..f2718ce708f854 Binary files /dev/null and b/docs/guides/ti/images/factory_data_overview.png differ diff --git a/docs/guides/ti/ti_factory_data_user_guide.md b/docs/guides/ti/ti_factory_data_user_guide.md new file mode 100644 index 00000000000000..c8168779d17119 --- /dev/null +++ b/docs/guides/ti/ti_factory_data_user_guide.md @@ -0,0 +1,127 @@ +# Texas Instruments Matter Factory Data Programming User Guide + +This document describes how to use the factory data programming feature for +Matter example applications from Texas Instruments. + +## Background + +The Matter specification lists various information elements that are programmed +at the factory. These values do not change and some are unique per device. This +feature enables customers developing Matter products on TI devices to program +this data and use this as a starting point towards developing their factory +programming infrastructure for their Matter devices. + +## Solution Overview: + +TI Matter examples allow the use of factory data in the following two ways: + +- **Example Out of Box Factory Data** : Use TI example DAC values to get + started. This is intended to be used when just starting with Matter or + during development until customer or product specific data is not required. +- **Custom factory data** : Allows users to configure custom factory data via + a JSON file. The custom values are then processed by a script provided by TI + and merged with the Matter application to create a binary that can be + flashed on to devices. + +### Solution Block Diagram + +![Block Diagram](images/factory_data_overview.png) + +Each element is described in more detail below: + +1. Factory Data JSON: This file is located at src/platform/cc13xx_26xx. + Developers can configure this per device. Elements in this file are from the + specification. +2. Matter Application with dummy factory data: Any TI Matter example application +3. `BIM`/MCUBoot: Boot Image Manager/MCUBoot image used for OTA. This is built + with the Matter application and does not require additional build steps from + developers. +4. create_factory_data.py: Processes a factory data JSON file and generates a + hex file with the unique factory data values configured in the JSON file. +5. factory_data_trim.py: When using the custom factory data option, this script + removes the dummy factory data which is required to be able to successfully + compile the application. +6. `oad`\_and_factory_data_merge_tool.py: Merges the factory data hex, Matter + application without factory data and `BIM`/MCUBoot image to generate a + functional hex that can be programmed onto the device. + +## Flash memory layout + +![Memory Layout 1](images/cc13x2_memmap.png) + +![Memory Layout 2](images/cc13x4_memmap.png) + +## How to use + +Out of box factory data location is configured to be on second last page of +flash. For CC13x2, the starting address is `0xAC000`. For CC13x4, the starting +address is `0xFE800`. This can be configured in the linker file. + +To configure: + +1. Linker file: Set the start address for factory data in the linker file being + used by the application + +``` +FLASH_FACTORY_DATA (R) : ORIGIN = 0x000ac000, LENGTH = 0x00000900 +``` + +``` +/* Define base address for the DAC arrays and struct */ + PROVIDE (_factory_data_base_address = + DEFINED(_factory_data_base_address) ? _factory_data_base_address : 0xAC000); +``` + +2. create_factory_data.py: Set the address of the start of the factory data + elements. Refer to the comments in the script. + +``` + # there are 17 elements, each element will need 8 bytes in the struct + # 4 for length of the element, and 4 for the pointer to the element + # factory data starts at 0xAC000 or 0xFE800, so the elements will + # start 136 bytes after the start address + factory_data_dict = json.load(args.factory_data_json_file[0]) + factory_data_schema = json.load(args.factory_data_schema[0]) + + validate(factory_data_dict, factory_data_schema) + factory_data = factory_data_dict['elements'] + + struct_idx = 0 + values_idx = 0 + if device_family == 'cc13x2_26x2': + value_address = 0xAC088 + else: + value_address = 0xFE888 +``` + +``` + if device_family == 'cc13x2_26x2': + subprocess.call(['objcopy', 'temp.bin','--input-target','binary','--output-target', 'ihex', args.factory_data_hex_file, '--change-addresses=0xac000']) + else: + subprocess.call(['objcopy', 'temp.bin','--input-target','binary','--output-target', 'ihex', args.factory_data_hex_file, '--change-addresses=0xfe800']) +``` + +3. In the example's args.gni file, set 'custom_factory_data' to true + +It is recommended to keep a dedicated page (2 pages for CC13x4) for factory +data. + +### Formatting certs and keys for JSON file + +To format the DAC, private key and PAI as hex strings as shown in the Factory +Data JSON file, use the chip-cert tool located at src/tools/chip-cert and run +the _convert-cert_ command, and list -X, or X.509 DER hex encoded format, as the +output format. These strings can then be copied into the JSON file. + +The SPAKE parameters should be converted from base-64 to hex as well before +being copied into the JSON file. + +### Creating images + +The example application can be built using the instructions in the example's +README. The factory data from the JSON file will be formatted into a hex file +that will then be merged into the final executable. The final executable will be +named _{example-application}-`bim`.hex_ for CC13x2 and +_{example-application}-mcuboot.hex_ for CC13x4, and the factory data that was +inputted into the JSON file will be named +_{example-application}-factory-data.hex_. diff --git a/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn b/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn index dec41e71dc265c..f861549db2fcac 100644 --- a/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn @@ -108,6 +108,10 @@ ti_simplelink_executable("all-clusters-app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${project_dir}/main", diff --git a/examples/all-clusters-app/cc13x2x7_26x2x7/args.gni b/examples/all-clusters-app/cc13x2x7_26x2x7/args.gni index 9228f70c4a0f03..23c3aee1afb0bb 100644 --- a/examples/all-clusters-app/cc13x2x7_26x2x7/args.gni +++ b/examples/all-clusters-app/cc13x2x7_26x2x7/args.gni @@ -50,3 +50,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" matter_software_ver_str = "1.0d1" + +custom_factory_data = true diff --git a/examples/all-clusters-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/all-clusters-app/cc13x2x7_26x2x7/main/AppTask.cpp index 2d5896a236b570..b6b9bf1e8bd8f4 100644 --- a/examples/all-clusters-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/all-clusters-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -230,6 +230,19 @@ int AppTask::Init() ; } + // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + ret = PlatformMgr().StartEventLoopTask(); if (ret != CHIP_NO_ERROR) { @@ -259,9 +272,6 @@ int AppTask::Init() ConfigurationMgr().LogDeviceConfig(); - // Initialize device attestation config - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - // We only have network commissioning on endpoint 0. emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); diff --git a/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/AppTask.h b/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/AppTask.h index 002e1b3f70557c..6ab8ca425ddbdf 100644 --- a/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/AppTask.h +++ b/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/AppTask.h @@ -30,6 +30,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + class AppTask { public: @@ -62,6 +66,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index 0fd26ca07fdc5f..5bb01459551d91 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -112,6 +112,10 @@ ti_simplelink_executable("all-clusters-app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${project_dir}/main", diff --git a/examples/all-clusters-app/cc13x4_26x4/args.gni b/examples/all-clusters-app/cc13x4_26x4/args.gni index 7c2e2acc9ae809..35d9666f3ed07c 100644 --- a/examples/all-clusters-app/cc13x4_26x4/args.gni +++ b/examples/all-clusters-app/cc13x4_26x4/args.gni @@ -50,3 +50,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" matter_software_ver_str = "1.0.1+1" + +custom_factory_data = true diff --git a/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp b/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp index 1ab7b33a03c846..f82436346fc241 100644 --- a/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp +++ b/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp @@ -246,6 +246,19 @@ int AppTask::Init() ; } +// Initialize device attestation config +#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + // Init ZCL Data Model and start server PLAT_LOG("Initialize Server"); static chip::CommonCaseDeviceServerInitParams initParams; @@ -259,13 +272,6 @@ int AppTask::Init() ConfigurationMgr().LogDeviceConfig(); - // Initialize device attestation config -#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - // We only have network commissioning on endpoint 0. emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); diff --git a/examples/all-clusters-app/cc13x4_26x4/main/include/AppTask.h b/examples/all-clusters-app/cc13x4_26x4/main/include/AppTask.h index 002e1b3f70557c..6ab8ca425ddbdf 100644 --- a/examples/all-clusters-app/cc13x4_26x4/main/include/AppTask.h +++ b/examples/all-clusters-app/cc13x4_26x4/main/include/AppTask.h @@ -30,6 +30,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + class AppTask { public: @@ -62,6 +66,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/lighting-app/cc13x2x7_26x2x7/BUILD.gn b/examples/lighting-app/cc13x2x7_26x2x7/BUILD.gn index 86c9229a05aff3..a745c65a1407cf 100644 --- a/examples/lighting-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/lighting-app/cc13x2x7_26x2x7/BUILD.gn @@ -91,6 +91,10 @@ ti_simplelink_executable("lighting_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${chip_root}/examples/providers/", diff --git a/examples/lighting-app/cc13x2x7_26x2x7/args.gni b/examples/lighting-app/cc13x2x7_26x2x7/args.gni index 56695a5ad89396..8f2c82446b1cf0 100644 --- a/examples/lighting-app/cc13x2x7_26x2x7/args.gni +++ b/examples/lighting-app/cc13x2x7_26x2x7/args.gni @@ -49,3 +49,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8005" matter_software_ver = "0x0001" matter_software_ver_str = "1.0d1" + +custom_factory_data = true diff --git a/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.cpp b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.cpp index c9e8845a4f7323..7d84e656927d09 100644 --- a/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.cpp +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.cpp @@ -180,6 +180,19 @@ int AppTask::Init() ; } + // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + ret = ThreadStackMgr().InitThreadStack(); if (ret != CHIP_NO_ERROR) { @@ -226,13 +239,6 @@ int AppTask::Init() Server::GetInstance().Init(initParams); - // Initialize device attestation config -#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - // Initialize LEDs PLAT_LOG("Initialize LEDs"); LED_init(); diff --git a/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.h b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.h index 3d305601bc12f7..c82a122fef4ea8 100644 --- a/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.h +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.h @@ -30,6 +30,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + // Application-defined error codes in the CHIP_ERROR space. #define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) #define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) @@ -85,6 +89,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/lighting-app/cc13x4_26x4/BUILD.gn b/examples/lighting-app/cc13x4_26x4/BUILD.gn index 8b24330ea346d2..f4e9ce30d080aa 100644 --- a/examples/lighting-app/cc13x4_26x4/BUILD.gn +++ b/examples/lighting-app/cc13x4_26x4/BUILD.gn @@ -99,6 +99,10 @@ ti_simplelink_executable("lighting_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${chip_root}/examples/providers/", diff --git a/examples/lighting-app/cc13x4_26x4/args.gni b/examples/lighting-app/cc13x4_26x4/args.gni index 4292dcd7982393..c9f4b718ec9aca 100644 --- a/examples/lighting-app/cc13x4_26x4/args.gni +++ b/examples/lighting-app/cc13x4_26x4/args.gni @@ -48,3 +48,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8005" matter_software_ver = "0x0001" matter_software_ver_str = "1.0.1+1" + +custom_factory_data = true diff --git a/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp b/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp index b6cce74ca13aae..94674a1a787a95 100644 --- a/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp +++ b/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp @@ -214,6 +214,19 @@ int AppTask::Init() ; } + // Initialize device attestation config +#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + // Init ZCL Data Model and start server PLAT_LOG("Initialize Server"); static CommonCaseDeviceServerInitParams initParams; @@ -225,13 +238,6 @@ int AppTask::Init() Server::GetInstance().Init(initParams); - // Initialize device attestation config -#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - // Initialize LEDs PLAT_LOG("Initialize LEDs"); LED_init(); diff --git a/examples/lighting-app/cc13x4_26x4/src/AppTask.h b/examples/lighting-app/cc13x4_26x4/src/AppTask.h index 3d305601bc12f7..c82a122fef4ea8 100644 --- a/examples/lighting-app/cc13x4_26x4/src/AppTask.h +++ b/examples/lighting-app/cc13x4_26x4/src/AppTask.h @@ -30,6 +30,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + // Application-defined error codes in the CHIP_ERROR space. #define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) #define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) @@ -85,6 +89,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn b/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn index 1bbb257ceccd33..db4f599aad8f79 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn @@ -91,6 +91,10 @@ ti_simplelink_executable("lock_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${chip_root}/examples/providers/", diff --git a/examples/lock-app/cc13x2x7_26x2x7/args.gni b/examples/lock-app/cc13x2x7_26x2x7/args.gni index 8c7a4eb1c448e5..b10e4def1a1a7c 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/args.gni +++ b/examples/lock-app/cc13x2x7_26x2x7/args.gni @@ -49,3 +49,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" matter_software_ver_str = "1.0d1" + +custom_factory_data = true diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp deleted file mode 100644 index 1988455e958398..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ /dev/null @@ -1,394 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2020 Texas Instruments Incorporated - * All rights reserved. - * - * 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 "AppTask.h" -#include "AppConfig.h" -#include "AppEvent.h" -#include - -#include "FreeRTOS.h" - -#include -#include - -#include -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR -#include -#include -#include -#include -#include -#endif - -#include -#include - -#include - -#include -#include - -/* syscfg */ -#include - -#define APP_TASK_STACK_SIZE (4096) -#define APP_TASK_PRIORITY 4 -#define APP_EVENT_QUEUE_SIZE 10 - -using namespace ::chip; -using namespace ::chip::Credentials; -using namespace ::chip::DeviceLayer; - -static TaskHandle_t sAppTaskHandle; -static QueueHandle_t sAppEventQueue; - -static LED_Handle sAppRedHandle; -static LED_Handle sAppGreenHandle; -static Button_Handle sAppLeftHandle; -static Button_Handle sAppRightHandle; -static DeviceInfoProviderImpl sExampleDeviceInfoProvider; - -AppTask AppTask::sAppTask; - -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR -static DefaultOTARequestor sRequestorCore; -static DefaultOTARequestorStorage sRequestorStorage; -static DefaultOTARequestorDriver sRequestorUser; -static BDXDownloader sDownloader; -static OTAImageProcessorImpl sImageProcessor; - -void InitializeOTARequestor(void) -{ - // Initialize and interconnect the Requestor and Image Processor objects - SetRequestorInstance(&sRequestorCore); - - sRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); - sRequestorCore.Init(Server::GetInstance(), sRequestorStorage, sRequestorUser, sDownloader); - sImageProcessor.SetOTADownloader(&sDownloader); - sDownloader.SetImageProcessorDelegate(&sImageProcessor); - sRequestorUser.Init(&sRequestorCore, &sImageProcessor); -} -#endif - -int AppTask::StartAppTask() -{ - int ret = 0; - - sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent)); - if (sAppEventQueue == NULL) - { - PLAT_LOG("Failed to allocate app event queue"); - while (true) - ; - } - - // Start App task. - if (xTaskCreate(AppTaskMain, "APP", APP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, APP_TASK_PRIORITY, &sAppTaskHandle) != - pdPASS) - { - PLAT_LOG("Failed to create app task"); - while (true) - ; - } - return ret; -} - -int AppTask::Init() -{ - LED_Params ledParams; - Button_Params buttonParams; - - cc13x2_26x2LogInit(); - - // Init Chip memory management before the stack - Platform::MemoryInit(); - - CHIP_ERROR ret = PlatformMgr().InitChipStack(); - if (ret != CHIP_NO_ERROR) - { - PLAT_LOG("PlatformMgr().InitChipStack() failed"); - while (true) - ; - } - - ret = ThreadStackMgr().InitThreadStack(); - if (ret != CHIP_NO_ERROR) - { - PLAT_LOG("ThreadStackMgr().InitThreadStack() failed"); - while (true) - ; - } -#if CHIP_DEVICE_CONFIG_THREAD_FTD - ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); -#else - ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); -#endif - if (ret != CHIP_NO_ERROR) - { - PLAT_LOG("ConnectivityMgr().SetThreadDeviceType() failed"); - while (true) - ; - } - - ret = PlatformMgr().StartEventLoopTask(); - if (ret != CHIP_NO_ERROR) - { - PLAT_LOG("PlatformMgr().StartEventLoopTask() failed"); - while (true) - ; - } - - ret = ThreadStackMgrImpl().StartThreadTask(); - if (ret != CHIP_NO_ERROR) - { - PLAT_LOG("ThreadStackMgr().StartThreadTask() failed"); - while (true) - ; - } - - // Init ZCL Data Model and start server - PLAT_LOG("Initialize Server"); - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - - // Initialize info provider - sExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); - SetDeviceInfoProvider(&sExampleDeviceInfoProvider); - - chip::Server::GetInstance().Init(initParams); - - // Initialize device attestation config - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - - // Initialize LEDs - PLAT_LOG("Initialize LEDs"); - LED_init(); - - LED_Params_init(&ledParams); // default PWM LED - sAppRedHandle = LED_open(CONFIG_LED_RED, &ledParams); - LED_setOff(sAppRedHandle); - - LED_Params_init(&ledParams); // default PWM LED - sAppGreenHandle = LED_open(CONFIG_LED_GREEN, &ledParams); - LED_setOff(sAppGreenHandle); - - // Initialize buttons - PLAT_LOG("Initialize buttons"); - Button_init(); - - Button_Params_init(&buttonParams); - buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; - buttonParams.longPressDuration = 1000U; // ms - sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); - Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler); - - Button_Params_init(&buttonParams); - buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; - buttonParams.longPressDuration = 1000U; // ms - sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); - Button_setCallback(sAppRightHandle, ButtonRightEventHandler); - - // Initialize BoltLock module - PLAT_LOG("Initialize BoltLock"); - BoltLockMgr().Init(); - - BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted); - - ConfigurationMgr().LogDeviceConfig(); - -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR - InitializeOTARequestor(); -#endif - // QR code will be used with CHIP Tool - PrintOnboardingCodes(RendezvousInformationFlags(RendezvousInformationFlag::kBLE)); - - return 0; -} - -void AppTask::AppTaskMain(void * pvParameter) -{ - AppEvent event; - - sAppTask.Init(); - - while (true) - { - /* Task pend until we have stuff to do */ - if (xQueueReceive(sAppEventQueue, &event, portMAX_DELAY) == pdTRUE) - { - sAppTask.DispatchEvent(&event); - } - } -} - -void AppTask::PostEvent(const AppEvent * aEvent) -{ - if (xQueueSend(sAppEventQueue, aEvent, 0) != pdPASS) - { - /* Failed to post the message */ - } -} - -void AppTask::ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events) -{ - AppEvent event; - event.Type = AppEvent::kEventType_ButtonLeft; - - if (events & Button_EV_CLICKED) - { - event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked; - } - else if (events & Button_EV_LONGCLICKED) - { - event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongClicked; - } - // button callbacks are in ISR context - if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS) - { - /* Failed to post the message */ - } -} - -void AppTask::ButtonRightEventHandler(Button_Handle handle, Button_EventMask events) -{ - AppEvent event; - event.Type = AppEvent::kEventType_ButtonRight; - - if (events & Button_EV_CLICKED) - { - event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked; - } - else if (events & Button_EV_LONGCLICKED) - { - event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongClicked; - } - // button callbacks are in ISR context - if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS) - { - /* Failed to post the message */ - } -} - -void AppTask::ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor) -{ - // If the action has been initiated by the lock, update the bolt lock trait - // and start flashing the LEDs rapidly to indicate action initiation. - if (aAction == BoltLockManager::LOCK_ACTION) - { - PLAT_LOG("Lock initiated"); - ; // TODO - } - else if (aAction == BoltLockManager::UNLOCK_ACTION) - { - PLAT_LOG("Unlock initiated"); - ; // TODO - } - - LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); - LED_startBlinking(sAppGreenHandle, 50 /* ms */, LED_BLINK_FOREVER); - LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); - LED_startBlinking(sAppRedHandle, 110 /* ms */, LED_BLINK_FOREVER); -} - -void AppTask::ActionCompleted(BoltLockManager::Action_t aAction) -{ - // if the action has been completed by the lock, update the bolt lock trait. - // Turn on the lock LED if in a LOCKED state OR - // Turn off the lock LED if in an UNLOCKED state. - if (aAction == BoltLockManager::LOCK_ACTION) - { - PLAT_LOG("Lock completed"); - LED_stopBlinking(sAppGreenHandle); - LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); - LED_stopBlinking(sAppRedHandle); - LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); - } - else if (aAction == BoltLockManager::UNLOCK_ACTION) - { - PLAT_LOG("Unlock completed"); - LED_stopBlinking(sAppGreenHandle); - LED_setOff(sAppGreenHandle); - LED_stopBlinking(sAppRedHandle); - LED_setOff(sAppRedHandle); - } -} - -void AppTask::DispatchEvent(AppEvent * aEvent) -{ - switch (aEvent->Type) - { - case AppEvent::kEventType_ButtonLeft: - if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) - { - if (!BoltLockMgr().IsUnlocked()) - { - BoltLockMgr().InitiateAction(0, BoltLockManager::UNLOCK_ACTION); - } - } - else if (AppEvent::kAppEventButtonType_LongClicked == aEvent->ButtonEvent.Type) - { - chip::Server::GetInstance().ScheduleFactoryReset(); - } - break; - - case AppEvent::kEventType_ButtonRight: - if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) - { - if (BoltLockMgr().IsUnlocked()) - { - BoltLockMgr().InitiateAction(0, BoltLockManager::LOCK_ACTION); - } - } - else if (AppEvent::kAppEventButtonType_LongClicked == aEvent->ButtonEvent.Type) - { - // Enable BLE advertisements - if (!ConnectivityMgr().IsBLEAdvertisingEnabled()) - { - if (Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() == CHIP_NO_ERROR) - { - PLAT_LOG("Enabled BLE Advertisements"); - } - else - { - PLAT_LOG("OpenBasicCommissioningWindow() failed"); - } - } - else - { - // Disable BLE advertisements - ConnectivityMgr().SetBLEAdvertisingEnabled(false); - PLAT_LOG("Disabled BLE Advertisements"); - } - } - break; - - case AppEvent::kEventType_AppEvent: - if (NULL != aEvent->Handler) - { - aEvent->Handler(aEvent); - } - break; - - case AppEvent::kEventType_None: - default: - break; - } -} diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/BoltLockManager.cpp b/examples/lock-app/cc13x2x7_26x2x7/main/BoltLockManager.cpp deleted file mode 100644 index b048fc9e9d3f09..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/BoltLockManager.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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 "BoltLockManager.h" - -#include "AppConfig.h" -#include "AppTask.h" -#include "FreeRTOS.h" - -#define ACTUATOR_MOVEMENT_PERIOS_MS 500 - -BoltLockManager BoltLockManager::sLock; - -int BoltLockManager::Init() -{ - int ret = 0; - - mTimerHandle = xTimerCreate("BLT_TIMER", pdMS_TO_TICKS(ACTUATOR_MOVEMENT_PERIOS_MS), pdFALSE, this, TimerEventHandler); - if (NULL == mTimerHandle) - { - PLAT_LOG("failed to create bolt lock timer"); - while (true) - ; - } - - mState = kState_LockingCompleted; - mAutoLockTimerArmed = false; - mAutoRelock = false; - mAutoLockDuration = 0; - - return ret; -} - -void BoltLockManager::SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB) -{ - mActionInitiated_CB = aActionInitiated_CB; - mActionCompleted_CB = aActionCompleted_CB; -} - -bool BoltLockManager::IsActionInProgress() -{ - return (mState == kState_LockingInitiated || mState == kState_UnlockingInitiated); -} - -bool BoltLockManager::IsUnlocked() -{ - return (mState == kState_UnlockingCompleted); -} - -void BoltLockManager::EnableAutoRelock(bool aOn) -{ - mAutoRelock = aOn; -} - -void BoltLockManager::SetAutoLockDuration(uint32_t aDurationInSecs) -{ - mAutoLockDuration = aDurationInSecs; -} - -bool BoltLockManager::InitiateAction(int32_t aActor, Action_t aAction) -{ - bool action_initiated = false; - State_t new_state; - - // Initiate Lock/Unlock Action only when the previous one is complete. - if (mState == kState_LockingCompleted && aAction == UNLOCK_ACTION) - { - action_initiated = true; - - new_state = kState_UnlockingInitiated; - } - else if (mState == kState_UnlockingCompleted && aAction == LOCK_ACTION) - { - action_initiated = true; - - new_state = kState_LockingInitiated; - } - - if (action_initiated) - { - if (mAutoLockTimerArmed && new_state == kState_LockingInitiated) - { - // If auto lock timer has been armed and someone initiates locking, - // cancel the timer and continue as normal. - mAutoLockTimerArmed = false; - - CancelTimer(); - } - - StartTimer(ACTUATOR_MOVEMENT_PERIOS_MS); - - // Since the timer started successfully, update the state and trigger callback - mState = new_state; - - if (mActionInitiated_CB) - { - mActionInitiated_CB(aAction, aActor); - } - } - - return action_initiated; -} - -void BoltLockManager::StartTimer(uint32_t aTimeoutMs) -{ - xTimerChangePeriod(mTimerHandle, pdMS_TO_TICKS(aTimeoutMs), 100); - xTimerStart(mTimerHandle, 100); -} - -void BoltLockManager::CancelTimer(void) -{ - xTimerStop(mTimerHandle, 100); -} - -void BoltLockManager::TimerEventHandler(TimerHandle_t aTimer) -{ - BoltLockManager * lock = static_cast(pvTimerGetTimerID(aTimer)); - - // The timer event handler will be called in the context of the timer task - // once sLockTimer expires. Post an event to apptask queue with the actual handler - // so that the event can be handled in the context of the apptask. - AppEvent event; - event.Type = AppEvent::kEventType_AppEvent; - event.BoltLockEvent.Context = static_cast(lock); - if (lock->mAutoLockTimerArmed) - { - event.Handler = AutoReLockTimerEventHandler; - } - else - { - event.Handler = ActuatorMovementTimerEventHandler; - } - GetAppTask().PostEvent(&event); -} - -void BoltLockManager::AutoReLockTimerEventHandler(AppEvent * aEvent) -{ - BoltLockManager * lock = static_cast(aEvent->BoltLockEvent.Context); - int32_t actor = 0; - - // Make sure auto lock timer is still armed. - if (!lock->mAutoLockTimerArmed) - { - return; - } - - lock->mAutoLockTimerArmed = false; - - PLAT_LOG("Auto Re-Lock has been triggered!"); - - lock->InitiateAction(actor, LOCK_ACTION); -} - -void BoltLockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent) -{ - Action_t actionCompleted = INVALID_ACTION; - - BoltLockManager * lock = static_cast(aEvent->BoltLockEvent.Context); - - if (lock->mState == kState_LockingInitiated) - { - lock->mState = kState_LockingCompleted; - actionCompleted = LOCK_ACTION; - } - else if (lock->mState == kState_UnlockingInitiated) - { - lock->mState = kState_UnlockingCompleted; - actionCompleted = UNLOCK_ACTION; - } - - if (actionCompleted != INVALID_ACTION) - { - if (lock->mActionCompleted_CB) - { - lock->mActionCompleted_CB(actionCompleted); - } - - if (lock->mAutoRelock && actionCompleted == UNLOCK_ACTION) - { - // Start the timer for auto relock - lock->StartTimer(lock->mAutoLockDuration * 1000); - - lock->mAutoLockTimerArmed = true; - - PLAT_LOG("Auto Re-lock enabled. Will be triggered in %u seconds", lock->mAutoLockDuration); - } - } -} diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp b/examples/lock-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp deleted file mode 100644 index f3b352607c913e..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Copyright (c) 2020 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 "AppConfig.h" -#include "BoltLockManager.h" - -#include -#include -#include -#include - -using namespace ::chip; -using namespace ::chip::app::Clusters; - -void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, - uint8_t * value) -{ - if (attributePath.mClusterId == OnOff::Id && attributePath.mAttributeId == OnOff::Attributes::OnOff::Id) - { - BoltLockMgr().InitiateAction(0, *value ? BoltLockManager::LOCK_ACTION : BoltLockManager::UNLOCK_ACTION); - } -} - -/** @brief OnOff Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - * TODO Issue #3841 - * emberAfOnOffClusterInitCallback happens before the stack initialize the cluster - * attributes to the default value. - * The logic here expects something similar to the deprecated Plugins callback - * emberAfPluginOnOffClusterServerPostInitCallback. - * - */ -void emberAfOnOffClusterInitCallback(EndpointId endpoint) -{ - // TODO: implement any additional Cluster Server init actions -} diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/AppConfig.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/AppConfig.h deleted file mode 100644 index 3cead418532caa..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/AppConfig.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -#ifndef APP_CONFIG_H -#define APP_CONFIG_H - -// Logging -#ifdef __cplusplus -extern "C" { -#endif - -int cc13x2_26x2LogInit(void); -void cc13x2_26x2Log(const char * aFormat, ...); -#define PLAT_LOG(...) cc13x2_26x2Log(__VA_ARGS__); - -#ifdef __cplusplus -} -#endif -#endif // APP_CONFIG_H diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/AppEvent.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/AppEvent.h deleted file mode 100644 index ad9e93ee3ad1a5..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/AppEvent.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Copyright (c) 2018 Nest Labs, Inc. - * All rights reserved. - * - * 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. - */ - -#ifndef APP_EVENT_H -#define APP_EVENT_H - -struct AppEvent; -typedef void (*EventHandler)(AppEvent *); - -struct AppEvent -{ - enum AppEventType - { - kEventType_None = 0, - kEventType_ButtonLeft, - kEventType_ButtonRight, - kEventType_AppEvent, - }; - - enum AppEventButtonType - { - kAppEventButtonType_None = 0, - kAppEventButtonType_Clicked, - kAppEventButtonType_LongClicked, - }; - - enum AppEventType Type; - - union - { - struct - { - enum AppEventButtonType Type; - } ButtonEvent; - - struct - { - void * Context; - } BoltLockEvent; - }; - - EventHandler Handler; -}; - -#endif // APP_EVENT_H diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/AppTask.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/AppTask.h deleted file mode 100644 index 21d552fa89b7d7..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/AppTask.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -#ifndef APP_TASK_H -#define APP_TASK_H - -#include -#include - -#include "FreeRTOS.h" -#include "semphr.h" -#include "task.h" - -#include "AppEvent.h" -#include "BoltLockManager.h" - -#include - -class AppTask -{ -public: - int StartAppTask(); - static void AppTaskMain(void * pvParameter); - - void PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction); - void PostEvent(const AppEvent * event); - -private: - friend AppTask & GetAppTask(void); - - int Init(); - - // should this be done by BoltLock Manager? I don't want to unravel this spaghetti quite yet - static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor); - static void ActionCompleted(BoltLockManager::Action_t aAction); - - void DispatchEvent(AppEvent * event); - - static void ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events); - static void ButtonRightEventHandler(Button_Handle handle, Button_EventMask events); - static void TimerEventHandler(void * p_context); - - enum Function_t - { - kFunction_NoneSelected = 0, - kFunction_SoftwareUpdate = 0, - kFunction_FactoryReset, - - kFunction_Invalid - } Function; - - Function_t mFunction; - bool mFunctionTimerActive; - - static AppTask sAppTask; -}; - -inline AppTask & GetAppTask(void) -{ - return AppTask::sAppTask; -} - -#endif // APP_TASK_H diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/BoltLockManager.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/BoltLockManager.h deleted file mode 100644 index 40fc4ffb338a67..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/BoltLockManager.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -#ifndef LOCK_MANAGER_H -#define LOCK_MANAGER_H - -#include -#include - -#include "AppEvent.h" - -#include -#include - -class BoltLockManager -{ -public: - enum Action_t - { - LOCK_ACTION = 0, - UNLOCK_ACTION, - - INVALID_ACTION - } Action; - - enum State_t - { - kState_LockingInitiated = 0, - kState_LockingCompleted, - kState_UnlockingInitiated, - kState_UnlockingCompleted, - } State; - - int Init(); - bool IsUnlocked(); - void EnableAutoRelock(bool aOn); - void SetAutoLockDuration(uint32_t aDurationInSecs); - bool IsActionInProgress(); - bool InitiateAction(int32_t aActor, Action_t aAction); - - typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor); - typedef void (*Callback_fn_completed)(Action_t); - void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB); - -private: - friend BoltLockManager & BoltLockMgr(void); - State_t mState; - - Callback_fn_initiated mActionInitiated_CB; - Callback_fn_completed mActionCompleted_CB; - - bool mAutoRelock; - uint32_t mAutoLockDuration; - bool mAutoLockTimerArmed; - TimerHandle_t mTimerHandle; - - void CancelTimer(void); - void StartTimer(uint32_t aTimeoutMs); - - static void TimerEventHandler(TimerHandle_t aTimer); - static void AutoReLockTimerEventHandler(AppEvent * aEvent); - static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); - - static BoltLockManager sLock; -}; - -inline BoltLockManager & BoltLockMgr(void) -{ - return BoltLockManager::sLock; -} - -#endif // LOCK_MANAGER_H diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h deleted file mode 100644 index 424e38a29f7766..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -/** - * @file - * Example project configuration file for CHIP. - * - * This is a place to put application or project-specific overrides - * to the default configuration values for general CHIP features. - * - */ - -#ifndef CHIP_PROJECT_CONFIG_H -#define CHIP_PROJECT_CONFIG_H - -#if BUILD_RELEASE // release build -// Note: Default Pairing/PIN/Serial Numbers being used. These should not be enabled for production builds -#endif // BUILD_RELEASE - -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 -#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 - -/** - * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER - * - * Enables the use of a hard-coded default serial number if none - * is found in CHIP NV storage. - */ -#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" - -/** - * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION - * - * The hardware version number assigned to device or product by the device vendor. This - * number is scoped to the device product id, and typically corresponds to a revision of the - * physical device, a change to its packaging, and/or a change to its marketing presentation. - * This value is generally *not* incremented for device software versions. - */ -#ifndef CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION -#define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 1 -#endif - -/** - * Values set by args.gni: - * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID - * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID - * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING - * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION - */ - -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for CHIP-over-BLE (CHIPOBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - -/** - * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE - * - * A size, in bytes, of the individual debug event logging buffer. - */ -#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) - -#define MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED 1 - -/** - * CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT - * - * Enable the OpenThread SRP client to allow for CHIP device discovery. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1 - -/** - * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE - * - * For a development build, set the default importance of events to be logged as Debug. - * Since debug is the lowest importance level, this means all standard, critical, info and - * debug importance level vi events get logged. - */ -#if BUILD_RELEASE -#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Production -#else -#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Debug -#endif // BUILD_RELEASE - -#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 - -/** - * @def CHIP_IM_MAX_NUM_COMMAND_HANDLER - * - * @brief Defines the maximum number of CommandHandler, limits the number of active commands transactions on server. - */ -#define CHIP_IM_MAX_NUM_COMMAND_HANDLER 2 - -/** - * @def CHIP_IM_MAX_NUM_WRITE_HANDLER - * - * @brief Defines the maximum number of WriteHandler, limits the number of active write transactions on server. - */ -#define CHIP_IM_MAX_NUM_WRITE_HANDLER 2 - -#endif // CHIP_PROJECT_CONFIG_H diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h deleted file mode 100644 index 30f5633cc3bc7f..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -/** - * @file - * Overrides to default OpenThread configuration. - * - */ - -#pragma once - -// Use the TI-supplied default platform configuration for remainder -#include "openthread-core-cc13x2_26x2-config.h" diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/main.cpp b/examples/lock-app/cc13x2x7_26x2x7/main/main.cpp deleted file mode 100644 index 8311c8990aa5c6..00000000000000 --- a/examples/lock-app/cc13x2x7_26x2x7/main/main.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2020 Texas Instruments Incorporated - * - * 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 -#include - -#include - -#include -#include - -#include - -/* Driver Header files */ -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#define TOTAL_ICALL_HEAP_SIZE (0xc800) - -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; - -__attribute__((section(".heap"))) uint8_t GlobalHeapZoneBuffer[TOTAL_ICALL_HEAP_SIZE]; -uint32_t heapSize = TOTAL_ICALL_HEAP_SIZE; - -// ================================================================================ -// FreeRTOS Callbacks -// ================================================================================ -extern "C" void vApplicationStackOverflowHook(void) -{ - while (true) - { - ; - } -} - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - Board_init(); - bpool((void *) GlobalHeapZoneBuffer, TOTAL_ICALL_HEAP_SIZE); - - GPIO_init(); - - NVS_init(); - - UART_init(); - - ECDH_init(); - - ECDSA_init(); - - AESECB_init(); - - SHA2_init(); - - int ret = GetAppTask().StartAppTask(); - if (ret != 0) - { - // can't log until the kernel is started - // PLAT_LOG("GetAppTask().StartAppTask() failed"); - while (true) - ; - } - - vTaskStartScheduler(); - - // Should never get here. - while (true) - ; -} diff --git a/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.cpp b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.cpp index d4e3d8f17f42db..380b05e32ca668 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.cpp +++ b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.cpp @@ -210,6 +210,19 @@ int AppTask::Init() ; } + // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + // Init ZCL Data Model and start server PLAT_LOG("Initialize Server"); static CommonCaseDeviceServerInitParams initParams; @@ -221,13 +234,6 @@ int AppTask::Init() Server::GetInstance().Init(initParams); - // Initialize device attestation config -#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - // Initialize LEDs PLAT_LOG("Initialize LEDs"); LED_init(); diff --git a/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.h b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.h index 15939e6581737b..7778fd5f2a5e1f 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.h +++ b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.h @@ -30,6 +30,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + // Application-defined error codes in the CHIP_ERROR space. #define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) #define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) @@ -84,6 +88,10 @@ class AppTask bool mSyncClusterToButtonAction; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/lock-app/cc13x4_26x4/BUILD.gn b/examples/lock-app/cc13x4_26x4/BUILD.gn index d7ec4065ea098f..67560cd7469f41 100644 --- a/examples/lock-app/cc13x4_26x4/BUILD.gn +++ b/examples/lock-app/cc13x4_26x4/BUILD.gn @@ -95,6 +95,10 @@ ti_simplelink_executable("lock_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${chip_root}/examples/providers/", diff --git a/examples/lock-app/cc13x4_26x4/args.gni b/examples/lock-app/cc13x4_26x4/args.gni index 2db85d82d398d3..d7508aaa640661 100644 --- a/examples/lock-app/cc13x4_26x4/args.gni +++ b/examples/lock-app/cc13x4_26x4/args.gni @@ -48,4 +48,7 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" matter_software_ver_str = "1.0.1+1" + # should be maj.min.rev+build with later parts optional for MCUBoot + +custom_factory_data = true diff --git a/examples/lock-app/cc13x4_26x4/src/AppTask.cpp b/examples/lock-app/cc13x4_26x4/src/AppTask.cpp index c73fd1f3909100..c42d06c705d846 100644 --- a/examples/lock-app/cc13x4_26x4/src/AppTask.cpp +++ b/examples/lock-app/cc13x4_26x4/src/AppTask.cpp @@ -209,6 +209,19 @@ int AppTask::Init() ; } + // Initialize device attestation config +#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + // Init ZCL Data Model and start server PLAT_LOG("Initialize Server"); static CommonCaseDeviceServerInitParams initParams; @@ -220,13 +233,6 @@ int AppTask::Init() Server::GetInstance().Init(initParams); - // Initialize device attestation config -#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - // Initialize LEDs PLAT_LOG("Initialize LEDs"); LED_init(); diff --git a/examples/lock-app/cc13x4_26x4/src/AppTask.h b/examples/lock-app/cc13x4_26x4/src/AppTask.h index 15939e6581737b..7778fd5f2a5e1f 100644 --- a/examples/lock-app/cc13x4_26x4/src/AppTask.h +++ b/examples/lock-app/cc13x4_26x4/src/AppTask.h @@ -30,6 +30,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + // Application-defined error codes in the CHIP_ERROR space. #define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) #define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) @@ -84,6 +88,10 @@ class AppTask bool mSyncClusterToButtonAction; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp index 46db7a1aaa2670..aa3469b030f4c7 100644 --- a/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp +++ b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp @@ -27,11 +27,6 @@ namespace Credentials { namespace CC13X2_26X2 { namespace { - -extern "C" { - -extern void cc13x2_26x2Log(const char * aFormat, ...); - typedef struct { const uint32_t len; @@ -50,12 +45,14 @@ 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, @@ -110,7 +107,8 @@ const uint8_t gPaiCert[] = { 0xd7, 0xdf, 0xea, 0x3f, 0x4d, 0xa4, 0x6f, 0x35, 0x7a, 0xfe, 0xac, 0xb8, 0x9b, 0x26, 0x77, 0x06, 0xd2, 0x8a, }; -const factoryData gFactoryData = { +const factoryData gFactoryData = +{ .dac_priv_key = { .len = sizeof(gDacPrivKey), .data = gDacPrivKey, @@ -129,8 +127,6 @@ const factoryData gFactoryData = { }, }; -} // extern "C" - CHIP_ERROR LoadKeypairFromRaw(ByteSpan private_key, ByteSpan public_key, Crypto::P256Keypair & keypair) { Crypto::P256SerializedKeypair serialized_keypair; diff --git a/examples/platform/cc13x4_26x4/CC13X4_26X4DeviceAttestationCreds.cpp b/examples/platform/cc13x4_26x4/CC13X4_26X4DeviceAttestationCreds.cpp index 2bbc7cb1829ab2..2cd36b6a14e93f 100644 --- a/examples/platform/cc13x4_26x4/CC13X4_26X4DeviceAttestationCreds.cpp +++ b/examples/platform/cc13x4_26x4/CC13X4_26X4DeviceAttestationCreds.cpp @@ -50,12 +50,14 @@ 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, diff --git a/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn b/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn index 525133b1f6aa90..4c670552dc2baf 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn @@ -91,6 +91,10 @@ ti_simplelink_executable("pump_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${project_dir}/main", diff --git a/examples/pump-app/cc13x2x7_26x2x7/args.gni b/examples/pump-app/cc13x2x7_26x2x7/args.gni index aeeb0708a235e7..1467940fa222ee 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/args.gni +++ b/examples/pump-app/cc13x2x7_26x2x7/args.gni @@ -47,3 +47,7 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x800A" matter_software_ver = "0x0001" matter_software_ver_str = "1.0d1" + +chip_openthread_ftd = false + +custom_factory_data = true diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp index 625d48392f59a8..38f248093548cf 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -207,6 +207,19 @@ int AppTask::Init() sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); Button_setCallback(sAppRightHandle, ButtonRightEventHandler); + // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + // Initialize Pump module PLAT_LOG("Initialize Pump"); PumpMgr().Init(); @@ -222,15 +235,11 @@ int AppTask::Init() (void) initParams.InitializeStaticResourcesBeforeServerInit(); chip::Server::GetInstance().Init(initParams); - // Initialize device attestation config -#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - ConfigurationMgr().LogDeviceConfig(); + uint32_t iterationCount; + mFactoryDataProvider.GetSpake2pIterationCount(iterationCount); + #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR InitializeOTARequestor(); #endif diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h index 7fd3f38ff6f0d5..47b4fd56f2d671 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h +++ b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h @@ -31,6 +31,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + struct Identify; class AppTask @@ -79,6 +83,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/pump-app/cc13x4_26x4/BUILD.gn b/examples/pump-app/cc13x4_26x4/BUILD.gn index f3fc4384f69336..7cbf21cc41140e 100644 --- a/examples/pump-app/cc13x4_26x4/BUILD.gn +++ b/examples/pump-app/cc13x4_26x4/BUILD.gn @@ -99,6 +99,10 @@ ti_simplelink_executable("pump_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${project_dir}/main", diff --git a/examples/pump-app/cc13x4_26x4/args.gni b/examples/pump-app/cc13x4_26x4/args.gni index 66e2a5a2e64ed0..05c67f203ca2a9 100644 --- a/examples/pump-app/cc13x4_26x4/args.gni +++ b/examples/pump-app/cc13x4_26x4/args.gni @@ -33,9 +33,9 @@ openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc chip_openthread_ftd = true # Disable CHIP Logging -#chip_progress_logging = false -#chip_detail_logging = false -#chip_automation_logging = false +chip_progress_logging = true +chip_detail_logging = true +chip_automation_logging = true # BLE options chip_config_network_layer_ble = true @@ -48,3 +48,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x800A" matter_software_ver = "0x0001" matter_software_ver_str = "1.0.1+1" + +custom_factory_data = true diff --git a/examples/pump-app/cc13x4_26x4/main/AppTask.cpp b/examples/pump-app/cc13x4_26x4/main/AppTask.cpp index 8611b750f80a34..c6e6d766c7e42d 100644 --- a/examples/pump-app/cc13x4_26x4/main/AppTask.cpp +++ b/examples/pump-app/cc13x4_26x4/main/AppTask.cpp @@ -207,6 +207,19 @@ int AppTask::Init() sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); Button_setCallback(sAppRightHandle, ButtonRightEventHandler); + // Initialize device attestation config +#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else + SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); +#endif +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + // Initialize Pump module PLAT_LOG("Initialize Pump"); PumpMgr().Init(); @@ -222,13 +235,6 @@ int AppTask::Init() (void) initParams.InitializeStaticResourcesBeforeServerInit(); chip::Server::GetInstance().Init(initParams); - // Initialize device attestation config -#ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - ConfigurationMgr().LogDeviceConfig(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR diff --git a/examples/pump-app/cc13x4_26x4/main/include/AppTask.h b/examples/pump-app/cc13x4_26x4/main/include/AppTask.h index 7fd3f38ff6f0d5..47b4fd56f2d671 100644 --- a/examples/pump-app/cc13x4_26x4/main/include/AppTask.h +++ b/examples/pump-app/cc13x4_26x4/main/include/AppTask.h @@ -31,6 +31,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + struct Identify; class AppTask @@ -79,6 +83,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn b/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn index 8d0d2d4c72d612..fb118046b876c4 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn @@ -90,6 +90,10 @@ ti_simplelink_executable("pump_controller_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${project_dir}/main", diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni b/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni index fb13057bc99474..d78851719f1fb5 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni @@ -47,3 +47,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8011" matter_software_ver = "0x0001" matter_software_ver_str = "1.0d1" + +custom_factory_data = true diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp index cc59f4daee7b26..0650341acbc081 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -176,19 +176,25 @@ int AppTask::Init() ; } - // Init ZCL Data Model and start server - PLAT_LOG("Initialize Server"); - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - chip::Server::GetInstance().Init(initParams); - // Initialize device attestation config #ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#endif #else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); #endif + // Init ZCL Data Model and start server + PLAT_LOG("Initialize Server"); + static chip::CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + chip::Server::GetInstance().Init(initParams); + // Initialize LEDs PLAT_LOG("Initialize LEDs"); LED_init(); diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppTask.h b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppTask.h index bf13d20bca6ee6..bb815585471add 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppTask.h +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppTask.h @@ -31,6 +31,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + struct Identify; class AppTask @@ -74,6 +78,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/pump-controller-app/cc13x4_26x4/BUILD.gn b/examples/pump-controller-app/cc13x4_26x4/BUILD.gn index 95fa5205a3dd67..c1b106f0feb1c2 100644 --- a/examples/pump-controller-app/cc13x4_26x4/BUILD.gn +++ b/examples/pump-controller-app/cc13x4_26x4/BUILD.gn @@ -98,6 +98,10 @@ ti_simplelink_executable("pump_controller_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "${project_dir}", "${project_dir}/main", diff --git a/examples/pump-controller-app/cc13x4_26x4/args.gni b/examples/pump-controller-app/cc13x4_26x4/args.gni index 375ff1b7b08ffb..e2beed52434bcf 100644 --- a/examples/pump-controller-app/cc13x4_26x4/args.gni +++ b/examples/pump-controller-app/cc13x4_26x4/args.gni @@ -48,3 +48,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8011" matter_software_ver = "0x0001" matter_software_ver_str = "1.0.1+1" + +custom_factory_data = true diff --git a/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp b/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp index b51878e64651b6..a8a61bda096d22 100644 --- a/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp +++ b/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp @@ -176,19 +176,25 @@ int AppTask::Init() ; } - // Init ZCL Data Model and start server - PLAT_LOG("Initialize Server"); - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - chip::Server::GetInstance().Init(initParams); - // Initialize device attestation config #ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); +#endif #else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); #endif + // Init ZCL Data Model and start server + PLAT_LOG("Initialize Server"); + static chip::CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + chip::Server::GetInstance().Init(initParams); + // Initialize LEDs PLAT_LOG("Initialize LEDs"); LED_init(); diff --git a/examples/pump-controller-app/cc13x4_26x4/main/include/AppTask.h b/examples/pump-controller-app/cc13x4_26x4/main/include/AppTask.h index bf13d20bca6ee6..bb815585471add 100644 --- a/examples/pump-controller-app/cc13x4_26x4/main/include/AppTask.h +++ b/examples/pump-controller-app/cc13x4_26x4/main/include/AppTask.h @@ -31,6 +31,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + struct Identify; class AppTask @@ -74,6 +78,10 @@ class AppTask bool mFunctionTimerActive; static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/shell/cc13x2x7_26x2x7/BUILD.gn b/examples/shell/cc13x2x7_26x2x7/BUILD.gn index 45351e854e6150..5264bd079c02b0 100644 --- a/examples/shell/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/shell/cc13x2x7_26x2x7/BUILD.gn @@ -99,6 +99,10 @@ ti_simplelink_executable("shell_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "include", "main", diff --git a/examples/shell/cc13x2x7_26x2x7/args.gni b/examples/shell/cc13x2x7_26x2x7/args.gni index 92dd1dcdfdd0b2..7a2a55a580dd24 100644 --- a/examples/shell/cc13x2x7_26x2x7/args.gni +++ b/examples/shell/cc13x2x7_26x2x7/args.gni @@ -50,3 +50,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" matter_software_ver_str = "1.0d1" + +custom_factory_data = true diff --git a/examples/shell/cc13x2x7_26x2x7/include/AppTask.h b/examples/shell/cc13x2x7_26x2x7/include/AppTask.h index 3fe4f972427717..e9426478b5af61 100644 --- a/examples/shell/cc13x2x7_26x2x7/include/AppTask.h +++ b/examples/shell/cc13x2x7_26x2x7/include/AppTask.h @@ -27,6 +27,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + class AppTask { public: @@ -39,6 +43,10 @@ class AppTask CHIP_ERROR Init(); static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp index 0c30a0e34c55fb..701e86fed40e05 100644 --- a/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp @@ -144,19 +144,24 @@ CHIP_ERROR AppTask::Init() while (true) ; } - - // Init ZCL Data Model and start server - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - chip::Server::GetInstance().Init(initParams); - // Initialize device attestation config #ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#endif #else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); #endif + // Init ZCL Data Model and start server + static chip::CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + chip::Server::GetInstance().Init(initParams); + #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR InitializeOTARequestor(); #endif diff --git a/examples/shell/cc13x4_26x4/BUILD.gn b/examples/shell/cc13x4_26x4/BUILD.gn index 1b950f20f1d9bc..e6db696baa649c 100644 --- a/examples/shell/cc13x4_26x4/BUILD.gn +++ b/examples/shell/cc13x4_26x4/BUILD.gn @@ -98,6 +98,10 @@ ti_simplelink_executable("shell_app") { deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] } + if (custom_factory_data) { + defines = [ "CC13XX_26XX_FACTORY_DATA" ] + } + include_dirs = [ "include", "main", diff --git a/examples/shell/cc13x4_26x4/args.gni b/examples/shell/cc13x4_26x4/args.gni index 13e622146a320e..6726b735b8e43a 100644 --- a/examples/shell/cc13x4_26x4/args.gni +++ b/examples/shell/cc13x4_26x4/args.gni @@ -49,3 +49,5 @@ matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" matter_software_ver_str = "1.0.1+1" + +custom_factory_data = true diff --git a/examples/shell/cc13x4_26x4/include/AppTask.h b/examples/shell/cc13x4_26x4/include/AppTask.h index 3fe4f972427717..e9426478b5af61 100644 --- a/examples/shell/cc13x4_26x4/include/AppTask.h +++ b/examples/shell/cc13x4_26x4/include/AppTask.h @@ -27,6 +27,10 @@ #include +#ifdef CC13XX_26XX_FACTORY_DATA +#include +#endif + class AppTask { public: @@ -39,6 +43,10 @@ class AppTask CHIP_ERROR Init(); static AppTask sAppTask; + +#ifdef CC13XX_26XX_FACTORY_DATA + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; +#endif }; inline AppTask & GetAppTask(void) diff --git a/examples/shell/cc13x4_26x4/main/AppTask.cpp b/examples/shell/cc13x4_26x4/main/AppTask.cpp index 1ae57e8cc471b8..2c6aadaef69772 100644 --- a/examples/shell/cc13x4_26x4/main/AppTask.cpp +++ b/examples/shell/cc13x4_26x4/main/AppTask.cpp @@ -150,18 +150,24 @@ CHIP_ERROR AppTask::Init() ; } - // Init ZCL Data Model and start server - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - chip::Server::GetInstance().Init(initParams); - // Initialize device attestation config #ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS +#ifdef CC13XX_26XX_FACTORY_DATA + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); +#else SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); +#endif #else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); #endif + // Init ZCL Data Model and start server + static chip::CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + chip::Server::GetInstance().Init(initParams); + #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR InitializeOTARequestor(); #endif diff --git a/scripts/setup/requirements.ti.txt b/scripts/setup/requirements.ti.txt index 07f5e30471f1c1..7a6b48fb896bef 100644 --- a/scripts/setup/requirements.ti.txt +++ b/scripts/setup/requirements.ti.txt @@ -3,3 +3,5 @@ click cryptography>=2.6 ecdsa>=0.17.0 intelhex +jsonschema +ecdsa \ No newline at end of file diff --git a/src/platform/cc13xx_26xx/FactoryDataProvider.cpp b/src/platform/cc13xx_26xx/FactoryDataProvider.cpp new file mode 100644 index 00000000000000..695d7e5f757f39 --- /dev/null +++ b/src/platform/cc13xx_26xx/FactoryDataProvider.cpp @@ -0,0 +1,333 @@ +/* + * + * Copyright (c) 2023 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 "FactoryDataProvider.h" +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +typedef struct +{ + uint32_t len; + uint8_t * data; +} data_ptr; + +typedef struct +{ + data_ptr serial_number; + data_ptr vendor_id; + data_ptr product_id; + data_ptr vendor_name; + data_ptr product_name; + data_ptr manufacturing_date; + data_ptr hw_ver; + data_ptr hw_ver_str; + data_ptr dac_cert; + data_ptr dac_priv_key; + data_ptr pai_cert; + data_ptr rd_uniqueid; + data_ptr spake2p_it; + data_ptr spake2p_salt; + data_ptr spake2p_verifier; + data_ptr discriminator; + data_ptr passcode; +} factoryData; + +#if defined(__GNUC__) +factoryData __attribute__((section(".factory_data_struct"))) __attribute__((used)) mFactoryData = +#else + +#error "compiler currently not supported" + +#endif + {}; + +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); +} + +CHIP_ERROR FactoryDataProvider::Init() +{ + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::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 FactoryDataProvider::GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) +{ + out_firmware_info_buffer.reduce_size(0); + + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetDeviceAttestationCert(MutableByteSpan & outBuffer) +{ + ReturnErrorCodeIf(outBuffer.size() < mFactoryData.dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(outBuffer.data(), mFactoryData.dac_cert.data, mFactoryData.dac_cert.len); + outBuffer.reduce_size(mFactoryData.dac_cert.len); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::GetProductAttestationIntermediateCert(MutableByteSpan & outBuffer) +{ + ReturnErrorCodeIf(outBuffer.size() < mFactoryData.pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(outBuffer.data(), mFactoryData.pai_cert.data, mFactoryData.pai_cert.len); + outBuffer.reduce_size(mFactoryData.pai_cert.len); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & messageToSign, MutableByteSpan & outSignBuffer) +{ + Crypto::P256ECDSASignature signature; + Crypto::P256Keypair keypair; + + VerifyOrReturnError(IsSpanUsable(outSignBuffer), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(IsSpanUsable(messageToSign), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(outSignBuffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL); + + // Extract public key from DAC cert. + uint8_t dacBuf[600] = { 0 }; + MutableByteSpan dacCertSpan(dacBuf); + ReturnErrorCodeIf(dacCertSpan.size() < mFactoryData.dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(dacCertSpan.data(), mFactoryData.dac_cert.data, mFactoryData.dac_cert.len); + dacCertSpan.reduce_size(mFactoryData.dac_cert.len); + chip::Crypto::P256PublicKey dacPublicKey; + + ReturnErrorOnFailure(chip::Crypto::ExtractPubkeyFromX509Cert(dacCertSpan, dacPublicKey)); + + uint8_t privKeyBuf[600] = { 0 }; + MutableByteSpan privKeySpan(privKeyBuf); + ReturnErrorCodeIf(privKeySpan.size() < mFactoryData.dac_priv_key.len, CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(privKeySpan.data(), mFactoryData.dac_priv_key.data, mFactoryData.dac_priv_key.len); + privKeySpan.reduce_size(mFactoryData.dac_priv_key.len); + + uint8_t pubKeyBuf[600] = { 0 }; + MutableByteSpan pubKeySpan(pubKeyBuf); + ReturnErrorCodeIf(pubKeySpan.size() < dacPublicKey.Length(), CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(pubKeySpan.data(), dacPublicKey.Bytes(), dacPublicKey.Length()); + pubKeySpan.reduce_size(dacPublicKey.Length()); + + ReturnErrorOnFailure(LoadKeypairFromRaw(privKeySpan, pubKeySpan, keypair)); + ReturnErrorOnFailure(keypair.ECDSA_sign_msg(messageToSign.data(), messageToSign.size(), signature)); + + return CopySpanToMutableSpan(ByteSpan{ signature.ConstBytes(), signature.Length() }, outSignBuffer); +} +CHIP_ERROR FactoryDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator) +{ + ReturnErrorCodeIf(sizeof(setupDiscriminator) < mFactoryData.discriminator.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.discriminator.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(&setupDiscriminator, mFactoryData.discriminator.data, mFactoryData.discriminator.len); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::SetSetupDiscriminator(uint16_t setupDiscriminator) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} +CHIP_ERROR FactoryDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount) +{ + ReturnErrorCodeIf(sizeof(iterationCount) < mFactoryData.spake2p_it.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.spake2p_it.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memset(&iterationCount, 0, sizeof(iterationCount)); + memcpy(&iterationCount, mFactoryData.spake2p_it.data, mFactoryData.spake2p_it.len); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) +{ + ReturnErrorCodeIf(saltBuf.size() < mFactoryData.spake2p_salt.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.spake2p_salt.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(saltBuf.data(), mFactoryData.spake2p_salt.data, mFactoryData.spake2p_salt.len); + saltBuf.reduce_size(mFactoryData.spake2p_salt.len); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) +{ + ReturnErrorCodeIf(verifierBuf.size() < mFactoryData.spake2p_verifier.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.spake2p_verifier.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(verifierBuf.data(), mFactoryData.spake2p_verifier.data, mFactoryData.spake2p_verifier.len); + verifierLen = mFactoryData.spake2p_verifier.len; + verifierBuf.reduce_size(verifierLen); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetSetupPasscode(uint32_t & setupPasscode) +{ + ReturnErrorCodeIf(sizeof(setupPasscode) < mFactoryData.passcode.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.passcode.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(&setupPasscode, mFactoryData.passcode.data, mFactoryData.passcode.len); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::SetSetupPasscode(uint32_t setupPasscode) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} +CHIP_ERROR FactoryDataProvider::GetVendorName(char * buf, size_t bufSize) +{ + ReturnErrorCodeIf(bufSize < mFactoryData.vendor_name.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.vendor_name.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(buf, mFactoryData.vendor_name.data, mFactoryData.vendor_name.len); + buf[mFactoryData.vendor_name.len] = '\0'; + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetVendorId(uint16_t & vendorId) +{ + ReturnErrorCodeIf(sizeof(vendorId) < mFactoryData.vendor_id.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.vendor_id.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(&vendorId, mFactoryData.vendor_id.data, mFactoryData.vendor_id.len); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetProductName(char * buf, size_t bufSize) +{ + ReturnErrorCodeIf(bufSize < mFactoryData.product_name.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.product_name.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memset(buf, 0, bufSize); + memcpy(buf, mFactoryData.product_name.data, mFactoryData.product_name.len); + buf[mFactoryData.product_name.len] = '\0'; + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetProductId(uint16_t & productId) +{ + ReturnErrorCodeIf(sizeof(productId) < mFactoryData.product_id.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.product_id.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(&productId, mFactoryData.product_id.data, mFactoryData.product_id.len); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} +CHIP_ERROR FactoryDataProvider::GetProductURL(char * buf, size_t bufSize) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} +CHIP_ERROR FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize) +{ + ReturnErrorCodeIf(bufSize < mFactoryData.serial_number.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.serial_number.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memset(buf, 0, bufSize); + memcpy(buf, mFactoryData.serial_number.data, mFactoryData.serial_number.len); + buf[mFactoryData.serial_number.len] = '\0'; + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) +{ + ReturnErrorCodeIf(!mFactoryData.manufacturing_date.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + uint8_t tmp[10] = { 0 }; + memcpy(tmp, mFactoryData.manufacturing_date.data, 10); + year = ((tmp[0] - 0x30) * 1000) + ((tmp[1] - 0x30) * 100) + ((tmp[2] - 0x30) * 10) + (tmp[3] - 0x30); + month = ((tmp[5] - 0x30) * 10) + (tmp[6] - 0x30); + day = ((tmp[8] - 0x30) * 10) + (tmp[9] - 0x30); + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion) +{ + ReturnErrorCodeIf(sizeof(hardwareVersion) < mFactoryData.hw_ver.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.hw_ver.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(&hardwareVersion, mFactoryData.hw_ver.data, mFactoryData.hw_ver.len); + return CHIP_NO_ERROR; +} +CHIP_ERROR FactoryDataProvider::GetHardwareVersionString(char * buf, size_t bufSize) +{ + ReturnErrorCodeIf(bufSize < mFactoryData.hw_ver_str.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.hw_ver_str.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memset(buf, 0, bufSize); + memcpy(buf, mFactoryData.hw_ver_str.data, mFactoryData.hw_ver_str.len); + buf[mFactoryData.hw_ver_str.len] = '\0'; + + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) +{ + ReturnErrorCodeIf(uniqueIdSpan.size() < mFactoryData.rd_uniqueid.len, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(!mFactoryData.rd_uniqueid.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + memcpy(uniqueIdSpan.data(), mFactoryData.rd_uniqueid.data, mFactoryData.rd_uniqueid.len); + uniqueIdSpan.reduce_size(mFactoryData.rd_uniqueid.len); + + return CHIP_NO_ERROR; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/FactoryDataProvider.h b/src/platform/cc13xx_26xx/FactoryDataProvider.h new file mode 100644 index 00000000000000..c84d28ac665915 --- /dev/null +++ b/src/platform/cc13xx_26xx/FactoryDataProvider.h @@ -0,0 +1,69 @@ +/* + * + * Copyright (c) 2023 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 +#include +#include + +namespace chip { +namespace DeviceLayer { +class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentialsProvider, + public CommissionableDataProvider, + public DeviceInstanceInfoProvider +{ + +public: + static FactoryDataProvider & GetDefaultInstance(); + + FactoryDataProvider() {} + CHIP_ERROR Init(); + + // ===== Members functions that implement the DeviceAttestationCredentialsProvider + CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & outBuffer) override; + CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override; + CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & outBuffer) override; + CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & outBuffer) override; + CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & messageToSign, MutableByteSpan & outSignBuffer) override; + + // ===== Members functions that implement the CommissionableDataProvider + CHIP_ERROR GetSetupDiscriminator(uint16_t & setupDiscriminator) override; + CHIP_ERROR SetSetupDiscriminator(uint16_t setupDiscriminator) override; + CHIP_ERROR GetSpake2pIterationCount(uint32_t & iterationCount) override; + CHIP_ERROR GetSpake2pSalt(MutableByteSpan & saltBuf) override; + CHIP_ERROR GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) override; + CHIP_ERROR GetSetupPasscode(uint32_t & setupPasscode) override; + CHIP_ERROR SetSetupPasscode(uint32_t setupPasscode) override; + + // ===== Members functions that implement the DeviceInstanceInfoProvider + CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override; + CHIP_ERROR GetVendorId(uint16_t & vendorId) override; + CHIP_ERROR GetProductName(char * buf, size_t bufSize) override; + CHIP_ERROR GetProductId(uint16_t & productId) override; + CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override; + CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override; + CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override; + CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override; + CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override; + CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override; + CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override; + CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override; +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn b/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn index ff746181a7f632..e0005c9fb2b9dd 100644 --- a/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn @@ -16,6 +16,8 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/platform/device.gni") +import("../factory_data_config.gni") + assert(chip_device_platform == "cc13x2_26x2") if (chip_enable_openthread) { @@ -48,6 +50,12 @@ static_library("cc13x2_26x2") { deps = [ "${chip_root}/src/platform/logging:headers" ] + public = [ + "${chip_root}/src/credentials/CHIPCert.h", + "${chip_root}/src/credentials/CertificationDeclaration.h", + "${chip_root}/src/credentials/DeviceAttestationCredsProvider.h", + ] + public_deps = [ "${chip_root}/src/crypto", "${chip_root}/src/platform:platform_base", @@ -60,6 +68,12 @@ static_library("cc13x2_26x2") { ] } + if (custom_factory_data) { + sources += [ + "../FactoryDataProvider.cpp", + "../FactoryDataProvider.h", + ] + } if (chip_enable_ota_requestor) { sources += [ # this needs to be in the final link to place the data correctly diff --git a/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota_factory_data.lds b/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota_factory_data.lds new file mode 100644 index 00000000000000..3f0905e0a3135a --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota_factory_data.lds @@ -0,0 +1,294 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * Copyright (c) 2020 Texas Instruments Incorporated + * + * 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. + */ + +/** + * @file + * Linkerscript for Matter executable with space reserved for the TI BIM. + */ + +STACKSIZE = 0x800; +RESERVED_RAM_SIZE_BLE_ROM = 0x00000FDF; + + +MEMORY +{ + /* last two pages removed for BIM, Flash Bootloader, and Factory Data. CCFG is supplied by the BIM project */ + /* FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x000affa8 */ + /* FLASH_CCFG (RX) : ORIGIN = 0x000affa8, LENGTH = 0x00000058 */ + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x000ac000 + FLASH_FACTORY_DATA (R) : ORIGIN = 0x000ac000, LENGTH = 0x00000900 + /* BLE ROM reserves RAM at the beginning of the ram image, size RESERVED_RAM_SIZE_BLE_ROM */ + /* SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00024000 */ + SRAM (RWX) : ORIGIN = 0x20000FDF, LENGTH = 0x00023021 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : ORIGIN = 0x90000000, LENGTH = 0x40000 +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_FACTORY_DATA", FLASH_FACTORY_DATA); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_LOG", LOG_DATA); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + /* BIM header placed at the base of flash by default */ + PROVIDE (_img_header_base_address = + DEFINED(_img_header_base_address) ? _img_header_base_address : 0x0); + + .oad_image_header (_img_header_base_address) : AT (_img_header_base_address) { + KEEP (*(.oad_image_header)) + } > REGION_TEXT + + /* interrupt vectors shifted to accommodate BIM header */ + PROVIDE (_intvecs_base_address = + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x100); + + .resetVecs (_intvecs_base_address) : AT (_intvecs_base_address) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + PROVIDE (_vtable_base_address = + DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000 + RESERVED_RAM_SIZE_BLE_ROM); + + .ramVecs (_vtable_base_address) (NOLOAD) : { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* Define base address for the DAC arrays and struct */ + PROVIDE (_factory_data_base_address = + DEFINED(_factory_data_base_address) ? _factory_data_base_address : 0xAC000); + + .factory_data(_factory_data_base_address) : AT (_factory_data_base_address) { + KEEP (*(.factory_data_struct)) + } > REGION_FACTORY_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_1800, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20001800; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * --------- DO NOT MODIFY ----------- + */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); + DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); + DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); + DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); + DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); + DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); + DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); + DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); + + /* + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0APriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; + .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; + .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0AAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxAltControlTableEntry_is_placed = 0; + .dmaSpi1RxAltControlTableEntry DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxAltControlTableEntry_is_placed = 0; + .dmaSpi1TxAltControlTableEntry DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxAltControlTableEntry)} > REGION_DATA + + + + /* if a ROM-only symbol is present, then ROM is being used. + * Reserve memory for surgically placed config constants. + */ + _rom_rodata_start = 0x2000; + _rom_rodata_size = DEFINED(ROM_RODATA_SIZE) ? 0 : DEFINED(ROM_RODATA_SIZE_NO_OAD) ? 0x330 : 0; + + .rom_rodata_reserve (_rom_rodata_start): { + . += _rom_rodata_size; + } > REGION_TEXT AT> REGION_TEXT + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + *(.rodata_*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(4) { + __data_load__ = LOADADDR (.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + /* End of executable code/data, NVS is not part of the OTA image */ + PROVIDE (_flash_end_address = .); + + .nvs (0xA8000) (NOLOAD) : AT (0xA0000) ALIGN(0x2000) { + *(.nvs) + } > REGION_TEXT + + /* CCFG is supplied by the BIM project */ + /* + .ccfg : { + KEEP (*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + */ + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN (4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + .heap : { + __heap_start__ = .; + end = __heap_start__; + _end = end; + __end = end; + KEEP(*(.heap)) + __heap_end__ = .; + __HeapLimit = __heap_end__; + } > REGION_HEAP AT> REGION_HEAP + + .stack (NOLOAD) : ALIGN(0x8) { + _stack = .; + __stack = .; + KEEP(*(.stack)) + . += STACKSIZE; + _stack_end = .; + __stack_end = .; + } > REGION_STACK AT> REGION_STACK + + .log_data (COPY) : { + KEEP (*(.log_data)) + } > REGION_LOG +} + +ENTRY(resetISR) diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn b/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn index 414e7b1d78bcdc..0c62b3855ad353 100644 --- a/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn @@ -16,6 +16,8 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/platform/device.gni") +import("../factory_data_config.gni") + assert(chip_device_platform == "cc13x4_26x4") if (chip_enable_openthread) { @@ -48,6 +50,12 @@ static_library("cc13x4_26x4") { deps = [ "${chip_root}/src/platform/logging:headers" ] + public = [ + "${chip_root}/src/credentials/CHIPCert.h", + "${chip_root}/src/credentials/CertificationDeclaration.h", + "${chip_root}/src/credentials/DeviceAttestationCredsProvider.h", + ] + public_deps = [ "${chip_root}/src/crypto", "${chip_root}/src/platform:platform_base", @@ -60,6 +68,13 @@ static_library("cc13x4_26x4") { ] } + if (custom_factory_data) { + sources += [ + "../FactoryDataProvider.cpp", + "../FactoryDataProvider.h", + ] + } + if (chip_enable_ota_requestor) { sources += [ "OTAImageProcessorImpl.cpp" ] } diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds index 52e08615592fed..f639f640d2414d 100644 --- a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds @@ -256,4 +256,4 @@ SECTIONS { } > REGION_LOG } -ENTRY(resetISR) +ENTRY(resetISR) \ No newline at end of file diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_factory_data.lds b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_factory_data.lds new file mode 100644 index 00000000000000..c082497d88429e --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_factory_data.lds @@ -0,0 +1,269 @@ +/* + * + * 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. + */ + +/** + * @file + * Linkerscript for a non-OTA Matter executable. + */ + +STACKSIZE = 0x2000; + +MEMORY +{ + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x000FE800 + FLASH_FACTORY_DATA (R) : ORIGIN = 0x000FE800, LENGTH = 0x900 + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash + */ + FLASH_CCFG (RX) : ORIGIN = 0x50000000, LENGTH = 0x00000800 + SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00040000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : ORIGIN = 0x90000000, LENGTH = 0x40000 +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_FACTORY_DATA", FLASH_FACTORY_DATA); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_LOG", LOG_DATA); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + PROVIDE (_intvecs_base_address = + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x00); + + .resetVecs (_intvecs_base_address) : AT (_intvecs_base_address) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + PROVIDE (_vtable_base_address = + DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000); + + .vtable (_vtable_base_address) (NOLOAD) : { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* Define base address for the DAC arrays and struct */ + PROVIDE (_factory_data_base_address = + DEFINED(_factory_data_base_address) ? _factory_data_base_address : 0xFE800); + + .factory_data(_factory_data_base_address) : AT (_factory_data_base_address) { + KEEP (*(.factory_data_struct)) + } > REGION_FACTORY_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_0400, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20000400; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * --------- DO NOT MODIFY ----------- + */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); + DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); + DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); + DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); + DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); + DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); + DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); + DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); + + /* + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0APriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; + .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; + .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0AAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxAltControlTableEntry_is_placed = 0; + .dmaSpi1RxAltControlTableEntry DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxAltControlTableEntry_is_placed = 0; + .dmaSpi1TxAltControlTableEntry DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxAltControlTableEntry)} > REGION_DATA + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + *(.rodata_*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(4) { + __data_load__ = LOADADDR (.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + /* End of executable code/data, NVS is not part of the OTA image */ + PROVIDE (_flash_end_address = .); + + /* 5 pages of NV Memory (0x800 each) offset by 1 page for BIM/CCFG */ + /*.nvs (NOLOAD) : ALIGN(0x2000) { */ + .nvs (0xFB000) (NOLOAD) : AT (0xFB000) ALIGN(0x800) { + *(.nvs) + } > REGION_TEXT + + .ccfg : { + KEEP (*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN (4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + .heap : { + __heap_start__ = .; + end = __heap_start__; + _end = end; + __end = end; + KEEP(*(.heap)) + __heap_end__ = .; + __HeapLimit = __heap_end__; + } > REGION_HEAP AT> REGION_HEAP + + .stack (NOLOAD) : ALIGN(0x8) { + _stack = .; + __stack = .; + KEEP(*(.stack)) + . += STACKSIZE; + _stack_end = .; + __stack_end = .; + } > REGION_STACK AT> REGION_STACK + + .log_data (COPY) : { + KEEP (*(.log_data)) + } > REGION_LOG +} + +ENTRY(resetISR) diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota_factory_data.lds b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota_factory_data.lds new file mode 100644 index 00000000000000..1228a3cc38d3e0 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota_factory_data.lds @@ -0,0 +1,280 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * Copyright (c) 2020 Texas Instruments Incorporated + * + * 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. + */ + +/** + * @file + * Linkerscript for Matter executable with space reserved for MCUBoot. + */ + +STACKSIZE = 0x2000; + +MEMORY +{ + MCUBOOT_HDR (RX) : ORIGIN = 0x00006000, LENGTH = 0x00000080 + FLASH (RX) : ORIGIN = 0x00006080, LENGTH = 0x000F8780 + /* + * NVS is the last 5 pages of slot, this area is not erased + * during OTA. The slot size for the primary and secondary slots + * is therefore 0xF6000 (MCUBoot Header + all the remaining space) + */ + /* FLASH_NVS (RX) : ORIGIN = 0x000FC000, LENGTH = 0x00002800 */ + FLASH_FACTORY_DATA (R) : ORIGIN = 0x000FE800, LENGTH = 0x900 + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash + */ + /* FLASH_CCFG (RX) : ORIGIN = 0x50000000, LENGTH = 0x00000800 */ + SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00040000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : ORIGIN = 0x90000000, LENGTH = 0x40000 +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_FACTORY_DATA", FLASH_FACTORY_DATA); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_LOG", LOG_DATA); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + /* interrupt vectors shifted to accommodate MCUBoot header */ + PROVIDE (_intvecs_base_address = + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x6080); + + .resetVecs (_intvecs_base_address) : AT (_intvecs_base_address) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + PROVIDE (_vtable_base_address = + DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000); + + .vtable (_vtable_base_address) (NOLOAD) : { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* Define base address for the Factory Data arrays and struct */ + PROVIDE (_factory_data_base_address = + DEFINED(_factory_data_base_address) ? _factory_data_base_address : 0xFE800); + + .factory_data(_factory_data_base_address) : AT (_factory_data_base_address) { + KEEP (*(.factory_data_struct)) + } > REGION_FACTORY_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_0400, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20000400; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * --------- DO NOT MODIFY ----------- + */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); + DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); + DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); + DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); + DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); + DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); + DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); + DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); + + /* + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0APriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; + .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; + .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0AAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxAltControlTableEntry_is_placed = 0; + .dmaSpi1RxAltControlTableEntry DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxAltControlTableEntry_is_placed = 0; + .dmaSpi1TxAltControlTableEntry DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxAltControlTableEntry)} > REGION_DATA + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + *(.rodata_*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(4) { + __data_load__ = LOADADDR (.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + /* End of executable code/data, NVS is not part of the OTA image */ + PROVIDE (_flash_end_address = .); + + /* 5 pages of NV Memory (0x800 each) at the end of Flash */ + .nvs (0xFC000) (NOLOAD) : AT (0xFC000) ALIGN(0x800) { + *(.nvs) + } > REGION_TEXT + + /* CCFG is supplied by the MCUBoot project */ + /* + .ccfg : { + KEEP (*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + */ + + .bss (NOLOAD) : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN (4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + .heap (NOLOAD) : { + __heap_start__ = .; + end = __heap_start__; + _end = end; + __end = end; + KEEP(*(.heap)) + __heap_end__ = .; + __HeapLimit = __heap_end__; + } > REGION_HEAP AT> REGION_HEAP + + .stack (NOLOAD) : ALIGN(0x8) { + _stack = .; + __stack = .; + KEEP(*(.stack)) + . += STACKSIZE; + _stack_end = .; + __stack_end = .; + } > REGION_STACK AT> REGION_STACK + + .log_data (COPY) : { + KEEP (*(.log_data)) + } > REGION_LOG +} + +ENTRY(resetISR) diff --git a/src/platform/cc13xx_26xx/factory_data.schema b/src/platform/cc13xx_26xx/factory_data.schema new file mode 100644 index 00000000000000..62331d3fa47a25 --- /dev/null +++ b/src/platform/cc13xx_26xx/factory_data.schema @@ -0,0 +1,100 @@ +{ + "$id": "TI_Factory_Data_schema", + "$schema": "https://example.com/employee.schema.json", + "description": "A representation of all factory data used in TI Matter devices", + "type": "object", + "properties": { + "elements": { + "type": "array", + "items":{ + "description":"Factory data elements", + "type": "object", + "properties": { + "serial_number": { + "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 + }, + "manufacturing_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": 65535 + }, + "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": 36, + "maxLength": 68 + }, + "dac_cert": { + "description": "DAC certificate string", + "type": "string" + }, + "dac_priv_key": { + "description": "DAC private key string", + "type": "string" + }, + "pai_cert": { + "description": "PAI certificate string", + "type": "string" + }, + "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}){16,}$" + }, + "spake2_verifier": { + "description": "A verifier for the Symmetric Password-Authenticated Key Exchange", + "type": "string", + "pattern": "^hex:([0-9A-Fa-f]{2}){16,}$" + } + } + } + } + } +} + diff --git a/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json b/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json new file mode 100644 index 00000000000000..1dc884cc5a23b6 --- /dev/null +++ b/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json @@ -0,0 +1,72 @@ +{ + "elements": [ + { + "serial_number": "1234567890", + "len": 10 + }, + { + "vendor_id": 65521, + "len": 2 + }, + { + "product_id": 32778, + "len": 2 + }, + { + "vendor_name": "Texas Instruments", + "len": 17 + }, + { + "product_name": "PumpApp", + "len": 7 + }, + { + "manufacturing_date": "2023-07-05", + "len": 10 + }, + { + "hw_ver": 1234, + "len": 2 + }, + { + "hw_ver_str": "1234", + "len": 4 + }, + { + "dac_cert": "hex:308201f73082019da00302010202084688eb94ad32b2e4300a06082a8648ce3d040302304d311f301d06035504030c164d617474657220446576656c6f706d656e742050414931143012060a2b0601040182a27c02010c044646463131143012060a2b0601040182a27c02020c04383030363020170d3231303632383134323334335a180f39393939313233313233353935395a30523124302206035504030c1b4d617474657220446576656c6f706d656e7420444143203030303031143012060a2b0601040182a27c02010c044646463131143012060a2b0601040182a27c02020c04383030363059301306072a8648ce3d020106082a8648ce3d03010703420004c565fdadfd16dd62e43f1960b993bb572cfdd81f6d7167671b7745dcbe6f65af665a1d931c05b9f9a3e9456685602c05c69646b8f75998dbaa687a5c564902daa360305e300c0603551d130101ff04023000300e0603551d0f0101ff040403020780301d0603551d0e041604149b40606f9e047fb860788e3dc112d75e87957768301f0603551d2304183016801443345712ba2c87ef25497b11d798589b84357f88300a06082a8648ce3d0403020348003045022100b928f93ee387ef3e0072882284bd8add5cd6d05581bfcc5517cf9e9bcdd437da022010079ccf7f1f2dda46ace967ae5be966e7f28adfa028b8f87f939ed4158dc0f8", + "len": 507 + }, + { + "dac_priv_key": "hex:505a211dbda871330d635da3b07eb1c5088a8fc70124fbb33e93d5060582c7c5", + "len": 32 + }, + { + "pai_cert": "hex:308201dc30820181a00302010202087f7ef3db08a38f68300a06082a8648ce3d04030230303118301606035504030c0f4d617474657220546573742050414131143012060a2b0601040182a27c02010c04464646313020170d3231303632383134323334335a180f39393939313233313233353935395a304d311f301d06035504030c164d617474657220446576656c6f706d656e742050414931143012060a2b0601040182a27c02010c044646463131143012060a2b0601040182a27c02020c04383030363059301306072a8648ce3d020106082a8648ce3d0301070342000442935577353515cefa8f0e30e2347e90eed6fd515be882d1bcba7483d7ff6ef4dedf98f7f74f17421de5450cfffb3e7f6d4f6228534114fbb85c2d52d182b66aa366306430120603551d130101ff040830060101ff020100300e0603551d0f0101ff040403020106301d0603551d0e0416041443345712ba2c87ef25497b11d798589b84357f88301f0603551d230418301680146afd22771f511fecbf1641976710dcdc31a1717e300a06082a8648ce3d0403020349003046022100ff25f1d154c3137e0e086d82ab0b11b5661839b712b1342c6cde94fbe318a92b02210092e281f98a2fcc14cdf40750d280d7dfea3f4da46f357afeacb89b267706d28a", + "len": 480 + }, + { + "rd_uniqueid": "hex:91a9c12a7c80700a31ddcfa7fce63e44", + "len": 16 + }, + { + "spake2_it": 2000, + "len": 2 + }, + { + "spake2_salt": "hex:5350414b453250204b65792053616c74", + "len": 16 + }, + { + "spake2_verifier": "hex:7d04776bb469c494922830144f3fa2f19cfd82c04d108d8ba6353fdd92c01f9304511b6c4765bab147949dd942c43b3d8dc6323089ca3189d9e4a5636e16d82f1aef728b0d902c1a9b0f7e9652ab7f657861b6bbacd6bfdf04f80709248b83dec7", + "len": 97 + }, + { + "discriminator": 3840, + "len": 2 + }, + { + "passcode": 20202021, + "len": 4 + } + ] +} diff --git a/src/platform/cc13xx_26xx/factory_data_config.gni b/src/platform/cc13xx_26xx/factory_data_config.gni new file mode 100644 index 00000000000000..4f5a1b319256cf --- /dev/null +++ b/src/platform/cc13xx_26xx/factory_data_config.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2020 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() { + custom_factory_data = "" +} diff --git a/third_party/ti_simplelink_sdk/create_factory_data.py b/third_party/ti_simplelink_sdk/create_factory_data.py new file mode 100644 index 00000000000000..224979a9587306 --- /dev/null +++ b/third_party/ti_simplelink_sdk/create_factory_data.py @@ -0,0 +1,164 @@ +#!/usr/bin/env python + +# 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 json +import subprocess + +import intelhex +from jsonschema import validate + + +def create_hex_file(args): + # create empty factory data file + factory_data_intelhex = intelhex.IntelHex() + factory_data_struct_intelhex = intelhex.IntelHex() + + device_family = args.device_family + + # there are 17 elements, each element will need 8 bytes in the struct + # 4 for length of the element, and 4 for the pointer to the element + # factory data starts at 0xAC000 or 0xFE800, so the elements will + # start 136 bytes after the start address + factory_data_dict = json.load(args.factory_data_json_file[0]) + factory_data_schema = json.load(args.factory_data_schema[0]) + + validate(factory_data_dict, factory_data_schema) + factory_data = factory_data_dict['elements'] + + struct_idx = 0 + values_idx = 0 + if device_family == 'cc13x2_26x2': + value_address = 0xAC088 + else: + value_address = 0xFE888 + + for element in factory_data: + # get the length in hex and write to first hex file + len_integer = element['len'] + + factory_data_struct_intelhex[struct_idx + 3] = (len_integer & 0xFF000000) >> 24 + factory_data_struct_intelhex[struct_idx + 2] = (len_integer & 0x00FF0000) >> 16 + factory_data_struct_intelhex[struct_idx + 1] = (len_integer & 0x0000FF00) >> 8 + factory_data_struct_intelhex[struct_idx] = (len_integer & 0x000000FF) + + struct_idx += 4 + + # write the address to the file and increment by the size of the element + factory_data_struct_intelhex[struct_idx + 3] = (value_address & 0xFF000000) >> 24 + factory_data_struct_intelhex[struct_idx + 2] = (value_address & 0x00FF0000) >> 16 + factory_data_struct_intelhex[struct_idx + 1] = (value_address & 0x0000FF00) >> 8 + factory_data_struct_intelhex[struct_idx] = (value_address & 0x000000FF) + + struct_idx += 4 + value_address += len_integer + + # convert the value to hex and write to the second file + key = list(element.keys())[0] + if type(element[key]) == str: + list_value = list(element[key].strip(" ")) + hex_check = ''.join(list_value[0:4]) + if hex_check == "hex:": + list_value = list_value[4:] + idx = 0 + list_len = len(list_value) + while idx < list_len: + hex_list = [] + hex_str_1 = list_value[idx] + + hex_list.append(hex_str_1) + hex_str_2 = list_value[idx+1] + + hex_list.append(hex_str_2) + final_hex_str = ''.join(hex_list) + + factory_data_intelhex[values_idx] = int(final_hex_str, 16) + values_idx += 1 + idx += 2 + else: + for ele in list_value: + factory_data_intelhex[values_idx] = ord(ele) + values_idx += 1 + else: + if key != "spake2_it" and key != "passcode": + factory_data_intelhex[values_idx] = (element[key] & 0x00FF) + factory_data_intelhex[values_idx + 1] = (element[key] & 0xFF00) >> 8 + + values_idx += 2 + elif key == "spake2_it": + if len_integer == 2: + factory_data_intelhex[values_idx] = (element[key] & 0x00FF) + factory_data_intelhex[values_idx + 1] = (element[key] & 0xFF00) >> 8 + + values_idx += 2 + elif len_integer == 3: + factory_data_intelhex[values_idx] = (element[key] & 0x0000FF) + factory_data_intelhex[values_idx + 1] = (element[key] & 0x00FF00) >> 8 + factory_data_intelhex[values_idx + 2] = (element[key] & 0xFF0000) >> 16 + + values_idx += 3 + else: + factory_data_intelhex[values_idx] = (element[key] & 0x000000FF) + factory_data_intelhex[values_idx + 1] = (element[key] & 0x0000FF00) >> 8 + factory_data_intelhex[values_idx + 2] = (element[key] & 0x00FF0000) >> 16 + factory_data_intelhex[values_idx + 3] = (element[key] & 0xFF000000) >> 24 + + values_idx += 4 + else: + factory_data_intelhex[values_idx] = (element[key] & 0x000000FF) + factory_data_intelhex[values_idx + 1] = (element[key] & 0x0000FF00) >> 8 + factory_data_intelhex[values_idx + 2] = (element[key] & 0x00FF0000) >> 16 + factory_data_intelhex[values_idx + 3] = (element[key] & 0xFF000000) >> 24 + + values_idx += 4 + + # merge both hex files + idx = 0 + while idx < values_idx: + factory_data_struct_intelhex[struct_idx] = factory_data_intelhex[idx] + idx = idx + 1 + struct_idx = struct_idx + 1 + + # output to hex file + factory_data_struct_intelhex.tofile(args.factory_data_hex_file, format='hex') + + # get hex file in a format that can be merged in a later step + subprocess.call(['objcopy', args.factory_data_hex_file, '--input-target', 'ihex', '--output-target', 'binary', 'temp.bin']) + if device_family == 'cc13x2_26x2': + subprocess.call(['objcopy', 'temp.bin', '--input-target', 'binary', '--output-target', + 'ihex', args.factory_data_hex_file, '--change-addresses=0xac000']) + else: + subprocess.call(['objcopy', 'temp.bin', '--input-target', 'binary', '--output-target', + 'ihex', args.factory_data_hex_file, '--change-addresses=0xfe800']) + subprocess.call(['rm', 'temp.bin']) + + +def main(): + parser = argparse.ArgumentParser(description="TI Factory Data hex file creator") + + parser.add_argument('-factory_data', '--factory_data_json_file', required=True, nargs=1, + help="JSON file of factory data", type=argparse.FileType('r')) + parser.add_argument('-schema', '--factory_data_schema', required=True, nargs=1, + help="Factory Data Schema", type=argparse.FileType('r')) + parser.add_argument('-o', '--factory_data_hex_file', required=True) + parser.add_argument('-device', '--device_family', required=True) + + args = parser.parse_args() + create_hex_file(args) + + +if __name__ == "__main__": + main() diff --git a/third_party/ti_simplelink_sdk/factory_data_merge_tool.py b/third_party/ti_simplelink_sdk/factory_data_merge_tool.py new file mode 100644 index 00000000000000..af475737a8b254 --- /dev/null +++ b/third_party/ti_simplelink_sdk/factory_data_merge_tool.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +# 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. + +"""Simple hexmerge script for combining the BIM, Factory Data, and App + +This script provides a basic utility to combine the Matter application hex file and Factory Data hex file. The output is a combined hex file that can be programmed on the target and run. + +Run with: + python factory_data_merge_tool.py +""" + +import sys + +import intelhex + +hex_file = sys.argv[1] +factory_data = sys.argv[2] +combined_hex = sys.argv[3] + +# merge matter hex file and factory hex file +matter_hex = intelhex.IntelHex() +matter_hex.fromfile(hex_file, format='hex') + +factory_data_hex = intelhex.IntelHex() +factory_data_hex.fromfile(factory_data, format='hex') + +matter_hex.merge(factory_data_hex, overlap='replace') +matter_hex.tofile(combined_hex, format='hex') diff --git a/third_party/ti_simplelink_sdk/factory_data_trim.py b/third_party/ti_simplelink_sdk/factory_data_trim.py new file mode 100644 index 00000000000000..c38be1f0a0a2ac --- /dev/null +++ b/third_party/ti_simplelink_sdk/factory_data_trim.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +# 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. + +"""Script to extract the factory data content from the matter application + factory data image + +This script will trim the factory data content out of the matter application image. It will also get the length of the factory data from the matter application map file. The output is the Matter image without the dummy factory d. + +Run with: + python factory_data_trim.py +""" + +import itertools +import re +import sys + +import intelhex + +matter_app_file = sys.argv[1] +matter_app_map_file = sys.argv[2] +matter_image_without_factory_data_hex = sys.argv[3] +device_family = sys.argv[4] + +# extract factory data length from map file +with open(matter_app_map_file, "r") as map_file: + if device_family == 'cc13x2_26x2': + pattern = ".factory_data 0x000ac000" + else: + pattern = ".factory_data 0x000fe800" + for line in map_file: + if re.search(pattern, line): + factory_data_num_bytes = line + break + +# this is the length of the factory data in hexadecmial form +factory_data_num_bytes = factory_data_num_bytes[32:] + +# convert hex image to dictionary +matter_image = intelhex.IntelHex() +matter_image.fromfile(matter_app_file, format='hex') +matter_image_dict = matter_image.todict() + +if device_family == 'cc13x2_26x2': + # 704512 is 0xAC000 - start of factory data + start_index = list(matter_image_dict.keys()).index(704512) +else: + # 1042432 is 0xFE800 - start of factory data + start_index = list(matter_image_dict.keys()).index(1042432) +# convert length of factory data into a decimal value +end_index = start_index + int(factory_data_num_bytes, 16) + +# slice dictionary to remove factory data elements +matter_image_dict_first_half = dict(itertools.islice(matter_image_dict.items(), 0, start_index)) +matter_image_dict_second_half = dict(itertools.islice(matter_image_dict.items(), end_index, len(matter_image_dict))) + +# convert sliced dictionary to back to hex +matter_image_without_factory_data_first_half = intelhex.IntelHex() +matter_image_without_factory_data_second_half = intelhex.IntelHex() + +matter_image_without_factory_data_first_half.fromdict(matter_image_dict_first_half) +matter_image_without_factory_data_second_half.fromdict(matter_image_dict_second_half) + +matter_image_without_factory_data_first_half.merge(matter_image_without_factory_data_second_half, overlap='error') + +matter_image_without_factory_data_first_half.tofile(matter_image_without_factory_data_hex, format='hex') diff --git a/third_party/ti_simplelink_sdk/oad_and_factory_data_merge_tool.py b/third_party/ti_simplelink_sdk/oad_and_factory_data_merge_tool.py new file mode 100644 index 00000000000000..d98fc94593dd95 --- /dev/null +++ b/third_party/ti_simplelink_sdk/oad_and_factory_data_merge_tool.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +# 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. + +"""Simple hexmerge script for combining the BIM, Factory Data, and App + +This script provides a basic utility to combine the OAD application binary file with the Boot Image Manager hex file and Factory Data hex file. The output is a combined hex file that can be programmed on the target and run. + +Run with: + python oad_and_factory_data_merge_tool.py +""" + +import sys + +import intelhex + +oad_bin_file = sys.argv[1] +bim_hex_file = sys.argv[2] +factory_data = sys.argv[3] +combined_hex = sys.argv[4] + +# merge binary executable with bim hex file and factory hex file +ota_image = intelhex.IntelHex() +if (oad_bin_file.endswith('hex')): + ota_image.fromfile(oad_bin_file, format='hex') + +else: + ota_image.fromfile(oad_bin_file, format='bin') + +bim_hex = intelhex.IntelHex() +bim_hex.fromfile(bim_hex_file, format='hex') + +factory_data_hex = intelhex.IntelHex() +factory_data_hex.fromfile(factory_data, format='hex') + +ota_image.merge(bim_hex, overlap='error') +ota_image.merge(factory_data_hex, overlap='replace') + +ota_image.tofile(combined_hex, format='hex') diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni index 9cc800e9b1e139..1da4bbb0e76763 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni @@ -17,6 +17,7 @@ import("//build_overrides/chip.gni") import("//build_overrides/ti_simplelink_sdk.gni") import("${build_root}/toolchain/flashable_executable.gni") +import("${chip_root}/src/platform/cc13xx_26xx/factory_data_config.gni") import("${chip_root}/src/platform/device.gni") import("ti_simplelink_board.gni") import("ti_simplelink_sdk.gni") @@ -75,7 +76,11 @@ template("ti_simplelink_executable") { if (chip_enable_ota_requestor) { sources += [ "${chip_root}/src/platform/cc13xx_26xx/oad_image_header.c" ] - ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds" + if (custom_factory_data) { + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota_factory_data.lds" + } else { + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds" + } } else { ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos.lds" } @@ -83,9 +88,17 @@ template("ti_simplelink_executable") { if (chip_enable_ota_requestor) { sources += [ "${chip_root}/src/platform/cc13xx_26xx/oad_image_header.c" ] - ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds" + if (custom_factory_data) { + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota_factory_data.lds" + } else { + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds" + } } else { - ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds" + if (custom_factory_data) { + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_factory_data.lds" + } else { + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds" + } } } else if (ti_simplelink_device_family == "cc32xx") { ldscript = "${ti_simplelink_sdk_root}/source/ti/boards/cc32xxsf/cc32xxsf_freertos.lds" @@ -104,11 +117,67 @@ template("ti_simplelink_executable") { if (chip_enable_ota_requestor) { if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { + if (custom_factory_data) { + pw_python_action("${simplelink_target_name}-without-factory-data.hex") { + public_deps = [ ":${simplelink_target_name}.out.image" ] + + script = "${ti_simplelink_sdk_build_root}/factory_data_trim.py" + sources = [ "${root_out_dir}/${objcopy_image_name}" ] + outputs = + [ "${root_out_dir}/${output_base_name}-without-factory-data.hex" ] + + args = [ + rebase_path("${root_out_dir}/${output_base_name}.hex", + root_out_dir), + rebase_path("${root_out_dir}/${output_base_name}.out.map", + root_out_dir), + rebase_path( + "${root_out_dir}/${output_base_name}-without-factory-data.hex", + root_out_dir), + "cc13x2_26x2", + ] + } + pw_python_action("${simplelink_target_name}-factory-data.hex") { + script = "${ti_simplelink_sdk_build_root}/create_factory_data.py" + sources = [ + "${chip_root}/src/platform/cc13xx_26xx/factory_data.schema", + "${chip_root}/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json", + ] + outputs = [ "${root_out_dir}/${output_base_name}-factory-data.hex" ] + + args = [ + "-factory_data", + rebase_path( + "${chip_root}/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json"), + "-schema", + rebase_path( + "${chip_root}/src/platform/cc13xx_26xx/factory_data.schema"), + "-o", + rebase_path("${root_out_dir}/${output_base_name}-factory-data.hex", + root_out_dir), + "-device", + "cc13x2_26x2", + ] + } + } pw_python_action("${simplelink_target_name}.bin") { - public_deps = [ ":${simplelink_target_name}.out.image" ] + if (custom_factory_data) { + public_deps = + [ ":${simplelink_target_name}-without-factory-data.hex" ] + } else { + public_deps = [ ":${simplelink_target_name}.out.image" ] + } script = "${ti_simplelink_sdk_root}//tools/common/oad/oad_image_tool.py" - sources = [ "${root_out_dir}/${objcopy_image_name}" ] + if (custom_factory_data) { + sources = + [ "${root_out_dir}/${output_base_name}-without-factory-data.hex" ] + input_path = + "${root_out_dir}/${output_base_name}-without-factory-data.hex" + } else { + sources = [ "${root_out_dir}/${objcopy_image_name}" ] + input_path = "${root_out_dir}/${output_base_name}.hex" + } outputs = [ "${root_out_dir}/${output_base_name}.bin" ] args = [ @@ -117,7 +186,7 @@ template("ti_simplelink_executable") { rebase_path(root_out_dir, root_build_dir), "7", "-hex1", - rebase_path("${root_out_dir}/${output_base_name}.hex", root_out_dir), + rebase_path(input_path, root_out_dir), "-o", output_base_name, ] @@ -136,12 +205,22 @@ template("ti_simplelink_executable") { ] } } - action("${simplelink_target_name}-bim.hex") { + pw_python_action("${simplelink_target_name}-bim.hex") { public_deps = [ ":${simplelink_target_name}.bin" ] + if (custom_factory_data) { + public_deps += [ ":${simplelink_target_name}-factory-data.hex" ] - script = "${ti_simplelink_sdk_build_root}/oad_merge_tool.py" - sources = [ "${root_out_dir}/${output_base_name}.bin" ] - outputs = [ "${root_out_dir}/${output_base_name}-bim.hex" ] + script = "${ti_simplelink_sdk_build_root}/oad_and_factory_data_merge_tool.py" + sources = [ + "${root_out_dir}/${output_base_name}-factory-data.hex", + "${root_out_dir}/${output_base_name}.bin", + ] + outputs = [ "${root_out_dir}/${output_base_name}-bim.hex" ] + } else { + script = "${ti_simplelink_sdk_build_root}/oad_merge_tool.py" + sources = [ "${root_out_dir}/${output_base_name}.bin" ] + outputs = [ "${root_out_dir}/${output_base_name}-bim.hex" ] + } if (defined(invoker.bim_hex)) { bim_hex = invoker.bim_hex @@ -149,16 +228,30 @@ template("ti_simplelink_executable") { bim_hex = "${ti_simplelink_sdk_root}/examples/nortos/${ti_simplelink_board}/bim/hexfiles/bim_offchip/Release/bim_offchip.hex" } - args = [ - rebase_path("${root_out_dir}/${output_base_name}.bin", - root_build_dir), - rebase_path(bim_hex, root_build_dir), - rebase_path("${root_out_dir}/${output_base_name}-bim.hex", - root_build_dir), - ] + if (custom_factory_data) { + args = [ + rebase_path("${root_out_dir}/${output_base_name}.bin", + root_build_dir), + rebase_path(bim_hex, root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-factory-data.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-bim.hex", + root_build_dir), + ] + } else { + args = [ + rebase_path("${root_out_dir}/${output_base_name}.bin", + root_build_dir), + rebase_path(bim_hex, root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-bim.hex", + root_build_dir), + ] + } + + args += [ "${root_out_dir}/${output_base_name}-bim.hex" ] } pw_python_action("${target_name}.ota") { - public_deps = [ ":${simplelink_target_name}.bin" ] + public_deps = [ ":${simplelink_target_name}-bim.hex" ] script = "${chip_root}/src/app/ota_image_tool.py" sources = [ "${root_out_dir}/${output_base_name}.bin" ] @@ -187,23 +280,97 @@ template("ti_simplelink_executable") { "-da", matter_ota_digest, ] - } else { + args += [ - "-da", - "sha256", + "-v", + matter_device_vid, + "-p", + matter_device_pid, + "-vn", + matter_software_ver, + "-vs", + matter_software_ver_str, ] - } - if (defined(invoker.ota_args)) { - args += invoker.ota_args + if (defined(invoker.ota_digest)) { + args += [ + "-da", + matter_ota_digest, + ] + } else { + args += [ + "-da", + "sha256", + ] + } + if (defined(invoker.ota_args)) { + args += invoker.ota_args + } } } } else if (ti_simplelink_device_family == "cc13x4_26x4") { + if (custom_factory_data) { + pw_python_action("${simplelink_target_name}-without-factory-data.hex") { + public_deps = [ ":${simplelink_target_name}.out.image" ] + + script = "${ti_simplelink_sdk_build_root}/factory_data_trim.py" + sources = [ "${root_out_dir}/${objcopy_image_name}" ] + outputs = + [ "${root_out_dir}/${output_base_name}-without-factory-data.hex" ] + + args = [ + rebase_path("${root_out_dir}/${output_base_name}.hex", + root_out_dir), + rebase_path("${root_out_dir}/${output_base_name}.out.map", + root_out_dir), + rebase_path( + "${root_out_dir}/${output_base_name}-without-factory-data.hex", + root_out_dir), + "cc13x4_26x4", + ] + } + pw_python_action("${simplelink_target_name}-factory-data.hex") { + script = "${ti_simplelink_sdk_build_root}/create_factory_data.py" + sources = [ + "${chip_root}/src/platform/cc13xx_26xx/factory_data.schema", + "${chip_root}/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json", + ] + outputs = [ "${root_out_dir}/${output_base_name}-factory-data.hex" ] + + args = [ + "-factory_data", + rebase_path( + "${chip_root}/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json"), + "-schema", + rebase_path( + "${chip_root}/src/platform/cc13xx_26xx/factory_data.schema"), + "-o", + rebase_path("${root_out_dir}/${output_base_name}-factory-data.hex", + root_out_dir), + "-device", + "cc13x4_26x4", + ] + } + } + # add MCUBoot Header to the executable action("${simplelink_target_name}_header.hex") { - public_deps = [ ":${simplelink_target_name}.out.image" ] + if (custom_factory_data) { + public_deps = + [ ":${simplelink_target_name}-without-factory-data.hex" ] + } else { + public_deps = [ ":${simplelink_target_name}.out.image" ] + } script = "${ti_simplelink_sdk_root}/source/third_party/mcuboot/scripts/imgtool.py" - sources = [ "${root_out_dir}/${output_base_name}.hex" ] + if (custom_factory_data) { + sources = + [ "${root_out_dir}/${output_base_name}-without-factory-data.hex" ] + input_path = + "${root_out_dir}/${output_base_name}-without-factory-data.hex" + } else { + sources = [ "${root_out_dir}/${output_base_name}.hex" ] + input_path = "${root_out_dir}/${output_base_name}.hex" + } outputs = [ "${root_out_dir}/${output_base_name}_header.hex" ] args = [ @@ -222,7 +389,7 @@ template("ti_simplelink_executable") { rebase_path( "${ti_simplelink_sdk_root}/source/third_party/mcuboot/root-ec-p256.pem", root_build_dir), - rebase_path("${root_out_dir}/${output_base_name}.hex", root_out_dir), + rebase_path(input_path, root_out_dir), rebase_path("${root_out_dir}/${output_base_name}_header.hex", root_out_dir), ] @@ -354,21 +521,46 @@ template("ti_simplelink_executable") { ":${simplelink_target_name}_mcubootloader.image", ] - script = "${ti_simplelink_sdk_build_root}/oad_merge_tool.py" - sources = [ - "${root_out_dir}/${output_base_name}.mcubootloader.hex", - "${root_out_dir}/${output_base_name}_header.bin", - ] + if (custom_factory_data) { + public_deps += [ ":${simplelink_target_name}-factory-data.hex" ] + + script = "${ti_simplelink_sdk_build_root}/oad_and_factory_data_merge_tool.py" + sources = [ + "${root_out_dir}/${output_base_name}-factory-data.hex", + "${root_out_dir}/${output_base_name}.mcubootloader.hex", + "${root_out_dir}/${output_base_name}_header.bin", + ] + } else { + script = "${ti_simplelink_sdk_build_root}/oad_merge_tool.py" + sources = [ + "${root_out_dir}/${output_base_name}.mcubootloader.hex", + "${root_out_dir}/${output_base_name}_header.bin", + ] + } + outputs = [ "${root_out_dir}/${output_base_name}-mcuboot.hex" ] - args = [ - rebase_path("${root_out_dir}/${output_base_name}_header.hex", - root_build_dir), - rebase_path("${root_out_dir}/${output_base_name}.mcubootloader.hex", - root_build_dir), - rebase_path("${root_out_dir}/${output_base_name}-mcuboot.hex", - root_build_dir), - ] + if (custom_factory_data) { + args = [ + rebase_path("${root_out_dir}/${output_base_name}_header.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}.mcubootloader.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-factory-data.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-mcuboot.hex", + root_build_dir), + ] + } else { + args = [ + rebase_path("${root_out_dir}/${output_base_name}_header.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}.mcubootloader.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-mcuboot.hex", + root_build_dir), + ] + } } pw_python_action("${target_name}.ota") { # For MCUBoot the image could be truncated to the actual executable @@ -413,6 +605,71 @@ template("ti_simplelink_executable") { } } } + } else if (ti_simplelink_device_family == "cc13x4_26x4" && + custom_factory_data) { + pw_python_action("${simplelink_target_name}-without-factory-data.hex") { + public_deps = [ ":${simplelink_target_name}.out.image" ] + + script = "${ti_simplelink_sdk_build_root}/factory_data_trim.py" + sources = [ "${root_out_dir}/${objcopy_image_name}" ] + outputs = + [ "${root_out_dir}/${output_base_name}-without-factory-data.hex" ] + + args = [ + rebase_path("${root_out_dir}/${output_base_name}.hex", root_out_dir), + rebase_path("${root_out_dir}/${output_base_name}.out.map", + root_out_dir), + rebase_path( + "${root_out_dir}/${output_base_name}-without-factory-data.hex", + root_out_dir), + "cc13x4_26x4", + ] + } + pw_python_action("${simplelink_target_name}-factory-data.hex") { + script = "${ti_simplelink_sdk_build_root}/create_factory_data.py" + sources = [ + "${chip_root}/src/platform/cc13xx_26xx/factory_data.schema", + "${chip_root}/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json", + ] + outputs = [ "${root_out_dir}/${output_base_name}-factory-data.hex" ] + + args = [ + "-factory_data", + rebase_path( + "${chip_root}/src/platform/cc13xx_26xx/factory_data_cc13xx_26xx.json"), + "-schema", + rebase_path( + "${chip_root}/src/platform/cc13xx_26xx/factory_data.schema"), + "-o", + rebase_path("${root_out_dir}/${output_base_name}-factory-data.hex", + root_out_dir), + "-device", + "cc13x4_26x4", + ] + } + pw_python_action("${simplelink_target_name}-and-factory-data.hex") { + public_deps = [ + ":${simplelink_target_name}-factory-data.hex", + ":${simplelink_target_name}-without-factory-data.hex", + ] + script = "${ti_simplelink_sdk_build_root}/factory_data_merge_tool.py" + sources = [ + "${root_out_dir}/${output_base_name}-factory-data.hex", + "${root_out_dir}/${output_base_name}-without-factory-data.hex", + ] + outputs = [ "${root_out_dir}/${output_base_name}-and-factory-data.hex" ] + + args = [ + rebase_path( + "${root_out_dir}/${output_base_name}-without-factory-data.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-factory-data.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-and-factory-data.hex", + root_build_dir), + ] + args += [ "${root_out_dir}/${output_base_name}-and-factory-data.hex" ] + } } group(simplelink_target_name) {