diff --git a/epicardium/api/control.c b/epicardium/api/control.c index 9302eb5e6debc07cbd9cfa1ff4fc04c80ebcbf8c..e11037b4f2ad9ffbecc3bd23e8369551dca4336c 100644 --- a/epicardium/api/control.c +++ b/epicardium/api/control.c @@ -199,11 +199,14 @@ void core1_boot(void) core1_start(&core1_initial_ivt); } -void core1_reset(void) +void core1_trigger_reset(void) { /* Signal core 1 that we intend to load a new payload. */ api_interrupt_trigger(EPIC_INT_RESET); +} +void core1_wait_ready(void) +{ /* Wait for the core to accept */ while (1) { while (SEMA_GetSema(_CONTROL_SEMAPHORE) == E_BUSY) { diff --git a/epicardium/api/dispatcher.h b/epicardium/api/dispatcher.h index 2299f54df34f5ac0d13e187de1bb712ae2af1b34..4b79095ea530aa8b06cd1bf71d5d5b91972eb049 100644 --- a/epicardium/api/dispatcher.h +++ b/epicardium/api/dispatcher.h @@ -37,7 +37,10 @@ void api_prepare_args(char *args); void core1_boot(void); /* Reset core 1 into a state where it can accept a new payload */ -void core1_reset(void); +void core1_trigger_reset(void); + +/* Wait for core 1 to respond that it is ready for a new payload */ +void core1_wait_ready(void); /* Load a payload into core 1 */ void core1_load(void *ivt, char *args); diff --git a/epicardium/modules/lifecycle.c b/epicardium/modules/lifecycle.c index 859681543ae5ff23d1b31ae7b396a75f66376c64..b3ce83c1862b09ea4f2e095c1031f67357bce982 100644 --- a/epicardium/modules/lifecycle.c +++ b/epicardium/modules/lifecycle.c @@ -2,6 +2,7 @@ #include "modules/log.h" #include "modules/modules.h" #include "api/dispatcher.h" +#include "api/interrupt-sender.h" #include "l0der/l0der.h" #include "card10.h" @@ -87,6 +88,9 @@ static int load_stat(char *name) */ static int do_load(struct load_info *info) { + struct l0dable_info l0dable; + int res; + if (*info->name == '\0') { LOG_INFO("lifecycle", "Loading Python interpreter ..."); } else { @@ -100,11 +104,21 @@ static int do_load(struct load_info *info) if (info->do_reset) { LOG_DEBUG("lifecycle", "Triggering core 1 reset."); - core1_reset(); - api_dispatcher_init(); + core1_trigger_reset(); } + /* + * Wait for the core to become ready to accept a new payload. + */ + core1_wait_ready(); + + /* + * Reinitialize API + */ + api_dispatcher_init(); + api_interrupt_init(); + switch (info->type) { case PL_PYTHON_SCRIPT: case PL_PYTHON_DIR: @@ -112,14 +126,7 @@ static int do_load(struct load_info *info) core1_load(PYCARDIUM_IVT, info->name); break; case PL_L0DABLE: - /* - * Always reset when loading a l0dable to make sure the memory - * space is absolutely free. - */ - core1_reset(); - - struct l0dable_info l0dable; - int res = l0der_load_path(info->name, &l0dable); + res = l0der_load_path(info->name, &l0dable); if (res != 0) { LOG_ERR("lifecycle", "l0der failed: %d\n", res); xSemaphoreGive(api_mutex);