Skip to content

Commit 776f0be

Browse files
committed
soc: esp32s3: AMP support
Updates and fixes to support APPCPU. - fix ld scripts - fix and update memory layout - fix build issues - fix sysbuild Signed-off-by: Marek Matej <[email protected]>
1 parent a4bce3c commit 776f0be

File tree

12 files changed

+555
-289
lines changed

12 files changed

+555
-289
lines changed

soc/espressif/common/loader.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ void map_rom_segments(uint32_t app_drom_start, uint32_t app_drom_vaddr,
8484
unsigned int segments = 0;
8585
unsigned int ram_segments = 0;
8686

87-
/* Using already fetched bootloader image header from bootloader_init */
8887
offset += sizeof(esp_image_header_t);
8988

9089
while (segments++ < 16) {
@@ -223,7 +222,6 @@ void map_rom_segments(uint32_t app_drom_start, uint32_t app_drom_vaddr,
223222
"IROM",
224223
app_irom_start_aligned, app_irom_vaddr_aligned,
225224
app_irom_size, app_irom_size);
226-
ets_printf("\n\r");
227225
esp_rom_uart_tx_wait_idle(0);
228226
}
229227

@@ -248,7 +246,7 @@ void __start(void)
248246
}
249247
#endif
250248

251-
#ifndef CONFIG_MCUBOOT
249+
#if !defined(CONFIG_MCUBOOT) && !defined(CONFIG_SOC_ESP32S3_APPCPU)
252250
map_rom_segments(_app_drom_start, _app_drom_vaddr, _app_drom_size,
253251
_app_irom_start, _app_irom_vaddr, _app_irom_size);
254252
#endif

soc/espressif/esp32/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ config ESP32_APPCPU_DRAM
3232
config SOC_ENABLE_APPCPU
3333
bool
3434
default y
35-
depends on IPM && SOC_ESP32_PROCPU
36-
depends on MBOX && SOC_ESP32_PROCPU
35+
depends on (IPM || MBOX) && SOC_ESP32_PROCPU
3736
help
3837
This hidden configuration lets PROCPU core to map and start APPCPU whenever IPM is enabled.
3938

soc/espressif/esp32s3/CMakeLists.txt

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
if (CONFIG_SOC_ESP32S3_APPCPU)
4-
zephyr_sources(soc_appcpu.c)
4+
5+
zephyr_sources(
6+
soc_appcpu.c
7+
)
8+
59
else()
10+
611
zephyr_sources(
712
soc.c
813
soc_cache.c
914
esp32s3-mp.c
1015
../common/loader.c
1116
)
17+
1218
endif()
1319

1420
zephyr_include_directories(.)
@@ -22,13 +28,24 @@ zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
2228
# Get flash size to use in esptool as string
2329
math(EXPR esptoolpy_flashsize "${CONFIG_FLASH_SIZE} / 0x100000")
2430

25-
# Make rom loader compatible binary file
26-
if(NOT CONFIG_BOOTLOADER_MCUBOOT)
31+
# Get UART baudrate from DT
32+
dt_chosen(dts_shell_uart PROPERTY "zephyr,shell-uart")
33+
if(${dts_shell_uart})
34+
dt_prop(monitor_baud PATH ${dts_shell_uart} PROPERTY "current-speed")
35+
endif()
36+
37+
board_runner_args(esp32 "--esp-monitor-baud=${monitor_baud}")
38+
39+
message("-- Espressif HAL path: ${ESP_IDF_PATH}")
40+
41+
# Select image processing
42+
43+
if(CONFIG_ESP_SIMPLE_BOOT OR CONFIG_MCUBOOT)
2744

2845
if(CONFIG_BUILD_OUTPUT_BIN)
2946

3047
set(ESPTOOL_PY ${ESP_IDF_PATH}/tools/esptool_py/esptool.py)
31-
message("esptool path: ${ESPTOOL_PY}")
48+
message("-- Use the esptool.py: ${ESPTOOL_PY}")
3249

3350
set(ELF2IMAGE_ARG "")
3451
if(NOT CONFIG_MCUBOOT)
@@ -37,49 +54,35 @@ if(NOT CONFIG_BOOTLOADER_MCUBOOT)
3754

3855
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
3956
COMMAND ${PYTHON_EXECUTABLE} ${ESPTOOL_PY}
40-
ARGS --chip esp32s3 elf2image ${ELF2IMAGE_ARG}
57+
ARGS --chip ${CONFIG_SOC} elf2image ${ELF2IMAGE_ARG}
4158
--flash_mode dio --flash_freq 40m
4259
--flash_size ${esptoolpy_flashsize}MB
4360
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
4461
${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)
45-
endif()
46-
47-
endif()
4862

