Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorあく <alleteam@gmail.com>2021-12-24 17:33:58 +0300
committerGitHub <noreply@github.com>2021-12-24 17:33:58 +0300
commit7cea359be84cb8bf72879f1264faf9b088b054f9 (patch)
treeb3db66dd1ed9265c0d61584c9b7a20bce8a0b900 /applications/storage
parent79e0aed1e6be9e8670595219a5e1567e92ab183b (diff)
Storage: lfs config fingerprinting. RTC: fix data collision in lock register, refactor and cleanup. (#928)
Diffstat (limited to 'applications/storage')
-rw-r--r--applications/storage/storages/storage-int.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/applications/storage/storages/storage-int.c b/applications/storage/storages/storage-int.c
index 097934b6..3351be3b 100644
--- a/applications/storage/storages/storage-int.c
+++ b/applications/storage/storages/storage-int.c
@@ -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");