Skip to content

Commit d84baa8

Browse files
rajkan01hugueskamba
authored andcommitted
CMake: Add a function to generate executable artifacts with memap (#13695)
- Add linker option to generate map file for GCC_ARM and ARM toolchain - Add mbed_generate_map_file function to call memap.py (parse the map file). - Add mbed_generate_executable function to generate executable artifacts with a memory map table
1 parent 22dd57b commit d84baa8

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,28 @@ function(mbed_generate_bin_hex target)
167167
VERBATIM
168168
)
169169
endfunction()
170+
171+
#
172+
# Parse toolchain generated map file of `target` and display a readable table format.
173+
#
174+
function(mbed_generate_map_file target)
175+
find_package (Python3)
176+
add_custom_command(
177+
TARGET
178+
${target}
179+
POST_BUILD
180+
COMMAND ${Python3_EXECUTABLE} ${MBED_ROOT}/tools/memap.py -t ${MBED_TOOLCHAIN} -d 4 ${CMAKE_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map
181+
WORKING_DIRECTORY
182+
${CMAKE_BINARY_DIR}
183+
COMMENT
184+
"Displaying memory map for ${target}"
185+
)
186+
endfunction()
187+
188+
#
189+
# Generate executables
190+
#
191+
function(mbed_generate_executable target)
192+
mbed_generate_bin_hex(${target})
193+
mbed_generate_map_file(${target})
194+
endfunction()

tools/cmake/toolchains/ARM.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function(mbed_set_toolchain_options target)
5555

5656
list(APPEND link_options
5757
"${MBED_STUDIO_ARM_COMPILER}"
58+
"--map"
5859
)
5960

6061
# Add linking time preprocessor macro for TFM targets

tools/cmake/toolchains/GCC_ARM.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function(mbed_set_toolchain_options target)
2121
"-Wl,--end-group"
2222
"-specs=nosys.specs"
2323
"-T" "${CMAKE_BINARY_DIR}/${APP_TARGET}.link_script.ld"
24+
"-Wl,-Map=${CMAKE_BINARY_DIR}/${APP_TARGET}.map"
25+
"-Wl,--cref"
2426
)
2527

2628
# Add linking time preprocessor macro for TFM targets

0 commit comments

Comments
 (0)