Kaynağa Gözat

esp_hw_support: remove public dependency on bootloader_support

In c4bcf111, soc_memory_types.h header was moved from soc to
esp_hw_support. Since some of the functions are also used in
bootloader and because esp_hw_support is not part of the bootloader
build, part of the functions were moved into bootloader_support.
To make these functions available to the app, bootloader_support was
added as a public dependency of esp_hw_support.

Since esp_hw_support is in common requirements list, this has added
bootloader_support as a public requirement to every component in the
build. Adding new public requirements outside of common components
is undesirable, since components may accidentally include headers
from bootloader_support without explicitly declaring it as a
requirement.

This commit reverts this addition. Until a better solution is found,
some part of esp_memory_utils.h is duplicated into
bootloader_memory_utils.h. A CI check is added to make sure these
files stay in sync.
Ivan Grokhotkov 3 yıl önce
ebeveyn
işleme
85cb079838

+ 8 - 1
.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:

+ 5 - 0
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

+ 2 - 2
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)

+ 134 - 1
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
  *

+ 47 - 0
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 <input> <output> <from> <to>
+#   Extract lines of <input> starting with a line which matches <from>
+#   and ending with a line which matches <to>, and write the result to <output>.
+function get_file_part
+{
+    input_file=$1
+    output_file=$2
+    from_line=$3
+    to_line=$4
+
+    awk "/${from_line}/{print START; select=1; next} /${to_line}/{print \"END\"; select=0} select{print \$0}" "${input_file}" > "${output_file}"
+}
+
+esp_hw_support_part_file=esp_hw_support_part.h
+bootloader_support_part_file=bootloader_support_part.h
+
+get_file_part "${esp_hw_support_header}" "${esp_hw_support_part_file}" "${esp_hw_support_start}" "${esp_hw_support_end}"
+get_file_part "${bootloader_support_header}" "${bootloader_support_part_file}" "${bootloader_support_start}" "${bootloader_support_end}"
+
+if ! diff --unified "${esp_hw_support_part_file}" "${bootloader_support_part_file}"; then
+    echo ""
+    echo "    The content of common sections in esp_memory_utils.h and bootloader_memory_utils.h is different."
+    echo "    If you made changes to one of these files, please update the other one with the same changes."
+    echo "    See ${esp_hw_support_part_file} and ${bootloader_support_part_file} for details."
+    exit 1
+fi
+
+echo "esp_memory_utils.h and bootloader_memory_utils.h are in sync."
+rm -f "${esp_hw_support_part_file}" "${bootloader_support_part_file}"

+ 1 - 0
tools/ci/executable-list.txt

@@ -54,6 +54,7 @@ tools/ci/check_callgraph.py
 tools/ci/check_codeowners.py
 tools/ci/check_copyright.py
 tools/ci/check_deprecated_kconfigs.py
+tools/ci/check_esp_memory_utils_headers.sh
 tools/ci/check_examples_rom_header.sh
 tools/ci/check_executables.py
 tools/ci/check_idf_version.sh