Skip to content

Commit

Permalink
[bouffalo lab] Cherry-pick: fix on wifi scan & write operation of bl …
Browse files Browse the repository at this point in the history
…config littlefs & header reserved size, and update script to generate DAC & MFD (#2)

* [bouffalo lab] update scripts and documents to support more options t… (project-chip#37454)

* [bouffalo lab] update scripts and documents to support more options to generate and download test mfd

* Restyled by prettier-markdown

* Restyled by autopep8

* Restyled by isort

* Restyled by prettier-markdown

---------

Co-authored-by: Restyled.io <commits@restyled.io>

* [bouffalolab] update macro define for header reserve size and etherne… (project-chip#37516)

* [bouffalolab] update macro define for header reserve size and ethernet zap configuration

* re-generate lighting-app-ethernet.matter

* [bouffalo lab] open commission window when last fabric is removed (project-chip#37517)

* [bouffalo lab] open commission window when last fabric is removed

* Restyled by whitespace

* fix compile error

---------

Co-authored-by: Restyled.io <commits@restyled.io>

* [bouffalo lab] fix wifi scan issues and update some platform changes (project-chip#37455)

* [bouffalo lab] fix wifi scan issues and update some platform changes

* Restyled by clang-format

* Restyled by gn

* Restyled by clang-format

* fix wifi scan on bl706 + bl602 platform

* Restyled by whitespace

* Restyled by clang-format

* use strncpy to copy ssid

* Restyled by whitespace

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>

* [bouffalo lab] Advertise commissionable on last fabric removal is disabled by default (project-chip#37531)

* [bouffalo lab] Make it possible for application to implement its own fabric delegate

* Advertise commissionable on last fabric removal is disabled by default

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
wy-hh and restyled-commits authored Feb 15, 2025
1 parent 68caf63 commit f114123
Show file tree
Hide file tree
Showing 42 changed files with 739 additions and 185 deletions.
18 changes: 14 additions & 4 deletions docs/guides/bouffalolab/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,34 @@ git clone --recurse-submodules https://github.com/project-chip/connectedhomeip.g
git clone --depth=1 https://github.com/project-chip/connectedhomeip.git
```
- check out `Bouffalo Lab` platform support repos as follows:
- Check out necessary submodules
Checkout `BL_IOT_SDK` for `BL602`, `BL702` and `BL702L` platform:
```
./scripts/checkout_submodules.py --shallow --recursive --platform bouffalolab
```
Checkout `bouffalo_sdk` for `BL616` platform:
```
scripts/checkout_submodules.py --shallow --recursive --platform bouffalolab
./scripts/checkout_submodules.py --shallow --recursive --platform bouffalo_sdk
```
> Please contact `Bouffalo Lab` for `BL616` SDK access.
If you want to checkout Matter Linux example and development tools, please
try as follows:
```
scripts/checkout_submodules.py --shallow --recursive --platform linux bouffalolab
./scripts/checkout_submodules.py --shallow --recursive --platform linux bouffalolab
```
Or if you want to checkout Matter Darwin example and development tools,
please try as follows:
```
scripts/checkout_submodules.py --shallow --recursive --platform darwin bouffalolab
./scripts/checkout_submodules.py --shallow --recursive --platform darwin bouffalolab
```
# Setup build environment
Expand Down
140 changes: 116 additions & 24 deletions docs/guides/bouffalolab/matter_factory_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Script tool
call `chip-cert` to generate test certificates and verify certificates.

Please run below command to compile `chip-cert` tool under `connnectedhomeip`
repo.
repo for Linux platform.

```shell
./scripts/build/build_examples.py --target linux-x64-chip-cert build
Expand Down Expand Up @@ -111,24 +111,47 @@ repo.

Please reference to `--help` for more detail.

## Generate with default test certificates
## Generate with default configuration

- Run following command to generate all plain text factory data
- Default setting uses the following parameters

- PAI certification:
[test PAI certification](../../../credentials/test/attestation/Chip-Test-PAI-FFF1-8000-Key.pem)

- Vendor ID for DAC: 0xFFF1; Vendor ID for CD: 0x130d

- Product ID for DAC: 0x8000, Product ID for CD: 0x1001

* Run following command to generate all plain text factory data

Please create output folder first. Here takes `out/test-cert` as example.

```shell
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert
```

- Run following command to generate factory data which encrypt private of
- Check DAC certificate. Here takes `out_130d_1001_106_dac_cert.pem` as
generated test certificate.

```shell
openssl x509 -noout -text -in out/test-cert/out_130d_1001_106_dac_cert.pem
```

- Check Certification Declare. Here takes `out_130d_1001_cd.der` as
generated test certificate.

```shell
./out/linux-x64-chip-cert/chip-cert print-cd out/test-cert/out_130d_1001_cd.der
```

* Run following command to generate factory data which encrypt private of
device attestation data

```shell
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --key <hex string of 16 bytes>
```

> An example of hex string of 16 bytes: 12345678123456781234567812345678
> An example of hex string of 16 bytes: 12345678123456781234567812345678.

After command executes successfully, the output folder will has files as below:

Expand All @@ -153,20 +176,26 @@ After command executes successfully, the output folder will has files as below:
Self-defined PAA/PAI certificates may use in development and test scenario. But,
user should know it has limit to work with real ecosystem.

- Export environment variables in terminal for easy operations
- Export environment variables in terminal for certificates generation

```
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
export TEST_CERT_CN=BFLB # Common Name
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
export TEST_CERT_PRODUCT_ID=1001 # Product ID hex string
export TEST_CERT_CN=BFLB # Common Name
```

- Generate PAA certificate and key to `out/cert` folder.

```shell
mkdir out/test-cert
./out/linux-x64-chip-cert/chip-cert gen-att-cert --type a --subject-cn "${TEST_CERT_CN} PAA 01" --valid-from "2020-10-15 14:23:43" --lifetime 7305 --out-key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --out out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --subject-vid ${TEST_CERT_VENDOR_ID}
```

- Check PAA certificate

```shell
openssl x509 -noout -text -in out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem
```

- Convert PAA PEM format file to PAA DER format file

```shell
Expand All @@ -182,14 +211,84 @@ user should know it has limit to work with real ecosystem.
./out/linux-x64-chip-cert/chip-cert gen-att-cert --type i --subject-cn "${TEST_CERT_CN} PAI 01" --subject-vid ${TEST_CERT_VENDOR_ID} --valid-from "2020-10-15 14:23:43" --lifetime 7305 --ca-key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --ca-cert out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --out-key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem --out out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem
```

- Generate `MFD` in plain text data
- Check PAI certificate

```shell
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --paa_cert out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --paa_key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --pai_cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --pai_key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem
```
```shell
openssl x509 -noout -text -in out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem
```

> Appending `--key <hex string of 16 bytes>` option to enable encrypt
> private key of attestation device data.
- Generate `MFD` in plain text data with same VID/PID in DAC and CD

- Use same environment variables `TEST_CERT_VENDOR_ID` and
`TEST_CERT_PRODUCT_ID` for CD.

```shell
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --paa_cert out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --paa_key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --pai_cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --pai_key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem --dac_pid 0x${TEST_CERT_PRODUCT_ID} --vendor_id 0x${TEST_CERT_VENDOR_ID} --product_id 0x${TEST_CERT_PRODUCT_ID}
```

> Appending `--key <hex string of 16 bytes>` option to enable encrypt
> private key of attestation device data.

- Check DAC certificate. Here takes `out_130d_1001_1349_dac_cert.pem` as
generated test certification.

```shell
openssl x509 -noout -text -in out/test-cert/out_130d_1001_1349_dac_cert.pem
```

- Check PAA/PAI/DAC certificate chain.

```shell
./out/linux-x64-chip-cert/chip-cert validate-att-cert --dac out/test-cert/out_130d_1001_1349_dac_cert.pem --pai out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --paa out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem
```

- Check Certification Declare. Here takes `out_130d_1001_cd.der` as
generated test certification.

```shell
./out/linux-x64-chip-cert/chip-cert print-cd out/test-cert/out_130d_1001_cd.der
```

- Generate `MFD` in plain text data with different VID/PID in DAC and CD

- Export vendor ID and product ID for CD

```shell
export TEST_CD_VENDOR_ID=730D # Vendor ID hex string
export TEST_CD_PRODUCT_ID=7001 # Product ID hex string
```

- Run script to generate DAC/CD and `MFD`.

```shell
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --paa_cert out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --paa_key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --pai_cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --pai_key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem --dac_pid 0x${TEST_CERT_PRODUCT_ID} --vendor_id 0x${TEST_CD_VENDOR_ID} --product_id 0x${TEST_CD_PRODUCT_ID}
```

> Appending `--key <hex string of 16 bytes>` option to enable encrypt
> private key of attestation device data.
>
> Please use --`vendor_name` and `--product_name` to change vendor name
> and product name.

- Check DAC certificate. Here takes `out_130d_1001_1349_dac_cert.pem` as
generated test certification.

```shell
openssl x509 -noout -text -in out/test-cert/out_130d_1001_1349_dac_cert.pem
```

- Check PAA/PAI/DAC certificate chain.

```shell
./out/linux-x64-chip-cert/chip-cert validate-att-cert --dac out/test-cert/out_130d_1001_1349_dac_cert.pem --pai out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --paa out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem
```

- Check Certification Declare. Here takes `out_730D_7001_cd.der` as
generated test certification.

```shell
./out/linux-x64-chip-cert/chip-cert print-cd out/test-cert/out_130d_1001_cd.der
```

## Generate with self-defined DAC certificate and key

Expand All @@ -200,14 +299,14 @@ user should know it has limit to work with real ecosystem.

```
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
export TEST_CERT_PRODUCT_ID=1001 # Vendor ID hex string
export TEST_CERT_PRODUCT_ID=1001 # Product ID hex string
export TEST_CERT_CN=BFLB # Common Name
```

- Generate DAC certificate and key

```shell
out/linux-x64-chip-cert/chip-cert gen-att-cert --type d --subject-cn "${TEST_CERT_CN} PAI 01" --subject-vid ${TEST_CERT_VENDOR_ID} --subject-pid ${TEST_CERT_VENDOR_ID} --valid-from "2020-10-16 14:23:43" --lifetime 5946 --ca-key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem --ca-cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --out-key out/test-cert/Chip-DAC-Key-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem --out out/test-cert/Chip-DAC-Cert-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem
out/linux-x64-chip-cert/chip-cert gen-att-cert --type d --subject-cn "${TEST_CERT_CN} PAI 01" --subject-vid ${TEST_CERT_VENDOR_ID} --subject-pid ${TEST_CERT_PRODUCT_ID} --valid-from "2020-10-16 14:23:43" --lifetime 5946 --ca-key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem --ca-cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --out-key out/test-cert/Chip-DAC-Key-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem --out out/test-cert/Chip-DAC-Cert-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem
```

> **Note**, `--valid-from` and `--lifetime` should be in `--valid-from` and
Expand Down Expand Up @@ -238,12 +337,5 @@ key.
> If `MFD` file has cipher text data, please append
> `--key <hex string of 16 bytes>` option to program to this key to efuse.

- Limits on BL IOT SDK

If developer would like to program `MFD` with all plain text data, option
`--key <hex string of 16 bytes>` needs pass to script, otherwise, flash tool
will raise an error. And SoC BL602, BL702 and BL702L use BL IOT SDK for
Matter Application.

Please free contact to `Bouffalo Lab` for DAC provider service and higher
security solution, such as SoC inside certificate requesting.
12 changes: 0 additions & 12 deletions examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,9 @@ extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
extern BaseType_t TrapNetCounter, *pTrapNetCounter;
if (app_pds_wakeup_source == PDS_WAKEUP_BY_RTC)
{
extern void * pxCurrentTCB;

ChipLogProgress(NotSpecified, "wakeup source: rtc. %lu vs %lu ms @ %lu\r\n", xExpectedIdleTime,
(uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before), (uint32_t) bl_rtc_get_timestamp_ms());

ChipLogProgress(NotSpecified, "application_sleep; %lu, %lu, %lu\r\n", (uint32_t) sleep_calling_time, (uint32_t) sleep_time,
(uint32_t) wakeup_time);
}
else if (app_pds_wakeup_source == PDS_WAKEUP_BY_GPIO)
{

if (((1 << CHIP_RESET_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler)
{
app_pds_irq_handler(&gpio_key);
Expand All @@ -79,10 +71,6 @@ extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
{
app_pds_irq_handler(&gpio_contact);
}

ChipLogProgress(NotSpecified, "wakeup source: gpio -> 0x%08lX. %lu vs %lu ms @ %lu\r\n", app_pds_wakeup_pin,
xExpectedIdleTime, (uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before),
(uint32_t) bl_rtc_get_timestamp_ms());
}

app_pds_wakeup_source = -1;
Expand Down
11 changes: 9 additions & 2 deletions examples/lighting-app/bouffalolab/bl602/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ bl_iot_sdk("sdk") {
"OTA_AUTO_REBOOT_DELAY=${ota_auto_reboot_delay_seconds}",
"CHIP_UART_BAUDRATE=${baudrate}",
"SYS_AOS_LOOP_ENABLE",
"CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE=48",
]

defines += [ "PW_RPC_ENABLED=${chip_enable_pw_rpc}" ]
Expand All @@ -97,7 +96,7 @@ bouffalolab_executable("lighting_app") {
output_name = "chip-bl602-lighting-example.out"

defines = [
"APP_TASK_STACK_SIZE=2044",
"APP_TASK_STACK_SIZE=4096",
"CHIP_UART_BAUDRATE=${baudrate}",
"START_ENTRY=bfl_main",
"SYS_AOS_LOOP_ENABLE",
Expand All @@ -110,6 +109,10 @@ bouffalolab_executable("lighting_app") {
defines +=
[ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ]

if (enable_lwip_pbuf_ram) {
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
}

bl_plat_name = "bl602"
sources = [
"${examples_plat_dir}/common/route_hook/bl_route_hook.c",
Expand Down Expand Up @@ -228,6 +231,10 @@ bouffalolab_executable("lighting_app") {
inputs = [ ldscript ]

if (chip_print_memory_usage) {
if (enable_lwip_pbuf_ram) {
ldflags += [ "-Wl,--defsym=__RAM_PBUF_POOL=0" ]
}

ldflags += [
"-Wl,--print-memory-usage",
"-fstack-usage",
Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/bouffalolab/bl616/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ bouffalolab_executable("lighting_app") {
defines += [ "BOOT_PIN_RESET=2" ]
}

if (enable_lwip_pbuf_ram) {
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
}

defines += [ "BL616DK" ]

sources = [
Expand Down
11 changes: 1 addition & 10 deletions examples/lighting-app/bouffalolab/bl616/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ import("${chip_root}/src/platform/bouffalolab/BL616/args.gni")

bouffalo_sdk_target = get_label_info(":sdk", "label_no_toolchain")

pw_log_BACKEND = "${chip_root}/src/pw_backends/log"
pw_assert_BACKEND = "${chip_root}/src/pw_backends/assert"
pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex"

chip_detail_logging = true
chip_detail_logging = false

# use -Os instead of -Og
is_debug = false

pw_build_LINK_DEPS = [
"$dir_pw_assert:impl",
"$dir_pw_log:impl",
]
5 changes: 1 addition & 4 deletions examples/lighting-app/bouffalolab/bl702/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ bl_iot_sdk("sdk") {
}

defines += [ "CHIP_DEVICE_CONFIG_ENABLE_ETHERNET=${chip_enable_ethernet}" ]
if (chip_enable_ethernet) {
defines += [ "CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE=48" ]
}

if (enable_psram) {
defines += [ "CFG_USE_PSRAM=1" ]
Expand Down Expand Up @@ -129,7 +126,7 @@ bouffalolab_executable("lighting_app") {
bl_plat_name = "bl702"

defines = [
"APP_TASK_STACK_SIZE=2048",
"APP_TASK_STACK_SIZE=4096",
"CHIP_UART_BAUDRATE=${baudrate}",
"START_ENTRY=bl702_main",
]
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl702l/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bouffalolab_executable("lighting_app") {
bl_plat_name = "bl702l"

defines = [
"APP_TASK_STACK_SIZE=2048",
"APP_TASK_STACK_SIZE=4096",
"CHIP_UART_BAUDRATE=${baudrate}",
"START_ENTRY=bl702_main",
]
Expand Down
Loading

0 comments on commit f114123

Please sign in to comment.