Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kg-nordicsemi
Copy link

  • factory data can be placed before or after settings partition
    -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

@@ -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
Copy link
Contributor

@kkasperczyk-no kkasperczyk-no Oct 23, 2024

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.

Copy link
Contributor

@ArekBalysNordic ArekBalysNordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kg-nordicsemi kg-nordicsemi force-pushed the Factory-data-before-settings branch 2 times, most recently from a4c701d to a1c3d8c Compare October 23, 2024 13:44
// 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 =
Copy link
Contributor

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?

Copy link
Contributor

@ArekBalysNordic ArekBalysNordic Oct 24, 2024

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);
Copy link
Contributor

@kkasperczyk-no kkasperczyk-no Oct 24, 2024

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:

  1. 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.
  2. 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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constexpr size_t SettingsBlockEnd =
constexpr size_t kSettingsBlockEnd =

Copy link
Contributor

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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 =
Copy link
Contributor

@ArekBalysNordic ArekBalysNordic Oct 24, 2024

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.

Copy link
Contributor

@kkasperczyk-no kkasperczyk-no left a 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);
Copy link
Contributor

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);
Copy link
Contributor

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() ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if I do this like this: constexpr size_t kFactoryDataBlockBegin = FactoryDataBlockBegin();
there is an following error:
image

src/platform/nrfconnect/FactoryDataProvider.h Show resolved Hide resolved
Copy link
Contributor

@ArekBalysNordic ArekBalysNordic left a 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants