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.9 platform updates #24691

Merged
merged 19 commits into from
Feb 9, 2023

Conversation

andrei-menzopol
Copy link
Contributor

@andrei-menzopol andrei-menzopol commented Jan 27, 2023

This PR includes K32W0 platform updates for SDK 2.6.9

  • Enable hardware SHA256 usage
  • Enable OTA usage of AES through SecLib
  • Fix compile issue when chip_enable_ble=false
  • Enable build time option for FRO32K enablement
  • Add instructions to disable logging for low power
  • Update contact sensor
  • Add correct commissioning flow flag
  • Early init for OT Settings
  • Fix onboarding info call
  • Fix BLE advertising interval
  • Set BLE own address type to random
  • Add spake2p verifier option
  • add code to generate, store and return Unique ID
  • Fix python script and add code on embedded to read hash and data length, calculate and compare hashes
  • Add support for custom factory data provider
  • Add custom factory data provider for lock/contact
  • Add support for rotating device ID
  • Format GATT database config
  • Simplify fetching next OTA block
  • Support new ram buffer modifications
  • Fix NotifyUpdateApplied
  • Low power updates
  • Remove tinycrypt from common stack
  • Add tinycrypt on k32w0 platform
  • Add NXP-Ultrafast-P256 on k32w0 platform
  • Enable PDM encryption
  • Update RamStorage API
  • K32W0 build updates
  • etc

Also I moved CHIPCryptoPALTinyCrypt.cpp from the common stack since it was more platform specific and didn't belong there.

@pullapprove pullapprove bot requested a review from mrjerryjohns February 7, 2023 02:02
andrei-menzopol and others added 19 commits February 9, 2023 02:08
[K32W0] Enable hardware SHA256 usage

* port/matter/ksdk_mbedtls is now used, which is a lightweight
version of port/ksdk/ksdk_mbedtls that contains only AES/SHA
ALT implementations. Another difference is that all calls are
redirected through SecLib, to protect access to hardware modules
through mutexes.
* Added flag gSecLibUseSha256Alt_d, which enables correct
usage of SecLib switch mechanism between sw/hw SHA256. It
also enables the correct overwrite of mbedtls_sha256_context
structure in sha256_alt.h
* Matter is using lengthy SHA256 operations during
CASE/PASE sessions. If hardware SHA256 is used in these
cases, subsequent calls to SecLib API will switch to
software SHA256. Updated Hash_SHA256_stream:: API to
use software SHA256 explicitly.
* Bypassed mbedtls_entropy_func in both Matter and Openthread
by creating a strong_entropy_func that uses hardware TRNG to
generate a seed. Under ot-nxp, a new file was added: crypto.c,
which overwrites otPlatRandom* API. The main issue with mbedtl_
entropy_func was that it starts a SHA256 process for the accumulator
and another SHA256 process for the final seed. The current SHA256 for
the accumulator is finished at the next mbedtls_entropy_func call.
This could block the hardware SHA256 indefinitely or over a long period
of time (if a SHA256 process is started, but mbedlts_entropy_func is not
called anymore).

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

[K32W0] Enable OTA usage of AES through SecLib

Ota module uses AES ROM API to access the hardware AES
module. Flag gOTA_UseSecLibAes was introduced to redirect
all AES calls through SecLib, which protects AES hardware
against two situations:
 - concurrent access through the AES mutex.
 - ISR interruption through restarting the AES operation if
an interrupt occurred (which means the AES key was overwritten).

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

Fix compile issue when chip_enable_ble=false

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Enable build time option for FRO32K enablement

If a custom board doesn't have a 32KHz crystal fitted, one
can use instead the on chip 32 KHz free running oscillator.
This is less precise than the crystal but allows for recalibration
at certain time intervals, so the drift is reduced. This patch
adds the `use_fro_32k` GN option to the build system. If set to 1,
this will switch the clock source for 32KHz from crystal to FRO.
By default, it is set to 0, so the crystal is used.

Also as part of this patch is documenting the option for the relevant
NXP K32W0 examples i.e. lighting-app, lock-app & contact-sensor-app

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>

[K32W0] Add instructions to disable logging for low power

Logging is enabled by default (chip_logging set to true), but can be
overwritten by setting chip_logging=false in the build arguments.
Additionally, a user can disable/enable logging levels/flavors in
src/platform/nxp/k32w/k32w0/args.gni.

Updated README files for contact-sensor and lock-app to take into
account logging disabling.

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

[K32W0] Fix build errors

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

Fix compilation issue: duplicate definition

vDynStopAll was introduced in FWK.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Fix undefined function reference

ECP256 functions were moved.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Update doc for contact sensor

Contact sensor led change

Doc update

[K32W0] Add correct commissioning flow flag

The default value for onboarding commissioning flow is
standard (0). Updated the applications to set the correct
commissioning flow flag, which is kUserActionRequired (1),
since the user has to press a button for the BLE advertising
to start.

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

k32w0: Use the new API for Save-on-Idle functionality

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

k32w0: Early init for OT Settings

Early initialization for OT Settings is needed in PDM_SAVE_IDLE
context where calibration data callbacks may be called before
OT full initialization.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Fix onboarding info call

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

[K32W0] Fix BLE advertising interval

The fast/slow advertising macros are expressed in units of
0.625ms, so the macro values should be multiplied by the
unit to obtain the actual interval in ms.

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

[K32W0] Set BLE own address type to random

Old implementation was using gBleAddrTypePublic_c (0) as own
address type, which caused the BLE address to always be set
to the value fixed into the Controller by the manufacturer.
Setting own address type to gBleAddrTypeRandom_c (1) should
ensure that a random BLE address is generated at least on
every boot.

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

Updating script/readme to allow to encrypt manufacturing data

Signed-off-by: Gatien Chapon <gatien.chapon@nxp.com>

[K32W0] Add spake2p verifier option

