Files
mkrtos-real/mkrtos_bootstrap/CMakeLists.txt

166 lines
6.1 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.13)
2023-08-20 20:52:23 +08:00
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-Werror \
2023-09-18 22:49:53 +08:00
-DUSE_STDPERIPH_DRIVER=1 \
2023-08-20 20:52:23 +08:00
-DSMP=1 \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-unused-variable \
2023-08-23 00:42:36 +08:00
-Wno-deprecated \
2023-08-20 20:52:23 +08:00
")
2023-09-18 22:49:53 +08:00
include_directories(${CMAKE_SOURCE_DIR}/)
2023-12-23 19:20:48 +08:00
include_directories(${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/inc)
file(GLOB deps *.c)
2024-01-18 01:09:39 +08:00
if (${CONFIG_CPU_TYPE} STREQUAL "stm32f1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTM32F10X_XL ")
2023-12-23 19:20:48 +08:00
file(GLOB
bsp_src
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/*.c
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/*.c
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport/*.c
)
list(APPEND deps ${bsp_src})
include_directories(
2024-01-18 01:09:39 +08:00
${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/STM32F1
2023-12-23 19:20:48 +08:00
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/Include
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport
)
2024-01-18 01:09:39 +08:00
add_subdirectory(bsp/STM32F1)
2024-04-10 15:55:07 +00:00
set(LINKS_FLAGS " --gc-section ")
2024-01-18 00:48:16 +08:00
elseif(${CONFIG_CPU_TYPE} STREQUAL "stm32f2" )
2023-12-23 19:20:48 +08:00
file(GLOB bsp_src ${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/*.c)
list(APPEND deps ${bsp_src})
include_directories(
2024-01-18 00:48:16 +08:00
${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/STM32F2
2023-12-23 19:20:48 +08:00
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Include
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include
)
2024-01-18 00:48:16 +08:00
add_subdirectory(bsp/STM32F2)
2024-04-10 15:55:07 +00:00
set(LINKS_FLAGS " --gc-section ")
2024-01-18 00:48:16 +08:00
elseif(${CONFIG_CPU_TYPE} STREQUAL "stm32f4" )
if(${CONFIG_BOARD_NAME} STREQUAL "STM32F407VET6" )
2024-01-18 00:48:16 +08:00
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTM32F40_41xxx ")
endif()
2023-12-23 19:20:48 +08:00
file(GLOB bsp_src ${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F4xx_DSP_StdPeriph_Lib_V1.9.0/Libraries/STM32F4xx_StdPeriph_Driver/src/*.c)
list(APPEND deps ${bsp_src})
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F4xx_DSP_StdPeriph_Lib_V1.9.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.c)
include_directories(
2024-01-18 00:48:16 +08:00
${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/STM32F4
2023-12-23 19:20:48 +08:00
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F4xx_DSP_StdPeriph_Lib_V1.9.0/Libraries/STM32F4xx_StdPeriph_Driver/inc
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F4xx_DSP_StdPeriph_Lib_V1.9.0/Libraries/CMSIS/Include
${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F4xx_DSP_StdPeriph_Lib_V1.9.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include
)
2024-01-18 00:48:16 +08:00
add_subdirectory(bsp/STM32F4)
2024-04-10 15:55:07 +00:00
set(LINKS_FLAGS " --gc-section ")
2024-01-18 00:48:16 +08:00
elseif(${CONFIG_CPU_TYPE} STREQUAL "Cortex-R52" )
include_directories(
${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/Cortex-R52
)
add_subdirectory(bsp/Cortex-R52)
2024-04-10 15:55:07 +00:00
set(LINKS_FLAGS " --gc-section ")
elseif(${CONFIG_CPU_TYPE} STREQUAL "swm34s" )
file(GLOB bsp_src
${CMAKE_SOURCE_DIR}/mkrtos_bsp/SWM34/SWM341_StdPeriph_Driver/CMSIS/DeviceSupport/system_SWM341.c
${CMAKE_SOURCE_DIR}/mkrtos_bsp/SWM34/SWM341_StdPeriph_Driver/SWM341_StdPeriph_Driver/*.c
)
list(APPEND deps ${bsp_src})
include_directories(
${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/SWM34S
${CMAKE_SOURCE_DIR}/mkrtos_bsp/SWM34/SWM341_StdPeriph_Driver/CMSIS/DeviceSupport
${CMAKE_SOURCE_DIR}/mkrtos_bsp/SWM34/SWM341_StdPeriph_Driver/CMSIS/CoreSupport
${CMAKE_SOURCE_DIR}/mkrtos_bsp/SWM34/SWM341_StdPeriph_Driver/SWM341_StdPeriph_Driver
)
add_subdirectory(bsp/SWM34S)
2024-04-10 15:55:07 +00:00
set(LINKS_FLAGS " --gc-section ")
2024-03-31 16:06:11 +00:00
elseif(${CONFIG_CPU_TYPE} STREQUAL "aarch64_qemu" )
include_directories(
${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/AARCH64_QEMU
)
add_subdirectory(bsp/AARCH64_QEMU)
2024-04-10 15:55:07 +00:00
set(LINKS_FLAGS " ")
2024-04-10 15:55:07 +00:00
endif()
2024-03-31 16:06:11 +00:00
2024-04-10 15:55:07 +00:00
if ((DEFINED CONFIG_MMU) AND (CONFIG_MMU STREQUAL "y"))
add_custom_target(
gen_sys_cpio
COMMAND
cd ${CMAKE_SOURCE_DIR}/build/output/cpio
COMMAND
ls | cpio -H newc -o > ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio
COMMAND
cd ${CMAKE_SOURCE_DIR}/build/output
COMMAND
${CMAKE_OBJCOPY} -I binary -O elf64-littleaarch64 -B aarch64 rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build/output
BYPRODUCTS ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf
)
add_dependencies(
gen_sys_cpio
mkrtos_dump
2024-04-10 15:19:02 +00:00
)
2024-04-10 15:55:07 +00:00
set_source_files_properties(${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf PROPERTIES EXTERNAL_OBJECT true)
add_executable(bootstrap.elf
${deps}
${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf
)
add_dependencies(bootstrap.elf gen_sys_cpio)
else()
add_executable(bootstrap.elf
2023-12-23 19:20:48 +08:00
${deps}
2024-04-10 15:55:07 +00:00
)
endif()
2024-03-31 16:06:11 +00:00
# message("CONFIG_CPU_TYPE="${CONFIG_CPU_TYPE})
string(TOUPPER ${CONFIG_CPU_TYPE} cpu_type)
2023-12-23 19:20:48 +08:00
set_target_properties(bootstrap.elf PROPERTIES LINK_FLAGS
2024-04-10 15:55:07 +00:00
"-T ${CMAKE_CURRENT_LIST_DIR}/bsp/${cpu_type}/link.lds ${LINKS_FLAGS} ")
2023-12-23 19:20:48 +08:00
target_link_libraries(
bootstrap.elf
--whole-archive
boot_bsp
--no-whole-archive
2024-04-10 15:19:02 +00:00
${GCC_LIB_PATH}/libgcc.a
)
2023-08-20 20:52:23 +08:00
add_custom_target(
bootstrap_dump ALL
COMMAND
${CMAKE_OBJCOPY} -O binary -S bootstrap.elf bootstrap.bin
COMMAND
mkdir -p ${CMAKE_SOURCE_DIR}/build/output
COMMAND
2024-03-31 16:06:11 +00:00
mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio
2023-08-20 20:52:23 +08:00
COMMAND
2024-03-31 16:06:11 +00:00
cp bootstrap.bin ${CMAKE_SOURCE_DIR}/build/output/bootstrap
COMMAND
2023-08-20 20:52:23 +08:00
cp bootstrap.elf ${CMAKE_SOURCE_DIR}/build/output/bootstrap.elf
2023-09-18 22:49:53 +08:00
COMMAND
${CMAKE_SIZE} bootstrap.elf
2023-08-20 20:52:23 +08:00
)
2023-12-23 19:20:48 +08:00
add_dependencies(bootstrap_dump bootstrap.elf)
2024-04-10 15:55:07 +00:00
add_dependencies(bootstrap.elf boot_bsp)