Skip to content

Commit cd7ab98

Browse files
committed
[Bouffalo Lab] Add a script to demonstrate mfd partition generation
1 parent a296b66 commit cd7ab98

File tree

3 files changed

+799
-13
lines changed

3 files changed

+799
-13
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# Introduction to Matter factory data
2+
3+
Each Matter device should have it own unique factory data manufactured.
4+
5+
This guide demonstrates what `Bouffalo Lab` provides to support factory data:
6+
7+
- credential factory data protected by hardware security engine
8+
- reference tool to generate factory data
9+
- tool/method to program factory data
10+
11+
# Matter factory data
12+
13+
## How to enable
14+
15+
One dedicate flash region allocates for factory data as below which is read-only for firmware.
16+
17+
```toml
18+
name = "MFD"
19+
address0 = 0x3FE000
20+
size0 = 0x1000
21+
```
22+
23+
To enable matter factory data feature, please append `-mfd` option at end of target name. Take BL616 Wi-Fi Matter Light as example.
24+
25+
```
26+
./scripts/build/build_examples.py --target bouffalolab-bl616dk-light-wifi-mfd build
27+
```
28+
29+
## Factory data
30+
31+
This flash region is divided to two parts:
32+
33+
- One is plain text data, such as Vendor ID, Product ID, Serial number and so on.
34+
35+
> For development/test purpose, all data can put in plain text data.
36+
37+
- Other is cipher text data, such as private key for device attestation data.
38+
39+
`Bouffalo Lab` provides hardware security engine to decrypt this part data with **only hardware access** efuse key.
40+
41+
Current supported data
42+
43+
- DAC certificate and private key
44+
- PAI certificate
45+
- Certificate declaration
46+
47+
- Discriminator ID
48+
- Pass Code
49+
- Spake2p iteration count, salt and verifier
50+
- Vendor ID and name
51+
- Product ID and name
52+
- Product part number and product label
53+
- Manufacturing date
54+
- Hardware version and version string
55+
- Serial Number
56+
- Unique identifier
57+
58+
> Note, it is available to add customer/product own information in factory data, please reference to `bl_mfd.h`/`bl_mfd.c` in SDK and reference generation script [generate_factory_data.py](../../../scripts/tools/bouffalolab/generate_factory_data.py)
59+
60+
# Generate Matter factory data
61+
62+
Script tool [generate_factory_data.py](../../../scripts/tools/bouffalolab/generate_factory_data.py) call `chip-cert` to generate test certificates and verify certificates.
63+
64+
Please run below command to compile `chip-cert` tool under `connnectedhomeip` repo.
65+
66+
```shell
67+
./scripts/build/build_examples.py --target linux-x64-chip-cert build
68+
```
69+
70+
## Command options
71+
72+
- `--cd`, certificate declare
73+
74+
If not specified, `Chip-Test-CD-Signing-Cert.pem` and `Chip-Test-CD-Signing-Key.pem` will sign a test certificate declare for development and test purpose
75+
76+
- `--pai_cert` and `--pai-key`, PAI certificate and PAI private key
77+
78+
If not specified, `Chip-Test-PAI-FFF1-8000-Cert.pem` and `Chip-Test-PAI-FFF1-8000-Key.pem` will be used for development and test purpose.
79+
80+
- `--dac_cert` and `--dac_key`, DAC certificate and DAC private key.
81+
82+
If not specified, script will use PAI certificate and key specified by`--pai_cert` and `--pai-key` to generate DAC certificate and private key for development and test prupose.
83+
84+
- `--discriminator`, discriminator ID
85+
86+
If not specified, script will generate for user.
87+
88+
- `--passcode`, passcode
89+
90+
If not specified, script will generate for user.
91+
92+
- `--spake2p_it` and `--spake2p_salt`
93+
94+
If not specified, script will generate and calculate verifier for user.
95+
96+
Please reference to `--help` for more detail.
97+
98+
## Generate with default test certificates
99+
100+
- Run following command to generate all plain text factory data
101+
102+
```shell
103+
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert
104+
```
105+
106+
- Run following command to generate factory data which encrypt private of device attestation data
107+
108+
```shell
109+
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --key <hex string of 16 bytes>
110+
```
111+
112+
> An example of hex string of 16 bytes: 12345678123456781234567812345678
113+
114+
After command executes successfully, the output folder will has files as below:
115+
116+
- Test certificate declare file which file name ends with `cd.der`
117+
118+
If user wants to reuse CD generated before, please specify CD with option `--cd` as below.
119+
120+
```shell
121+
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --cd <cd file>
122+
```
123+
124+
- Test DAC certificate and DAC certificate key which file names ends with `dac_cert.pem` and `dac_key.pem` separately.
125+
126+
- QR code picture which file name ends with `onboard.png`
127+
- On board information which file name ends with `onboard.txt`
128+
- Matter factory data which file name ends with `mfd.bin`.
129+
130+
## Generate with self-defined PAA/PAI certificates
131+
132+
Self-defined PAA/PAI certificates may use in development and test scenario. But, user should know it has limit to work with real ecosystem.
133+
134+
- Export environment variables in terminal for easy operations
135+
136+
```
137+
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
138+
export TEST_CERT_CN=BFLB # Common Name
139+
```
140+
141+
- Generate PAA certificate and key to `out/cert` folder.
142+
143+
```shell
144+
mkdir out/test-cert
145+
./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}
146+
```
147+
148+
- Convert PAA PEM format file to PAA DER format file
149+
150+
```shell
151+
./out/linux-x64-chip-cert/chip-cert convert-cert -d out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.der
152+
```
153+
154+
> Please save this PAA DER format file which will be used by `chip-tool` during commissioning.
155+
156+
- Generate PAI certificate and key:
157+
158+
```shell
159+
./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
160+
```
161+
162+
- Generate MFD in plain text data
163+
164+
```shell
165+
./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
166+
```
167+
168+
> Appending `--key <hex string of 16 bytes>` option to enable encrypt private key of attestation device data.
169+
170+
## Generate with self-defined DAC certificate and key
171+
172+
Self-defined DAC certificates may use in development and test scenario. But, user should know it has limit to work with real ecosystem.
173+
174+
- Export environment variables in terminal for easy operations
175+
176+
```
177+
export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string
178+
export TEST_CERT_PRODUCT_ID=1001 # Vendor ID hex string
179+
export TEST_CERT_CN=BFLB # Common Name
180+
```
181+
182+
- Generate DAC certificate and key
183+
184+
```shell
185+
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
186+
```
187+
188+
> **Note**, `--valid-from` and `--lifetime` should be in `--valid-from` and `--lifetime` of PAI certificate.
189+
190+
- Generate MFD in plain text data
191+
192+
```shell
193+
./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --pai_cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --dac_cert out/test-cert/Chip-DAC-Cert-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem --dac_key out/test-cert/Chip-DAC-Key-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem
194+
```
195+
196+
> Appending `--key <hex string of 16 bytes>` option to enable encrypt private key of attestation device data.
197+
198+
199+
# Program factory data
200+
201+
After each target built successfully, a flash programming python script will be generated under out folder.
202+
203+
Take BL616 Wi-Fi Matter Light as example, `chip-bl616-lighting-example.flash.py` is using to program firmware, and also for factory data and factory decryption key.
204+
205+
```shell
206+
/out/bouffalolab-bl616dk-light-wifi-mfd/chip-bl616-lighting-example.flash.py --port <serial port> --mfd out/test-cert/<mfd bin file>
207+
```
208+
209+
> If mfd file has cipher text data, please append `--key <hex string of 16 bytes>` option to program to this key to efuse.
210+
211+
- Limits on BL IOT SDK
212+
213+
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.
214+
215+
Please free contact to `Bouffalo Lab` for DAC provider service and higher security solution, such as SoC inside certificate requesting.
216+
217+
218+
219+
220+
221+
222+