If --spake2p_verifier option is used, the script
will not generate a new verifier using the spake2p
tool. Instead, it will directly encode SPAKE2+ inputs
in the final binary.

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

[k32w0] add code to generate, store and return Unique ID

Update python script that generates the factory data binary to include length and 4byte SHA value for integrity check on embedded

[k32w0] Fix python script and add code on embedded to read hash and data length, calculate and compare hashes

[K32W0] Add support for custom factory data provider

A user can inherit `K32W0FactoryDataProvider` to provide additional
functionality (such as parsing custom factory data fields) that is
customer specific.

Enable usage of custom factory data provider:
* Set both `chip_with_factory_data=1` and `use_custom_factory_provider=1`.
By setting `use_custom_factory_provider`, a flag is set to 1 in order
to select the correct provider at compile time (the default or the custom
one): CHIP_DEVICE_CONFIG_USE_CUSTOM_PROVIDER
* Implement `IsIdInvalid` method to offer a way of checking the validity
of custom IDs.

Added an example of a custom factory data provider that can be used
by any application, alongside with a README with more details.

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

[K32W0] Add custom factory data provider for lock/contact

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

[K32W0] Add support for rotating device ID

Support for C3 characteristic (additional data containing rotating
device ID) can be enabled by setting chip_enable_additional_data_advertising
and chip_enable_rotating_device_id to 1 in the build gn args.

C3 value is computed in EncodeAdditionalDataTlv, each time StartAdvertising
is called. The attribute is registered with the GATT server through
GattServer_RegisterHandlesForReadNotifications. Once a read event is
received, if the handle is equal to the C3 handle, the attribute will
be updated in the GATT database with the latest additional data, then
the application will call GattServer_SendAttributeReadStatus to send
the response to the client.

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

[K32W0] Format GATT database config

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

[K32W0] Simplify fetching next OTA block

Fetching next block is scheduled inside the callback that is
called once room for next block is available. Old implementation
was notifying the AppTask, which notified back the platform to
start fetching a new block.

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

[K32W0] Support new ram buffer modifications

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

[K32W0] Fix NotifyUpdateApplied

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

[K32W0] temporary fix for factory reset delete records

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

low power: fix allow/dissalow app functions

Don't use PWR_PreventEnterLowPower() since it has global effect and
can corrupt the app state when used more than once.

Use PWR_AllowDeviceToSleep() / PWR_DisallowDeviceToSleep()

Signed-off-by: George Stefan <george.stefan@nxp.com>

[K32W0] Fix order of application sections

Invert the order of image signature and factory data sections
in order to avoid unwanted owerwrites.

Also rename pFlash to flash_config.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Keep FRO32K active when gClkUseFro32K is defined

This is just an work-around, future clean solution is to move
vOptimizeConsumption() to custom board files.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Allow redefinition of the sleep/wakeup callbacks

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Refactor factory data generator tool

Redesigned the tool to follow an OOP approach.
The updated tool can be found in the new folder factory_data_generator
and is split into three files:
* generate.py - new version of the old implementation.
* default.py - defines some default classes that describe arguments.
* custom.py - deines custom classes that derive from the default classes.

Added README that offers some tool implementation details.
It also references the manufacturing flow README for tool
usage.
Added docstrings to files/classes to offer additional details.
Removed previous factory data tool.

Add support for the following options:
* Vendor ID
* Product ID
* Certification Declaration
* Vendor Name
* Product Name
* Serial Number
* Manufacturing Date
* Hardware Version
* Hardware Version String
* Unique ID

A new flag is introduced which sets the number of custom provider IDs:
CHIP_DEVICE_CONFIG_CUSTOM_PROVIDER_NUMBER_IDS

Custom factory data providers should now implement SetCustomIds
instead of IsIdInvalid. This method should set the max lengths of
each custom field. The validity check is done in SearchForId and
it's the same for default/custom IDs.

Signed-off-by: Marius Tache <marius.tache@nxp.com>
Signed-off-by: Ethan Tan <ethan.tan@nxp.com>

[K32W0] Update first image run checking

Old version was using a PDM key to check if a new image is applied.
Removed this key and updated the check process to actually check
the software version that is embedded in the binary.

User can overwrite a software version by using chip_software_version
gn arg.

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

[K32W0] Remove app_config.h

[K32W0] Fix factory data start address in docs

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

Rework tickless code to be in sync with SDK examples and add allow/disallow low power in BLE commissioning when FRO32K is used

k32w0: low power: fix state machine

- use new API:
  - remove App_PostCallbackMessage(), call directly dm_lp_processEvent()
  - in dm_switch_init15_4AfterWakeUp() set the correct state: 15.4 inactive, BLE active
  - remove stopM2(), sched_disable() since they are called from dm_lp_preSleep()
  - disabling the scheduler must be done before calling vMMAC_Disable() so it works correctly
  - use otSysEventSignalPending() since we're called form ISR context

- kThreadWarmNotInitializedValue = 1000;  /* 1 ms */
- clean up

Signed-off-by: George Stefan <george.stefan@nxp.com>

[K32W0] Fix compile fail when rotating + factory data are enabled

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

k32w0: include NXP platform generic platform config file

There's a common NXP platform config file that's shared across
all platforms. K32W0 should also include it, especially since
it contains a fix for the max # of retransmissions
(CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS)

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
(cherry picked from commit 0e156a32ee28b7b1202c08da2aa0e975ceb2b0fa)

[K32W0] Update cluster config for lock-app

lock-app is now a Door Lock device type.
Removed OnOff cluster and added DoorLock cluster.
Updated app ZCL callbacks.

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

[K32W0] Call InitOTA after Dnssd is initialized

Previous implementation was using a timer to detect if the
Dnssd intialized event was received, then it initialized the
OTA requestor.
New implementation removes this timer and directly initializes
OTA when the event is received in MatterEventHandler.

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

