From d59e8b50d2ea7822daca8dd5cfdf6cde6f0f169f Mon Sep 17 00:00:00 2001 From: Felipe Neves Date: Mon, 27 Jul 2020 14:21:51 -0300 Subject: [PATCH 1/3] freertos: move startup code out of iram memory --- components/freertos/linker.lf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/freertos/linker.lf b/components/freertos/linker.lf index a45fc9e4e0..d5122137c0 100644 --- a/components/freertos/linker.lf +++ b/components/freertos/linker.lf @@ -112,3 +112,6 @@ entries: queue: xQueueAddToSet (default) queue: xQueueRemoveFromSet (default) queue: xQueueSelectFromSet (default) + port:start_app(default) + port:start_app_other_cores(default) + From a1e5dd58b22e60ff4889f8d91437d3019c2927c4 Mon Sep 17 00:00:00 2001 From: Felipe Neves Date: Mon, 27 Jul 2020 15:24:07 -0300 Subject: [PATCH 2/3] startup: moved init core functions out of iram memory --- components/esp_system/linker.lf | 8 +++++++- components/esp_system/startup.c | 12 ++++++------ components/freertos/linker.lf | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/components/esp_system/linker.lf b/components/esp_system/linker.lf index e55780553c..4dd94b6c56 100644 --- a/components/esp_system/linker.lf +++ b/components/esp_system/linker.lf @@ -5,7 +5,13 @@ entries: panic_handler (noflash) reset_reason (noflash) system_api:esp_system_abort (noflash) - + startup:do_secondary_init(default) + startup:start_cpu0_default(default) + startup:do_core_init(default) + startup:do_system_init_fn(default) + startup:start_cpu_other_cores_default(default) + startup:do_global_ctors(default) + if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF: usb_console:esp_usb_console_write_char (noflash) usb_console:esp_usb_console_write_buf (noflash) diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index be2089757e..ee24ed2c03 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -120,7 +120,7 @@ static IRAM_ATTR void _Unwind_SetNoFunctionContextInstall_Default(unsigned char static const char* TAG = "cpu_start"; -static void IRAM_ATTR do_global_ctors(void) +static void do_global_ctors(void) { extern void (*__init_array_start)(void); extern void (*__init_array_end)(void); @@ -140,7 +140,7 @@ static void IRAM_ATTR do_global_ctors(void) } } -static void IRAM_ATTR do_system_init_fn(void) +static void do_system_init_fn(void) { extern esp_system_init_fn_t _esp_system_init_fn_array_start; extern esp_system_init_fn_t _esp_system_init_fn_array_end; @@ -166,7 +166,7 @@ static void IRAM_ATTR start_app_other_cores_default(void) } } -static void IRAM_ATTR start_cpu_other_cores_default(void) +static void start_cpu_other_cores_default(void) { do_system_init_fn(); @@ -178,7 +178,7 @@ static void IRAM_ATTR start_cpu_other_cores_default(void) } #endif -static void IRAM_ATTR do_core_init(void) +static void do_core_init(void) { /* Initialize heap allocator. WARNING: This *needs* to happen *after* the app cpu has booted. If the heap allocator is initialized first, it will put free memory linked list items into @@ -277,7 +277,7 @@ static void IRAM_ATTR do_core_init(void) assert(flash_ret == ESP_OK); } -static void IRAM_ATTR do_secondary_init(void) +static void do_secondary_init(void) { #if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE // The port layer transferred control to this function with other cores 'paused', @@ -304,7 +304,7 @@ static void IRAM_ATTR do_secondary_init(void) #endif } -void IRAM_ATTR start_cpu0_default(void) +void start_cpu0_default(void) { ESP_EARLY_LOGI(TAG, "Pro cpu start user code"); diff --git a/components/freertos/linker.lf b/components/freertos/linker.lf index d5122137c0..60523aded2 100644 --- a/components/freertos/linker.lf +++ b/components/freertos/linker.lf @@ -113,5 +113,6 @@ entries: queue: xQueueRemoveFromSet (default) queue: xQueueSelectFromSet (default) port:start_app(default) + port:main_task(default) port:start_app_other_cores(default) - + port:xPortStartScheduler(default) \ No newline at end of file From e67162a7eae70b1f77f8c99a2d20f400f08048b2 Mon Sep 17 00:00:00 2001 From: Felipe Neves Date: Mon, 31 Aug 2020 14:00:46 -0300 Subject: [PATCH 3/3] startup: namespaced start_app and start_app_other_core to avoid user code collision --- components/esp_system/linker.lf | 7 ------- components/esp_system/startup.c | 12 ++++++------ components/freertos/linker.lf | 7 +++---- components/freertos/xtensa/port.c | 4 ++-- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/components/esp_system/linker.lf b/components/esp_system/linker.lf index 4dd94b6c56..d1c32659ac 100644 --- a/components/esp_system/linker.lf +++ b/components/esp_system/linker.lf @@ -4,13 +4,6 @@ entries: panic (noflash) panic_handler (noflash) reset_reason (noflash) - system_api:esp_system_abort (noflash) - startup:do_secondary_init(default) - startup:start_cpu0_default(default) - startup:do_core_init(default) - startup:do_system_init_fn(default) - startup:start_cpu_other_cores_default(default) - startup:do_global_ctors(default) if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF: usb_console:esp_usb_console_write_char (noflash) diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index ee24ed2c03..8678f6d7be 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -81,7 +81,7 @@ uint64_t g_startup_time = 0; // App entry point for core 0 -extern void start_app(void); +extern void esp_startup_start_app(void); // Entry point for core 0 from hardware init (port layer) void start_cpu0(void) __attribute__((weak, alias("start_cpu0_default"))) __attribute__((noreturn)); @@ -91,7 +91,7 @@ void start_cpu0(void) __attribute__((weak, alias("start_cpu0_default"))) __attri void start_cpu_other_cores(void) __attribute__((weak, alias("start_cpu_other_cores_default"))) __attribute__((noreturn)); // App entry point for core [1..X] -void start_app_other_cores(void) __attribute__((weak, alias("start_app_other_cores_default"))) __attribute__((noreturn)); +void esp_startup_start_app_other_cores(void) __attribute__((weak, alias("esp_startup_start_app_other_cores_default"))) __attribute__((noreturn)); static volatile bool s_system_inited[SOC_CPU_CORES_NUM] = { false }; @@ -159,7 +159,7 @@ static void do_system_init_fn(void) } #if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE -static void IRAM_ATTR start_app_other_cores_default(void) +static void esp_startup_start_app_other_cores_default(void) { while (1) { esp_rom_delay_us(UINT32_MAX); @@ -174,7 +174,7 @@ static void start_cpu_other_cores_default(void) esp_rom_delay_us(100); } - start_app_other_cores(); + esp_startup_start_app_other_cores(); } #endif @@ -304,7 +304,7 @@ static void do_secondary_init(void) #endif } -void start_cpu0_default(void) +static void start_cpu0_default(void) { ESP_EARLY_LOGI(TAG, "Pro cpu start user code"); @@ -353,7 +353,7 @@ void start_cpu0_default(void) s_system_full_inited = true; #endif - start_app(); + esp_startup_start_app(); while (1); } diff --git a/components/freertos/linker.lf b/components/freertos/linker.lf index 60523aded2..f5a6761a5d 100644 --- a/components/freertos/linker.lf +++ b/components/freertos/linker.lf @@ -112,7 +112,6 @@ entries: queue: xQueueAddToSet (default) queue: xQueueRemoveFromSet (default) queue: xQueueSelectFromSet (default) - port:start_app(default) - port:main_task(default) - port:start_app_other_cores(default) - port:xPortStartScheduler(default) \ No newline at end of file + port:main_task (default) + port:esp_startup_start_app (default) + port:esp_startup_start_app_other_cores (default) \ No newline at end of file diff --git a/components/freertos/xtensa/port.c b/components/freertos/xtensa/port.c index 597d1d6471..acd99114dd 100644 --- a/components/freertos/xtensa/port.c +++ b/components/freertos/xtensa/port.c @@ -547,7 +547,7 @@ static void main_task(void* args) #if !CONFIG_FREERTOS_UNICORE -void start_app_other_cores(void) +void esp_startup_start_app_other_cores(void) { // For now, we only support up to two core: 0 and 1. if (xPortGetCoreID() >= 2) { @@ -581,7 +581,7 @@ void start_app_other_cores(void) } #endif -void start_app(void) +void esp_startup_start_app(void) { #if CONFIG_ESP_INT_WDT esp_int_wdt_init();