forked from crosstyan/w806-air103-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
97 lines (89 loc) · 3.52 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
cmake_minimum_required(VERSION 3.20)
set(CMAKE_TOOLCHAIN_FILE
${CMAKE_CURRENT_LIST_DIR}/toolchain-csky-unknown-elf.cmake)
project(demo)
enable_language(C CXX ASM)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_library(config INTERFACE)
target_include_directories(config INTERFACE config)
add_subdirectory(lib)
add_executable(demo.elf src/serial.cpp src/main.cpp src/timer.cpp src/coret.cpp)
target_link_libraries(demo.elf haldrivers dsp freeRTOS)
# remapping `printf`
target_sources(demo.elf PUBLIC lib/port/libc_port.c)
target_include_directories(demo.elf PRIVATE src/include)
add_compile_definitions(WM_SWD_ENABLE=1)
set(LD_SCRIPT_PATH gcc_csky.ld)
get_filename_component(LD_SCRIPT_PATH_ABSOLUTE ${LD_SCRIPT_PATH} ABSOLUTE)
set_target_properties(
demo.elf
PROPERTIES CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
LINK_DEPENDS ${LD_SCRIPT_PATH_ABSOLUTE}
LINK_FLAGS "-T \"${LD_SCRIPT_PATH_ABSOLUTE}\" \
-Wl,-Map=\"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map\" \
")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/demo.bin"
COMMAND
${TOOLCHAIN_PREFIX}/bin/${TOOLCHAIN}-objcopy -Obinary
"${CMAKE_CURRENT_BINARY_DIR}/demo.elf"
"${CMAKE_CURRENT_BINARY_DIR}/demo.bin"
DEPENDS demo.elf)
set(WM_SECBOOT_NAME w800_secboot)
# set(WM_SECBOOT_NAME W806_secboot)
set(SEC_IMG_HEADER 8002000)
set(SEC_IMG_POS 8002400)
set(RUN_IMG_HEADER 8010000) # image header
set(RUN_IMG_POS 8010400) # image app address
set(UPD_IMG_POS 8010000) # image update address/OTA
find_program(WM_TOOL wm_tool)
if(NOT WM_TOOL)
message(WARNING "wm_tool not found. Image generation will not be available.")
else()
file(COPY misc/${WM_SECBOOT_NAME}.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${WM_SECBOOT_NAME}.img
COMMAND
${WM_TOOL} -b ${CMAKE_CURRENT_BINARY_DIR}/${WM_SECBOOT_NAME}.bin -o
${CMAKE_CURRENT_BINARY_DIR}/${WM_SECBOOT_NAME} -it 0 -fc 0 -ra
${SEC_IMG_POS} -ih ${SEC_IMG_HEADER} -ua ${UPD_IMG_POS} -nh
${RUN_IMG_HEADER} -un 0 -df
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${WM_SECBOOT_NAME}.bin)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/demo.img
${CMAKE_CURRENT_BINARY_DIR}/demo.fls
COMMAND
${WM_TOOL} -b ${CMAKE_CURRENT_BINARY_DIR}/demo.bin -o
${CMAKE_CURRENT_BINARY_DIR}/demo -it 1 -fc 0 -ra ${RUN_IMG_POS} -ih
${RUN_IMG_HEADER} -ua ${UPD_IMG_POS} -nh 0 -un 0 -df -sb
${CMAKE_CURRENT_BINARY_DIR}/${WM_SECBOOT_NAME}.img
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/demo.bin
${CMAKE_CURRENT_BINARY_DIR}/${WM_SECBOOT_NAME}.img)
# https://github.com/github0null/w800_cmake_sdk/blob/e8d91ca604f0b623d9097273bdb69ebaf47785ee/tools/make_firmware.sh.in#L103C18-L103C30
# https://github.com/github0null/w800_cmake_sdk/blob/e8d91ca604f0b623d9097273bdb69ebaf47785ee/tools/w800/wm_tool.c#L3483-L3569
add_custom_target(
img
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/demo.img
COMMENT "Building image file")
add_custom_target(
fls ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/demo.fls
COMMENT "Building fls file")
endif()
add_custom_target(
bin ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/demo.bin"
COMMENT "Building binary file")
add_custom_target(
size
${TOOLCHAIN_PREFIX}/bin/${TOOLCHAIN}-size
"${CMAKE_CURRENT_BINARY_DIR}/demo.elf"
DEPENDS demo.elf)