Skip to content

Commit

Permalink
rg_sytem: update_boot_config
Browse files Browse the repository at this point in the history
  • Loading branch information
ducalex committed Nov 30, 2024
1 parent e313c55 commit f2d4a67
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions components/retro-go/rg_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ IRAM_ATTR void esp_panic_putchar_hook(char c)
logbuf_putc(&panicTrace, c);
}

static bool update_boot_config(const char *part, const char *name, const char *args, uint32_t flags)
{
if (app.initialized)
{
rg_settings_set_string(NS_BOOT, SETTING_BOOT_NAME, name);
rg_settings_set_string(NS_BOOT, SETTING_BOOT_ARGS, args);
rg_settings_set_number(NS_BOOT, SETTING_BOOT_FLAGS, flags);
rg_settings_commit();
}
else
{
rg_storage_delete(RG_BASE_PATH_CONFIG "/boot.json");
}
#if defined(ESP_PLATFORM)
// Check if the OTA settings are already correct, and if so do not call esp_ota_set_boot_partition
// This is simply to avoid an unecessary flash write...
const esp_partition_t *current = esp_ota_get_boot_partition();
if (current && part && strncmp(current->label, part, 16) == 0)
{
RG_LOGI("Boot partition already set to desired app!");
return true;
}
esp_err_t err = esp_ota_set_boot_partition(esp_partition_find_first(
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, part));
if (err != ESP_OK)
{
RG_LOGE("esp_ota_set_boot_partition returned 0x%02X!", err);
return false;
}
#endif
return true;
}

static void update_memory_statistics(void)
{
#ifdef ESP_PLATFORM
Expand Down Expand Up @@ -469,14 +502,11 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
profile->lock = rg_mutex_create();
#endif

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

if (app.bootFlags & RG_BOOT_ONCE)
esp_ota_set_boot_partition(esp_partition_find_first(
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, RG_APP_LAUNCHER));
#endif
update_boot_config(RG_APP_LAUNCHER, NULL, NULL, 0);

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

if (app.initialized)
{
rg_settings_set_string(NS_BOOT, SETTING_BOOT_NAME, name);
rg_settings_set_string(NS_BOOT, SETTING_BOOT_ARGS, args);
rg_settings_set_number(NS_BOOT, SETTING_BOOT_FLAGS, flags);
rg_settings_commit();
}
#if defined(ESP_PLATFORM)
// Check if the OTA settings are already correct, and if so do not call esp_ota_set_boot_partition
// This is simply to avoid an unecessary flash write...
const esp_partition_t *current = esp_ota_get_boot_partition();
if (current && partition && strncmp(current->label, partition, 16) == 0)
{
RG_LOGI("Boot partition already set to desired app!");
if (update_boot_config(partition, name, args, flags))
rg_system_restart();
}
esp_err_t err = esp_ota_set_boot_partition(esp_partition_find_first(
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, partition));
if (err != ESP_OK)
{
RG_LOGE("esp_ota_set_boot_partition returned 0x%02X!", err);
RG_PANIC("Unable to set boot app!");
}
rg_system_restart();
#endif
RG_PANIC("Switch not implemented!");

RG_PANIC("Failed to switch app!");
}

bool rg_system_have_app(const char *app)
Expand Down

0 comments on commit f2d4a67

Please sign in to comment.