1# SPDX-License-Identifier: Apache-2.0
2
3zephyr_sources(
4  vectors.S
5  soc_irq.S
6  soc_irq.c
7  soc.c
8  ../common/loader.c
9  )
10
11zephyr_include_directories(.)
12
13zephyr_sources_ifndef(CONFIG_BOOTLOADER_MCUBOOT hw_init.c)
14
15zephyr_library_sources_ifdef(CONFIG_PM power.c)
16zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
17
18# get flash size to use in esptool as string
19math(EXPR esptoolpy_flashsize "${CONFIG_FLASH_SIZE} / 0x100000")
20
21if(NOT CONFIG_BOOTLOADER_MCUBOOT)
22
23  if(CONFIG_BUILD_OUTPUT_BIN)
24    # make ESP ROM loader compatible image
25    message("ESP-IDF path: ${ESP_IDF_PATH}")
26
27    set(ESPTOOL_PY ${ESP_IDF_PATH}/tools/esptool_py/esptool.py)
28    message("esptool path: ${ESPTOOL_PY}")
29
30    set(ELF2IMAGE_ARG "")
31    if(NOT CONFIG_MCUBOOT)
32      set(ELF2IMAGE_ARG "--ram-only-header")
33    endif()
34
35    set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
36      COMMAND ${PYTHON_EXECUTABLE} ${ESPTOOL_PY}
37      ARGS --chip esp32c6 elf2image ${ELF2IMAGE_ARG}
38      --flash_mode dio --flash_freq 40m --flash_size ${esptoolpy_flashsize}MB
39      -o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
40      ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)
41  endif()
42
43endif()
44
45# get code-partition slot0 address
46dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
47dt_reg_addr(img_0_off PATH ${dts_partition_path})
48
49# get code-partition boot address
50dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
51dt_reg_addr(boot_off PATH ${dts_partition_path})
52
53if(CONFIG_BOOTLOADER_MCUBOOT)
54  board_finalize_runner_args(esp32 "--esp-app-address=${img_0_off}")
55else()
56  board_finalize_runner_args(esp32 "--esp-app-address=${boot_off}")
57endif()
58
59if(CONFIG_MCUBOOT)
60    # search from cross references between bootloader sections
61    message("check_callgraph using: ${ESP_IDF_PATH}/tools/ci/check_callgraph.py")
62    set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
63      COMMAND
64        ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/tools/ci/check_callgraph.py
65      ARGS
66        --rtl-dirs ${CMAKE_BINARY_DIR}/zephyr
67        --elf-file ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf
68        find-refs --from-section=.iram0.iram_loader --to-section=.iram0.text
69        --exit-code)
70endif()
71
72if(CONFIG_MCUBOOT)
73  set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.ld CACHE INTERNAL "")
74else()
75  set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/default.ld CACHE INTERNAL "")
76endif()
77