Skip to content

Commit 1069d3a

Browse files
committed
rg_sytem: update_boot_config
1 parent e313c55 commit 1069d3a

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

components/retro-go/rg_system.c

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,37 @@ IRAM_ATTR void esp_panic_putchar_hook(char c)
117117
logbuf_putc(&panicTrace, c);
118118
}
119119

120+
static bool update_boot_config(const char *partition, 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 (partition && (!current || strncmp(current->label, partition, 16) != 0))
138+
{
139+
esp_err_t err = esp_ota_set_boot_partition(esp_partition_find_first(
140+
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, partition));
141+
if (err != ESP_OK)
142+
{
143+
RG_LOGE("esp_ota_set_boot_partition returned 0x%02X!", err);
144+
return false;
145+
}
146+
}
147+
#endif
148+
return true;
149+
}
150+
120151
static void update_memory_statistics(void)
121152
{
122153
#ifdef ESP_PLATFORM
@@ -469,14 +500,11 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
469500
profile->lock = rg_mutex_create();
470501
#endif
471502

472-
#ifdef ESP_PLATFORM
473503
if (app.lowMemoryMode)
474504
rg_gui_alert("External memory not detected", "Boot will continue but it will surely crash...");
475505

476506
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
507+
update_boot_config(RG_APP_LAUNCHER, NULL, NULL, 0);
480508

481509
rg_task_create("rg_sysmon", &system_monitor_task, NULL, 3 * 1024, RG_TASK_PRIORITY_5, -1);
482510
app.initialized = true;
@@ -862,32 +890,10 @@ void rg_system_switch_app(const char *partition, const char *name, const char *a
862890
{
863891
RG_LOGI("Switching to app %s (%s)", partition ?: "-", name ?: "-");
864892

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!");
893+
if (update_boot_config(partition, name, args, flags))
879894
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!");
895+
896+
RG_PANIC("Failed to switch app!");
891897
}
892898

893899
bool rg_system_have_app(const char *app)
@@ -1204,8 +1210,7 @@ static void emu_update_save_slot(uint8_t slot)
12041210
app.bootFlags &= ~RG_BOOT_SLOT_MASK;
12051211
app.bootFlags |= app.saveSlot << 4;
12061212
app.bootFlags |= RG_BOOT_RESUME;
1207-
rg_settings_set_number(NS_BOOT, SETTING_BOOT_FLAGS, app.bootFlags);
1208-
rg_settings_commit();
1213+
update_boot_config(NULL, app.configNs, app.bootArgs, app.bootFlags);
12091214
}
12101215

12111216
rg_storage_commit();

0 commit comments

Comments
 (0)