diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index f5e1fe2cb4..61b119d822 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -26,7 +26,7 @@ else() # esp_timer is added here because cpu_start.c uses esp_timer set(priv_requires app_trace app_update bootloader_support esp_system log mbedtls nvs_flash pthread spi_flash vfs espcoredump esp_common perfmon esp_timer esp_ipc esp_pm) - set(fragments linker.lf ld/esp32_fragments.lf) + set(fragments linker.lf) idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" diff --git a/components/esp32/component.mk b/components/esp32/component.mk index 8eed73f91e..7c65594384 100644 --- a/components/esp32/component.mk +++ b/components/esp32/component.mk @@ -17,7 +17,7 @@ COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/ld \ -u ld_include_panic_highint_hdl \ $(addprefix -T ,$(LINKER_SCRIPTS)) \ -COMPONENT_ADD_LDFRAGMENTS += ld/esp32_fragments.lf linker.lf +COMPONENT_ADD_LDFRAGMENTS += linker.lf # final linking of project ELF depends on all binary libraries, and # all linker scripts (except esp32_out.ld, as this is code generated here.) diff --git a/components/esp32/ld/esp32_fragments.lf b/components/esp32/ld/esp32_fragments.lf deleted file mode 100644 index 48e15baca5..0000000000 --- a/components/esp32/ld/esp32_fragments.lf +++ /dev/null @@ -1,120 +0,0 @@ -[sections:text] -entries: - .text+ - .literal+ - -[sections:data] -entries: - .data+ - -[sections:bss] -entries: - .bss+ - -[sections:common] -entries: - COMMON - -[sections:legacy_bss] -entries: - .dynsbss - .sbss+ - .gnu.linkonce.sb+ - .scommon - .sbss2+ - .gnu.linkonce.sb2+ - .dynbss - .share.mem - .gnu.linkonce.b+ - -[sections:rodata] -entries: - .rodata+ - -[sections:rtc_text] -entries: - .rtc.text+ - .rtc.literal - -[sections:rtc_data] -entries: - .rtc.data+ - -[sections:rtc_rodata] -entries: - .rtc.rodata+ - -[sections:rtc_bss] -entries: - .rtc.bss - -[sections:iram] -entries: - .iram1+ - -[sections:iram_data] -entries: - .iram.data+ - -[sections:iram_bss] -entries: - .iram.bss+ - -[sections:extram_bss] -entries: - .ext_ram.bss+ - -[sections:dram] -entries: - .dram1+ - -[scheme:default] -entries: - if APP_BUILD_USE_FLASH_SECTIONS = y: - text -> flash_text - rodata -> flash_rodata - else: - text -> iram0_text - rodata -> dram0_data - data -> dram0_data - bss -> dram0_bss - common -> dram0_bss - if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: - extram_bss -> extern_ram - else: - extram_bss -> dram0_bss - legacy_bss -> dram0_bss - iram -> iram0_text - iram_data -> iram0_data - iram_bss -> iram0_bss - dram -> dram0_data - rtc_text -> rtc_text - rtc_data -> rtc_data - rtc_rodata -> rtc_data - rtc_bss -> rtc_bss - -[scheme:rtc] -entries: - text -> rtc_text - data -> rtc_data - rodata -> rtc_data - bss -> rtc_bss - common -> rtc_bss - -[scheme:noflash] -entries: - text -> iram0_text - rodata -> dram0_data - -[scheme:noflash_data] -entries: - rodata -> dram0_data - -[scheme:noflash_text] -entries: - text -> iram0_text - -[mapping:default] -archive: * -entries: - * (default) diff --git a/components/esp32c3/CMakeLists.txt b/components/esp32c3/CMakeLists.txt index fb12a45134..1bcac4332b 100644 --- a/components/esp32c3/CMakeLists.txt +++ b/components/esp32c3/CMakeLists.txt @@ -27,7 +27,7 @@ else() app_trace app_update bootloader_support log mbedtls nvs_flash pthread spi_flash vfs espcoredump esp_common esp_timer) - set(fragments linker.lf ld/esp32c3_fragments.lf) + set(fragments linker.lf) idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" diff --git a/components/esp32c3/ld/esp32c3_fragments.lf b/components/esp32c3/ld/esp32c3_fragments.lf deleted file mode 100644 index feea1ec538..0000000000 --- a/components/esp32c3/ld/esp32c3_fragments.lf +++ /dev/null @@ -1,99 +0,0 @@ -[sections:text] -entries: - .text+ - .literal+ - -[sections:data] -entries: - .data+ - -[sections:bss] -entries: - .bss+ - -[sections:common] -entries: - COMMON - -[sections:rodata] -entries: - .rodata+ - -[sections:rtc_text] -entries: - .rtc.text+ - .rtc.literal - -[sections:rtc_data] -entries: - .rtc.data+ - -[sections:rtc_rodata] -entries: - .rtc.rodata+ - -[sections:rtc_bss] -entries: - .rtc.bss - -[sections:iram] -entries: - .iram1+ - -[sections:iram_data] -entries: - .iram.data+ - -[sections:iram_bss] -entries: - .iram.bss+ - -[sections:dram] -entries: - .dram1+ - -[scheme:default] -entries: - if APP_BUILD_USE_FLASH_SECTIONS = y: - text -> flash_text - rodata -> flash_rodata - else: - text -> iram0_text - rodata -> dram0_data - data -> dram0_data - bss -> dram0_bss - common -> dram0_bss - iram -> iram0_text - iram_data -> iram0_data - iram_bss -> iram0_bss - dram -> dram0_data - rtc_text -> rtc_text - rtc_data -> rtc_data - rtc_rodata -> rtc_data - rtc_bss -> rtc_bss - -[scheme:rtc] -entries: - text -> rtc_text - data -> rtc_data - rodata -> rtc_data - bss -> rtc_bss - common -> rtc_bss - -[scheme:noflash] -entries: - text -> iram0_text - rodata -> dram0_data - -[scheme:noflash_data] -entries: - rodata -> dram0_data - -[scheme:noflash_text] -entries: - text -> iram0_text - -[mapping:default] -archive: * -entries: - * (default) diff --git a/components/esp32s2/CMakeLists.txt b/components/esp32s2/CMakeLists.txt index 6cf09ac6f5..82afdc8392 100644 --- a/components/esp32s2/CMakeLists.txt +++ b/components/esp32s2/CMakeLists.txt @@ -29,7 +29,7 @@ else() app_trace app_update bootloader_support esp_system log mbedtls nvs_flash pthread spi_flash vfs espcoredump esp_common esp_timer) - set(fragments linker.lf ld/esp32s2_fragments.lf) + set(fragments linker.lf) idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" diff --git a/components/esp32s3/CMakeLists.txt b/components/esp32s3/CMakeLists.txt index dde455bbf9..20d35aef25 100644 --- a/components/esp32s3/CMakeLists.txt +++ b/components/esp32s3/CMakeLists.txt @@ -26,7 +26,7 @@ else() # esp_timer is added here because cpu_start.c uses esp_timer set(priv_requires app_trace app_update bootloader_support log mbedtls nvs_flash pthread spi_flash vfs espcoredump esp_common perfmon esp_timer esp_ipc) - set(fragments linker.lf ld/esp32s3_fragments.lf) + set(fragments linker.lf) idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" diff --git a/components/esp32s3/ld/esp32s3_fragments.lf b/components/esp32s3/ld/esp32s3_fragments.lf deleted file mode 100644 index feea1ec538..0000000000 --- a/components/esp32s3/ld/esp32s3_fragments.lf +++ /dev/null @@ -1,99 +0,0 @@ -[sections:text] -entries: - .text+ - .literal+ - -[sections:data] -entries: - .data+ - -[sections:bss] -entries: - .bss+ - -[sections:common] -entries: - COMMON - -[sections:rodata] -entries: - .rodata+ - -[sections:rtc_text] -entries: - .rtc.text+ - .rtc.literal - -[sections:rtc_data] -entries: - .rtc.data+ - -[sections:rtc_rodata] -entries: - .rtc.rodata+ - -[sections:rtc_bss] -entries: - .rtc.bss - -[sections:iram] -entries: - .iram1+ - -[sections:iram_data] -entries: - .iram.data+ - -[sections:iram_bss] -entries: - .iram.bss+ - -[sections:dram] -entries: - .dram1+ - -[scheme:default] -entries: - if APP_BUILD_USE_FLASH_SECTIONS = y: - text -> flash_text - rodata -> flash_rodata - else: - text -> iram0_text - rodata -> dram0_data - data -> dram0_data - bss -> dram0_bss - common -> dram0_bss - iram -> iram0_text - iram_data -> iram0_data - iram_bss -> iram0_bss - dram -> dram0_data - rtc_text -> rtc_text - rtc_data -> rtc_data - rtc_rodata -> rtc_data - rtc_bss -> rtc_bss - -[scheme:rtc] -entries: - text -> rtc_text - data -> rtc_data - rodata -> rtc_data - bss -> rtc_bss - common -> rtc_bss - -[scheme:noflash] -entries: - text -> iram0_text - rodata -> dram0_data - -[scheme:noflash_data] -entries: - rodata -> dram0_data - -[scheme:noflash_text] -entries: - text -> iram0_text - -[mapping:default] -archive: * -entries: - * (default) diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index bcb16a907e..1d10d6e646 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -5,7 +5,8 @@ list(APPEND srcs "src/esp_err_to_name.c") # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. idf_component_register(SRCS "${srcs}" INCLUDE_DIRS include - REQUIRES ${target}) + REQUIRES ${target} + LDFRAGMENTS "common.lf" "soc.lf") set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 4) diff --git a/components/esp_common/common.lf b/components/esp_common/common.lf new file mode 100644 index 0000000000..afbb997e68 --- /dev/null +++ b/components/esp_common/common.lf @@ -0,0 +1,34 @@ +# Sections emitted by compiler by default. + +[sections:text] +entries: + .text+ + .literal+ + +[sections:data] +entries: + .data+ + +[sections:bss] +entries: + .bss+ + +[sections:common] +entries: + COMMON + +[sections:legacy_bss] +entries: + .dynsbss + .sbss+ + .gnu.linkonce.sb+ + .scommon + .sbss2+ + .gnu.linkonce.sb2+ + .dynbss + .share.mem + .gnu.linkonce.b+ + +[sections:rodata] +entries: + .rodata+ diff --git a/components/esp_common/component.mk b/components/esp_common/component.mk index ea720ca509..7ce3ea3b6e 100644 --- a/components/esp_common/component.mk +++ b/components/esp_common/component.mk @@ -4,3 +4,5 @@ COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_SRCDIRS := src + +COMPONENT_ADD_LDFRAGMENTS += common.lf soc.lf diff --git a/components/esp_common/soc.lf b/components/esp_common/soc.lf new file mode 100644 index 0000000000..46193323e5 --- /dev/null +++ b/components/esp_common/soc.lf @@ -0,0 +1,43 @@ +# Sections that can be placed in memory regions common +# to supported SoCs. This is here since some of counterpart attributes +# are in esp_attr.h. +# +# Ideally esp_attr.h would be split between this component and `soc`. +# Those moved to `soc` are the counterpart attributes to these sections. + +[sections:rtc_text] +entries: + .rtc.text+ + .rtc.literal + +[sections:rtc_data] +entries: + .rtc.data+ + +[sections:rtc_rodata] +entries: + .rtc.rodata+ + +[sections:rtc_bss] +entries: + .rtc.bss + +[sections:iram] +entries: + .iram1+ + +[sections:iram_data] +entries: + .iram.data+ + +[sections:iram_bss] +entries: + .iram.bss+ + +[sections:dram] +entries: + .dram1+ + +[sections:extram_bss] +entries: + .ext_ram.bss+ diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index f08e901ddb..2cde7bff29 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -36,7 +36,7 @@ else() # link-time registration is used. esp_pm app_update nvs_flash pthread app_trace esp_gdbstub esp_ipc espcoredump - LDFRAGMENTS "linker.lf") + LDFRAGMENTS "linker.lf" "app.lf") add_subdirectory(port) # After system initialization, `start_app` (and its other cores variant) is called. diff --git a/components/esp32s2/ld/esp32s2_fragments.lf b/components/esp_system/app.lf similarity index 61% rename from components/esp32s2/ld/esp32s2_fragments.lf rename to components/esp_system/app.lf index 65f93737a9..15484115d0 100644 --- a/components/esp32s2/ld/esp32s2_fragments.lf +++ b/components/esp_system/app.lf @@ -1,49 +1,3 @@ -[sections:text] -entries: - .text+ - .literal+ - -[sections:data] -entries: - .data+ - -[sections:bss] -entries: - .bss+ - -[sections:common] -entries: - COMMON - -[sections:rodata] -entries: - .rodata+ - -[sections:rtc_text] -entries: - .rtc.text+ - .rtc.literal - -[sections:rtc_data] -entries: - .rtc.data+ - -[sections:rtc_rodata] -entries: - .rtc.rodata+ - -[sections:rtc_bss] -entries: - .rtc.bss - -[sections:iram] -entries: - .iram1+ - -[sections:dram] -entries: - .dram1+ - [scheme:default] entries: if APP_BUILD_USE_FLASH_SECTIONS = y: @@ -55,7 +9,14 @@ entries: data -> dram0_data bss -> dram0_bss common -> dram0_bss + if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: + extram_bss -> extern_ram + else: + extram_bss -> dram0_bss + legacy_bss -> dram0_bss iram -> iram0_text + iram_data -> iram0_data + iram_bss -> iram0_bss dram -> dram0_data rtc_text -> rtc_text rtc_data -> rtc_data diff --git a/components/esp_system/component.mk b/components/esp_system/component.mk index e6a0693ae7..4c25426b64 100644 --- a/components/esp_system/component.mk +++ b/components/esp_system/component.mk @@ -13,7 +13,7 @@ SOC_NAME := $(IDF_TARGET) COMPONENT_SRCDIRS := . COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_PRIV_INCLUDEDIRS := port/include port -COMPONENT_ADD_LDFRAGMENTS += linker.lf +COMPONENT_ADD_LDFRAGMENTS += linker.lf app.lf ifndef CONFIG_IDF_ENV_FPGA COMPONENT_OBJEXCLUDE += fpga_overrides.o diff --git a/components/soc/CMakeLists.txt b/components/soc/CMakeLists.txt index 6fc84323bb..a86afd16a1 100644 --- a/components/soc/CMakeLists.txt +++ b/components/soc/CMakeLists.txt @@ -2,7 +2,7 @@ idf_component_register(SRCS "lldesc.c" "soc_include_legacy_warn.c" "memory_layout_utils.c" INCLUDE_DIRS include - LDFRAGMENTS linker.lf) + LDFRAGMENTS "linker.lf") idf_build_get_property(target IDF_TARGET) add_subdirectory(${target}) diff --git a/docs/en/api-guides/linker-script-generation.rst b/docs/en/api-guides/linker-script-generation.rst index da9d01091f..4dbc2ef611 100644 --- a/docs/en/api-guides/linker-script-generation.rst +++ b/docs/en/api-guides/linker-script-generation.rst @@ -388,7 +388,10 @@ There exists a special scheme with the name ``default``. This scheme is special These catch-all rules then effectively serve as fallback rules for those whose mappings were not specified. -The ``default scheme`` is defined in :component_file:`{IDF_TARGET_PATH_NAME}/ld/{IDF_TARGET_PATH_NAME}_fragments.lf`. The ``noflash`` and ``rtc`` scheme fragments which are built-in schemes referenced in the quick start guide are also defined in this file. + +The ``default scheme`` is defined in :component_file:`esp_system/app.lf`. The ``noflash`` and ``rtc`` scheme fragments which are +built-in schemes referenced in the quick start guide are also defined in this file. + .. _ldgen-mapping-fragment : diff --git a/docs/zh_CN/api-guides/linker-script-generation.rst b/docs/zh_CN/api-guides/linker-script-generation.rst index 84212f414d..0327cf935f 100644 --- a/docs/zh_CN/api-guides/linker-script-generation.rst +++ b/docs/zh_CN/api-guides/linker-script-generation.rst @@ -388,7 +388,7 @@ ESP-IDF v4.0 变更了链接器脚本片段文件使用的一些语法: 这些生成的包罗规则将用于未指定映射规则的情况。 -``默认`` 协议在 :component_file:`{IDF_TARGET_PATH_NAME}/ld/{IDF_TARGET_PATH_NAME}_fragments.lf` 文件中定义,快速上手指南中提到的内置 ``noflash`` 协议和 ``rtc`` 协议也在该文件中定义。 +``默认`` 协议在 :component_file:`esp_system/app.lf` 文件中定义,快速上手指南中提到的内置 ``noflash`` 协议和 ``rtc`` 协议也在该文件中定义。 .. _ldgen-mapping-fragment : diff --git a/tools/ci/test_build_system.sh b/tools/ci/test_build_system.sh index 3c8298a7f8..99454f78c1 100755 --- a/tools/ci/test_build_system.sh +++ b/tools/ci/test_build_system.sh @@ -167,7 +167,7 @@ function run_tests() print_status "Touching a linker fragment file should trigger re-link of app" # only app linker script is generated by tool for now take_build_snapshot - touch ${IDF_PATH}/components/esp32/linker.lf + touch ${IDF_PATH}/components/esp_common/common.lf make assert_rebuilt ${APP_BINS} assert_not_rebuilt ${BOOTLOADER_BINS} diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index a1b91bb9fa..66697552b1 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -230,13 +230,13 @@ function run_tests() print_status "Updating fragment file should only re-link app" # only app linker script is generated by tool for now take_build_snapshot - cp ${IDF_PATH}/components/esp32/ld/esp32_fragments.lf . + cp ${IDF_PATH}/components/esp_common/common.lf . sleep 1 # ninja may ignore if the timestamp delta is too low - echo "# (Build test comment)" >> ${IDF_PATH}/components/esp32/ld/esp32_fragments.lf + echo "# (Build test comment)" >> ${IDF_PATH}/components/esp_common/common.lf idf.py build || failure "Failed to rebuild with modified linker fragment file" assert_rebuilt ${APP_BINS} assert_not_rebuilt ${BOOTLOADER_BINS} - mv esp32_fragments.lf ${IDF_PATH}/components/esp32/ld/ + mv common.lf ${IDF_PATH}/components/esp_common print_status "sdkconfig update triggers full recompile" clean_build_dir