[K32W0] Add software version logging for contact sensor

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

Remove tinycrypt from common stack

Update openthread and ot-nxp submodules

[K32W0] Add tinycrypt on k32w0 platform

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

[K32W0] Define internal storage variables in linker script

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

[K32W0] Add NXP-Ultrafast-P256 on k32w0 platform

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

[K32W0] Enable PDM encryption

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

[K32W0] Update RamStorage API

* RamStorage is no longer a static class.
* Split K32WConfig and KVS common RAM buffer into five smaller
RAM buffers that are managed by RamStorage instances.
* Decoupled KVS from K32WConfig API. It now uses RamStorage API.
* Moved PDM initialization in PlatformManagerImpl.
* ConfigurationManager deletes the not-retained K32WConfig storages
and KVS storages upon factory resetting.

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

[K32W0] Move RAM storage key in a separate header

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

[K32W0] Simplify RAM storage key usage

Define a RamStorageKey API for key operations that redirects
calls to the corresponding RamStorage instance.

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

[K32W0] Create header file for Ram storage metadata

Add base key IDs and NVM IDs in a separate header file.
Application should be able to overwrite the IDs.

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

[K32W0] Reset state on image authentication failed.

CancelImageUpdate should be called at requestor level to make sure
the state is correctly reset upon:
* image authentication fail.
* process header fail.

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

[K32W0] Remove CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER

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

[K32W0] Fix setting software version in gn arg

Move chip_software_version in application build layer.

The actual software version can be changed in two ways:
* directly by the application by overwriting CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION.
This should be the go-to option for clients.
* by specifying chip_software_version gn arg with a value != 0.
This is mainly used for OTA image generation in automation testing.

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

[K32W0] Consider about new memory map planning reserve more space for Application

[K32W0] Remove connection when ble disconnect

[K32W0] Fix public key casting when using factory data

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

Add ADC read on idle task, add init of ADC for low power and non low power apps, remove BLE call

[K32W0] Enable idle hook for lock app

Set lock-app FreeRTOS configuration to be similar to
lighting-app: enable idle hook and set minimal stack size
to a decent value.

Removed ISR check from button handler, since all keyboard
events are sent from the TMR_Task, so the app is never in ISR
context.

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

[k32w0] add hash id for k32w0 factory data implementation,
move to TLV form (type is hash id, after which comes length then the
actual hash)

[K32W0] remove code that is not needed, move code to app
level, add config when not using fro32k

[K32W0] Add print-memory-usage flag

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

[K32W0] Remove DAC PK when using factory data

When using factory data, DAC certificate parsing and PK are not
needed because the signing function uses only the private key.

This results in a considerable flash usage decrease due to many
mbedtls functions not being used anymore.

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

[K32W0] Update SDK 2.6.9 link in readme files

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

[COMMON] Add CHIPNXPPlatformDefaultConfig.h

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

[K32W0] Fix P256Keypair::Initialize declaration

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

[K32W0] fix "gn gen --check" error when factory data function enabled

[K32W0] Clear advertising flag after starting advertising failure

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

lock-app: regenereate zap files, include cluster-id.h

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

lighting-app: regenerate zap-files

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

[K32W0] Move PDM defines to sdk config file

Some PDM-related flags were placed in openthread config file,
which is not intuitively.
Move them to a general sdk config file.

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

[K32W0] Update CHIPCryptoPALNXPUltrafastP256.cpp

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

[K32W0] Fix lock-app

Fix door-lock cluster id reference and ZclCallbacks function signatures

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

[K32W0] Remove SDK patching

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

[K32W0] Update tinycrypt paths

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

Co-authored-by: Marius Tache marius.tache@nxp.com
Co-authored-by: Doru Gucea doru-cristian.gucea@nxp.com
Co-authored-by: Alex Porosanu alexandru.porosanu@nxp.com
Co-authored-by: Gatien Chapon gatien.chapon@nxp.com
Co-authored-by: George Stefan george.stefan@nxp.com
Co-authored-by: Ethan Tan ethan.tan@nxp.com
Co-authored-by: Mihai Ignat mihai.ignat@nxp.com
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
@github-actions
Copy link

github-actions bot commented Feb 9, 2023

PR #24691: Size comparison from cc0f0d8 to c7604a0

Full report (1 build for cc32xx)
platform target config section cc0f0d8 c7604a0 change % change
cc32xx lock CC3235SF_LAUNCHXL 0 0 0 0.0
(read only) 640233 640233 0 0.0
(read/write) 204084 204084 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197488 197488 0 0.0
.comment 194 194 0 0.0
.data 1476 1476 0 0.0
.debug_abbrev 928439 928439 0 0.0
.debug_aranges 87352 87352 0 0.0
.debug_frame 299840 299840 0 0.0
.debug_info 20194647 20194647 0 0.0
.debug_line 2649781 2649781 0 0.0
.debug_loc 2785870 2785870 0 0.0
.debug_ranges 280720 280720 0 0.0
.debug_str 3001804 3001804 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 105585 105585 0 0.0
.shstrtab 232 232 0 0.0
.stab 204 204 0 0.0
.stabstr 441 441 0 0.0
.stack 2048 2048 0 0.0
.strtab 375840 375840 0 0.0
.symtab 255856 255856 0 0.0
.text 532524 532524 0 0.0

@andy31415 andy31415 merged commit 7d17e47 into project-chip:master Feb 9, 2023
@andrei-menzopol andrei-menzopol deleted the upstream-k32w0-changes branch February 9, 2023 15:04
lpbeliveau-silabs pushed a commit to lpbeliveau-silabs/connectedhomeip that referenced this pull request Feb 13, 2023
* Upstream K32W0 SDK 2.6.9 changes

[K32W0] Enable hardware SHA256 usage

