Преглед на файлове

esp32: move app linker scripts

Renz Bagaporo преди 4 години
родител
ревизия
b06dba7823

+ 0 - 26
components/esp32/CMakeLists.txt

@@ -14,29 +14,3 @@ idf_component_register(INCLUDE_DIRS include
                        REQUIRED_IDF_TARGETS esp32)
 
 target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
-
-if(NOT BOOTLOADER_BUILD)
-    idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
-    target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
-
-    # Process the template file through the linker script generation mechanism, and use the output for linking the
-    # final binary
-    target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"
-                        PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32.project.ld")
-
-    target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
-
-    idf_build_get_property(config_dir CONFIG_DIR)
-    # Preprocess esp32.ld linker script to include configuration, becomes esp32_out.ld
-    set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
-    add_custom_command(
-        OUTPUT esp32_out.ld
-        COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32_out.ld -I ${config_dir} ${LD_DIR}/esp32.ld
-        MAIN_DEPENDENCY ${LD_DIR}/esp32.ld
-        DEPENDS ${sdkconfig_header}
-        COMMENT "Generating linker script..."
-        VERBATIM)
-
-    add_custom_target(esp32_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld)
-    add_dependencies(${COMPONENT_LIB} esp32_linker_script)
-endif()

+ 0 - 6
components/esp32/Makefile.projbuild

@@ -1,6 +0,0 @@
-ESP32_LINKER_SCRIPT_TEMPLATE := $(COMPONENT_PATH)/ld/esp32.project.ld.in
-ESP32_LINKER_SCRIPT_OUTPUT_DIR := $(realpath $(BUILD_DIR_BASE)/esp32)
-
-# Target to generate linker script generator from fragments presented by each of
-# the components
-$(eval $(call ldgen_process_template, $(ESP32_LINKER_SCRIPT_TEMPLATE), $(ESP32_LINKER_SCRIPT_OUTPUT_DIR)/esp32.project.ld))

+ 2 - 30
components/esp32/component.mk

@@ -2,33 +2,5 @@
 # Component Makefile
 #
 
-COMPONENT_SRCDIRS := .
-
-#Linker scripts used to link the final application.
-#Warning: These linker scripts are only used when the normal app is compiled; the bootloader
-#specifies its own scripts.
-LINKER_SCRIPTS += $(COMPONENT_BUILD_DIR)/esp32.project.ld esp32.peripherals.ld
-
-#ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
-#linker will ignore panic_highint_hdl.S as it has no other files depending on any
-#symbols in it.
-COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/ld \
-                         -T esp32_out.ld \
-                         -u ld_include_panic_highint_hdl \
-                         $(addprefix -T ,$(LINKER_SCRIPTS)) \
-
-# final linking of project ELF depends on all binary libraries, and
-# all linker scripts (except esp32_out.ld, as this is code generated here.)
-COMPONENT_ADD_LINKER_DEPS := $(addprefix ld/, $(filter-out $(COMPONENT_BUILD_DIR)/esp32.project.ld, $(LINKER_SCRIPTS))) \
-                            $(COMPONENT_BUILD_DIR)/esp32.project.ld
-
-# Preprocess esp32.ld linker script into esp32_out.ld
-#
-# The library doesn't really depend on esp32_out.ld, but it
-# saves us from having to add the target to a Makefile.projbuild
-$(COMPONENT_LIBRARY): esp32_out.ld
-
-esp32_out.ld: $(COMPONENT_PATH)/ld/esp32.ld ../include/sdkconfig.h
-	$(CC) -I ../include -C -P -x c -E $< -o $@
-
-COMPONENT_EXTRA_CLEAN := esp32_out.ld $(COMPONENT_BUILD_DIR)/esp32.project.ld
+COMPONENT_ADD_LINKER_DEPS := $(COMPONENT_PATH) ld/esp32.peripherals.ld
+COMPONENT_ADD_LDFLAGS := -T $(COMPONENT_PATH)/ld/esp32.peripherals.ld

+ 0 - 24
components/esp32c3/CMakeLists.txt

@@ -14,27 +14,3 @@ idf_component_register(INCLUDE_DIRS include
                        REQUIRED_IDF_TARGETS esp32c3)
 
 target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32c3.peripherals.ld")
