Skip to content

Commit 7dc6bb6

Browse files
authored
Merge branch 'espressif:release/v5.4' into release/v5.4
2 parents 75962f8 + 28980b6 commit 7dc6bb6

File tree

349 files changed

+8586
-2050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

349 files changed

+8586
-2050
lines changed

.gitlab/ci/common.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ variables:
5656

5757
# Docker images
5858
ESP_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-env-v5.4:2"
59-
ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v5.4:1-1"
59+
ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v5.4:2-1"
6060
TARGET_TEST_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/target-test-env-v5.4:2"
6161
SONARQUBE_SCANNER_IMAGE: "${CI_DOCKER_REGISTRY}/sonarqube-scanner:5"
6262
PRE_COMMIT_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-pre-commit:1"
@@ -191,13 +191,21 @@ variables:
191191
fi
192192

193193
# Custom OpenOCD
194-
if [[ ! -z "$OOCD_DISTRO_URL" && "$CI_JOB_STAGE" == "target_test" ]]; then
195-
echo "Using custom OpenOCD from ${OOCD_DISTRO_URL}"
196-
wget $OOCD_DISTRO_URL
197-
ARCH_NAME=$(basename $OOCD_DISTRO_URL)
198-
tar -x -f $ARCH_NAME
199-
export OPENOCD_SCRIPTS=$PWD/openocd-esp32/share/openocd/scripts
200-
export PATH=$PWD/openocd-esp32/bin:$PATH
194+
if [[ "$CI_JOB_STAGE" == "target_test" ]]; then
195+
machine="$(uname -m)"
196+
if [[ "$machine" == "armv7l" ]] ; then
197+
OOCD_DISTRO_URL="$OOCD_DISTRO_URL_ARMHF"
198+
elif [[ "$machine" == "aarch64" ]] ; then
199+
OOCD_DISTRO_URL="$OOCD_DISTRO_URL_ARM64"
200+
fi
201+
if [[ ! -z "$OOCD_DISTRO_URL" ]]; then
202+
echo "Using custom OpenOCD from ${OOCD_DISTRO_URL}"
203+
wget $OOCD_DISTRO_URL
204+
ARCH_NAME=$(basename $OOCD_DISTRO_URL)
205+
tar -x -f $ARCH_NAME
206+
export OPENOCD_SCRIPTS=$PWD/openocd-esp32/share/openocd/scripts
207+
export PATH=$PWD/openocd-esp32/bin:$PATH
208+
fi
201209
fi
202210

203211
if [[ -n "$CI_PYTHON_TOOL_REPO" ]]; then

.gitlab/ci/pre_check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ pipeline_variables:
165165
if [ -n "$CI_PYTHON_CONSTRAINT_BRANCH" ]; then
166166
echo "BUILD_AND_TEST_ALL_APPS=1" >> pipeline.env
167167
fi
168+
- echo "OOCD_DISTRO_URL_ARMHF=$OOCD_DISTRO_URL_ARMHF" >> pipeline.env
169+
- echo "OOCD_DISTRO_URL_ARM64=$OOCD_DISTRO_URL_ARM64" >> pipeline.env
168170
- python tools/ci/ci_process_description.py
169171
- cat pipeline.env
170172
- python tools/ci/artifacts_handler.py upload --type modified_files_and_components_report

.gitmodules

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454
sbom-supplier = Person: Dave Gamble
5555
sbom-url = https://github.com/DaveGamble/cJSON
5656
sbom-description = Ultralightweight JSON parser in ANSI C
57-
sbom-hash = acc76239bee01d8e9c858ae2cab296704e52d916
57+
sbom-hash = 8f2beb57ddad1f94bed899790b00f46df893ccac
5858
sbom-cve-exclude-list = CVE-2024-31755 Resolved in v1.7.18
59+
sbom-cve-exclude-list = CVE-2023-26819 Resolved in commit a328d65ad490b64da8c87523cbbfe16050ba5bf6
60+
sbom-cve-exclude-list = CVE-2023-53154 Resolved in v1.7.18
5961

6062
[submodule "components/mbedtls/mbedtls"]
6163
path = components/mbedtls/mbedtls

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ repos:
2323
.*.pb-c.h|
2424
.*.pb-c.c|
2525
.*.yuv|
26-
.*.rgb
26+
.*.rgb|
27+
docs/sphinx-known-warnings\.txt
2728
)$
2829
- id: end-of-file-fixer
2930
exclude: *whitespace_excludes
@@ -56,6 +57,7 @@ repos:
5657
rev: v2.3.0
5758
hooks:
5859
- id: codespell
60+
exclude: ^docs/sphinx-known-warnings\.txt$
5961
- repo: local
6062
hooks:
6163
- id: check-executables

