Skip to content

Commit

Permalink
[K32W0] SDK 2.6.10 fixes & features (#25342)
Browse files Browse the repository at this point in the history
* [K32W0] Enable factory data onboarding print

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Implement OTA custom payload processing

OTAImageProcessorImpl has become more customizable through delegating
block processing to pre-registered OTATlvProcessor instances.

New OTA image format:
| OTA image header | TLV1 | ... | TLVn |

The new format can be generated using NXP's custom wrapper over the
standard tool: `scripts/tools/nxp/factory_data_generator/ota_image_tool.py

A customer can opt to enable the default processors by setting the gn
arg chip_enable_ota_default_processors=1. Thus, the application, SSBL
and factory data processors (if factory data enabled) will be registered.

Note: This is not backwards compatible because of the TLV metadata needed
for TLV processor selection.

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Make OTAImageProcessorImpl generic

Moved default OTA image processor implementation in a common K32W folder.
Platforms should define two hooks:
* OtaHookInit - for K32W0, it is defined in OTAHooks.cpp as a WEAK symbol.
* OtaHookReset - resets the board after taking the corresponding actions.

Other than that, the implementation is generic. The actual OTA processing is
delegated to the registered OTA TLV processors.

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Removed write from restore

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* disable high power config for k32w041am platform by default

* [K32W0] Remove logging assert in LP

The user can opt to enable the logging in the low power build, but
at their own risk, since it could break LP timings/functionality.
The last statement is based on the initial introduction of the assert.

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Use full IC reset

Setting gResetSystemReset_d to 1 will enable full reset of the IC
by calling RESET_SystemReset. Otherwise, RESET_ArmReset will be
called and the core will do a reboot while maintaining the RAM on,
enabling exchange of information across reset.

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Make ota_image_tool.py wrapper executable

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Add bss_discard section

Unretainable data should be moved to a special section,
such that it's not included in the binary. This was observed
in the PDM library with external flash support.

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Add support for additional factory data fields

PartNumber, ProductLabel and ProductURL getter APIs were
moved under DeviceInstanceInfoProvider interface.

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Add recovery mechanism for factory data

If a power loss occurs during factory data update through OTA, the board
might be in a state in which it has erased factory data section, causing
the app task to fail at initialization.

During initialization, the factory data provider should check if a certain
predefined PDM id exists. If it does, then most likely the internal flash
section for factory data is empty, so a restore from external flash must
be done.

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] public RamStorage.h and RamStorageKey.h two header files

* [K32W0] Fix gn check for OTAImageProcessorImpl

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Update SDK link in README files

* [K32W0] Update TLV header

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Mark OTA readme as orphan

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Restyled by autopep8

* Restyled by isort

* [K32W0] Fix readme misspells

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Fix code-lints errors

Signed-off-by: Marius Tache <marius.tache@nxp.com>

* Restyled by prettier-markdown

---------

Signed-off-by: Marius Tache <marius.tache@nxp.com>
Co-authored-by: tanyue518 <ethan.tan@nxp.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored and pull[bot] committed Oct 28, 2023
1 parent bbfe9fc commit 1251216
Show file tree
Hide file tree
Showing 26 changed files with 1,764 additions and 218 deletions.
41 changes: 32 additions & 9 deletions examples/contact-sensor-app/nxp/k32w/k32w0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ 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.9](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_9_K32W061DK6.zip).
[K32W061DK6 SDK 2.6.10](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_10_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_9_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ export NXP_K32W0_SDK_ROOT=/home/user/Desktop/SDK_2_6_10_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
Expand All @@ -204,7 +204,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.9](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_9_K32W041AMDK6.zip).
[K32W041AMDK6 SDK 2.6.10](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_10_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 Down Expand Up @@ -273,8 +273,8 @@ Program the firmware using the official
[OpenThread Flash Instructions](https://github.com/openthread/ot-nxp/tree/main/src/k32w0/k32w061#flash-binaries).

All you have to do is to replace the Openthread binaries from the above
documentation with _out/debug/chip-k32w0x-light-example.bin_ if DK6Programmer is
used or with _out/debug/chip-k32w0x-light-example_ if MCUXpresso is used.
documentation with _out/debug/chip-k32w0x-contact-example.bin_ if DK6Programmer
is used or with _out/debug/chip-k32w0x-contact-example_ if MCUXpresso is used.

## Pigweed tokenizer

Expand Down Expand Up @@ -489,12 +489,35 @@ Build the Linux OTA provider application:
user@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/ota-provider-app chip_config_network_layer_ble=false
```

Build OTA image and start the OTA Provider Application:
Build Linux chip-tool:

```
user@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/chip-tool out/chip-tool-app
```

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|`

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).

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`

Start the OTA Provider Application:

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

A note regarding OTA image header version (`-vn` option). An application binary
Expand Down Expand Up @@ -522,7 +545,7 @@ user@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool accesscontrol
Provision the device and assign node id _2_:

```
user@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool pairing ble-thread 2 hex:<operationalDataset> 20202021 3840
user@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool pairing ble-thread 2 hex:<operationalDataset> 20202021 3840
```

Start the OTA process:
Expand Down
17 changes: 11 additions & 6 deletions examples/contact-sensor-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@

/* OTA related includes */
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
#include "OTAImageProcessorImpl.h"
#include "OtaSupport.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <src/platform/nxp/k32w/common/OTAImageProcessorImpl.h>
#endif

#include "Keyboard.h"
Expand Down Expand Up @@ -94,7 +94,6 @@ static DefaultOTARequestor gRequestorCore;
static DefaultOTARequestorStorage gRequestorStorage;
static DeviceLayer::DefaultOTARequestorDriver gRequestorUser;
static BDXDownloader gDownloader;
static OTAImageProcessorImpl gImageProcessor;

constexpr uint16_t requestedOtaBlockSize = 1024;
#endif
Expand Down Expand Up @@ -142,10 +141,10 @@ CHIP_ERROR AppTask::Init()
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif
#endif // CONFIG_CHIP_K32W0_REAL_FACTORY_DATA

// QR code will be used with CHIP Tool
AppTask::PrintOnboardingInfo();
#endif

/* HW init leds */
#if !cPWR_UsePowerDownMode
Expand Down Expand Up @@ -245,11 +244,17 @@ void AppTask::InitOTA(intptr_t arg)
gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gRequestorUser.SetMaxDownloadBlockSize(requestedOtaBlockSize);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
gImageProcessor.SetOTADownloader(&gDownloader);
auto & imageProcessor = OTAImageProcessorImpl::GetDefaultInstance();
gRequestorUser.Init(&gRequestorCore, &imageProcessor);
CHIP_ERROR err = imageProcessor.Init(&gDownloader);
if (err != CHIP_NO_ERROR)
{
K32W_LOG("Image processor init failed");
assert(err == CHIP_NO_ERROR);
}

// Connect the gDownloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gDownloader.SetImageProcessorDelegate(&imageProcessor);
// Initialize and interconnect the Requestor and Image Processor objects -- END
}
#endif
Expand Down
41 changes: 29 additions & 12 deletions examples/lighting-app/nxp/k32w/k32w0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ 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.9](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_9_K32W061DK6.zip).
[K32W061DK6 SDK 2.6.10](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_10_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_9_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ export NXP_K32W0_SDK_ROOT=/home/user/Desktop/SDK_2_6_10_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ source ./scripts/activate.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/lighting-app/nxp/k32w/k32w0
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-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"
Expand All @@ -217,7 +217,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.9](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_9_K32W041AMDK6.zip).
[K32W041AMDK6 SDK 2.6.10](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_10_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 Down Expand Up @@ -502,10 +502,33 @@ Build the Linux OTA provider application:
user@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/ota-provider-app chip_config_network_layer_ble=false
```

Build OTA image and start the OTA Provider Application:
Build Linux chip-tool:

```
user@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/chip-tool out/chip-tool-app
```

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|`

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).

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`

Start the OTA Provider Application:

```
user@computer1:~/connectedhomeip$ : ./src/app/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 1 -vs "1.0" -da sha256 chip-k32w0x-light-example.bin chip-k32w0x-light-example.ota
user@computer1:~/connectedhomeip$ : rm -rf /tmp/chip_*
user@computer1:~/connectedhomeip$ : ./out/ota-provider-app/chip-ota-provider-app -f chip-k32w0x-light-example.ota
```
Expand All @@ -517,12 +540,6 @@ 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:

```
user@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/chip-tool out/chip-tool-app
```

Provision the OTA provider application and assign node id _1_. Also, grant ACL
entries to allow OTA requestors:

Expand All @@ -535,7 +552,7 @@ user@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool accesscontrol
Provision the device and assign node id _2_:

```
user@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool pairing ble-thread 2 hex:<operationalDataset> 20202021 3840
user@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool pairing ble-thread 2 hex:<operationalDataset> 20202021 3840
```

Start the OTA process:
Expand Down
17 changes: 11 additions & 6 deletions examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

/* OTA related includes */
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
#include "OTAImageProcessorImpl.h"
#include "OtaSupport.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <src/platform/nxp/k32w/common/OTAImageProcessorImpl.h>
#endif

#include "Keyboard.h"
Expand Down Expand Up @@ -105,7 +105,6 @@ static DefaultOTARequestor gRequestorCore;
static DefaultOTARequestorStorage gRequestorStorage;
static DeviceLayer::DefaultOTARequestorDriver gRequestorUser;
static BDXDownloader gDownloader;
static OTAImageProcessorImpl gImageProcessor;

constexpr uint16_t requestedOtaBlockSize = 1024;
#endif
Expand Down Expand Up @@ -147,10 +146,10 @@ CHIP_ERROR AppTask::Init()
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif
#endif // CONFIG_CHIP_K32W0_REAL_FACTORY_DATA

// QR code will be used with CHIP Tool
AppTask::PrintOnboardingInfo();
#endif

/* HW init leds */
LED_Init();
Expand Down Expand Up @@ -254,11 +253,17 @@ void AppTask::InitOTA(intptr_t arg)
gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gRequestorUser.SetMaxDownloadBlockSize(requestedOtaBlockSize);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
gImageProcessor.SetOTADownloader(&gDownloader);
auto & imageProcessor = OTAImageProcessorImpl::GetDefaultInstance();
gRequestorUser.Init(&gRequestorCore, &imageProcessor);
CHIP_ERROR err = imageProcessor.Init(&gDownloader);
if (err != CHIP_NO_ERROR)
{
K32W_LOG("Image processor init failed");
assert(err == CHIP_NO_ERROR);
}

// Connect the gDownloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gDownloader.SetImageProcessorDelegate(&imageProcessor);
// Initialize and interconnect the Requestor and Image Processor objects -- END
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions examples/lock-app/nxp/k32w/k32w0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ 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.9](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_9_K32W061DK6.zip).
[K32W061DK6 SDK 2.6.10](https://cache.nxp.com/lgfiles/bsps/SDK_2_6_10_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_9_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ export NXP_K32W0_SDK_ROOT=/home/user/Desktop/SDK_2_6_10_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/lock-app/nxp/k32w/k32w0
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ CHIP_ERROR AppTask::Init()
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif
#endif // CONFIG_CHIP_K32W0_REAL_FACTORY_DATA

// QR code will be used with CHIP Tool
AppTask::PrintOnboardingInfo();
#endif

/* HW init leds */
#if !cPWR_UsePowerDownMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ SECTIONS
. = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */
} > RAM0

/* BSS section for unretained contents */
.bss_discard (NOLOAD) : ALIGN(4)
{
*(.discard.bss.pdm)

. = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */
} > RAM0

/* DEFAULT NOINIT SECTION */
.noinit (NOLOAD): ALIGN(4)
{
Expand Down
Loading

0 comments on commit 1251216

Please sign in to comment.