From 4702feeeebcd4ccb3090f4747f96aea6d719f432 Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Wed, 7 Apr 2021 15:04:51 +0800 Subject: [PATCH] esp_wifi: move unused wifi log to noload section to save binary size --- components/esp32/ld/esp32.project.ld.in | 8 ++- components/esp32c3/ld/esp32c3.project.ld.in | 6 ++ components/esp32s2/ld/esp32s2.project.ld.in | 8 ++- components/esp32s3/ld/esp32s3.project.ld.in | 8 ++- components/esp_wifi/Kconfig | 77 --------------------- components/esp_wifi/lib | 2 +- components/esp_wifi/linker.lf | 40 +++++++++++ components/esp_wifi/src/wifi_init.c | 61 +++++----------- 8 files changed, 85 insertions(+), 125 deletions(-) diff --git a/components/esp32/ld/esp32.project.ld.in b/components/esp32/ld/esp32.project.ld.in index a9ff6f9ea9..f58878ac9e 100644 --- a/components/esp32/ld/esp32.project.ld.in +++ b/components/esp32/ld/esp32.project.ld.in @@ -311,7 +311,13 @@ SECTIONS . = ALIGN(4); } >default_rodata_seg - _flash_rodata_align = ALIGNOF(.flash.rodata); + .flash.rodata_noload (NOLOAD) : + { + . = ALIGN (4); + mapping[rodata_noload] + } > default_rodata_seg + + _flash_rodata_align = ALIGNOF(.flash.rodata_noload); .flash.text : { diff --git a/components/esp32c3/ld/esp32c3.project.ld.in b/components/esp32c3/ld/esp32c3.project.ld.in index 58f27c9e19..7c4c031a28 100644 --- a/components/esp32c3/ld/esp32c3.project.ld.in +++ b/components/esp32c3/ld/esp32c3.project.ld.in @@ -345,6 +345,12 @@ SECTIONS . = ALIGN(4); } > default_rodata_seg + .flash.rodata_noload (NOLOAD) : + { + . = ALIGN (4); + mapping[rodata_noload] + } > default_rodata_seg + /* Marks the end of IRAM code segment */ .iram0.text_end (NOLOAD) : { diff --git a/components/esp32s2/ld/esp32s2.project.ld.in b/components/esp32s2/ld/esp32s2.project.ld.in index fb942d5ac9..c99ec5bab5 100644 --- a/components/esp32s2/ld/esp32s2.project.ld.in +++ b/components/esp32s2/ld/esp32s2.project.ld.in @@ -325,7 +325,13 @@ SECTIONS . = ALIGN(4); } >default_rodata_seg - _flash_rodata_align = ALIGNOF(.flash.rodata); + .flash.rodata_noload (NOLOAD) : + { + . = ALIGN (4); + mapping[rodata_noload] + } > default_rodata_seg + + _flash_rodata_align = ALIGNOF(.flash.rodata_noload); .flash.text : { diff --git a/components/esp32s3/ld/esp32s3.project.ld.in b/components/esp32s3/ld/esp32s3.project.ld.in index d420afb646..92e3d669be 100644 --- a/components/esp32s3/ld/esp32s3.project.ld.in +++ b/components/esp32s3/ld/esp32s3.project.ld.in @@ -363,7 +363,13 @@ SECTIONS . = ALIGN(4); } > default_rodata_seg - _flash_rodata_align = ALIGNOF(.flash.rodata); + .flash.rodata_noload (NOLOAD) : + { + . = ALIGN (4); + mapping[rodata_noload] + } > default_rodata_seg + + _flash_rodata_align = ALIGNOF(.flash.rodata_noload); /* Marks the end of IRAM code segment */ .iram0.text_end (NOLOAD) : diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index d8af7fa0aa..bf24961688 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -218,83 +218,6 @@ menu "Wi-Fi" help Set the number of WiFi management short buffer. - config ESP32_WIFI_DEBUG_LOG_ENABLE - bool "Enable WiFi debug log" - default n - help - Select this option to enable WiFi debug log - - choice ESP32_WIFI_DEBUG_LOG_LEVEL - depends on ESP32_WIFI_DEBUG_LOG_ENABLE - prompt "WiFi debug log level" - default ESP32_WIFI_DEBUG_LOG_DEBUG - help - The WiFi log is divided into the following levels: ERROR,WARNING,INFO,DEBUG,VERBOSE. - The ERROR,WARNING,INFO levels are enabled by default, and the DEBUG,VERBOSE levels can be enabled here. - - config ESP32_WIFI_DEBUG_LOG_DEBUG - bool "WiFi Debug Log Debug" - config ESP32_WIFI_DEBUG_LOG_VERBOSE - bool "WiFi Debug Log Verbose" - endchoice - - choice ESP32_WIFI_DEBUG_LOG_MODULE - depends on ESP32_WIFI_DEBUG_LOG_ENABLE - prompt "WiFi debug log module" - default ESP32_WIFI_DEBUG_LOG_MODULE_WIFI - help - The WiFi log module contains three parts: WIFI,COEX,MESH. The WIFI module indicates the logs related to - WiFi, the COEX module indicates the logs related to WiFi and BT(or BLE) coexist, the MESH module indicates - the logs related to Mesh. When ESP32_WIFI_LOG_MODULE_ALL is enabled, all modules are selected. - - config ESP32_WIFI_DEBUG_LOG_MODULE_ALL - bool "WiFi Debug Log Module All" - config ESP32_WIFI_DEBUG_LOG_MODULE_WIFI - bool "WiFi Debug Log Module WiFi" - config ESP32_WIFI_DEBUG_LOG_MODULE_COEX - bool "WiFi Debug Log Module Coex" - config ESP32_WIFI_DEBUG_LOG_MODULE_MESH - bool "WiFi Debug Log Module Mesh" - endchoice - - config ESP32_WIFI_DEBUG_LOG_SUBMODULE - depends on ESP32_WIFI_DEBUG_LOG_ENABLE - bool "WiFi debug log submodule" - default n - help - Enable this option to set the WiFi debug log submodule. - Currently the log submodule contains the following parts: INIT,IOCTL,CONN,SCAN. - The INIT submodule indicates the initialization process.The IOCTL submodule indicates the API calling - process. - The CONN submodule indicates the connecting process.The SCAN submodule indicates the scaning process. - - config ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL - depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE - bool "WiFi Debug Log Submodule All" - default n - help - When this option is enabled, all debug submodules are selected. - - config ESP32_WIFI_DEBUG_LOG_SUBMODULE_INIT - depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL) - bool "WiFi Debug Log Submodule Init" - default n - - config ESP32_WIFI_DEBUG_LOG_SUBMODULE_IOCTL - depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL) - bool "WiFi Debug Log Submodule Ioctl" - default n - - config ESP32_WIFI_DEBUG_LOG_SUBMODULE_CONN - depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL) - bool "WiFi Debug Log Submodule Conn" - default n - - config ESP32_WIFI_DEBUG_LOG_SUBMODULE_SCAN - depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL) - bool "WiFi Debug Log Submodule Scan" - default n - config ESP32_WIFI_IRAM_OPT bool "WiFi IRAM speed optimization" default n if (BT_ENABLED && ESP32_SPIRAM_SUPPORT) diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index f522a17117..1b54038e45 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit f522a17117a0d64fce697d2b26c6e4a8c1781b1b +Subproject commit 1b54038e45596e23bed19ccb41d519065f0174ed diff --git a/components/esp_wifi/linker.lf b/components/esp_wifi/linker.lf index 8b2c35d86a..39a203f63b 100644 --- a/components/esp_wifi/linker.lf +++ b/components/esp_wifi/linker.lf @@ -43,6 +43,26 @@ entries: entries: wifi_slp_rx_iram -> iram0_text +[sections:wifi_log_error] +entries: + .rodata_wlog_error+ + +[sections:wifi_log_warning] +entries: + .rodata_wlog_warning+ + +[sections:wifi_log_info] +entries: + .rodata_wlog_info+ + +[sections:wifi_log_debug] +entries: + .rodata_wlog_debug+ + +[sections:wifi_log_verbose] +entries: + .rodata_wlog_verbose+ + [scheme:wifi_default] entries: wifi_slp_iram -> flash_text @@ -50,6 +70,26 @@ entries: wifi_slp_rx_iram -> flash_text wifi_iram -> flash_text wifi_rx_iram -> flash_text + if LOG_MAXIMUM_LEVEL <= 0: + wifi_log_error -> rodata_noload + else: + wifi_log_error -> flash_rodata + if LOG_MAXIMUM_LEVEL <= 1: + wifi_log_warning -> rodata_noload + else: + wifi_log_warning -> flash_rodata + if LOG_MAXIMUM_LEVEL <= 2: + wifi_log_info -> rodata_noload + else: + wifi_log_info -> flash_rodata + if LOG_MAXIMUM_LEVEL <= 3: + wifi_log_debug -> rodata_noload + else: + wifi_log_debug -> flash_rodata + if LOG_MAXIMUM_LEVEL <= 4: + wifi_log_verbose -> rodata_noload + else: + wifi_log_verbose -> flash_rodata [mapping:wifi_default] archive: * diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 2b00a04282..04fe932331 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -80,51 +80,24 @@ static void __attribute__((constructor)) s_set_default_wifi_log_level(void) esp_log_level_set("ESPNOW", CONFIG_LOG_DEFAULT_LEVEL); } -static void esp_wifi_set_debug_log(void) +static void esp_wifi_set_log_level(void) { - /* set WiFi log level and module */ -#if CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE - uint32_t g_wifi_log_level = WIFI_LOG_INFO; - uint32_t g_wifi_log_module = 0; - uint32_t g_wifi_log_submodule = 0; -#if CONFIG_ESP32_WIFI_DEBUG_LOG_DEBUG - g_wifi_log_level = WIFI_LOG_DEBUG; + wifi_log_level_t wifi_log_level = WIFI_LOG_INFO; + /* set WiFi log level */ +#if CONFIG_LOG_MAXIMUM_LEVEL == 0 + wifi_log_level = WIFI_LOG_NONE; +#elif CONFIG_LOG_MAXIMUM_LEVEL == 1 + wifi_log_level = WIFI_LOG_ERROR; +#elif CONFIG_LOG_MAXIMUM_LEVEL == 2 + wifi_log_level = WIFI_LOG_WARNING; +#elif CONFIG_LOG_MAXIMUM_LEVEL == 3 + wifi_log_level = WIFI_LOG_INFO; +#elif CONFIG_LOG_MAXIMUM_LEVEL == 4 + wifi_log_level = WIFI_LOG_DEBUG; +#elif CONFIG_LOG_MAXIMUM_LEVEL == 5 + wifi_log_level = WIFI_LOG_VERBOSE; #endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_VERBOSE - g_wifi_log_level = WIFI_LOG_VERBOSE; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_ALL - g_wifi_log_module = WIFI_LOG_MODULE_ALL; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_WIFI - g_wifi_log_module = WIFI_LOG_MODULE_WIFI; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_COEX - g_wifi_log_module = WIFI_LOG_MODULE_COEX; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_MESH - g_wifi_log_module = WIFI_LOG_MODULE_MESH; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL - g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_ALL; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_INIT - g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_INIT; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_IOCTL - g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_IOCTL; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_CONN - g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_CONN; -#endif -#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_SCAN - g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_SCAN; -#endif - esp_wifi_internal_set_log_level(g_wifi_log_level); - esp_wifi_internal_set_log_mod(g_wifi_log_module, g_wifi_log_submodule, true); - -#endif /* CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE*/ - + esp_wifi_internal_set_log_level(wifi_log_level); } esp_err_t esp_wifi_deinit(void) @@ -267,13 +240,13 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) #if CONFIG_SW_COEXIST_ENABLE coex_init(); #endif + esp_wifi_set_log_level(); esp_err_t result = esp_wifi_init_internal(config); if (result == ESP_OK) { #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_init(); esp_wifi_internal_set_mac_sleep(true); #endif - esp_wifi_set_debug_log(); #if CONFIG_IDF_TARGET_ESP32 s_wifi_mac_time_update_cb = esp_wifi_internal_update_mac_time; #endif