chore: Use CMake way for linker options (#4396)

Co-authored-by: Richard Li <richard.li@ces.hk>
This commit is contained in:
Raphael Coeffic
2023-12-14 09:12:31 +10:00
committed by GitHub
co-authored by Richard Li
parent f10e5e879f
commit 42e245b1da
8 changed files with 76 additions and 43 deletions
+36 -28
View File
@@ -500,33 +500,14 @@ set(COMMON_FLAGS "${COMMON_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS} -Wimplicit")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS} -fno-rtti")
# these are in addition to CMAKE_CXX_FLAGS
set(LINKER_DIR ${RADIO_SRC_DIR}/boards/generic_stm32/linker)
set(CMAKE_EXE_LINKER_FLAGS "-lm -T${LINKER_DIR}/firmware.ld -L${LINKER_DIR} -L${LINKER_DIR}/${TARGET_LINKER_DIR}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=firmware.map,--cref,--no-warn-mismatch,--gc-sections")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TARGET_LINKER_PARAMS}")
if(SEMIHOSTING)
add_definitions(-DSEMIHOSTING)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=rdimon.specs")
endif()
# Use newlib nano, which saves a few kilobytes.
if(NOT NANO STREQUAL NO)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nano.specs")
if(LUA)
# Lua needs %g and %f
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -u _printf_float -u _scanf_float")
endif()
if(SDRAM)
# Target with SDRAM do not need a custom allocator for now
# as the custom allocator has alignement issues
message("Target has SDRAM, do not use BIN_ALLOCATOR")
else()
# Nano's malloc does work well with lua, use our own
add_definitions(-DUSE_BIN_ALLOCATOR)
set(SRC ${SRC} bin_allocator.cpp)
endif()
if(SDRAM)
# Target with SDRAM do not need a custom allocator for now
# as the custom allocator has alignement issues
message("Target has SDRAM, do not use BIN_ALLOCATOR")
else()
# Nano's malloc does work well with lua, use our own
add_definitions(-DUSE_BIN_ALLOCATOR)
set(SRC ${SRC} bin_allocator.cpp)
endif()
# Bootloader
@@ -543,13 +524,40 @@ link_libraries(firmware -lstdc++)
add_dependencies(firmware ${RADIO_DEPENDENCIES})
set_target_properties(firmware PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_options(firmware PRIVATE
-lm -T${LINKER_DIR}/firmware.ld
-Wl,-Map=firmware.map,--cref,--no-warn-mismatch,--gc-sections
--specs=nano.specs
)
if (DEFINED TARGET_FLASH_SIZE)
message("TARGET_FLASH_SIZE = ${TARGET_FLASH_SIZE}")
# message("TARGET_FLASH_SIZE = ${TARGET_FLASH_SIZE}")
target_link_options(firmware PRIVATE
-Wl,--defsym=__flash_size=${TARGET_FLASH_SIZE}
)
endif()
if (DEFINED TARGET_SDRAM_START)
# message("TARGET_SDRAM_START = ${TARGET_SDRAM_START}")
target_link_options(firmware PRIVATE
-Wl,--defsym=__sdram_start=${TARGET_SDRAM_START}
)
endif()
if (DEFINED TARGET_SDRAM_SIZE)
# message("TARGET_SDRAM_SIZE = ${TARGET_SDRAM_SIZE}")
target_link_options(firmware PRIVATE
-Wl,--defsym=__sdram_size=${TARGET_SDRAM_SIZE}
)
endif()
if (LUA)
# Lua needs %g and %f
target_link_options(firmware PRIVATE
"SHELL:-u _printf_float" "SHELL:-u _scanf_float"
)
endif()
if(ACCESS_DENIED)
add_subdirectory(thirdparty/AccessDenied)
include_directories(thirdparty/AccessDenied)
@@ -12,8 +12,8 @@ BOOTLOADER_SIZE = 0x20000;
MIN_HEAP_SIZE = 4096K;
/* SDRAM definitions */
SDRAM_START = DEFINED(__SDRAM_START__) ? __SDRAM_START__ : 0xD0000000;
SDRAM_SIZE = DEFINED(__SDRAM_SIZE__) ? __SDRAM_SIZE__ : 8192K;
SDRAM_START = DEFINED(__sdram_start) ? __sdram_start : 0xD0000000;
SDRAM_SIZE = DEFINED(__sdram_size) ? __sdram_size : 8192K;
/* Highest heap address */
HEAP_ADDRESS = SDRAM_START + SDRAM_SIZE;
@@ -10,6 +10,9 @@ set(ARCH ARM)
set(STM32USB_DIR ${THIRDPARTY_DIR}/STM32_USB-Host-Device_Lib_V2.2.0/Libraries)
add_definitions(-DSTM32 -DLUA_INPUTS -DVARIO)
set(LINKER_DIR ${RADIO_SRC_DIR}/boards/generic_stm32/linker)
add_link_options(-L${LINKER_DIR} -L${LINKER_DIR}/${TARGET_LINKER_DIR})
include_directories(${RADIO_SRC_DIR}/targets/common/arm/stm32)
include_directories(${STM32USB_DIR}/STM32_USB_OTG_Driver/inc)
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Core/inc)
@@ -151,19 +151,29 @@ remove_definitions(-DUSE_WATCHDOG)
add_definitions(-DBOOT)
set(CMAKE_EXE_LINKER_FLAGS "-mcpu=${MCU} -mthumb -nostartfiles -lm")
set(LINKER_DIR ${RADIO_SRC_DIR}/boards/generic_stm32/linker)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_DIR}/bootloader.ld -L${LINKER_DIR} -L${LINKER_DIR}/${TARGET_LINKER_DIR}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=bootloader.map,--cref,--no-warn-mismatch,--gc-sections")
# use smaller nano libc
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nano.specs")
add_executable(bootloader EXCLUDE_FROM_ALL ${BOOTLOADER_SRC})
add_dependencies(bootloader ${BITMAPS_TARGET})
target_link_options(bootloader PRIVATE
-lm -nostartfiles -T${LINKER_DIR}/bootloader.ld
-Wl,-Map=bootloader.map,--cref,--no-warn-mismatch,--gc-sections
--specs=nano.specs
)
if (DEFINED TARGET_SDRAM_START)
# message("TARGET_SDRAM_START = ${TARGET_SDRAM_START}")
target_link_options(bootloader PRIVATE
-Wl,--defsym=__sdram_start=${TARGET_SDRAM_START}
)
endif()
if (DEFINED TARGET_SDRAM_SIZE)
# message("TARGET_SDRAM_SIZE = ${TARGET_SDRAM_SIZE}")
target_link_options(bootloader PRIVATE
-Wl,--defsym=__sdram_size=${TARGET_SDRAM_SIZE}
)
endif()
target_include_directories(bootloader
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
)
@@ -3,6 +3,12 @@ set(MCU cortex-m3)
set(FPU_FLAGS "")
if(NOT NATIVE_BUILD)
# Add MCU specific flags
add_link_options(
-mcpu=cortex-m3 -mfloat-abi=soft
)
# STM32 HAL/LL library
set(STM32CUBE_DIR ${THIRDPARTY_DIR}/STM32F2xx_HAL_Driver)
include_directories(${STM32CUBE_DIR}/Inc)
@@ -3,6 +3,12 @@ set(MCU cortex-m4)
set(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
if(NOT NATIVE_BUILD)
# Add MCU specific flags
add_link_options(
-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
)
# STM32 HAL/LL library
set(STM32CUBE_DIR ${THIRDPARTY_DIR}/STM32F4xx_HAL_Driver)
include_directories(${STM32CUBE_DIR}/Inc)
+1 -1
View File
@@ -26,7 +26,7 @@ set(PPM_LIMITS_SYMETRICAL YES)
# for size report script
set(CPU_TYPE_FULL STM32F429xI)
set(TARGET_LINKER_DIR stm32f429_sdram)
set(TARGET_LINKER_PARAMS "-Wl,--defsym=__SDRAM_START__=0xC0000000")
set(TARGET_SDRAM_START 0xC0000000)
set(SIZE_TARGET_MEM_DEFINE "MEM_SIZE_SDRAM1=8192")
+2 -2
View File
@@ -16,7 +16,6 @@ set(HAPTIC YES)
set(GUI_DIR colorlcd)
set(BITMAPS_DIR 480x272)
set(TARGET_DIR pl18)
set(LINKER_SCRIPT targets/pl18/stm32f4_flash.ld)
set(RTC_BACKUP_RAM YES)
set(PPM_LIMITS_SYMETRICAL YES)
set(USB_SERIAL ON CACHE BOOL "Enable USB serial (CDC)")
@@ -29,7 +28,8 @@ set(WIRELESS_CHARGER YES)
# for size report script
set(CPU_TYPE_FULL STM32F429xI)
set(TARGET_LINKER_DIR stm32f429_sdram)
set(TARGET_LINKER_PARAMS "-Wl,--defsym=__SDRAM_START__=0xC0000000")
set(TARGET_SDRAM_START 0xC0000000)
set(SIZE_TARGET_MEM_DEFINE "MEM_SIZE_SDRAM1=8192")
#set(RF_BAUD_RATE 921600 230400 115200 57600 38400 19200 9600 4800 2400 1200)