49-
## When building for APPCPU
50-
if (CONFIG_SOC_ESP32S3_APPCPU)
51-
52-
if(CONFIG_BUILD_OUTPUT_BIN)
53-
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
54-
COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/tools/esp_bin2c_array.py
55-
ARGS -i ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
56-
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.c
57-
-a "esp32s3_appcpu_fw_array")
5863
endif()
5964

60-
else()
61-
## Building for PROCPU
62-
63-
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)
65+
endif()
6466

65-
# Get code-partition boot address
67+
# Select the image origin depending on the boot configuration
68+
if(CONFIG_SOC_ESP32S3_APPCPU)
69+
dt_nodelabel(dts_partition_path NODELABEL "slot0_appcpu_partition")
70+
elseif(CONFIG_MCUBOOT)
6671
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
67-
dt_reg_addr(boot_off PATH ${dts_partition_path})
68-
69-
# Get code-partition slot0 address
72+
elseif(CONFIG_ESP_SIMPLE_BOOT)
73+
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
74+
else()
7075
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
71-
dt_reg_addr(img_0_off PATH ${dts_partition_path})
76+
endif()
7277

73-
if(CONFIG_BOOTLOADER_MCUBOOT)
74-
board_finalize_runner_args(esp32 "--esp-app-address=${img_0_off}")
75-
else()
76-
board_finalize_runner_args(esp32 "--esp-app-address=${boot_off}")
77-
endif()
78+
dt_reg_addr(image_off PATH ${dts_partition_path})
79+
board_finalize_runner_args(esp32 "--esp-app-address=${image_off}")
7880

79-
endif()
81+
message("-- Image partition ${dts_partition_path}")
8082

83+
# Look for cross references between bootloader sections
8184
if(CONFIG_MCUBOOT)
82-
# search from cross references between bootloader sections
85+
8386
message("check_callgraph using: ${ESP_IDF_PATH}/tools/ci/check_callgraph.py")
8487
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
8588
COMMAND

soc/espressif/esp32s3/Kconfig

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,6 @@ config SOC_SERIES_ESP32S3
1414

1515
if SOC_SERIES_ESP32S3
1616

17-
config ESP32S3_APPCPU_IRAM
18-
hex "ESP32S3 APPCPU IRAM size"
19-
depends on SOC_ESP32S3_PROCPU || SOC_ESP32S3_APPCPU
20-
default 0x20000
21-
help
22-
Defines APPCPU IRAM area in bytes.
23-
24-
config ESP32S3_APPCPU_DRAM
25-
hex "ESP32S3 APPCPU DRAM size"
26-
depends on SOC_ESP32S3_PROCPU || SOC_ESP32S3_APPCPU
27-
default 0x10000
28-
help
29-
Defines APPCPU DRAM area in bytes.
30-
31-
config SOC_ENABLE_APPCPU
32-
bool
33-
default y
34-
depends on IPM && SOC_ESP32S3_PROCPU
35-
depends on MBOX && SOC_ESP32S3_PROCPU
36-
help
37-
This hidden configuration lets PROCPU core to map and start APPCPU whenever IPM is enabled.
38-
3917
menu "Cache config"
4018

4119
choice ESP32S3_INSTRUCTION_CACHE_SIZE
@@ -178,4 +156,6 @@ config MAC_BB_PD
178156

179157
endmenu # Cache config
180158

159+
rsource "Kconfig.amp"
160+
181161
endif # SOC_SERIES_ESP32S3

soc/espressif/esp32s3/Kconfig.amp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_SERIES_ESP32S3
5+
6+
menu "AMP config"
7+
8+
config ESP32S3_APPCPU_IRAM_SIZE
9+
hex "ESP32S3 APPCPU IRAM size"
10+
depends on SOC_ESP32S3_PROCPU || SOC_ESP32S3_APPCPU
11+
default 0x10000
12+
help
13+
Defines APPCPU IRAM area size in bytes.
14+
15+
config ESP32S3_APPCPU_DRAM_SIZE
16+
hex "ESP32S3 APPCPU DRAM size"
17+
depends on SOC_ESP32S3_PROCPU || SOC_ESP32S3_APPCPU
18+
default 0x10000
19+
help
20+
Defines APPCPU DRAM area size in bytes.
21+
22+
config SOC_ENABLE_APPCPU
23+
bool
24+
default y
25+
depends on (IPM || MBOX) && SOC_ESP32S3_PROCPU
26+
help
27+
This hidden configuration lets PROCPU core to map and start APPCPU whenever IPM is enabled.
28+
29+
endmenu # AMP config
30+
31+
endif # SOC_SERIES_ESP32S3