examples/lighting-app/bouffalolab/README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ The following steps take examples for `BL602DK`, `BL704LDK` and `BL706DK`.
9999
100100
```
101101
./scripts/build/build_examples.py --target bouffalolab-bl602dk-light build
102+
./scripts/build/build_examples.py --target bouffalolab-bl616dk-light-wifi build
102103
./scripts/build/build_examples.py --target bouffalolab-bl704ldk-light build
103104
./scripts/build/build_examples.py --target bouffalolab-bl706dk-light build
104105
```
@@ -113,23 +114,23 @@ The following steps take examples for `BL602DK`, `BL704LDK` and `BL706DK`.
113114
114115
### Build options with build_examples.py
115116
116-
- `-wifi`, to specify that connectivity Wi-Fi is enabled for Matter
117-
application.
117+
- `-wifi`, specifies to use Wi-Fi for Matter application.
118118
119-
- BL602 uses `-wifi` by default
120-
- BL702 needs specify to use BL706 + BL602 for Wi-Fi connectivity.
119+
- BL602 uses Wi-Fi by defualt. `-wifi` could be elided.
120+
- BL702 needs it to specify to use BL706 + BL602 for Wi-Fi.
121121
122-
- `-thread`, to specify that connectivity Thread is enabled for Matter
122+
- `-thread`, specifies to use Thread for Matter
123123
application.
124124
125-
- BL70X uses `-thread` by default.
125+
- BL70X uses Thread by defualt. `-thread` could be elided.
126126
127-
- `-ethernet`, to specify that connectivity Ethernet is enabled for Matte
128-
application.
127+
- `-ethernet`, specifies to use Ethernet for Matter application.
129128
130-
- BL706 needs specify to use Ethernet connectivity.
129+
- BL706 needs it to specify to use Ethernet.
131130
132-
- `-easyflash`, to specify that `easyflash` is used for flash storage access.
131+
- `-littlefs`, specifies to use littlefs for flash access.
132+
- `-easyflash`, specifies to use `easyflash` for flash access.
133+
- for platform BL602/BL70X, it is necessary to specify one of `-easyflash` and `-littlefs`.
133134
- `-mfd`, enable Matter factory data feature, which load factory data from
134135
`MFD` partition
135136
- `-shell`, enable command line
@@ -175,9 +176,10 @@ The following steps take examples for `BL602DK`, `BL704LDK` and `BL706DK`.
175176
176177
177178
```shell
178-
./out/bouffalolab-bl602dk-light/chip-bl602-lighting-example.flash.py --port /dev/ttyACM0
179-
./out/bouffalolab-bl704ldk-light/chip-bl702l-lighting-example.flash.py --port /dev/ttyACM0
180-
./out/bouffalolab-bl706dk-light/chip-bl702-lighting-example.flash.py --port /dev/ttyACM0
179+
./out/bouffalolab-bl602dk-light-littlefs/chip-bl602-lighting-example.flash.py --port /dev/ttyACM0
180+
./out/bouffalolab-bl616dk-light-wifi/chip-bl616dk-lighting-example.flash.py --port /dev/ttyACM0
181+
./out/bouffalolab-bl704ldk-light-littlefs/chip-bl702l-lighting-example.flash.py --port /dev/ttyACM0
182+
./out/bouffalolab-bl706dk-light-littlefs/chip-bl702-lighting-example.flash.py --port /dev/ttyACM0
181183
```
182184
183185
- To wipe out flash and download image, please append `--erase`

0 commit comments

Comments
 (0)