From 86b18469ef78b51275d17abd2e0f84002a5d1c31 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Tue, 8 Sep 2020 12:35:44 +0100 Subject: [PATCH 1/6] cmake gcc arm: fix prelinking stage - add definitions We need to use macros for bootloader. Get definitions and pass it to the linker. --- CMakeLists.txt | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f751b85acf..64036617b1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,22 @@ function(mbed_configure_app_target target) mbed_set_language_standard(${target}) endfunction() +# Get definitions - we need them for linker preprocessing +set(_compile_definitions + "$" +) + +set(_compile_definitions + "$<$:-D$>" +) + +function(generate_compile_definitions _filename) + file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}\n") +endfunction() + +generate_compile_definitions(${CMAKE_BINARY_DIR}/compile_time_defs.txt) +set(_linker_preprocess_definitions ${CMAKE_BINARY_DIR}/compile_time_defs.txt) + # # Specifies linker script used for linking `target`. # @@ -85,10 +101,7 @@ function(mbed_set_mbed_target_linker_script target) -Wl,--wrap,_realloc_r -Wl,--wrap,_memalign_r -Wl,--wrap,_calloc_r -Wl,--wrap,exit -Wl,--wrap,atexit -Wl,-n -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp - -DMBED_ROM_START=0x0 -DMBED_ROM_SIZE=0x100000 -DMBED_RAM_START=0x20000000 - -DMBED_RAM_SIZE=0x30000 -DMBED_RAM1_START=0x1fff0000 - -DMBED_RAM1_SIZE=0x10000 -DMBED_BOOT_STACK_SIZE=1024 - -DXIP_ENABLE=0 + @${_linker_preprocess_definitions} ${mbed_target_startup} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} From e7ab3a8dbd39100fd436dd7100dbca93fd2473c2 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Tue, 8 Sep 2020 13:20:04 +0100 Subject: [PATCH 2/6] CMake: fix gcc arm prebuild command - use link options --- CMakeLists.txt | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64036617b1f..7bb6deb3a0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,16 +76,22 @@ set(_compile_definitions "$" ) +set(_linker_options + "$" +) + set(_compile_definitions - "$<$:-D$>" + "$<$:-D$>" ) -function(generate_compile_definitions _filename) - file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}\n") +function(generate_definitions) + file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n") + file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/linker_options.txt" CONTENT "${_linker_options}\n") endfunction() -generate_compile_definitions(${CMAKE_BINARY_DIR}/compile_time_defs.txt) -set(_linker_preprocess_definitions ${CMAKE_BINARY_DIR}/compile_time_defs.txt) +generate_definitions() +set(_linker_preprocess_definitions @${CMAKE_BINARY_DIR}/compile_time_defs.txt) +set(_linker_preprocess_options @${CMAKE_BINARY_DIR}/linker_options.txt) # # Specifies linker script used for linking `target`. @@ -97,11 +103,7 @@ function(mbed_set_mbed_target_linker_script target) if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") set(CMAKE_PRE_BUILD_COMMAND COMMAND "arm-none-eabi-cpp" -E -P - -Wl,--gc-sections -Wl,--wrap,main -Wl,--wrap,_malloc_r -Wl,--wrap,_free_r - -Wl,--wrap,_realloc_r -Wl,--wrap,_memalign_r -Wl,--wrap,_calloc_r - -Wl,--wrap,exit -Wl,--wrap,atexit -Wl,-n - -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp - @${_linker_preprocess_definitions} + ${_linker_preprocess_options} ${_linker_preprocess_definitions} ${mbed_target_startup} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} From 284ae2dcd5ef7fcd37f3894602322af56ebe0e44 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Tue, 8 Sep 2020 13:20:33 +0100 Subject: [PATCH 3/6] CMake: fix linker script name --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bb6deb3a0a..a1d07da8227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,14 +97,14 @@ set(_linker_preprocess_options @${CMAKE_BINARY_DIR}/linker_options.txt) # Specifies linker script used for linking `target`. # function(mbed_set_mbed_target_linker_script target) - get_property(mbed_target_startup GLOBAL PROPERTY MBED_TARGET_LINKER_FILE) + get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE) # TODO: @mbed-os-tools This pre-build commands should get details from target + profile. if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") set(CMAKE_PRE_BUILD_COMMAND COMMAND "arm-none-eabi-cpp" -E -P ${_linker_preprocess_options} ${_linker_preprocess_definitions} - ${mbed_target_startup} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld + ${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} BYPRODUCTS "${CMAKE_BINARY_DIR}/${target}.link_script.ld" @@ -113,7 +113,7 @@ function(mbed_set_mbed_target_linker_script target) set(CMAKE_PRE_BUILD_COMMAND COMMAND "") target_link_options(mbed-os PUBLIC - "--scatter=${mbed_target_startup}" + "--scatter=${mbed_target_linker_script}" ) endif() add_custom_command( From 584825a9d5be4b91deb5d259a3d3db18e147b72f Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Tue, 8 Sep 2020 13:27:02 +0100 Subject: [PATCH 4/6] CMake: protect specific Gcc Arm fixes in linker preprocessing --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1d07da8227..d268a9e66a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,10 @@ function(mbed_configure_app_target target) mbed_set_language_standard(${target}) endfunction() +# GCC ARM requires preprecessing linker script, execute generators to get definitions needed for +# this step - linker options and compile definitions +if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") + # Get definitions - we need them for linker preprocessing set(_compile_definitions "$" @@ -93,6 +97,8 @@ generate_definitions() set(_linker_preprocess_definitions @${CMAKE_BINARY_DIR}/compile_time_defs.txt) set(_linker_preprocess_options @${CMAKE_BINARY_DIR}/linker_options.txt) +endif() + # # Specifies linker script used for linking `target`. # From a1b29d065326c2b49a3c834a9f2170a461be9574 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Tue, 8 Sep 2020 13:33:57 +0100 Subject: [PATCH 5/6] CMake: remove false comment, we fixed it already --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d268a9e66a8..d0a8b31287e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,6 @@ endif() function(mbed_set_mbed_target_linker_script target) get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE) - # TODO: @mbed-os-tools This pre-build commands should get details from target + profile. if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") set(CMAKE_PRE_BUILD_COMMAND COMMAND "arm-none-eabi-cpp" -E -P From dbec0ce40cb953acc94592224c1afb17ba70b4c3 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Tue, 8 Sep 2020 13:59:58 +0100 Subject: [PATCH 6/6] CMake: move gcc arm related function to GCC_ARM.cmake --- CMakeLists.txt | 30 +----------------------------- cmake/toolchains/GCC_ARM.cmake | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0a8b31287e..f0c01e6e41c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,40 +71,12 @@ function(mbed_configure_app_target target) mbed_set_language_standard(${target}) endfunction() -# GCC ARM requires preprecessing linker script, execute generators to get definitions needed for -# this step - linker options and compile definitions -if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") - -# Get definitions - we need them for linker preprocessing -set(_compile_definitions - "$" -) - -set(_linker_options - "$" -) - -set(_compile_definitions - "$<$:-D$>" -) - -function(generate_definitions) - file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n") - file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/linker_options.txt" CONTENT "${_linker_options}\n") -endfunction() - -generate_definitions() -set(_linker_preprocess_definitions @${CMAKE_BINARY_DIR}/compile_time_defs.txt) -set(_linker_preprocess_options @${CMAKE_BINARY_DIR}/linker_options.txt) - -endif() - # # Specifies linker script used for linking `target`. # function(mbed_set_mbed_target_linker_script target) get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE) - + mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions _linker_preprocess_options) if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") set(CMAKE_PRE_BUILD_COMMAND COMMAND "arm-none-eabi-cpp" -E -P diff --git a/cmake/toolchains/GCC_ARM.cmake b/cmake/toolchains/GCC_ARM.cmake index b884a149b25..94544348313 100644 --- a/cmake/toolchains/GCC_ARM.cmake +++ b/cmake/toolchains/GCC_ARM.cmake @@ -55,3 +55,23 @@ function(mbed_set_toolchain_options target) ${link_options} ) endfunction() + +# GCC ARM requires preprecessing linker script, execute generators to get definitions needed for +# this step - linker options and compile definitions +function(mbed_generate_gcc_options_for_linker target definitions_file linker_options_file) + set(_compile_definitions + "$" + ) + + set(_linker_options + "$" + ) + + set(_compile_definitions + "$<$:-D$>" + ) + file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n") + file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/linker_options.txt" CONTENT "${_linker_options}\n") + set(definitions_file @${CMAKE_BINARY_DIR}/compile_time_defs.txt) + set(linker_options_file @${CMAKE_BINARY_DIR}/linker_options.txt) +endfunction()