* port/matter/ksdk_mbedtls is now used, which is a lightweight
version of port/ksdk/ksdk_mbedtls that contains only AES/SHA
ALT implementations. Another difference is that all calls are
redirected through SecLib, to protect access to hardware modules
through mutexes.
* Added flag gSecLibUseSha256Alt_d, which enables correct
usage of SecLib switch mechanism between sw/hw SHA256. It
also enables the correct overwrite of mbedtls_sha256_context
structure in sha256_alt.h
* Matter is using lengthy SHA256 operations during
CASE/PASE sessions. If hardware SHA256 is used in these
cases, subsequent calls to SecLib API will switch to
software SHA256. Updated Hash_SHA256_stream:: API to
use software SHA256 explicitly.
* Bypassed mbedtls_entropy_func in both Matter and Openthread
by creating a strong_entropy_func that uses hardware TRNG to
generate a seed. Under ot-nxp, a new file was added: crypto.c,
which overwrites otPlatRandom* API. The main issue with mbedtl_
entropy_func was that it starts a SHA256 process for the accumulator
and another SHA256 process for the final seed. The current SHA256 for
the accumulator is finished at the next mbedtls_entropy_func call.
This could block the hardware SHA256 indefinitely or over a long period
of time (if a SHA256 process is started, but mbedlts_entropy_func is not
called anymore).

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

[K32W0] Enable OTA usage of AES through SecLib

Ota module uses AES ROM API to access the hardware AES
module. Flag gOTA_UseSecLibAes was introduced to redirect
all AES calls through SecLib, which protects AES hardware
against two situations:
 - concurrent access through the AES mutex.
 - ISR interruption through restarting the AES operation if
an interrupt occurred (which means the AES key was overwritten).

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

Fix compile issue when chip_enable_ble=false

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Enable build time option for FRO32K enablement

If a custom board doesn't have a 32KHz crystal fitted, one
can use instead the on chip 32 KHz free running oscillator.
This is less precise than the crystal but allows for recalibration
at certain time intervals, so the drift is reduced. This patch
adds the `use_fro_32k` GN option to the build system. If set to 1,
this will switch the clock source for 32KHz from crystal to FRO.
By default, it is set to 0, so the crystal is used.

Also as part of this patch is documenting the option for the relevant
NXP K32W0 examples i.e. lighting-app, lock-app & contact-sensor-app

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>

[K32W0] Add instructions to disable logging for low power

Logging is enabled by default (chip_logging set to true), but can be
overwritten by setting chip_logging=false in the build arguments.
Additionally, a user can disable/enable logging levels/flavors in
src/platform/nxp/k32w/k32w0/args.gni.

Updated README files for contact-sensor and lock-app to take into
account logging disabling.

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

[K32W0] Fix build errors

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

Fix compilation issue: duplicate definition

vDynStopAll was introduced in FWK.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Fix undefined function reference

ECP256 functions were moved.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Update doc for contact sensor

Contact sensor led change

Doc update

[K32W0] Add correct commissioning flow flag

The default value for onboarding commissioning flow is
standard (0). Updated the applications to set the correct
commissioning flow flag, which is kUserActionRequired (1),
since the user has to press a button for the BLE advertising
to start.

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

k32w0: Use the new API for Save-on-Idle functionality

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

k32w0: Early init for OT Settings

Early initialization for OT Settings is needed in PDM_SAVE_IDLE
context where calibration data callbacks may be called before
OT full initialization.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Fix onboarding info call

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

[K32W0] Fix BLE advertising interval

The fast/slow advertising macros are expressed in units of
0.625ms, so the macro values should be multiplied by the
unit to obtain the actual interval in ms.

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

[K32W0] Set BLE own address type to random

Old implementation was using gBleAddrTypePublic_c (0) as own
address type, which caused the BLE address to always be set
to the value fixed into the Controller by the manufacturer.
Setting own address type to gBleAddrTypeRandom_c (1) should
ensure that a random BLE address is generated at least on
every boot.

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

Updating script/readme to allow to encrypt manufacturing data

Signed-off-by: Gatien Chapon <gatien.chapon@nxp.com>

[K32W0] Add spake2p verifier option

If --spake2p_verifier option is used, the script
will not generate a new verifier using the spake2p
tool. Instead, it will directly encode SPAKE2+ inputs
in the final binary.

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

[k32w0] add code to generate, store and return Unique ID

Update python script that generates the factory data binary to include length and 4byte SHA value for integrity check on embedded

[k32w0] Fix python script and add code on embedded to read hash and data length, calculate and compare hashes

[K32W0] Add support for custom factory data provider

A user can inherit `K32W0FactoryDataProvider` to provide additional
functionality (such as parsing custom factory data fields) that is
customer specific.

Enable usage of custom factory data provider:
* Set both `chip_with_factory_data=1` and `use_custom_factory_provider=1`.
By setting `use_custom_factory_provider`, a flag is set to 1 in order
to select the correct provider at compile time (the default or the custom
one): CHIP_DEVICE_CONFIG_USE_CUSTOM_PROVIDER
* Implement `IsIdInvalid` method to offer a way of checking the validity
of custom IDs.

Added an example of a custom factory data provider that can be used
by any application, alongside with a README with more details.

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

[K32W0] Add custom factory data provider for lock/contact

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

[K32W0] Add support for rotating device ID

Support for C3 characteristic (additional data containing rotating
device ID) can be enabled by setting chip_enable_additional_data_advertising
and chip_enable_rotating_device_id to 1 in the build gn args.

C3 value is computed in EncodeAdditionalDataTlv, each time StartAdvertising
is called. The attribute is registered with the GATT server through
GattServer_RegisterHandlesForReadNotifications. Once a read event is
received, if the handle is equal to the C3 handle, the attribute will
be updated in the GATT database with the latest additional data, then
the application will call GattServer_SendAttributeReadStatus to send
the response to the client.

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

[K32W0] Format GATT database config

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

[K32W0] Simplify fetching next OTA block

