From c49db35ee0fa58909e5f37876a935c7baa9337bd Mon Sep 17 00:00:00 2001 From: hedger Date: Tue, 5 Jul 2022 15:17:26 +0300 Subject: [PATCH] storage: lfs fingerprint wasn't updated when both geometry changed & factory reset was requested, resulting in second re-format on next boot (#1372) --- applications/storage/storages/storage_int.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/applications/storage/storages/storage_int.c b/applications/storage/storages/storage_int.c index 9b1ec700..bdd78172 100644 --- a/applications/storage/storages/storage_int.c +++ b/applications/storage/storages/storage_int.c @@ -4,6 +4,7 @@ #define TAG "StorageInt" #define STORAGE_PATH "/int" +#define LFS_CLEAN_FINGERPRINT 0 typedef struct { const size_t start_address; @@ -162,8 +163,9 @@ static LFSData* storage_int_lfs_data_alloc() { return lfs_data; }; -static bool storage_int_is_fingerprint_valid(LFSData* lfs_data) { - bool value = true; +// Returns true if fingerprint was invalid and LFS reformatting is needed +static bool storage_int_check_and_set_fingerprint(LFSData* lfs_data) { + bool value = false; uint32_t os_fingerprint = 0; os_fingerprint |= ((lfs_data->start_page & 0xFF) << 0); @@ -171,13 +173,13 @@ static bool storage_int_is_fingerprint_valid(LFSData* lfs_data) { os_fingerprint |= ((LFS_DISK_VERSION_MAJOR & 0xFFFF) << 16); uint32_t rtc_fingerprint = furi_hal_rtc_get_register(FuriHalRtcRegisterLfsFingerprint); - if(rtc_fingerprint == 0) { + if(rtc_fingerprint == LFS_CLEAN_FINGERPRINT) { 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; + value = true; } return value; @@ -187,8 +189,9 @@ static void storage_int_lfs_mount(LFSData* lfs_data, StorageData* storage) { int err; lfs_t* lfs = &lfs_data->lfs; + bool was_fingerprint_outdated = storage_int_check_and_set_fingerprint(lfs_data); bool need_format = furi_hal_rtc_is_flag_set(FuriHalRtcFlagFactoryReset) || - !storage_int_is_fingerprint_valid(lfs_data); + was_fingerprint_outdated; if(need_format) { // Format storage