Skip to content

Commit 5a71377

Browse files
sylvioalvescfriedt
authored andcommitted
soc: esp32c3: add flash dts values into cmake config
This configures soc and flash size definition using DTSI information instead of hardcoded values. Signed-off-by: Sylvio Alves <[email protected]>
1 parent f1e2621 commit 5a71377

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

soc/riscv/esp32c3/CMakeLists.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ zephyr_sources(
99
loader.c
1010
)
1111

12+
# get code-partition slot0 address
13+
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
14+
dt_reg_addr(img_0_off PATH ${dts_partition_path})
15+
16+
# get code-partition boot address
17+
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
18+
dt_reg_addr(boot_off PATH ${dts_partition_path})
19+
1220
if(CONFIG_BOOTLOADER_ESP_IDF)
1321
include(ExternalProject)
1422

@@ -45,14 +53,14 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
4553
CONFIGURE_COMMAND ""
4654
BUILD_COMMAND
4755
${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
56+
--offset 0x8000 --flash-size ${CONFIG_ESPTOOLPY_FLASHSIZE} ${ESP_IDF_PATH}/components/partition_table/partitions_singleapp.csv ${espidf_build_dir}/partitions_singleapp.bin
4957
INSTALL_COMMAND ""
5058
)
5159

5260
if(CONFIG_BUILD_OUTPUT_BIN)
5361
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
5462
COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
55-
ARGS --chip esp32c3 elf2image --flash_mode dio --flash_freq 40m
63+
ARGS --chip ${CONFIG_SOC} elf2image --flash_mode dio --flash_freq 40m --flash_size ${CONFIG_ESPTOOLPY_FLASHSIZE}
5664
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
5765
${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)
5866
endif()
@@ -65,20 +73,10 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
6573

6674
board_finalize_runner_args(esp32 "--esp-flash-partition_table=${espidf_build_dir}/partitions_singleapp.bin")
6775

68-
board_finalize_runner_args(esp32 "--esp-boot-address=0x0000")
69-
7076
board_finalize_runner_args(esp32 "--esp-partition-table-address=0x8000")
7177

72-
board_finalize_runner_args(esp32 "--esp-app-address=0x10000")
73-
7478
endif()
7579

76-
if(CONFIG_BOOTLOADER_MCUBOOT)
80+
board_finalize_runner_args(esp32 "--esp-boot-address=${boot_off}")
7781

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()
82+
board_finalize_runner_args(esp32 "--esp-app-address=${img_0_off}")

soc/riscv/esp32c3/Kconfig.soc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,30 @@ config SOC_ESP32C3
99
select CLOCK_CONTROL
1010
select CLOCK_CONTROL_ESP32
1111

12+
if SOC_ESP32C3
13+
1214
config IDF_TARGET_ESP32C3
1315
bool "ESP32C3 as target board"
1416
default y
15-
depends on SOC_ESP32C3
1617

1718
config ESPTOOLPY_FLASHFREQ_80M
1819
bool
1920
default y
20-
depends on SOC_ESP32C3
21+
22+
config FLASH_SIZE
23+
int
24+
default $(dt_node_reg_size_int,/soc/flash-controller@60002000/flash@0,0)
25+
26+
config FLASH_BASE_ADDRESS
27+
hex
28+
default $(dt_node_reg_addr_hex,/soc/flash-controller@60002000/flash@0)
29+
30+
config ESPTOOLPY_FLASHSIZE
31+
string
32+
default "1MB" if FLASH_SIZE = 0x100000
33+
default "2MB" if FLASH_SIZE = 0x200000
34+
default "4MB" if FLASH_SIZE = 0x400000
35+
default "8MB" if FLASH_SIZE = 0x800000
36+
default "16MB" if FLASH_SIZE = 0x1000000
37+
38+
endif

0 commit comments

Comments
 (0)