Skip to content

Commit

Permalink
[nrfconnect] Added factory data accessor implementation. (#19614)
Browse files Browse the repository at this point in the history
* [nrfconnect] Added factory data accessor implementation.

The nrfconnect uses test values defined in the header
files for the factory data purpose. The data belonging
to factory data should be read from dedicated location
in flash memory.

* Added FactoryDataProvider class that overrides API
to get factory data elements.
* Added FactoryDataParser module that read factory data
partition from flash and parses cbor format to get raw
data.

* Fixed some nrfconnect builds

* Addressed review comments

* Address more review comments

In particular, don't continue booting an app if mandatory
factory data fields are missing.

* Restyled by whitespace

* Restyled by clang-format

Co-authored-by: Damian Krolik <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Arkadiusz Bałys <[email protected]>
  • Loading branch information
4 people authored and pull[bot] committed Aug 9, 2022
1 parent 2b8b008 commit 2468133
Show file tree
Hide file tree
Showing 44 changed files with 1,020 additions and 104 deletions.
7 changes: 7 additions & 0 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ chip_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_LOG_LE
chip_gn_arg_bool ("chip_automation_logging" "false")
chip_gn_arg_bool ("chip_malloc_sys_heap" CONFIG_CHIP_MALLOC_SYS_HEAP)

if (CONFIG_CHIP_FACTORY_DATA)
chip_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false")
chip_gn_arg_bool ("chip_enable_factory_data" "true")
elseif (CONFIG_CHIP_FACTORY_DATA_CUSTOM_BACKEND)
chip_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false")
endif()

if (CONFIG_CHIP_ROTATING_DEVICE_ID)
chip_gn_arg_bool("chip_enable_rotating_device_id" "true")
chip_gn_arg_bool("chip_enable_additional_data_advertising" "true")
Expand Down
16 changes: 16 additions & 0 deletions config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ config CHIP_DEBUG_SYMBOLS
help
Build the application with debug symbols.

config CHIP_FACTORY_DATA
bool "Enable Factory Data support"
select ZCBOR
help
Enables support for reading factory data from flash memory partition.
It requires factory_data partition to exist in the partition manager
configuration file pm_static.yml.

config CHIP_FACTORY_DATA_CUSTOM_BACKEND
bool "Enable Factory Data custom backend"
depends on !CHIP_FACTORY_DATA
help
Enables user custom factory data implementation. It cannot be used
with the CHIP_FACTORY_DATA that enabled default nRF Connect factory data
implementation.

config CHIP_FACTORY_DATA_BUILD
bool "Enable Factory Data build"
default n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@ mcuboot_pad:
size: 0x200
app:
address: 0x7200
size: 0xf4e00
size: 0xf3e00
mcuboot_primary:
orig_span: &id001
- mcuboot_pad
- app
span: *id001
address: 0x7000
size: 0xf5000
size: 0xf4000
region: flash_primary
mcuboot_primary_app:
orig_span: &id002
- app
span: *id002
address: 0x7200
size: 0xf4e00
size: 0xf3e00
factory_data:
address: 0xfb000
size: 0x1000
region: flash_primary
settings_storage:
address: 0xfc000
size: 0x4000
region: flash_primary
mcuboot_secondary:
address: 0x0
size: 0xf5000
size: 0xf4000
device: MX25R64
region: external_flash
external_flash:
address: 0xf5000
size: 0x70b000
address: 0xf4000
size: 0x70c000
device: MX25R64
region: external_flash
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ mcuboot_pad:
size: 0x200
app:
address: 0xC200
size: 0xefe00
size: 0xeee00
mcuboot_primary:
orig_span: &id001
- mcuboot_pad
- app
span: *id001
address: 0xC000
size: 0xf0000
size: 0xef000
region: flash_primary
mcuboot_primary_app:
orig_span: &id002
- app
span: *id002
address: 0xC200
size: 0xefe00
size: 0xeee00
factory_data:
address: 0xfb000
size: 0x1000
region: flash_primary
settings_storage:
address: 0xfc000
size: 0x4000
Expand All @@ -33,17 +37,17 @@ mcuboot_primary_1:
region: ram_flash
mcuboot_secondary:
address: 0x0
size: 0xf0000
size: 0xef000
device: MX25R64
region: external_flash
mcuboot_secondary_1:
address: 0xf0000
address: 0xef000
size: 0x40000
device: MX25R64
region: external_flash
external_flash:
address: 0x130000
size: 0x6D0000
address: 0x12f000
size: 0x6D1000
device: MX25R64
region: external_flash
pcd_sram:
Expand Down
7 changes: 7 additions & 0 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ CHIP_ERROR AppTask::Init()
k_timer_user_data_set(&sFunctionTimer, this);

// Initialize CHIP server
#if CONFIG_CHIP_FACTORY_DATA
ReturnErrorOnFailure(mFactoryDataProvider.Init());
SetDeviceInstanceInfoProvider(&mFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider);
SetCommissionableDataProvider(&mFactoryDataProvider);
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif

static CommonCaseDeviceServerInitParams initParams;
static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) };
Expand Down
8 changes: 8 additions & 0 deletions examples/all-clusters-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include <platform/CHIPDeviceLayer.h>

#if CONFIG_CHIP_FACTORY_DATA
#include <platform/nrfconnect/FactoryDataProvider.h>
#endif

struct k_timer;
class AppEvent;
class LEDWidget;
Expand Down Expand Up @@ -63,4 +67,8 @@ class AppTask
bool mIsThreadProvisioned{ false };
bool mIsThreadEnabled{ false };
bool mHaveBLEConnections{ false };