Fetching next block is scheduled inside the callback that is
called once room for next block is available. Old implementation
was notifying the AppTask, which notified back the platform to
start fetching a new block.

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

[K32W0] Support new ram buffer modifications

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

[K32W0] Fix NotifyUpdateApplied

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

[K32W0] temporary fix for factory reset delete records

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

low power: fix allow/dissalow app functions

Don't use PWR_PreventEnterLowPower() since it has global effect and
can corrupt the app state when used more than once.

Use PWR_AllowDeviceToSleep() / PWR_DisallowDeviceToSleep()

Signed-off-by: George Stefan <george.stefan@nxp.com>

[K32W0] Fix order of application sections

Invert the order of image signature and factory data sections
in order to avoid unwanted owerwrites.

Also rename pFlash to flash_config.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Keep FRO32K active when gClkUseFro32K is defined

This is just an work-around, future clean solution is to move
vOptimizeConsumption() to custom board files.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Allow redefinition of the sleep/wakeup callbacks

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Refactor factory data generator tool

Redesigned the tool to follow an OOP approach.
The updated tool can be found in the new folder factory_data_generator
and is split into three files:
* generate.py - new version of the old implementation.
* default.py - defines some default classes that describe arguments.
* custom.py - deines custom classes that derive from the default classes.

Added README that offers some tool implementation details.
It also references the manufacturing flow README for tool
usage.
Added docstrings to files/classes to offer additional details.
Removed previous factory data tool.

Add support for the following options:
* Vendor ID
* Product ID
* Certification Declaration
* Vendor Name
* Product Name
* Serial Number
* Manufacturing Date
* Hardware Version
* Hardware Version String
* Unique ID

A new flag is introduced which sets the number of custom provider IDs:
CHIP_DEVICE_CONFIG_CUSTOM_PROVIDER_NUMBER_IDS

Custom factory data providers should now implement SetCustomIds
instead of IsIdInvalid. This method should set the max lengths of
each custom field. The validity check is done in SearchForId and
it's the same for default/custom IDs.

Signed-off-by: Marius Tache <marius.tache@nxp.com>
Signed-off-by: Ethan Tan <ethan.tan@nxp.com>

[K32W0] Update first image run checking

Old version was using a PDM key to check if a new image is applied.
Removed this key and updated the check process to actually check
the software version that is embedded in the binary.

User can overwrite a software version by using chip_software_version
gn arg.

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

[K32W0] Remove app_config.h

[K32W0] Fix factory data start address in docs

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

Rework tickless code to be in sync with SDK examples and add allow/disallow low power in BLE commissioning when FRO32K is used

k32w0: low power: fix state machine

- use new API:
  - remove App_PostCallbackMessage(), call directly dm_lp_processEvent()
  - in dm_switch_init15_4AfterWakeUp() set the correct state: 15.4 inactive, BLE active
  - remove stopM2(), sched_disable() since they are called from dm_lp_preSleep()
  - disabling the scheduler must be done before calling vMMAC_Disable() so it works correctly
  - use otSysEventSignalPending() since we're called form ISR context

- kThreadWarmNotInitializedValue = 1000;  /* 1 ms */
- clean up

Signed-off-by: George Stefan <george.stefan@nxp.com>

[K32W0] Fix compile fail when rotating + factory data are enabled

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

k32w0: include NXP platform generic platform config file

There's a common NXP platform config file that's shared across
all platforms. K32W0 should also include it, especially since
it contains a fix for the max # of retransmissions
(CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS)

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
(cherry picked from commit 0e156a32ee28b7b1202c08da2aa0e975ceb2b0fa)

[K32W0] Update cluster config for lock-app

lock-app is now a Door Lock device type.
Removed OnOff cluster and added DoorLock cluster.
Updated app ZCL callbacks.

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

[K32W0] Call InitOTA after Dnssd is initialized

Previous implementation was using a timer to detect if the
Dnssd intialized event was received, then it initialized the
OTA requestor.
New implementation removes this timer and directly initializes
OTA when the event is received in MatterEventHandler.

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

[K32W0] Add software version logging for contact sensor

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

Remove tinycrypt from common stack

Update openthread and ot-nxp submodules

[K32W0] Add tinycrypt on k32w0 platform

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

[K32W0] Define internal storage variables in linker script

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

[K32W0] Add NXP-Ultrafast-P256 on k32w0 platform

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

[K32W0] Enable PDM encryption

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

[K32W0] Update RamStorage API

* RamStorage is no longer a static class.
* Split K32WConfig and KVS common RAM buffer into five smaller
RAM buffers that are managed by RamStorage instances.
* Decoupled KVS from K32WConfig API. It now uses RamStorage API.
* Moved PDM initialization in PlatformManagerImpl.
* ConfigurationManager deletes the not-retained K32WConfig storages
and KVS storages upon factory resetting.

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

[K32W0] Move RAM storage key in a separate header

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

[K32W0] Simplify RAM storage key usage

Define a RamStorageKey API for key operations that redirects
calls to the corresponding RamStorage instance.

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

[K32W0] Create header file for Ram storage metadata

Add base key IDs and NVM IDs in a separate header file.
Application should be able to overwrite the IDs.

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

[K32W0] Reset state on image authentication failed.

CancelImageUpdate should be called at requestor level to make sure
the state is correctly reset upon:
* image authentication fail.
* process header fail.

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

[K32W0] Remove CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER

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

[K32W0] Fix setting software version in gn arg

Move chip_software_version in application build layer.

The actual software version can be changed in two ways:
* directly by the application by overwriting CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION.
This should be the go-to option for clients.
* by specifying chip_software_version gn arg with a value != 0.
This is mainly used for OTA image generation in automation testing.

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

[K32W0] Consider about new memory map planning reserve more space for Application

[K32W0] Remove connection when ble disconnect

