Updater: handle storage errors when removing files, fix folder remove routine, prevent unused services from starting (#2432)
* Updater: handle storage errors when removing files * Updater: properly handle folder removal in post update cleanup stage. Prevent power, desktop and dolphin services from starting on update. * Desktop, Dolphin, Power: proper handling and message for special boot mode. * Desktop, Power: add missing TAG * Updater: unify start skip message and fix double delete in backup worker * Cli: unify special boot mode message
This commit is contained in:
		
							parent
							
								
									0c06e54831
								
							
						
					
					
						commit
						3efb7d4050
					
				| @ -373,7 +373,7 @@ int32_t bt_srv(void* p) { | |||||||
|     Bt* bt = bt_alloc(); |     Bt* bt = bt_alloc(); | ||||||
| 
 | 
 | ||||||
|     if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { |     if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { | ||||||
|         FURI_LOG_W(TAG, "Skipped BT init: device in special startup mode"); |         FURI_LOG_W(TAG, "Skipping start in special boot mode"); | ||||||
|         ble_glue_wait_for_c2_start(FURI_HAL_BT_C2_START_TIMEOUT); |         ble_glue_wait_for_c2_start(FURI_HAL_BT_C2_START_TIMEOUT); | ||||||
|         furi_record_create(RECORD_BT, bt); |         furi_record_create(RECORD_BT, bt); | ||||||
|         return 0; |         return 0; | ||||||
|  | |||||||
| @ -461,7 +461,7 @@ int32_t cli_srv(void* p) { | |||||||
|     if(furi_hal_rtc_get_boot_mode() == FuriHalRtcBootModeNormal) { |     if(furi_hal_rtc_get_boot_mode() == FuriHalRtcBootModeNormal) { | ||||||
|         cli_session_open(cli, &cli_vcp); |         cli_session_open(cli, &cli_vcp); | ||||||
|     } else { |     } else { | ||||||
|         FURI_LOG_W(TAG, "Skipped CLI session open: device in special startup mode"); |         FURI_LOG_W(TAG, "Skipping start in special boot mode"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     while(1) { |     while(1) { | ||||||
|  | |||||||
| @ -17,6 +17,8 @@ | |||||||
| #include "helpers/pin_lock.h" | #include "helpers/pin_lock.h" | ||||||
| #include "helpers/slideshow_filename.h" | #include "helpers/slideshow_filename.h" | ||||||
| 
 | 
 | ||||||
|  | #define TAG "Desktop" | ||||||
|  | 
 | ||||||
| static void desktop_auto_lock_arm(Desktop*); | static void desktop_auto_lock_arm(Desktop*); | ||||||
| static void desktop_auto_lock_inhibit(Desktop*); | static void desktop_auto_lock_inhibit(Desktop*); | ||||||
| static void desktop_start_auto_lock_timer(Desktop*); | static void desktop_start_auto_lock_timer(Desktop*); | ||||||
| @ -321,6 +323,12 @@ static bool desktop_check_file_flag(const char* flag_path) { | |||||||
| 
 | 
 | ||||||
| int32_t desktop_srv(void* p) { | int32_t desktop_srv(void* p) { | ||||||
|     UNUSED(p); |     UNUSED(p); | ||||||
|  | 
 | ||||||
|  |     if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { | ||||||
|  |         FURI_LOG_W(TAG, "Skipping start in special boot mode"); | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     Desktop* desktop = desktop_alloc(); |     Desktop* desktop = desktop_alloc(); | ||||||
| 
 | 
 | ||||||
|     bool loaded = DESKTOP_SETTINGS_LOAD(&desktop->settings); |     bool loaded = DESKTOP_SETTINGS_LOAD(&desktop->settings); | ||||||
|  | |||||||
| @ -154,6 +154,12 @@ static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin) { | |||||||
| 
 | 
 | ||||||
| int32_t dolphin_srv(void* p) { | int32_t dolphin_srv(void* p) { | ||||||
|     UNUSED(p); |     UNUSED(p); | ||||||
|  | 
 | ||||||
|  |     if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { | ||||||
|  |         FURI_LOG_W(TAG, "Skipping start in special boot mode"); | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     Dolphin* dolphin = dolphin_alloc(); |     Dolphin* dolphin = dolphin_alloc(); | ||||||
|     furi_record_create(RECORD_DOLPHIN, dolphin); |     furi_record_create(RECORD_DOLPHIN, dolphin); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,6 +4,7 @@ | |||||||
| #include <furi_hal.h> | #include <furi_hal.h> | ||||||
| 
 | 
 | ||||||
| #define POWER_OFF_TIMEOUT 90 | #define POWER_OFF_TIMEOUT 90 | ||||||
|  | #define TAG "Power" | ||||||
| 
 | 
 | ||||||
| void power_draw_battery_callback(Canvas* canvas, void* context) { | void power_draw_battery_callback(Canvas* canvas, void* context) { | ||||||
|     furi_assert(context); |     furi_assert(context); | ||||||
| @ -217,6 +218,12 @@ static void power_check_battery_level_change(Power* power) { | |||||||
| 
 | 
 | ||||||
| int32_t power_srv(void* p) { | int32_t power_srv(void* p) { | ||||||
|     UNUSED(p); |     UNUSED(p); | ||||||
|  | 
 | ||||||
|  |     if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { | ||||||
|  |         FURI_LOG_W(TAG, "Skipping start in special boot mode"); | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     Power* power = power_alloc(); |     Power* power = power_alloc(); | ||||||
|     power_update_info(power); |     power_update_info(power); | ||||||
|     furi_record_create(RECORD_POWER, power); |     furi_record_create(RECORD_POWER, power); | ||||||
|  | |||||||
| @ -97,7 +97,16 @@ static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_ | |||||||
|                 path_concat( |                 path_concat( | ||||||
|                     STORAGE_EXT_PATH_PREFIX, furi_string_get_cstr(entry_ptr->name), file_path); |                     STORAGE_EXT_PATH_PREFIX, furi_string_get_cstr(entry_ptr->name), file_path); | ||||||
|                 FURI_LOG_D(TAG, "Removing %s", furi_string_get_cstr(file_path)); |                 FURI_LOG_D(TAG, "Removing %s", furi_string_get_cstr(file_path)); | ||||||
|                 storage_simply_remove(update_task->storage, furi_string_get_cstr(file_path)); | 
 | ||||||
|  |                 FS_Error result = | ||||||
|  |                     storage_common_remove(update_task->storage, furi_string_get_cstr(file_path)); | ||||||
|  |                 if(result != FSE_OK && result != FSE_EXIST) { | ||||||
|  |                     FURI_LOG_E( | ||||||
|  |                         TAG, | ||||||
|  |                         "%s remove failed, cause %s", | ||||||
|  |                         furi_string_get_cstr(file_path), | ||||||
|  |                         storage_error_get_desc(result)); | ||||||
|  |                 } | ||||||
|                 furi_string_free(file_path); |                 furi_string_free(file_path); | ||||||
|             } else if(entry_ptr->type == ResourceManifestEntryTypeDirectory) { |             } else if(entry_ptr->type == ResourceManifestEntryTypeDirectory) { | ||||||
|                 n_dir_entries++; |                 n_dir_entries++; | ||||||
| @ -116,7 +125,6 @@ static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_ | |||||||
|                             n_dir_entries); |                             n_dir_entries); | ||||||
| 
 | 
 | ||||||
|                 FuriString* folder_path = furi_string_alloc(); |                 FuriString* folder_path = furi_string_alloc(); | ||||||
|                 File* folder_file = storage_file_alloc(update_task->storage); |  | ||||||
| 
 | 
 | ||||||
|                 do { |                 do { | ||||||
|                     path_concat( |                     path_concat( | ||||||
| @ -125,24 +133,17 @@ static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_ | |||||||
|                         folder_path); |                         folder_path); | ||||||
| 
 | 
 | ||||||
|                     FURI_LOG_D(TAG, "Removing folder %s", furi_string_get_cstr(folder_path)); |                     FURI_LOG_D(TAG, "Removing folder %s", furi_string_get_cstr(folder_path)); | ||||||
|                     if(!storage_dir_open(folder_file, furi_string_get_cstr(folder_path))) { |                     FS_Error result = storage_common_remove( | ||||||
|                         FURI_LOG_W( |                         update_task->storage, furi_string_get_cstr(folder_path)); | ||||||
|  |                     if(result != FSE_OK && result != FSE_EXIST) { | ||||||
|  |                         FURI_LOG_E( | ||||||
|                             TAG, |                             TAG, | ||||||
|                             "%s can't be opened, skipping", |                             "%s remove failed, cause %s", | ||||||
|                             furi_string_get_cstr(folder_path)); |                             furi_string_get_cstr(folder_path), | ||||||
|                         break; |                             storage_error_get_desc(result)); | ||||||
|                     } |                     } | ||||||
| 
 |  | ||||||
|                     if(storage_dir_read(folder_file, NULL, NULL, 0)) { |  | ||||||
|                         FURI_LOG_I( |  | ||||||
|                             TAG, "%s is not empty, skipping", furi_string_get_cstr(folder_path)); |  | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     storage_simply_remove(update_task->storage, furi_string_get_cstr(folder_path)); |  | ||||||
|                 } while(false); |                 } while(false); | ||||||
| 
 | 
 | ||||||
|                 storage_file_free(folder_file); |  | ||||||
|                 furi_string_free(folder_path); |                 furi_string_free(folder_path); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -96,9 +96,9 @@ static void furi_thread_body(void* context) { | |||||||
|     furi_assert(thread->state == FuriThreadStateRunning); |     furi_assert(thread->state == FuriThreadStateRunning); | ||||||
| 
 | 
 | ||||||
|     if(thread->is_service) { |     if(thread->is_service) { | ||||||
|         FURI_LOG_E( |         FURI_LOG_W( | ||||||
|             TAG, |             TAG, | ||||||
|             "%s service thread exited. Thread memory cannot be reclaimed.", |             "%s service thread TCB memory will not be reclaimed", | ||||||
|             thread->name ? thread->name : "<unknown service>"); |             thread->name ? thread->name : "<unknown service>"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ | |||||||
| #include <furi.h> | #include <furi.h> | ||||||
| #include <furi_hal_version.h> | #include <furi_hal_version.h> | ||||||
| #include <furi_hal_memory.h> | #include <furi_hal_memory.h> | ||||||
|  | #include <furi_hal_rtc.h> | ||||||
| 
 | 
 | ||||||
| #define TAG "Flipper" | #define TAG "Flipper" | ||||||
| 
 | 
 | ||||||
| @ -29,10 +30,10 @@ static void flipper_print_version(const char* target, const Version* version) { | |||||||
| void flipper_init() { | void flipper_init() { | ||||||
|     flipper_print_version("Firmware", furi_hal_version_get_firmware_version()); |     flipper_print_version("Firmware", furi_hal_version_get_firmware_version()); | ||||||
| 
 | 
 | ||||||
|     FURI_LOG_I(TAG, "starting services"); |     FURI_LOG_I(TAG, "Boot mode %d, starting services", furi_hal_rtc_get_boot_mode()); | ||||||
| 
 | 
 | ||||||
|     for(size_t i = 0; i < FLIPPER_SERVICES_COUNT; i++) { |     for(size_t i = 0; i < FLIPPER_SERVICES_COUNT; i++) { | ||||||
|         FURI_LOG_I(TAG, "starting service %s", FLIPPER_SERVICES[i].name); |         FURI_LOG_I(TAG, "Starting service %s", FLIPPER_SERVICES[i].name); | ||||||
| 
 | 
 | ||||||
|         FuriThread* thread = furi_thread_alloc_ex( |         FuriThread* thread = furi_thread_alloc_ex( | ||||||
|             FLIPPER_SERVICES[i].name, |             FLIPPER_SERVICES[i].name, | ||||||
| @ -44,7 +45,7 @@ void flipper_init() { | |||||||
|         furi_thread_start(thread); |         furi_thread_start(thread); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     FURI_LOG_I(TAG, "services startup complete"); |     FURI_LOG_I(TAG, "Startup complete"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void vApplicationGetIdleTaskMemory( | void vApplicationGetIdleTaskMemory( | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 あく
						あく