Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.3 nrf cherry picks #33134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ matter_add_gn_arg_bool ("chip_system_config_provide_statistics" CONFIG_CHIP_ST
matter_add_gn_arg_bool ("chip_enable_icd_server" CONFIG_CHIP_ENABLE_ICD_SUPPORT)
matter_add_gn_arg_bool ("chip_enable_factory_data" CONFIG_CHIP_FACTORY_DATA)
matter_add_gn_arg_bool ("chip_enable_read_client" CONFIG_CHIP_ENABLE_READ_CLIENT)
matter_add_gn_arg_bool ("chip_mdns_minimal" CONFIG_WIFI_NRF700X)
matter_add_gn_arg_bool ("chip_mdns_platform" CONFIG_NET_L2_OPENTHREAD)

if (CONFIG_CHIP_ENABLE_ICD_SUPPORT)
matter_add_gn_arg_bool ("chip_enable_icd_lit" CONFIG_CHIP_ICD_LIT_SUPPORT)
Expand All @@ -157,10 +159,10 @@ if (CONFIG_CHIP_ROTATING_DEVICE_ID)
matter_add_gn_arg_bool("chip_enable_additional_data_advertising" TRUE)
endif()

if (CONFIG_NET_L2_OPENTHREAD)
matter_add_gn_arg_string("chip_mdns" "platform")
elseif(CONFIG_WIFI_NRF700X)
if(CONFIG_WIFI_NRF700X)
matter_add_gn_arg_string("chip_mdns" "minimal")
elseif (CONFIG_NET_L2_OPENTHREAD)
matter_add_gn_arg_string("chip_mdns" "platform")
else()
matter_add_gn_arg_string("chip_mdns" "none")
endif()
Expand Down
6 changes: 3 additions & 3 deletions config/nrfconnect/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ config SHELL_STACK_SIZE
default 2616 if CHIP_WIFI

config SHELL_MINIMAL
default y
default y if !CHIP_MEMORY_PROFILING

config KERNEL_SHELL
default n
default n if !CHIP_MEMORY_PROFILING

config SENSOR_SHELL
default n
Expand All @@ -482,7 +482,7 @@ config HWINFO_SHELL
default n

config OPENTHREAD_SHELL
default n
default n if !CHIP_MEMORY_PROFILING

endif # SHELL

Expand Down
9 changes: 7 additions & 2 deletions config/nrfconnect/chip-module/Kconfig.features
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ endif # CHIP_SPI_NOR

config CHIP_MEMORY_PROFILING
bool "Enable features for tracking memory usage"
# Matter stack
select CHIP_STATISTICS
# Heap
select CHIP_MALLOC_SYS_HEAP_WATERMARKS_SUPPORT if CHIP_MALLOC_SYS_HEAP
select SYS_HEAP_RUNTIME_STATS if CHIP_MALLOC_SYS_HEAP
# Crypto
select MBEDTLS_MEMORY_DEBUG if !CHIP_CRYPTO_PSA
select SYS_HEAP_RUNTIME_STATS if CHIP_MALLOC_SYS_HEAP
select KERNEL_SHELL
# Network
select NET_STATISTICS
select NET_SHELL
select NET_BUF_POOL_USAGE
select OPENTHREAD_SHELL if !CHIP_WIFI
# Zephyr
select KERNEL_SHELL
help
Enables features for tracking memory usage in Matter.

Expand Down
83 changes: 22 additions & 61 deletions config/nrfconnect/chip-module/generate_factory_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@
#


# Create a JSON file based on factory data given via kConfigs.
# Create a .hex file in CBOR format based on factory data given via kConfigs.
#
# This function creates a list of arguments for external script and then run it to write a JSON file.
# Created JSON file can be checked using JSON SCHEMA file if it is provided.
# Next, the resulting .hex file is generated based on previously created JSON file.
#
# This script can be manipulated using following kConfigs:
# - To merge generated factory data with final zephyr.hex file set kConfig CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=y
# - To use default certification paths set CONFIG_CHIP_FACTORY_DATA_USE_DEFAULTS_CERTS_PATH=y
#
# During generation process a some file will be created in zephyr's build directory:
# During generation process the following files will be created in zephyr's build directory:
# - <factory_data_target>.json a file containing all factory data written in JSON format.
# - <factory_data_target>.hex a file containing all factory data in CBOR format.
# - <factory_data_target>.bin a binary file containing all raw factory data in CBOR format.
# - <factory_data_target>.cbor a file containing all factory data in CBOR format.
#
# [Args]:
# factory_data_target - a name for target to generate factory_data.
# script_path - a path to script that makes a JSON factory data file from given arguments.
# schema_path - a path to JSON schema file which can be used to verify generated factory data JSON file.
# This argument is optional, if you don't want to verify the JSON file put it empty "".
# output_path - a path to output directory, where created JSON file will be stored.
function(nrfconnect_create_factory_data_json factory_data_target script_path schema_path output_path)
# output_path - a path to output directory, where created hex and JSON files will be stored.
function(nrfconnect_create_factory_data factory_data_target script_path schema_path output_path)

