1# SPDX-License-Identifier: Apache-2.0
2
3set(flag_for_ram_report ram)
4set(flag_for_rom_report rom)
5set(flag_for_footprint all)
6set(report_depth 99)
7
8if(DEFINED ZEPHYR_WORKSPACE)
9  set(workspace_arg "--workspace=${ZEPHYR_WORKSPACE}")
10elseif(DEFINED WEST_TOPDIR)
11  set(workspace_arg "--workspace=${WEST_TOPDIR}")
12endif()
13
14foreach(report ram_report rom_report)
15  add_custom_target(
16    ${report}
17    ${PYTHON_EXECUTABLE}
18    ${ZEPHYR_BASE}/scripts/footprint/size_report
19    -k ${ZEPHYR_BINARY_DIR}/${KERNEL_ELF_NAME}
20    -z ${ZEPHYR_BASE}
21    -o ${CMAKE_BINARY_DIR}
22    ${workspace_arg}
23    -d ${report_depth}
24    ${flag_for_${report}}
25    DEPENDS ${logical_target_for_zephyr_elf}
26            $<TARGET_PROPERTY:zephyr_property_target,${report}_DEPENDENCIES>
27    USES_TERMINAL
28    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
29    )
30endforeach()
31
32add_custom_target(
33  footprint
34  DEPENDS ram_report rom_report
35  )
36
37if(CONFIG_BUILD_WITH_TFM)
38  foreach(report ram rom)
39    add_custom_target(
40      tfm_${report}_report
41      ${PYTHON_EXECUTABLE}
42      ${ZEPHYR_BASE}/scripts/footprint/size_report
43      -k $<TARGET_PROPERTY:tfm,TFM_S_ELF_FILE>
44      -z ${ZEPHYR_BASE}
45      -o ${CMAKE_BINARY_DIR}
46      ${workspace_arg}
47      -d ${report_depth}
48      --json tfm_${report}.json
49      ${flag_for_${report}_report}
50      DEPENDS tfm
51      USES_TERMINAL
52      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
53      )
54  endforeach()
55
56  add_custom_target(
57    tfm_footprint
58    DEPENDS tfm_ram_report tfm_rom_report
59    )
60endif()
61
62if(CONFIG_TFM_BL2)
63  foreach(report ram rom)
64    add_custom_target(
65      bl2_${report}_report
66      ${PYTHON_EXECUTABLE}
67      ${ZEPHYR_BASE}/scripts/footprint/size_report
68      -k $<TARGET_PROPERTY:tfm,BL2_ELF_FILE>
69      -z ${ZEPHYR_BASE}
70      -o ${CMAKE_BINARY_DIR}
71      ${workspace_arg}
72      -d ${report_depth}
73      --json bl2_${report}.json
74      ${flag_for_${report}_report}
75      DEPENDS tfm
76      USES_TERMINAL
77      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
78      )
79  endforeach()
80
81  add_custom_target(
82    bl2_footprint
83    DEPENDS bl2_ram_report bl2_rom_report
84    )
85endif()
86
87find_program(PUNCOVER puncover)
88
89if(NOT ${PUNCOVER} STREQUAL PUNCOVER-NOTFOUND)
90  add_custom_target(
91    puncover
92    ${PUNCOVER}
93    --elf_file       ${ZEPHYR_BINARY_DIR}/${KERNEL_ELF_NAME}
94    --gcc_tools_base ${CROSS_COMPILE}
95    --src_root       ${ZEPHYR_BASE}
96    --build_dir      ${CMAKE_BINARY_DIR}
97    DEPENDS ${logical_target_for_zephyr_elf}
98            $<TARGET_PROPERTY:zephyr_property_target,${report}_DEPENDENCIES>
99    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
100    USES_TERMINAL
101    )
102endif()
103
104find_program(PAHOLE pahole)
105
106if(NOT ${PAHOLE} STREQUAL PAHOLE-NOTFOUND)
107  add_custom_target(
108    pahole
109    ${PAHOLE}
110    --anon_include
111    --nested_anon_include
112    --show_decl_info
113    $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
114    ${ZEPHYR_BINARY_DIR}/${KERNEL_ELF_NAME}
115    DEPENDS ${logical_target_for_zephyr_elf}
116            $<TARGET_PROPERTY:zephyr_property_target,${report}_DEPENDENCIES>
117    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
118    USES_TERMINAL
119    )
120endif()
121