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