Skip to content

Commit f1e2621

Browse files
sylvioalvescfriedt
authored andcommitted
soc: esp32c3: prepare kconfigs and cmake to support mcuboot
This modifies esp32c3 SOC configuration to support MCUBoot. CmakeLists is moved from board to soc specific. It also includes MCUBoot changes. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 245b826 commit f1e2621

File tree

6 files changed

+95
-76
lines changed

6 files changed

+95
-76
lines changed

boards/riscv/esp32c3_devkitm/CMakeLists.txt

Lines changed: 0 additions & 66 deletions
This file was deleted.

boards/riscv/esp32c3_devkitm/Kconfig.defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
config BOARD
7-
default "esp32c3"
7+
default "esp32c3_devkitm"
88
depends on BOARD_ESP32C3_DEVKITM
99

1010
config ENTROPY_ESP32_RNG

boards/riscv/esp32c3_devkitm/esp32c3_devkitm_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
88
CONFIG_CONSOLE=y
99
CONFIG_SERIAL=y
1010
CONFIG_UART_CONSOLE=y
11-
CONFIG_XIP=n
1211
CONFIG_PINMUX=y
1312
CONFIG_PINMUX_ESP32=y
1413
CONFIG_GPIO=y

soc/riscv/esp32c3/CMakeLists.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,79 @@ zephyr_sources(
66
soc_irq.S
77
soc_irq.c
88
soc.c
9+
loader.c
910
)
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()

soc/riscv/esp32c3/Kconfig.defconfig

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55

66
if SOC_ESP32C3
77

8+
if BOOTLOADER_MCUBOOT
9+
10+
config HAS_FLASH_LOAD_OFFSET
11+
default y
12+
13+
config XIP
14+
default y
15+
16+
config MCUBOOT_GENERATE_UNSIGNED_IMAGE
17+
default y
18+
19+
config MCUBOOT_GENERATE_CONFIRMED_IMAGE
20+
default y
21+
22+
config ROM_START_OFFSET
23+
default 0x20
24+
25+
endif
26+
827
config SOC
928
default "esp32c3"
1029

@@ -23,9 +42,6 @@ config GEN_IRQ_VECTOR_TABLE
2342
config DYNAMIC_INTERRUPTS
2443
default y
2544

26-
config XIP
27-
default n
28-
2945
config ISR_STACK_SIZE
3046
default 2048
3147

soc/riscv/esp32c3/Kconfig.soc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,3 @@ config ESPTOOLPY_FLASHFREQ_80M
1818
bool
1919
default y
2020
depends on SOC_ESP32C3
21-
22-
config BOOTLOADER_ESP_IDF
23-
bool "Use esp-idf 2nd stage bootloader"
24-
default y
25-
depends on SOC_ESP32C3

0 commit comments

Comments
 (0)