[FL-2510] Fixed BT startup while backing up LFS (#1180)
* Waiting for dummy BT record on LFS ops; cleaner retry for backup file open * Fixed files not being closed on failed open
This commit is contained in:
		| @@ -29,7 +29,8 @@ static bool update_task_pre_update(UpdateTask* update_task) { | |||||||
|  |  | ||||||
|     update_task->state.total_stages = 1; |     update_task->state.total_stages = 1; | ||||||
|     update_task_set_progress(update_task, UpdateTaskStageLfsBackup, 0); |     update_task_set_progress(update_task, UpdateTaskStageLfsBackup, 0); | ||||||
|     furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); // to avoid bootloops |     /* to avoid bootloops */ | ||||||
|  |     furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); | ||||||
|     if((success = lfs_backup_create(update_task->storage, string_get_cstr(backup_file_path)))) { |     if((success = lfs_backup_create(update_task->storage, string_get_cstr(backup_file_path)))) { | ||||||
|         furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeUpdate); |         furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeUpdate); | ||||||
|     } |     } | ||||||
| @@ -61,7 +62,7 @@ static bool update_task_post_update(UpdateTask* update_task) { | |||||||
|     string_t file_path; |     string_t file_path; | ||||||
|     string_init(file_path); |     string_init(file_path); | ||||||
|  |  | ||||||
|     // status text is too long, too few stages to bother with a counter |     /* status text is too long, too few stages to bother with a counter */ | ||||||
|     update_task->state.total_stages = 0; |     update_task->state.total_stages = 0; | ||||||
|  |  | ||||||
|     do { |     do { | ||||||
| @@ -70,9 +71,6 @@ static bool update_task_post_update(UpdateTask* update_task) { | |||||||
|             string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, file_path); |             string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, file_path); | ||||||
|  |  | ||||||
|         bool unpack_resources = !string_empty_p(update_task->manifest->resource_bundle); |         bool unpack_resources = !string_empty_p(update_task->manifest->resource_bundle); | ||||||
|         if(unpack_resources) { |  | ||||||
|             update_task->state.total_stages++; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         update_task_set_progress(update_task, UpdateTaskStageLfsRestore, 0); |         update_task_set_progress(update_task, UpdateTaskStageLfsRestore, 0); | ||||||
|         furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); |         furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); | ||||||
| @@ -117,7 +115,7 @@ int32_t update_task_worker_backup_restore(void* context) { | |||||||
|  |  | ||||||
|     FuriHalRtcBootMode boot_mode = furi_hal_rtc_get_boot_mode(); |     FuriHalRtcBootMode boot_mode = furi_hal_rtc_get_boot_mode(); | ||||||
|     if((boot_mode != FuriHalRtcBootModePreUpdate) && (boot_mode != FuriHalRtcBootModePostUpdate)) { |     if((boot_mode != FuriHalRtcBootModePreUpdate) && (boot_mode != FuriHalRtcBootModePostUpdate)) { | ||||||
|         // no idea how we got here. Clear to normal boot |         /* no idea how we got here. Clear to normal boot */ | ||||||
|         furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); |         furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); | ||||||
|         return UPDATE_TASK_NOERR; |         return UPDATE_TASK_NOERR; | ||||||
|     } |     } | ||||||
| @@ -128,12 +126,17 @@ int32_t update_task_worker_backup_restore(void* context) { | |||||||
|         return UPDATE_TASK_FAILED; |         return UPDATE_TASK_FAILED; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /* Waiting for BT service to 'start', so we don't race for boot mode */ | ||||||
|  |     furi_record_open("bt"); | ||||||
|  |  | ||||||
|     if(boot_mode == FuriHalRtcBootModePreUpdate) { |     if(boot_mode == FuriHalRtcBootModePreUpdate) { | ||||||
|         success = update_task_pre_update(update_task); |         success = update_task_pre_update(update_task); | ||||||
|     } else if(boot_mode == FuriHalRtcBootModePostUpdate) { |     } else if(boot_mode == FuriHalRtcBootModePostUpdate) { | ||||||
|         success = update_task_post_update(update_task); |         success = update_task_post_update(update_task); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     furi_record_close("bt"); | ||||||
|  |  | ||||||
|     if(success) { |     if(success) { | ||||||
|         update_task_set_progress(update_task, UpdateTaskStageCompleted, 100); |         update_task_set_progress(update_task, UpdateTaskStageCompleted, 100); | ||||||
|     } else { |     } else { | ||||||
| @@ -141,4 +144,4 @@ int32_t update_task_worker_backup_restore(void* context) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED; |     return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -206,12 +206,14 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header, | |||||||
|     bool failed = false; |     bool failed = false; | ||||||
|     uint8_t n_tries = FILE_OPEN_NTRIES; |     uint8_t n_tries = FILE_OPEN_NTRIES; | ||||||
|     do { |     do { | ||||||
|         while( |         while(n_tries-- > 0) { | ||||||
|             (n_tries-- > 0) && |             if(storage_file_open( | ||||||
|             !storage_file_open(out_file, string_get_cstr(fname), FSAM_WRITE, FSOM_CREATE_ALWAYS)) { |                    out_file, string_get_cstr(fname), FSAM_WRITE, FSOM_CREATE_ALWAYS)) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|             FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", string_get_cstr(fname), n_tries); |             FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", string_get_cstr(fname), n_tries); | ||||||
|  |             storage_file_close(out_file); | ||||||
|             osDelay(FILE_OPEN_RETRY_DELAY); |             osDelay(FILE_OPEN_RETRY_DELAY); | ||||||
|             continue; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if(!storage_file_is_open(out_file)) { |         if(!storage_file_is_open(out_file)) { | ||||||
| @@ -257,11 +259,13 @@ bool tar_archive_add_file( | |||||||
|     File* src_file = storage_file_alloc(archive->storage); |     File* src_file = storage_file_alloc(archive->storage); | ||||||
|     uint8_t n_tries = FILE_OPEN_NTRIES; |     uint8_t n_tries = FILE_OPEN_NTRIES; | ||||||
|     do { |     do { | ||||||
|         while((n_tries-- > 0) && |         while(n_tries-- > 0) { | ||||||
|               !storage_file_open(src_file, fs_file_path, FSAM_READ, FSOM_OPEN_EXISTING)) { |             if(storage_file_open(src_file, fs_file_path, FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|             FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", fs_file_path, n_tries); |             FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", fs_file_path, n_tries); | ||||||
|  |             storage_file_close(src_file); | ||||||
|             osDelay(FILE_OPEN_RETRY_DELAY); |             osDelay(FILE_OPEN_RETRY_DELAY); | ||||||
|             continue; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if(!storage_file_is_open(src_file) || |         if(!storage_file_is_open(src_file) || | ||||||
| @@ -341,4 +345,4 @@ bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const ch | |||||||
|     free(name); |     free(name); | ||||||
|     storage_file_free(directory); |     storage_file_free(directory); | ||||||
|     return success; |     return success; | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user