mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-28 16:46:31 +03:00
fix(esp_hw_support): guard SPIRAM-dependent code with !BOOTLOADER_BUILD
The bootloader subproject's full Kconfig discovery resolves CONFIG_SPIRAM=y
when the parent app has it enabled, even though esp_psram is not linked
into the bootloader (the CMake gate is
'if(NOT non_os_build) if(CONFIG_SPIRAM) idf_component_optional_requires(PRIVATE esp_psram)').
Shared sources in esp_hw_support that #include esp_psram private headers
or call esp_psram functions guarded only by '#if CONFIG_SPIRAM' then fail
to compile in the bootloader with
"fatal error: esp_private/esp_psram_extram.h: No such file or directory".
Mirror the CMake gate in source guards: every '#if CONFIG_SPIRAM' block in
a bootloader-compiled source that touches esp_psram becomes
'#if !BOOTLOADER_BUILD && CONFIG_SPIRAM'. The leaked CONFIG_SPIRAM value
in the bootloader's sdkconfig.h is then harmless because every dependent
block evaluates to false.
Sites updated:
- esp_memory_utils.c: include of esp_psram_extram.h and all
esp_psram_check_ptr_addr() call sites
- port/esp32{c5,c61,p4,s31}/cpu_region_protect.c: include of
esp_psram_extram.h (inner SPIRAM_FETCH/RODATA/PRE_CONFIGURE blocks are
already inside outer !BOOTLOADER_BUILD guards)
- port/esp32{p4,s31}/pmu_sleep.c: include of esp_psram_impl.h and
esp_psram_impl_{enter,exit}_halfsleep_mode() call sites
Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2010-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "esp_attr.h"
|
||||
#include "esp_cpu.h"
|
||||
#include "esp_memory_utils.h"
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
#include "esp_private/esp_psram_extram.h"
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,7 @@ bool esp_ptr_dma_ext_capable(const void *p)
|
||||
#if !SOC_PSRAM_DMA_CAPABLE
|
||||
return false;
|
||||
#endif //!SOC_PSRAM_DMA_CAPABLE
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
return esp_psram_check_ptr_addr(p);
|
||||
#else
|
||||
return false;
|
||||
@@ -36,7 +36,7 @@ bool esp_ptr_executable(const void *p)
|
||||
return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH)
|
||||
|| (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH)
|
||||
|| (ip >= SOC_IROM_MASK_LOW && ip < SOC_IROM_MASK_HIGH)
|
||||
#if SOC_SPIRAM_SUPPORTED && CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && SOC_SPIRAM_SUPPORTED && CONFIG_SPIRAM
|
||||
|| esp_ptr_external_ram(p)
|
||||
#endif
|
||||
#if defined(SOC_CACHE_APP_LOW) && defined(CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE)
|
||||
@@ -62,7 +62,7 @@ bool esp_ptr_byte_accessible(const void *p)
|
||||
* additional check is required */
|
||||
r |= (ip >= SOC_RTC_DRAM_LOW && ip < SOC_RTC_DRAM_HIGH);
|
||||
#endif
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
r |= esp_psram_check_ptr_addr(p);
|
||||
#endif
|
||||
#if CONFIG_ESP32S3_DATA_CACHE_16KB
|
||||
@@ -82,14 +82,14 @@ bool esp_ptr_external_ram(const void *p)
|
||||
#if !SOC_SPIRAM_SUPPORTED
|
||||
return false;
|
||||
#endif //!SOC_SPIRAM_SUPPORTED
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
return esp_psram_check_ptr_addr(p);
|
||||
#else
|
||||
return false;
|
||||
#endif //CONFIG_SPIRAM
|
||||
}
|
||||
|
||||
#if CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
|
||||
bool esp_stack_ptr_in_extram(uint32_t sp)
|
||||
{
|
||||
//Check if stack ptr is on PSRAM, and 16 byte aligned.
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include "esp_cpu.h"
|
||||
#include "esp_fault.h"
|
||||
#include "esp32c5/rom/rom_layout.h"
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
#include "esp_private/esp_psram_extram.h"
|
||||
#endif /* CONFIG_SPIRAM */
|
||||
#endif /* !BOOTLOADER_BUILD && CONFIG_SPIRAM */
|
||||
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
// Without L bit set
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "esp_cpu.h"
|
||||
#include "esp_fault.h"
|
||||
#include "esp32c61/rom/rom_layout.h"
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
#include "esp_private/esp_psram_extram.h"
|
||||
#endif /* CONFIG_SPIRAM */
|
||||
#endif /* !BOOTLOADER_BUILD && CONFIG_SPIRAM */
|
||||
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
// Without L bit set
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include "esp_fault.h"
|
||||
#include "hal/cache_ll.h"
|
||||
#include "riscv/csr.h"
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
#include "esp_private/esp_psram_extram.h"
|
||||
#endif /* CONFIG_SPIRAM */
|
||||
#endif /* !BOOTLOADER_BUILD && CONFIG_SPIRAM */
|
||||
|
||||
#include "soc/chip_revision.h"
|
||||
#include "hal/config.h"
|
||||
@@ -198,14 +198,14 @@ static void esp_cpu_configure_region_protection_rev_v3(void)
|
||||
PMP_ENTRY_SET_CACHED_AND_UNCACHED(22, 26, page_aligned_drom_resv_end, PMP_TOR | R);
|
||||
|
||||
#else
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
const uint32_t pmpaddr10 = PMPADDR_NAPOT(SOC_EXTRAM_LOW, SOC_EXTRAM_HIGH);
|
||||
PMP_RESET_AND_ENTRY_SET(10, pmpaddr10, PMP_NAPOT | CONDITIONAL_RWX);
|
||||
|
||||
const uint32_t pmpaddr11 = PMPADDR_NAPOT(CACHE_LL_L2MEM_NON_CACHE_ADDR(SOC_EXTRAM_LOW), CACHE_LL_L2MEM_NON_CACHE_ADDR(SOC_EXTRAM_HIGH));
|
||||
PMP_RESET_AND_ENTRY_SET(11, pmpaddr11, PMP_NAPOT | CONDITIONAL_RWX);
|
||||
_Static_assert(SOC_EXTRAM_LOW < SOC_EXTRAM_HIGH, "Invalid I/D_EXTRAM region");
|
||||
#endif /* CONFIG_SPIRAM */
|
||||
#endif /* !BOOTLOADER_BUILD && CONFIG_SPIRAM */
|
||||
|
||||
const uint32_t pmpaddr12 = PMPADDR_NAPOT(SOC_IROM_LOW, SOC_IROM_HIGH);
|
||||
PMP_RESET_AND_ENTRY_SET(12, pmpaddr12, PMP_NAPOT | CONDITIONAL_RX);
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#if CONFIG_SPIRAM
|
||||
#include "hal/ldo_ll.h"
|
||||
#include "hal/mspi_ll.h"
|
||||
#endif
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
#include "esp_private/esp_psram_impl.h"
|
||||
#endif
|
||||
|
||||
@@ -417,7 +419,7 @@ SPM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt,
|
||||
pmu_sleep_cache_sync_items(SMMU_GID_DEFAULT, CACHE_SYNC_WRITEBACK, CACHE_MAP_L1_DCACHE, 0, 0); // No PSRAM dirty data after this time write back
|
||||
|
||||
if (!dslp) {
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
psram_ctrlr_ll_wait_all_transaction_done();
|
||||
#if CONFIG_PM_SLP_SPIRAM_HALFSLEEP_ENABLED
|
||||
esp_psram_impl_enter_halfsleep_mode();
|
||||
@@ -518,7 +520,7 @@ SPM_IRAM_ATTR bool pmu_sleep_finish(bool dslp)
|
||||
_psram_ctrlr_ll_select_clk_source(PSRAM_CTRLR_LL_MSPI_ID_3, PSRAM_CLK_SRC_MPLL);
|
||||
#endif
|
||||
}
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
mspi_ll_psram_unhold_all_pins();
|
||||
#if CONFIG_PM_SLP_SPIRAM_HALFSLEEP_ENABLED
|
||||
esp_psram_impl_exit_halfsleep_mode();
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include "esp_fault.h"
|
||||
#include "hal/cache_ll.h"
|
||||
#include "riscv/csr.h"
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
#include "esp_private/esp_psram_extram.h"
|
||||
#endif /* CONFIG_SPIRAM */
|
||||
#endif /* !BOOTLOADER_BUILD && CONFIG_SPIRAM */
|
||||
|
||||
/* TODO: [ESP32S31] IDF-15238 */
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "hal/efuse_hal.h"
|
||||
#include "hal/mspi_ll.h"
|
||||
#include "esp_hw_log.h"
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
#include "esp_private/esp_psram_impl.h"
|
||||
#include "hal/psram_ctrlr_ll.h"
|
||||
#endif
|
||||
@@ -341,7 +341,7 @@ void pmu_sleep_init(const pmu_sleep_config_t *config, bool dslp)
|
||||
IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp)
|
||||
{
|
||||
if (!dslp) {
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
psram_ctrlr_ll_wait_all_transaction_done();
|
||||
#if CONFIG_PM_SLP_SPIRAM_HALFSLEEP_ENABLED
|
||||
esp_psram_impl_enter_halfsleep_mode();
|
||||
@@ -390,7 +390,7 @@ IRAM_ATTR bool pmu_sleep_finish(bool dslp)
|
||||
rtc_clk_mpll_enable();
|
||||
rtc_clk_mpll_configure(clk_hal_xtal_get_freq_mhz(), s_mpll_freq_mhz_before_sleep, false);
|
||||
}
|
||||
#if CONFIG_SPIRAM
|
||||
#if !BOOTLOADER_BUILD && CONFIG_SPIRAM
|
||||
mspi_ll_psram_unhold_all_pins();
|
||||
#if CONFIG_PM_SLP_SPIRAM_HALFSLEEP_ENABLED
|
||||
esp_psram_impl_exit_halfsleep_mode();
|
||||
|
||||
Reference in New Issue
Block a user