soc/espressif/esp32s3/Kconfig.defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ config FLASH_SIZE
99
config FLASH_BASE_ADDRESS
1010
default $(dt_node_reg_addr_hex,/soc/flash-controller@60002000/flash@0)
1111

12+
config BOOTLOADER_MCUBOOT
13+
default y if SOC_ESP32S3_APPCPU
14+
1215
endif # SOC_SERIES_ESP32S3

soc/espressif/esp32s3/default.ld

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,16 @@
1010

1111
#include "memory.h"
1212

13-
/* The "user_iram_end" represents the 2nd stage bootloader
14-
* "iram_loader_seg" start address (that should not be overlapped).
15-
* If no bootloader is used, we can extend it to gain more user ram.
16-
*/
17-
#ifdef CONFIG_ESP_SIMPLE_BOOT
18-
user_iram_end = (BOOTLOADER_USER_DRAM_END + IRAM_DRAM_OFFSET);
19-
#else
20-
user_iram_end = BOOTLOADER_IRAM_LOADER_SEG_START;
21-
#endif
22-
2313
/* User available SRAM memory segments */
24-
user_dram_seg_org = SRAM1_DRAM_START;
25-
user_iram_seg_org = SRAM0_IRAM_START + CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE;
26-
user_dram_end = BOOTLOADER_IRAM_LOADER_SEG_START - IRAM_DRAM_OFFSET;
27-
user_idram_size = user_dram_end - SRAM1_DRAM_START;
28-
sram0_iram_size = SRAM0_SIZE - CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE;
29-
user_iram_seg_len = user_idram_size + sram0_iram_size;
30-
user_dram_seg_len = user_idram_size;
14+
amp_total_size = APPCPU_SRAM_TOTAL_SIZE;
15+
procpu_iram_end = USER_IRAM_END - APPCPU_SRAM_TOTAL_SIZE;
16+
procpu_dram_end = USER_DRAM_END - APPCPU_SRAM_TOTAL_SIZE;
17+
18+
procpu_iram_org = SRAM_USER_IRAM_START;
19+
procpu_iram_len = procpu_iram_end - procpu_iram_org;
20+
21+
procpu_dram_org = SRAM1_DRAM_START;
22+
procpu_dram_len = procpu_dram_end - procpu_dram_org;
3123

3224
/* Aliases */
3325
#define FLASH_CODE_REGION irom0_0_seg
@@ -36,6 +28,7 @@ user_dram_seg_len = user_idram_size;
3628
#define RAMABLE_REGION dram0_0_seg
3729
#define ROMABLE_REGION FLASH
3830

31+
/* Zephyr macro re-definitions */
3932
#undef GROUP_DATA_LINK_IN
4033
#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion AT > lregion
4134

@@ -66,14 +59,13 @@ MEMORY
6659
FLASH (R): org = 0x0, len = FLASH_SIZE - 0x100
6760
#endif /* CONFIG_BOOTLOADER_MCUBOOT */
6861

69-
iram0_0_seg(RX): org = user_iram_seg_org, len = user_iram_seg_len - APPCPU_IRAM_SIZE
70-
dram0_0_seg(RW): org = user_dram_seg_org, len = user_dram_seg_len - APPCPU_DRAM_SIZE
62+
iram0_0_seg(RX): org = procpu_iram_org, len = procpu_iram_len
63+
dram0_0_seg(RW): org = procpu_dram_org, len = procpu_dram_len
7164

7265
irom0_0_seg(RX): org = IROM_SEG_ORG, len = IROM_SEG_LEN
7366
drom0_0_seg(R): org = DROM_SEG_ORG, len = DROM_SEG_LEN
7467

75-
/**
76-
* `ext_ram_seg` and `drom0_0_seg` share the same bus and the address region.
68+
/* The `ext_ram_seg` and `drom0_0_seg` share the same bus and the address region.
7769
* A dummy section is used to avoid overlap. See `.ext_ram.dummy` in `sections.ld.in`
7870
*/
7971
#if defined(CONFIG_ESP_SPIRAM)
@@ -101,11 +93,15 @@ MEMORY
10193
ENTRY(CONFIG_KERNEL_ENTRY)
10294

