Skip to content
Snippets Groups Projects
Commit 8ba8ebe1 authored by Renze's avatar Renze
Browse files

Make the firmware unbrickable

parent 6c2d7e47
Branches
Tags
No related merge requests found
...@@ -77,7 +77,7 @@ static int load_stat(char *name) ...@@ -77,7 +77,7 @@ static int load_stat(char *name)
/* A python script */ /* A python script */
return PL_PYTHON_SCRIPT; return PL_PYTHON_SCRIPT;
} else if (strcmp(name + name_len - 4, ".elf") == 0) { } else if (strcmp(name + name_len - 4, ".elf") == 0) {
return PL_L0DABLE; return 0;//PL_L0DABLE; //Dangerous!
} }
return -ENOEXEC; return -ENOEXEC;
...@@ -239,6 +239,54 @@ static int write_default_menu(void) ...@@ -239,6 +239,54 @@ static int write_default_menu(void)
return 0; return 0;
} }
/*
* Embed the main.py script in the Epicardium binary.
*/
__asm(".section \".rodata\"\n"
"_main_script_start:\n"
".incbin \"../preload/main.py\"\n"
"_main_script_end:\n"
".previous\n");
extern const uint8_t _main_script_start;
extern const uint8_t _main_script_end;
static int write_default_main(void)
{
const size_t length =
(uintptr_t)&_main_script_end - (uintptr_t)&_main_script_start;
int ret;
LOG_INFO("lifecycle", "Writing default main ...");
int fd = epic_file_open("main.py", "w");
if (fd < 0) {
return fd;
}
ret = epic_file_write(fd, &_main_script_start, length);
if (ret < 0) {
return ret;
}
ret = epic_file_close(fd);
if (ret < 0) {
return ret;
}
return 0;
}
static void factory_reset(void)
{
LOG_ERR("lifecycle", "Factory reset!");
epic_file_unlink("/main.py");
epic_file_unlink("/menu.py");
epic_file_unlink("/mac.txt");
write_default_menu();
write_default_main();
}
/* /*
* Go back to the menu. * Go back to the menu.
*/ */
...@@ -368,13 +416,17 @@ void vLifecycleTask(void *pvParameters) ...@@ -368,13 +416,17 @@ void vLifecycleTask(void *pvParameters)
xSemaphoreGive(core1_mutex); xSemaphoreGive(core1_mutex);
hardware_init();
if (epic_buttons_read(BUTTON_RIGHT_TOP)) {
factory_reset();
}
/* If `main.py` exists, start it. Otherwise, start `menu.py`. */ /* If `main.py` exists, start it. Otherwise, start `menu.py`. */
if (epic_exec("main.py") < 0) { if (epic_exec("main.py") < 0) {
return_to_menu(); return_to_menu();
} }
hardware_init();
/* When triggered, reset core 1 to menu */ /* When triggered, reset core 1 to menu */
while (1) { while (1) {
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment