Skip to content

Commit 3a9f916

Browse files
wy-hhchapongatien
authored andcommittedNov 20, 2024
[nxp fromtree] [Bouffalo Lab] Add a script to demonstrate mfd partition generation (project-chip#35192)
* [Bouffalo Lab] Add a script to demonstrate mfd partition generation * fix restyle * fix restyle * fix lint code and spell * fix lint code and spell * revert changes on Makefile of doc (cherry picked from commit 4440785)
1 parent d944825 commit 3a9f916

File tree

4 files changed

+827
-17
lines changed

4 files changed

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

‎docs/guides/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and features.
99
:hidden:
1010
1111
*
12+
bouffalolab/matter_factory_data
1213
esp32/README
1314
nxp/README
1415
ti/ti_matter_overview
@@ -23,6 +24,7 @@ ti/ti_matter_overview
2324
- [Android - Building](./android_building.md)
2425
- [Apple - Testing with iPhone, iPad, macOS, Apple TV, HomePod, Watch, etc](./darwin.md)
2526
- [ASR - Getting Started Guide](./asr_getting_started_guide.md)
27+
- [Bouffalo Lab - Matter factory data generation](./bouffalolab/matter_factory_data.md)
2628
- [Espressif (ESP32) - Getting Started Guide](./esp32/README.md)
2729
- [Infineon PSoC6 - Software Update](./infineon_psoc6_software_update.md)
2830
- [Linux - Simulated Devices](./simulated_device_linux.md)

‎examples/lighting-app/bouffalolab/README.md

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `Bouffalo Lab`
1+
# Matter `Bouffalo Lab` Lighting Example
22

33
This example functions as a light bulb device type, with on/off and level
44
capabilities and uses a test Vendor ID (VID) and a Product ID (PID)
@@ -17,8 +17,6 @@ Legacy supported boards:
1717
- `BL602-NIGHT-LIGHT`
1818
- `XT-ZB6-DevKit`
1919
- `BL706-NIGHT-LIGHT`
20-
- `BL706DK`
21-
- `BL704LDK`
2220

2321
> Warning: Changing the VID/PID may cause compilation problems, we recommend
2422
> leaving it as the default while using this example.
@@ -99,6 +97,7 @@ The following steps take examples for `BL602DK`, `BL704LDK` and `BL706DK`.
9997
10098
```
10199
./scripts/build/build_examples.py --target bouffalolab-bl602dk-light build
100+
./scripts/build/build_examples.py --target bouffalolab-bl616dk-light-wifi build
102101
./scripts/build/build_examples.py --target bouffalolab-bl704ldk-light build
103102
./scripts/build/build_examples.py --target bouffalolab-bl706dk-light build
104103
```
@@ -113,25 +112,28 @@ The following steps take examples for `BL602DK`, `BL704LDK` and `BL706DK`.
113112
114113
### Build options with build_examples.py
115114
116-
- `-wifi`, to specify that connectivity Wi-Fi is enabled for Matter
117-
application.
115+
- `-wifi`, specifies to use Wi-Fi for Matter application.
118116
119-
- BL602 uses `-wifi` by default
120-
- BL702 needs specify to use BL706 + BL602 for Wi-Fi connectivity.
117+
- BL602 uses Wi-Fi by default. `-wifi` could be elided.
118+
- BL702 needs it to specify to use BL706 + BL602 for Wi-Fi.
121119
122-
- `-thread`, to specify that connectivity Thread is enabled for Matter
123-
application.
120+
- `-thread`, specifies to use Thread for Matter application.
124121
125-
- BL70X uses `-thread` by default.
122+
- BL70X uses Thread by default. `-thread` could be elided.
126123
127-
- `-ethernet`, to specify that connectivity Ethernet is enabled for Matte
128-
application.
124+
- `-ethernet`, specifies to use Ethernet for Matter application.
129125
130-
- BL706 needs specify to use Ethernet connectivity.
126+
- BL706 needs it to specify to use Ethernet.
131127
132-
- `-easyflash`, to specify that `easyflash` is used for flash storage access.
128+
- `-littlefs`, specifies to use `littlefs` for flash access.
129+
- `-easyflash`, specifies to use `easyflash` for flash access.
130+
- for platform BL602/BL70X, it is necessary to specify one of `-easyflash`
131+
and `-littlefs`.
133132
- `-mfd`, enable Matter factory data feature, which load factory data from
134133
`MFD` partition
134+
- Please refer to
135+
[Bouffalo Lab Matter factory data guide](../../../docs/guides/bouffalolab/matter_factory_data.md)
136+
or contact to `Bouffalo Lab` for support.
135137
- `-shell`, enable command line
136138
- `-rpc`, enable Pigweed RPC feature
137139
- `-115200`, set UART baudrate to 115200 for log and command line
@@ -175,9 +177,10 @@ The following steps take examples for `BL602DK`, `BL704LDK` and `BL706DK`.
175177
176178
177179
```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
180+
./out/bouffalolab-bl602dk-light-littlefs/chip-bl602-lighting-example.flash.py --port /dev/ttyACM0
181+
./out/bouffalolab-bl616dk-light-wifi/chip-bl616dk-lighting-example.flash.py --port /dev/ttyACM0
182+
./out/bouffalolab-bl704ldk-light-littlefs/chip-bl702l-lighting-example.flash.py --port /dev/ttyACM0
183+
./out/bouffalolab-bl706dk-light-littlefs/chip-bl702-lighting-example.flash.py --port /dev/ttyACM0
181184
```
182185
183186
- To wipe out flash and download image, please append `--erase`

0 commit comments

Comments
 (0)