From 9274a062fbcf0a6695d5d409934028f79216f938 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 7 Feb 2022 17:20:59 +0800 Subject: [PATCH] esp-system: removed esp_phy and nvs dependencies, change app update and pm to weak dependencies --- components/esp_system/CMakeLists.txt | 9 +++++-- components/esp_system/freertos_hooks.c | 26 +++++++++---------- components/esp_system/panic.c | 8 +++++- components/esp_system/startup.c | 14 +++++++--- tools/ci/check_copyright_ignore.txt | 1 - .../system/g1_components/CMakeLists.txt | 9 +++---- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index ebd597758a..3747cbd10e 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -40,12 +40,11 @@ else() # [refactor-todo] requirements due to init code, # should be removable once using component init functions # link-time registration is used. - esp_pm app_update nvs_flash pthread # [refactor-todo] requires "driver" for headers: # - periph_ctrl.h # - rtc_cntl.h # - spi_common_internal.h - esp_phy efuse driver + pthread bootloader_support efuse driver LDFRAGMENTS "linker.lf" "app.lf") add_subdirectory(port) @@ -91,3 +90,9 @@ endif() # [refactor-todo] requirement from the panic handler, # need to introduce panic "event" concept to remove this dependency (IDF-2194) idf_component_optional_requires(PRIVATE esp_gdbstub) + +idf_component_optional_requires(PRIVATE app_update) + +if(CONFIG_PM_ENABLE) + idf_component_optional_requires(PRIVATE pm) +endif() diff --git a/components/esp_system/freertos_hooks.c b/components/esp_system/freertos_hooks.c index 74f1db518e..3889cfcc79 100644 --- a/components/esp_system/freertos_hooks.c +++ b/components/esp_system/freertos_hooks.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-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include @@ -21,8 +13,11 @@ #include "esp_freertos_hooks.h" #include "sdkconfig.h" + +#if CONFIG_PM_ENABLE #include "esp_pm.h" #include "esp_private/pm_impl.h" +#endif //We use just a static array here because it's not expected many components will need //an idle or tick hook. @@ -58,9 +53,12 @@ void esp_vApplicationIdleHook(void) #ifdef CONFIG_PM_ENABLE esp_pm_impl_idle_hook(); + esp_pm_impl_waiti(); +#else + cpu_hal_waiti(); #endif - esp_pm_impl_waiti(); + } esp_err_t esp_register_freertos_idle_hook_for_cpu(esp_freertos_idle_cb_t new_idle_cb, UBaseType_t cpuid) diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index f15f1a0be2..228eb2fd27 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -11,7 +11,6 @@ #include "esp_private/system_internal.h" #include "esp_private/usb_console.h" -#include "esp_ota_ops.h" #include "esp_cpu.h" #include "soc/rtc.h" @@ -26,6 +25,11 @@ #include "sdkconfig.h" +#if __has_include("esp_ota_ops.h") +#include "esp_ota_ops.h" +#define HAS_ESP_OTA 1 +#endif + #if CONFIG_ESP_COREDUMP_ENABLE #include "esp_core_dump.h" #endif @@ -309,11 +313,13 @@ void esp_panic_handler(panic_info_t *info) PANIC_INFO_DUMP(info, state); panic_print_str("\r\n"); +#if HAS_ESP_OTA panic_print_str("\r\nELF file SHA256: "); char sha256_buf[65]; esp_ota_get_app_elf_sha256(sha256_buf, sizeof(sha256_buf)); panic_print_str(sha256_buf); panic_print_str("\r\n"); +#endif //HAS_ESP_OTA panic_print_str("\r\n"); diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index dab43faf2f..0bc753c368 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -12,7 +12,6 @@ #include "esp_system.h" #include "esp_log.h" -#include "esp_ota_ops.h" #include "sdkconfig.h" @@ -35,10 +34,13 @@ #include "esp_sleep.h" #include "esp_xt_wdt.h" +#if __has_include("esp_ota_ops.h") +#include "esp_ota_ops.h" +#define HAS_ESP_OTA 1 +#endif + /***********************************************/ // Headers for other components init functions -#include "nvs_flash.h" - #include "esp_coexist_internal.h" #if CONFIG_ESP_COREDUMP_ENABLE @@ -50,8 +52,12 @@ #endif #include "esp_private/dbg_stubs.h" + +#if CONFIG_PM_ENABLE #include "esp_pm.h" #include "esp_private/pm_impl.h" +#endif + #include "esp_pthread.h" #include "esp_vfs_console.h" #include "esp_private/esp_clk.h" @@ -368,6 +374,7 @@ static void start_cpu0_default(void) int cpu_freq = esp_clk_cpu_freq(); ESP_EARLY_LOGI(TAG, "cpu freq: %d Hz", cpu_freq); +#if HAS_ESP_OTA // [refactor-todo] find a better way to handle this. // Display information about the current running image. if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { const esp_app_desc_t *app_desc = esp_ota_get_app_description(); @@ -389,6 +396,7 @@ static void start_cpu0_default(void) ESP_EARLY_LOGI(TAG, "ELF file SHA256: %s...", buf); ESP_EARLY_LOGI(TAG, "ESP-IDF: %s", app_desc->idf_ver); } +#endif //HAS_ESP_OTA // Initialize core components and services. do_core_init(); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 622183dd9f..d8058a83ca 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -675,7 +675,6 @@ components/esp_serial_slave_link/include/essl_spi/esp32c3_defs.h components/esp_serial_slave_link/include/essl_spi/esp32s2_defs.h components/esp_serial_slave_link/include/essl_spi/esp32s3_defs.h components/esp_system/esp_err.c -components/esp_system/freertos_hooks.c components/esp_system/include/eh_frame_parser.h components/esp_system/include/esp_debug_helpers.h components/esp_system/include/esp_expression_with_stack.h diff --git a/tools/test_apps/system/g1_components/CMakeLists.txt b/tools/test_apps/system/g1_components/CMakeLists.txt index 5592e3a449..03b9ba0e24 100644 --- a/tools/test_apps/system/g1_components/CMakeLists.txt +++ b/tools/test_apps/system/g1_components/CMakeLists.txt @@ -22,10 +22,8 @@ set(extra_allowed_components # These components are currently included into "G1" build, but shouldn't. # After removing the extra dependencies, remove the components from this list as well. set(extra_components_which_shouldnt_be_included - # app_update gets added because of bootloader_support, spi_flash, espcoredump, esp_system. + # app_update gets added because of bootloader_support, spi_flash, espcoredump. # bootloader_support, spi_flash, espcoredump should be removed from dependencies; - # esp_system code that reads app version should be made conditional on app_update being included - # (via weak CMake dependency and #if __has_include in C code) app_update # of G1 components, bootloader is only included from spi_flash # [refactor-todo]: see if this dependency from spi_flash can be made weak @@ -50,9 +48,9 @@ set(extra_components_which_shouldnt_be_included esp_event # esp_netif is a dependency of lwip and esp_event, should disappear once lwip is removed. esp_netif - # esp_phy is a dependency of esp_system and esp_wifi. For the former, it can be made a weak dependency. + # esp_phy is a dependency of esp_wifi. esp_phy - # esp_pm is pulled in by esp_system and freertos, can be made a weak dependency + # esp_pm is pulled in by freertos, can be made a weak dependency # conditional on related Kconfig option. It is also used by esp_wifi, driver, mbedtls, # all of which should be removed from G1-only build. esp_pm @@ -74,7 +72,6 @@ set(extra_components_which_shouldnt_be_included # it is hard to make it conditional, need to remove bootloader_support. mbedtls # nvs_flash is required by: - # esp_system — no obvious reason, [refactor-todo] why? # esp_wifi, esp_phy — both should be removed nvs_flash # partition_table is pulled in by app_update, esptool_py, bootloader; all to be removed