# set script args for future purpose
set(script_args)
Expand Down Expand Up @@ -120,62 +124,25 @@ if(CONFIG_CHIP_DEVICE_ENABLE_KEY)
string(APPEND script_args "--enable_key \"${CONFIG_CHIP_DEVICE_ENABLE_KEY}\"\n")
endif()

# Set output JSON file and path to SCHEMA file to validate generated factory data
set(factory_data_json ${output_path}/${factory_data_target}.json)
string(APPEND script_args "-o \"${factory_data_json}\"\n")
# Set output path and path to SCHEMA file to validate generated factory data
set(factory_data_output_path ${output_path}/${factory_data_target})
string(APPEND script_args "-o \"${factory_data_output_path}\"\n")
string(APPEND script_args "-s \"${schema_path}\"\n")

# Add optional offset and size arguments to generate both .hex and .json files.
string(APPEND script_args "--offset $<TARGET_PROPERTY:partition_manager,PM_FACTORY_DATA_ADDRESS>\n")
string(APPEND script_args "--size $<TARGET_PROPERTY:partition_manager,PM_FACTORY_DATA_OFFSET>\n")

# execute first script to create a JSON file
separate_arguments(separated_script_args NATIVE_COMMAND ${script_args})
add_custom_command(
OUTPUT ${factory_data_json}
OUTPUT ${factory_data_output_path}.hex
DEPENDS ${FACTORY_DATA_SCRIPT_PATH}
COMMAND ${Python3_EXECUTABLE} ${FACTORY_DATA_SCRIPT_PATH} ${separated_script_args}
COMMENT "Generating new Factory Data..."
)
add_custom_target(${factory_data_target} ALL
DEPENDS ${factory_data_json}
)

endfunction()


# Create a .hex file with factory data in CBOR format.
#
# This function creates a .hex and .cbor files from given JSON factory data file.
#
#
# During generation process some files will be created in zephyr's build directory:
# - <factory_data_target>.hex a file containing all factory data in CBOR format.
# - <factory_data_target>.bin a binary file containing all raw factory data in CBOR format.
# - <factory_data_target>.cbor a file containing all factory data in CBOR format.
#
# [Args]:
# factory_data_hex_target - a name for target to generate factory data HEX file.
# factory_data_target - a name for target to generate factory data JSON file.
# script_path - a path to script that makes a factory data .hex file from given arguments.
# output_path - a path to output directory, where created JSON file will be stored.
function(nrfconnect_create_factory_data_hex_file factory_data_hex_target factory_data_target script_path output_path)

# Pass the argument list via file
set(cbor_script_args "-i ${output_path}/${factory_data_target}.json\n")
string(APPEND cbor_script_args "-o ${output_path}/${factory_data_target}\n")
# get partition address and offset from partition manager during compilation
string(APPEND cbor_script_args "--offset $<TARGET_PROPERTY:partition_manager,PM_FACTORY_DATA_ADDRESS>\n")
string(APPEND cbor_script_args "--size $<TARGET_PROPERTY:partition_manager,PM_FACTORY_DATA_OFFSET>\n")
string(APPEND cbor_script_args "-r\n")

# execute second script to create a hex file containing factory data in cbor format
separate_arguments(separated_cbor_script_args NATIVE_COMMAND ${cbor_script_args})
set(factory_data_hex ${output_path}/${factory_data_target}.hex)

add_custom_command(OUTPUT ${factory_data_hex}
COMMAND ${Python3_EXECUTABLE} ${script_path} ${separated_cbor_script_args}
COMMENT "Generating factory data HEX file..."
DEPENDS ${factory_data_target} ${script_path}
)
add_custom_target(${factory_data_hex_target}
DEPENDS ${factory_data_hex}
DEPENDS ${factory_data_output_path}.hex
)