components/app_trace/app_trace_membufs_proto.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
@@ -148,6 +148,18 @@ static esp_err_t esp_apptrace_membufs_swap_waitus(esp_apptrace_membufs_proto_dat
148148
if (res != ESP_OK) {
149149
break;
150150
}
151+
#if CONFIG_IDF_TARGET_ESP32S3
152+
/*
153+
* ESP32S3 has a serious data corruption issue with the transferred data to host.
154+
* This delay helps reduce the failure rate by temporarily reducing heavy memory writes
155+
* from RTOS-level tracing and giving OpenOCD more time to read trace memory before
156+
* the current thread continues execution. While this doesn't completely prevent
157+
* memory access from other threads/cores/ISRs, it has shown to significantly improve
158+
* reliability when combined with CRC checks in OpenOCD. In practice, this reduces the
159+
* number of retries needed to read an entire block without corruption.
160+
*/
161+
esp_rom_delay_us(100);
162+
#endif
151163
}
152164
return res;
153165
}
@@ -339,7 +351,7 @@ uint8_t *esp_apptrace_membufs_up_buffer_get(esp_apptrace_membufs_proto_data_t *p
339351
esp_err_t esp_apptrace_membufs_up_buffer_put(esp_apptrace_membufs_proto_data_t *proto, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
340352
{
341353
esp_apptrace_membufs_pkt_end(ptr);
342-
// TODO: mark block as busy in order not to re-use it for other tracing calls until it is completely written
354+
// TODO: mark block as busy in order not to reuse it for other tracing calls until it is completely written
343355
// TODO: avoid potential situation when all memory is consumed by low prio tasks which can not complete writing due to
344356
// higher prio tasks and the latter can not allocate buffers at all
345357
// this is abnormal situation can be detected on host which will receive only uncompleted buffers

components/app_trace/port/xtensa/port.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
@@ -12,7 +12,7 @@
1212
// ======================
1313

1414
// Xtensa has useful feature: TRAX debug module. It allows recording program execution flow at run-time without disturbing CPU.
15-
// Exectution flow data are written to configurable Trace RAM block. Besides accessing Trace RAM itself TRAX module also allows to read/write
15+
// Execution flow data are written to configurable Trace RAM block. Besides accessing Trace RAM itself TRAX module also allows to read/write
1616
// trace memory via its registers by means of JTAG, APB or ERI transactions.
1717
// ESP32 has two Xtensa cores with separate TRAX modules on them and provides two special memory regions to be used as trace memory.
1818
// Chip allows muxing access to those trace memory blocks in such a way that while one block is accessed by CPUs another one can be accessed by host
@@ -47,17 +47,23 @@
4747
// 2. TRAX Registers layout
4848
// ========================
4949

50-
// This module uses two TRAX HW registers to communicate with host SW (OpenOCD).
50+
// This module uses two TRAX HW registers and one Performance Monitor register to communicate with host SW (OpenOCD).
5151
// - Control register uses TRAX_DELAYCNT as storage. Only lower 24 bits of TRAX_DELAYCNT are writable. Control register has the following bitfields:
5252
// | 31..XXXXXX..24 | 23 .(host_connect). 23| 22..(block_id)..15 | 14..(block_len)..0 |
5353
// 14..0 bits - actual length of user data in trace memory block. Target updates it every time it fills memory block and exposes it to host.
5454
// Host writes zero to this field when it finishes reading exposed block;
5555
// 21..15 bits - trace memory block transfer ID. Block counter. It can overflow. Updated by target, host should not modify it. Actually can be 2 bits;
5656
// 22 bit - 'host data present' flag. If set to one there is data from host, otherwise - no host data;
5757
// 23 bit - 'host connected' flag. If zero then host is not connected and tracing module works in post-mortem mode, otherwise in streaming mode;
58-
// - Status register uses TRAX_TRIGGERPC as storage. If this register is not zero then current CPU is changing TRAX registers and
59-
// this register holds address of the instruction which application will execute when it finishes with those registers modifications.
60-
// See 'Targets Connection' setion for details.
58+
// - Status register uses TRAX_TRIGGERPC as storage. If this register is not zero then current CPU is changing TRAX registers and
59+
// this register holds address of the instruction which application will execute when it finishes with those registers modifications.
60+
// See 'Targets Connection' section for details.
61+
// - CRC16 register uses ERI_PERFMON_PM1 as storage. This register is used to store CRC16 checksum of the exposed trace memory block.
62+
// The register has the following format:
63+
// | 31..16 (CRC indicator) | 15..0 (CRC16 value) |
64+
// CRC indicator (0xA55A) is used to distinguish valid CRC values from other data that might be in the register.
65+
// CRC16 is calculated over the entire exposed block and is updated every time a block is exposed to the host.
66+
// This allows the host to verify data integrity of the received trace data.
6167

6268
// 3. Modes of operation
6369
// =====================
@@ -127,7 +133,7 @@
127133

128134
// Access to internal module's data is synchronized with custom mutex. Mutex is a wrapper for portMUX_TYPE and uses almost the same sync mechanism as in
129135
// vPortCPUAcquireMutex/vPortCPUReleaseMutex. The mechanism uses S32C1I Xtensa instruction to implement exclusive access to module's data from tasks and
130-
// ISRs running on both cores. Also custom mutex allows specifying timeout for locking operation. Locking routine checks underlaying mutex in cycle until
136+
// ISRs running on both cores. Also custom mutex allows specifying timeout for locking operation. Locking routine checks underlying mutex in cycle until
131137
// it gets its ownership or timeout expires. The differences of application tracing module's mutex implementation from vPortCPUAcquireMutex/vPortCPUReleaseMutex are:
132138
// - Support for timeouts.
133139
// - Local IRQs for CPU which owns the mutex are disabled till the call to unlocking routine. This is made to avoid possible task's prio inversion.
@@ -142,9 +148,9 @@
142148

143149
// Timeout mechanism is based on xthal_get_ccount() routine and supports timeout values in microseconds.
144150
// There are two situations when task/ISR can be delayed by tracing API call. Timeout mechanism takes into account both conditions:
145-
// - Trace data are locked by another task/ISR. When wating on trace data lock.
151+
// - Trace data are locked by another task/ISR. When waiting on trace data lock.
146152
// - Current TRAX memory input block is full when working in streaming mode (host is connected). When waiting for host to complete previous block reading.
147-
// When wating for any of above conditions xthal_get_ccount() is called periodically to calculate time elapsed from trace API routine entry. When elapsed
153+
// When waiting for any of above conditions xthal_get_ccount() is called periodically to calculate time elapsed from trace API routine entry. When elapsed
148154
// time exceeds specified timeout value operation is canceled and ESP_ERR_TIMEOUT code is returned.
149155
#include "sdkconfig.h"
150156
#include "soc/soc.h"
@@ -159,11 +165,15 @@
159165
#include "esp_log.h"
160166
#include "esp_app_trace_membufs_proto.h"
161167
#include "esp_app_trace_port.h"
168+
#include "esp_rom_crc.h"
162169

163170
// TRAX is disabled, so we use its registers for our own purposes
164171
// | 31..XXXXXX..24 | 23 .(host_connect). 23 | 22 .(host_data). 22| 21..(block_id)..15 | 14..(block_len)..0 |
165172
#define ESP_APPTRACE_TRAX_CTRL_REG ERI_TRAX_DELAYCNT
166173
#define ESP_APPTRACE_TRAX_STAT_REG ERI_TRAX_TRIGGERPC
174+
#define ESP_APPTRACE_TRAX_CRC16_REG ERI_PERFMON_PM1
175+
176+
#define ESP_APPTRACE_CRC_INDICATOR (0xA55AU << 16)
167177

168178
#define ESP_APPTRACE_TRAX_BLOCK_LEN_MSK 0x7FFFUL
169179
#define ESP_APPTRACE_TRAX_BLOCK_LEN(_l_) ((_l_) & ESP_APPTRACE_TRAX_BLOCK_LEN_MSK)
@@ -498,7 +508,8 @@ static esp_err_t esp_apptrace_trax_buffer_swap_start(uint32_t curr_block_id)
498508
uint32_t acked_block = ESP_APPTRACE_TRAX_BLOCK_ID_GET(ctrl_reg);
499509
uint32_t host_to_read = ESP_APPTRACE_TRAX_BLOCK_LEN_GET(ctrl_reg);
500510
if (host_to_read != 0 || acked_block != (curr_block_id & ESP_APPTRACE_TRAX_BLOCK_ID_MSK)) {
501-
ESP_APPTRACE_LOGD("HC[%d]: Can not switch %" PRIx32 " %" PRIu32 " %" PRIx32 " %" PRIx32 "/%" PRIx32, esp_cpu_get_core_id(), ctrl_reg, host_to_read, acked_block,
511+
ESP_APPTRACE_LOGD("HC[%d]: Can not switch %" PRIx32 " %" PRIu32 " %" PRIx32 " %" PRIx32 "/%" PRIx32,
512+
esp_cpu_get_core_id(), ctrl_reg, host_to_read, acked_block,
502513
curr_block_id & ESP_APPTRACE_TRAX_BLOCK_ID_MSK, curr_block_id);
503514
res = ESP_ERR_NO_MEM;
504515
goto _on_err;
@@ -514,6 +525,14 @@ static esp_err_t esp_apptrace_trax_buffer_swap_end(uint32_t new_block_id, uint32
514525
{
515526
uint32_t ctrl_reg = eri_read(ESP_APPTRACE_TRAX_CTRL_REG);
516527
uint32_t host_connected = ESP_APPTRACE_TRAX_HOST_CONNECT & ctrl_reg;
528+
529+
/* calculate CRC16 of the already switched block */
530+
if (prev_block_len > 0) {
531+
const uint8_t *prev_block_start = s_trax_blocks[!((new_block_id % 2))];
532+
uint16_t crc16 = esp_rom_crc16_le(0, prev_block_start, prev_block_len);
533+
eri_write(ESP_APPTRACE_TRAX_CRC16_REG, crc16 | ESP_APPTRACE_CRC_INDICATOR);
534+
ESP_APPTRACE_LOGD("CRC16:%x %d @%x", crc16, prev_block_len, prev_block_start);
535+
}
517536
eri_write(ESP_APPTRACE_TRAX_CTRL_REG, ESP_APPTRACE_TRAX_BLOCK_ID(new_block_id) |
518537
host_connected | ESP_APPTRACE_TRAX_BLOCK_LEN(prev_block_len));
519538
esp_apptrace_trax_buffer_swap_unlock();

components/app_trace/sys_view/Sample/FreeRTOSV10.4/SEGGER_SYSVIEW_FreeRTOS.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void _cbSendTaskList(void) {
108108
* Called from SystemView when asked by the host, returns the
109109
* current system time in micro seconds.
110110
*/
111-
static U64 _cbGetTime(void) {
111+
__attribute__((unused)) static U64 _cbGetTime(void) {
112112
U64 Time;
113113

114114
Time = xTaskGetTickCountFromISR();
@@ -260,7 +260,10 @@ void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 Stac
260260
*/
261261
// Callbacks provided to SYSTEMVIEW by FreeRTOS
262262
const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = {
263-
_cbGetTime,
263+
/* Callback _cbGetTime locks xKernelLock inside xTaskGetTickCountFromISR, this can cause deadlock on multi-core.
264+
To prevent deadlock, always lock xKernelLock before s_sys_view_lock. Omitting the callback here results in sending
265+
SYSVIEW_EVTID_SYSTIME_CYCLES events instead of SYSVIEW_EVTID_SYSTIME_US */
266+
NULL,
264267
_cbSendTaskList,
265268
};
266269

components/bootloader_support/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ if(CONFIG_APP_BUILD_TYPE_APP_2NDBOOT)
3636
)
3737
endif()
3838

39+
if(CONFIG_ESP_ROM_REV0_HAS_NO_ECDSA_INTERFACE)
40+
list(APPEND srcs "src/${IDF_TARGET}/bootloader_ecdsa.c")
41+
endif()
42+
3943
if(BOOTLOADER_BUILD OR CONFIG_APP_BUILD_TYPE_RAM)
4044
set(include_dirs "include" "bootloader_flash/include"
4145
"private_include")
@@ -50,10 +54,6 @@ if(BOOTLOADER_BUILD OR CONFIG_APP_BUILD_TYPE_RAM)
5054
"src/${IDF_TARGET}/bootloader_${IDF_TARGET}.c"
5155
)
5256
list(APPEND priv_requires hal)
53-
if(CONFIG_ESP_ROM_REV0_HAS_NO_ECDSA_INTERFACE)
54-
list(APPEND srcs
55-
"src/${IDF_TARGET}/bootloader_ecdsa.c")
56-
endif()
5757
else()
5858
list(APPEND srcs
5959
"src/idf/bootloader_sha.c")

components/bootloader_support/src/bootloader_common_loader.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define ESP_PARTITION_HASH_LEN 32 /* SHA-256 digest length */
3030
#define IS_FIELD_SET(rev_full) (((rev_full) != 65535) && ((rev_full) != 0))
31+
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
3132

3233
static const char* TAG = "boot_comm";
3334

@@ -242,7 +243,10 @@ rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void)
242243
#if ESP_ROM_HAS_LP_ROM
243244
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_LOW)
244245
#else
245-
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_HIGH - sizeof(rtc_retain_mem_t))
246+
/* Since the structure containing the retain_mem_t is aligned on 8 by the linker, make sure we align this
247+
* structure size here too */
248+
#define RETAIN_MEM_SIZE ALIGN_UP(sizeof(rtc_retain_mem_t), 8)
249+
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_HIGH - RETAIN_MEM_SIZE)
246250
#endif //ESP_ROM_HAS_LP_ROM
247251
static rtc_retain_mem_t *const s_bootloader_retain_mem = (rtc_retain_mem_t *)RTC_RETAIN_MEM_ADDR;
248252
return s_bootloader_retain_mem;

components/bootloader_support/src/esp_image_format.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,20 +768,27 @@ static esp_err_t verify_segment_header(int index, const esp_image_segment_header
768768
bool map_segment = should_map(load_addr);
769769

770770
#if SOC_MMU_PAGE_SIZE_CONFIGURABLE
771+
esp_err_t err = ESP_FAIL;
772+
771773
/* ESP APP descriptor is present in the DROM segment #0 */
772774
if (index == 0 && metadata->start_addr != ESP_BOOTLOADER_OFFSET) {
773-
const esp_app_desc_t *app_desc = (const esp_app_desc_t *)bootloader_mmap(segment_data_offs, sizeof(esp_app_desc_t));
774-
if (!app_desc || app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) {
775+
uint32_t mmu_page_size = 0, magic_word = 0;
776+
const uint32_t mmu_page_size_offset = segment_data_offs + offsetof(esp_app_desc_t, mmu_page_size);
777+
CHECK_ERR(bootloader_flash_read(segment_data_offs, &magic_word, sizeof(uint32_t), true));
778+
CHECK_ERR(bootloader_flash_read(mmu_page_size_offset, &mmu_page_size, sizeof(uint32_t), true));
779+
// Extract only the lowest byte from mmu_page_size (as per image format)
780+
mmu_page_size &= 0xFF;
781+
782+
if (magic_word != ESP_APP_DESC_MAGIC_WORD) {
775783
ESP_LOGE(TAG, "Failed to fetch app description header!");
776784
return ESP_FAIL;
777785
}
778786

779787
// Convert from log base 2 number to actual size while handling legacy image case (value 0)
780-
metadata->mmu_page_size = (app_desc->mmu_page_size > 0) ? (1UL << app_desc->mmu_page_size) : SPI_FLASH_MMU_PAGE_SIZE;
788+
metadata->mmu_page_size = (mmu_page_size > 0) ? (1UL << mmu_page_size) : SPI_FLASH_MMU_PAGE_SIZE;
781789
if (metadata->mmu_page_size != SPI_FLASH_MMU_PAGE_SIZE) {
782790
ESP_LOGI(TAG, "MMU page size mismatch, configured: 0x%x, found: 0x%"PRIx32, SPI_FLASH_MMU_PAGE_SIZE, metadata->mmu_page_size);
783791
}
784-
bootloader_munmap(app_desc);
785792
} else if (index == 0 && metadata->start_addr == ESP_BOOTLOADER_OFFSET) {
786793
// Bootloader always uses the default MMU page size
787794
metadata->mmu_page_size = SPI_FLASH_MMU_PAGE_SIZE;
@@ -808,6 +815,10 @@ static esp_err_t verify_segment_header(int index, const esp_image_segment_header
808815
}
809816

810817
return ESP_OK;
818+
#if SOC_MMU_PAGE_SIZE_CONFIGURABLE
819+
err:
820+
return err;
821+
#endif
811822
}
812823

813824
static bool should_map(uint32_t load_addr)

0 commit comments

Comments
 (0)