-
-if(NOT BOOTLOADER_BUILD)
-    target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32c3_out.ld")
-
-    # Process the template file through the linker script generation mechanism, and use the output for linking the
-    # final binary
-    target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.project.ld.in"
-            PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32c3.project.ld")
-    target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32c3.peripherals.ld")
-
-    idf_build_get_property(config_dir CONFIG_DIR)
-    # Preprocess esp32c3.ld linker script to include configuration, becomes esp32c3_out.ld
-    set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
-    add_custom_command(
-        OUTPUT esp32c3_out.ld
-        COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32c3_out.ld -I ${config_dir} ${LD_DIR}/esp32c3.ld
-        MAIN_DEPENDENCY ${LD_DIR}/esp32c3.ld
-        DEPENDS ${sdkconfig_header}
-        COMMENT "Generating linker script..."
-        VERBATIM)
-
-    add_custom_target(esp32c3_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32c3_out.ld)
-    add_dependencies(${COMPONENT_LIB} esp32c3_linker_script)
-endif()

+ 0 - 27
components/esp32s2/CMakeLists.txt

@@ -14,30 +14,3 @@ idf_component_register(INCLUDE_DIRS include
                        REQUIRED_IDF_TARGETS esp32s2)
 
 target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s2.peripherals.ld")
-
-if(NOT BOOTLOADER_BUILD)
-    idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
-    target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32s2_out.ld")
-
-    # Process the template file through the linker script generation mechanism, and use the output for linking the
-    # final binary
-    target_linker_script(${COMPONENT_LIB} INTERFACE
-                         "${CMAKE_CURRENT_LIST_DIR}/ld/esp32s2.project.ld.in"
-                         PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32s2.project.ld")
-
-    target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s2.peripherals.ld")
-
-    idf_build_get_property(config_dir CONFIG_DIR)
-    # Preprocess esp32s2.ld linker script to include configuration, becomes esp32s2_out.ld
-    set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
-    add_custom_command(
-        OUTPUT esp32s2_out.ld
-        COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32s2_out.ld -I ${config_dir} ${LD_DIR}/esp32s2.ld
-        MAIN_DEPENDENCY ${LD_DIR}/esp32s2.ld
-        DEPENDS ${sdkconfig_header}
-        COMMENT "Generating linker script..."
-        VERBATIM)
-
-    add_custom_target(esp32s2_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32s2_out.ld)
-    add_dependencies(${COMPONENT_LIB} esp32s2_linker_script)
-endif()

+ 0 - 26
components/esp32s3/CMakeLists.txt

@@ -14,29 +14,3 @@ idf_component_register(INCLUDE_DIRS include
                        REQUIRED_IDF_TARGETS esp32s3)
 
 target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s3.peripherals.ld")
-
-if(NOT BOOTLOADER_BUILD)
-    idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
-    target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32s3_out.ld")
-
-    # Process the template file through the linker script generation mechanism, and use the output for linking the
-    # final binary
-    target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32s3.project.ld.in"
-                                          PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32s3.project.ld")
-
-    target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s3.peripherals.ld")
-
-    idf_build_get_property(config_dir CONFIG_DIR)
-    # Preprocess esp32s3.ld linker script to include configuration, becomes esp32s3_out.ld
-    set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
-    add_custom_command(
-        OUTPUT esp32s3_out.ld
-        COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32s3_out.ld -I ${config_dir} ${LD_DIR}/esp32s3.ld
-        MAIN_DEPENDENCY ${LD_DIR}/esp32s3.ld
-        DEPENDS ${sdkconfig_header}
-        COMMENT "Generating linker script..."
-        VERBATIM)
-
-    add_custom_target(esp32s3_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32s3_out.ld)
-    add_dependencies(${COMPONENT_LIB} esp32s3_linker_script)
-endif()

+ 28 - 21
components/esp_hw_support/CMakeLists.txt

@@ -35,26 +35,33 @@ idf_component_register(SRCS ${srcs}
 idf_build_get_property(target IDF_TARGET)
 add_subdirectory(port/${target})
 
-if(CONFIG_SPIRAM_CACHE_WORKAROUND AND NOT BOOTLOADER_BUILD)
-    # Note: Adding as a PUBLIC compile option here causes this option to propagate to all
-    # components that depend on esp32.
-    #
-    # To handle some corner cases, the same flag is set in project_include.cmake
-    target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
-    # also, make sure we link with this option so correct toolchain libs are pulled in
-    target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
-    # set strategy selected
-    # note that we don't need to set link options as the library linked is independent of this
-    if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST)
-        target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
-        target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
-    endif()
-    if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW)
-        target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
-        target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
-    endif()
-    if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS)
-        target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
-        target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
+if(NOT BOOTLOADER_BUILD)
+
+    if(CONFIG_SPIRAM_CACHE_WORKAROUND)
+        # Note: Adding as a PUBLIC compile option here causes this option to propagate to all
+        # components that depend on esp32.
+        #
+        # To handle some corner cases, the same flag is set in project_include.cmake
+        target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
+        # also, make sure we link with this option so correct toolchain libs are pulled in
+        target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
+        # set strategy selected
+        # note that we don't need to set link options as the library linked is independent of this
+        if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST)
+            target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
+            target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
+        endif()
+        if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW)
+            target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
+            target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
+        endif()
+        if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS)
+            target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
+            target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
+        endif()
     endif()
