From b2fbfa999584761265ce7f7fe742eb5425ff0a24 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Wed, 12 Feb 2025 02:54:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[bouffalo=20lab]=20update=20scripts=20and?= =?UTF-8?q?=20documents=20to=20support=20more=20options=20t=E2=80=A6=20(#3?= =?UTF-8?q?7454)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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 --- docs/guides/bouffalolab/getting_started.md | 18 ++- .../guides/bouffalolab/matter_factory_data.md | 140 +++++++++++++++--- .../flashing/bouffalolab_firmware_utils.py | 120 +++++++++++---- scripts/setup/requirements.bouffalolab.txt | 3 +- .../bouffalolab/generate_factory_data.py | 55 ++++--- 5 files changed, 264 insertions(+), 72 deletions(-) diff --git a/docs/guides/bouffalolab/getting_started.md b/docs/guides/bouffalolab/getting_started.md index eb96bc8da04728..08d61fce816c49 100644 --- a/docs/guides/bouffalolab/getting_started.md +++ b/docs/guides/bouffalolab/getting_started.md @@ -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 diff --git a/docs/guides/bouffalolab/matter_factory_data.md b/docs/guides/bouffalolab/matter_factory_data.md index 9021cd80f61815..b46cb4801bef50 100644 --- a/docs/guides/bouffalolab/matter_factory_data.md +++ b/docs/guides/bouffalolab/matter_factory_data.md @@ -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 @@ -111,9 +111,18 @@ 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. @@ -121,14 +130,28 @@ Please reference to `--help` for more detail. ./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 ``` - > 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: @@ -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 @@ -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 ` 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 ` 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 ` 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 @@ -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 @@ -238,12 +337,5 @@ key. > If `MFD` file has cipher text data, please append > `--key ` 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 ` 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. diff --git a/scripts/flashing/bouffalolab_firmware_utils.py b/scripts/flashing/bouffalolab_firmware_utils.py index e6ca898609102f..a65ec869ed7b39 100755 --- a/scripts/flashing/bouffalolab_firmware_utils.py +++ b/scripts/flashing/bouffalolab_firmware_utils.py @@ -446,7 +446,67 @@ def exe_gen_ota_image_cmd(flashtool_exe): 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): + def construct_prog_confg(): + + iot_cfg = { + "param": { + "interface_type": "uart", + "comport_uart": self.args["port"], + "speed_uart": self.args["baudrate"], + "speed_jlink": "1000", + "chip_xtal": self.args["xtal"], + "ota": "", + "version": "", + "aes_key": "", + "aes_iv": "", + "addr": "0x0", + "publickey": "", + "privatekey": "" + }, + "check_box": { + "fw_download": True, + "mfg_download": False, + "media_download": False, + "romfs_download": False, + "psm_download": False, + "key_download": False, + "data_download": False, + "factory_download": True if self.args["dts"] else False, + "mfd_download": True if self.args["mfd"] else False, + "boot2_download": True if self.args["boot2"] else False, + "ckb_erase_all": "True" if self.args["erase"] else "False", + "partition_download": True if self.args["pt"] else False, + "encrypt": False, + "sign": False, + "single_download": False, + "auto_efuse_verify": False + }, + "input_path": { + "fw_bin_input": self.args['firmware'], + "mfg_bin_input": "", + "media_bin_input": "", + "romfs_dir_input": "", + "psm_bin_input": "", + "key_bin_input": "", + "data_bin_input": "", + "factory_bin_input": self.args["dts"], + "mfd_bin_input": self.args["mfd"], + "boot2_bin_input": self.args["boot2"], + "img_bin_input": "", + "pt_table_bin_input": self.args["pt"], + "publickey": "", + "privatekey": "" + } + } + + conf_toml = os.path.splitext(self.args['firmware'])[0] + "_config.toml" + + with open(conf_toml, "w", encoding="utf-8") as f: + toml.dump(iot_cfg, f) + + return conf_toml + + def exe_prog_cmd(flashtool_exe, mfd_addr, flashtool_path): if not self.args["port"]: return @@ -454,33 +514,43 @@ def exe_prog_cmd(flashtool_exe, mfd_addr): 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["mfd"] and not self.args["key"]: + conf_toml = construct_prog_confg() - if self.args["boot2"]: - prog_cmd += ["--boot2", self.args["boot2"]] + prog_cmd = [ + flashtool_exe, + "--chipname", self.args["chipname"], + "--config", conf_toml, + ] - if self.args["sk"]: - prog_cmd += ["--sk", self.args["sk"]] + else: + 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 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: - 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.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: + 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"] + 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) @@ -500,7 +570,7 @@ def exe_prog_cmd(flashtool_exe, mfd_addr): os.chdir(self.work_dir) exe_gen_ota_image_cmd(flashtool_exe) - exe_prog_cmd(flashtool_exe, mfd_addr) + exe_prog_cmd(flashtool_exe, mfd_addr, flashtool_path) def bouffalo_sdk_prog(self): diff --git a/scripts/setup/requirements.bouffalolab.txt b/scripts/setup/requirements.bouffalolab.txt index 2abdd5f27c873a..9dc4cc2c226ac0 100644 --- a/scripts/setup/requirements.bouffalolab.txt +++ b/scripts/setup/requirements.bouffalolab.txt @@ -5,4 +5,5 @@ qrcode==7.4.2 bitarray==2.6.0 python_stdnum==1.18 pycryptodome>=3.20.0 -construct>=2.10.70 \ No newline at end of file +toml>=0.10.2 +construct>=2.10.70 diff --git a/scripts/tools/bouffalolab/generate_factory_data.py b/scripts/tools/bouffalolab/generate_factory_data.py index 28f362ba2d3b21..d548f9c5fd06d5 100755 --- a/scripts/tools/bouffalolab/generate_factory_data.py +++ b/scripts/tools/bouffalolab/generate_factory_data.py @@ -132,7 +132,9 @@ def gen_test_certs(chip_cert: str, pai_cert: str = None, pai_key: str = None, dac_cert: str = None, - dac_key: str = None): + dac_key: str = None, + dac_product_id: int = None, + discriminator: int = None): def parse_cert_file(cert): @@ -188,7 +190,7 @@ def verify_certificates(chip_cert, paa_cert, pai_cert, dac_cert): log.info("Verify Certificate Chain: {}".format(" ".join(cmd))) subprocess.run(cmd) - def gen_dac_certificate(chip_cert, device_name, vendor_id, product_id, pai_cert, pai_key, dac_cert, dac_key, pai_issue_date, pai_expire_date): + def gen_dac_certificate(chip_cert, device_name, dac_vid, dac_pid, pai_cert, pai_key, dac_cert, dac_key, pai_issue_date, pai_expire_date, discriminator): def gen_valid_times(issue_date, expire_date): now = datetime.now() - timedelta(days=1) @@ -205,8 +207,8 @@ def gen_valid_times(issue_date, expire_date): cmd = [chip_cert, "gen-att-cert", "--type", "d", # device attestation certificate "--subject-cn", device_name + " Test DAC 0", - "--subject-vid", hex(vendor_id), - "--subject-pid", hex(product_id), + "--subject-vid", hex(dac_vid), + "--subject-pid", hex(dac_pid), "--ca-cert", pai_cert, "--ca-key", pai_key, "--out", dac_cert, @@ -229,7 +231,7 @@ def convert_pem_to_der(chip_cert, action, pem): return der - def gen_cd(chip_cert, dac_vendor_id, dac_product_id, vendor_id, product_id, cd_cert, cd_key, cd): + def gen_cd(chip_cert, paa_cert, dac_vendor_id, dac_product_id, vendor_id, product_id, cd_cert, cd_key, cd): if os.path.isfile(cd): return @@ -254,15 +256,29 @@ def gen_cd(chip_cert, dac_vendor_id, dac_product_id, vendor_id, product_id, cd_c "--dac-origin-product-id", hex(dac_product_id), ] - log.info("Generate CD: {}".format(" ".join(cmd))) + if paa_cert: + cmd += ["--authorized-paa-cert", paa_cert] + + log.info("Generate CD: {}".format(shlex.join(cmd))) subprocess.run(cmd) pai_vendor_id, pai_product_id, pai_issue_date, pai_expire_date = parse_cert_file(pai_cert) - dac_vendor_id = pai_vendor_id if pai_vendor_id else vendor_id - dac_product_id = pai_product_id if pai_product_id else product_id + dac_vendor_id = pai_vendor_id + + if dac_product_id is not None and pai_product_id is not None and dac_product_id != pai_product_id: + raise Exception("Specified product id for DAC certificate is not same as product id in PAI certificate.") + + if pai_product_id is not None: + dac_product_id = pai_product_id + + if dac_cert is None: + dac_disc_vp = "{}_{}_{}".format(hex(dac_vendor_id).split("x")[-1], hex(dac_product_id).split("x")[-1], discriminator) + dac_cert = os.path.join(output, "out_{}_dac_cert.pem".format(dac_disc_vp)) + dac_key = os.path.join(output, "out_{}_dac_key.pem".format(dac_disc_vp)) + gen_dac_certificate(chip_cert, device_name, dac_vendor_id, dac_product_id, pai_cert, - pai_key, dac_cert, dac_key, pai_issue_date, pai_expire_date) + pai_key, dac_cert, dac_key, pai_issue_date, pai_expire_date, discriminator) dac_cert_der = convert_pem_to_der(chip_cert, "convert-cert", dac_cert) dac_key_der = convert_pem_to_der(chip_cert, "convert-key", dac_key) @@ -273,7 +289,7 @@ def gen_cd(chip_cert, dac_vendor_id, dac_product_id, vendor_id, product_id, cd_c verify_certificates(chip_cert, paa_cert, pai_cert, dac_cert) - gen_cd(chip_cert, dac_vendor_id, dac_product_id, vendor_id, product_id, cd_cert, cd_key, cd) + gen_cd(chip_cert, paa_cert, dac_vendor_id, dac_product_id, vendor_id, product_id, cd_cert, cd_key, cd) return cd, pai_cert_der, dac_cert_der, dac_key_der @@ -446,10 +462,14 @@ def to_bytes(input): else: return None + def hex_to_int(hex_string): + return int(hex_string, 16) + parser = argparse.ArgumentParser(description="Bouffalo Lab Factory Data generator tool") parser.add_argument("--dac_cert", type=str, help="DAC certificate file.") parser.add_argument("--dac_key", type=str, help="DAC certificate privat key.") + parser.add_argument("--dac_pid", type=hex_to_int, help="Product Identification, hex string, used in DAC certificate. ") parser.add_argument("--passcode", type=int, help="Setup pincode, optional.") parser.add_argument("--pai_cert", type=str, default=TEST_PAI_CERT, help="PAI certificate file.") parser.add_argument("--cd", type=str, help="Certificate Declaration file.") @@ -459,9 +479,9 @@ def to_bytes(input): parser.add_argument("--spake2p_it", type=int, default=None, help="Spake2+ iteration count, optional.") parser.add_argument("--spake2p_salt", type=base64.b64decode, help="Spake2+ salt in hex string, optional.") - parser.add_argument("--vendor_id", type=int, default=0x130D, help="Vendor Identification, mandatory.") + parser.add_argument("--vendor_id", type=hex_to_int, default=0x130D, help="Vendor Identification, hex string, mandatory.") parser.add_argument("--vendor_name", type=str, default="Bouffalo Lab", help="Vendor Name string, optional.") - parser.add_argument("--product_id", type=int, default=0x1001, help="Product Identification, mandatory.") + parser.add_argument("--product_id", type=hex_to_int, default=0x1001, help="Product Identification, hex string, mandatory.") parser.add_argument("--product_name", type=str, default="Test Product", help="Product Name string, optional.") parser.add_argument("--product_part_no", type=str, help="Product Part number, optional.") @@ -493,11 +513,8 @@ def to_bytes(input): unique_id = gen_test_unique_id(args.unique_id) spake2p_it, spake2p_salt, spake2p_verifier = gen_test_spake2(passcode, args.spake2p_it, args.spake2p_salt) - vp_info = "{}_{}".format(hex(args.vendor_id), hex(args.product_id)) - vp_disc_info = "{}_{}_{}".format(hex(args.vendor_id), hex(args.product_id), discriminator) - if args.dac_cert is None: - args.dac_cert = os.path.join(args.output, "out_{}_dac_cert.pem".format(vp_disc_info)) - args.dac_key = os.path.join(args.output, "out_{}_dac_key.pem".format(vp_disc_info)) + vp_info = "{}_{}".format(hex(args.vendor_id).split('x')[-1], hex(args.product_id).split('x')[-1]) + vp_disc_info = "{}_{}".format(vp_info, discriminator) if args.cd is None: args.cd = os.path.join(args.output, "out_{}_cd.der".format(vp_info)) @@ -515,7 +532,9 @@ def to_bytes(input): args.pai_cert, args.pai_key, args.dac_cert, - args.dac_key) + args.dac_key, + args.dac_pid, + discriminator) mfd_output = os.path.join(args.output, "out_{}_mfd.bin".format(vp_disc_info)) args.dac_cert = dac_cert_der From 728de39b3a301fce73fa0a23d4452b99180a2350 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Wed, 12 Feb 2025 03:10:24 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[bouffalolab]=20update=20macro=20define=20f?= =?UTF-8?q?or=20header=20reserve=20size=20and=20etherne=E2=80=A6=20(#37516?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [bouffalolab] update macro define for header reserve size and ethernet zap configuration * re-generate lighting-app-ethernet.matter --- .../lighting-app/bouffalolab/bl602/BUILD.gn | 1 - .../lighting-app/bouffalolab/bl702/BUILD.gn | 3 - .../data_model/lighting-app-ethernet.matter | 14 +- .../data_model/lighting-app-ethernet.zap | 174 +++++++++++++++++- .../bouffalolab/common/SystemPlatformConfig.h | 6 +- 5 files changed, 190 insertions(+), 8 deletions(-) diff --git a/examples/lighting-app/bouffalolab/bl602/BUILD.gn b/examples/lighting-app/bouffalolab/bl602/BUILD.gn index c45251824fefbb..a487c81c00ad21 100644 --- a/examples/lighting-app/bouffalolab/bl602/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl602/BUILD.gn @@ -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}" ] diff --git a/examples/lighting-app/bouffalolab/bl702/BUILD.gn b/examples/lighting-app/bouffalolab/bl702/BUILD.gn index 9cec7d240e0ff7..c86d3313ba6256 100644 --- a/examples/lighting-app/bouffalolab/bl702/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702/BUILD.gn @@ -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" ] diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter index ac770a74de722e..94f286d9f605a3 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter @@ -2126,6 +2126,18 @@ endpoint 0 { binding cluster OtaSoftwareUpdateProvider; + server cluster Descriptor { + callback attribute deviceTypeList; + callback attribute serverList; + callback attribute clientList; + callback attribute partsList; + callback attribute generatedCommandList; + callback attribute acceptedCommandList; + callback attribute attributeList; + callback attribute featureMap; + callback attribute clusterRevision; + } + server cluster AccessControl { emits event AccessControlEntryChanged; emits event AccessControlExtensionChanged; @@ -2208,7 +2220,7 @@ endpoint 0 { ram attribute lastNetworkingStatus; ram attribute lastNetworkID; ram attribute lastConnectErrorValue; - ram attribute featureMap default = 1; + ram attribute featureMap default = 4; ram attribute clusterRevision default = 1; handle command ScanNetworks; diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap index 5a0e876845aef6..b1f2eace627e8e 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap @@ -61,6 +61,176 @@ "deviceTypeCode": 22, "deviceTypeProfileId": 259, "clusters": [ + { + "name": "Descriptor", + "code": 29, + "mfgCode": null, + "define": "DESCRIPTOR_CLUSTER", + "side": "server", + "enabled": 1, + "attributes": [ + { + "name": "DeviceTypeList", + "code": 0, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ServerList", + "code": 1, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClientList", + "code": 2, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "PartsList", + "code": 3, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "GeneratedCommandList", + "code": 65528, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AcceptedCommandList", + "code": 65529, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "EventList", + "code": 65530, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AttributeList", + "code": 65531, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "server", + "type": "bitmap32", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClusterRevision", + "code": 65533, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + } + ] + }, { "name": "Access Control", "code": 31, @@ -1197,7 +1367,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "1", + "defaultValue": "4", "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -4147,4 +4317,4 @@ "parentEndpointIdentifier": null } ] -} \ No newline at end of file +} diff --git a/src/platform/bouffalolab/common/SystemPlatformConfig.h b/src/platform/bouffalolab/common/SystemPlatformConfig.h index 89a0a5a8f9a966..5802b386225b28 100644 --- a/src/platform/bouffalolab/common/SystemPlatformConfig.h +++ b/src/platform/bouffalolab/common/SystemPlatformConfig.h @@ -38,9 +38,13 @@ struct ChipDeviceEvent; // #define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(mbedtls_sha256_context) in hw_acc/sha256_alt.h #define CHIP_CONFIG_SHA256_CONTEXT_SIZE (32 + 64 + 64 + 19 * 32) #define CHIP_CONFIG_SHA256_CONTEXT_ALIGN 32 -#define CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE (388) #else // #define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(bl_sha_ctx_t) #define CHIP_CONFIG_SHA256_CONTEXT_SIZE ((7 + 1 + 5 + 18 + 16 + 16 + 7) * sizeof(unsigned int)) #endif + +#if CHIP_SYSTEM_CONFIG_USE_LWIP +#define CHIP_SYSTEM_CONFIG_HEADER_RESERVE_SIZE \ + (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN + CHIP_SYSTEM_HEADER_RESERVE_SIZE) +#endif From cdbd77f2c3ea8daf2a98edc658d9a41c10571be0 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Wed, 12 Feb 2025 04:04:00 +0800 Subject: [PATCH 3/5] [bouffalo lab] open commission window when last fabric is removed (#37517) * [bouffalo lab] open commission window when last fabric is removed * Restyled by whitespace * fix compile error --------- Co-authored-by: Restyled.io --- .../bouffalolab/common/plat/platform.cpp | 32 +++++++++++++++++++ .../BL616/ThreadStackManagerImpl.cpp | 6 ++++ .../BL702/ThreadStackManagerImpl.cpp | 6 ++++ .../BL702L/ThreadStackManagerImpl.cpp | 6 ++++ .../bouffalolab/common/BLConfig_littlefs.cpp | 4 +-- .../common/ConfigurationManagerImpl.cpp | 11 +++++++ .../common/ConfigurationManagerImpl.h | 4 +++ .../common/ThreadStackManagerImpl.h | 1 + 8 files changed, 68 insertions(+), 2 deletions(-) diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index ef6a2452cdbb04..57dcb795e730ff 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -177,6 +177,35 @@ void UnlockOpenThreadTask(void) } #endif +class AppFabricTableDelegate : public FabricTable::Delegate +{ + void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) + { + if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) + { + ChipLogProgress(DeviceLayer, "Performing erasing of settings partition"); + PlatformMgr().ScheduleWork([](intptr_t) { +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + ConfigurationManagerImpl::GetDefaultInstance().ClearThreadStack(); + ThreadStackMgrImpl().FactoryResetThreadStack(); + ThreadStackMgr().InitThreadStack(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + ChipLogProgress(DeviceLayer, "Clearing WiFi provision"); + chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + + CHIP_ERROR err = Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Failed to open the Basic Commissioning Window"); + } + }); + } + } +}; + CHIP_ERROR PlatformManagerImpl::PlatformInit(void) { chip::RendezvousInformationFlags rendezvousMode(chip::RendezvousInformationFlag::kOnNetwork); @@ -263,6 +292,9 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); + static AppFabricTableDelegate sAppFabricDelegate; + chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppFabricDelegate); + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/platform/bouffalolab/BL616/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL616/ThreadStackManagerImpl.cpp index 251ccf5113a294..17d73f9ea2309e 100644 --- a/src/platform/bouffalolab/BL616/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL616/ThreadStackManagerImpl.cpp @@ -63,6 +63,12 @@ bool ThreadStackManagerImpl::IsInitialized() return sInstance.mThreadStackLock != NULL; } +void ThreadStackManagerImpl::FactoryResetThreadStack(void) +{ + VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL); + otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance()); +} + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp index 784dfa396cd371..a2072eff6be32d 100644 --- a/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp @@ -65,6 +65,12 @@ bool ThreadStackManagerImpl::IsInitialized() return sInstance.mThreadStackLock != NULL; } +void ThreadStackManagerImpl::FactoryResetThreadStack(void) +{ + VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL); + otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance()); +} + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp index 784dfa396cd371..a2072eff6be32d 100644 --- a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp @@ -65,6 +65,12 @@ bool ThreadStackManagerImpl::IsInitialized() return sInstance.mThreadStackLock != NULL; } +void ThreadStackManagerImpl::FactoryResetThreadStack(void) +{ + VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL); + otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance()); +} + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/bouffalolab/common/BLConfig_littlefs.cpp b/src/platform/bouffalolab/common/BLConfig_littlefs.cpp index 7f5e221195e8d3..84b7db21ead7b2 100644 --- a/src/platform/bouffalolab/common/BLConfig_littlefs.cpp +++ b/src/platform/bouffalolab/common/BLConfig_littlefs.cpp @@ -278,7 +278,7 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si blconfig_lfs->cfg->lock(blconfig_lfs->cfg); - ret = lfs_file_open(blconfig_lfs, &file, write_key, LFS_O_CREAT | LFS_O_RDWR); + ret = lfs_file_open(blconfig_lfs, &file, write_key, LFS_O_CREAT | LFS_O_RDWR | LFS_O_TRUNC); VerifyOrExit(ret == LFS_ERR_OK, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); lfs_file_write(blconfig_lfs, &file, val, size); @@ -353,7 +353,7 @@ CHIP_ERROR BLConfig::FactoryResetConfig(void) blconfig_lfs->cfg->lock(blconfig_lfs->cfg); - ret = lfs_file_open(blconfig_lfs, &file, reset_key, LFS_O_CREAT | LFS_O_RDWR); + ret = lfs_file_open(blconfig_lfs, &file, reset_key, LFS_O_CREAT | LFS_O_RDWR | LFS_O_TRUNC); if (ret != LFS_ERR_OK) { blconfig_lfs->cfg->unlock(blconfig_lfs->cfg); diff --git a/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp index 176803d00a1ebe..39d535aba6ade1 100644 --- a/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp +++ b/src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp @@ -190,6 +190,17 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void) BLConfig::RunConfigUnitTest(); } +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +void ConfigurationManagerImpl::ClearThreadStack() +{ +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT + ThreadStackMgr().ClearAllSrpHostAndServices(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT + ChipLogProgress(DeviceLayer, "Clearing Thread provision"); + ThreadStackMgr().ErasePersistentInfo(); +} +#endif + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; diff --git a/src/platform/bouffalolab/common/ConfigurationManagerImpl.h b/src/platform/bouffalolab/common/ConfigurationManagerImpl.h index 1e7bb53922eb79..765d6b53b1a904 100644 --- a/src/platform/bouffalolab/common/ConfigurationManagerImpl.h +++ b/src/platform/bouffalolab/common/ConfigurationManagerImpl.h @@ -38,6 +38,10 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours); bool IsFullyProvisioned(); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + void ClearThreadStack(); +#endif + private: // ===== Members that implement the ConfigurationManager private interface. diff --git a/src/platform/bouffalolab/common/ThreadStackManagerImpl.h b/src/platform/bouffalolab/common/ThreadStackManagerImpl.h index 462d2de76ac32d..cd743bf93848eb 100644 --- a/src/platform/bouffalolab/common/ThreadStackManagerImpl.h +++ b/src/platform/bouffalolab/common/ThreadStackManagerImpl.h @@ -65,6 +65,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager, using ThreadStackManager::InitThreadStack; CHIP_ERROR InitThreadStack(otInstance * otInst); + void FactoryResetThreadStack(void); private: // ===== Methods that implement the ThreadStackManager abstract interface. From 517d968aa789868044e8e49cd32e01f1908605e5 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Wed, 12 Feb 2025 13:07:27 +0800 Subject: [PATCH 4/5] [bouffalo lab] fix wifi scan issues and update some platform changes (#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 --- .../bouffalolab/bl702l/app_pds.cpp | 12 -- .../lighting-app/bouffalolab/bl602/BUILD.gn | 10 +- .../lighting-app/bouffalolab/bl616/BUILD.gn | 4 + .../lighting-app/bouffalolab/bl616/args.gni | 11 +- .../lighting-app/bouffalolab/bl702/BUILD.gn | 2 +- .../lighting-app/bouffalolab/bl702l/BUILD.gn | 2 +- .../bouffalolab/bl602/ldscripts/flash_rom.ld | 7 +- .../bouffalolab/bl602/lwipopts/lwipopts.h | 30 +++- .../platform/bouffalolab/bl616/lwipopts.h | 21 ++- .../bl702/ldscripts/psram_flash.ld | 3 + .../bl702l/ldscripts/psram_flash.ld | 3 + .../common/bouffalo_sdk/platform_port.cpp | 2 + .../bouffalolab/common/plat/platform.cpp | 3 +- scripts/build/builders/bouffalolab.py | 10 +- .../BL602/NetworkCommissioningDriver.cpp | 2 +- .../BL702/ConnectivityManagerImpl.cpp | 7 + .../BL702/NetworkCommissioningDriver.cpp | 131 ++++++++++-------- .../BL702/NetworkCommissioningDriver.h | 6 +- .../common/CHIPDevicePlatformConfig.h | 2 + .../common/DiagnosticDataProviderImpl.cpp | 8 +- .../common/DiagnosticDataProviderImpl.h | 1 + third_party/bouffalolab/bl602/bl_iot_sdk.gni | 16 ++- .../bouffalolab/bl616/bouffalo_sdk.gni | 18 ++- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 1 + third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 1 + third_party/bouffalolab/repo | 2 +- 26 files changed, 210 insertions(+), 105 deletions(-) diff --git a/examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp b/examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp index e3ed09ae6393c1..d6b2141108d75c 100644 --- a/examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp +++ b/examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp @@ -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); @@ -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; diff --git a/examples/lighting-app/bouffalolab/bl602/BUILD.gn b/examples/lighting-app/bouffalolab/bl602/BUILD.gn index a487c81c00ad21..fa35de6932f25b 100644 --- a/examples/lighting-app/bouffalolab/bl602/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl602/BUILD.gn @@ -96,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", @@ -109,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", @@ -227,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", diff --git a/examples/lighting-app/bouffalolab/bl616/BUILD.gn b/examples/lighting-app/bouffalolab/bl616/BUILD.gn index 6671db3f9f7a6d..6890ad52000eee 100644 --- a/examples/lighting-app/bouffalolab/bl616/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl616/BUILD.gn @@ -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 = [ diff --git a/examples/lighting-app/bouffalolab/bl616/args.gni b/examples/lighting-app/bouffalolab/bl616/args.gni index d031a4b769ec88..aa60a4234e0c07 100644 --- a/examples/lighting-app/bouffalolab/bl616/args.gni +++ b/examples/lighting-app/bouffalolab/bl616/args.gni @@ -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", -] diff --git a/examples/lighting-app/bouffalolab/bl702/BUILD.gn b/examples/lighting-app/bouffalolab/bl702/BUILD.gn index c86d3313ba6256..35b7041d7d89f2 100644 --- a/examples/lighting-app/bouffalolab/bl702/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702/BUILD.gn @@ -126,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", ] diff --git a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn index c004af4134dfc2..de9210b4b1b714 100644 --- a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn @@ -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", ] diff --git a/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld b/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld index 206f89bd077fd3..6393c9d2d75663 100644 --- a/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld +++ b/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld @@ -11,7 +11,9 @@ __RFTLV_HEAD1_L = (0x41524150); /* PAPA */ __RAM_START = 0x4200C000; __RAM_END = 0x4200C000 + 256K - __EM_SIZE; /* leave 8K left for BLE */ -__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K); +__RAM_PBUF_POOL = DEFINED(__RAM_PBUF_POOL) ? __RAM_PBUF_POOL : 30K; + +__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K + 30K - 12K - __RAM_PBUF_POOL); __RAM_WIFI_LEN = (__RAM_END - __RAM_START - __RAM_TCM_LEN); MEMORY @@ -173,6 +175,9 @@ SECTIONS *libwifi_drv.a:bl_utils.o(.bss*) *(.wifi_ram*) . = ALIGN(16); + + KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*)) + . = ALIGN(16); } > ram_wifi PROVIDE( _heap_wifi_start = . ); diff --git a/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h b/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h index 93c14da58cfbbb..ebcb05a4866f67 100644 --- a/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h +++ b/examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h @@ -78,10 +78,6 @@ a lot of data that needs to be copied, this should be set high. */ #define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB + MEMP_NUM_UDP_PCB + MEMP_NUM_TCP_PCB_LISTEN) -/* ---------- Pbuf options ---------- */ -/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ -#define PBUF_POOL_SIZE 20 - /* ---------- TCP options ---------- */ #define LWIP_TCP 1 #define IP_DEFAULT_TTL 64 @@ -269,17 +265,37 @@ a lot of data that needs to be copied, this should be set high. */ #define LWIP_NETIF_EXT_STATUS_CALLBACK 1 -/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ #define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN) -#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) - /* --------------------------------- ---------- MISC. options ---------- --------------------------------- */ +#if defined(CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM) && CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM +#define PBUF_POOL_SIZE 0 +#define MEM_LIBC_MALLOC 0 +#define MEM_USE_POOLS 0 +#define MEMP_USE_CUSTOM_POOLS 0 + +#include +#include +#define LWIP_PBUF_CUSTOM_DATA mem_size_t pool; + +#if defined(__cplusplus) +extern "C" const mem_size_t * memp_sizes; +extern "C" struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset); +#else +extern const mem_size_t * memp_sizes; +extern struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset); +#endif +#else + +#define PBUF_POOL_SIZE 20 +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#endif + #if defined(__cplusplus) extern "C" int bl_rand(void); extern "C" int * __errno(void); diff --git a/examples/platform/bouffalolab/bl616/lwipopts.h b/examples/platform/bouffalolab/bl616/lwipopts.h index 91d779fb9356e5..04671c945c227d 100644 --- a/examples/platform/bouffalolab/bl616/lwipopts.h +++ b/examples/platform/bouffalolab/bl616/lwipopts.h @@ -120,10 +120,9 @@ extern const int fhost_tcpip_priority; #define MEMP_NUM_UDP_PCB 16 #define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5) -#define PBUF_POOL_SIZE 0 #define MEM_ALIGNMENT 4 #define MEM_SIZE 30720 -#define PBUF_POOL_BUFSIZE (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + 1280) +#define PBUF_POOL_BUFSIZE (1280 + 462 + 26) #define MEMP_MEM_MALLOC 1 // #define LWIP_HOOK_FILENAME "lwiphooks.h" @@ -177,4 +176,22 @@ extern const int fhost_tcpip_priority; #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \ u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM"))) +#if defined(CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM) && CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM +#define PBUF_POOL_SIZE 0 + +#include +#include +#define LWIP_PBUF_CUSTOM_DATA mem_size_t pool; + +#if defined(__cplusplus) +extern "C" const mem_size_t * memp_sizes; +extern "C" struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset); +#else +extern const mem_size_t * memp_sizes; +extern struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset); +#endif +#else +#define PBUF_POOL_SIZE 20 +#endif + #endif /* LWIP_HDR_LWIPOPTS_H__ */ diff --git a/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld b/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld index a9ed71746418e8..593af0d2defb7d 100644 --- a/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld +++ b/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld @@ -208,6 +208,9 @@ SECTIONS _bt_l2cap_fixed_chan_list_start = .; KEEP(*(SORT_BY_NAME("._bt_l2cap_fixed_chan.static.*"))) _bt_l2cap_fixed_chan_list_end = .; + + . = ALIGN(8); + KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*)) } >tcm_ocram AT >flash .boot2 (NOLOAD) : diff --git a/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash.ld b/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash.ld index 597d98a4b11658..076f3d6659d084 100644 --- a/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash.ld +++ b/examples/platform/bouffalolab/bl702l/ldscripts/psram_flash.ld @@ -170,6 +170,9 @@ SECTIONS _bt_l2cap_fixed_chan_list_start = .; KEEP(*(SORT_BY_NAME("._bt_l2cap_fixed_chan.static.*"))) _bt_l2cap_fixed_chan_list_end = .; + + . = ALIGN(8); + KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*)) } >tcm_ocram AT >flash .boot2 (NOLOAD) : diff --git a/examples/platform/bouffalolab/common/bouffalo_sdk/platform_port.cpp b/examples/platform/bouffalolab/common/bouffalo_sdk/platform_port.cpp index f92b527b410d3a..e1be14c2a2806f 100644 --- a/examples/platform/bouffalolab/common/bouffalo_sdk/platform_port.cpp +++ b/examples/platform/bouffalolab/common/bouffalo_sdk/platform_port.cpp @@ -56,6 +56,8 @@ extern "C" void vAssertCalled(void) printf("vAssertCalled, ra = %p in task %s\r\n", (void *) ra, pcTaskGetName(NULL)); } + abort(); + while (true) ; } diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index 57dcb795e730ff..09a495c6a7e97c 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -263,7 +263,8 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) } else { - ChipLogError(NotSpecified, "sFactoryDataProvider.Init() failed"); + ChipLogError(NotSpecified, "factory data provider is failed to initialize, use example DAC provider."); + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); } #else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); diff --git a/scripts/build/builders/bouffalolab.py b/scripts/build/builders/bouffalolab.py index d575259aafab7a..5cee2d873bb8b7 100644 --- a/scripts/build/builders/bouffalolab.py +++ b/scripts/build/builders/bouffalolab.py @@ -285,16 +285,14 @@ def PreBuildCommand(self): def PostBuildCommand(self): - bouffalo_sdk_chips = ["bl616"] - abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin") - - if self.chip_name not in bouffalo_sdk_chips: - abs_path_fw_raw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".raw") + if self.chip_name in ["bl616"]: + abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".raw") + else: + abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin") if os.path.isfile(abs_path_fw): target_dir = self.output_dir.replace(self.chip_dir, "").strip("/") - 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") diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index 87136268afd0d2..3da54f09457664 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -268,7 +268,7 @@ void BLWiFiDriver::OnScanWiFiNetworkDone() } wifi_mgmr_ap_item_t * ScanResult = (wifi_mgmr_ap_item_t *) pvPortMalloc(ap_num * sizeof(wifi_mgmr_ap_item_t)); - wifi_mgmr_get_scan_result(ScanResult, &ap_num, 0, mScanSSID); + wifi_mgmr_get_scan_result(ScanResult, &ap_num, mScanType, mScanSSID); if (ScanResult) { diff --git a/src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp b/src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp index 24df9f365ad4ba..4b2b8b736a4016 100644 --- a/src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp @@ -106,8 +106,15 @@ extern "C" void wifiInterface_eventGotIP(struct netif * interface) extern "C" void wifiInterface_eventScanDone(struct netif * interface, netbus_fs_scan_ind_cmd_msg_t * pmsg) { + ChipDeviceEvent event; + ChipLogProgress(DeviceLayer, "wifiInterface_eventScanDone"); + + memset(&event, 0, sizeof(ChipDeviceEvent)); NetworkCommissioning::BLWiFiDriver::GetInstance().OnScanWiFiNetworkDone(pmsg); + + event.Type = kWiFiOnScanDone; + PlatformMgr().PostEventOrDie(&event); } #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp index 22df7c3b4f90c2..43f813a7587450 100644 --- a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp @@ -211,15 +211,15 @@ void BLWiFiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callba { if (callback != nullptr) { - ChipLogError(NetworkProvisioning, "ssid.data(): %s", ssid.data()); - if (ssid.data()) { memset(mScanSSID, 0, sizeof(mScanSSID)); memcpy(mScanSSID, ssid.data(), ssid.size()); mScanSpecific = true; } - mpScanCallback = callback; + + mScanResponseNum = 0; + mpScanCallback = callback; wifiInterface_startScan(); } } @@ -229,81 +229,100 @@ void BLWiFiDriver::OnScanWiFiNetworkDone(void * opaque) netbus_wifi_mgmr_msg_cmd_t * pkg_data = (netbus_wifi_mgmr_msg_cmd_t *) ((struct pkg_protocol *) opaque)->payload; netbus_fs_scan_ind_cmd_msg_t * pmsg = (netbus_fs_scan_ind_cmd_msg_t *) ((netbus_fs_scan_ind_cmd_msg_t *) pkg_data); - size_t i = 0, ap_num = 0; + size_t i = 0, ap_num = 0, ap_cnt = 0; WiFiScanResponse *pScanResponse, *p; - for (i = 0; i < pmsg->num; i++) - { - ChipLogProgress(DeviceLayer, "OnScanWiFiNetworkDone %s", pmsg->records[i].ssid); - if (mScanSpecific && !strcmp(mScanSSID, (char *) (pmsg->records[i].ssid))) - { - ap_num = 1; - break; - } - } + ChipLogProgress(DeviceLayer, "expected ssid %s. get %d in total, %d", mScanSSID, pmsg->num, mScanSpecific); - if (0 == pmsg->num || (mScanSpecific && 0 == ap_num)) + if (mScanSpecific) { - ChipLogProgress(DeviceLayer, "No AP found"); - if (mpScanCallback != nullptr) + for (i = 0; i < pmsg->num; i++) { - mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), nullptr); - mpScanCallback = nullptr; + if (mScanSpecific && !strcmp(mScanSSID, (char *) (pmsg->records[i].ssid))) + { + ap_num = 1; + break; + } } - return; - } - - if (ap_num) - { - p = pScanResponse = (WiFiScanResponse *) malloc(sizeof(WiFiScanResponse) * ap_num); } else { - p = pScanResponse = (WiFiScanResponse *) malloc(sizeof(WiFiScanResponse) * pmsg->num); - ap_num = pmsg->num; + ap_num = pmsg->num; } - for (i = 0; i < pmsg->num; i++) + + if (ap_num) { - if (mScanSpecific && strcmp(mScanSSID, (char *) (pmsg->records[i].ssid))) + p = mScanResponse = (WiFiScanResponse *) malloc(sizeof(WiFiScanResponse) * ap_num); + if (mScanResponse == nullptr) { - continue; + return; } - p->security.SetRaw(pmsg->records[i].auth_mode); - p->ssidLen = strlen((char *) pmsg->records[i].ssid) < chip::DeviceLayer::Internal::kMaxWiFiSSIDLength - ? strlen((char *) pmsg->records[i].ssid) - : chip::DeviceLayer::Internal::kMaxWiFiSSIDLength; - p->channel = pmsg->records[i].channel; - p->wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4; - p->rssi = pmsg->records[i].rssi; - memcpy(p->ssid, pmsg->records[i].ssid, p->ssidLen); - memcpy(p->bssid, pmsg->records[i].bssid, 6); - - if (mScanSpecific) + for (i = 0; i < pmsg->num; i++) { - break; - } - - p++; - } - - if (CHIP_NO_ERROR == DeviceLayer::SystemLayer().ScheduleLambda([ap_num, pScanResponse]() { - BLScanResponseIterator iter(ap_num, pScanResponse); - if (GetInstance().mpScanCallback) + if (mScanSpecific && strcmp(mScanSSID, (char *) (pmsg->records[i].ssid))) { - GetInstance().mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), &iter); - GetInstance().mpScanCallback = nullptr; + continue; } - else + + p->security.SetRaw(pmsg->records[i].auth_mode); + strncpy((char *) p->ssid, (const char *) pmsg->records[i].ssid, kMaxWiFiSSIDLength); + p->ssidLen = strlen((char *) pmsg->records[i].ssid); + p->channel = pmsg->records[i].channel; + p->wiFiBand = chip::DeviceLayer::NetworkCommissioning::WiFiBand::k2g4; + p->rssi = pmsg->records[i].rssi; + memcpy(p->bssid, pmsg->records[i].bssid, 6); + + p++; + ap_cnt++; + + if (ap_cnt >= ap_num) { - ChipLogError(DeviceLayer, "can't find the ScanCallback function"); + break; } - })) + } + } + + mScanResponseNum = ap_cnt; +} + +void BLWiFiDriver::OnScanWiFiNetworkDone(void) +{ + size_t ap_cnt = mScanResponseNum; + WiFiScanResponse * pScanResponse = mScanResponse; + + if (mScanResponse) + { + if (CHIP_NO_ERROR == DeviceLayer::SystemLayer().ScheduleLambda([ap_cnt, pScanResponse]() { + BLScanResponseIterator iter(ap_cnt, pScanResponse); + if (GetInstance().mpScanCallback) + { + GetInstance().mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), &iter); + GetInstance().mpScanCallback = nullptr; + } + else + { + ChipLogError(DeviceLayer, "can't find the ScanCallback function"); + } + })) + { + ChipLogProgress(DeviceLayer, "ScheduleLambda OK"); + } + + free(mScanResponse); + mScanResponse = nullptr; + } + else { - ChipLogProgress(DeviceLayer, "ScheduleLambda OK"); + ChipLogProgress(DeviceLayer, "No AP found"); + if (mpScanCallback != nullptr) + { + mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), nullptr); + mpScanCallback = nullptr; + } } - free(pScanResponse); + mScanResponseNum = 0; } CHIP_ERROR GetConfiguredNetwork(Network & network) diff --git a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h index 8e5557b8787438..b98ea60ab6127d 100644 --- a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h +++ b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h @@ -113,7 +113,8 @@ class BLWiFiDriver final : public WiFiDriver CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen); void OnConnectWiFiNetwork(bool isConnected); - void OnScanWiFiNetworkDone(void * opaque = NULL); + void OnScanWiFiNetworkDone(void); + void OnScanWiFiNetworkDone(void * opaque); void OnNetworkStatusChange(void); CHIP_ERROR SetLastDisconnectReason(const ChipDeviceEvent * event); @@ -128,6 +129,9 @@ class BLWiFiDriver final : public WiFiDriver private: bool NetworkMatch(const WiFiNetwork & network, ByteSpan networkId); + WiFiScanResponse * mScanResponse = nullptr; + size_t mScanResponseNum = 0; + WiFiNetwork mSavedNetwork; WiFiNetwork mStagingNetwork; ScanCallback * mpScanCallback; diff --git a/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h b/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h index bc34d9124b6d92..7f1bbf360fdd7f 100644 --- a/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h +++ b/src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h @@ -58,4 +58,6 @@ #define CHIP_CONFIG_FREERTOS_USE_STATIC_QUEUE 1 #elif CHIP_DEVICE_LAYER_TARGET_BL702 #define CHIP_CONFIG_FREERTOS_USE_STATIC_TASK 1 +#elif CHIP_DEVICE_LAYER_TARGET_BL702L +#define CHIP_CONFIG_FREERTOS_USE_STATIC_TASK 1 #endif diff --git a/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp index a5d70240ba5a04..12a58f995d7d26 100644 --- a/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp @@ -78,7 +78,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeap CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) { #if CHIP_DEVICE_LAYER_TARGET_BL616 - return CHIP_ERROR_NOT_IMPLEMENTED; + struct meminfo info; + bflb_mem_usage(KMEM_HEAP, &info); + currentHeapHighWatermark = info.total_size - info.max_free_size; + #else #ifdef CFG_USE_PSRAM currentHeapHighWatermark = @@ -86,8 +89,9 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & cu #else currentHeapHighWatermark = get_heap_size() - xPortGetMinimumEverFreeHeapSize(); #endif - return CHIP_NO_ERROR; #endif + + return CHIP_NO_ERROR; } CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut) diff --git a/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.h b/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.h index 8001afb0544cb3..6ff0d07ad30d1e 100644 --- a/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.h +++ b/src/platform/bouffalolab/common/DiagnosticDataProviderImpl.h @@ -32,6 +32,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider static DiagnosticDataProviderImpl & GetDefaultInstance(); // ===== Methods that implement the PlatformManager abstract interface. + bool SupportsWatermarks() override { return true; } CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override; CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override; diff --git a/third_party/bouffalolab/bl602/bl_iot_sdk.gni b/third_party/bouffalolab/bl602/bl_iot_sdk.gni index ba564db1469bec..0cf4768465f131 100644 --- a/third_party/bouffalolab/bl602/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl602/bl_iot_sdk.gni @@ -20,6 +20,7 @@ import("${chip_root}/src/lib/lib.gni") declare_args() { bl_iot_sdk_root = "${chip_root}/third_party/bouffalolab/repo" + enable_lwip_pbuf_ram = false enable_debug_coredump = false coredump_binary_id = 0 } @@ -63,6 +64,10 @@ template("bl_iot_sdk") { "-include", rebase_path("${invoker.freertos_config}", root_build_dir), ] + + if (defined(invoker.enable_lwip_pbuf_ram) && invoker.enable_lwip_pbuf_ram) { + defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ] + } } source_set("${sdk_target_name}_soc") { @@ -906,6 +911,10 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/lwip_dhcpd", ] + if (defined(invoker.enable_lwip_pbuf_ram) && invoker.enable_lwip_pbuf_ram) { + include_dirs += [ "${bouffalolab_iot_sdk_build_root}/patches/lwip" ] + } + defines = [ "LWIP_IPV6=1" ] } @@ -927,7 +936,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/lwip/src/core/inet_chksum.c", "${bl_iot_sdk_root}/components/network/lwip/src/core/init.c", "${bl_iot_sdk_root}/components/network/lwip/src/core/ip.c", - "${bl_iot_sdk_root}/components/network/lwip/src/core/mem.c", "${bl_iot_sdk_root}/components/network/lwip/src/core/memp.c", "${bl_iot_sdk_root}/components/network/lwip/src/core/netif.c", "${bl_iot_sdk_root}/components/network/lwip/src/core/pbuf.c", @@ -941,6 +949,12 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/lwip/src/core/udp.c", ] + if (defined(invoker.enable_lwip_pbuf_ram) && invoker.enable_lwip_pbuf_ram) { + sources += [ "${bouffalolab_iot_sdk_build_root}/patches/lwip/mem.c" ] + } else { + sources += [ "${bl_iot_sdk_root}/components/network/lwip/src/core/mem.c" ] + } + sources += [ "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/autoip.c", "${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/dhcp.c", diff --git a/third_party/bouffalolab/bl616/bouffalo_sdk.gni b/third_party/bouffalolab/bl616/bouffalo_sdk.gni index 174b04b8160ae2..9b498966eded53 100644 --- a/third_party/bouffalolab/bl616/bouffalo_sdk.gni +++ b/third_party/bouffalolab/bl616/bouffalo_sdk.gni @@ -21,6 +21,7 @@ declare_args() { # Location of the bl616 SDK. bouffalo_sdk_root = "${chip_root}/third_party/bouffalolab/bouffalo_sdk" + enable_lwip_pbuf_ram = false enable_debug_coredump = false coredump_binary_id = 0 bouffalo_sdk_coredump_version = 1 @@ -72,6 +73,10 @@ template("bouffalo_sdk") { if (defined(invoker.defines)) { defines += invoker.defines } + + if (defined(invoker.enable_lwip_pbuf_ram) && invoker.enable_lwip_pbuf_ram) { + defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ] + } } config("${sdk_target_name}_config_startup") { @@ -412,6 +417,7 @@ template("bouffalo_sdk") { include_dirs = [ "${bouffalo_sdk_root}/components/libc" ] sources = [ + "${bouffalo_sdk_root}/components/libc/assert.c", "${bouffalo_sdk_root}/components/libc/newlib/port_init_fini.c", "${bouffalo_sdk_root}/components/libc/newlib/port_memory.c", "${bouffalo_sdk_root}/components/libc/newlib/syscalls_nosys.c", @@ -895,6 +901,10 @@ template("bouffalo_sdk") { include_dirs += [ "${bouffalo_sdk_root}/components/net/lwip/lwip/src/apps/dhcpd" ] + if (defined(invoker.enable_lwip_pbuf_ram) && invoker.enable_lwip_pbuf_ram) { + include_dirs += [ "${bouffalolab_iot_sdk_build_root}/patches/lwip" ] + } + defines = [ "CONFIG_LWIP", "CONFIG_MAC_TXQ_DEPTH=8", @@ -937,7 +947,6 @@ template("bouffalo_sdk") { "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/ipv6/ip6_frag.c", "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/ipv6/mld6.c", "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/ipv6/nd6.c", - "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/mem.c", "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/memp.c", "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/netif.c", "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/pbuf.c", @@ -952,6 +961,13 @@ template("bouffalo_sdk") { "${bouffalo_sdk_root}/components/net/lwip/lwip/src/netif/ethernet.c", ] + if (defined(invoker.enable_lwip_pbuf_ram) && invoker.enable_lwip_pbuf_ram) { + sources += [ "${bouffalolab_iot_sdk_build_root}/patches/lwip/mem.c" ] + } else { + sources += + [ "${bouffalo_sdk_root}/components/net/lwip/lwip/src/core/mem.c" ] + } + sources += [ "${bouffalo_sdk_root}/components/net/lwip/lwip/src/apps/dhcpd/dhcp_server_raw.c", "${bouffalo_sdk_root}/components/net/lwip/lwip/src/apps/lwiperf/lwiperf.c", diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index 76d35da758e883..45122f43c34021 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -21,6 +21,7 @@ import("${chip_root}/src/lib/lib.gni") declare_args() { bl_iot_sdk_root = "${chip_root}/third_party/bouffalolab/repo" + enable_lwip_pbuf_ram = false enable_debug_coredump = false coredump_binary_id = 0 } diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index ac608a72098cd6..514d25d2172427 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -21,6 +21,7 @@ import("${chip_root}/src/lib/lib.gni") declare_args() { bl_iot_sdk_root = "${chip_root}/third_party/bouffalolab/repo" + enable_lwip_pbuf_ram = false enable_pds = false enable_debug_coredump = false coredump_binary_id = 0 diff --git a/third_party/bouffalolab/repo b/third_party/bouffalolab/repo index 75df6e87ffa10b..11448aeb1a5d9c 160000 --- a/third_party/bouffalolab/repo +++ b/third_party/bouffalolab/repo @@ -1 +1 @@ -Subproject commit 75df6e87ffa10b905c9dbb0efc5fd35f96955c55 +Subproject commit 11448aeb1a5d9c000859db47863a3bfcbc4d6032 From 83a13776d8f4caf5814491880738d1cb9f21fdd7 Mon Sep 17 00:00:00 2001 From: wyhong <30567533+wy-hh@users.noreply.github.com> Date: Sat, 15 Feb 2025 05:53:48 +0800 Subject: [PATCH 5/5] [bouffalo lab] Advertise commissionable on last fabric removal is disabled by default (#37531) * [bouffalo lab] Make it possible for application to implement its own fabric delegate * Advertise commissionable on last fabric removal is disabled by default --- .../bouffalolab/data_model/lighting-app-ethernet.matter | 1 + .../bouffalolab/data_model/lighting-app-ethernet.zap | 2 +- examples/platform/bouffalolab/common/plat/plat.h | 4 ++++ examples/platform/bouffalolab/common/plat/platform.cpp | 4 ++++ scripts/tools/bouffalolab/generate_factory_data.py | 2 +- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter index 94f286d9f605a3..34dc919f7fa908 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.matter @@ -2133,6 +2133,7 @@ endpoint 0 { callback attribute partsList; callback attribute generatedCommandList; callback attribute acceptedCommandList; + callback attribute eventList; callback attribute attributeList; callback attribute featureMap; callback attribute clusterRevision; diff --git a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap index b1f2eace627e8e..8c82d00ee751f6 100644 --- a/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap +++ b/examples/lighting-app/bouffalolab/data_model/lighting-app-ethernet.zap @@ -4317,4 +4317,4 @@ "parentEndpointIdentifier": null } ] -} +} \ No newline at end of file diff --git a/examples/platform/bouffalolab/common/plat/plat.h b/examples/platform/bouffalolab/common/plat/plat.h index f0360ff19a70c5..6a9535a088cf3f 100644 --- a/examples/platform/bouffalolab/common/plat/plat.h +++ b/examples/platform/bouffalolab/common/plat/plat.h @@ -23,6 +23,10 @@ #define EXT_DISCOVERY_TIMEOUT_SECS 20 +#ifndef CONFIG_APP_ADVERTISE_COMMISSIONABLE_ON_LAST_FABRIC_REMOVAL +#define CONFIG_APP_ADVERTISE_COMMISSIONABLE_ON_LAST_FABRIC_REMOVAL 0 +#endif + typedef void (*app_pds_gpio_irq_handler_t)(void * arg); #ifdef __cplusplus diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index 09a495c6a7e97c..7e62e45515aff3 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -177,6 +177,7 @@ void UnlockOpenThreadTask(void) } #endif +#if CONFIG_APP_ADVERTISE_COMMISSIONABLE_ON_LAST_FABRIC_REMOVAL class AppFabricTableDelegate : public FabricTable::Delegate { void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) @@ -205,6 +206,7 @@ class AppFabricTableDelegate : public FabricTable::Delegate } } }; +#endif CHIP_ERROR PlatformManagerImpl::PlatformInit(void) { @@ -293,8 +295,10 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); +#if CONFIG_APP_ADVERTISE_COMMISSIONABLE_ON_LAST_FABRIC_REMOVAL static AppFabricTableDelegate sAppFabricDelegate; chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppFabricDelegate); +#endif chip::DeviceLayer::PlatformMgr().UnlockChipStack(); diff --git a/scripts/tools/bouffalolab/generate_factory_data.py b/scripts/tools/bouffalolab/generate_factory_data.py index d548f9c5fd06d5..be9baf2086de6d 100755 --- a/scripts/tools/bouffalolab/generate_factory_data.py +++ b/scripts/tools/bouffalolab/generate_factory_data.py @@ -259,7 +259,7 @@ def gen_cd(chip_cert, paa_cert, dac_vendor_id, dac_product_id, vendor_id, produc if paa_cert: cmd += ["--authorized-paa-cert", paa_cert] - log.info("Generate CD: {}".format(shlex.join(cmd))) + log.info("Generate CD: {}".format(" ".join(cmd))) subprocess.run(cmd) pai_vendor_id, pai_product_id, pai_issue_date, pai_expire_date = parse_cert_file(pai_cert)