@@ -117,6 +117,39 @@ IRAM_ATTR void esp_panic_putchar_hook(char c)
117117 logbuf_putc (& panicTrace , c );
118118}
119119
120+ static bool update_boot_config (const char * part , const char * name , const char * args , uint32_t flags )
121+ {
122+ if (app .initialized )
123+ {
124+ rg_settings_set_string (NS_BOOT , SETTING_BOOT_NAME , name );
125+ rg_settings_set_string (NS_BOOT , SETTING_BOOT_ARGS , args );
126+ rg_settings_set_number (NS_BOOT , SETTING_BOOT_FLAGS , flags );
127+ rg_settings_commit ();
128+ }
129+ else
130+ {
131+ rg_storage_delete (RG_BASE_PATH_CONFIG "/boot.json" );
132+ }
133+ #if defined(ESP_PLATFORM )
134+ // Check if the OTA settings are already correct, and if so do not call esp_ota_set_boot_partition
135+ // This is simply to avoid an unecessary flash write...
136+ const esp_partition_t * current = esp_ota_get_boot_partition ();
137+ if (current && part && strncmp (current -> label , part , 16 ) == 0 )
138+ {
139+ RG_LOGI ("Boot partition already set to desired app!" );
140+ return true;
141+ }
142+ esp_err_t err = esp_ota_set_boot_partition (esp_partition_find_first (
143+ ESP_PARTITION_TYPE_APP , ESP_PARTITION_SUBTYPE_ANY , part ));
144+ if (err != ESP_OK )
145+ {
146+ RG_LOGE ("esp_ota_set_boot_partition returned 0x%02X!" , err );
147+ return false;
148+ }
149+ #endif
150+ return true;
151+ }
152+
120153static void update_memory_statistics (void )
121154{
122155#ifdef ESP_PLATFORM
@@ -469,14 +502,11 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
469502 profile -> lock = rg_mutex_create ();
470503#endif
471504
472- #ifdef ESP_PLATFORM
473505 if (app .lowMemoryMode )
474506 rg_gui_alert ("External memory not detected" , "Boot will continue but it will surely crash..." );
475507
476508 if (app .bootFlags & RG_BOOT_ONCE )
477- esp_ota_set_boot_partition (esp_partition_find_first (
478- ESP_PARTITION_TYPE_APP , ESP_PARTITION_SUBTYPE_ANY , RG_APP_LAUNCHER ));
479- #endif
509+ update_boot_config (RG_APP_LAUNCHER , NULL , NULL , 0 );
480510
481511 rg_task_create ("rg_sysmon" , & system_monitor_task , NULL , 3 * 1024 , RG_TASK_PRIORITY_5 , -1 );
482512 app .initialized = true;
@@ -862,32 +892,10 @@ void rg_system_switch_app(const char *partition, const char *name, const char *a
862892{
863893 RG_LOGI ("Switching to app %s (%s)" , partition ?: "-" , name ?: "-" );
864894
865- if (app .initialized )
866- {
867- rg_settings_set_string (NS_BOOT , SETTING_BOOT_NAME , name );
868- rg_settings_set_string (NS_BOOT , SETTING_BOOT_ARGS , args );
869- rg_settings_set_number (NS_BOOT , SETTING_BOOT_FLAGS , flags );
870- rg_settings_commit ();
871- }
872- #if defined(ESP_PLATFORM )
873- // Check if the OTA settings are already correct, and if so do not call esp_ota_set_boot_partition
874- // This is simply to avoid an unecessary flash write...
875- const esp_partition_t * current = esp_ota_get_boot_partition ();
876- if (current && partition && strncmp (current -> label , partition , 16 ) == 0 )
877- {
878- RG_LOGI ("Boot partition already set to desired app!" );
895+ if (update_boot_config (partition , name , args , flags ))
879896 rg_system_restart ();
880- }
881- esp_err_t err = esp_ota_set_boot_partition (esp_partition_find_first (
882- ESP_PARTITION_TYPE_APP , ESP_PARTITION_SUBTYPE_ANY , partition ));
883- if (err != ESP_OK )
884- {
885- RG_LOGE ("esp_ota_set_boot_partition returned 0x%02X!" , err );
886- RG_PANIC ("Unable to set boot app!" );
887- }
888- rg_system_restart ();
889- #endif
890- RG_PANIC ("Switch not implemented!" );
897+
898+ RG_PANIC ("Failed to switch app!" );
891899}
892900
893901bool rg_system_have_app (const char * app )
0 commit comments