From efbc980d4fa3484902be1b452971fb36aad45325 Mon Sep 17 00:00:00 2001 From: jingli Date: Fri, 29 Oct 2021 11:35:42 +0800 Subject: [PATCH] fix: app crash when OTA because the OTA task's stack is in rtc fast memory --- components/spi_flash/cache_utils.c | 31 ++++++++++++++++------------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/components/spi_flash/cache_utils.c b/components/spi_flash/cache_utils.c index dedd5f2b35..7715900055 100644 --- a/components/spi_flash/cache_utils.c +++ b/components/spi_flash/cache_utils.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -83,6 +75,17 @@ static volatile bool s_flash_op_complete = false; static volatile int s_flash_op_cpu = -1; #endif +static inline bool esp_task_stack_is_sane_cache_disabled(void) +{ + const void *sp = (const void *)esp_cpu_get_sp(); + + return esp_ptr_in_dram(sp) +#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP + || esp_ptr_in_rtc_dram_fast(sp) +#endif + ; +} + void spi_flash_init_lock(void) { s_flash_op_mutex = xSemaphoreCreateRecursiveMutex(); @@ -130,7 +133,7 @@ void IRAM_ATTR spi_flash_op_block_func(void *arg) void IRAM_ATTR spi_flash_disable_interrupts_caches_and_other_cpu(void) { - assert(esp_ptr_in_dram((const void *)esp_cpu_get_sp())); + assert(esp_task_stack_is_sane_cache_disabled()); spi_flash_op_lock(); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 97be9a450a..08792076b9 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -2566,7 +2566,6 @@ components/soc/include/soc/uhci_periph.h components/soc/include/soc/usb_periph.h components/soc/lldesc.c components/soc/soc_include_legacy_warn.c -components/spi_flash/cache_utils.c components/spi_flash/cache_utils.h components/spi_flash/esp32/flash_ops_esp32.c components/spi_flash/esp32/spi_flash_rom_patch.c