1# SPDX-License-Identifier: Apache-2.0
2if("${BOARD_DEBUG_RUNNER}" STREQUAL "mdb-nsim" OR "${BOARD_FLASH_RUNNER}" STREQUAL "mdb-nsim")
3# mdb is required to run nsim multicore targets
4find_program(
5  MDB
6  mdb64
7  )
8set(MDB_BASIC_OPTIONS -nooptions -nogoifmain -toggle=include_local_symbols=1)
9
10# remove previous .sc.project folder which has temporary settings for MDB.
11set(MDB_OPTIONS ${CMAKE_COMMAND} -E rm -rf ${APPLICATION_BINARY_DIR}/.sc.project)
12if(CONFIG_MP_MAX_NUM_CPUS GREATER 1)
13  set(MULTIFILES ${MDB} -multifiles=)
14  foreach(val RANGE ${CONFIG_MP_MAX_NUM_CPUS})
15    if(val LESS CONFIG_MP_MAX_NUM_CPUS)
16      MATH(EXPR PSET_NUM "${val}+1")
17      set(CORE_NUM ${val})
18      list(APPEND MDB_OPTIONS && ${MDB} -pset=${PSET_NUM} -psetname=core${CORE_NUM})
19      if(PSET_NUM GREATER 1)
20        list(APPEND MDB_OPTIONS -prop=download=2)
21      endif()
22      if(PSET_NUM LESS ${CONFIG_MP_MAX_NUM_CPUS})
23        set(MULTIFILES ${MULTIFILES}core${CORE_NUM},)
24      else()
25        set(MULTIFILES ${MULTIFILES}core${CORE_NUM})
26      endif()
27      list(APPEND MDB_OPTIONS ${MDB_BASIC_OPTIONS} -nsim @${BOARD_DIR}/support/${MDB_ARGS} ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME})
28    endif()
29  endforeach()
30  list(APPEND MDB_OPTIONS && NSIM_MULTICORE=1 ${MULTIFILES} -run -cl)
31else()
32 list(APPEND MDB_OPTIONS && ${MDB} ${MDB_BASIC_OPTIONS} -nsim @${BOARD_DIR}/support/${MDB_ARGS} -run -cl)
33endif()
34
35string(REPLACE ";" " " MDB_COMMAND "${MDB_OPTIONS}")
36add_custom_target(run_nsim
37  COMMAND
38  ${MDB_OPTIONS}
39  ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME}
40  DEPENDS ${logical_target_for_zephyr_elf}
41  WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
42  COMMENT "MDB COMMAND: ${MDB_COMMAND} ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME}"
43  USES_TERMINAL
44)
45else()
46find_program(
47  NSIM
48  nsimdrv
49  )
50
51add_custom_target(run_nsim
52  COMMAND
53  ${NSIM}
54  -propsfile
55  ${BOARD_DIR}/support/${NSIM_PROPS}
56  ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME}
57  DEPENDS ${logical_target_for_zephyr_elf}
58  WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
59  COMMENT "nSIM COMMAND: ${NSIM} -propsfile ${BOARD_DIR}/support/${NSIM_PROPS} ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME}"
60  USES_TERMINAL
61  )
62
63add_custom_target(debugserver_nsim
64  COMMAND
65  ${NSIM}
66  -propsfile
67  ${BOARD_DIR}/support/${NSIM_PROPS}
68  -gdb -port=3333
69  DEPENDS ${logical_target_for_zephyr_elf}
70  WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
71  USES_TERMINAL
72  )
73endif()
74