From 4a6e7933223e12f2f00b51bd4b198aa41c2f678c Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Mon, 1 Jun 2020 20:33:23 +0800 Subject: [PATCH] esp32: Reduce using ESP_EARLY_LOGx and move some code after the stdout initialization After setting _GLOBAL_REENT, ESP_LOGIx can be used instead of ESP_EARLY_LOGx. Closes: https://github.com/espressif/esp-idf/issues/5343 --- components/bootloader_support/src/flash_encrypt.c | 10 +++++----- components/efuse/src/esp_efuse_api.c | 2 +- components/efuse/src/esp_efuse_fields.c | 2 +- components/esp32/cpu_start.c | 15 ++++++++------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/components/bootloader_support/src/flash_encrypt.c b/components/bootloader_support/src/flash_encrypt.c index a7f0768a07..c39804ae59 100644 --- a/components/bootloader_support/src/flash_encrypt.c +++ b/components/bootloader_support/src/flash_encrypt.c @@ -36,7 +36,7 @@ void esp_flash_encryption_init_checks() uint8_t flash_crypt_cnt_wr_dis = 0; esp_efuse_read_field_blob(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT, &flash_crypt_cnt_wr_dis, 1); if (!flash_crypt_cnt_wr_dis) { - ESP_EARLY_LOGE(TAG, "Flash encryption & Secure Boot together requires FLASH_CRYPT_CNT efuse to be write protected. Fixing now..."); + ESP_LOGE(TAG, "Flash encryption & Secure Boot together requires FLASH_CRYPT_CNT efuse to be write protected. Fixing now..."); esp_flash_write_protect_crypt_cnt(); } } @@ -48,13 +48,13 @@ void esp_flash_encryption_init_checks() mode = esp_get_flash_encryption_mode(); if (mode == ESP_FLASH_ENC_MODE_DEVELOPMENT) { #ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE - ESP_EARLY_LOGE(TAG, "Flash encryption settings error: app is configured for RELEASE but efuses are set for DEVELOPMENT"); - ESP_EARLY_LOGE(TAG, "Mismatch found in security options in bootloader menuconfig and efuse settings. Device is not secure."); + ESP_LOGE(TAG, "Flash encryption settings error: app is configured for RELEASE but efuses are set for DEVELOPMENT"); + ESP_LOGE(TAG, "Mismatch found in security options in bootloader menuconfig and efuse settings. Device is not secure."); #else - ESP_EARLY_LOGW(TAG, "Flash encryption mode is DEVELOPMENT (not secure)"); + ESP_LOGW(TAG, "Flash encryption mode is DEVELOPMENT (not secure)"); #endif } else if (mode == ESP_FLASH_ENC_MODE_RELEASE) { - ESP_EARLY_LOGI(TAG, "Flash encryption mode is RELEASE"); + ESP_LOGI(TAG, "Flash encryption mode is RELEASE"); } } #endif diff --git a/components/efuse/src/esp_efuse_api.c b/components/efuse/src/esp_efuse_api.c index a000d73b8c..57a71970a3 100644 --- a/components/efuse/src/esp_efuse_api.c +++ b/components/efuse/src/esp_efuse_api.c @@ -197,7 +197,7 @@ esp_efuse_coding_scheme_t esp_efuse_get_coding_scheme(esp_efuse_block_t blk) scheme = EFUSE_CODING_SCHEME_REPEAT; } } - ESP_EARLY_LOGD(TAG, "coding scheme %d", scheme); + ESP_LOGD(TAG, "coding scheme %d", scheme); return scheme; } diff --git a/components/efuse/src/esp_efuse_fields.c b/components/efuse/src/esp_efuse_fields.c index 8e3cdc7992..17fdcdddb0 100644 --- a/components/efuse/src/esp_efuse_fields.c +++ b/components/efuse/src/esp_efuse_fields.c @@ -82,7 +82,7 @@ void esp_efuse_reset(void) void esp_efuse_disable_basic_rom_console(void) { if (esp_efuse_write_field_cnt(ESP_EFUSE_CONSOLE_DEBUG_DISABLE, 1) == ESP_OK) { - ESP_EARLY_LOGI(TAG, "Disable BASIC ROM Console fallback via efuse..."); + ESP_LOGI(TAG, "Disable BASIC ROM Console fallback via efuse..."); } } diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 403d3f85c7..316ef630d4 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -204,10 +204,6 @@ void IRAM_ATTR call_start_cpu0() } ESP_EARLY_LOGI(TAG, "Starting app cpu, entry point is %p", call_start_cpu1); -#ifdef CONFIG_SECURE_FLASH_ENC_ENABLED - esp_flash_encryption_init_checks(); -#endif - //Flush and enable icache for APP CPU Cache_Flush(1); Cache_Read_Enable(1); @@ -348,9 +344,6 @@ void start_cpu0_default(void) #if CONFIG_ESP32_BROWNOUT_DET esp_brownout_init(); -#endif -#if CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE - esp_efuse_disable_basic_rom_console(); #endif rtc_gpio_force_hold_dis_all(); esp_vfs_dev_uart_register(); @@ -364,6 +357,14 @@ void start_cpu0_default(void) _GLOBAL_REENT->_stdin = (FILE*) &__sf_fake_stdin; _GLOBAL_REENT->_stdout = (FILE*) &__sf_fake_stdout; _GLOBAL_REENT->_stderr = (FILE*) &__sf_fake_stderr; +#endif + // After setting _GLOBAL_REENT, ESP_LOGIx can be used instead of ESP_EARLY_LOGx. + +#ifdef CONFIG_SECURE_FLASH_ENC_ENABLED + esp_flash_encryption_init_checks(); +#endif +#if CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE + esp_efuse_disable_basic_rom_console(); #endif esp_timer_init(); esp_set_time_from_rtc();