From d9999ad5dfd18aa52e5977546f7b1458eee19ff9 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:49:48 +0800 Subject: [PATCH] [Bouffalo Lab] Update Bouffalo SDK to bouffalolab_release_bl_iot_sdk_1.6.40-2000-gb17d51bc3 (#34837) * [Bouffalo Lab] Update Bouffalo SDK to bouffalolab_release_bl_iot_sdk_1.6.40-2000-gb17d51bc3 * [Bouffalo Lab] Update bouffalo lab docker image tag for ci build * fix restyle & spells and rollback boringssl * fix lintcode and python3 module required --- .github/workflows/examples-bouffalolab.yaml | 2 +- examples/lighting-app/bouffalolab/README.md | 198 +++--- .../lighting-app/bouffalolab/bl602/BUILD.gn | 3 - .../lighting-app/bouffalolab/bl602/args.gni | 2 + .../lighting-app/bouffalolab/bl702/BUILD.gn | 3 - .../lighting-app/bouffalolab/bl702/args.gni | 3 + .../lighting-app/bouffalolab/bl702l/BUILD.gn | 3 - .../lighting-app/bouffalolab/bl702l/args.gni | 1 + .../bouffalolab/common/AppTask.cpp | 7 +- .../bouffalolab/bl602/lwipopts/lwipopts.h | 2 +- .../bouffalolab/bl702l/FreeRTOSConfig.h | 8 +- .../bl702l/ldscripts/psram_flash_rom.ld | 3 - .../common/iot_sdk/platform_port.cpp | 73 +- .../bouffalolab/common/plat/OTAConfig.cpp | 1 + .../bouffalolab/common/plat/platform.cpp | 9 +- .../common/route_hook/bl_route_hook.c | 14 +- scripts/build/build/targets.py | 34 +- scripts/build/builders/bouffalolab.py | 100 +-- .../build/testdata/all_targets_linux_x64.txt | 2 +- .../flashing/bouffalolab_firmware_utils.py | 624 +++++++++++++----- scripts/setup/requirements.bouffalolab.txt | 2 +- src/lib/shell/streamer_bouffalolab.cpp | 1 + src/lwip/BUILD.gn | 1 + src/platform/bouffalolab/BL602/BUILD.gn | 9 +- src/platform/bouffalolab/BL702/BUILD.gn | 9 +- .../BL702/bl702-openthread-core-bl-config.h | 111 ++-- src/platform/bouffalolab/BL702L/BUILD.gn | 9 +- .../BL702L/PlatformManagerImpl.cpp | 2 - .../BL702L/ThreadStackManagerImpl.cpp | 30 +- .../BL702L/bl702l-openthread-core-bl-config.h | 111 ++-- .../common/ConfigurationManagerImpl.cpp | 4 + .../common/FactoryDataProvider.cpp | 230 +------ src/platform/bouffalolab/common/Logging.cpp | 22 +- .../common/OTAImageProcessorImpl.cpp | 2 - src/platform/bouffalolab/common/args.gni | 3 +- third_party/bouffalolab/bl602/bl_iot_sdk.gni | 65 +- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 84 ++- third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 236 ++++--- .../common/bouffalolab_executable.gni | 24 +- third_party/bouffalolab/common/rsicv.gni | 4 +- third_party/bouffalolab/repo | 2 +- 41 files changed, 1083 insertions(+), 970 deletions(-) diff --git a/.github/workflows/examples-bouffalolab.yaml b/.github/workflows/examples-bouffalolab.yaml index 12b033b791f900..933a9b60361eb3 100644 --- a/.github/workflows/examples-bouffalolab.yaml +++ b/.github/workflows/examples-bouffalolab.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-bouffalolab:54 + image: ghcr.io/project-chip/chip-build-bouffalolab:68 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/examples/lighting-app/bouffalolab/README.md b/examples/lighting-app/bouffalolab/README.md index 83ff6a87b6a0f4..d2fd8b72afadf6 100644 --- a/examples/lighting-app/bouffalolab/README.md +++ b/examples/lighting-app/bouffalolab/README.md @@ -4,7 +4,13 @@ This example functions as a light bulb device type, with on/off and level capabilities and uses a test Vendor ID (VID) and a Product ID (PID) of **0x8005**. -The steps were verified on `Bouffalo Lab` BL602 and BL706 development board. +Current supported boards: + +- `BL602DK` +- `BL706DK` +- `BL704LDK` + +Legacy supported boards: - `BL602-IoT-Matter-V1`, [here](https://www.amazon.com/dp/B0B9ZVGXD8) to purchase. @@ -21,10 +27,6 @@ The steps were verified on `Bouffalo Lab` BL602 and BL706 development board. BL602/BL604 is combo chip-set for Wi-Fi 802.11b/g/n and BLE 5.0 base-band/MAC. -### BL602-IoT-Matter-V1 - - - ## BL70x BL70x is combo chip-set for BLE and IEEE 802.15.4/ZigBee/Thread. @@ -35,16 +37,34 @@ BL70x is combo chip-set for BLE and IEEE 802.15.4/ZigBee/Thread. general name. BL70x has fully certified with all Thread 1.3 features, included Thread `SSED` -and Thread Border Router with `DUA manager`. - -### `XT-ZB6-DevKit` - - +and Thread Border Router. + +## Solutions introduction + +`Bouffalo Lab` has full connectives support for Matter Applications. + +- Wi-Fi 4/6 application, we have + - BL602, Wi-Fi 4 application. + - BL706 + BL602, Wi-Fi 4 application. BL602 runs as a normal WLAN + transceiver; TCP/IP stack runs as BL706 side. We recommend this solution + is for Openthread Border Router application and Matter ZigBee bridge. + - Openthread Border Router application, please refer to Openthread + Border Router application + - Matter ZigBee Bridge application, please contact `Bouffalo Lab` for + support. +- Thread application, we have + - B70X +- Ethernet application, we have + - BL706. It supports single Matter application, and also Openthread Border + Router application and Matter ZigBee bridge + - Openthread Border Router application, please refer to Openthread + Border Router application + - Matter ZigBee application, please contact `Bouffalo Lab` for + support. ## Initial setup -The following steps in this document were validated on Ubuntu 18.04/20.04 and -Mac OS. +The following steps in this document were validated on Ubuntu 20.04. - Install dependencies as specified in the **connectedhomeip** repository: [Building Matter](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/BUILDING.md). @@ -58,77 +78,67 @@ Mac OS. source ./scripts/activate.sh -p bouffalolab ``` - > After environment setup `Bouffalo Lab` flash tool, `bflb-iot-tool`, - > imports under this environment. If not, please try - > `scripts/bootstrap.sh -p bouffalolab` for matter environment update. - - Setup build environment for `Bouffalo Lab` SoC - Run `setup.sh` to install `Bouffalo Lab` SDK to /opt/bouffalolab_sdk - ``` - cd third_party/bouffalolab/repo - sudo bash scripts/setup.sh + ./integrations/docker/images/stage-2/chip-build-bouffalolab/setup.sh ``` - Please execute following command to export `BOUFFALOLAB_SDK_ROOT` before - building. + Script `setpu.sh` requires to select install path, and please execute + following command to export `BOUFFALOLAB_SDK_ROOT` before building. ``` - export BOUFFALOLAB_SDK_ROOT=/opt/bouffalolab_sdk + export BOUFFALOLAB_SDK_ROOT="Your install path" ``` ## Build CHIP Lighting App example -The following steps take examples for `BL602-IoT-Matter-V1` BL602 board, -`BL706DK` BL706 board, and `BL704LDK` BL704L board . +The following steps take examples for `BL602DK`, `BL704LDK` and `BL706DK`. - Build lighting app with UART baudrate 2000000 ``` - ./scripts/build/build_examples.py --target bouffalolab-bl602-iot-matter-v1-light build - ./scripts/build/build_examples.py --target bouffalolab-bl706dk-light build - ./scripts/build/build_examples.py --target bouffalolab-bl706dk-light-ethernet build - ./scripts/build/build_examples.py --target bouffalolab-bl706dk-light-wifi build + ./scripts/build/build_examples.py --target bouffalolab-bl602dk-light build ./scripts/build/build_examples.py --target bouffalolab-bl704ldk-light build - ``` - -- Build lighting app with UART baudrate 115200 - - ``` - ./scripts/build/build_examples.py --target bouffalolab-bl602-iot-matter-v1-light-115200 build - ./scripts/build/build_examples.py --target bouffalolab-bl706dk-light-light-115200 build - ./scripts/build/build_examples.py --target bouffalolab-bl704ldk-light-light-115200 build + ./scripts/build/build_examples.py --target bouffalolab-bl706dk-light build ``` - Build lighting app with RPC enabled and UART baudrate 115200. ``` - ./scripts/build/build_examples.py --target bouffalolab-bl602-iot-matter-v1-light-rpc build - ./scripts/build/build_examples.py --target bouffalolab-bl706dk-light-light-rpc build - ./scripts/build/build_examples.py --target bouffalolab-bl704ldk-light-light-rpc build + ./scripts/build/build_examples.py --target bouffalolab-bl602dk-light-light-rpc-115200 build + ./scripts/build/build_examples.py --target bouffalolab-bl704ldk-light-light-rpc-115200 build + ./scripts/build/build_examples.py --target bouffalolab-bl706dk-light-light-rpc-115200 build ``` ### Build options with build_examples.py -- `-shell`, enable UART command line -- `-115200`, set UART baudrate to 115200 for log and command line +- `-wifi`, to specify that connectivity Wi-Fi is enabled for Matter + application. + + - BL602 uses `-wifi` by default + - BL702 needs specify to use BL706 + BL602 for Wi-Fi connectivity. + +- `-thread`, to specify that connectivity Thread is enabled for Matter + application. + + - BL70X uses `-thread` by default. + +- `-ethernet`, to specify that connectivity Ethernet is enabled for Matte + application. + + - BL706 needs specify to use Ethernet connectivity. + +- `-easyflash`, to specify that `easyflash` is used for flash storage access. +- `-mfd`, enable Matter factory data feature, which load factory data from + `MFD` partition +- `-shell`, enable command line - `-rpc`, enable Pigweed RPC feature +- `-115200`, set UART baudrate to 115200 for log and command line - `-cdc`, enable USB CDC feature, only support for BL706, and can't work with Ethernet Board - `-resetCnt`, enable feature to do factory reset when continues power cycle is greater than 3 -- `-mfd`, enable Matter factory data feature, which load factory data from - `DTS` region and `MFD` partition - - Please contact to `Bouffalo Lab` for Matter factory data support. -- `-mfdtest`, enable Matter factory data module, but only load factory data - from `FactoryDataProvider.cpp` file. -- `-wifi`, to specify that connectivity Wi-Fi is enabled for Matter - application. -- `-ethernet`, to specify that connectivity Ethernet is enabled for Matter - application. -- `-thread`, to specify that connectivity Thread is enabled for Matter - application. - `-mot`, to specify to use openthread stack under `third_party/openthread/repo` - Without `-mot` specified, Matter Thread will use openthread stack under @@ -147,12 +157,6 @@ The following steps take examples for `BL602-IoT-Matter-V1` BL602 board, - `chip-bl702-lighting-example.flash.py` for BL702 - `chip-bl702l-lighting-example.flash.py` for BL702L - > Note 1, `*.flash.py` should be ran under Matter build environment; if - > python module `bflb_iot_tool` is not found, please try to do - > `source scripts/bootstrap.sh` or install as - > `pip3 install bflb-iot-tool`.
Note 2, different build options will - > generate different output folder. - Download operation steps as below, please check `help` option of script for more detail. @@ -167,45 +171,25 @@ The following steps take examples for `BL602-IoT-Matter-V1` BL602 board, - Type following command for image download. Please set serial port accordingly, here we use /dev/ttyACM0 as a serial port example. - - `bl602-iot-matter-v1`, `bl706dk` and `bl704ldk` without additional - build options - - ```shell - ./out/bouffalolab-bl602-iot-matter-v1-light/chip-bl602-lighting-example.flash.py --port /dev/ttyACM0 - ./out/bouffalolab-bl706dk-light/chip-bl702-lighting-example.flash.py --port /dev/ttyACM0 - ./out/bouffalolab-bl704ldk-light/chip-bl702l-lighting-example.flash.py --port /dev/ttyACM0 - ``` + - `BL602DK`, `BL704LDK` and `BL706DK`. - - `bl706dk` with 115200 baudrate setting ```shell - ./out/bouffalolab-bl706dk-light-115200/chip-bl702-lighting-example.flash.py --port /dev/ttyACM0 + ./out/bouffalolab-bl602dk-light/chip-bl602-lighting-example.flash.py --port /dev/ttyACM0 + ./out/bouffalolab-bl704ldk-light/chip-bl702l-lighting-example.flash.py --port /dev/ttyACM0 + ./out/bouffalolab-bl706dk-light/chip-bl702-lighting-example.flash.py --port /dev/ttyACM0 ``` - - To wipe out flash and download image, please append `--erase` to the - above command. + - To wipe out flash and download image, please append `--erase` + option. Take BL602DK as example. ```shell - ./out/bouffalolab-bl602-iot-matter-v1-light/chip-bl602-lighting-example.flash.py --port /dev/ttyACM0 --erase - ./out/bouffalolab-bl706dk-light-115200/chip-bl702-lighting-example.flash.py --port /dev/ttyACM0 --erase - ./out/bouffalolab-bl704ldk-light/chip-bl702l-lighting-example.flash.py --port /dev/ttyACM0 --erase + ./out/bouffalolab-bl602dk-light/chip-bl602-lighting-example.flash.py --port /dev/ttyACM0 --erase ``` > Note, better to append --erase option to download image for BL602 > develop board at first time. -- Using `Bouffalo Lab` GUI flash tool `BLDevCube`, please download on - [this page](https://dev.bouffalolab.com/download). - - Hold BOOT pin and reset chip, put the board in download mode. - - Select `DTS` file; - - Select Partition Table under - `examples/platform/bouffalolab/bl602/flash_config` or - `examples/platform/bouffalolab/bl702/flash_config` - - Select Firmware Bin; - - Select Chip Erase if need; - - Choose Target COM port. - - Then click Create & Download. - ## Run the example - You can open the serial console. For example, if the device is at @@ -249,13 +233,13 @@ sudo ot-ctl dataset active -x - Enter build out folder of chip-tool and running the following command to do BLE commission - - BL602 + - Wi-Fi ```shell ./chip-tool pairing ble-wifi 20202021 3840 ``` - - BL706 + - Thread ```shell ./chip-tool pairing ble-thread hex: 20202021 3840 @@ -308,34 +292,26 @@ After successful commissioning, cluster commands available to control the board. Please take [guide](../../ota-provider-app/linux/README.md) for more detail on ota-provider-app build and usage. -### Create the Matter OTA image with Bouffalolab OTA `bin.xz.hash` format image - -- `Bouffalo Lab` OTA `bin.xz.hash` format image +### Create the Matter OTA image - - Build `Bouffalo Lab` OTA image as following execution using python - script `*.flash.py` under firmware build out folder, - `shell ./.flash.py --build` After script executed, - a folder `ota_images` and an image `FW_OTA.bin.xz.hash` will be - generated. `FW_OTA.bin.xz.hash` is compressed with hash verification for - build out firmware. +`Bouffalo Lab` Matter OTA image contains two parts: - - `bin.xz.hash` image +- `Bouffalo Lab` OTA bootable image: + - Add boot parameters, signature/encryption if specified + - And specify whether image has be compressed. +- Add Matter recognition header by + [ota_image_tool.py](../../../docs/guides/openthread_border_router_pi.md). - After compile done, the build script will call - `.flash.py` to generate `Bouffalo Lab` OTA format - image as above, and put it under out folder with name likes - `.bin.xz.hash` +Script `*.flash.py` builds `Bouffalo Lab` bootable image and call +[ota_image_tool.py](../../../docs/guides/openthread_border_router_pi.md) to add +Matter recognition header. Take `BL602DK` as example. -* Build Matter `*.ota` OTA image with `Bouffalo Lab` OTA image under - **connectedhomeip** repo folder - - ```shell - $ ./src/app/ota_image_tool.py create -v 0xFFF1 -p 0x8005 -vn 10 -vs "1.0" -da sha256 lighting-app.ota - - ``` +```shell +./out/bouffalolab-bl602dk-light/chip-bl602-lighting-example.flash.py --build-ota --vendor-id --product-id --version --version-str --digest-algorithm +``` - > lighting-app.ota should have greater software version which is defined by - > macro `CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION` in CHIPProjectConfig.h +> lighting-app.ota should have greater software version which is defined by +> macro `CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION` in CHIPProjectConfig.h ### Start ota-provider-app diff --git a/examples/lighting-app/bouffalolab/bl602/BUILD.gn b/examples/lighting-app/bouffalolab/bl602/BUILD.gn index f03a18c004a131..6fc584fa8eeade 100644 --- a/examples/lighting-app/bouffalolab/bl602/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl602/BUILD.gn @@ -110,9 +110,6 @@ bouffalolab_executable("lighting_app") { defines += [ "CONF_ENABLE_FRAME_PTR=${enable_debug_frame_ptr}" ] defines += [ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ] - defines += [ - "CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST=${chip_enable_factory_data_test}", - ] bl_plat_name = "bl602" sources = [ diff --git a/examples/lighting-app/bouffalolab/bl602/args.gni b/examples/lighting-app/bouffalolab/bl602/args.gni index 4c69abdaa1259f..0fcb5aac2edc9b 100644 --- a/examples/lighting-app/bouffalolab/bl602/args.gni +++ b/examples/lighting-app/bouffalolab/bl602/args.gni @@ -25,6 +25,8 @@ pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" chip_detail_logging = false +#is_debug = false + pw_build_LINK_DEPS = [ "$dir_pw_assert:impl", "$dir_pw_log:impl", diff --git a/examples/lighting-app/bouffalolab/bl702/BUILD.gn b/examples/lighting-app/bouffalolab/bl702/BUILD.gn index ac3a5e5f7e66af..209e473e693869 100644 --- a/examples/lighting-app/bouffalolab/bl702/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702/BUILD.gn @@ -138,9 +138,6 @@ bouffalolab_executable("lighting_app") { defines += [ "CONF_ENABLE_FRAME_PTR=${enable_debug_frame_ptr}" ] defines += [ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ] - defines += [ - "CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST=${chip_enable_factory_data_test}", - ] if (chip_config_network_layer_ble) { defines += [ "CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=1" ] } diff --git a/examples/lighting-app/bouffalolab/bl702/args.gni b/examples/lighting-app/bouffalolab/bl702/args.gni index e35ae89f6a9426..e06c706903b935 100644 --- a/examples/lighting-app/bouffalolab/bl702/args.gni +++ b/examples/lighting-app/bouffalolab/bl702/args.gni @@ -25,6 +25,9 @@ pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" chip_detail_logging = false +# use -Os instead of -Og +is_debug = false + pw_build_LINK_DEPS = [ "$dir_pw_assert:impl", "$dir_pw_log:impl", diff --git a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn index f7ca4144bb8a04..50d2bd417a2ba4 100644 --- a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn @@ -115,9 +115,6 @@ bouffalolab_executable("lighting_app") { defines += [ "CONF_ENABLE_FRAME_PTR=${enable_debug_frame_ptr}" ] defines += [ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ] - defines += [ - "CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST=${chip_enable_factory_data_test}", - ] if (chip_config_network_layer_ble) { defines += [ "CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=1" ] } diff --git a/examples/lighting-app/bouffalolab/bl702l/args.gni b/examples/lighting-app/bouffalolab/bl702l/args.gni index f2eb36a8b29f73..3120af1cce60f6 100644 --- a/examples/lighting-app/bouffalolab/bl702l/args.gni +++ b/examples/lighting-app/bouffalolab/bl702l/args.gni @@ -24,6 +24,7 @@ pw_assert_BACKEND = "$dir_pw_assert_log" pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" chip_detail_logging = false +is_debug = false pw_build_LINK_DEPS = [ "$dir_pw_assert:impl", diff --git a/examples/lighting-app/bouffalolab/common/AppTask.cpp b/examples/lighting-app/bouffalolab/common/AppTask.cpp index fafc9943e24890..7e9b4920d03783 100644 --- a/examples/lighting-app/bouffalolab/common/AppTask.cpp +++ b/examples/lighting-app/bouffalolab/common/AppTask.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #if HEAP_MONITORING @@ -133,7 +134,8 @@ void AppTask::PostEvent(app_event_t event) void AppTask::AppTaskMain(void * pvParameter) { app_event_t appEvent; - bool onoff = false; + bool onoff = false; + uint64_t currentHeapFree = 0; #if !(CHIP_DEVICE_LAYER_TARGET_BL702 && CHIP_DEVICE_CONFIG_ENABLE_ETHERNET) sLightLED.Init(); @@ -184,7 +186,8 @@ void AppTask::AppTaskMain(void * pvParameter) vTaskSuspend(NULL); - ChipLogProgress(NotSpecified, "App Task started, with SRAM heap %d left\r\n", xPortGetFreeHeapSize()); + DiagnosticDataProviderImpl::GetDefaultInstance().GetCurrentHeapFree(currentHeapFree); + ChipLogProgress(NotSpecified, "App Task started, with SRAM heap %lld left\r\n", currentHeapFree); while (true) { diff --git a/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h b/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h index dea0e2e715136d..ba744a119d77e3 100644 --- a/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h +++ b/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h @@ -264,7 +264,7 @@ a lot of data that needs to be copied, this should be set high. */ #define LWIP_IPV6_DHCP6 1 #define LWIP_AUTOIP 1 #define LWIP_IPV6_MLD 1 -#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS 1 +#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS 0 #define LWIP_HOOK_FILENAME "bl_lwip_hooks.h" #define LWIP_NETIF_EXT_STATUS_CALLBACK 1 diff --git a/examples/platform/bouffalolab/bl702l/FreeRTOSConfig.h b/examples/platform/bouffalolab/bl702l/FreeRTOSConfig.h index a131725750a742..27b474da904602 100644 --- a/examples/platform/bouffalolab/bl702l/FreeRTOSConfig.h +++ b/examples/platform/bouffalolab/bl702l/FreeRTOSConfig.h @@ -159,9 +159,9 @@ to exclude the API function. */ /* Normal assert() semantics without relying on the provision of an assert.h header file. */ #ifdef __cplusplus -extern "C" void (*vAssertCalled)(void); +extern "C" void vAssertCalled(void); #else -extern void (*vAssertCalled)(void); +extern void vAssertCalled(void); #endif #define configASSERT(x) \ if ((x) == 0) \ @@ -182,9 +182,9 @@ Like all task stack sizes, the value is the number of words, not bytes. */ #if (configUSE_TICKLESS_IDLE != 0) #include "portmacro.h" #ifdef __cplusplus -extern "C" void (*vApplicationSleep)(TickType_t xExpectedIdleTime); +extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime); #else -extern void (*vApplicationSleep)(TickType_t xExpectedIdleTime); +extern void vApplicationSleep(TickType_t xExpectedIdleTime); #endif #define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vApplicationSleep(xExpectedIdleTime) #endif diff --git a/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld b/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld index 9b244b848e56e3..5d74cdb0557a90 100644 --- a/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld +++ b/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash_rom.ld @@ -297,7 +297,4 @@ SECTIONS /* rom driver */ INCLUDE ../../third_party/bouffalolab/repo/components/platform/soc/bl702l/bl702l/evb/ld/romdriver.ld - - /* rom data & code */ - INCLUDE ../../third_party/bouffalolab/repo/components/platform/soc/bl702l/bl702l/evb/ld/rom_map.ld } diff --git a/examples/platform/bouffalolab/common/iot_sdk/platform_port.cpp b/examples/platform/bouffalolab/common/iot_sdk/platform_port.cpp index 32cf15e2ea7cb3..5b18c866ed7c3f 100644 --- a/examples/platform/bouffalolab/common/iot_sdk/platform_port.cpp +++ b/examples/platform/bouffalolab/common/iot_sdk/platform_port.cpp @@ -56,12 +56,6 @@ extern "C" { #elif CHIP_DEVICE_LAYER_TARGET_BL702L #include #endif - -#if CHIP_DEVICE_LAYER_TARGET_BL702L -#include -#include -#include -#endif } #include @@ -85,7 +79,6 @@ extern "C" unsigned int sleep(unsigned int seconds) return 0; } -#if !CHIP_DEVICE_LAYER_TARGET_BL702L extern "C" void vApplicationStackOverflowHook(TaskHandle_t xTask, char * pcTaskName) { printf("Stack Overflow checked. Stack name %s", pcTaskName); @@ -169,9 +162,7 @@ extern "C" void vAssertCalled(void) { void * ra = (void *) __builtin_return_address(0); -#if CONF_ENABLE_FRAME_PTR == 0 taskDISABLE_INTERRUPTS(); -#endif if (xPortIsInsideInterrupt()) { @@ -182,65 +173,14 @@ extern "C" void vAssertCalled(void) printf("vAssertCalled, ra = %p in task %s\r\n", (void *) ra, pcTaskGetName(NULL)); } -#if CONF_ENABLE_FRAME_PTR portABORT(); -#endif while (true) ; } -#endif - -#if CHIP_DEVICE_LAYER_TARGET_BL702L -extern "C" void __attribute__((weak)) user_vAssertCalled(void) -{ - void * ra = (void *) __builtin_return_address(0); - - taskDISABLE_INTERRUPTS(); - if (xPortIsInsideInterrupt()) - { - printf("vAssertCalled, ra = %p in ISR\r\n", (void *) ra); - } - else - { - printf("vAssertCalled, ra = %p in task %s\r\n", (void *) ra, pcTaskGetName(NULL)); - } - - while (true) - ; -} - -extern "C" void __attribute__((weak)) user_vApplicationStackOverflowHook(TaskHandle_t xTask, char * pcTaskName) -{ - puts("Stack Overflow checked\r\n"); - if (pcTaskName) - { - printf("Stack name %s\r\n", pcTaskName); - } - while (1) - { - /*empty here*/ - } -} - -extern "C" void __attribute__((weak)) user_vApplicationMallocFailedHook(void) -{ - printf("Memory Allocate Failed. Current left size is %d bytes\r\n", xPortGetFreeHeapSize()); -#if defined(CFG_USE_PSRAM) - printf("Current psram left size is %d bytes\r\n", xPortGetFreeHeapSizePsram()); -#endif - while (1) - { - /*empty here*/ - } -} - -extern "C" void bflb_assert(void) __attribute__((weak, alias("user_vAssertCalled"))); -#else extern "C" void user_vAssertCalled(void) __attribute__((weak, alias("vAssertCalled"))); extern "C" void bflb_assert(void) __attribute__((weak, alias("vAssertCalled"))); -#endif // ================================================================================ // Main Code @@ -336,16 +276,8 @@ extern "C" void setup_heap() { bl_sys_init(); -#if CHIP_DEVICE_LAYER_TARGET_BL702 - bl_sys_em_config(); -#elif CHIP_DEVICE_LAYER_TARGET_BL702L +#if CHIP_DEVICE_LAYER_TARGET_BL702 || CHIP_DEVICE_LAYER_TARGET_BL702L bl_sys_em_config(); - - // Initialize rom data - extern uint8_t _rom_data_run; - extern uint8_t _rom_data_load; - extern uint8_t _rom_data_size; - memcpy((void *) &_rom_data_run, (void *) &_rom_data_load, (size_t) &_rom_data_size); #endif #if CHIP_DEVICE_LAYER_TARGET_BL702 @@ -376,9 +308,6 @@ extern "C" void app_init(void) #if CHIP_DEVICE_LAYER_TARGET_BL702L bl_flash_init(); - - rom_freertos_init(256, 400); - rom_hal_init(); #endif hosal_uart_init(&uart_stdio); diff --git a/examples/platform/bouffalolab/common/plat/OTAConfig.cpp b/examples/platform/bouffalolab/common/plat/OTAConfig.cpp index b6ca3b621cd747..30bc9d2ea46ac0 100644 --- a/examples/platform/bouffalolab/common/plat/OTAConfig.cpp +++ b/examples/platform/bouffalolab/common/plat/OTAConfig.cpp @@ -20,6 +20,7 @@ #include #include + // Global OTA objects chip::DefaultOTARequestor gRequestorCore; chip::DefaultOTARequestorStorage gRequestorStorage; diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index 329e3eee49f262..6a91567ab9b803 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -42,7 +42,7 @@ #include #endif -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE || CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST +#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE #include #endif @@ -87,7 +87,7 @@ chip::app::Clusters::NetworkCommissioning::Instance } #endif -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE || CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST +#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE namespace { FactoryDataProvider sFactoryDataProvider; } @@ -180,7 +180,7 @@ void UnlockOpenThreadTask(void) CHIP_ERROR PlatformManagerImpl::PlatformInit(void) { chip::RendezvousInformationFlags rendezvousMode(chip::RendezvousInformationFlag::kOnNetwork); -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE || CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST +#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE CHIP_ERROR retFactoryData = sFactoryDataProvider.Init(); #endif @@ -213,7 +213,6 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) #else ReturnLogErrorOnFailure(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice)); #endif - #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI @@ -221,7 +220,7 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) #endif // Initialize device attestation config -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE || CONFIG_BOUFFALOLAB_FACTORY_DATA_TEST +#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE if (CHIP_NO_ERROR == retFactoryData) { SetDeviceInstanceInfoProvider(&sFactoryDataProvider); diff --git a/examples/platform/bouffalolab/common/route_hook/bl_route_hook.c b/examples/platform/bouffalolab/common/route_hook/bl_route_hook.c index 68c51bd327e3a2..0da6d1bfb34383 100644 --- a/examples/platform/bouffalolab/common/route_hook/bl_route_hook.c +++ b/examples/platform/bouffalolab/common/route_hook/bl_route_hook.c @@ -8,6 +8,7 @@ #include "lwip/prot/ip6.h" #include "lwip/prot/nd6.h" #include "lwip/raw.h" +#include #include "bl_route_hook.h" #include "bl_route_table.h" @@ -158,17 +159,21 @@ int8_t bl_route_hook_init(void) uint8_t ret = 0; struct netif * lwip_netif = deviceInterface_getNetif(); + LOCK_TCPIP_CORE(); + if (lwip_netif == NULL) { printf("Invalid network interface\r\n"); - return -1; + ret = -1; + goto exit; } for (bl_route_hook_t * iter = s_hooks; iter != NULL; iter++) { if (iter->netif == lwip_netif) { - return 0; + ret = 0; + break; } } @@ -176,7 +181,8 @@ int8_t bl_route_hook_init(void) if (hook == NULL) { printf("Cannot allocate hook\r\n"); - return -1; + ret = -1; + goto exit; } if (mld6_joingroup_netif(lwip_netif, ip_2_ip6(&router_group)) != ERR_OK) @@ -202,5 +208,7 @@ int8_t bl_route_hook_init(void) { free(hook); } + UNLOCK_TCPIP_CORE(); + return ret; } diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 827c7db045b825..bf21adf48e22d1 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -15,7 +15,7 @@ from builders.ameba import AmebaApp, AmebaBoard, AmebaBuilder from builders.android import AndroidApp, AndroidBoard, AndroidBuilder, AndroidProfile from builders.asr import ASRApp, ASRBoard, ASRBuilder -from builders.bouffalolab import BouffalolabApp, BouffalolabBoard, BouffalolabBuilder, BouffalolabMfd +from builders.bouffalolab import BouffalolabApp, BouffalolabBoard, BouffalolabBuilder from builders.cc32xx import cc32xxApp, cc32xxBuilder from builders.cyw30739 import Cyw30739App, Cyw30739Board, Cyw30739Builder from builders.efr32 import Efr32App, Efr32Board, Efr32Builder @@ -662,17 +662,19 @@ def BuildBouffalolabTarget(): # Boards target.AppendFixedTargets([ - TargetPart('BL602-IoT-Matter-V1', + TargetPart('BL602DK', board=BouffalolabBoard.BL602_IoT_Matter_V1, module_type="BL602"), + TargetPart('BL704LDK', board=BouffalolabBoard.BL704LDK, module_type="BL704L"), + TargetPart('BL706DK', + board=BouffalolabBoard.BL706DK, module_type="BL706C-22"), TargetPart('BL602-NIGHT-LIGHT', board=BouffalolabBoard.BL602_NIGHT_LIGHT, module_type="BL602"), - TargetPart('XT-ZB6-DevKit', board=BouffalolabBoard.XT_ZB6_DevKit, - module_type="BL706C-22"), TargetPart('BL706-NIGHT-LIGHT', board=BouffalolabBoard.BL706_NIGHT_LIGHT, module_type="BL706C-22"), - TargetPart('BL706DK', - board=BouffalolabBoard.BL706DK, module_type="BL706C-22"), - TargetPart('BL704LDK', board=BouffalolabBoard.BL704LDK, module_type="BL704L"), + TargetPart('BL602-IoT-Matter-V1', + board=BouffalolabBoard.BL602_IoT_Matter_V1, module_type="BL602"), + TargetPart('XT-ZB6-DevKit', board=BouffalolabBoard.XT_ZB6_DevKit, + module_type="BL706C-22"), ]) # Apps @@ -680,20 +682,20 @@ def BuildBouffalolabTarget(): TargetPart('light', app=BouffalolabApp.LIGHT), ]) + target.AppendModifier('ethernet', enable_ethernet=True) + target.AppendModifier('wifi', enable_wifi=True) + target.AppendModifier('thread', enable_thread=True) + target.AppendModifier('easyflash', enable_easyflash=True) target.AppendModifier('shell', enable_shell=True) - target.AppendModifier('115200', baudrate=115200) + target.AppendModifier('mfd', enable_mfd=True) + target.AppendModifier('rotating_device_id', enable_rotating_device_id=True) target.AppendModifier('rpc', enable_rpcs=True) target.AppendModifier('cdc', enable_cdc=True) + target.AppendModifier('mot', use_matter_openthread=True) target.AppendModifier('resetCnt', enable_resetCnt=True) - target.AppendModifier('rotating_device_id', enable_rotating_device_id=True) - target.AppendModifier('mfd', function_mfd=BouffalolabMfd.MFD_RELEASE) - target.AppendModifier('mfdtest', function_mfd=BouffalolabMfd.MFD_TEST) - target.AppendModifier('ethernet', enable_ethernet=True) - target.AppendModifier('wifi', enable_wifi=True) - target.AppendModifier('thread', enable_thread=True) - target.AppendModifier('fp', enable_frame_ptr=True) target.AppendModifier('memmonitor', enable_heap_monitoring=True) - target.AppendModifier('mot', use_matter_openthread=True) + target.AppendModifier('115200', baudrate=115200) + target.AppendModifier('fp', enable_frame_ptr=True) return target diff --git a/scripts/build/builders/bouffalolab.py b/scripts/build/builders/bouffalolab.py index a8adfbb2a32b74..af0002457b3270 100644 --- a/scripts/build/builders/bouffalolab.py +++ b/scripts/build/builders/bouffalolab.py @@ -67,12 +67,6 @@ def GnArgName(self): raise Exception('Unknown board #: %r' % self) -class BouffalolabMfd(Enum): - MFD_DISABLE = auto() - MFD_TEST = auto() - MFD_RELEASE = auto() - - class BouffalolabBuilder(GnBuilder): def __init__(self, @@ -87,13 +81,14 @@ def __init__(self, enable_cdc: bool = False, enable_resetCnt: bool = False, enable_rotating_device_id: bool = False, - function_mfd: BouffalolabMfd = BouffalolabMfd.MFD_DISABLE, + enable_mfd: bool = False, enable_ethernet: bool = False, enable_wifi: bool = False, enable_thread: bool = False, enable_frame_ptr: bool = False, enable_heap_monitoring: bool = False, - use_matter_openthread: bool = False + use_matter_openthread: bool = False, + enable_easyflash: bool = False, ): if 'BL602' == module_type: @@ -113,16 +108,14 @@ def __init__(self, self.argsOpt = [] self.chip_name = bouffalo_chip - self.enable_frame_ptr = enable_frame_ptr + self.app = app + self.board = board toolchain = os.path.join(root, os.path.split(os.path.realpath(__file__))[0], '../../../config/bouffalolab/toolchain') toolchain = f'custom_toolchain="{toolchain}:riscv_gcc"' if toolchain: self.argsOpt.append(toolchain) - self.app = app - self.board = board - self.argsOpt.append(f'board="{self.board.GnArgName()}"') self.argsOpt.append(f'baudrate="{baudrate}"') @@ -135,13 +128,8 @@ def __init__(self, elif bouffalo_chip == "bl702l": enable_wifi, enable_thread, enable_ethernet = False, True, False - if (enable_ethernet or enable_wifi) and enable_thread: - raise Exception('Currently, Thread can NOT be enabled with Wi-Fi or Ethernet') - - if enable_thread: - chip_mdns = "platform" - elif enable_ethernet or enable_wifi: - chip_mdns = "minimal" + if [enable_wifi, enable_thread, enable_ethernet].count(True) > 1: + raise Exception('Currently, only one of wifi, thread and ethernet supports.') # hardware connectivity support check if bouffalo_chip == "bl602": @@ -156,6 +144,14 @@ def __init__(self, if enable_ethernet or enable_wifi: raise Exception(f"SoC {bouffalo_chip} does NOT support connectivity Ethernet/Wi-Fi currently.") + if enable_thread: + chip_mdns = "platform" + elif enable_ethernet or enable_wifi: + chip_mdns = "minimal" + + if enable_frame_ptr and bouffalo_chip == "bl616": + raise Exception("BL616 does NOT support frame pointer for debug purpose.") + self.argsOpt.append(f'chip_enable_ethernet={str(enable_ethernet).lower()}') self.argsOpt.append(f'chip_enable_wifi={str(enable_wifi).lower()}') self.argsOpt.append(f'chip_enable_openthread={str(enable_thread).lower()}') @@ -166,13 +162,18 @@ def __init__(self, self.argsOpt.append(f'chip_mdns="{chip_mdns}"') self.argsOpt.append(f'chip_inet_config_enable_ipv4={str(enable_ethernet or enable_wifi).lower()}') + self.argsOpt.append(f'bouffalo_sdk_component_easyflash_enabled=true') + if enable_thread: self.argsOpt.append('chip_system_config_use_open_thread_inet_endpoints=true') self.argsOpt.append('chip_with_lwip=false') self.argsOpt.append(f'openthread_project_core_config_file="{bouffalo_chip}-openthread-core-bl-config.h"') + self.argsOpt.append(f'openthread_package_version="7e32165be"') + if not use_matter_openthread: - self.argsOpt.append( - 'openthread_root="//third_party/connectedhomeip/third_party/bouffalolab/repo/components/network/thread/openthread"') + if bouffalo_chip in {"bl702", "bl702l"}: + self.argsOpt.append( + 'openthread_root="//third_party/connectedhomeip/third_party/bouffalolab/repo/components/network/thread/openthread"') if enable_cdc: if bouffalo_chip != "bl702": @@ -194,12 +195,10 @@ def __init__(self, self.argsOpt.append('chip_enable_additional_data_advertising=true') self.argsOpt.append('chip_enable_rotating_device_id=true') - if BouffalolabMfd.MFD_DISABLE != function_mfd: - if BouffalolabMfd.MFD_RELEASE == function_mfd: - self.argsOpt.append("chip_enable_factory_data=true") - elif BouffalolabMfd.MFD_TEST == function_mfd: - self.argsOpt.append("chip_enable_factory_data_test=true") + if enable_mfd: + self.argsOpt.append("chip_enable_factory_data=true") + self.enable_frame_ptr = enable_frame_ptr self.argsOpt.append(f"enable_debug_frame_ptr={str(enable_frame_ptr).lower()}") self.argsOpt.append(f"enable_heap_monitoring={str(enable_heap_monitoring).lower()}") @@ -211,12 +210,12 @@ def __init__(self, def print_enviroment_error(self): logging.fatal('*' * 80) + logging.error('Flashtool is not installed, or environment variable BOUFFALOLAB_SDK_ROOT is not exported.') logging.fatal('\tPlease make sure Bouffalo Lab SDK installs as below:') - logging.fatal('\t\tcd third_party/bouffalolab/repo') - logging.fatal('\t\tsudo bash scripts/setup.sh') + logging.fatal('\t\t./integrations/docker/images/stage-2/chip-build-bouffalolab/setup.sh') logging.fatal('\tPlease make sure BOUFFALOLAB_SDK_ROOT exports before building as below:') - logging.fatal('\t\texport BOUFFALOLAB_SDK_ROOT=/opt/bouffalolab_sdk') + logging.fatal('\t\texport BOUFFALOLAB_SDK_ROOT="your install path"') logging.fatal('*' * 80) def GnBuildArgs(self): @@ -234,29 +233,32 @@ def build_outputs(self): name = f"{self.app.AppNamePrefix(self.chip_name)}.{ext}" yield BuilderOutput(os.path.join(self.output_dir, name), name) - def PostBuildCommand(self): - - # Generate Bouffalo Lab format OTA image for development purpose. - ota_images_folder_path = self.output_dir + "/ota_images" - ota_images_dev_image = self.output_dir + "/" + self.app.AppNamePrefix(self.chip_name) + ".bin.xz.hash" - ota_images_image = self.output_dir + "/ota_images/FW_OTA.bin.xz.hash" - ota_images_firmware = self.output_dir + "/" + self.app.AppNamePrefix(self.chip_name) + ".bin" - - ota_images_flash_tool = self.output_dir + "/" + self.app.AppNamePrefix(self.chip_name) + ".flash.py" + def PreBuildCommand(self): + os.system("rm -rf {}/config".format(self.output_dir)) + os.system("rm -rf {}/ota_images".format(self.output_dir)) + os.system("rm -rf {}".format(os.path.join(self.output_dir, 'boot2*.bin'))) + os.system("rm -rf {}".format(os.path.join(self.output_dir, '%s*' % self.app.AppNamePrefix(self.chip_name)))) - os.system("rm -rf " + ota_images_folder_path) - os.system("rm -rf " + ota_images_dev_image) + def PostBuildCommand(self): - if not os.path.isfile(ota_images_firmware): - return + abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin") - os.system("python " + ota_images_flash_tool + " --build > /dev/null") + if os.path.isfile(abs_path_fw): + target_dir = self.output_dir.replace(self.chip_dir, "").strip("/") - if not os.path.isfile(ota_images_image): - return + abs_path_fw_bin = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin") + path_fw = os.path.join(target_dir, self.app.AppNamePrefix(self.chip_name) + ".bin") + path_flash_script = os.path.join(target_dir, self.app.AppNamePrefix(self.chip_name) + ".flash.py") - os.system("cp " + ota_images_image + " " + ota_images_dev_image) + logging.info('*' * 80) - logging.info("PostBuild:") - logging.info("Bouffalo Lab unsigned OTA image: " + - self.app.AppNamePrefix(self.chip_name) + ".bin.xz.hash is generated.") + logging.info("Firmware is built out at: {}".format(path_fw)) + logging.info("Command to generate ota image: ") + logging.info('./{} --build-ota --vendor-id --product-id ' + '--version --version-str ' + '--digest-algorithm '.format(path_flash_script)) + logging.info("Command to generate and sign ota image: ") + logging.info('./{} --build-ota --vendor-id --product-id ' + '--version --version-str ' + '--digest-algorithm --sk '.format(path_flash_script)) + logging.info('*' * 80) diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 5242b85c038a22..a8e5b8770caa63 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -1,7 +1,7 @@ ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed} asr-{asr582x,asr595x,asr550x}-{all-clusters,all-clusters-minimal,lighting,light-switch,lock,bridge,temperature-measurement,thermostat,ota-requestor,dishwasher,refrigerator}[-ota][-shell][-no_logging][-factory][-rotating_id][-rio] android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller,kotlin-matter-controller,virtual-device-app}[-no-debug] -bouffalolab-{bl602-iot-matter-v1,bl602-night-light,xt-zb6-devkit,bl706-night-light,bl706dk,bl704ldk}-light[-shell][-115200][-rpc][-cdc][-resetcnt][-rotating_device_id][-mfd][-mfdtest][-ethernet][-wifi][-thread][-fp][-memmonitor][-mot] +bouffalolab-{bl602dk,bl704ldk,bl706dk,bl602-night-light,bl706-night-light,bl602-iot-matter-v1,xt-zb6-devkit}-light[-ethernet][-wifi][-thread][-easyflash][-shell][-mfd][-rotating_device_id][-rpc][-cdc][-mot][-resetcnt][-memmonitor][-115200][-fp] cc32xx-{lock,air-purifier} ti-cc13x4_26x4-{all-clusters,lighting,lock,pump,pump-controller}[-mtd][-ftd] cyw30739-{cyw30739b2_p5_evk_01,cyw30739b2_p5_evk_02,cyw30739b2_p5_evk_03,cyw930739m2evb_01,cyw930739m2evb_02}-{light,light-switch,lock,thermostat} diff --git a/scripts/flashing/bouffalolab_firmware_utils.py b/scripts/flashing/bouffalolab_firmware_utils.py index 402f0453936741..2c4e1cca4c5789 100755 --- a/scripts/flashing/bouffalolab_firmware_utils.py +++ b/scripts/flashing/bouffalolab_firmware_utils.py @@ -13,21 +13,30 @@ # See the License for the specific language governing permissions and # limitations under the License. -import importlib.metadata +import binascii import logging import os import pathlib +import platform import re import shutil +import subprocess import sys import coloredlogs import firmware_utils +import toml +from Crypto.Cipher import AES coloredlogs.install(level='DEBUG') # Additional options that can be use to configure an `Flasher` # object (as dictionary keys) and/or passed as command line options. + + +def any_base_int(s): return int(s, 0) + + BOUFFALO_OPTIONS = { # Configuration options define properties used in flashing operations. 'configuration': { @@ -39,7 +48,7 @@ } }, 'pt': { - 'help': 'Partition table for board', + 'help': 'Partition table for board for bl iot sdk', 'default': None, 'argparse': { 'metavar': 'PARTITION_TABLE_FILE', @@ -47,7 +56,7 @@ } }, 'dts': { - 'help': 'Device tree file', + 'help': 'Device tree file for bl iot sdk', 'default': None, 'argparse': { 'metavar': 'DEVICE_TREE_FILE', @@ -55,7 +64,7 @@ } }, 'xtal': { - 'help': 'XTAL for board', + 'help': 'XTAL configuration for bl iot sdk', 'default': None, 'argparse': { 'metavar': 'XTAL', @@ -75,84 +84,456 @@ 'metavar': 'BAUDRATE', }, }, - 'build': { - 'help': 'Build OTA image', + 'sk': { + 'help': 'private key to sign firmware to flash or sign ota image.', 'default': None, 'argparse': { - 'action': 'store_true' + 'metavar': 'path', + 'type': pathlib.Path } }, - 'ota': { - 'help': 'output directory of ota image build', + 'mfd': { + 'help': 'matter factory data', 'default': None, 'argparse': { - 'metavar': 'DIR', + 'metavar': 'path', 'type': pathlib.Path } }, - 'pk': { - 'help': 'public key to sign firmware to flash or sign ota image.', + 'mfd-str': { + 'help': 'matter factory data string, only available for using bl iot sdk', 'default': None, 'argparse': { - 'metavar': 'path', - 'type': pathlib.Path + 'metavar': 'mfd_str', } }, - 'sk': { - 'help': 'private key to sign firmware to flash or sign ota image.', + 'key': { + 'help': 'data key in security engine for matter factory data decryption', 'default': None, 'argparse': { - 'metavar': 'path', - 'type': pathlib.Path + 'metavar': 'key', } }, 'boot2': { - 'help': 'boot2 image.', + 'help': 'boot2 image', + 'default': None, + 'argparse': { + 'metavar': 'path', + } + }, + 'config': { + 'help': 'firmware programming configuration for bouffalo sdk', 'default': None, 'argparse': { 'metavar': 'path', } + }, + 'build-ota': { + 'help': 'build ota image', + 'default': None, + 'argparse': { + 'action': 'store_true' + }, + }, + 'vendor-id': { + 'help': 'vendor id passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'vendor_id', + "type": any_base_int + } + }, + 'product-id': { + 'help': 'product id passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'product_id', + "type": any_base_int + } + }, + 'version': { + 'help': 'software version (numeric) passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'version', + "type": any_base_int + } + }, + 'version-str': { + 'help': 'software version string passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'version_str', + } + }, + 'digest-algorithm': { + 'help': 'digest algorithm passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'digest_algorithm', + } + }, + "min-version": { + 'help': 'minimum software version passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'min_version', + "type": any_base_int + } + }, + "max-version": { + 'help': 'maximum software version passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'max_version', + "type": any_base_int + } + }, + "release-notes": { + 'help': 'release note passes to ota_image_tool.py ota image if --build-ota present', + 'default': None, + 'argparse': { + 'metavar': 'release_notes', + } } }, } +MATTER_ROOT = os.getcwd() + + +class DictObject: + def __init__(self, data_dict): + for key, value in data_dict.items(): + if isinstance(value, dict): + self.__dict__[key] = DictObject(value) + else: + self.__dict__[key] = value + + def __getattr__(self, name): + return self.__dict__.get(name, None) + + def __setattr__(self, name, value): + self.__dict__[name] = value + + def __repr__(self): + return str(self.__dict__) + class Flasher(firmware_utils.Flasher): - isErase = False + args = {} + work_dir = None def __init__(self, **options): super().__init__(platform=None, module=__name__, **options) self.define_options(BOUFFALO_OPTIONS) - def get_boot_image(self, config_path, boot2_image): + def find_file(self, path_dir, name_partten): - boot_image_guess = None + ret_files = [] - for root, dirs, files in os.walk(config_path, topdown=False): + for root, dirs, files in os.walk(path_dir, topdown=False): for name in files: - logging.info("get_boot_image {} {}".format(root, boot2_image)) - if boot2_image: - return os.path.join(root, boot2_image) + if re.match(name_partten, name): + ret_files.append(os.path.join(root, name)) + + return ret_files + + def parse_mfd(self): + + def decrypt_data(data_bytearray, key_bytearray, iv_bytearray): + data_bytearray += bytes([0] * (16 - (len(data_bytearray) % 16))) + cryptor = AES.new(key_bytearray, AES.MODE_CBC, iv_bytearray) + plaintext = cryptor.decrypt(data_bytearray) + return plaintext + + self.args["iv"] = None + + if not self.args["mfd"] and not self.args["mfd_str"]: + return None + + if self.args['mfd_str']: + try: + iv = self.args['mfd_str'].split(":")[1].split(',')[0] + except Exception: + raise Exception("Invalid mfd-str format.") + + self.args["iv"] = iv + return self.args['mfd_str'] + + with open(self.args["mfd"], 'rb') as f: + bytes_obj = f.read() + + sec_len = int.from_bytes(bytes_obj[0:4], byteorder='little') + if sec_len: + crc_val_calc = binascii.crc32(bytes_obj[4: 4 + sec_len]) + crc_val = int.from_bytes(bytes_obj[4 + sec_len: 4 + sec_len + 4], byteorder='little') + if crc_val_calc != crc_val: + raise Exception("MFD partition file has invalid format in secured data.") + bytes_sec = bytes_obj[4: 4 + sec_len] + + if not self.args["key"]: + raise Exception("MFD has secured data, but no key input.") + else: + bytes_sec = [] + + raw_start = 4 + sec_len + 4 + raw_len = int.from_bytes(bytes_obj[raw_start: raw_start + 4], byteorder='little') + if raw_len: + crc_val_calc = binascii.crc32(bytes_obj[raw_start + 4: raw_start + 4 + raw_len]) + crc_val = int.from_bytes(bytes_obj[raw_start + 4 + raw_len: raw_start + 4 + raw_len + 4], byteorder='little') + if crc_val_calc != crc_val: + raise Exception("MFD partition file has invalid format in raw data.") + bytes_raw = bytes_obj[raw_start + 4: raw_start + 4 + raw_len] + else: + bytes_raw = [] + + offset = 0 + dict_raw = {} + while offset < raw_len: + type_id = int.from_bytes(bytes_raw[offset: offset + 2], byteorder='little') + type_len = int.from_bytes(bytes_raw[offset + 2: offset + 4], byteorder='little') + + if 0x8001 == type_id: + self.args["iv"] = bytes_raw[offset + 4: offset + 4 + type_len] + + if offset + 4 + type_len <= raw_len: + dict_raw[type_id] = bytes(bytes_raw[offset + 4: offset + 4 + type_len]).hex() + + offset += (4 + type_len) + + if sec_len > 0 and self.args["key"] and not self.args["iv"]: + raise Exception("No IV found in secured mfd data.") + + offset = 0 + dict_sec = {} + if bytes_sec and self.args["iv"] and self.args["key"]: + + bytes_sec = decrypt_data(bytes_sec, bytearray.fromhex(self.args["key"]), self.args["iv"]) + while offset < raw_len: + type_id = int.from_bytes(bytes_sec[offset: offset + 2], byteorder='little') + type_len = int.from_bytes(bytes_sec[offset + 2:offset + 4], byteorder='little') + + if offset + 4 + type_len <= sec_len: + dict_sec[type_id] = bytes(bytes_sec[offset + 4: offset + 4 + type_len]).hex() + + offset += (4 + type_len) + + self.args["iv"] = self.args["iv"].hex() + + mfd_str = "" + if dict_sec.keys(): + for idx in range(1, 1 + max(dict_sec.keys())): + if idx in dict_sec.keys(): + mfd_str += dict_sec[idx] + "," else: - if name == "boot2_isp_release.bin": - return os.path.join(root, name) - elif not boot_image_guess and name.find("release") >= 0: - boot_image_guess = os.path.join(root, name) + mfd_str += "," - return boot_image_guess + mfd_str = mfd_str + ":" + for idx in range(0x8001, 1 + max(dict_raw.keys())): + if idx in dict_raw.keys(): + mfd_str += dict_raw[idx] + "," + else: + mfd_str += "," - def get_dts_file(self, config_path, xtal_value, chip_name): + self.args["mfd_str"] = mfd_str - for root, dirs, files in os.walk(config_path, topdown=False): - for name in files: - if chip_name == 'bl702': - if name.find("bl_factory_params_IoTKitA_32M.dts") >= 0: - return os.path.join(config_path, name) + return self.args['mfd_str'] + + def iot_sdk_prog(self): + + def get_tools(): + flashtool_path = os.environ.get('BOUFFALOLAB_SDK_ROOT') + "/flashtool/BouffaloLabDevCube-v1.9.0" + bflb_tools_dict = { + "linux": {"flash_tool": "bflb_iot_tool-ubuntu"}, + "win32": {"flash_tool": "bflb_iot_tool.exe"}, + "darwin": {"flash_tool": "bflb_iot_tool-macos"}, + } + + try: + flashtool_exe = flashtool_path + "/" + bflb_tools_dict[sys.platform]["flash_tool"] + except Exception: + raise Exception("Do NOT support {} operating system to program firmware.".format(sys.platform)) + + if not os.path.exists(flashtool_exe): + logging.fatal('*' * 80) + logging.error('Flashtool is not installed, or environment variable BOUFFALOLAB_SDK_ROOT is not exported.') + logging.fatal('\tPlease make sure Bouffalo Lab SDK installs as below:') + logging.fatal('\t\t./third_party/bouffalolab/env-setup.sh') + + logging.fatal('\tPlease make sure BOUFFALOLAB_SDK_ROOT exports before building as below:') + logging.fatal('\t\texport BOUFFALOLAB_SDK_ROOT="your install path"') + logging.fatal('*' * 80) + raise Exception("Flash tool is not installed.") + + return flashtool_path, flashtool_exe + + def get_dts_file(flashtool_path, dts): + + if dts: + return dts + else: + return os.path.join(flashtool_path, "chips", self.args["chipname"], + "device_tree", "bl_factory_params_IoTKitA_{}.dts".format(self.args["xtal"])) + + def get_boot_image(flashtool_path, boot2_image): + + if boot2_image: + return boot2_image + + if self.args["chipname"] in ["bl702l"]: + return None + + builtin_imgs_path = os.path.join(flashtool_path, "chips", self.args["chipname"], "builtin_imgs") + boot2_images = self.find_file(builtin_imgs_path, r'boot2_isp_release.bin') + if len(boot2_images) > 1: + raise Exception("More than one boot2 image found.") + if len(boot2_images) == 0: + raise Exception("No boot2 image found.") + + return boot2_images[0] + + def get_mfd_addr(): + with open(self.args["pt"], 'r') as file: + partition_config = toml.load(file) + + mfd_addr = None + for v in partition_config["pt_entry"]: + if v["name"] == "MFD" or v["name"] == "mfd": + mfd_addr = v["address0"] + + return mfd_addr + + def exe_gen_ota_image_cmd(flashtool_exe): + + os.system("rm -rf {}/FW_OTA.bin*".format(self.work_dir)) + os.system("rm -rf {}/ota_images".format(self.work_dir)) + + if not self.args["build_ota"]: + return + + gen_ota_img_cmd = [ + flashtool_exe, + "--build", + "--chipname", self.args["chipname"], + "--dts", self.args["dts"], + "--firmware", self.args["firmware"], + "--pt", self.args["pt"], + "--ota", self.work_dir + ] + + if self.args["sk"]: + gen_ota_img_cmd += ["--sk", self.args["sk"]] + + logging.info("ota image generating: {}".format(" ".join(gen_ota_img_cmd))) + process = subprocess.Popen(gen_ota_img_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + while process.poll() is None: + line = process.stdout.readline().decode('utf-8').rstrip() + if line: + logging.info(line) + + fw_ota_images = self.find_file(self.work_dir, r'^FW_OTA.+\.hash$') + if not fw_ota_images or 0 == len(fw_ota_images): + raise Exception("Failed to generate Bouffalo Lab OTA image.") + + os.system("mkdir -p {}/ota_images".format(self.work_dir)) + fw_name = os.path.basename(self.args["firmware"])[:-len(".bin")] + for img in fw_ota_images: + ota_img_name = os.path.basename(img) + new_name = os.path.join(self.work_dir, "ota_images", fw_name + ota_img_name[len("FW_OTA"):]) + os.system("mv {} {}".format(img, new_name)) + + def exe_prog_cmd(flashtool_exe, mfd_addr): + + if not self.args["port"]: + return + + if self.args["mfd"] and not mfd_addr: + raise Exception("No MFD partition found in partition table.") + + prog_cmd = [ + flashtool_exe, + "--port", self.args["port"], + "--baudrate", self.args["baudrate"], + "--chipname", self.args["chipname"], + "--firmware", self.args["firmware"], + "--dts", self.args["dts"], + "--pt", self.args["pt"], + ] + + if self.args["boot2"]: + prog_cmd += ["--boot2", self.args["boot2"]] + + if self.args["sk"]: + prog_cmd += ["--sk", self.args["sk"]] + + if mfd_addr and self.args["mfd_str"]: + if self.args["key"] and not self.args["iv"]: + logging.warning("mfd file has no iv, do NOT program mfd key.") else: - if name.find(xtal_value) >= 0: - return os.path.join(config_path, name) - return None + prog_cmd += ["--dac_key", self.args["key"]] + prog_cmd += ["--dac_iv", self.args["iv"]] + prog_cmd += ["--dac_addr", hex(mfd_addr)] + prog_cmd += ["--dac_value", self.args["mfd_str"]] + + if self.option.erase: + prog_cmd += ["--erase"] + + logging.info("firmware programming: {}".format(" ".join(prog_cmd))) + process = subprocess.Popen(prog_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + while process.poll() is None: + line = process.stdout.readline().decode('utf-8').rstrip() + if line: + logging.info(line) + + flashtool_path, flashtool_exe = get_tools() + self.args["pt"] = os.path.join(os.getcwd(), str(self.args["pt"])) + mfd_addr = get_mfd_addr() + + self.parse_mfd() + self.args["dts"] = get_dts_file(flashtool_path, self.args["dts"]) + self.args["boot2"] = get_boot_image(flashtool_path, self.args["boot2"]) + + os.chdir(self.work_dir) + + exe_gen_ota_image_cmd(flashtool_exe) + exe_prog_cmd(flashtool_exe, mfd_addr) + + def gen_ota_image(self): + sys.path.insert(0, os.path.join(MATTER_ROOT, 'src', 'app')) + import ota_image_tool + + bflb_ota_images = self.find_file(os.path.join(self.work_dir, "ota_images"), r".+\.(ota|hash)$") + if len(bflb_ota_images) == 0: + raise Exception("No bouffalo lab OTA image found.") + + ota_image_cfg_list = [ + "vendor_id", + "product_id", + "version", + "version_str", + "digest_algorithm", + "min_version", + "max_version", + "release_notes", + ] + ota_image_cfg = {} + for k in ota_image_cfg_list: + if self.args[k] is not None: + ota_image_cfg[k] = self.args[k] + ota_image_cfg = DictObject(ota_image_cfg) + + for img in bflb_ota_images: + ota_image_cfg.input_files = [img] + ota_image_cfg.output_file = img + ".matter" + ota_image_tool.validate_header_attributes(ota_image_cfg) + ota_image_tool.generate_image(ota_image_cfg) + + if re.match(r".+\.(xz.ota|xz.hash)$", img): + self.log(0, 'Matter OTA compressed image generated: {}'.format(ota_image_cfg.output_file)) + else: + self.log(0, 'Matter OTA image generated: {}'.format(ota_image_cfg.output_file)) def verify(self): """Not supported""" @@ -166,159 +547,38 @@ def actions(self): """Perform actions on the device according to self.option.""" self.log(3, 'Options:', self.option) - try: - import bflb_iot_tool - import bflb_iot_tool.__main__ - - version_target_str = "1.8.6" - version_target = version_target_str.split('.') - version_target = "".join(["%03d" % int(var) for var in version_target]) - - version_current_str = importlib.metadata.version("bflb_iot_tool") - version_current = version_current_str.split('.') - version_current = "".join(["%03d" % int(var) for var in version_current]) - - if version_current < version_target: - raise Exception("bflb_iot_tool {} version is less than {}".format(version_current_str, version_target_str)) - - except Exception as e: - - logging.error('Please try the following command to setup or upgrade Bouffalo Lab environment:') - logging.error('source scripts/activate.sh -p bouffalolab') - logging.error('Or') - logging.error('source scripts/bootstrap.sh -p bouffalolab') - - logging.error('If upgrade bflb_iot_tool failed, try pip uninstall bflb_iot_tool first.') - - raise Exception(e) - - tool_path = os.path.dirname(bflb_iot_tool.__file__) - - options_keys = BOUFFALO_OPTIONS["configuration"].keys() - arguments = [__file__] - work_dir = None + if platform.machine() not in ["x86_64"]: + raise Exception("Only support x86_64 CPU machine to program firmware.") if self.option.reset: self.reset() if self.option.verify_application: self.verify() - chip_name = None - chip_config_path = None - boot2_image = None - dts_path = None - xtal_value = None + self.args = dict(vars(self.option)) + self.args["application"] = os.path.join(os.getcwd(), str(self.args["application"])) + self.work_dir = os.path.dirname(self.args["application"]) + if self.args["sk"]: + self.args["sk"] = str(self.args["sk"]) - is_for_ota_image_building = None - is_for_programming = False - has_private_key = False - has_public_key = False - ota_output_folder = None + if self.args["mfd"]: + self.args["mfd"] = os.path.join(MATTER_ROOT, str(self.args["mfd"])) - boot2_image = None + self.args["application"] = os.path.join(os.getcwd(), str(self.args["application"])) + self.args["firmware"] = str(pathlib.Path(self.args["application"]).with_suffix(".bin")) + if self.args["application"] != self.args["firmware"]: + shutil.copy2(self.args["application"], self.args["firmware"]) - command_args = {} - for (key, value) in dict(vars(self.option)).items(): + if self.args["build_ota"]: + if self.args["port"]: + raise Exception("Do not generate OTA image with firmware programming.") - if self.option.build and value: - if "port" in command_args.keys(): - continue - else: - if "ota" in command_args.keys(): - continue - - if key == "application": - key = "firmware" - work_dir = os.path.dirname(os.path.join(os.getcwd(), str(value))) - elif key == "boot2": - boot2_image = value - continue - elif key in options_keys: - pass - else: - continue + if self.args["mfd"] and self.args["mfd_str"]: + raise Exception("Cannot use option mfd and mfd-str together.") + self.iot_sdk_prog() - if value: - if value is True: - arg = ("--{}".format(key)).strip() - elif isinstance(value, pathlib.Path): - arg = ("--{}={}".format(key, os.path.join(os.getcwd(), str(value)))).strip() - else: - arg = ("--{}={}".format(key, value)).strip() - - arguments.append(arg) - - if key == "chipname": - chip_name = value - elif key == "xtal": - xtal_value = value - elif key == "dts": - dts_path = value - elif "port" == key: - if value: - is_for_programming = True - elif "build" == key: - if value: - is_for_ota_image_building = True - elif "pk" == key: - if value: - has_public_key = True - elif "sk" == key: - if value: - has_private_key = True - elif "ota" == key and value: - ota_output_folder = os.path.join(os.getcwd(), value) - - if is_for_ota_image_building and is_for_programming: - logging.error("ota imge build can't work with image programming") - raise Exception("Wrong operation.") - - if not ((has_private_key and has_public_key) or (not has_public_key and not has_private_key)): - logging.error("Key pair expects a pair of public key and private.") - raise Exception("Wrong key pair.") - - if is_for_ota_image_building == "ota_sign" and (not has_private_key or not has_public_key): - logging.error("Expecting key pair to sign OTA image.") - raise Exception("Wrong key pair.") - - if not dts_path and xtal_value: - chip_config_path = os.path.join(tool_path, "chips", chip_name, "device_tree") - dts_path = self.get_dts_file(chip_config_path, xtal_value, chip_name) - arguments.append("--dts") - arguments.append(dts_path) - - if boot2_image: - chip_config_path = os.path.join(tool_path, "chips", chip_name, "builtin_imgs") - boot2_image = self.get_boot_image(chip_config_path, boot2_image) - arguments.append("--boot2") - arguments.append(boot2_image) - else: - if self.option.erase: - arguments.append("--erase") - - if chip_name in {"bl602", "bl702"}: - chip_config_path = os.path.join(tool_path, "chips", chip_name, "builtin_imgs") - boot2_image = self.get_boot_image(chip_config_path, boot2_image) - arguments.append("--boot2") - arguments.append(boot2_image) - - os.chdir(work_dir) - arguments[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', arguments[0]) - sys.argv = arguments - - if ota_output_folder: - if os.path.exists(ota_output_folder): - shutil.rmtree(ota_output_folder) - os.mkdir(ota_output_folder) - - logging.info("Arguments {}".format(arguments)) - bflb_iot_tool.__main__.run_main() - - if ota_output_folder: - ota_images = os.listdir(ota_output_folder) - for img in ota_images: - if img not in ['FW_OTA.bin.xz.hash']: - os.remove(os.path.join(ota_output_folder, img)) + if self.args["build_ota"]: + self.gen_ota_image() return self diff --git a/scripts/setup/requirements.bouffalolab.txt b/scripts/setup/requirements.bouffalolab.txt index a66a47943e913a..933330c0a4ad82 100644 --- a/scripts/setup/requirements.bouffalolab.txt +++ b/scripts/setup/requirements.bouffalolab.txt @@ -1,7 +1,7 @@ -bflb-iot-tool>=1.8.6 jsonschema>=4.4.0 cbor2>=5.4.3 ecdsa>=0.18.0 qrcode==7.4.2 bitarray==2.6.0 python_stdnum==1.18 +pycryptodome>=3.20.0 \ No newline at end of file diff --git a/src/lib/shell/streamer_bouffalolab.cpp b/src/lib/shell/streamer_bouffalolab.cpp index ae22227dc4dd90..9a7b669ae47088 100644 --- a/src/lib/shell/streamer_bouffalolab.cpp +++ b/src/lib/shell/streamer_bouffalolab.cpp @@ -20,6 +20,7 @@ * Source implementation of an input / output stream for Bouffalo Lab targets. */ +#include #include #include diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index 6d7e58d8a59fff..145bc2dd1d0183 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -64,6 +64,7 @@ if (lwip_platform == "cc13xx_26xx") { import("${chip_root}/src/platform/device.gni") } else if (lwip_platform == "bl702l") { import("//build_overrides/bouffalolab_iot_sdk.gni") + import("${chip_root}/src/platform/device.gni") } else if (lwip_platform == "nxp") { import("//build_overrides/nxp_sdk.gni") } else if (lwip_platform == "mw320") { diff --git a/src/platform/bouffalolab/BL602/BUILD.gn b/src/platform/bouffalolab/BL602/BUILD.gn index 215131d87be32d..a85ab72011242a 100644 --- a/src/platform/bouffalolab/BL602/BUILD.gn +++ b/src/platform/bouffalolab/BL602/BUILD.gn @@ -34,7 +34,6 @@ static_library("BL602") { sources += [ "../../FreeRTOS/SystemTimeSupport.cpp", "../../SingletonConfigurationManager.cpp", - "../common/BLConfig.cpp", "../common/ConfigurationManagerImpl.cpp", "../common/ConnectivityManagerImpl.cpp", "../common/DiagnosticDataProviderImpl.cpp", @@ -56,15 +55,17 @@ static_library("BL602") { ] } - defines = - [ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ] - if (chip_enable_factory_data || chip_enable_factory_data_test) { + if (chip_enable_factory_data) { sources += [ "../common/FactoryDataProvider.cpp", "../common/FactoryDataProvider.h", ] } + if (bouffalo_sdk_component_easyflash_enabled) { + sources += [ "../common/BLConfig.cpp" ] + } + deps = [ "${chip_root}/src/credentials:credentials_header", "${chip_root}/src/lib/dnssd:platform_header", diff --git a/src/platform/bouffalolab/BL702/BUILD.gn b/src/platform/bouffalolab/BL702/BUILD.gn index 7bf2b615d42294..a305b0d9db00ad 100644 --- a/src/platform/bouffalolab/BL702/BUILD.gn +++ b/src/platform/bouffalolab/BL702/BUILD.gn @@ -36,7 +36,6 @@ static_library("BL702") { sources += [ "../../FreeRTOS/SystemTimeSupport.cpp", "../../SingletonConfigurationManager.cpp", - "../common/BLConfig.cpp", "../common/ConfigurationManagerImpl.cpp", "../common/ConnectivityManagerImpl.cpp", "../common/DiagnosticDataProviderImpl.cpp", @@ -60,15 +59,17 @@ static_library("BL702") { deps = [ "${chip_root}/src/platform/logging:headers" ] - defines = - [ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ] - if (chip_enable_factory_data || chip_enable_factory_data_test) { + if (chip_enable_factory_data) { sources += [ "../common/FactoryDataProvider.cpp", "../common/FactoryDataProvider.h", ] } + if (bouffalo_sdk_component_easyflash_enabled) { + sources += [ "../common/BLConfig.cpp" ] + } + if (chip_enable_wifi) { sources += [ "ConfigurationManagerImpl.cpp", diff --git a/src/platform/bouffalolab/BL702/bl702-openthread-core-bl-config.h b/src/platform/bouffalolab/BL702/bl702-openthread-core-bl-config.h index 220a843b9e60b8..6edc822faf12cc 100644 --- a/src/platform/bouffalolab/BL702/bl702-openthread-core-bl-config.h +++ b/src/platform/bouffalolab/BL702/bl702-openthread-core-bl-config.h @@ -26,39 +26,74 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OPENTHREAD_CORE_BL702_CONFIG_H_ -#define OPENTHREAD_CORE_BL702_CONFIG_H_ +#ifndef OPENTHREAD_CORE_PROJ_CONFIG_H +#define OPENTHREAD_CORE_PROJ_CONFIG_H -/** - * @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE - * - * Define to 1 to enable NCP HDLC support. - * - */ -#ifndef OPENTHREAD_CONFIG_NCP_HDLC_ENABLE -#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 0 +#define OPENTHREAD_CONFIG_PLATFORM_INFO "BL702" + +// #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG + +#if !defined(OPENTHREAD_FTD) && !defined(OPENTHREAD_MTD) +#if CHIP_DEVICE_CONFIG_THREAD_FTD +#define OPENTHREAD_FTD 1 +#define OPENTHREAD_MTD 0 +#else +#define OPENTHREAD_FTD 0 +#define OPENTHREAD_MTD 1 +#endif #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE - * - * Define to 1 to enable otPlatFlash* APIs to support non-volatile storage. - * - * When defined to 1, the platform MUST implement the otPlatFlash* APIs instead of the otPlatSettings* APIs. - * - */ -#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 0 +#define OPENTHREAD_CONFIG_PING_SENDER_ENABLE 1 + +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1 +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 1 + +#define OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE 1 +#define OPENTHREAD_CONFIG_DUA_ENABLE 1 +#define OPENTHREAD_CONFIG_MLR_ENABLE 1 + +#define OPENTHREAD_CONFIG_IP6_FRAGMENTATION_ENABLE 1 + +#define OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 1 +#define OPENTHREAD_CONFIG_TMF_ANYCAST_LOCATOR_ENABLE 1 +#define OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE 1 + +// #define OPENTHREAD_CONFIG_COAP_API_ENABLE 1 +// #define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 1 +// #define OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE 1 + +#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1 +#define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE 1 + +#define OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE 1 + +#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 +#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE 1 + +// #define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 1 -#define OPENTHREAD_RADIO 0 +// #define OPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE 1 +// #define OPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE 1 -#ifndef LMAC154_RADIO_RECEIVE_SENSITIVITY -#define LMAC154_RADIO_RECEIVE_SENSITIVITY -103 +#if OPENTHREAD_FTD +#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 1 +#define OPENTHREAD_CONFIG_JOINER_ENABLE 1 #endif -#ifndef OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY -#define OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY 40 +#if OPENTHREAD_MTD +#define OPENTHREAD_CONFIG_JOINER_ENABLE 1 #endif +#define OPENTHREAD_CONFIG_TCP_ENABLE 0 +#define OPENTHREAD_CONFIG_TLS_ENABLE 0 +#define OPENTHREAD_CONFIG_SRP_SERVER_ENABLE 0 +#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0 +#define OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE 0 + #define OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE 0 #define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE 1 #define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 0 @@ -67,31 +102,13 @@ #define OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE 1 #define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 - #define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 1 -#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1 -#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 -#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1 -#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 1 -#define OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE 1 - -#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 0 -#define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 0 -// #define OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE 0 -#define OPENTHREAD_CONFIG_TCP_ENABLE 0 -#define OPENTHREAD_CONFIG_TLS_ENABLE 0 - -#define OPENTHREAD_CONFIG_PING_SENDER_ENABLE 1 -// #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG - -#define OPENTHREAD_ENABLE_VENDOR_EXTENSION 0 #define OPENTHREAD_EXAMPLES_SIMULATION 0 +#define OPENTHREAD_PLATFORM_POSIX 0 +#define OPENTHREAD_ENABLE_VENDOR_EXTENSION 0 -#ifndef OPENTHREAD_CONFIG_DIAG_ENABLE -#define OPENTHREAD_CONFIG_DIAG_ENABLE 0 -#endif - -#define ENABLE_OPENTHREAD_BORDER_ROUTER 0 +#define IEEE802_15_4_RADIO_RECEIVE_SENSITIVITY -105 +#define OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY 40 -#endif // OPENTHREAD_CORE_BL702_CONFIG_H_ +#endif // OPENTHREAD_CORE_PROJ_CONFIG_H diff --git a/src/platform/bouffalolab/BL702L/BUILD.gn b/src/platform/bouffalolab/BL702L/BUILD.gn index d688878c6ceb82..d85f727fed4ea3 100644 --- a/src/platform/bouffalolab/BL702L/BUILD.gn +++ b/src/platform/bouffalolab/BL702L/BUILD.gn @@ -34,7 +34,6 @@ static_library("BL702L") { sources += [ "../../FreeRTOS/SystemTimeSupport.cpp", "../../SingletonConfigurationManager.cpp", - "../common/BLConfig.cpp", "../common/ConfigurationManagerImpl.cpp", "../common/ConnectivityManagerImpl.cpp", "../common/DiagnosticDataProviderImpl.cpp", @@ -58,15 +57,17 @@ static_library("BL702L") { deps = [ "${chip_root}/src/platform/logging:headers" ] - defines = - [ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ] - if (chip_enable_factory_data || chip_enable_factory_data_test) { + if (chip_enable_factory_data) { sources += [ "../common/FactoryDataProvider.cpp", "../common/FactoryDataProvider.h", ] } + if (bouffalo_sdk_component_easyflash_enabled) { + sources += [ "../common/BLConfig.cpp" ] + } + if (chip_enable_openthread) { # needed for MTD/FTD diff --git a/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp b/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp index d72c1090064968..68c75305f64ed8 100644 --- a/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp @@ -37,7 +37,6 @@ extern "C" { namespace chip { namespace DeviceLayer { -extern "C" void (*ot_otrNotifyEvent_ptr)(ot_system_event_t sevent); extern "C" int bl_rand_stream(unsigned char *, int); extern "C" void otrNotifyEvent(ot_system_event_t sevent); @@ -63,7 +62,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) opt.bf.isCoexEnable = true; ot_utils_init(); - ot_otrNotifyEvent_ptr = otrNotifyEvent; ot_alarmInit(); ot_radioInit(opt); diff --git a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp index bc6a558b20f6c2..784dfa396cd371 100644 --- a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp @@ -32,17 +32,12 @@ #include #include -extern "C" { -#include -} - namespace chip { namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; ThreadStackManagerImpl ThreadStackManagerImpl::sInstance; -extern "C" void (*ot_otrNotifyEvent_ptr)(ot_system_event_t sevent); CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack(void) { @@ -108,6 +103,31 @@ extern "C" otInstance * otrGetInstance() return ThreadStackMgrImpl().OTInstance(); } +extern "C" uint32_t otrEnterCrit(void) +{ + if (xPortIsInsideInterrupt()) + { + return taskENTER_CRITICAL_FROM_ISR(); + } + else + { + taskENTER_CRITICAL(); + return 0; + } +} + +extern "C" void otrExitCrit(uint32_t tag) +{ + if (xPortIsInsideInterrupt()) + { + taskEXIT_CRITICAL_FROM_ISR(tag); + } + else + { + taskEXIT_CRITICAL(); + } +} + extern "C" ot_system_event_t otrGetNotifyEvent(void) { ot_system_event_t sevent = OT_SYSTEM_EVENT_NONE; diff --git a/src/platform/bouffalolab/BL702L/bl702l-openthread-core-bl-config.h b/src/platform/bouffalolab/BL702L/bl702l-openthread-core-bl-config.h index 220a843b9e60b8..6937bba875750b 100644 --- a/src/platform/bouffalolab/BL702L/bl702l-openthread-core-bl-config.h +++ b/src/platform/bouffalolab/BL702L/bl702l-openthread-core-bl-config.h @@ -26,39 +26,74 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OPENTHREAD_CORE_BL702_CONFIG_H_ -#define OPENTHREAD_CORE_BL702_CONFIG_H_ +#ifndef OPENTHREAD_CORE_PROJ_CONFIG_H +#define OPENTHREAD_CORE_PROJ_CONFIG_H -/** - * @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE - * - * Define to 1 to enable NCP HDLC support. - * - */ -#ifndef OPENTHREAD_CONFIG_NCP_HDLC_ENABLE -#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 0 +#define OPENTHREAD_CONFIG_PLATFORM_INFO "BL702L" + +// #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG + +#if !defined(OPENTHREAD_FTD) && !defined(OPENTHREAD_MTD) +#if CHIP_DEVICE_CONFIG_THREAD_FTD +#define OPENTHREAD_FTD 1 +#define OPENTHREAD_MTD 0 +#else +#define OPENTHREAD_FTD 0 +#define OPENTHREAD_MTD 1 +#endif #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE - * - * Define to 1 to enable otPlatFlash* APIs to support non-volatile storage. - * - * When defined to 1, the platform MUST implement the otPlatFlash* APIs instead of the otPlatSettings* APIs. - * - */ -#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 0 +#define OPENTHREAD_CONFIG_PING_SENDER_ENABLE 1 + +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1 +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 1 + +#define OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE 1 +#define OPENTHREAD_CONFIG_DUA_ENABLE 1 +#define OPENTHREAD_CONFIG_MLR_ENABLE 1 + +#define OPENTHREAD_CONFIG_IP6_FRAGMENTATION_ENABLE 1 + +#define OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 1 +#define OPENTHREAD_CONFIG_TMF_ANYCAST_LOCATOR_ENABLE 1 +#define OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE 1 + +// #define OPENTHREAD_CONFIG_COAP_API_ENABLE 1 +// #define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 1 +// #define OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE 1 + +#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1 +#define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE 1 + +#define OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE 1 + +#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 +#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE 1 + +// #define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 1 -#define OPENTHREAD_RADIO 0 +// #define OPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE 1 +// #define OPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE 1 -#ifndef LMAC154_RADIO_RECEIVE_SENSITIVITY -#define LMAC154_RADIO_RECEIVE_SENSITIVITY -103 +#if OPENTHREAD_FTD +#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 1 +#define OPENTHREAD_CONFIG_JOINER_ENABLE 1 #endif -#ifndef OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY -#define OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY 40 +#if OPENTHREAD_MTD +#define OPENTHREAD_CONFIG_JOINER_ENABLE 1 #endif +#define OPENTHREAD_CONFIG_TCP_ENABLE 0 +#define OPENTHREAD_CONFIG_TLS_ENABLE 0 +#define OPENTHREAD_CONFIG_SRP_SERVER_ENABLE 0 +#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0 +#define OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE 0 + #define OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE 0 #define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE 1 #define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 0 @@ -67,31 +102,13 @@ #define OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE 1 #define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 - #define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 1 -#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1 -#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 -#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1 -#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 1 -#define OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE 1 - -#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 0 -#define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 0 -// #define OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE 0 -#define OPENTHREAD_CONFIG_TCP_ENABLE 0 -#define OPENTHREAD_CONFIG_TLS_ENABLE 0 - -#define OPENTHREAD_CONFIG_PING_SENDER_ENABLE 1 -// #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG - -#define OPENTHREAD_ENABLE_VENDOR_EXTENSION 0 #define OPENTHREAD_EXAMPLES_SIMULATION 0 +#define OPENTHREAD_PLATFORM_POSIX 0 +#define OPENTHREAD_ENABLE_VENDOR_EXTENSION 0 -#ifndef OPENTHREAD_CONFIG_DIAG_ENABLE -#define OPENTHREAD_CONFIG_DIAG_ENABLE 0 -#endif - -#define ENABLE_OPENTHREAD_BORDER_ROUTER 0 +#define IEEE802_15_4_RADIO_RECEIVE_SENSITIVITY -105 +#define OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY 40 -#endif // OPENTHREAD_CORE_BL702_CONFIG_H_ +#endif // OPENTHREAD_CORE_PROJ_CONFIG_H diff --git a/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp index 4495a7a08ade1b..4318dcc4a58dac 100644 --- a/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp +++ b/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp @@ -190,6 +190,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) ChipLogProgress(DeviceLayer, "Performing factory reset"); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + ThreadStackMgr().ErasePersistentInfo(); +#endif + err = BLConfig::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { diff --git a/src/platform/bouffalolab/common/FactoryDataProvider.cpp b/src/platform/bouffalolab/common/FactoryDataProvider.cpp index 056b4da903ef55..0785b5be88ab9a 100644 --- a/src/platform/bouffalolab/common/FactoryDataProvider.cpp +++ b/src/platform/bouffalolab/common/FactoryDataProvider.cpp @@ -19,15 +19,8 @@ #include -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE -#include -#else -extern "C" { -#include -} -#endif - #include "FactoryDataProvider.h" +#include namespace chip { namespace DeviceLayer { @@ -43,18 +36,15 @@ CHIP_ERROR LoadKeypairFromRaw(ByteSpan privateKey, ByteSpan publicKey, Crypto::P CHIP_ERROR FactoryDataProvider::Init() { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE if (false == mfd_init()) { return CHIP_ERROR_PERSISTED_STORAGE_FAILED; } -#endif return CHIP_NO_ERROR; } CHIP_ERROR FactoryDataProvider::GetCertificationDeclaration(MutableByteSpan & outBuffer) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getCd(outBuffer.data(), outBuffer.size()); @@ -69,27 +59,6 @@ CHIP_ERROR FactoryDataProvider::GetCertificationDeclaration(MutableByteSpan & ou } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - - static const unsigned char Chip_Test_CD_130D_f001_der[] = { - 0x30, 0x81, 0xe9, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x81, 0xdb, 0x30, 0x81, 0xd8, - 0x02, 0x01, 0x03, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x45, - 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x38, 0x04, 0x36, 0x15, 0x24, 0x00, 0x01, 0x25, - 0x01, 0x0d, 0x13, 0x36, 0x02, 0x05, 0x01, 0xf0, 0x18, 0x25, 0x03, 0x34, 0x12, 0x2c, 0x04, 0x13, 0x5a, 0x49, 0x47, 0x32, - 0x30, 0x31, 0x34, 0x31, 0x5a, 0x42, 0x33, 0x33, 0x30, 0x30, 0x30, 0x31, 0x2d, 0x32, 0x34, 0x24, 0x05, 0x00, 0x24, 0x06, - 0x00, 0x25, 0x07, 0x76, 0x98, 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, 0x21, 0x00, 0xd9, 0x91, 0xc9, 0xce, 0xaf, 0x8e, 0x81, 0x56, 0x10, 0x63, - 0x1d, 0x1d, 0x69, 0x3d, 0x0c, 0xbb, 0xb6, 0x17, 0x6e, 0x0b, 0x91, 0xba, 0x7b, 0x23, 0x57, 0xdc, 0x50, 0x80, 0x23, 0xc9, - 0x8e, 0xd0, 0x02, 0x20, 0x34, 0x5d, 0xeb, 0xd7, 0x38, 0xca, 0x8f, 0xfb, 0xa8, 0x4e, 0x8b, 0xe9, 0x5b, 0x66, 0x8b, 0x15, - 0xb9, 0x0a, 0x9a, 0xf2, 0x11, 0x82, 0x0a, 0x7a, 0xf2, 0x9f, 0x3b, 0xdd, 0xd8, 0x15, 0x51, 0x07 - }; - - ReturnErrorOnFailure(CopySpanToMutableSpan(ByteSpan(Chip_Test_CD_130D_f001_der), outBuffer)); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) @@ -101,7 +70,6 @@ CHIP_ERROR FactoryDataProvider::GetFirmwareInformation(MutableByteSpan & out_fir CHIP_ERROR FactoryDataProvider::GetDeviceAttestationCert(MutableByteSpan & outBuffer) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getDacCert(outBuffer.data(), outBuffer.size()); @@ -116,43 +84,10 @@ CHIP_ERROR FactoryDataProvider::GetDeviceAttestationCert(MutableByteSpan & outBu } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - static const uint8_t Dac_Cert_Array[] = { - 0x30, 0x82, 0x01, 0xd0, 0x30, 0x82, 0x01, 0x76, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x68, 0xa3, 0xb6, 0x6e, 0x27, - 0x6b, 0x5b, 0x29, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x30, 0x31, 0x18, 0x30, - 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, - 0x50, 0x41, 0x49, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, - 0x04, 0x31, 0x33, 0x30, 0x44, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, 0x32, 0x33, 0x34, - 0x33, 0x5a, 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, - 0x48, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x11, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, - 0x65, 0x73, 0x74, 0x20, 0x44, 0x41, 0x43, 0x20, 0x30, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, - 0x82, 0xa2, 0x7c, 0x02, 0x01, 0x0c, 0x04, 0x31, 0x33, 0x30, 0x44, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, - 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, 0x02, 0x0c, 0x04, 0x46, 0x30, 0x30, 0x31, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, - 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, - 0xd8, 0x19, 0x93, 0xac, 0xf1, 0xc8, 0x63, 0xbb, 0x04, 0x2b, 0x8c, 0x2e, 0x4d, 0xe4, 0x08, 0x39, 0x4f, 0xf9, 0x3e, 0xa3, - 0x89, 0x19, 0x96, 0x8c, 0x22, 0xa1, 0x0f, 0xeb, 0x4c, 0x20, 0x2a, 0x8a, 0x12, 0xff, 0xe4, 0xe6, 0x09, 0x4f, 0x13, 0x4b, - 0xa8, 0x35, 0x53, 0x2f, 0xa4, 0x9d, 0x8e, 0x79, 0x8c, 0x07, 0x01, 0x5c, 0x73, 0xff, 0x0d, 0x1c, 0x34, 0xfe, 0x14, 0x7f, - 0xbe, 0xc6, 0x70, 0xf8, 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, - 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x1d, - 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x63, 0x9f, 0xbd, 0x91, 0x8c, 0x90, 0xed, 0x7a, 0xbf, 0x64, 0xcd, - 0xe8, 0x2e, 0x13, 0x10, 0x8e, 0xee, 0x5d, 0x6f, 0x8e, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, - 0x80, 0x14, 0x3a, 0xb2, 0xfa, 0x06, 0x27, 0xcc, 0x4a, 0xdc, 0x84, 0xac, 0x9c, 0x95, 0x1e, 0x8c, 0x8f, 0xdc, 0x4c, 0x0d, - 0xec, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, - 0x21, 0x00, 0xd6, 0xc3, 0xab, 0x6d, 0xbd, 0xd0, 0xa2, 0x45, 0xbc, 0xcf, 0xb7, 0x2d, 0x6f, 0x5e, 0xd1, 0xbe, 0xd7, 0xd4, - 0xea, 0xca, 0x9e, 0xf2, 0xa1, 0x09, 0x77, 0xc3, 0x43, 0xa2, 0x29, 0x67, 0x63, 0x3d, 0x02, 0x20, 0x2b, 0xb8, 0x39, 0xf8, - 0x31, 0xeb, 0x83, 0x31, 0xe2, 0x31, 0xeb, 0xd2, 0x5c, 0x82, 0xe4, 0xb7, 0x14, 0xfd, 0x62, 0x97, 0x1f, 0x64, 0xff, 0x51, - 0x43, 0x83, 0xb4, 0xa9, 0x19, 0x6f, 0x96, 0xcf - }; - - ReturnErrorOnFailure(CopySpanToMutableSpan(ByteSpan(Dac_Cert_Array), outBuffer)); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetProductAttestationIntermediateCert(MutableByteSpan & outBuffer) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getPaiCert(outBuffer.data(), outBuffer.size()); @@ -167,36 +102,6 @@ CHIP_ERROR FactoryDataProvider::GetProductAttestationIntermediateCert(MutableByt } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - static const uint8_t Pai_Cert_Array[] = { - 0x30, 0x82, 0x01, 0xa7, 0x30, 0x82, 0x01, 0x4e, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x01, 0x0f, 0x96, 0xa1, 0x42, - 0x5c, 0xe7, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x1a, 0x31, 0x18, 0x30, - 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, - 0x50, 0x41, 0x41, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x36, 0x32, 0x38, 0x31, 0x34, 0x32, 0x33, 0x34, 0x33, 0x5a, - 0x18, 0x0f, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x30, 0x31, - 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x54, 0x65, 0x73, - 0x74, 0x20, 0x50, 0x41, 0x49, 0x31, 0x14, 0x30, 0x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x02, - 0x01, 0x0c, 0x04, 0x31, 0x33, 0x30, 0x44, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, - 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xdb, 0xbe, 0xac, 0xd5, 0xf3, 0xd6, - 0x32, 0x36, 0x04, 0x00, 0xe0, 0xa1, 0x16, 0x8d, 0xbf, 0x0c, 0x74, 0x8f, 0xdb, 0xd7, 0x03, 0x7f, 0x8c, 0x4e, 0x65, 0x58, - 0x27, 0x2f, 0xfa, 0x2d, 0x64, 0x61, 0x4e, 0xe5, 0x72, 0xb8, 0xa5, 0x87, 0x8c, 0x15, 0xc7, 0x25, 0x55, 0x47, 0xc4, 0xc9, - 0x62, 0xda, 0xd7, 0x02, 0x64, 0xd2, 0x84, 0x2d, 0xe8, 0x2d, 0xf1, 0x69, 0xcb, 0x56, 0x42, 0x86, 0xf8, 0x55, 0xa3, 0x66, - 0x30, 0x64, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, - 0x01, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, - 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x3a, 0xb2, 0xfa, 0x06, 0x27, 0xcc, 0x4a, 0xdc, 0x84, 0xac, 0x9c, - 0x95, 0x1e, 0x8c, 0x8f, 0xdc, 0x4c, 0x0d, 0xec, 0x01, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, - 0x80, 0x14, 0x78, 0x5c, 0xe7, 0x05, 0xb8, 0x6b, 0x8f, 0x4e, 0x6f, 0xc7, 0x93, 0xaa, 0x60, 0xcb, 0x43, 0xea, 0x69, 0x68, - 0x82, 0xd5, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30, 0x44, 0x02, - 0x20, 0x0f, 0x12, 0x2f, 0x8c, 0x83, 0xab, 0xdd, 0x35, 0x53, 0xbc, 0xcd, 0xe5, 0xec, 0x2d, 0x84, 0x99, 0x24, 0xb5, 0xe0, - 0x1a, 0x54, 0x45, 0x37, 0x78, 0xba, 0x88, 0xa8, 0x51, 0x18, 0xf8, 0x0e, 0x05, 0x02, 0x20, 0x59, 0x84, 0x16, 0xe1, 0xd1, - 0xee, 0x5e, 0xc6, 0x50, 0xcd, 0x5d, 0x58, 0x47, 0xb8, 0x10, 0x82, 0xa9, 0xa2, 0x2f, 0x4f, 0x31, 0x7e, 0xc7, 0x5d, 0xb6, - 0x6c, 0xc9, 0xc5, 0x70, 0xb8, 0x1e, 0xd8 - }; - - ReturnErrorOnFailure(CopySpanToMutableSpan(ByteSpan(Pai_Cert_Array), outBuffer)); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & messageToSign, MutableByteSpan & outSignBuffer) @@ -210,8 +115,6 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & me return CHIP_ERROR_BUFFER_TOO_SMALL; } -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE - uint32_t dacCertSize = 0, dacPrivateKeySize = 0; uint8_t * pDacCertPtr = mfd_getDacCertPtr(&dacCertSize); uint8_t * pDacPrivateKeyPtr = mfd_getDacPrivateKeyPtr(&dacPrivateKeySize); @@ -225,21 +128,6 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & me ByteSpan dacCert(pDacCertPtr, dacCertSize); ByteSpan dacPrivateKey(pDacPrivateKeyPtr, dacPrivateKeySize); -#else - static const uint8_t Dac_PrivateKey_Array[] = { 0x65, 0x11, 0x78, 0x2e, 0xf7, 0xcd, 0x30, 0x59, 0xbd, 0x3a, 0xdd, - 0x44, 0x6f, 0xc5, 0xdd, 0x92, 0xe5, 0xd8, 0x3c, 0x56, 0x9d, 0x67, - 0x7a, 0x29, 0xc7, 0xe9, 0xa7, 0x8f, 0x67, 0xc5, 0x5f, 0xf2 }; - - uint8_t dac_cert_array[Credentials::kMaxDERCertLength]; - uint8_t dac_cert_private_key_array[sizeof(Dac_PrivateKey_Array)]; - MutableByteSpan dacCert(dac_cert_array, Credentials::kMaxDERCertLength), - dacPrivateKey(dac_cert_private_key_array, sizeof(dac_cert_private_key_array)); - - ReturnErrorOnFailure(CopySpanToMutableSpan(ByteSpan(Dac_PrivateKey_Array), dacPrivateKey)); - ReturnErrorOnFailure(GetDeviceAttestationCert(dacCert)); - -#endif - ReturnErrorOnFailure(chip::Crypto::ExtractPubkeyFromX509Cert(dacCert, dacPublicKey)); ReturnErrorOnFailure(LoadKeypairFromRaw(dacPrivateKey, ByteSpan(dacPublicKey.Bytes(), dacPublicKey.Length()), keypair)); @@ -252,7 +140,6 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & me CHIP_ERROR FactoryDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getDiscriminator((uint8_t *) &setupDiscriminator, sizeof(setupDiscriminator)); @@ -267,11 +154,6 @@ CHIP_ERROR FactoryDataProvider::GetSetupDiscriminator(uint16_t & setupDiscrimina } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - setupDiscriminator = 3840; - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::SetSetupDiscriminator(uint16_t setupDiscriminator) @@ -281,7 +163,6 @@ CHIP_ERROR FactoryDataProvider::SetSetupDiscriminator(uint16_t setupDiscriminato CHIP_ERROR FactoryDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getSapke2It((uint8_t *) &iterationCount, sizeof(iterationCount)); @@ -295,16 +176,10 @@ CHIP_ERROR FactoryDataProvider::GetSpake2pIterationCount(uint32_t & iterationCou } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - iterationCount = 1000; - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getSapke2Salt(saltBuf.data(), saltBuf.size()); @@ -319,25 +194,10 @@ CHIP_ERROR FactoryDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - static const char spake2pSalt[] = "U1BBS0UyUCBLZXkgU2FsdA=="; - uint32_t aSpake2pSaltLen; - - if (!utils_base64decode((const uint8_t *) spake2pSalt, sizeof(spake2pSalt) - 1, saltBuf.size(), saltBuf.data(), - &aSpake2pSaltLen)) - { - return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - } - - saltBuf = MutableByteSpan(saltBuf.data(), aSpake2pSaltLen); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getSapke2Verifier(verifierBuf.data(), verifierBuf.size()); @@ -353,27 +213,10 @@ CHIP_ERROR FactoryDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - static const char spake2pVerifier[] = "jdf0KbjmAwujViR8WckvvklJzE0UL+uIOiIjTtb3a5kE/" - "WdbVWhmDFSSjLqFhiiCILxXQ4NVO3YBWTdkERnTlXbFmx+T/32FMRpZLPz8yqFXyALytJW7ZJfArBz0/CP9hA=="; - uint32_t aSpake2pVerifierLen; - - if (!utils_base64decode((const uint8_t *) spake2pVerifier, sizeof(spake2pVerifier) - 1, verifierBuf.size(), verifierBuf.data(), - &aSpake2pVerifierLen)) - { - return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - } - - verifierBuf = MutableByteSpan(verifierBuf.data(), aSpake2pVerifierLen); - verifierLen = aSpake2pVerifierLen; - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetSetupPasscode(uint32_t & setupPasscode) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getPasscode((uint8_t *) &setupPasscode, sizeof(setupPasscode)); @@ -387,10 +230,6 @@ CHIP_ERROR FactoryDataProvider::GetSetupPasscode(uint32_t & setupPasscode) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - setupPasscode = 49808401; - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::SetSetupPasscode(uint32_t setupPasscode) @@ -400,7 +239,6 @@ CHIP_ERROR FactoryDataProvider::SetSetupPasscode(uint32_t setupPasscode) CHIP_ERROR FactoryDataProvider::GetVendorName(char * buf, size_t bufSize) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getVendorName(buf, bufSize); @@ -415,17 +253,10 @@ CHIP_ERROR FactoryDataProvider::GetVendorName(char * buf, size_t bufSize) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - static const char vendorName[] = "Bouffalo Lab"; - strncpy(buf, vendorName, bufSize); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetVendorId(uint16_t & vendorId) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getVendorId((uint8_t *) &vendorId, sizeof(vendorId)); @@ -439,15 +270,10 @@ CHIP_ERROR FactoryDataProvider::GetVendorId(uint16_t & vendorId) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - vendorId = 0x130D; - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetProductName(char * buf, size_t bufSize) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getProductName(buf, bufSize); @@ -462,16 +288,10 @@ CHIP_ERROR FactoryDataProvider::GetProductName(char * buf, size_t bufSize) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - strncpy(buf, CHIP_BLE_DEVICE_NAME, bufSize); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetProductId(uint16_t & productId) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getProductId((uint8_t *) &productId, sizeof(productId)); @@ -485,16 +305,10 @@ CHIP_ERROR FactoryDataProvider::GetProductId(uint16_t & productId) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - productId = 0xf001; - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getPartNumber(buf, bufSize); @@ -509,14 +323,10 @@ CHIP_ERROR FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; -#endif } CHIP_ERROR FactoryDataProvider::GetProductURL(char * buf, size_t bufSize) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getProductUrl(buf, bufSize); @@ -531,14 +341,10 @@ CHIP_ERROR FactoryDataProvider::GetProductURL(char * buf, size_t bufSize) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; -#endif } CHIP_ERROR FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getProductLabel(buf, bufSize); @@ -553,14 +359,10 @@ CHIP_ERROR FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; -#endif } CHIP_ERROR FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getSerialNumber(buf, bufSize); @@ -575,11 +377,6 @@ CHIP_ERROR FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - strncpy(buf, CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER, bufSize); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) @@ -602,12 +399,10 @@ CHIP_ERROR FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & #define OS_DAY ((__DATE__[4] == ' ' ? 0 : __DATE__[4] - '0') * 10 + (__DATE__[5] - '0')) -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE if (mfd_getManufacturingDate(&year, &month, &day)) { return CHIP_NO_ERROR; } -#endif year = (uint16_t) OS_YEAR; month = (uint8_t) OS_MONTH; @@ -618,7 +413,6 @@ CHIP_ERROR FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & CHIP_ERROR FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getHardwareVersion((uint8_t *) &hardwareVersion, sizeof(hardwareVersion)); @@ -632,16 +426,10 @@ CHIP_ERROR FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion) } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - hardwareVersion = CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION; - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetHardwareVersionString(char * buf, size_t bufSize) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getHardwareVersionString(buf, bufSize); if (len > 0) @@ -655,16 +443,10 @@ CHIP_ERROR FactoryDataProvider::GetHardwareVersionString(char * buf, size_t bufS } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - strncpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING, bufSize); - - return CHIP_NO_ERROR; -#endif } CHIP_ERROR FactoryDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) { -#if CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE int len = 0; len = mfd_getRotatingDeviceIdUniqueId(uniqueIdSpan.data(), uniqueIdSpan.size()); @@ -678,16 +460,6 @@ CHIP_ERROR FactoryDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & un } return CHIP_ERROR_BUFFER_TOO_SMALL; -#else - constexpr uint8_t uniqueId[] = CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID; - - VerifyOrReturnValue(uniqueIdSpan.size() >= sizeof(uniqueId), CHIP_ERROR_INVALID_ARGUMENT); - - memcpy(uniqueIdSpan.data(), uniqueId, sizeof(uniqueId)); - uniqueIdSpan.reduce_size(sizeof(uniqueId)); - - return CHIP_NO_ERROR; -#endif } } // namespace DeviceLayer diff --git a/src/platform/bouffalolab/common/Logging.cpp b/src/platform/bouffalolab/common/Logging.cpp index b05912f180f33b..1ee0128d97cd62 100644 --- a/src/platform/bouffalolab/common/Logging.cpp +++ b/src/platform/bouffalolab/common/Logging.cpp @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include - #include #include +#include +#include #include #include @@ -64,13 +64,25 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) switch (category) { case kLogCategory_Error: - __utils_printf("[%10u][%s][ERROR] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#if CHIP_DEVICE_LAYER_TARGET_BL602 || CHIP_DEVICE_LAYER_TARGET_BL702 || CHIP_DEVICE_LAYER_TARGET_BL702L + __utils_printf("[%10lu][%s][ERROR] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#else + printf("[%10lu][%s][ERROR] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#endif break; case kLogCategory_Progress: - __utils_printf("[%10u][%s][PROGR] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#if CHIP_DEVICE_LAYER_TARGET_BL602 || CHIP_DEVICE_LAYER_TARGET_BL702 || CHIP_DEVICE_LAYER_TARGET_BL702L + __utils_printf("[%10lu][%s][PROGR] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#else + printf("[%10lu][%s][PROGR] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#endif break; case kLogCategory_Detail: - __utils_printf("[%10u][%s][DETAIL] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#if CHIP_DEVICE_LAYER_TARGET_BL602 || CHIP_DEVICE_LAYER_TARGET_BL702 || CHIP_DEVICE_LAYER_TARGET_BL702L + __utils_printf("[%10lu][%s][DETAIL] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#else + printf("[%10lu][%s][DETAIL] %s\r\n", xTaskGetTickCount(), module, formattedMsg); +#endif break; } #else diff --git a/src/platform/bouffalolab/common/OTAImageProcessorImpl.cpp b/src/platform/bouffalolab/common/OTAImageProcessorImpl.cpp index 0f70a2a33edc1e..0d3357b38f0106 100644 --- a/src/platform/bouffalolab/common/OTAImageProcessorImpl.cpp +++ b/src/platform/bouffalolab/common/OTAImageProcessorImpl.cpp @@ -18,11 +18,9 @@ #include #include -#if CHIP_DEVICE_LAYER_TARGET_BL602 || CHIP_DEVICE_LAYER_TARGET_BL702 || CHIP_DEVICE_LAYER_TARGET_BL702L extern "C" { #include #include -#endif extern void hal_reboot(void); } diff --git a/src/platform/bouffalolab/common/args.gni b/src/platform/bouffalolab/common/args.gni index 48159fd3b6b4b9..075219605b4f07 100644 --- a/src/platform/bouffalolab/common/args.gni +++ b/src/platform/bouffalolab/common/args.gni @@ -14,7 +14,8 @@ declare_args() { chip_enable_factory_data = false - chip_enable_factory_data_test = false chip_enable_ethernet = false + + bouffalo_sdk_component_easyflash_enabled = false } diff --git a/third_party/bouffalolab/bl602/bl_iot_sdk.gni b/third_party/bouffalolab/bl602/bl_iot_sdk.gni index a9acca8efd19f4..d6896957e17204 100644 --- a/third_party/bouffalolab/bl602/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl602/bl_iot_sdk.gni @@ -357,6 +357,11 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/stage/blfdt/inc", "${bl_iot_sdk_root}/components/stage/cli/cli/include", ] + + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + include_dirs += [ "${bl_iot_sdk_root}/components/stage/easyflash4/inc" ] + } } source_set("${sdk_target_name}_stage") { @@ -364,6 +369,7 @@ template("bl_iot_sdk") { "EF_ENV_CACHE_TABLE_SIZE=64", "RHINO_CONFIG_WORKQUEUE=0", ] + sources = [ "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt.c", "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_addresses.c", @@ -375,10 +381,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_sw.c", "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_wip.c", "${bl_iot_sdk_root}/components/stage/blog/blog.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", "${bl_iot_sdk_root}/components/stage/yloop/src/aos_freertos.c", "${bl_iot_sdk_root}/components/stage/yloop/src/device.c", "${bl_iot_sdk_root}/components/stage/yloop/src/local_event.c", @@ -388,16 +390,25 @@ template("bl_iot_sdk") { cflags_c = [ "-Wno-sign-compare" ] configs += [ + ":${sdk_target_name}_config", ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_freertos", ":${sdk_target_name}_config_fs", ":${sdk_target_name}_config_sys", ":${sdk_target_name}_config_utils", ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_config_stage", - ] + + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + sources += [ + "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", + ] + } + + public_configs = [ ":${sdk_target_name}_config_stage" ] } config("${sdk_target_name}_config_sys") { @@ -561,6 +572,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include", "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/zephyr", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/misc", "${bl_iot_sdk_root}/components/network/ble/blestack/src/port/include", "${bl_iot_sdk_root}/components/network/ble/blestack/src", "${bl_iot_sdk_root}/components/network/ble/blestack/src/host", @@ -727,7 +739,7 @@ template("bl_iot_sdk") { source_set("${sdk_target_name}_wifi") { defines = [ "BL602_MATTER_SUPPORT", - "LWIP_IPV6", + "LWIP_IPV6=1", "CONFIG_WPA_WAPI_PSK=0", ] @@ -832,6 +844,19 @@ template("bl_iot_sdk") { libs = [ "${bl_iot_sdk_root}/components/network/wifi/lib/libwifi.a" ] + cflags_c = [ + "-Wno-unused-function", + "-Wno-shadow", + "-Wno-old-style-declaration", + "-Wno-incompatible-pointer-types", + "-Wno-format-security", + "-Wno-format-nonliteral", + "-Wno-unused-but-set-variable", + "-Wno-unused-variable", + "-fcommon", + "-Wno-undef", + ] + configs += [ ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_stage", @@ -846,18 +871,6 @@ template("bl_iot_sdk") { ] deps = [ ":${sdk_target_name}_hosal" ] - - cflags_c = [ - "-Wno-unused-function", - "-Wno-shadow", - "-Wno-old-style-declaration", - "-Wno-incompatible-pointer-types", - "-Wno-format-security", - "-Wno-format-nonliteral", - "-Wno-unused-but-set-variable", - "-Wno-unused-variable", - "-fcommon", - ] } config("${sdk_target_name}_config_lwip") { @@ -946,6 +959,7 @@ template("bl_iot_sdk") { [ "${bl_iot_sdk_root}/components/network/lwip_dhcpd/dhcp_server_raw.c" ] cflags_c = [ + "-Wno-unused-variable", "-Wno-incompatible-pointer-types", "-Wno-sign-compare", ] @@ -957,14 +971,17 @@ template("bl_iot_sdk") { } config("${sdk_target_name}_config_factory_data") { - include_dirs = [ "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/include" ] + include_dirs = + [ "${bl_iot_sdk_root}/components/network/matter/mfd/include" ] } source_set("${sdk_target_name}_factory_data") { + defines = [ "BL_MFD_PLAT_H=\"bl_mfd_bl602.h\"" ] sources = [ - "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/efuse_slot.c", - "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/matter_factory_data.c", + "${bl_iot_sdk_root}/components/network/matter/mfd/bl_mfd.c", + "${bl_iot_sdk_root}/components/network/matter/mfd/bl_mfd_decrypt.c", ] + configs += [ ":${sdk_target_name}_config", ":${sdk_target_name}_config_freertos", diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index f7c26e44c0dbbc..cb59d002986180 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -150,11 +150,11 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_std/BSP_Driver/std_drv/src/bl702_xip_sflash_ext.c", ] - configs += [ ":${sdk_target_name}_config_freertos" ] - public_configs = [ + configs += [ ":${sdk_target_name}_config", - ":${sdk_target_name}_config_BSP_Driver", + ":${sdk_target_name}_config_freertos", ] + public_configs = [ ":${sdk_target_name}_config_BSP_Driver" ] cflags_c = [ "-Wno-sign-compare", "-Wno-unused-variable", @@ -293,8 +293,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_boot2.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_button.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_gpio.c", - "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_hbn.c", - "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_hwtimer.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_pds.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_sys.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702_hal/hal_tcal.c", @@ -327,6 +325,7 @@ template("bl_iot_sdk") { "-Wno-format-truncation", "-Wno-shadow", "-Wno-incompatible-pointer-types", + "-Wno-array-bounds", ] configs += [ @@ -396,7 +395,6 @@ template("bl_iot_sdk") { config("${sdk_target_name}_config_stage") { include_dirs = [ - "${bl_iot_sdk_root}/components/stage/easyflash4/inc", "${bl_iot_sdk_root}/components/stage/yloop/include", "${bl_iot_sdk_root}/components/stage/blog", "${bl_iot_sdk_root}/components/stage/yloop/include/aos", @@ -404,6 +402,11 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/stage/cli/cli/include", ] + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + include_dirs += [ "${bl_iot_sdk_root}/components/stage/easyflash4/inc" ] + } + if (defined(invoker.enable_cdc_module) && invoker.enable_cdc_module) { cflags_cc = [ "-Wno-shadow" ] } @@ -425,10 +428,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_sw.c", "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_wip.c", "${bl_iot_sdk_root}/components/stage/blog/blog.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", "${bl_iot_sdk_root}/components/stage/yloop/src/aos_freertos.c", "${bl_iot_sdk_root}/components/stage/yloop/src/device.c", "${bl_iot_sdk_root}/components/stage/yloop/src/local_event.c", @@ -438,16 +437,25 @@ template("bl_iot_sdk") { cflags_c = [ "-Wno-sign-compare" ] configs += [ + ":${sdk_target_name}_config", ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_freertos", ":${sdk_target_name}_config_fs", ":${sdk_target_name}_config_sys", ":${sdk_target_name}_config_utils", ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_config_stage", - ] + + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + sources += [ + "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", + ] + } + + public_configs = [ ":${sdk_target_name}_config_stage" ] } config("${sdk_target_name}_config_sys") { @@ -618,6 +626,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include", "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/zephyr", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/misc", "${bl_iot_sdk_root}/components/network/ble/blestack/src/port/include", "${bl_iot_sdk_root}/components/network/ble/blestack/src", "${bl_iot_sdk_root}/components/network/ble/blestack/src/host", @@ -728,28 +737,38 @@ template("bl_iot_sdk") { source_set("${sdk_target_name}_openthread_port") { import("//build_overrides/openthread.gni") + if (invoker.chip_openthread_ftd) { + defines = [ "CHIP_DEVICE_CONFIG_THREAD_FTD=1" ] + } else { + defines = [ "CHIP_DEVICE_CONFIG_THREAD_FTD=0" ] + } + include_dirs = [ - "${bl_iot_sdk_root}/components/network/lmac154/include", + "${bl_iot_sdk_root}/components/network/lmac154/lmac154/include", "${bl_iot_sdk_root}/components/network/thread/openthread_port", "${openthread_root}/examples/platforms/utils/", "${openthread_root}/examples", ] sources = [ - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_alarm.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_diag.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_alarm_bl702.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio_bl70xx.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_sys.c", ] + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + sources += [ "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings_easyflash.c" ] + } + libs = [ - "${bl_iot_sdk_root}/components/network/lmac154/lib/liblmac154.a", + "${bl_iot_sdk_root}/components/network/lmac154/lmac154/lib/liblmac154.a", "${bl_iot_sdk_root}/components/network/thread/openthread_utils_bl702/lib/libopenthread_utils_bl702.a", ] + cflags_c = [ "-Wno-sign-compare" ] + configs += [ ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_utils", @@ -941,14 +960,17 @@ template("bl_iot_sdk") { } config("${sdk_target_name}_config_factory_data") { - include_dirs = [ "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/include" ] + include_dirs = + [ "${bl_iot_sdk_root}/components/network/matter/mfd/include" ] } source_set("${sdk_target_name}_factory_data") { + defines = [ "BL_MFD_PLAT_H=\"bl_mfd_bl702.h\"" ] sources = [ - "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/efuse_slot.c", - "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/matter_factory_data.c", + "${bl_iot_sdk_root}/components/network/matter/mfd/bl_mfd.c", + "${bl_iot_sdk_root}/components/network/matter/mfd/bl_mfd_decrypt.c", ] + configs += [ ":${sdk_target_name}_config", ":${sdk_target_name}_config_freertos", @@ -962,8 +984,6 @@ template("bl_iot_sdk") { public_deps = [ ":${sdk_target_name}_BSP_Driver", ":${sdk_target_name}_bl702_freertos", - ":${sdk_target_name}_ble", - ":${sdk_target_name}_factory_data", ":${sdk_target_name}_fs", ":${sdk_target_name}_hosal", ":${sdk_target_name}_libc", @@ -974,6 +994,11 @@ template("bl_iot_sdk") { ":${sdk_target_name}_utils", ] + if (defined(invoker.chip_config_network_layer_ble) && + invoker.chip_config_network_layer_ble) { + public_deps += [ ":${sdk_target_name}_ble" ] + } + if (defined(invoker.chip_enable_wifi) && invoker.chip_enable_wifi) { public_deps += [ ":${sdk_target_name}_wifi" ] public_deps += [ ":${sdk_target_name}_lwip" ] @@ -985,6 +1010,11 @@ template("bl_iot_sdk") { public_deps += [ ":${sdk_target_name}_lwip" ] } + if (defined(invoker.chip_enable_factory_data) && + invoker.chip_enable_factory_data) { + public_deps += [ ":${sdk_target_name}_factory_data" ] + } + if (defined(invoker.enable_cdc_module) && invoker.enable_cdc_module) { public_deps += [ ":${sdk_target_name}_bl702_usb_cdc" ] } diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index 2041432e3178bd..0e4ad70410467e 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -39,9 +39,9 @@ template("bl_iot_sdk") { defines = [ "__FILENAME__=strrchr(__FILE__,'/')?strrchr(__FILE__,'/')+1:__FILE__", "ARCH_RISCV", - "BL702L=BL702L", - "BFLB_USE_ROM_DRIVER=1", + "BUILD_ROM_CODE=1", "BFLB_USE_HAL_DRIVER=1", + "BL702L=BL702L", "CFG_COMPONENT_BLOG_ENABLE=0", ] @@ -79,7 +79,6 @@ template("bl_iot_sdk") { source_set("${sdk_target_name}_soc") { defines = [ "CFG_CPP_ENABLE", - "CFG_USE_ROM_CODE", "SYS_APP_TASK_STACK_SIZE=1024", "SYS_APP_TASK_PRIORITY=15", ] @@ -106,11 +105,11 @@ template("bl_iot_sdk") { configs += [ ":${sdk_target_name}_config", ":${sdk_target_name}_config_BSP_Driver", - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_hosal", ":${sdk_target_name}_config_fs", ":${sdk_target_name}_config_stage", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", ] } @@ -128,32 +127,7 @@ template("bl_iot_sdk") { ] } - config("${sdk_target_name}_config_bl702l_rom_a0") { - include_dirs = [ - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_rom_a0/bl702l_rom_ext/include/rom_ext", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_rom_a0/bl702l_rom_ext/include/rom_freertos", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_rom_a0/bl702l_rom_ext/include/rom_freertos/config", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_rom_a0/bl702l_rom_ext/include/rom_freertos/panic", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_rom_a0/bl702l_rom_ext/include/rom_freertos/portable/GCC/RISC-V", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_rom_a0/bl702l_rom_ext/include/rom_lmac154/include", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/inc", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/startup", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/MCU_Common/misc", - ] - } - - source_set("${sdk_target_name}_bl702l_rom_a0") { - defines = [ "portasmHANDLE_INTERRUPT=interrupt_entry" ] - - if (defined(invoker.enable_debug_frame_ptr) && - invoker.enable_debug_frame_ptr) { - defines += [ "CONF_ENABLE_FRAME_PTR=1" ] - } - - include_dirs = [ "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/regs" ] - - libs = [ "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_rom_a0/bl702l_rom_ext/lib/libbl702l_rom_ext.a" ] - + source_set("${sdk_target_name}_BSP_Driver") { sources = [ "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_acomp.c", "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_adc.c", @@ -163,16 +137,76 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_i2c.c", "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_pwm.c", "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_pwm_sc.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_romapi_patch.c", "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_sec_dbg.c", "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_sec_eng.c", "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_spi.c", "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/BSP_Driver/std_drv/src/bl702l_tzc_sec.c", - "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/MCU_Common/ring_buffer/ring_buffer.c", ] + sources += [ "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_std/MCU_Common/ring_buffer/ring_buffer.c" ] + configs += [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_config_freertos", + ] + public_configs = [ ":${sdk_target_name}_config_BSP_Driver" ] + cflags_c = [ + "-Wno-sign-compare", + "-Wno-unused-variable", + ] + } + + config("${sdk_target_name}_config_freertos") { + include_dirs = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/config", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/portable/GCC/RISC-V", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/panic", + ] + } + + source_set("${sdk_target_name}_bl702l_freertos") { + defines = [ "portasmHANDLE_INTERRUPT=interrupt_entry" ] + if (defined(invoker.enable_debug_frame_ptr) && + invoker.enable_debug_frame_ptr) { + defines += [ + "CONF_ENABLE_FRAME_PTR=1", + "CONF_ENABLE_FUNC_BACKTRACE_ELF=${invoker.debug_output_file}", + ] + } + + include_dirs = [ "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/portable/GCC/RISC-V/chip_specific_extensions/RV32F_float_abi_single" ] + + sources = [ + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/event_groups.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/list.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/misaligned/fp_asm.S", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/misaligned/misaligned_ldst.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/panic/panic_c.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/portable/GCC/RISC-V/port.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/portable/GCC/RISC-V/portASM.S", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/portable/MemMang/heap_5.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/portable/MemMang/heap_5_psram.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/queue.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/stream_buffer.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/tasks.c", + "${bl_iot_sdk_root}/components/platform/soc/bl702l/bl702l_freertos/timers.c", + ] + + cflags_c = [ + "-Wno-sign-compare", + "-Wno-old-style-declaration", + ] + + if (defined(invoker.enable_debug_frame_ptr) && + invoker.enable_debug_frame_ptr) { + cflags_c += [ + "-Wno-incompatible-pointer-types", + "-Wno-int-conversion", + ] + } public_configs = [ ":${sdk_target_name}_config", - ":${sdk_target_name}_config_bl702l_rom_a0", + ":${sdk_target_name}_config_freertos", ] } @@ -221,8 +255,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_boot2.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_button.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_gpio.c", - "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_hbn.c", - "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_hwtimer.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_sys.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_tcal.c", "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hosal_adc.c", @@ -245,7 +277,10 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_pka.c", "${bl_iot_sdk_root}/components/platform/hosal/sec_common/bl_sec_sha.c", ] - + sources += [ + "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/bl_pds.c", + "${bl_iot_sdk_root}/components/platform/hosal/bl702l_hal/hal_pds.c", + ] cflags_c = [ "-Wno-unused-variable", "-Wno-sign-compare", @@ -259,11 +294,11 @@ template("bl_iot_sdk") { configs += [ ":${sdk_target_name}_config_soc", ":${sdk_target_name}_config_BSP_Driver", - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_stage", ":${sdk_target_name}_config_sys", ":${sdk_target_name}_config_fs", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", ] if (defined(invoker.chip_config_network_layer_ble) && @@ -298,11 +333,11 @@ template("bl_iot_sdk") { "-Wno-builtin-declaration-mismatch", ] configs += [ - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_hosal", ":${sdk_target_name}_config_stage", ":${sdk_target_name}_config_fs", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", ] public_configs = [ ":${sdk_target_name}_config", @@ -317,19 +352,23 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/libc/newlibc/syscalls.c", ] cflags_c = [ "-Wno-builtin-declaration-mismatch" ] - configs += [ ":${sdk_target_name}_config_bl702l_rom_a0" ] + configs += [ ":${sdk_target_name}_config_freertos" ] public_configs = [ ":${sdk_target_name}_config" ] } config("${sdk_target_name}_config_stage") { include_dirs = [ - "${bl_iot_sdk_root}/components/stage/easyflash4/inc", "${bl_iot_sdk_root}/components/stage/yloop/include", "${bl_iot_sdk_root}/components/stage/blog", "${bl_iot_sdk_root}/components/stage/yloop/include/aos", "${bl_iot_sdk_root}/components/stage/blfdt/inc", "${bl_iot_sdk_root}/components/stage/cli/cli/include", ] + + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + include_dirs += [ "${bl_iot_sdk_root}/components/stage/easyflash4/inc" ] + } } source_set("${sdk_target_name}_stage") { @@ -348,10 +387,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_sw.c", "${bl_iot_sdk_root}/components/stage/blfdt/src/fdt_wip.c", "${bl_iot_sdk_root}/components/stage/blog/blog.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", - "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", "${bl_iot_sdk_root}/components/stage/yloop/src/aos_freertos.c", "${bl_iot_sdk_root}/components/stage/yloop/src/device.c", "${bl_iot_sdk_root}/components/stage/yloop/src/local_event.c", @@ -361,16 +396,25 @@ template("bl_iot_sdk") { cflags_c = [ "-Wno-sign-compare" ] configs += [ - ":${sdk_target_name}_config_bl702l_rom_a0", + ":${sdk_target_name}_config", ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_fs", ":${sdk_target_name}_config_sys", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_config_stage", - ] + + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + sources += [ + "${bl_iot_sdk_root}/components/stage/easyflash4/src/easyflash.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_env.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_port.c", + "${bl_iot_sdk_root}/components/stage/easyflash4/src/ef_utils.c", + ] + } + + public_configs = [ ":${sdk_target_name}_config_stage" ] } config("${sdk_target_name}_config_sys") { @@ -387,9 +431,9 @@ template("bl_iot_sdk") { sources = [ "${bl_iot_sdk_root}/components/sys/blmtd/bl_mtd.c" ] configs += [ ":${sdk_target_name}_config_BSP_Driver", - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_hosal", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", ] public_configs = [ ":${sdk_target_name}_config", @@ -429,9 +473,9 @@ template("bl_iot_sdk") { "-Wno-incompatible-pointer-types", ] configs += [ - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_hosal", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", ] public_configs = [ ":${sdk_target_name}_config", @@ -523,7 +567,7 @@ template("bl_iot_sdk") { configs += [ ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_hosal", - ":${sdk_target_name}_config_bl702l_rom_a0", + ":${sdk_target_name}_config_freertos", ] public_configs = [ ":${sdk_target_name}_config", @@ -539,6 +583,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/ble/blestack/src/include/drivers/bluetooth", "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include", "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/zephyr", + "${bl_iot_sdk_root}/components/network/ble/blestack/src/common/include/misc", "${bl_iot_sdk_root}/components/network/ble/blestack/src/port/include", "${bl_iot_sdk_root}/components/network/ble/blestack/src", "${bl_iot_sdk_root}/components/network/ble/blestack/src/host", @@ -567,26 +612,7 @@ template("bl_iot_sdk") { } source_set("${sdk_target_name}_ble") { - defines = [ - "CONFIG_BUILD_BLE_ROM_CODE=1", - "CONFIG_BLE_PDS=1", - "CONFIG_BT_CONN=1", - "CONFIG_BLE_TX_BUFF_DATA=2", - "CONFIG_BLE_ACT_MAX=5", - "CONFIG_BT_ALLROLES=1", - "CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=1", - "CONFIG_DISABLE_BT_HOST_PRIVACY=1", - "CONFIG_DISABLE_CONTROLLER_BLE_PRIVACY=1", - "CONFIG_DISABLE_BLE_CONTROLLER_TEST_MODE=1", - "CONFIG_EM_SIZE=8", - "CONFIG_LONG_RANG=0", - "CONFIG_PHY_UPDATE=0", - "CONFIG_CLK_ACC=0 ", - "CONFIG_LE_PING=0", - "CONFIG_CHIP_NAME=BL702L", - ] - - libs = [ "${bl_iot_sdk_root}/components/network/ble/btblecontroller_702l_m1s1p/lib/libbtblecontroller_702l_m1s1p.a" ] + libs = [ "${bl_iot_sdk_root}/components/network/ble/btblecontroller_702l_m0s1p/lib/libbtblecontroller_702l_m0s1p.a" ] include_dirs = [ "${bl_iot_sdk_root}/components/network/ble/blestack/src/common", @@ -617,15 +643,13 @@ template("bl_iot_sdk") { ] configs += [ + ":${sdk_target_name}_config", ":${sdk_target_name}_config_BSP_Driver", - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_hosal", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_freertos", ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_config_ble", - ] + public_configs = [ ":${sdk_target_name}_config_ble" ] cflags_c = [ "-Wno-sign-compare", @@ -646,6 +670,8 @@ template("bl_iot_sdk") { } config("${sdk_target_name}_config_openthread_port") { + defines = [ "OT_FREERTOS_ENABLE=1" ] + include_dirs = [ "${openthread_root}/src/core", "${openthread_root}/examples/platforms", @@ -657,38 +683,47 @@ template("bl_iot_sdk") { source_set("${sdk_target_name}_openthread_port") { import("//build_overrides/openthread.gni") + if (invoker.chip_openthread_ftd) { + defines = [ "CHIP_DEVICE_CONFIG_THREAD_FTD=1" ] + } else { + defines = [ "CHIP_DEVICE_CONFIG_THREAD_FTD=0" ] + } + include_dirs = [ - #"${bl_iot_sdk_root}/components/network/lmac154/include", + "${bl_iot_sdk_root}/components/network/lmac154/lmac154/include", "${bl_iot_sdk_root}/components/network/thread/openthread_port", "${openthread_root}/examples/platforms/utils/", "${openthread_root}/examples", ] sources = [ - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_alarm.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_diag.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_alarm_bl702l.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio_bl70xx.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_sys.c", + ] + + if (defined(invoker.bouffalo_sdk_component_easyflash_enabled) && + invoker.bouffalo_sdk_component_easyflash_enabled) { + sources += [ "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings_easyflash.c" ] + } - # "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_extern.cpp", + libs = [ + "${bl_iot_sdk_root}/components/network/lmac154/lmac154_bl702l/lib/liblmac154_bl702l.a", + "${bl_iot_sdk_root}/components/network/thread/openthread_utils_bl702l/lib/libopenthread_utils_bl702l.a", ] - libs = [ "${bl_iot_sdk_root}/components/network/thread/openthread_utils_bl702l/lib/libopenthread_utils_bl702l.a" ] + cflags_c = [ "-Wno-sign-compare" ] configs += [ + ":${sdk_target_name}_config", ":${sdk_target_name}_config_BSP_Driver", - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_utils", ":${sdk_target_name}_config_hosal", ":${sdk_target_name}_config_stage", + ":${sdk_target_name}_config_freertos", ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_config_openthread_port", - ] + public_configs = [ ":${sdk_target_name}_config_openthread_port" ] public_deps = [ "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", @@ -697,27 +732,30 @@ template("bl_iot_sdk") { } config("${sdk_target_name}_config_factory_data") { - include_dirs = [ "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/include" ] + include_dirs = + [ "${bl_iot_sdk_root}/components/network/matter/mfd/include" ] } source_set("${sdk_target_name}_factory_data") { + defines = [ "BL_MFD_PLAT_H=\"bl_mfd_bl702l.h\"" ] sources = [ - "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/efuse_slot.c", - "${bl_iot_sdk_root}/components/network/matter/matter_factory_data/matter_factory_data.c", + "${bl_iot_sdk_root}/components/network/matter/mfd/bl_mfd.c", + "${bl_iot_sdk_root}/components/network/matter/mfd/bl_mfd_decrypt.c", ] + configs += [ ":${sdk_target_name}_config", - ":${sdk_target_name}_config_bl702l_rom_a0", ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_hosal", + ":${sdk_target_name}_config_freertos", ] public_configs = [ ":${sdk_target_name}_config_factory_data" ] } group(sdk_target_name) { public_deps = [ - ":${sdk_target_name}_bl702l_rom_a0", - ":${sdk_target_name}_factory_data", + ":${sdk_target_name}_BSP_Driver", + ":${sdk_target_name}_bl702l_freertos", ":${sdk_target_name}_fs", ":${sdk_target_name}_hosal", ":${sdk_target_name}_libc", @@ -727,7 +765,6 @@ template("bl_iot_sdk") { ":${sdk_target_name}_sys", ":${sdk_target_name}_utils", ] - public_configs = [ ":${sdk_target_name}_config_BSP_Driver" ] if (defined(invoker.chip_config_network_layer_ble) && invoker.chip_config_network_layer_ble) { @@ -738,5 +775,10 @@ template("bl_iot_sdk") { invoker.chip_enable_openthread) { public_deps += [ ":${sdk_target_name}_openthread_port" ] } + + if (defined(invoker.chip_enable_factory_data) && + invoker.chip_enable_factory_data) { + public_deps += [ ":${sdk_target_name}_factory_data" ] + } } } diff --git a/third_party/bouffalolab/common/bouffalolab_executable.gni b/third_party/bouffalolab/common/bouffalolab_executable.gni index 7410067891fcb4..105a8dc2fe48e4 100644 --- a/third_party/bouffalolab/common/bouffalolab_executable.gni +++ b/third_party/bouffalolab/common/bouffalolab_executable.gni @@ -40,15 +40,22 @@ template("bouffalolab_executable") { "${chip_root}/scripts/flashing/bouffalolab_firmware_utils.py", "${chip_root}/scripts/flashing/firmware_utils.py", ] + copy(flashing_runtime_target) { + sources = flashing_script_inputs + outputs = [ "${root_out_dir}/{{source_file_part}}" ] + } + + flashing_config_target = target_name + ".config" + objcopy_image_name = output_base_name + ".bin" if (invoker.bl_plat_name == "bl602") { - flashing_script_inputs += [ "${chip_root}/examples/platform/bouffalolab/${invoker.bl_plat_name}/flash_config/partition_cfg_4M.toml" ] + flashing_config_inputs = [ "${chip_root}/examples/platform/bouffalolab/${invoker.bl_plat_name}/flash_config/partition_cfg_4M.toml" ] } else { - flashing_script_inputs += [ "${chip_root}/examples/platform/bouffalolab/${invoker.bl_plat_name}/flash_config/partition_cfg_2M.toml" ] + flashing_config_inputs = [ "${chip_root}/examples/platform/bouffalolab/${invoker.bl_plat_name}/flash_config/partition_cfg_2M.toml" ] } - copy(flashing_runtime_target) { - sources = flashing_script_inputs + copy(flashing_config_target) { + sources = flashing_config_inputs outputs = [ "${root_out_dir}/{{source_file_part}}" ] } @@ -58,6 +65,7 @@ template("bouffalolab_executable") { flashing_options = [ "bouffalolab" ] flashing_options += [ "--chipname" ] flashing_options += [ "${invoker.bl_plat_name}" ] + flashing_options += [ "--xtal" ] if (invoker.bl_plat_name == "bl602") { flashing_options += [ "40M" ] @@ -81,15 +89,15 @@ template("bouffalolab_executable") { [ rebase_path("partition_cfg_2M.toml", root_out_dir, root_out_dir) ] } - flashing_options += [ "--ota" ] - flashing_options += [ "ota_images/" ] - # set 2000000 baudrate for image download by default flashing_options += [ "--baudrate" ] flashing_options += [ "2000000" ] flashable_executable(target_name) { forward_variables_from(invoker, "*") - data_deps = [ ":${flashing_runtime_target}" ] + data_deps = [ + ":${flashing_config_target}", + ":${flashing_runtime_target}", + ] } } diff --git a/third_party/bouffalolab/common/rsicv.gni b/third_party/bouffalolab/common/rsicv.gni index 7d056d5a311088..fea2acd4d10100 100644 --- a/third_party/bouffalolab/common/rsicv.gni +++ b/third_party/bouffalolab/common/rsicv.gni @@ -16,8 +16,6 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/platform/device.gni") +import("${chip_root}/src/platform/device.gni") riscv_arch = "rv32imfc" riscv_abi = "ilp32f" -# riscv_cpu = "" -# riscv_float_abi = "hard" -# riscv_fpu = "" diff --git a/third_party/bouffalolab/repo b/third_party/bouffalolab/repo index 07ac148f70e1e3..51a4f451b67a33 160000 --- a/third_party/bouffalolab/repo +++ b/third_party/bouffalolab/repo @@ -1 +1 @@ -Subproject commit 07ac148f70e1e3773f0ba0fa5ccad00bdf40e4d9 +Subproject commit 51a4f451b67a33d07f11cc55e4dbd8ff5d374eb0