[K32W0] Fix public key casting when using factory data

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

Add ADC read on idle task, add init of ADC for low power and non low power apps, remove BLE call

[K32W0] Enable idle hook for lock app

Set lock-app FreeRTOS configuration to be similar to
lighting-app: enable idle hook and set minimal stack size
to a decent value.

Removed ISR check from button handler, since all keyboard
events are sent from the TMR_Task, so the app is never in ISR
context.

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

[k32w0] add hash id for k32w0 factory data implementation,
move to TLV form (type is hash id, after which comes length then the
actual hash)

[K32W0] remove code that is not needed, move code to app
level, add config when not using fro32k

[K32W0] Add print-memory-usage flag

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

[K32W0] Remove DAC PK when using factory data

When using factory data, DAC certificate parsing and PK are not
needed because the signing function uses only the private key.

This results in a considerable flash usage decrease due to many
mbedtls functions not being used anymore.

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

[K32W0] Update SDK 2.6.9 link in readme files

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

[COMMON] Add CHIPNXPPlatformDefaultConfig.h

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

[K32W0] Fix P256Keypair::Initialize declaration

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

[K32W0] fix "gn gen --check" error when factory data function enabled

[K32W0] Clear advertising flag after starting advertising failure

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

lock-app: regenereate zap files, include cluster-id.h

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

lighting-app: regenerate zap-files

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

[K32W0] Move PDM defines to sdk config file

Some PDM-related flags were placed in openthread config file,
which is not intuitively.
Move them to a general sdk config file.

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

[K32W0] Update CHIPCryptoPALNXPUltrafastP256.cpp

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

[K32W0] Fix lock-app

Fix door-lock cluster id reference and ZclCallbacks function signatures

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

[K32W0] Remove SDK patching

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

[K32W0] Update tinycrypt paths

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

Co-authored-by: Marius Tache marius.tache@nxp.com
Co-authored-by: Doru Gucea doru-cristian.gucea@nxp.com
Co-authored-by: Alex Porosanu alexandru.porosanu@nxp.com
Co-authored-by: Gatien Chapon gatien.chapon@nxp.com
Co-authored-by: George Stefan george.stefan@nxp.com
Co-authored-by: Ethan Tan ethan.tan@nxp.com
Co-authored-by: Mihai Ignat mihai.ignat@nxp.com

* Update ot-nxp submodule

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

* [K32W0] Update build

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

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Restyled by autopep8

* Restyled by isort

* Fix misspell

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

* Fix k32w builder

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

* Remove nxp/zap-generated files

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

* Restyled by gn

* Fix ZAP templates generation

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

* Fix readme files

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

* Fix lints

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

* Increase k32w0 build timeout

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

* Fix DoorLock attribute

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

* Add orphan sphinx tag

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

---------

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Co-authored-by: Restyled.io <commits@restyled.io>
lecndav pushed a commit to lecndav/connectedhomeip that referenced this pull request Mar 22, 2023
* Upstream K32W0 SDK 2.6.9 changes

[K32W0] Enable hardware SHA256 usage

* port/matter/ksdk_mbedtls is now used, which is a lightweight
version of port/ksdk/ksdk_mbedtls that contains only AES/SHA
ALT implementations. Another difference is that all calls are
redirected through SecLib, to protect access to hardware modules
through mutexes.
* Added flag gSecLibUseSha256Alt_d, which enables correct
usage of SecLib switch mechanism between sw/hw SHA256. It
also enables the correct overwrite of mbedtls_sha256_context
structure in sha256_alt.h
* Matter is using lengthy SHA256 operations during
CASE/PASE sessions. If hardware SHA256 is used in these
cases, subsequent calls to SecLib API will switch to
software SHA256. Updated Hash_SHA256_stream:: API to
use software SHA256 explicitly.
* Bypassed mbedtls_entropy_func in both Matter and Openthread
by creating a strong_entropy_func that uses hardware TRNG to
generate a seed. Under ot-nxp, a new file was added: crypto.c,
which overwrites otPlatRandom* API. The main issue with mbedtl_
entropy_func was that it starts a SHA256 process for the accumulator
and another SHA256 process for the final seed. The current SHA256 for
the accumulator is finished at the next mbedtls_entropy_func call.
This could block the hardware SHA256 indefinitely or over a long period
of time (if a SHA256 process is started, but mbedlts_entropy_func is not
called anymore).

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

[K32W0] Enable OTA usage of AES through SecLib

Ota module uses AES ROM API to access the hardware AES
module. Flag gOTA_UseSecLibAes was introduced to redirect
all AES calls through SecLib, which protects AES hardware
against two situations:
 - concurrent access through the AES mutex.
 - ISR interruption through restarting the AES operation if
an interrupt occurred (which means the AES key was overwritten).

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

Fix compile issue when chip_enable_ble=false

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Enable build time option for FRO32K enablement

If a custom board doesn't have a 32KHz crystal fitted, one
can use instead the on chip 32 KHz free running oscillator.
This is less precise than the crystal but allows for recalibration
at certain time intervals, so the drift is reduced. This patch
adds the `use_fro_32k` GN option to the build system. If set to 1,
this will switch the clock source for 32KHz from crystal to FRO.
By default, it is set to 0, so the crystal is used.

Also as part of this patch is documenting the option for the relevant
NXP K32W0 examples i.e. lighting-app, lock-app & contact-sensor-app

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>

[K32W0] Add instructions to disable logging for low power

Logging is enabled by default (chip_logging set to true), but can be
overwritten by setting chip_logging=false in the build arguments.
Additionally, a user can disable/enable logging levels/flavors in
src/platform/nxp/k32w/k32w0/args.gni.

Updated README files for contact-sensor and lock-app to take into
account logging disabling.

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

[K32W0] Fix build errors

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

Fix compilation issue: duplicate definition

vDynStopAll was introduced in FWK.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Fix undefined function reference

