@@ -6,4 +6,79 @@ zephyr_sources(
6
6
soc_irq.S
7
7
soc_irq.c
8
8
soc.c
9
+ loader.c
9
10
)
11
+
12
+ if (CONFIG_BOOTLOADER_ESP_IDF)
13
+ include (ExternalProject)
14
+
15
+ ## we use hello-world project, but I think any can be used.
16
+ set (espidf_components_dir ${ESP_IDF_PATH} /components)
17
+ set (espidf_prefix ${CMAKE_BINARY_DIR} /esp-idf)
18
+ set (espidf_build_dir ${espidf_prefix} /build )
19
+
20
+ ExternalProject_Add(
21
+ EspIdfBootloader
22
+ PREFIX ${espidf_prefix}
23
+ SOURCE_DIR ${espidf_components_dir} /bootloader/subproject
24
+ BINARY_DIR ${espidf_build_dir} /bootloader
25
+ CONFIGURE_COMMAND
26
+ ${CMAKE_COMMAND} -G${CMAKE_GENERATOR}
27
+ -S ${espidf_components_dir} /bootloader/subproject
28
+ -B ${espidf_build_dir} /bootloader -DSDKCONFIG=${espidf_build_dir} /sdkconfig
29
+ -DIDF_PATH=${ESP_IDF_PATH} -DIDF_TARGET=${CONFIG_SOC}
30
+ -DPYTHON_DEPS_CHECKED=1
31
+ -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
32
+ -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
33
+ -DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}
34
+ -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
35
+ -DPYTHON=${PYTHON_EXECUTABLE}
36
+ BUILD_COMMAND
37
+ ${CMAKE_COMMAND} --build .
38
+ INSTALL_COMMAND "" # This particular build system has no install command
39
+ )
40
+
41
+ ExternalProject_Add(
42
+ EspPartitionTable
43
+ SOURCE_DIR ${espidf_components_dir} /partition_table
44
+ BINARY_DIR ${espidf_build_dir}
45
+ CONFIGURE_COMMAND ""
46
+ BUILD_COMMAND
47
+ ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH} /components/partition_table/gen_esp32part.py -q
48
+ --offset 0x8000 --flash-size 4MB ${ESP_IDF_PATH} /components/partition_table/partitions_singleapp.csv ${espidf_build_dir} /partitions_singleapp.bin
49
+ INSTALL_COMMAND ""
50
+ )
51
+
52
+ if (CONFIG_BUILD_OUTPUT_BIN)
53
+ set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
54
+ COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH} /components/esptool_py/esptool/esptool.py
55
+ ARGS --chip esp32c3 elf2image --flash_mode dio --flash_freq 40m
56
+ -o ${CMAKE_BINARY_DIR} /zephyr/${CONFIG_KERNEL_BIN_NAME} .bin
57
+ ${CMAKE_BINARY_DIR} /zephyr/${CONFIG_KERNEL_BIN_NAME} .elf)
58
+ endif ()
59
+
60
+ set_property (TARGET bintools PROPERTY disassembly_flag_inline_source)
61
+
62
+ add_dependencies (app EspIdfBootloader EspPartitionTable)
63
+
64
+ board_finalize_runner_args(esp32 "--esp-flash-bootloader=${espidf_build_dir} /bootloader/bootloader.bin" )
65
+
66
+ board_finalize_runner_args(esp32 "--esp-flash-partition_table=${espidf_build_dir} /partitions_singleapp.bin" )
67
+
68
+ board_finalize_runner_args(esp32 "--esp-boot-address=0x0000" )
69
+
70
+ board_finalize_runner_args(esp32 "--esp-partition-table-address=0x8000" )
71
+
72
+ board_finalize_runner_args(esp32 "--esp-app-address=0x10000" )
73
+
74
+ endif ()
75
+
76
+ if (CONFIG_BOOTLOADER_MCUBOOT)
77
+
78
+ # get code-partition slot0 address
79
+ dt_nodelabel(dts_partition_path NODELABEL "slot0_partition" )
80
+ dt_reg_addr(img_0_off PATH ${dts_partition_path} )
81
+
82
+ board_finalize_runner_args(esp32 "--esp-app-address=${img_0_off} " )
83
+
84
+ endif ()
0 commit comments