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 a1c3d8c
Showing 1 changed file with 17 additions and 3 deletions.
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 a1c3d8c

Please sign in to comment.