You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.8 KiB
103 lines
2.8 KiB
cmake_minimum_required (VERSION 3.13)
|
|
|
|
include(CMakePrintHelpers)
|
|
|
|
set(SCRIPT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
|
|
|
|
set(CMAKE_TOOLCHAIN_FILE "${SCRIPT_PATH}/toolchain.cmake")
|
|
|
|
project (firmware VERSION 1.0 LANGUAGES C ASM)
|
|
|
|
set(CMAKE_GDB "arm-none-eabi-gdb")
|
|
|
|
set(LIBXIL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libxil)
|
|
set(LIBXIL_BSP_PATH ${LIBXIL_PATH}/ps7_cortexa9_0)
|
|
|
|
add_custom_command(OUTPUT ${LIBXIL_BSP_PATH}/lib/libxil.a
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBXIL_BSP_PATH}/lib
|
|
COMMAND make
|
|
COMMENT "build libxil.a"
|
|
WORKING_DIRECTORY ${LIBXIL_PATH})
|
|
|
|
# build firmware
|
|
add_executable(firmware)
|
|
set_target_properties(firmware
|
|
PROPERTIES OUTPUT_NAME firmware.elf)
|
|
|
|
target_sources(firmware PRIVATE
|
|
fs/lfs2/lfs2_util.c
|
|
fs/lfs2/lfs2.c
|
|
fs/fatfs/ff.c
|
|
fs/fatfs/ffunicode.c
|
|
fs/vfs.c
|
|
fs/vfs_lfs2.c
|
|
fs/cmd_vfs.c
|
|
fs/vfs_fat.c
|
|
fs/block_ram.c
|
|
src/console.c
|
|
src/serial.c
|
|
src/sock.c
|
|
src/libtelnet.c
|
|
src/tcp_console.c
|
|
src/ether_card.c
|
|
src/qspi_flash.c
|
|
src/cmd_flash.c
|
|
src/main.c
|
|
${LIBXIL_BSP_PATH}/lib/libxil.a)
|
|
|
|
target_compile_options(firmware
|
|
PRIVATE -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -nostartfiles -Wall)
|
|
|
|
target_link_options(firmware
|
|
PRIVATE -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard )
|
|
|
|
target_include_directories(firmware PRIVATE
|
|
${LIBXIL_BSP_PATH}/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${CMAKE_CURRENT_SOURCE_DIR}/fs)
|
|
|
|
target_link_directories(firmware BEFORE
|
|
PRIVATE ${LIBXIL_BSP_PATH}/lib)
|
|
|
|
target_link_libraries(firmware PRIVATE
|
|
-Wl,--start-group
|
|
c
|
|
xil
|
|
lwip4
|
|
-Wl,--end-group)
|
|
|
|
# if cmake version < 3.19, delete `TARGET firmware`
|
|
file(GENERATE
|
|
OUTPUT xilinx.spec
|
|
CONTENT "*startfile:\ncrti%O%s crtbegin%O%s\n"
|
|
TARGET firmware)
|
|
|
|
#add_custom_command(TARGET firmware PRE_LINK
|
|
# COMMAND ${CMAKE_COMMAND} -E echo "*startfile:" > xilinx.spec
|
|
# COMMAND ${CMAKE_COMMAND} -E echo "crti%O%s crtbegin%O%s" >> xilinx.spec
|
|
# COMMENT "Generate xilinx.spec")
|
|
|
|
# arm-none-eabi-gcc -dumpspecs | grep -A1 '*startfile:'
|
|
# the specs remove crt0.o, use xil-crt0.o in libxil.a
|
|
target_link_options(firmware
|
|
PRIVATE -T ${SCRIPT_PATH}/lscript.ld --specs=xilinx.spec)
|
|
|
|
target_link_options(firmware
|
|
PRIVATE -Wl,-Map=firmware.map -Wl,--build-id=none)
|
|
|
|
if (NOT CMAKE_HOST_WIN32)
|
|
add_custom_command(TARGET firmware POST_BUILD
|
|
COMMAND ${CMAKE_STRIP} -o firmware.elf.stripped firmware.elf
|
|
COMMENT "Copy firmware.elf to tftp directory")
|
|
endif()
|
|
|
|
add_custom_target(drun)
|
|
add_dependencies(drun firmware)
|
|
add_custom_command(TARGET drun POST_BUILD
|
|
COMMAND openocd -s ${CMAKE_CURRENT_SOURCE_DIR}/scripts -f ax7020.cfg)
|
|
|
|
# distclean
|
|
add_custom_target(distclean)
|
|
add_custom_command(TARGET distclean POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E rm -rf ${LIBXIL_BSP_PATH}/lib
|
|
COMMENT "Remove libxil libraries")
|
|
|