1# SPDX-License-Identifier: Apache-2.0
2
3if (CONFIG_SOC_ESP32S3_APPCPU)
4
5  zephyr_sources(
6    soc_appcpu.c
7    )
8
9else()
10
11  zephyr_sources(
12    soc.c
13    soc_cache.c
14    esp32s3-mp.c
15    ../common/loader.c
16    )
17
18endif()
19
20zephyr_include_directories(.)
21
22zephyr_sources_ifndef(CONFIG_BOOTLOADER_MCUBOOT hw_init.c)
23
24zephyr_library_sources_ifdef(CONFIG_NEWLIB_LIBC newlib_fix.c)
25
26# Power Management
27zephyr_library_sources_ifdef(CONFIG_PM power.c)
28zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
29
30# Get flash size to use in esptool as string
31math(EXPR esptoolpy_flashsize "${CONFIG_FLASH_SIZE} / 0x100000")
32
33# Get UART baudrate from DT
34dt_chosen(dts_shell_uart PROPERTY "zephyr,shell-uart")
35if(${dts_shell_uart})
36  dt_prop(monitor_baud PATH ${dts_shell_uart} PROPERTY "current-speed")
37endif()
38
39board_runner_args(esp32 "--esp-monitor-baud=${monitor_baud}")
40
41message("-- Espressif HAL path: ${ESP_IDF_PATH}")
42
43# Select image processing
44
45if(CONFIG_ESP_SIMPLE_BOOT OR CONFIG_MCUBOOT)
46
47  if(CONFIG_BUILD_OUTPUT_BIN)
48
49    set(ESPTOOL_PY ${ESP_IDF_PATH}/tools/esptool_py/esptool.py)
50    message("-- Use the esptool.py: ${ESPTOOL_PY}")
51
52    set(ELF2IMAGE_ARG "")
53    if(NOT CONFIG_MCUBOOT)
54      set(ELF2IMAGE_ARG "--ram-only-header")
55    endif()
56
57    set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
58      COMMAND ${PYTHON_EXECUTABLE} ${ESPTOOL_PY}
59      ARGS --chip ${CONFIG_SOC} elf2image ${ELF2IMAGE_ARG}
60      --flash_mode dio --flash_freq 40m
61      --flash_size ${esptoolpy_flashsize}MB
62      -o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
63      ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)
64
65  endif()
66
67endif()
68
69set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)
70
71# Select the image origin depending on the boot configuration
72if(CONFIG_SOC_ESP32S3_APPCPU)
73  dt_nodelabel(dts_partition_path NODELABEL "slot0_appcpu_partition")
74elseif(CONFIG_MCUBOOT)
75  dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
76elseif(CONFIG_ESP_SIMPLE_BOOT)
77  dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
78else()
79  dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
80endif()
81
82dt_reg_addr(image_off PATH ${dts_partition_path})
83board_finalize_runner_args(esp32 "--esp-app-address=${image_off}")
84
85message("-- Image partition ${dts_partition_path}")
86
87# Look for cross references between bootloader sections
88if(CONFIG_MCUBOOT)
89
90    message("check_callgraph using: ${ESP_IDF_PATH}/tools/ci/check_callgraph.py")
91    set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
92      COMMAND
93        ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/tools/ci/check_callgraph.py
94      ARGS
95        --rtl-dirs ${CMAKE_BINARY_DIR}/zephyr
96        --elf-file ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf
97        find-refs
98        --from-section='.iram0.loader_text'
99        --to-section='.iram0.text'
100        --exit-code)
101endif()
102
103if(CONFIG_MCUBOOT)
104  set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.ld CACHE INTERNAL "")
105elseif(CONFIG_SOC_ESP32S3_APPCPU)
106  set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/default_appcpu.ld CACHE INTERNAL "")
107else()
108  set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/default.ld CACHE INTERNAL "")
109endif()
110