+
+    set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/sleep_modes.c" PROPERTIES
+        COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion")
+
 endif()

+ 1 - 0
components/esp_system/CMakeLists.txt

@@ -58,6 +58,7 @@ else()
         PROPERTIES COMPILE_FLAGS
         -fno-stack-protector)
 
+    include(${CMAKE_CURRENT_LIST_DIR}/ld/ld.cmake)
 endif()
 
 if(CONFIG_IDF_ENV_FPGA)

+ 9 - 0
components/esp_system/Makefile.projbuild

@@ -0,0 +1,9 @@
+ESP32_LINKER_SCRIPT_TEMPLATE := $(COMPONENT_PATH)/ld/esp32/sections.ld.in
+ESP32_LINKER_SCRIPT_OUTPUT_DIR := $(BUILD_DIR_BASE)/esp_system/ld
+ESP32_SECTIONS_LINKER_SCRIPT := $(ESP32_LINKER_SCRIPT_OUTPUT_DIR)/sections.ld
+
+# Target to generate linker script generator from fragments presented by each of
+# the components
+$(eval $(call ldgen_process_template, $(ESP32_LINKER_SCRIPT_TEMPLATE), $(ESP32_SECTIONS_LINKER_SCRIPT)))
+
+$(APP_ELF): $(ESP32_SECTIONS_LINKER_SCRIPT)

+ 28 - 0
components/esp_system/component.mk

@@ -28,4 +28,32 @@ include $(COMPONENT_PATH)/port/soc/$(SOC_NAME)/component.mk
 
 # disable stack protection in files which are involved in initialization of that feature
 startup.o stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS))
+
+ld_input := $(COMPONENT_PATH)/ld/esp32/memory.ld.in
+ld_output := $(COMPONENT_BUILD_DIR)/ld/memory.ld
+
+sections_ld := $(COMPONENT_BUILD_DIR)/ld/sections.ld
+
+#Linker scripts used to link the final application.
+#Warning: These linker scripts are only used when the normal app is compiled; the bootloader
+#specifies its own scripts.
+LINKER_SCRIPTS += $(ld_output) $(sections_ld)
+
+#ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
+#linker will ignore panic_highint_hdl.S as it has no other files depending on any
+#symbols in it.
+COMPONENT_ADD_LDFLAGS += -u ld_include_panic_highint_hdl \
+                         $(addprefix -T ,$(LINKER_SCRIPTS)) \
+
+# Preprocess memory.ld.in linker script into memory.ld
+#
+# The library doesn't really depend on memory.ld, but it
+# saves us from having to add the target to a Makefile.projbuild
+$(COMPONENT_LIBRARY): $(ld_output)
+
+$(ld_output): $(ld_input) ../include/sdkconfig.h
+	mkdir -p $(COMPONENT_BUILD_DIR)/ld
+	$(CC) -I ../include -C -P -x c -E $< -o $@
+
+COMPONENT_EXTRA_CLEAN := $(ld_output) $(sections_ld)
 endif

+ 0 - 0
components/esp32/ld/esp32.ld → components/esp_system/ld/esp32/memory.ld.in


+ 0 - 0
components/esp32/ld/esp32.project.ld.in → components/esp_system/ld/esp32/sections.ld.in


+ 0 - 0
components/esp32c3/ld/esp32c3.ld → components/esp_system/ld/esp32c3/memory.ld.in


+ 0 - 0
components/esp32c3/ld/esp32c3.project.ld.in → components/esp_system/ld/esp32c3/sections.ld.in


+ 0 - 0
components/esp32s2/ld/esp32s2.ld → components/esp_system/ld/esp32s2/memory.ld.in


