Skip to content

Commit

Permalink
[nrf toup] Factory data partition location change
Browse files Browse the repository at this point in the history
- factory data can be placed before or after settings partition

Signed-off-by: Konrad Grucel <[email protected]>
  • Loading branch information
kg-nordicsemi committed Oct 23, 2024
1 parent bdec5fd commit a4c701d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 0 additions & 1 deletion config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,4 @@ config CHIP_ENABLE_BDX_LOG_TRANSFER
bool "Enable BDX transfer for diagnostic logs"
help
Enables the BDX protocol for diagnostics log transfer purposes.

endif # CHIP
20 changes: 17 additions & 3 deletions src/platform/nrfconnect/FactoryDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,26 @@ struct InternalFlashFactoryData

constexpr size_t FactoryDataBlockSize()
{
// calculate the factory data end address rounded up to the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE
// calculate the factory data and settings end address rounded up to the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE
// and make sure we do not overlap with settings partition
constexpr size_t kFactoryDataBlockEnd =
(FACTORY_DATA_ADDRESS + FACTORY_DATA_SIZE + CONFIG_FPROTECT_BLOCK_SIZE - 1) & (-CONFIG_FPROTECT_BLOCK_SIZE);
static_assert(kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS,

constexpr size_t SettingsBlockEnd =
(PM_SETTINGS_STORAGE_ADDRESS + PM_SETTINGS_STORAGE_SIZE + CONFIG_FPROTECT_BLOCK_SIZE - 1) &
(-CONFIG_FPROTECT_BLOCK_SIZE);

constexpr size_t kFactoryDataBlockBegin = FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE);

constexpr bool overlapsCheck =
(SettingsBlockEnd <= kFactoryDataBlockBegin) || (kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS);

static_assert(overlapsCheck,
"FPROTECT memory block, which contains factory data"
"partition overlaps with the settings partition."
"Probably your settings partition size is not a multiple"
"of the atomic FPROTECT block size of " TO_STR(CONFIG_FPROTECT_BLOCK_SIZE) "kB");

return kFactoryDataBlockEnd - FactoryDataBlockBegin();
}
#undef TO_STR
Expand All @@ -95,7 +106,10 @@ struct InternalFlashFactoryData
#endif // if CONFIG_FPROTECT
}
#else
CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite() { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite()
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
#endif
};

Expand Down

0 comments on commit a4c701d

Please sign in to comment.