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

[K32W0] SDK 2.6.11 fixes & features #27380

Merged
merged 1 commit into from
Jun 21, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/examples-k32w.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
if: github.actor != 'restyled-io[bot]'

container:
image: connectedhomeip/chip-build-k32w:0.7.0
image: connectedhomeip/chip-build-k32w:0.7.4
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
steps:
Expand Down
274 changes: 163 additions & 111 deletions docs/guides/nxp_manufacturing_flow.md

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion examples/contact-sensor-app/nxp/k32w/k32w0/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,22 @@ if (chip_pw_tokenizer_logging) {
}

group("k32w0") {
deps = [ ":contact_sensor_app" ]
deps = [
":binsign",
":contact_sensor_app",
]
if (chip_pw_tokenizer_logging) {
deps += [ ":contact_sensor_app.database" ]
}
}

action("binsign") {
deps = [ ":contact_sensor_app" ]
script = "${k32w0_platform_dir}/scripts/sign-outdir.py"
output_name = "bignsign.log"
outputs = [ "${root_build_dir}/${output_name}" ]
}

group("default") {
deps = [ ":k32w0" ]
}
163 changes: 127 additions & 36 deletions examples/contact-sensor-app/nxp/k32w/k32w0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,19 @@ In order to build the Project CHIP example, we recommend using a Linux
distribution (the demo-application was compiled on Ubuntu 20.04).

- Download
[K32W061DK6 SDK 2.6.10](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_10_K32W061DK6.zip).
[K32W061DK6 SDK 2.6.11](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_11_K32W061DK6.zip).

- Start building the application either with Secure Element or without

- without Secure Element

```
user@ubuntu:~/Desktop/git/connectedhomeip$ export NXP_K32W0_SDK_ROOT=/home/user/Desktop/SDK_2_6_10_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ export NXP_K32W0_SDK_ROOT=/home/user/Desktop/SDK_2_6_11_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ ./third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ source ./scripts/activate.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/contact-sensor-app/nxp/k32w/k32w0
user@ubuntu:~/Desktop/git/connectedhomeip/examples/contact-sensor-app/nxp/k32w/k32w0$ gn gen out/debug --args="k32w0_sdk_root=\"${NXP_K32W0_SDK_ROOT}\" chip_with_OM15082=1 chip_with_ot_cli=0 is_debug=false chip_crypto=\"platform\" chip_with_se05x=0 chip_pw_tokenizer_logging=true"
user@ubuntu:~/Desktop/git/connectedhomeip/examples/contact-sensor-app/nxp/k32w/k32w0$ ninja -C out/debug
user@ubuntu:~/Desktop/git/connectedhomeip/examples/contact-sensor-app/nxp/k32w/k32w0$ $NXP_K32W0_SDK_ROOT/tools/imagetool/sign_images.sh out/debug/
```

- with Secure element Exactly the same steps as above but set
Expand All @@ -204,7 +203,7 @@ Secure Element. These can be changed if building without Secure Element

Exactly the same steps as above but set argument build_for_k32w041am=1 in
the gn command and use
[K32W041AMDK6 SDK 2.6.10](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_10_K32W041AMDK6.zip).
[K32W041AMDK6 SDK 2.6.11](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_11_K32W041AMDK6.zip).

Also, in case the OM15082 Expansion Board is not attached to the DK6 board, the
build argument (chip_with_OM15082) inside the gn build instruction should be set
Expand All @@ -218,8 +217,8 @@ running oscillator as a clock source. In this case one must set the use_fro_32k
argument to 1.

In case signing errors are encountered when running the "sign_images.sh" script
install the recommanded packages (python version > 3, pip3, pycrypto,
pycryptodome):
(run automatically) install the recommanded packages (python version > 3, pip3,
pycrypto, pycryptodome):