+ 0 - 0
components/esp32s2/ld/esp32s2.project.ld.in → components/esp_system/ld/esp32s2/sections.ld.in


+ 0 - 0
components/esp32s3/ld/esp32s3.ld → components/esp_system/ld/esp32s3/memory.ld.in


+ 0 - 0
components/esp32s3/ld/esp32s3.project.ld.in → components/esp_system/ld/esp32s3/sections.ld.in


+ 32 - 0
components/esp_system/ld/ld.cmake

@@ -0,0 +1,32 @@
+# For each supported target, a memory.ld.in and sections.ld.in is processed and dictate the
+# memory layout of the app.
+#
+# memory.ld.in goes through the preprocessor
+# sections.ld.in goes through linker script generator
+
+idf_build_get_property(target IDF_TARGET)
+idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
+
+set(ld_input "${CMAKE_CURRENT_LIST_DIR}/${target}/memory.ld.in")
+set(ld_output "${CMAKE_CURRENT_BINARY_DIR}/ld/memory.ld")
+target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_output}")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ld")
+
+# Process the template file through the linker script generation mechanism, and use the output for linking the
+# final binary
+target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/${target}/sections.ld.in"
+                    PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/sections.ld")
+
+idf_build_get_property(config_dir CONFIG_DIR)
+# Preprocess memory.ld.in linker script to include configuration, becomes memory.ld
+add_custom_command(
+    OUTPUT ${ld_output}
+    COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o ${ld_output} -I ${config_dir} ${ld_input}
+    MAIN_DEPENDENCY ${ld_input}
+    DEPENDS ${sdkconfig_header}
+    COMMENT "Generating memory.ld linker script..."
+    VERBATIM)
+
+add_custom_target(memory_ld DEPENDS ${ld_output})
+add_dependencies(${COMPONENT_LIB} memory_ld)

+ 1 - 1
tools/ci/test_build_system.sh

@@ -160,7 +160,7 @@ function run_tests()
 
     print_status "Touching app-only template ld file should only re-link app"
     take_build_snapshot
-    touch ${IDF_PATH}/components/esp32/ld/esp32.project.ld.in
+    touch ${IDF_PATH}/components/esp_system/ld/esp32/sections.ld.in
     make
     assert_rebuilt ${APP_BINS}
     assert_not_rebuilt ${BOOTLOADER_BINS}

+ 6 - 6
tools/ci/test_build_system_cmake.sh

@@ -210,23 +210,23 @@ function run_tests()
 
     print_status "Updating app-only ld file should only re-link app"
     take_build_snapshot
-    cp ${IDF_PATH}/components/esp32/ld/esp32.project.ld.in .
+    cp ${IDF_PATH}/components/esp_system/ld/esp32/sections.ld.in .
     sleep 1  # ninja may ignore if the timestamp delta is too low
-    echo "/* (Build test comment) */" >> ${IDF_PATH}/components/esp32/ld/esp32.project.ld.in
+    echo "/* (Build test comment) */" >> ${IDF_PATH}/components/esp_system/ld/esp32/sections.ld.in
     idf.py build || failure "Failed to rebuild with modified linker script"
     assert_rebuilt ${APP_BINS}
     assert_not_rebuilt ${BOOTLOADER_BINS}
-    mv esp32.project.ld.in ${IDF_PATH}/components/esp32/ld/
+    mv sections.ld.in ${IDF_PATH}/components/esp_system/ld/esp32
 
     print_status "Updating ld file should only re-link app"
     take_build_snapshot
-    cp ${IDF_PATH}/components/esp32/ld/esp32.ld .
+    cp ${IDF_PATH}/components/esp_system/ld/esp32/memory.ld .
     sleep 1  # ninja may ignore if the timestamp delta is too low
-    echo "/* (Build test comment) */" >> ${IDF_PATH}/components/esp32/ld/esp32.ld
+    echo "/* (Build test comment) */" >> ${IDF_PATH}/components/esp_system/ld/esp32/memory.ld.in
     idf.py build || failure "Failed to rebuild with modified linker script"
     assert_rebuilt ${APP_BINS}
     assert_not_rebuilt ${BOOTLOADER_BINS}
-    mv esp32.ld ${IDF_PATH}/components/esp32/ld/
+    mv memory.ld ${IDF_PATH}/components/esp_system/ld/esp32/
 
     print_status "Updating fragment file should only re-link app" # only app linker script is generated by tool for now
     take_build_snapshot