10395
/* Used as a pointer to the heap end */
96+
#ifdef CONFIG_SOC_ENABLE_APPCPU
97+
_heap_sentry = procpu_dram_end;
98+
#else
10499
_heap_sentry = DRAM_RESERVED_START;
100+
#endif
105101

106102
SECTIONS
107103
{
108-
_iram_dram_offset = IRAM_DRAM_OFFSET;
104+
_iram_dram_offset = IRAM_DRAM_OFFSET;
109105

110106
#ifdef CONFIG_BOOTLOADER_MCUBOOT
111107
/* Reserve space for MCUboot header in the binary */
@@ -116,6 +112,7 @@ SECTIONS
116112
QUAD(0x0)
117113
QUAD(0x0)
118114
} > mcuboot_hdr
115+
/* Image load table */
119116
.metadata :
120117
{
121118
/* 0. Magic byte for load header */
@@ -144,7 +141,6 @@ SECTIONS
144141
} > metadata
145142
#endif /* CONFIG_BOOTLOADER_MCUBOOT */
146143

147-
148144
/* Virtual non-loadable sections */
149145
#include <zephyr/linker/rel-sections.ld>
150146

@@ -275,7 +271,9 @@ SECTIONS
275271
*(.entry.text)
276272
*(.init.literal)
277273
*(.init)
274+
278275
_init_end = ABSOLUTE(.);
276+
279277
} GROUP_DATA_LINK_IN(IRAM_REGION, ROMABLE_REGION)
280278

281279
.iram0.text : ALIGN(4)
@@ -310,6 +308,11 @@ SECTIONS
310308
*libphy.a:(.phyiram .phyiram.*)
311309
*libgcov.a:(.literal .text .literal.* .text.*)
312310

311+
/* APPCPU_ENABLED */
312+
*libzephyr.a:esp32s3-mp.*(.literal .text .literal.* .text.*)
313+
*libzephyr.a:bootloader_flash.*(.literal .text .literal.* .text.*)
314+
*libzephyr.a:flash_mmap.*(.literal .text .literal.* .text.*)
315+
313316
/* [mapping:esp_psram] */
314317
*libzephyr.a:mmu_psram_flash.*(.literal .literal.* .text .text.*)
315318
*libzephyr.a:esp_psram_impl_quad.*(.literal .literal.* .text .text.*)
@@ -550,6 +553,11 @@ SECTIONS
550553
*libzephyr.a:esp_mmu_map.*(.rodata .rodata.*)
551554
*libdrivers__interrupt_controller.a:(.rodata .rodata.*)
552555

556+
/* APPCPU_ENABLE */
557+
*libzephyr.a:esp32s3-mp.*(.rodata .rodata.*)
558+
*libzephyr.a:bootloader_flash.*(.rodata .rodata.* .sdata2 .sdata2.* .srodata .srodata.*)
559+
*libzephyr.a:flash_mmap.*(.rodata .rodata.* .sdata2 .sdata2.* .srodata .srodata.*)
560+
553561
/* [mapping:esp_psram] */
554562
*libzephyr.a:mmu_psram_flash.*(.rodata .rodata.*)
555563
*libzephyr.a:esp_psram_impl_octal.*(.rodata .rodata.*)
@@ -798,6 +806,10 @@ SECTIONS
798806

799807
} GROUP_DATA_LINK_IN(FLASH_CODE_REGION, ROMABLE_REGION)
800808

809+
/* --- END OF IROM --- */
810+
811+
/* --- START OF DROM --- */
812+
801813
/* This dummy section represents the .flash.text section but in default_rodata_seg.
802814
* Thus, it must have its alignment and (at least) its size.
803815
*/
@@ -879,6 +891,10 @@ SECTIONS
879891
_image_rodata_end = ABSOLUTE(.);
880892
} GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION)
881893

894+
/* --- END OF DROM --- */
895+
896+
/* --- START OF SPIRAM --- */
897+
882898
/**
883899
* This section is required to skip flash rodata sections, because `ext_ram_seg`
884900
* and `drom0_0_seg` are on the same bus
@@ -907,8 +923,9 @@ SECTIONS
907923

908924
#endif /* CONFIG_ESP_SPIRAM */
909925

910-
/* --- XTENSA GLUE AND DEBUG BEGIN --- */
926+
/* --- END OF SPIRAM --- */
911927

928+
/* --- XTENSA GLUE AND DEBUG BEGIN --- */
912929
#ifdef CONFIG_GEN_ISR_TABLES
913930
#include <zephyr/linker/intlist.ld>
914931
#endif

0 commit comments

Comments
 (0)