```
user@ubuntu:~$ python3 --version
Expand All @@ -238,6 +237,21 @@ The resulting output file can be found in out/debug/chip-k32w0x-contact-example.
- When using Secure element and cross-compiling on Linux, log messages from
the Plug&Trust middleware stack may not echo to the console.

## Rotating device id

This is an optional feature and can be used in multiple ways (please see section
5.4.2.4.5 from Matter specification). One use case is Amazon Frustration Free
Setup, which leverages the C3 Characteristic (Additional commissioning-related
data) to offer an easier way to set up the device. The rotating device id will
be encoded in this additional data and is programmed to rotate at pre-defined
moments. The algorithm uses a unique per-device identifier that must be
programmed during factory provisioning.

Please use the following build args:

- `chip_enable_rotating_device_id=1` - to enable rotating device id.
- `chip_enable_additional_data_advertising=1` - to enable C3 characteristic.

## Manufacturing data

See
Expand Down Expand Up @@ -375,18 +389,34 @@ application.

### Writing the SSBL

The SSBL can ge generated from one of the SDK demo examples. The SDK demo
example needs to be compiled inside MCUXpresso with the define _PDM_EXT_FLASH_.
The SSBL demo application can be imported from the _Quickstart panel_: _Import
SDK example(s)_ -> select _wireless->framework->ssbl_ application.
The SDK already provides an SSBL binary compiled with external flash support:
`boards/k32w061dk6/wireless_examples/framework/ssbl/binary/ssbl_ext_flash_pdm_support.bin`,
but it does not offer multi-image OTA support.

Alternatively, the SSBL can ge generated from one of the SDK demo examples. The
SSBL demo application can be imported from the `Quickstart panel`:
`Import SDK example(s) -> select wireless -> framework -> ssbl` application.

![SSBL Application Select](../../../../platform/nxp/k32w/k32w0/doc/images/ssbl_select.JPG)

The SSBL project must be compiled using the PDM_EXT_FLASH define.
To support multi-image OTA feature, the SSBL project must be compiled using the
following defines:

![PDM_EXT_FLASH](../../../../platform/nxp/k32w/k32w0/doc/images/pdm_ext_flash.JPG)
- `PDM_EXT_FLASH=1` - support PDM in external flash.
- `gOTAUseCustomOtaEntry=1` - support custom OTA entry for multi-image.
- `gOTACustomOtaEntryMemory=OTACustomStorage_ExtFlash` - K32W0 uses
`OTACustomStorage_ExtFlash` (1) by default.
- `SPIFI_DUAL_MODE_SUPPORT=1` - only for configurations that use dual `SPIFI`
flash (e.g. K32W041AM variant).

Once compiled, the required ssbl file is called k32w061dk6_ssbl.bin
Optionally, add the following defines:

- `SPIFI_OPTIM_SIZE=1` - to optimize SSBL size.
- `EXTERNAL_FLASH_DATA_OTA=1` - to support external read only data.

![SSBL_MULTI_IMAGE](../../../../platform/nxp/k32w/k32w0/doc/images/ssbl_multi_image.JPG)

Once compiled, the required SSBL file is called `k32w061dk6_ssbl.bin`.

![SSBL_BIN](../../../../platform/nxp/k32w/k32w0/doc/images/ssbl_bin.JPG)

Expand All @@ -396,15 +426,54 @@ Before writing the SSBL, it it recommanded to fully erase the internal flash:
DK6Programmer.exe -V 5 -P 1000000 -s <COM_PORT> -e Flash
```

k32w061dk6_ssbl.bin must be written at address 0 in the internal flash:
`k32w061dk6_ssbl.bin` must be written at address 0 in the internal flash:

```
DK6Programmer.exe -V2 -s <COM_PORT> -P 1000000 -Y -p FLASH@0x00="k32w061dk6_ssbl.bin"
```

### Writing the PSECT

First, image directory 0 must be written:
This is the list of all supported partitions:

```
0000000010000000 : SSBL partition

00000000 -----------> Start Address
1000 ---------------> 0x0010 Number of 512-bytes pages
00 -----------------> 0x00 Bootable flag
00 -----------------> 0x00 Image type (0x00 = SSBL)

004000000f020101: Application partition

00400000 -----------> 0x00004000 Start Address
0f02 ---------------> 0x020f Number of 512-bytes pages
01 -----------------> 0x01 Bootable flag
01 -----------------> 0x01 Image type (0x01 = Application)

00000010800000fe: Ext Flash text partition

00000010 -----------> 0x10000000 Start Address (external flash)
8000 ---------------> 0x0080 Number of 512-bytes pages
00 -----------------> 0x00 Bootable flag
fe -----------------> 0xFE Image type (0xFE = Ext Flash text)

00000110300200fc : OTA Image partition

00000110 -----------> 0x10010000 Start Address
3002----------------> 0x0230 Number of 512-bytes pages
00 -----------------> 0x00 Bootable flag
fc -----------------> 0xFC Image type (0xFC = OTA partition)

00000510100000fd: NVM partition

00000510 -----------> 0x10050000 Start Address
1000 ---------------> 0x0010 Number of 512-bytes pages
00 -----------------> 0x00 Bootable flag
fd -----------------> 0xFD Image type (0xFD = NVM partition)
```

