From 3e6c6696ef5683ad6bd15af982598d6857df88be Mon Sep 17 00:00:00 2001 From: dongheng Date: Thu, 26 Sep 2019 17:20:03 +0800 Subject: [PATCH] feat(make): add "iram_bss" to link some global varible from DRAM to IRAM --- components/esp8266/CMakeLists.txt | 2 +- components/esp8266/component.mk | 2 +- components/esp8266/ld/esp8266.project.ld.in | 14 +++++++++++++- components/esp8266/ld/esp8266_bss_fragments.lf | 5 +++++ components/esp8266/linker.lf | 6 ++++++ components/esp8266/source/startup.c | 5 +++++ components/freertos/CMakeLists.txt | 1 + components/freertos/component.mk | 2 ++ components/freertos/linker.lf | 5 +++++ components/lwip/CMakeLists.txt | 2 ++ components/lwip/component.mk | 2 ++ components/lwip/linker.lf | 5 +++++ 12 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 components/esp8266/ld/esp8266_bss_fragments.lf create mode 100644 components/freertos/linker.lf create mode 100644 components/lwip/linker.lf diff --git a/components/esp8266/CMakeLists.txt b/components/esp8266/CMakeLists.txt index 78d4ee5d..0679138a 100644 --- a/components/esp8266/CMakeLists.txt +++ b/components/esp8266/CMakeLists.txt @@ -52,7 +52,7 @@ else() set(include_dirs "include" "include/driver") set(priv_requires "wpa_supplicant" "log" "spi_flash" "tcpip_adapter" "esp_ringbuf" "bootloader_support" "nvs_flash" "util") - set(fragments linker.lf ld/esp8266_fragments.lf) + set(fragments linker.lf ld/esp8266_fragments.lf ld/esp8266_bss_fragments.lf) idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" diff --git a/components/esp8266/component.mk b/components/esp8266/component.mk index 75f35156..4cb89d13 100644 --- a/components/esp8266/component.mk +++ b/components/esp8266/component.mk @@ -25,7 +25,7 @@ endif #specifies its own scripts. LINKER_SCRIPTS += esp8266.rom.ld esp8266.peripherals.ld -COMPONENT_ADD_LDFRAGMENTS += ld/esp8266_fragments.lf linker.lf +COMPONENT_ADD_LDFRAGMENTS += ld/esp8266_fragments.lf ld/esp8266_bss_fragments.lf linker.lf COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/lib \ $(addprefix -l,$(LIBS)) \ diff --git a/components/esp8266/ld/esp8266.project.ld.in b/components/esp8266/ld/esp8266.project.ld.in index 063bc45a..9c42c682 100644 --- a/components/esp8266/ld/esp8266.project.ld.in +++ b/components/esp8266/ld/esp8266.project.ld.in @@ -81,10 +81,22 @@ SECTIONS mapping[iram0_text] _iram_text_end = ABSOLUTE(.); + } > iram0_0_seg + + .iram0.bss : + { + . = ALIGN (4); + /* Code marked as runnning out of IRAM */ + _iram_bss_start = ABSOLUTE(.); + + mapping[iram0_bss] + + . = ALIGN (4); + _iram_bss_end = ABSOLUTE(.); _iram_end = ABSOLUTE(.); } > iram0_0_seg - ASSERT(((_iram_text_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), + ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), "IRAM0 segment data does not fit.") .dram0.data : diff --git a/components/esp8266/ld/esp8266_bss_fragments.lf b/components/esp8266/ld/esp8266_bss_fragments.lf new file mode 100644 index 00000000..a69ce694 --- /dev/null +++ b/components/esp8266/ld/esp8266_bss_fragments.lf @@ -0,0 +1,5 @@ + +[scheme:iram_bss] +entries: + bss -> iram0_bss + common -> iram0_bss diff --git a/components/esp8266/linker.lf b/components/esp8266/linker.lf index fdd63250..f7090f77 100644 --- a/components/esp8266/linker.lf +++ b/components/esp8266/linker.lf @@ -14,3 +14,9 @@ entries: archive: libphy.a entries: * (noflash_text) + +[mapping:core] +archive: libcore.a +entries: + if ESP8266_CORE_GLOBAL_DATA_LINK_IRAM = y: + * (iram_bss) diff --git a/components/esp8266/source/startup.c b/components/esp8266/source/startup.c index fc8e8215..89ef3d81 100644 --- a/components/esp8266/source/startup.c +++ b/components/esp8266/source/startup.c @@ -116,6 +116,7 @@ void call_start_cpu(size_t start_addr) int *p; extern int _bss_start, _bss_end; + extern int _iram_bss_start, _iram_bss_end; esp_image_header_t *head = (esp_image_header_t *)(FLASH_BASE + (start_addr & (FLASH_SIZE - 1))); esp_image_segment_header_t *segment = (esp_image_segment_header_t *)((uintptr_t)head + sizeof(esp_image_header_t)); @@ -154,6 +155,10 @@ void call_start_cpu(size_t start_addr) for (p = &_bss_start; p < &_bss_end; p++) *p = 0; + /* clear iram_bss data */ + for (p = &_iram_bss_start; p < &_iram_bss_end; p++) + *p = 0; + __asm__ __volatile__( "rsil a2, 2\n" "movi a1, _chip_interrupt_tmp\n" diff --git a/components/freertos/CMakeLists.txt b/components/freertos/CMakeLists.txt index 3358175d..05047cb3 100644 --- a/components/freertos/CMakeLists.txt +++ b/components/freertos/CMakeLists.txt @@ -1,5 +1,6 @@ set(COMPONENT_ADD_INCLUDEDIRS include include/freertos include/freertos/private port/esp8266/include port/esp8266/include/freertos) set(COMPONENT_SRCDIRS "freertos" "port/esp8266") +set(COMPONENT_ADD_LDFRAGMENTS "linker.lf") register_component() diff --git a/components/freertos/component.mk b/components/freertos/component.mk index 770c78c9..37bf3831 100644 --- a/components/freertos/component.mk +++ b/components/freertos/component.mk @@ -12,3 +12,5 @@ COMPONENT_SRCDIRS := port/esp8266 ifndef CONFIG_DISABLE_FREERTOS COMPONENT_SRCDIRS += freertos endif + +COMPONENT_ADD_LDFRAGMENTS += linker.lf diff --git a/components/freertos/linker.lf b/components/freertos/linker.lf new file mode 100644 index 00000000..3d20805d --- /dev/null +++ b/components/freertos/linker.lf @@ -0,0 +1,5 @@ +[mapping:freertos] +archive: libfreertos.a +entries: + if FREERTOS_GLOBAL_DATA_LINK_IRAM = y: + * (iram_bss) diff --git a/components/lwip/CMakeLists.txt b/components/lwip/CMakeLists.txt index 8f02bad3..c526ed03 100644 --- a/components/lwip/CMakeLists.txt +++ b/components/lwip/CMakeLists.txt @@ -32,6 +32,8 @@ endif() set(COMPONENT_REQUIRES vfs) set(COMPONENT_PRIV_REQUIRES tcpip_adapter) +set(COMPONENT_ADD_LDFRAGMENTS "linker.lf") + register_component() component_compile_options(-Wno-address) diff --git a/components/lwip/component.mk b/components/lwip/component.mk index e7233b79..3950140b 100644 --- a/components/lwip/component.mk +++ b/components/lwip/component.mk @@ -24,6 +24,8 @@ ifdef CONFIG_USING_ESP_VFS COMPONENT_SRCDIRS += port endif +COMPONENT_ADD_LDFRAGMENTS += linker.lf + CFLAGS += -Wno-address #lots of LWIP source files evaluate macros that check address of stack variables lwip/src/apps/sntp/sntp.o: CFLAGS += -Wno-implicit-function-declaration diff --git a/components/lwip/linker.lf b/components/lwip/linker.lf new file mode 100644 index 00000000..bad3a479 --- /dev/null +++ b/components/lwip/linker.lf @@ -0,0 +1,5 @@ +[mapping:lwip] +archive: liblwip.a +entries: + if LWIP_GLOBAL_DATA_LINK_IRAM = y: + * (iram_bss)