-
Notifications
You must be signed in to change notification settings - Fork 11
/
mcu-img-utils.cmake
65 lines (56 loc) · 2.21 KB
/
mcu-img-utils.cmake
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
#####################################
# Convert .elf to .bin #
#####################################
function(mcu_elf2bin PROJ_NAME)
separate_arguments(EXTRA_OPTS UNIX_COMMAND "${ARGN}")
add_custom_command(TARGET ${PROJ_NAME} POST_BUILD
COMMAND "${CMAKE_OBJCOPY}" -O binary ${EXTRA_OPTS}
"${PROJ_NAME}.elf"
"${PROJ_NAME}.bin"
BYPRODUCTS "${PROJ_NAME}.bin"
COMMENT "Generating ${PROJ_NAME}.bin"
)
set_property(TARGET ${PROJ_NAME} PROPERTY TARGET_FILE_BIN "${CMAKE_CURRENT_BINARY_DIR}/${CMX_TARGET}.bin")
endfunction()
#####################################
# Convert .elf to .lst #
#####################################
function(mcu_elf2lst PROJ_NAME)
separate_arguments(EXTRA_OPTS UNIX_COMMAND "${ARGN}")
add_custom_command(TARGET ${PROJ_NAME} POST_BUILD
COMMAND "${CMAKE_OBJDUMP}" -S ${EXTRA_OPTS}
"${PROJ_NAME}.elf"
> "${PROJ_NAME}.lst"
BYPRODUCTS "${PROJ_NAME}.lst"
COMMENT "Generating ${PROJ_NAME}.lst"
)
set_property(TARGET ${PROJ_NAME} PROPERTY TARGET_FILE_LST "${CMAKE_CURRENT_BINARY_DIR}/${CMX_TARGET}.lst")
endfunction()
#####################################
# Create symbol map #
#####################################
function(mcu_map PROJ_NAME)
target_link_options(${PROJ_NAME} PRIVATE -Wl,-Map=${PROJ_NAME}.map,--cref)
set_target_properties(${PROJ_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES
"${PROJ_NAME}.map"
)
set_property(TARGET ${PROJ_NAME} PROPERTY TARGET_FILE_MAP "${CMAKE_CURRENT_BINARY_DIR}/${CMX_TARGET}.map")
endfunction()
#####################################
# Display size #
#####################################
function(mcu_imgsize PROJ_NAME)
add_custom_command(TARGET ${PROJ_NAME} POST_BUILD
COMMAND "${CMAKE_SIZE_UTIL}"
"$<TARGET_FILE:${PROJ_NAME}>"
)
endfunction()
#####################################
# Create all of the above #
#####################################
function(mcu_image_utils PROJ_NAME ELF2BIN_OPTS ELF2LST_OPTS)
mcu_elf2bin(${PROJ_NAME} ${ELF2BIN_OPTS})
mcu_elf2lst(${PROJ_NAME} ${ELF2LST_OPTS})
mcu_map(${PROJ_NAME})
mcu_imgsize(${PROJ_NAME})
endfunction()