Skip to content

Commit 28855ab

Browse files
wy-hhrestyled-commits
authored andcommitted
[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>
1 parent 7b57126 commit 28855ab

File tree

5 files changed

+264
-71
lines changed

5 files changed

+264
-71
lines changed

docs/platforms/bouffalolab/getting_started.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,34 @@ git clone --recurse-submodules https://github.com/project-chip/connectedhomeip.g
1717
git clone --depth=1 https://github.com/project-chip/connectedhomeip.git
1818
```
1919
20-
- check out `Bouffalo Lab` platform support repos as follows:
20+
- Check out necessary submodules
21+
22+
Checkout `BL_IOT_SDK` for `BL602`, `BL702` and `BL702L` platform:
23+
24+
```
25+
./scripts/checkout_submodules.py --shallow --recursive --platform bouffalolab
26+
```
27+
28+
Checkout `bouffalo_sdk` for `BL616` platform:
2129
2230
```
23-
scripts/checkout_submodules.py --shallow --recursive --platform bouffalolab
31+
./scripts/checkout_submodules.py --shallow --recursive --platform bouffalo_sdk
2432
```
2533
34+
> Please contact `Bouffalo Lab` for `BL616` SDK access.
35+
2636
If you want to checkout Matter Linux example and development tools, please
2737
try as follows:
2838
2939
```
30-
scripts/checkout_submodules.py --shallow --recursive --platform linux bouffalolab
40+
./scripts/checkout_submodules.py --shallow --recursive --platform linux bouffalolab
3141
```
3242
3343
Or if you want to checkout Matter Darwin example and development tools,
3444
please try as follows:
3545
3646
```
37-
scripts/checkout_submodules.py --shallow --recursive --platform darwin bouffalolab
47+
./scripts/checkout_submodules.py --shallow --recursive --platform darwin bouffalolab
3848
```
3949
4050
# Setup build environment

docs/platforms/bouffalolab/matter_factory_data.md

+116-24
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Script tool
7171
call `chip-cert` to generate test certificates and verify certificates.
7272

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

7676
```shell
7777
./scripts/build/build_examples.py --target linux-x64-chip-cert build
@@ -111,24 +111,47 @@ repo.
111111

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

114-
## Generate with default test certificates
114+
## Generate with default configuration
115115

116-
- Run following command to generate all plain text factory data
116+
- Default setting uses the following parameters
117+
118+
- PAI certification:
119+
[test PAI certification](../../../credentials/test/attestation/Chip-Test-PAI-FFF1-8000-Key.pem)
120+
121+
- Vendor ID for DAC: 0xFFF1; Vendor ID for CD: 0x130d
122+
123+
- Product ID for DAC: 0x8000, Product ID for CD: 0x1001
124+
125+
* Run following command to generate all plain text factory data
117126

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

120129
```shell
121130
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert
122131
```
123132

124-
- Run following command to generate factory data which encrypt private of
133+
- Check DAC certificate. Here takes `out_130d_1001_106_dac_cert.pem` as
134+
generated test certificate.
135+
136+
```shell
137+
openssl x509 -noout -text -in out/test-cert/out_130d_1001_106_dac_cert.pem
138+
```
139+
140+
- Check Certification Declare. Here takes `out_130d_1001_cd.der` as
141+
generated test certificate.
142+
143+
```shell
144+
./out/linux-x64-chip-cert/chip-cert print-cd out/test-cert/out_130d_1001_cd.der
145+
```
146+
147+
* Run following command to generate factory data which encrypt private of
125148
device attestation data
126149

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

131-
> An example of hex string of 16 bytes: 12345678123456781234567812345678
154+
> An example of hex string of 16 bytes: 12345678123456781234567812345678.
132155

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

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

156-
- Export environment variables in terminal for easy operations
179+
- Export environment variables in terminal for certificates generation
157180

158181
```
159-
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
160-
export TEST_CERT_CN=BFLB # Common Name
182+
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
183+
export TEST_CERT_PRODUCT_ID=1001 # Product ID hex string
184+
export TEST_CERT_CN=BFLB # Common Name
161185
```
162186

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

165189
```shell
166-
mkdir out/test-cert
167190
./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}
168191
```
169192

193+
- Check PAA certificate
194+
195+
```shell
196+
openssl x509 -noout -text -in out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem
197+
```
198+
170199
- Convert PAA PEM format file to PAA DER format file
171200

172201
```shell
@@ -182,14 +211,84 @@ user should know it has limit to work with real ecosystem.
182211
./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
183212
```
184213

185-
- Generate `MFD` in plain text data
214+
- Check PAI certificate
186215

187-
```shell
188-
./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
189-
```
216+
```shell
217+
openssl x509 -noout -text -in out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem
218+
```
190219

191-
> Appending `--key <hex string of 16 bytes>` option to enable encrypt
192-
> private key of attestation device data.
220+
- Generate `MFD` in plain text data with same VID/PID in DAC and CD
221+
222+
- Use same environment variables `TEST_CERT_VENDOR_ID` and
223+
`TEST_CERT_PRODUCT_ID` for CD.
224+
225+
```shell
226+
./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}
227+
```
228+
229+
> Appending `--key <hex string of 16 bytes>` option to enable encrypt
230+
> private key of attestation device data.
231+
232+
- Check DAC certificate. Here takes `out_130d_1001_1349_dac_cert.pem` as
233+
generated test certification.
234+
235+
```shell
236+
openssl x509 -noout -text -in out/test-cert/out_130d_1001_1349_dac_cert.pem
237+
```
238+
239+
- Check PAA/PAI/DAC certificate chain.
240+
241+
```shell
242+
./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
243+
```
244+
245+
- Check Certification Declare. Here takes `out_130d_1001_cd.der` as
246+
generated test certification.
247+
248+
```shell
249+
./out/linux-x64-chip-cert/chip-cert print-cd out/test-cert/out_130d_1001_cd.der
250+
```
251+
252+
- Generate `MFD` in plain text data with different VID/PID in DAC and CD
253+
254+
- Export vendor ID and product ID for CD
255+
256+
```shell
257+
export TEST_CD_VENDOR_ID=730D # Vendor ID hex string
258+
export TEST_CD_PRODUCT_ID=7001 # Product ID hex string
259+
```
260+
261+
- Run script to generate DAC/CD and `MFD`.
262+
263+
```shell
264+
./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}
265+
```
266+
267+
> Appending `--key <hex string of 16 bytes>` option to enable encrypt
268+
> private key of attestation device data.
269+
>
270+
> Please use --`vendor_name` and `--product_name` to change vendor name
271+
> and product name.
272+
273+
- Check DAC certificate. Here takes `out_130d_1001_1349_dac_cert.pem` as
274+
generated test certification.
275+
276+
```shell
277+
openssl x509 -noout -text -in out/test-cert/out_130d_1001_1349_dac_cert.pem
278+
```
279+
280+
- Check PAA/PAI/DAC certificate chain.
281+
282+
```shell
283+
./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
284+
```
285+
286+
- Check Certification Declare. Here takes `out_730D_7001_cd.der` as
287+
generated test certification.
288+
289+
```shell
290+
./out/linux-x64-chip-cert/chip-cert print-cd out/test-cert/out_130d_1001_cd.der
291+
```
193292

194293
## Generate with self-defined DAC certificate and key
195294

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

201300
```
202301
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
203-
export TEST_CERT_PRODUCT_ID=1001 # Vendor ID hex string
302+
export TEST_CERT_PRODUCT_ID=1001 # Product ID hex string
204303
export TEST_CERT_CN=BFLB # Common Name
205304
```
206305

207306
- Generate DAC certificate and key
208307

209308
```shell
210-
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
309+
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
211310
```
212311

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

241-
- Limits on BL IOT SDK
242-
243-
If developer would like to program `MFD` with all plain text data, option
244-
`--key <hex string of 16 bytes>` needs pass to script, otherwise, flash tool
245-
will raise an error. And SoC BL602, BL702 and BL702L use BL IOT SDK for
246-
Matter Application.
247-
248340
Please free contact to `Bouffalo Lab` for DAC provider service and higher
249341
security solution, such as SoC inside certificate requesting.

scripts/flashing/bouffalolab_firmware_utils.py

+95-25
Original file line numberDiff line numberDiff line change
@@ -446,41 +446,111 @@ def exe_gen_ota_image_cmd(flashtool_exe):
446446
new_name = os.path.join(self.work_dir, "ota_images", fw_name + ota_img_name[len("FW_OTA"):])
447447
os.system("mv {} {}".format(img, new_name))
448448

449-
def exe_prog_cmd(flashtool_exe, mfd_addr):
449+
def construct_prog_confg():
450+
451+
iot_cfg = {
452+
"param": {
453+
"interface_type": "uart",
454+
"comport_uart": self.args["port"],
455+
"speed_uart": self.args["baudrate"],
456+
"speed_jlink": "1000",
457+
"chip_xtal": self.args["xtal"],
458+
"ota": "",
459+
"version": "",
460+
"aes_key": "",
461+
"aes_iv": "",
462+
"addr": "0x0",
463+
"publickey": "",
464+
"privatekey": ""
465+
},
466+
"check_box": {
467+
"fw_download": True,
468+
"mfg_download": False,
469+
"media_download": False,
470+
"romfs_download": False,
471+
"psm_download": False,
472+
"key_download": False,
473+
"data_download": False,
474+
"factory_download": True if self.args["dts"] else False,
475+
"mfd_download": True if self.args["mfd"] else False,
476+
"boot2_download": True if self.args["boot2"] else False,
477+
"ckb_erase_all": "True" if self.args["erase"] else "False",
478+
"partition_download": True if self.args["pt"] else False,
479+
"encrypt": False,
480+
"sign": False,
481+
"single_download": False,
482+
"auto_efuse_verify": False
483+
},
484+
"input_path": {
485+
"fw_bin_input": self.args['firmware'],
486+
"mfg_bin_input": "",
487+
"media_bin_input": "",
488+
"romfs_dir_input": "",
489+
"psm_bin_input": "",
490+
"key_bin_input": "",
491+
"data_bin_input": "",
492+
"factory_bin_input": self.args["dts"],
493+
"mfd_bin_input": self.args["mfd"],
494+
"boot2_bin_input": self.args["boot2"],
495+
"img_bin_input": "",
496+
"pt_table_bin_input": self.args["pt"],
497+
"publickey": "",
498+
"privatekey": ""
499+
}
500+
}
501+
502+
conf_toml = os.path.splitext(self.args['firmware'])[0] + "_config.toml"
503+
504+
with open(conf_toml, "w", encoding="utf-8") as f:
505+
toml.dump(iot_cfg, f)
506+
507+
return conf_toml
508+
509+
def exe_prog_cmd(flashtool_exe, mfd_addr, flashtool_path):
450510

451511
if not self.args["port"]:
452512
return
453513

454514
if self.args["mfd"] and not mfd_addr:
455515
raise Exception("No MFD partition found in partition table.")
456516

457-
prog_cmd = [
458-
flashtool_exe,
459-
"--port", self.args["port"],
460-
"--baudrate", self.args["baudrate"],
461-
"--chipname", self.args["chipname"],
462-
"--firmware", self.args["firmware"],
463-
"--dts", self.args["dts"],
464-
"--pt", self.args["pt"],
465-
]
517+
if self.args["mfd"] and not self.args["key"]:
518+
conf_toml = construct_prog_confg()
466519

467-
if self.args["boot2"]:
468-
prog_cmd += ["--boot2", self.args["boot2"]]
520+
prog_cmd = [
521+
flashtool_exe,
522+
"--chipname", self.args["chipname"],
523+
"--config", conf_toml,
524+
]
469525

470-
if self.args["sk"]:
471-
prog_cmd += ["--sk", self.args["sk"]]
526+
else:
527+
prog_cmd = [
528+
flashtool_exe,
529+
"--port", self.args["port"],
530+
"--baudrate", self.args["baudrate"],
531+
"--chipname", self.args["chipname"],
532+
"--firmware", self.args["firmware"],
533+
"--dts", self.args["dts"],
534+
"--pt", self.args["pt"],
535+
]
472536

473-
if mfd_addr and self.args["mfd_str"]:
474-
if self.args["key"] and not self.args["iv"]:
475-
logging.warning("mfd file has no iv, do NOT program mfd key.")
476-
else:
477-
prog_cmd += ["--dac_key", self.args["key"]]
478-
prog_cmd += ["--dac_iv", self.args["iv"]]
479-
prog_cmd += ["--dac_addr", hex(mfd_addr)]
480-
prog_cmd += ["--dac_value", self.args["mfd_str"]]
537+
if self.args["boot2"]:
538+
prog_cmd += ["--boot2", self.args["boot2"]]
539+
540+
if self.args["sk"]:
541+
prog_cmd += ["--sk", self.args["sk"]]
542+
543+
if mfd_addr and self.args["mfd_str"]:
544+
if self.args["key"] and not self.args["iv"]:
545+
logging.warning("mfd file has no iv, do NOT program mfd key.")
546+
else:
547+
prog_cmd += ["--dac_key", self.args["key"]]
548+
prog_cmd += ["--dac_iv", self.args["iv"]]
549+
prog_cmd += ["--dac_addr", hex(mfd_addr)]
550+
prog_cmd += ["--dac_value", self.args["mfd_str"]]
481551

482-
if self.option.erase:
483-
prog_cmd += ["--erase"]
552+
if self.option.erase:
553+
prog_cmd += ["--erase"]
484554

485555
logging.info("firmware programming: {}".format(" ".join(prog_cmd)))
486556
process = subprocess.Popen(prog_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -500,7 +570,7 @@ def exe_prog_cmd(flashtool_exe, mfd_addr):
500570
os.chdir(self.work_dir)
501571

502572
exe_gen_ota_image_cmd(flashtool_exe)
503-
exe_prog_cmd(flashtool_exe, mfd_addr)
573+
exe_prog_cmd(flashtool_exe, mfd_addr, flashtool_path)
504574

505575
def bouffalo_sdk_prog(self):
506576

0 commit comments

Comments
 (0)