Skip to content

Commit

Permalink
[K32W0] SDK 2.6.11 fixes & features (#26827)
Browse files Browse the repository at this point in the history
* [K32W0] Sync with SDK NCCL change

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

* [K32W0] Add a flag chip_with_pdm_encryption to disable PDM encryption

* [K32W0] Fix name for OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_DIRECT

* [K32W0] Fix reboot reason bug

* [K32W0] Change date type for rebootCause, uint8_t is enough

* [K32W0] Add stop advertising retry

If stop advertising fails (timeout on event wait), then
rearm the timer as fast as possible to retry.
Once stop advertising is successful, slow advertising can start.

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

* [K32W0] Add ExitAction to OTATlvProcessor API

An OTA TLV processor should have the option of executing an action
when before a new processor is selected. This is called an exit
action. It should be useful in the context of transferring multiple
OTA images in external flash.

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

* [K32W0] Update OTA SDK usage

* Application and bootloader processors are now the same, referred to as
firmware processor.
* Application can now register callbacks for descriptor
processing.
* When using default processors, the OTA flags gOTAUseCustomOtaEntry
and gOTAAllowCustomStartAddress are defined and set to 1.

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

* [K32W0] Add JSON support for custom TLVs

*A user can now specify a custom TLV format (tag, descriptor and path)
by following the design of the ota_payload.schema. Option `--json` should
be used to specify the JSON file path.
* Add SSBL payload generation.

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

* [K32W0] Call ExitAction from TLV processor when all block has been consumed - Move code from ApplyAction to ExitAction method

* [K32W0] Update usage of new OTA SDK APIs

* [K32W0] Set custom OTA entry flags

Custom OTA entry structure will be saved at the top of external flash by default.
Fix heap start address. It should start after the stack size is subtracted from the top.

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

* [K32W0] Access OTA entry at Init and check OTA status

* [K32W0] Update OTA tool to support SSBL

Add a few examples to generate:
* application update image
* factory data update image
* SSBL update image
* app + SSBL + factory data update image
* maximum number of custom OTA entries image

Add README for K32W OTA.

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

* [K32W0] Add example for max entries testing

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

* [K32W0] Split default processors options

* chip_enable_ota_firmware_processor enables the firmware (App/SSBL)
processor. Enabled by default.
* chip_enable_ota_factory_data_processor enables the factory data
processor. Disabled by default.

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

* [K32W0] Update README SSBL/PSECT sections

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

* [K32W0] Bring README files up to date

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

* [K32W0] Fix chip_crypto_flavour name

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

* [K32W0] Fix readmes for k32w0 apps

* [K32W0] Update SecLib path in SDK build file

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

* [K32W0] Fix typo in README files regarding OTA image tool

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

* [K32W0] Extend factory data restore mechanism

The default restore mechanism is implemented as a weak function:
`FactoryDataDefaultRestoreMechanism`. It is registered in
`K32W0FactoryDataProvider::Init`, before factory data validation,
and it can be overwritten at application level.

Application can register additional restore mechanisms using the API:
`K32W0FactoryDataProvider::RegisterRestoreMechanism`.

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

* [K32W0] Improve rotating device id

Add README section related to rotating device id.
If unique id is not found in factory data, use the
default one.

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

* [K32W0] Fix error status for rotating device id getter

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

* [K32W0] Add retry mechanism when OTA is aborted

Upon an aborted transfer, the OTA will retry a query on the
backed up provider if CONFIG_CHIP_K32W0_OTA_ABORT_HOOK is set.

The retry mechanism is disabled by default.

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

* [K32W0] Add ota_custom_entry_address option

ota_custom_entry_address specifies at which address in external flash
the OTA custom entry is saved during OTA. By default, it is set to the
end of the PDM area: 0x000C1000.

Add internal/external flash description in linker.

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

* [K32W0] Revert all applied actions upon error

AbortAction for all selected OTA TLV processors will be called
if any processor fails to apply its action. This is a safety
mechanism to avoid having incompatible apps/data caused by partial
updates (e.g. incompatibility between SSBL and app).

Other changes:
* Clean factory data RAM buffer

* Increase reset resilience during OTA

During OTA, if factory data is updated, it is firstly backed up
in a PDM entry with id kNvmId_FactoryDataBackup. This entry should
be deleted only if the OTA entry state is otaApplied, which means
the device reset happened as expected.

If OTA entry state is not otaApplied, it means the reset was caused
by a different factor (e.g. power loss etc.) and the factory data
should be restored from the PDM (for the default registered mechanism).

* AbortAction should delete PDM id for factory data backup

* Add reset state for OTATlvProcessor base class

Derived classes should call OTATlvProcessor::ClearInternal() whenever
they want to reset their state.

* Update abort action for firmware processor

OTA_ResetCurrentEepromAddress should be called before setting
the offset to 0 through OTA_SetStartEepromOffset. Otherwise,
a check in OTA_SetStartEepromOffset will fail and the state is
not reset correctly.

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

* [K32W0] Add SPIFI_DUAL_MODE_SUPPORT info in README files

For K32W041AM, the multi-image SSBL must also be compiled with
SPIFI_DUAL_MODE_SUPPORT=1.

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

* [K32W0] Enclose CheckOtaEntry in OTA flag

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

* [K32W0] Enclose factory data backup usage in corresponding flag

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

* [K32W0] Update SDK in README files

Fix minor issue with image partitions information.

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

* [K32W0] Fix DiagnosticDataProvider memory leak

GetNetworkInterfaces returns some dynamically allocated data,
which is supposed to be freed upon calling ReleaseNetworkInterfaces.

Our platform implementation was using the default implementation of
ReleaseNetworkInterfaces (which does nothing). This is an obvious memory leak,
since subsequent calls to GetNetworkInterfaces dynamically allocated data that
was never freed.

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

* [K32W0] Automate output binary signing

Add BUILD.gn changes to call a python script postbuild
that signs the output binary.

Add signing python script.

Update readme files.

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>

* [K32W0] Fix chip_crypto_flavor typo

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

* [K32W0] Bump ot-nxp to latest

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

* [K32W0] Fix OTA generation tool

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

* [K32W0] Bump ot-nxp to latest

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

* [K32W0] Sync scripts and generated data with development

Updated manufacturing flow.

Signed-off-by: Mihai Ignat <mihai.ignat@nxp.com>
Signed-off-by: Marius Tache <marius.tache@nxp.com>

* [K32W0] Bump ot-nxp to latest

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

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Restyled by shellharden

* Restyled by shfmt

* Restyled by autopep8

* Restyled by isort

* [K32W0] Fix spell check

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

* [K32W0] Remove some binary examples (not used)

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

* [K32W0] Fix some lint errors

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

* [K32W0] Update workflow example yaml to latest

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

* Restyled by prettier-markdown

* [K32W0] Fix script issues

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

* Restyled by autopep8

* Restyled by isort

* [K32W0] Add PDM ID base value for apps

Applications should use kNvmId_ApplicationBase alongside an
offset to generate their own PDM IDs.

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

* Restyled by clang-format

---------

Signed-off-by: Marius Tache <marius.tache@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Mihai Ignat <mihai.ignat@nxp.com>
Co-authored-by: tanyue518 <ethan.tan@nxp.com>
Co-authored-by: Martin Cuvelier <martin.cuvelier@nxp.com>
Co-authored-by: Mihai Ignat <mihai.ignat@nxp.com>
Co-authored-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
6 people authored and pull[bot] committed Oct 24, 2023
1 parent 1400618 commit 1605154
Show file tree
Hide file tree
Showing 64 changed files with 1,833 additions and 638 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples-k32w.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
if: github.actor != 'restyled-io[bot]'

container:
image: connectedhomeip/chip-build-k32w:0.7.3
image: connectedhomeip/chip-build-k32w:0.7.14
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 @@ -99,6 +99,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 @@ -114,6 +123,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 @@ -129,10 +172,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

0 comments on commit 1605154

Please sign in to comment.