@@ -69,7 +69,7 @@ struct InternalFlashFactoryData
6969 // 2) it does not exceed the settings partition start address
7070 // Note that this block can overlap with app partition but this is not a problem since we do not aim to modify
7171 // the application code at runtime anyway.
72- constexpr size_t FactoryDataBlockBegin ()
72+ static constexpr size_t FactoryDataBlockBegin ()
7373 {
7474 // calculate the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE smaller than FACTORY_DATA_ADDRESS
7575 return FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE);
@@ -81,11 +81,19 @@ struct InternalFlashFactoryData
8181 // and make sure we do not overlap with settings partition
8282 constexpr size_t kFactoryDataBlockEnd =
8383 (FACTORY_DATA_ADDRESS + FACTORY_DATA_SIZE + CONFIG_FPROTECT_BLOCK_SIZE - 1 ) & (-CONFIG_FPROTECT_BLOCK_SIZE);
84- static_assert (kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS,
84+
85+ // Only the partition that is protected by fprotect must be aligned to fprotect block size
86+ constexpr size_t kSettingsBlockEnd = PM_SETTINGS_STORAGE_ADDRESS + PM_SETTINGS_STORAGE_SIZE;
87+
88+ constexpr bool kOverlapsCheck =
89+ (kSettingsBlockEnd <= FactoryDataBlockBegin ()) || (kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS);
90+
91+ static_assert (kOverlapsCheck ,
8592 " FPROTECT memory block, which contains factory data"
8693 " partition overlaps with the settings partition."
8794 " Probably your settings partition size is not a multiple"
8895 " of the atomic FPROTECT block size of " TO_STR (CONFIG_FPROTECT_BLOCK_SIZE) " kB" );
96+
8997 return kFactoryDataBlockEnd - FactoryDataBlockBegin ();
9098 }
9199#undef TO_STR
@@ -100,7 +108,10 @@ struct InternalFlashFactoryData
100108#endif // if CONFIG_FPROTECT
101109 }
102110#else
103- CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite () { return CHIP_ERROR_NOT_IMPLEMENTED; }
111+ CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite ()
112+ {
113+ return CHIP_ERROR_NOT_IMPLEMENTED;
114+ }
104115#endif
105116};
106117
0 commit comments