-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.cmake
More file actions
105 lines (101 loc) · 3.66 KB
/
Copy pathhelpers.cmake
File metadata and controls
105 lines (101 loc) · 3.66 KB
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
98
99
100
101
102
103
104
105
########################################################################
# programs for output files
########################################################################
find_program(LINKER arm-none-eabi-ld)
find_program(OBJCOPY arm-none-eabi-objcopy)
find_program(OBJDUMP arm-none-eabi-objdump)
find_program(GDB arm-none-eabi-gdb)
find_program(SIZE arm-none-eabi-size)
find_program(HEXDUMP hexdump)
find_program(OPENOCD openocd)
########################################################################
# JTAG helpers
########################################################################
set(TARGET_NAME "target_name_not_set")
macro(JTAG_TARGET name)
set(TARGET_NAME ${name})
foreach (interface jlink openjtag)
add_custom_target(
${interface}
COMMAND echo 'init; reset reset' |
${OPENOCD} -f ${CMAKE_SOURCE_DIR}/mcutk/${interface}.cfg
-f target/${TARGET_NAME}.cfg
-f ${CMAKE_SOURCE_DIR}/mcutk/gdb.cfg | grep -v 'libusb'
)
endforeach (interface)
endmacro(JTAG_TARGET)
########################################################################
# helper functions to build output formats
########################################################################
set(GEN_OUTPUTS_BIN_SIZE "bin_size_not_set") #set before calling
macro(GEN_OUTPUTS target)
get_filename_component(name ${target} NAME_WE)
#print the size information
add_custom_command(
OUTPUT ${name}_size DEPENDS ${target}
COMMAND ${SIZE} --format=berkeley ${target}
)
#command to create a map from elf
add_custom_command(
OUTPUT ${name}.map DEPENDS ${target}
COMMAND ${LINKER} -Map ${name}.map ${target} && rm a.out
)
#command to create a bin from elf
add_custom_command(
OUTPUT ${name}.bin DEPENDS ${target}
COMMAND ${OBJCOPY} -O binary ${target} ${name}.bin
--pad-to ${GEN_OUTPUTS_BIN_SIZE}
)
#command to create a ihx from elf
add_custom_command(
OUTPUT ${name}.ihx DEPENDS ${target}
COMMAND ${OBJCOPY} -O ihex ${target} ${name}.ihx
--pad-to ${GEN_OUTPUTS_BIN_SIZE}
)
#command to create a dump from elf
add_custom_command(
OUTPUT ${name}.dump DEPENDS ${target}
COMMAND ${OBJDUMP} -DSC ${target} > ${name}.dump
)
#command to create a rom from bin
add_custom_command(
OUTPUT ${name}.rom DEPENDS ${name}.bin
COMMAND ${HEXDUMP} -v -e'1/1 \"%.2X\\n\"' ${name}.bin > ${name}.rom
)
#add a top level target for output files
add_custom_target(
${name}_outputs ALL DEPENDS ${name}_size #${name}.map ${name}.bin ${name}.ihx ${name}.dump ${name}.rom
)
#commands to debug
add_custom_target(
gdb_${target}
DEPENDS ${target}
COMMAND ${GDB} ${target} -x ${CMAKE_SOURCE_DIR}/mcutk/cortex_m3.gdb
)
#example commands to debug using cgdb
add_custom_target(
cgdb_${target}
DEPENDS ${target}
COMMAND cgdb -d ${GDB} ${target} -x ${CMAKE_SOURCE_DIR}/mcutk/cortex_m3.gdb
)
#command to load in RAM and run
add_custom_target(
sram_${target}
DEPENDS ${target}
COMMAND ${GDB} ${target} -x ${CMAKE_SOURCE_DIR}/mcutk/sram_cortex_m3.gdb
)
#commands to flash the device
foreach (interface jlink openjtag)
add_custom_target(
flash_${interface}_${target}
DEPENDS ${target}
COMMAND ${OPENOCD} -f ${CMAKE_SOURCE_DIR}/mcutk/${interface}.cfg
-f target/${TARGET_NAME}.cfg
-f ${CMAKE_SOURCE_DIR}/mcutk/gdb.cfg
-c 'flash write_image erase ${target} 0x00000000 elf'
-c 'verify_image ${target} 0x00000000 elf'
-c 'reset run'
-c 'shutdown' | grep -v 'libusb'
)
endforeach (interface)
endmacro(GEN_OUTPUTS)