ECP256 functions were moved.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Update doc for contact sensor

Contact sensor led change

Doc update

[K32W0] Add correct commissioning flow flag

The default value for onboarding commissioning flow is
standard (0). Updated the applications to set the correct
commissioning flow flag, which is kUserActionRequired (1),
since the user has to press a button for the BLE advertising
to start.

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

k32w0: Use the new API for Save-on-Idle functionality

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

k32w0: Early init for OT Settings

Early initialization for OT Settings is needed in PDM_SAVE_IDLE
context where calibration data callbacks may be called before
OT full initialization.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Fix onboarding info call

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

[K32W0] Fix BLE advertising interval

The fast/slow advertising macros are expressed in units of
0.625ms, so the macro values should be multiplied by the
unit to obtain the actual interval in ms.

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

[K32W0] Set BLE own address type to random

Old implementation was using gBleAddrTypePublic_c (0) as own
address type, which caused the BLE address to always be set
to the value fixed into the Controller by the manufacturer.
Setting own address type to gBleAddrTypeRandom_c (1) should
ensure that a random BLE address is generated at least on
every boot.

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

Updating script/readme to allow to encrypt manufacturing data

Signed-off-by: Gatien Chapon <gatien.chapon@nxp.com>

[K32W0] Add spake2p verifier option

If --spake2p_verifier option is used, the script
will not generate a new verifier using the spake2p
tool. Instead, it will directly encode SPAKE2+ inputs
in the final binary.

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

[k32w0] add code to generate, store and return Unique ID

Update python script that generates the factory data binary to include length and 4byte SHA value for integrity check on embedded

[k32w0] Fix python script and add code on embedded to read hash and data length, calculate and compare hashes

[K32W0] Add support for custom factory data provider

A user can inherit `K32W0FactoryDataProvider` to provide additional
functionality (such as parsing custom factory data fields) that is
customer specific.

Enable usage of custom factory data provider:
* Set both `chip_with_factory_data=1` and `use_custom_factory_provider=1`.
By setting `use_custom_factory_provider`, a flag is set to 1 in order
to select the correct provider at compile time (the default or the custom
one): CHIP_DEVICE_CONFIG_USE_CUSTOM_PROVIDER
* Implement `IsIdInvalid` method to offer a way of checking the validity
of custom IDs.

Added an example of a custom factory data provider that can be used
by any application, alongside with a README with more details.

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

[K32W0] Add custom factory data provider for lock/contact

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

[K32W0] Add support for rotating device ID

Support for C3 characteristic (additional data containing rotating
device ID) can be enabled by setting chip_enable_additional_data_advertising
and chip_enable_rotating_device_id to 1 in the build gn args.

C3 value is computed in EncodeAdditionalDataTlv, each time StartAdvertising
is called. The attribute is registered with the GATT server through
GattServer_RegisterHandlesForReadNotifications. Once a read event is
received, if the handle is equal to the C3 handle, the attribute will
be updated in the GATT database with the latest additional data, then
the application will call GattServer_SendAttributeReadStatus to send
the response to the client.

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

[K32W0] Format GATT database config

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

[K32W0] Simplify fetching next OTA block

Fetching next block is scheduled inside the callback that is
called once room for next block is available. Old implementation
was notifying the AppTask, which notified back the platform to
start fetching a new block.

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

[K32W0] Support new ram buffer modifications

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

[K32W0] Fix NotifyUpdateApplied

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

[K32W0] temporary fix for factory reset delete records

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

low power: fix allow/dissalow app functions

Don't use PWR_PreventEnterLowPower() since it has global effect and
can corrupt the app state when used more than once.

Use PWR_AllowDeviceToSleep() / PWR_DisallowDeviceToSleep()

Signed-off-by: George Stefan <george.stefan@nxp.com>

[K32W0] Fix order of application sections

Invert the order of image signature and factory data sections
in order to avoid unwanted owerwrites.

Also rename pFlash to flash_config.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Keep FRO32K active when gClkUseFro32K is defined

This is just an work-around, future clean solution is to move
vOptimizeConsumption() to custom board files.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Allow redefinition of the sleep/wakeup callbacks

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

[K32W0] Refactor factory data generator tool

Redesigned the tool to follow an OOP approach.
The updated tool can be found in the new folder factory_data_generator
and is split into three files:
* generate.py - new version of the old implementation.
* default.py - defines some default classes that describe arguments.
* custom.py - deines custom classes that derive from the default classes.

Added README that offers some tool implementation details.
It also references the manufacturing flow README for tool
usage.
Added docstrings to files/classes to offer additional details.
Removed previous factory data tool.

Add support for the following options:
* Vendor ID
* Product ID
* Certification Declaration
* Vendor Name
* Product Name
* Serial Number
* Manufacturing Date
* Hardware Version
* Hardware Version String
* Unique ID

A new flag is introduced which sets the number of custom provider IDs:
CHIP_DEVICE_CONFIG_CUSTOM_PROVIDER_NUMBER_IDS

Custom factory data providers should now implement SetCustomIds
instead of IsIdInvalid. This method should set the max lengths of
each custom field. The validity check is done in SearchForId and
it's the same for default/custom IDs.

Signed-off-by: Marius Tache <marius.tache@nxp.com>
Signed-off-by: Ethan Tan <ethan.tan@nxp.com>

[K32W0] Update first image run checking

Old version was using a PDM key to check if a new image is applied.
Removed this key and updated the check process to actually check
the software version that is embedded in the binary.

User can overwrite a software version by using chip_software_version
gn arg.

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

[K32W0] Remove app_config.h

[K32W0] Fix factory data start address in docs

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

Rework tickless code to be in sync with SDK examples and add allow/disallow low power in BLE commissioning when FRO32K is used

k32w0: low power: fix state machine