#if CONFIG_CHIP_FACTORY_DATA
chip::DeviceLayer::FactoryDataProvider<chip::DeviceLayer::InternalFlashFactoryData> mFactoryDataProvider;
#endif
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@ mcuboot_pad:
size: 0x200
app:
address: 0x7200
size: 0xf4e00
size: 0xf3e00
mcuboot_primary:
orig_span: &id001
- mcuboot_pad
- app
span: *id001
address: 0x7000
size: 0xf5000
size: 0xf4000
region: flash_primary
mcuboot_primary_app:
orig_span: &id002
- app
span: *id002
address: 0x7200
size: 0xf4e00
size: 0xf3e00
factory_data:
address: 0xfb000
size: 0x1000
region: flash_primary
settings_storage:
address: 0xfc000
size: 0x4000
region: flash_primary
mcuboot_secondary:
address: 0x0
size: 0xf5000
size: 0xf4000
device: MX25R64
region: external_flash
external_flash:
address: 0xf5000
size: 0x70b000
address: 0xf4000
size: 0x70c000
device: MX25R64
region: external_flash
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ mcuboot_pad:
size: 0x200
app:
address: 0xC200
size: 0xefe00
size: 0xeee00
mcuboot_primary:
orig_span: &id001
- mcuboot_pad
- app
span: *id001
address: 0xC000
size: 0xf0000
size: 0xef000
region: flash_primary
mcuboot_primary_app:
orig_span: &id002
- app
span: *id002
address: 0xC200
size: 0xefe00
size: 0xeee00
factory_data:
address: 0xfb000
size: 0x1000
region: flash_primary
settings_storage:
address: 0xfc000
size: 0x4000
Expand All @@ -33,17 +37,17 @@ mcuboot_primary_1:
region: ram_flash
mcuboot_secondary:
address: 0x0
size: 0xf0000
size: 0xef000
device: MX25R64
region: external_flash
mcuboot_secondary_1:
address: 0xf0000
address: 0xef000
size: 0x40000
device: MX25R64
region: external_flash
external_flash:
address: 0x130000
size: 0x6D0000
address: 0x12f000
size: 0x6D1000
device: MX25R64
region: external_flash
pcd_sram:
Expand Down
7 changes: 7 additions & 0 deletions examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ CHIP_ERROR AppTask::Init()
k_timer_user_data_set(&sFunctionTimer, this);

// Initialize CHIP server
#if CONFIG_CHIP_FACTORY_DATA
ReturnErrorOnFailure(mFactoryDataProvider.Init());
SetDeviceInstanceInfoProvider(&mFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider);
SetCommissionableDataProvider(&mFactoryDataProvider);
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif

static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include <platform/CHIPDeviceLayer.h>

#if CONFIG_CHIP_FACTORY_DATA
#include <platform/nrfconnect/FactoryDataProvider.h>
#endif

struct k_timer;
class AppEvent;
class LEDWidget;
Expand Down Expand Up @@ -63,4 +67,8 @@ class AppTask
bool mIsThreadProvisioned{ false };
bool mIsThreadEnabled{ false };
bool mHaveBLEConnections{ false };

#if CONFIG_CHIP_FACTORY_DATA
chip::DeviceLayer::FactoryDataProvider<chip::DeviceLayer::InternalFlashFactoryData> mFactoryDataProvider;
#endif
};
4 changes: 4 additions & 0 deletions examples/chef/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y
# Configure CHIP shell
CONFIG_CHIP_LIB_SHELL=y
CONFIG_OPENTHREAD_SHELL=n

# Disable factory data support.
CONFIG_CHIP_FACTORY_DATA=n
CONFIG_CHIP_FACTORY_DATA_BUILD=n
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@ mcuboot_pad:
size: 0x200
app:
address: 0x7200
size: 0xf4e00
size: 0xf3e00
mcuboot_primary:
orig_span: &id001
- mcuboot_pad
- app
span: *id001
address: 0x7000
size: 0xf5000
size: 0xf4000
region: flash_primary
mcuboot_primary_app:
orig_span: &id002
- app
span: *id002
address: 0x7200
size: 0xf4e00
size: 0xf3e00
factory_data:
address: 0xfb000
size: 0x1000
region: flash_primary
settings_storage:
address: 0xfc000
size: 0x4000
region: flash_primary
mcuboot_secondary:
address: 0x0
size: 0xf5000
size: 0xf4000
device: MX25R64
region: external_flash
external_flash:
address: 0xf5000
size: 0x70b000
address: 0xf4000
size: 0x70c000
device: MX25R64
region: external_flash
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ mcuboot_pad:
size: 0x200
app:
address: 0xC200
size: 0xefe00
size: 0xeee00
mcuboot_primary:
orig_span: &id001
- mcuboot_pad
- app
span: *id001
address: 0xC000
size: 0xf0000
size: 0xef000
region: flash_primary
mcuboot_primary_app:
orig_span: &id002
- app
span: *id002
address: 0xC200
size: 0xefe00
size: 0xeee00
factory_data:
address: 0xfb000
size: 0x1000
region: flash_primary
settings_storage:
address: 0xfc000
size: 0x4000
Expand All @@ -33,17 +37,17 @@ mcuboot_primary_1:
region: ram_flash
mcuboot_secondary:
address: 0x0
size: 0xf0000
size: 0xef000
device: MX25R64
region: external_flash
mcuboot_secondary_1:
address: 0xf0000
address: 0xef000
size: 0x40000
device: MX25R64
region: external_flash
external_flash:
address: 0x130000
size: 0x6D0000
address: 0x12f000
size: 0x6D1000
device: MX25R64
region: external_flash
pcd_sram:
Expand Down
Loading

0 comments on commit 2468133

Please sign in to comment.