endfunction()
Expand All @@ -202,22 +169,16 @@ set(GENERATE_CBOR_SCRIPT_PATH ${CHIP_ROOT}/scripts/tools/nrfconnect/nrfconnect_g
set(FACTORY_DATA_SCHEMA_PATH ${CHIP_ROOT}/scripts/tools/nrfconnect/nrfconnect_factory_data.schema)
set(OUTPUT_FILE_PATH ${APPLICATION_BINARY_DIR}/zephyr)

# create a JSON file with all factory data
nrfconnect_create_factory_data_json(factory_data
${FACTORY_DATA_SCRIPT_PATH}
${FACTORY_DATA_SCHEMA_PATH}
${OUTPUT_FILE_PATH})

# create a .hex file with factory data in CBOR format based on the JSON file created previously
nrfconnect_create_factory_data_hex_file(factory_data_hex
factory_data
${GENERATE_CBOR_SCRIPT_PATH}
${OUTPUT_FILE_PATH})
nrfconnect_create_factory_data(factory_data
${FACTORY_DATA_SCRIPT_PATH}
${FACTORY_DATA_SCHEMA_PATH}
${OUTPUT_FILE_PATH})

if(CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE)
# set custom target for merging factory_data hex file
set_property(GLOBAL PROPERTY factory_data_PM_HEX_FILE ${OUTPUT_FILE_PATH}/factory_data.hex)
set_property(GLOBAL PROPERTY factory_data_PM_TARGET factory_data_hex)
set_property(GLOBAL PROPERTY factory_data_PM_TARGET factory_data)
endif()


Expand Down
18 changes: 18 additions & 0 deletions config/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,22 @@ config CHIP_OTA_IMAGE_EXTRA_ARGS

endif

config CHIP_BLE_EXT_ADVERTISING
bool "Bluetooth LE extended advertising"
help
Enable Bluetooth LE extended advertising, which allows the device to advertise
Matter service over Bluetooth LE for a period of time longer than 15 minutes.
If this config is true,
CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS define can be set up to 172800 seconds (48h).

config CHIP_BLE_ADVERTISING_DURATION
int "Bluetooth LE advertising duration in minutes"
range 15 2880 if CHIP_BLE_EXT_ADVERTISING
range 0 15
default 15
help
Specify how long the device will advertise Matter service over Bluetooth LE in minutes.
If CHIP_BLE_EXT_ADVERTISING is set to false, the maximum duration time is 15 minutes,
else the maximum duration time can be extended to 2880 minutes (48h).

endif
4 changes: 3 additions & 1 deletion config/zephyr/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ config LOG_DEFAULT_LEVEL

endif

# disable synchronous printk to avoid blocking IRQs which
# may affect time sensitive components
config PRINTK_SYNC
bool
default y
default n

config ASSERT
bool
Expand Down
77 changes: 58 additions & 19 deletions docs/guides/nrfconnect_factory_data_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data secure by applying hardware write protection.
- [Appearance field description](#appearance-field-description)
- [Enabling factory data support](#enabling-factory-data-support)
- [Generating factory data](#generating-factory-data)
- [Creating the factory data JSON file with the first script](#creating-the-factory-data-json-file-with-the-first-script)
- [Creating the factory data JSON and HEX files with the first script](#creating-the-factory-data-json-and-hex-files-with-the-first-script)
- [How to set user data](#how-to-set-user-data)
- [How to handle user data](#how-to-handle-user-data)
- [Verifying using the JSON Schema tool](#verifying-using-the-json-schema-tool)
Expand Down Expand Up @@ -218,14 +218,19 @@ file written in another way. To make sure that the JSON file is correct and the
device is able to read out parameters,
[verify the file using the JSON schema tool](#verifying-using-the-json-schema-tool).

### Creating the factory data JSON file with the first script
You can also use only the first script to generate both JSON and HEX files, by
providing optional `offset` and `size` arguments, which results in invoking the
script internally. Such option is the recommended one, but invoking two scripts
one by one is also supported to provide backward compatibility.

### Creating the factory data JSON and HEX files with the first script

A Matter device needs a proper factory data partition stored in the flash memory
to read out all required parameters during startup. To simplify the factory data
generation, you can use the
[generate_nrfconnect_chip_factory_data.py](../../scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py)
Python script to provide all required parameters and generate a human-readable
JSON file.
JSON file and save it to a HEX file.

To use this script, complete the following steps:

Expand All @@ -245,10 +250,10 @@ To use this script, complete the following steps:
--sn --vendor_id, --product_id, --vendor_name, --product_name, --date, --hw_ver, --hw_ver_str, --spake2_it, --spake2_salt, --discriminator
```

b. Add output file path:
b. Add output path to store .json file, e.g. my_dir/output:

```
-o <path_to_output_json_file>
-o <path_to_output_file>
```

c. Generate SPAKE2 verifier using one of the following methods:
Expand Down Expand Up @@ -341,6 +346,34 @@ To use this script, complete the following steps:
> `chip-cert` executable. See the note at the end of this section to learn
> how to get it.

k. (optional) Partition offset that is an address in device's NVM memory,
where factory data will be stored.

```
--offset <offset>
```

> **Note:** To generate a HEX file with factory data, you need to provide
> both `offset` and `size` optional arguments. As a result,
> `factory_data.hex` and `factory_data.bin` files are created in the
> `output` directory. The first file contains the required memory offset.
> For this reason, it can be programmed directly to the device using a
> programmer (for example, `nrfjprog`).

l. (optional) The maximum partition size in device's NVM memory, where
factory data will be stored.

```
--size <size>
```

> **Note:** To generate a HEX file with factory data, you need to provide
> both `offset` and `size` optional arguments. As a result,
> `factory_data.hex` and `factory_data.bin` files are created in the
> `output` directory. The first file contains the required memory offset.
> For this reason, it can be programmed directly to the device using a
> programmer (for example, `nrfjprog`).

4. Run the script using the prepared list of arguments:

```
Expand Down Expand Up @@ -370,8 +403,10 @@ $ python scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py \
--passcode 20202021 \
--product_finish "matte" \
--product_color "black" \
--out "build.json" \
--schema "scripts/tools/nrfconnect/nrfconnect_factory_data.schema"
--out "build" \
--schema "scripts/tools/nrfconnect/nrfconnect_factory_data.schema" \
--offset 0xf7000 \
--size 0x1000
```

As the result of the above example, a unique ID for the rotating device ID is
Expand Down Expand Up @@ -570,7 +605,7 @@ To generate a manual pairing code and a QR code, complete the following steps:
```

2. Complete steps 1, 2, and 3 from the
[Creating the factory data JSON file with the first script](#creating-the-factory-data-json-file-with-the-first-script)
[Creating the factory data JSON and HEX files with the first script](#creating-the-factory-data-json-and-hex-files-with-the-first-script)
section to prepare the final invocation of the Python script.

3. Add the `--generate_onboarding` argument to the Python script final
Expand Down Expand Up @@ -686,10 +721,15 @@ The output will look similar to the following one:
### Creating a factory data partition with the second script

To store the factory data set in the device's persistent storage, convert the
data from the JSON file to its binary representation in the CBOR format. To do
this, use the
data from the JSON file to its binary representation in the CBOR format. This is
done by the
[generate_nrfconnect_chip_factory_data.py](../../scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py),
if you provide optional `offset` and `size` arguments. If you provided these
arguments, skip the following steps of this section.

You can skip these optional arguments and do this, using the
[nrfconnect_generate_partition.py](../../scripts/tools/nrfconnect/nrfconnect_generate_partition.py)
to generate the factory data partition:
script, but this is obsolete solution kept only for backward compatibility:

1. Navigate to the _connectedhomeip_ root directory
2. Run the following command pattern:
Expand Down Expand Up @@ -924,14 +964,13 @@ $ west flash
## Using own factory data implementation

The [factory data generation process](#generating-factory-data) described above
is only an example valid for the nRF Connect platform. You can also create a HEX
file containing all components from the
[factory data component table](#factory-data-component-table) in any format and
then implement a parser to read out all parameters and pass them to a provider.
Each manufacturer can implement a factory data set on its own by implementing a
parser and a factory data accessor inside the Matter stack. Use the
[nRF Connect Provider](../../src/platform/nrfconnect/FactoryDataProvider.h) and
[FactoryDataParser](../../src/platform/nrfconnect/FactoryDataParser.h) as
is only an example valid for the nRF Connect platform. You can well create a HEX
file containing all [factory data components](#factory-data-component-table) in
any format and then implement a parser to read out all parameters and pass them
to a provider. Each manufacturer can implement a factory data set on its own by
implementing a parser and a factory data accessor inside the Matter stack. Use
the [nRF Connect Provider](../../src/platform/nrfconnect/FactoryDataProvider.h)
and [FactoryDataParser](../../src/platform/nrfconnect/FactoryDataParser.h) as
examples.

You can read the factory data set from the device's flash memory in different
Expand Down
Loading
Loading