-
Notifications
You must be signed in to change notification settings - Fork 59
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
[nrf toup] Factory data partition location change #499
base: master
Are you sure you want to change the base?
[nrf toup] Factory data partition location change #499
Conversation
@@ -76,11 +76,26 @@ 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); | |||
|
|||
#ifdef CONFIG_CHIP_FACTORY_DATA_BEFORE_SETTINGS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not quite goal of this task to create an additional option that allows to put factory data before or after the settings. It's more about accepting both cases without setting any Kconfig option that determines it. I would say you can just check which address is bigger settings or factory data. And based on that you already know which partition is the first one. Then you just need to verify if the first partition + its size ends before the second partition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a4c701d
to
a1c3d8c
Compare
// 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 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArekBalysNordic please correct me if I'm wrong, but I think that the settings partition does not need to be aligned to the fprotect block size, so the end address is just start address + size, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. Only the partition that is protected by fprotect must be aligned to fprotect block size. So we need to take care of factory data only. We need to be aware to not overlap settings partition by fprotect. Keep in mind that the protect block size varies depending on our platform.
constexpr size_t kFactoryDataBlockBegin = FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE); | ||
|
||
constexpr bool overlapsCheck = | ||
(SettingsBlockEnd <= kFactoryDataBlockBegin) || (kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this is correct. The problem that we consider here is the fact that fprotect has some fixed block size and we want to use it only on factory data (not on settings). There are two issues possible:
- The factory data is before the settings and its size is not aligned to the fprotect block size, so bigger range than expected will be covered by fprotect. In such case we have to check if factory data start+ factory data size + alignment to fprotect block size will not overlap with the start address of settings.
- The settings are before the factory data and the factory data size is not aligned. If the factory data is at the end of memory, the fprotect will do the alignment using the space before the factory data (because after that there is no memory left). In such case we have to check if memory end - (factory data size + alignment) does not overlap with the settings end.
// 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 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr size_t SettingsBlockEnd = | |
constexpr size_t kSettingsBlockEnd = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- replace its occurences.
|
||
constexpr size_t kFactoryDataBlockBegin = FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE); | ||
|
||
constexpr bool overlapsCheck = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr bool overlapsCheck = | |
constexpr bool kOverlapsCheck = |
& ditto
// 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 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. Only the partition that is protected by fprotect must be aligned to fprotect block size. So we need to take care of factory data only. We need to be aware to not overlap settings partition by fprotect. Keep in mind that the protect block size varies depending on our platform.
a1c3d8c
to
e7de8f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, please consult with @ArekBalysNordic that alignment is correct.
@@ -76,11 +76,21 @@ 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, | |||
|
|||
constexpr size_t kFactoryDataBlockBegin = FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArekBalysNordic could you verify the alignment of the factory data beginning? TBH I don't know where this magic with & and - fprotect block size comes from.
@@ -76,11 +76,21 @@ 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, | |||
|
|||
constexpr size_t kFactoryDataBlockBegin = FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you again calculate FcatoryDataBlockBegin since it is done above in function constexpr size_t FactoryDataBlockBegin()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e7de8f7
to
7afc8b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase the related sdk-nrf manifest PR to see whether it works before merging.
- factory data can be placed before or after settings partition Signed-off-by: Konrad Grucel <[email protected]>
7afc8b5
to
6b6c2eb
Compare
-added static_asserts, which checks whether factory data overlaps with settings partition
-added Kconfig which allow to choose the location of settings and factory data partition