First, image directory 0 (SSBL partition) must be written:

```
DK6Programmer.exe -V5 -s <COM port> -P 1000000 -w image_dir_0=0000000010000000
Expand All @@ -419,7 +488,7 @@ Here is the interpretation of the fields:
00 -> SSBL Image Type
```

Second, image directory 1 must be written:
Second, image directory 1 (application partition) must be written:

```
DK6Programmer.exe -V5 -s <COM port> -P 1000000 -w image_dir_1=00400000C9040101
Expand All @@ -429,11 +498,14 @@ Here is the interpretation of the fields:

```
00400000 -> start address 0x00004000
CD04 -> 0x4C9 pages of 512-bytes (= 612,5kB)
C904 -> 0x4C9 pages of 512-bytes (= 612.5kB)
01 -> bootable flag
01 -> image type for the application
```

Please note the user can write additional partitions by writing
`image_dir_2/3/4` with the wanted configuration.

### Writing the application

DK6Programmer can be used for flashing the application:
Expand Down Expand Up @@ -500,37 +572,56 @@ Build OTA image:
In order to build an OTA image, use NXP wrapper over the standard tool
`src/app/ota_image_tool.py`:

- `scripts/tools/nxp/factory_data_generator/ota_image_tool.py`. The tool can
be used to generate an OTA image with the following format:
`| OTA image header | TLV1 | TLV2 | ... | TLVn |` where each TLV is in the
form `|tag|length|value|`
- `scripts/tools/nxp/ota/ota_image_tool.py`.

The tool can be used to generate an OTA image with the following format:

```
| OTA image header | TLV1 | TLV2 | ... | TLVn |
```

where each TLV is in the form `|tag|length|value|`.

Note that "standard" TLV format is used. Matter TLV format is only used for
factory data TLV value. A user can enable the default processors by specifying
`chip_enable_ota_default_processors=1` in the build command. Please see more in
the [OTA image tool guide](../../../../../scripts/tools/nxp/ota/README.md).
factory data TLV value.

Here is an example that generate an OTA image with factory data and app TLV:
`user@computer1:~/connectedhomeip$ : ./scripts/tools/nxp/ota/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 1 -vs "1.0" -da sha256 -fd --cert_declaration ~/manufacturing/Chip-Test-CD-1037-a220.der -app chip-k32w0x-contact-example.bin chip-k32w0x-contact-example.bin chip-k32w0x-contact-example.ota`
A user can select which default processors to enable:

Start the OTA Provider Application:
- `chip_enable_ota_firmware_processor=1` to enable default firmware (app/SSBL)
update processor (enabled by default).
- `chip_enable_ota_factory_data_processor=1` to enable default factory data
update processor (disabled by default).

The address for storing the custom OTA entry can also be specified:

- `ota_custom_entry_address="0x000C1000"` is the default value, where
`0x000C1000` is the end address of the PDM area. PDM area ends at
`0x00100000` (top of external flash) and has a size of `63 * 4096` bytes.
The user should be aware of the external flash configuration and use an
address that does not overlap with anything else.

Please see more in the
[OTA image tool guide](../../../../../scripts/tools/nxp/ota/README.md).

Here is an example that generates an OTA image with application update TLV:

```
user@computer1:~/connectedhomeip$ : rm -rf /tmp/chip_*
user@computer1:~/connectedhomeip$ : ./out/ota-provider-app/chip-ota-provider-app -f chip-k32w0x-contact-example.ota
./scripts/tools/nxp/ota/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 42021 -vs "1.0" -da sha256 --app-input-file chip-k32w0x-contact-example.bin chip-k32w0x-contact-example.ota
```

A note regarding OTA image header version (`-vn` option). An application binary
has its own software version (given by
`CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION`, which can be overwritten). For
having a correct OTA process, the OTA header version should be the same as the
binary embedded software version. A user can set a custom software version in
the gn build args by setting `chip_software_version` to the wanted version.
has its own software version, given by
`CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION` (`42020` by default), which can be
overwritten. For having a correct OTA process, the OTA header version should be
the same as the binary embedded software version. A user can set a custom
software version in the gn build args by setting `chip_software_version` to the
wanted version.

Build Linux chip-tool:
Start the OTA Provider Application:

```
user@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/chip-tool out/chip-tool-app
user@computer1:~/connectedhomeip$ : rm -rf /tmp/chip_*
user@computer1:~/connectedhomeip$ : ./out/ota-provider-app/chip-ota-provider-app -f chip-k32w0x-contact-example.ota
```

Provision the OTA provider application and assign node id _1_. Also, grant ACL
Expand Down
50 changes: 49 additions & 1 deletion examples/contact-sensor-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ static BDXDownloader gDownloader;
constexpr uint16_t requestedOtaBlockSize = 1024;
#endif

#if CONFIG_CHIP_K32W0_REAL_FACTORY_DATA
CHIP_ERROR CustomFactoryDataRestoreMechanism(void)
{
K32W_LOG("This is a custom factory data restore mechanism.");

return CHIP_NO_ERROR;
}
#endif

CHIP_ERROR AppTask::StartAppTask()
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand All @@ -113,6 +122,40 @@ CHIP_ERROR AppTask::StartAppTask()
return err;
}

#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
static void CheckOtaEntry()
{
K32W_LOG("Current OTA_ENTRY_TOP_ADDR: 0x%x", OTA_ENTRY_TOP_ADDR);

CustomOtaEntries_t ota_entries;
if (gOtaSuccess_c == OTA_GetCustomEntries(&ota_entries) && ota_entries.ota_state != otaNoImage)
{
if (ota_entries.ota_state == otaApplied)
{
K32W_LOG("OTA successfully applied");
#if CONFIG_CHIP_K32W0_OTA_FACTORY_DATA_PROCESSOR
// If this point is reached, it means OTA_CommitCustomEntries was successfully called.
// Delete the factory data backup to stop doing a restore when the factory data provider
// is initialized. This ensures that both the factory data and app were updated, otherwise
// revert to the backed up factory data.
PDM_vDeleteDataRecord(kNvmId_FactoryDataBackup);
#endif
}
else
{
K32W_LOG("OTA failed with status %d", ota_entries.ota_state);
}

// Clear the entry
OTA_ResetCustomEntries();
}
else
{
K32W_LOG("Unable to access OTA entries structure");
}
}
#endif

CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand All @@ -128,10 +171,15 @@ CHIP_ERROR AppTask::Init()
// Init ZCL Data Model and start server
PlatformMgr().ScheduleWork(InitServer, 0);

// Initialize device attestation config
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
CheckOtaEntry();
#endif

// Initialize device attestation config
#if CONFIG_CHIP_K32W0_REAL_FACTORY_DATA
// Initialize factory data provider
ReturnErrorOnFailure(AppTask::FactoryDataProvider::GetDefaultInstance().Init());
AppTask::FactoryDataProvider::GetDefaultInstance().RegisterRestoreMechanism(CustomFactoryDataRestoreMechanism);
SetDeviceInstanceInfoProvider(&AppTask::FactoryDataProvider::GetDefaultInstance());
SetDeviceAttestationCredentialsProvider(&AppTask::FactoryDataProvider::GetDefaultInstance());
SetCommissionableDataProvider(&AppTask::FactoryDataProvider::GetDefaultInstance());
Expand Down
12 changes: 11 additions & 1 deletion examples/lighting-app/nxp/k32w/k32w0/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,22 @@ if (chip_pw_tokenizer_logging) {
}

group("k32w0") {
deps = [ ":light_app" ]
deps = [
":binsign",
":light_app",
]
if (chip_pw_tokenizer_logging) {
deps += [ ":light_app.database" ]
}
}

action("binsign") {
deps = [ ":light_app" ]
script = "${k32w0_platform_dir}/scripts/sign-outdir.py"
output_name = "bignsign.log"
outputs = [ "${root_build_dir}/${output_name}" ]
}

group("default") {
deps = [ ":k32w0" ]
}
Loading