Storage: lfs config fingerprinting. RTC: fix data collision in lock register, refactor and cleanup. (#928)
This commit is contained in:
@@ -161,12 +161,36 @@ static LFSData* storage_int_lfs_data_alloc() {
|
||||
return lfs_data;
|
||||
};
|
||||
|
||||
static bool storage_int_is_fingerprint_valid(LFSData* lfs_data) {
|
||||
bool value = true;
|
||||
|
||||
uint32_t os_fingerprint = 0;
|
||||
os_fingerprint |= ((lfs_data->start_page & 0xFF) << 0);
|
||||
os_fingerprint |= ((lfs_data->config.block_count & 0xFF) << 8);
|
||||
os_fingerprint |= ((LFS_DISK_VERSION_MAJOR & 0xFFFF) << 16);
|
||||
|
||||
uint32_t rtc_fingerprint = furi_hal_rtc_get_register(FuriHalRtcRegisterLfsFingerprint);
|
||||
if(rtc_fingerprint == 0) {
|
||||
FURI_LOG_I(TAG, "Storing LFS fingerprint in RTC");
|
||||
furi_hal_rtc_set_register(FuriHalRtcRegisterLfsFingerprint, os_fingerprint);
|
||||
} else if(rtc_fingerprint != os_fingerprint) {
|
||||
FURI_LOG_E(TAG, "LFS fingerprint mismatch");
|
||||
furi_hal_rtc_set_register(FuriHalRtcRegisterLfsFingerprint, os_fingerprint);
|
||||
value = false;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static void storage_int_lfs_mount(LFSData* lfs_data, StorageData* storage) {
|
||||
int err;
|
||||
lfs_t* lfs = &lfs_data->lfs;
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagFactoryReset)) {
|
||||
// Factory reset
|
||||
bool need_format = furi_hal_rtc_is_flag_set(FuriHalRtcFlagFactoryReset) ||
|
||||
!storage_int_is_fingerprint_valid(lfs_data);
|
||||
|
||||
if(need_format) {
|
||||
// Format storage
|
||||
err = lfs_format(lfs, &lfs_data->config);
|
||||
if(err == 0) {
|
||||
FURI_LOG_I(TAG, "Factory reset: Format successful, trying to mount");
|
||||
|
Reference in New Issue
Block a user