- use new API:
  - remove App_PostCallbackMessage(), call directly dm_lp_processEvent()
  - in dm_switch_init15_4AfterWakeUp() set the correct state: 15.4 inactive, BLE active
  - remove stopM2(), sched_disable() since they are called from dm_lp_preSleep()
  - disabling the scheduler must be done before calling vMMAC_Disable() so it works correctly
  - use otSysEventSignalPending() since we're called form ISR context

- kThreadWarmNotInitializedValue = 1000;  /* 1 ms */
- clean up

Signed-off-by: George Stefan <george.stefan@nxp.com>

[K32W0] Fix compile fail when rotating + factory data are enabled

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

k32w0: include NXP platform generic platform config file

There's a common NXP platform config file that's shared across
all platforms. K32W0 should also include it, especially since
it contains a fix for the max # of retransmissions
(CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS)

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
(cherry picked from commit 0e156a32ee28b7b1202c08da2aa0e975ceb2b0fa)

[K32W0] Update cluster config for lock-app

lock-app is now a Door Lock device type.
Removed OnOff cluster and added DoorLock cluster.
Updated app ZCL callbacks.

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

[K32W0] Call InitOTA after Dnssd is initialized

Previous implementation was using a timer to detect if the
Dnssd intialized event was received, then it initialized the
OTA requestor.
New implementation removes this timer and directly initializes
OTA when the event is received in MatterEventHandler.

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

[K32W0] Add software version logging for contact sensor

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

Remove tinycrypt from common stack

Update openthread and ot-nxp submodules

[K32W0] Add tinycrypt on k32w0 platform

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

[K32W0] Define internal storage variables in linker script

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

[K32W0] Add NXP-Ultrafast-P256 on k32w0 platform

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

[K32W0] Enable PDM encryption

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

[K32W0] Update RamStorage API

* RamStorage is no longer a static class.
* Split K32WConfig and KVS common RAM buffer into five smaller
RAM buffers that are managed by RamStorage instances.
* Decoupled KVS from K32WConfig API. It now uses RamStorage API.
* Moved PDM initialization in PlatformManagerImpl.
* ConfigurationManager deletes the not-retained K32WConfig storages
and KVS storages upon factory resetting.

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

[K32W0] Move RAM storage key in a separate header

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

[K32W0] Simplify RAM storage key usage

Define a RamStorageKey API for key operations that redirects
calls to the corresponding RamStorage instance.

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

[K32W0] Create header file for Ram storage metadata

Add base key IDs and NVM IDs in a separate header file.
Application should be able to overwrite the IDs.

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

[K32W0] Reset state on image authentication failed.

CancelImageUpdate should be called at requestor level to make sure
the state is correctly reset upon:
* image authentication fail.
* process header fail.

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

[K32W0] Remove CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER

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

[K32W0] Fix setting software version in gn arg

Move chip_software_version in application build layer.

The actual software version can be changed in two ways:
* directly by the application by overwriting CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION.
This should be the go-to option for clients.
* by specifying chip_software_version gn arg with a value != 0.
This is mainly used for OTA image generation in automation testing.

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

[K32W0] Consider about new memory map planning reserve more space for Application

[K32W0] Remove connection when ble disconnect

[K32W0] Fix public key casting when using factory data

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

Add ADC read on idle task, add init of ADC for low power and non low power apps, remove BLE call

[K32W0] Enable idle hook for lock app

Set lock-app FreeRTOS configuration to be similar to
lighting-app: enable idle hook and set minimal stack size
to a decent value.

Removed ISR check from button handler, since all keyboard
events are sent from the TMR_Task, so the app is never in ISR
context.

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

[k32w0] add hash id for k32w0 factory data implementation,
move to TLV form (type is hash id, after which comes length then the
actual hash)

[K32W0] remove code that is not needed, move code to app
level, add config when not using fro32k

[K32W0] Add print-memory-usage flag

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

[K32W0] Remove DAC PK when using factory data

When using factory data, DAC certificate parsing and PK are not
needed because the signing function uses only the private key.

This results in a considerable flash usage decrease due to many
mbedtls functions not being used anymore.

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

[K32W0] Update SDK 2.6.9 link in readme files

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

[COMMON] Add CHIPNXPPlatformDefaultConfig.h

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

[K32W0] Fix P256Keypair::Initialize declaration

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

[K32W0] fix "gn gen --check" error when factory data function enabled

[K32W0] Clear advertising flag after starting advertising failure

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

lock-app: regenereate zap files, include cluster-id.h

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

lighting-app: regenerate zap-files

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

[K32W0] Move PDM defines to sdk config file

Some PDM-related flags were placed in openthread config file,
which is not intuitively.
Move them to a general sdk config file.

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

[K32W0] Update CHIPCryptoPALNXPUltrafastP256.cpp

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

[K32W0] Fix lock-app

Fix door-lock cluster id reference and ZclCallbacks function signatures

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

[K32W0] Remove SDK patching

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

[K32W0] Update tinycrypt paths

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

Co-authored-by: Marius Tache marius.tache@nxp.com
Co-authored-by: Doru Gucea doru-cristian.gucea@nxp.com
Co-authored-by: Alex Porosanu alexandru.porosanu@nxp.com
Co-authored-by: Gatien Chapon gatien.chapon@nxp.com
Co-authored-by: George Stefan george.stefan@nxp.com
Co-authored-by: Ethan Tan ethan.tan@nxp.com
Co-authored-by: Mihai Ignat mihai.ignat@nxp.com

* Update ot-nxp submodule

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

* [K32W0] Update build

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

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Restyled by autopep8

* Restyled by isort

* Fix misspell

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

* Fix k32w builder

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

* Remove nxp/zap-generated files

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

* Restyled by gn

* Fix ZAP templates generation

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

* Fix readme files

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

* Fix lints

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

* Increase k32w0 build timeout

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

* Fix DoorLock attribute

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

* Add orphan sphinx tag

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

---------

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants