diff --git a/.gitlab/ci/pre_check.yml b/.gitlab/ci/pre_check.yml
index 66f1252703..ac9ad2be7b 100644
--- a/.gitlab/ci/pre_check.yml
+++ b/.gitlab/ci/pre_check.yml
@@ -113,15 +113,22 @@ check_public_headers:
script:
- python tools/ci/check_public_headers.py --jobs 4 --prefix xtensa-esp32-elf-
-check_soc_component:
+check_chip_support_components:
extends:
- .pre_check_base_template
- .rules:build
tags:
- build
+ artifacts:
+ when: on_failure
+ paths:
+ - esp_hw_support_part.h
+ - bootloader_support_part.h
+ expire_in: 1 week
script:
- python tools/ci/check_soc_headers_leak.py
- find ${IDF_PATH}/components/soc/*/include/soc/ -name "*_struct.h" -print0 | xargs -0 -n1 ./tools/ci/check_soc_struct_headers.py
+ - tools/ci/check_esp_memory_utils_headers.sh
check_esp_err_to_name:
extends:
diff --git a/components/bootloader_support/include/bootloader_memory_utils.h b/components/bootloader_support/include/bootloader_memory_utils.h
index 74c7b5308d..f2df0ed227 100644
--- a/components/bootloader_support/include/bootloader_memory_utils.h
+++ b/components/bootloader_support/include/bootloader_memory_utils.h
@@ -18,6 +18,8 @@
extern "C" {
#endif
+/** The content of this file is to be kept in sync with the common section of esp_memory_utils.h **/
+
/**
* @brief Check if the pointer is in iram
*
@@ -147,6 +149,9 @@ inline static void * esp_ptr_diram_iram_to_dram(const void *p) {
#endif
}
+/** End of the common section that has to be in sync with esp_memory_utils.h **/
+/** Don't add new functions below **/
+
#ifdef __cplusplus
}
#endif
diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt
index 034e223900..01deb5f259 100644
--- a/components/esp_hw_support/CMakeLists.txt
+++ b/components/esp_hw_support/CMakeLists.txt
@@ -1,7 +1,7 @@
idf_build_get_property(target IDF_TARGET)
-set(requires soc bootloader_support)
-set(priv_requires efuse spi_flash)
+set(requires soc)
+set(priv_requires efuse spi_flash bootloader_support)
set(srcs "compare_set.c" "cpu_util.c" "esp_memory_utils.c")
if(NOT BOOTLOADER_BUILD)
diff --git a/components/esp_hw_support/include/esp_memory_utils.h b/components/esp_hw_support/include/esp_memory_utils.h
index 75b99bae40..e66e917b87 100644
--- a/components/esp_hw_support/include/esp_memory_utils.h
+++ b/components/esp_hw_support/include/esp_memory_utils.h
@@ -13,12 +13,145 @@
#include "soc/soc_caps.h"
#include "sdkconfig.h"
#include "esp_attr.h"
-#include "bootloader_memory_utils.h"
#ifdef __cplusplus
extern "C" {
#endif
+/** Common functions, to be kept in sync with bootloader_memory_utils.h **/
+
+/**
+ * @brief Check if the pointer is in iram
+ *
+ * @param p pointer
+ *
+ * @return true: is in iram; false: not in iram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_iram(const void *p) {
+#if CONFIG_IDF_TARGET_ESP32 && CONFIG_FREERTOS_UNICORE
+ return ((intptr_t)p >= SOC_CACHE_APP_LOW && (intptr_t)p < SOC_IRAM_HIGH);
+#else
+ return ((intptr_t)p >= SOC_IRAM_LOW && (intptr_t)p < SOC_IRAM_HIGH);
+#endif
+}
+
+/**
+ * @brief Check if the pointer is in dram
+ *
+ * @param p pointer
+ *
+ * @return true: is in dram; false: not in dram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_dram(const void *p) {
+ return ((intptr_t)p >= SOC_DRAM_LOW && (intptr_t)p < SOC_DRAM_HIGH);
+}
+
+/**
+ * @brief Check if the pointer is in diram_dram
+ *
+ * @param p pointer
+ *
+ * @return true: is in diram_dram; false: not in diram_dram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_diram_dram(const void *p) {
+ return ((intptr_t)p >= SOC_DIRAM_DRAM_LOW && (intptr_t)p < SOC_DIRAM_DRAM_HIGH);
+}
+
+/**
+ * @brief Check if the pointer is in diram_iram
+ *
+ * @param p pointer
+ *
+ * @return true: is in diram_iram; false: not in diram_iram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_diram_iram(const void *p) {
+ return ((intptr_t)p >= SOC_DIRAM_IRAM_LOW && (intptr_t)p < SOC_DIRAM_IRAM_HIGH);
+}
+
+/**
+ * @brief Check if the pointer is in rtc_iram_fast
+ *
+ * @param p pointer
+ *
+ * @return true: is in rtc_iram_fast; false: not in rtc_iram_fast
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_rtc_iram_fast(const void *p) {
+#if SOC_RTC_FAST_MEM_SUPPORTED
+ return ((intptr_t)p >= SOC_RTC_IRAM_LOW && (intptr_t)p < SOC_RTC_IRAM_HIGH);
+#else
+ return false;
+#endif
+}
+
+/**
+ * @brief Check if the pointer is in rtc_dram_fast
+ *
+ * @param p pointer
+ *
+ * @return true: is in rtc_dram_fast; false: not in rtc_dram_fast
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_rtc_dram_fast(const void *p) {
+#if SOC_RTC_FAST_MEM_SUPPORTED
+ return ((intptr_t)p >= SOC_RTC_DRAM_LOW && (intptr_t)p < SOC_RTC_DRAM_HIGH);
+#else
+ return false;
+#endif
+}
+
+/**
+ * @brief Check if the pointer is in rtc_slow
+ *
+ * @param p pointer
+ *
+ * @return true: is in rtc_slow; false: not in rtc_slow
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_rtc_slow(const void *p) {
+#if SOC_RTC_SLOW_MEM_SUPPORTED
+ return ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH);
+#else
+ return false;
+#endif
+}
+
+
+/* Convert a D/IRAM DRAM pointer to equivalent word address in IRAM
+
+ - Address must be word aligned
+ - Address must pass esp_ptr_in_diram_dram() test, or result will be invalid pointer
+*/
+__attribute__((always_inline))
+inline static void * esp_ptr_diram_dram_to_iram(const void *p) {
+#if SOC_DIRAM_INVERTED
+ return (void *) ( SOC_DIRAM_IRAM_LOW + (SOC_DIRAM_DRAM_HIGH - (intptr_t)p) - 4);
+#else
+ return (void *) ( SOC_DIRAM_IRAM_LOW + ((intptr_t)p - SOC_DIRAM_DRAM_LOW) );
+#endif
+}
+
+/* Convert a D/IRAM IRAM pointer to equivalent word address in DRAM
+
+ - Address must be word aligned
+ - Address must pass esp_ptr_in_diram_iram() test, or result will be invalid pointer
+*/
+__attribute__((always_inline))
+inline static void * esp_ptr_diram_iram_to_dram(const void *p) {
+#if SOC_DIRAM_INVERTED
+ return (void *) ( SOC_DIRAM_DRAM_LOW + (SOC_DIRAM_IRAM_HIGH - (intptr_t)p) - 4);
+#else
+ return (void *) ( SOC_DIRAM_DRAM_LOW + ((intptr_t)p - SOC_DIRAM_IRAM_LOW) );
+#endif
+}
+
+/** End of common functions to be kept in sync with bootloader_memory_utils.h **/
+/** Add app-specific functions below **/
+
/**
* @brief Check if the pointer is dma capable
*
diff --git a/tools/ci/check_esp_memory_utils_headers.sh b/tools/ci/check_esp_memory_utils_headers.sh
new file mode 100755
index 0000000000..033022189b
--- /dev/null
+++ b/tools/ci/check_esp_memory_utils_headers.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# Some memory utility functions need to be defined both in bootloader and app contexts.
+# To avoid adding bootloader_support as a public dependency of every component,
+# and to avoid adding esp_hw_support as a bootloader dependency, some code is duplicated
+# between two memory utils files. This script checks that the duplicated code is in sync.
+
+esp_hw_support_header="${IDF_PATH}/components/esp_hw_support/include/esp_memory_utils.h"
+bootloader_support_header="${IDF_PATH}/components/bootloader_support/include/bootloader_memory_utils.h"
+
+bootloader_support_start="The content of this file is to be kept in sync with the common section of esp_memory_utils.h"
+bootloader_support_end="End of the common section that has to be in sync with esp_memory_utils.h"
+
+esp_hw_support_start="Common functions, to be kept in sync with bootloader_memory_utils.h"
+esp_hw_support_end="End of common functions to be kept in sync with bootloader_memory_utils.h"
+
+# get_file_part