@@ -72,15 +72,26 @@ struct InternalFlashFactoryData
72
72
73
73
constexpr size_t FactoryDataBlockSize ()
74
74
{
75
- // calculate the factory data end address rounded up to the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE
75
+ // calculate the factory data and settings end address rounded up to the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE
76
76
// and make sure we do not overlap with settings partition
77
77
constexpr size_t kFactoryDataBlockEnd =
78
78
(FACTORY_DATA_ADDRESS + FACTORY_DATA_SIZE + CONFIG_FPROTECT_BLOCK_SIZE - 1 ) & (-CONFIG_FPROTECT_BLOCK_SIZE);
79
- static_assert (kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS,
79
+
80
+ constexpr size_t SettingsBlockEnd =
81
+ (PM_SETTINGS_STORAGE_ADDRESS + PM_SETTINGS_STORAGE_SIZE + CONFIG_FPROTECT_BLOCK_SIZE - 1 ) &
82
+ (-CONFIG_FPROTECT_BLOCK_SIZE);
83
+
84
+ constexpr size_t kFactoryDataBlockBegin = FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE);
85
+
86
+ constexpr bool overlapsCheck =
87
+ (SettingsBlockEnd <= kFactoryDataBlockBegin ) || (kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS);
88
+
89
+ static_assert (overlapsCheck,
80
90
" FPROTECT memory block, which contains factory data"
81
91
" partition overlaps with the settings partition."
82
92
" Probably your settings partition size is not a multiple"
83
93
" of the atomic FPROTECT block size of " TO_STR (CONFIG_FPROTECT_BLOCK_SIZE) " kB" );
94
+
84
95
return kFactoryDataBlockEnd - FactoryDataBlockBegin ();
85
96
}
86
97
#undef TO_STR
@@ -95,7 +106,10 @@ struct InternalFlashFactoryData
95
106
#endif // if CONFIG_FPROTECT
96
107
}
97
108
#else
98
- CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite () { return CHIP_ERROR_NOT_IMPLEMENTED; }
109
+ CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite ()
110
+ {
111
+ return CHIP_ERROR_NOT_IMPLEMENTED;
112
+ }
99
113
#endif
100
114
};
101
115
0 commit comments