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 authored and ArekBalysNordic committed Nov 28, 2024
1 parent 9cfd6e1 commit 21ecc7d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/platform/nrfconnect/FactoryDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct InternalFlashFactoryData
// 2) it does not exceed the settings partition start address
// Note that this block can overlap with app partition but this is not a problem since we do not aim to modify
// the application code at runtime anyway.
constexpr size_t FactoryDataBlockBegin()
static constexpr size_t FactoryDataBlockBegin()
{
// calculate the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE smaller than FACTORY_DATA_ADDRESS
return FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE);
Expand All @@ -81,11 +81,19 @@ struct InternalFlashFactoryData
// 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,

// Only the partition that is protected by fprotect must be aligned to fprotect block size
constexpr size_t kSettingsBlockEnd = PM_SETTINGS_STORAGE_ADDRESS + PM_SETTINGS_STORAGE_SIZE;

constexpr bool kOverlapsCheck =
(kSettingsBlockEnd <= FactoryDataBlockBegin()) || (kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS);

static_assert(kOverlapsCheck,
"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 @@ -100,7 +108,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 21ecc7d

Please sign in to comment.