From a76ef290eaa445f0ad8603121b9a87745a24b072 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Thu, 30 Mar 2023 10:54:28 -0700 Subject: [PATCH] Support user_rf_pre_init() for SDK v3.0 (#8888) * For SDK v3.0+, early system calls that were called from user_rf_pre_init (SDK v2.2) need to now be called from user_pre_init. Moved user_rf_pre_init() call to the end of user_pre_init() so we can still perform early calls like: system_phy_set_rfoption(rf_mode), system_phy_set_powerup_option(2), etc. * Update comment * Improve "spoof_init_data" enable/disable logic. Out of an overabundance of caution, limit logic change to the experimental SDK v3.0.5. --- cores/esp8266/core_esp8266_main.cpp | 22 +++++++++++++++++----- cores/esp8266/core_esp8266_phy.cpp | 9 +++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index ccacc95e0..f034f4652 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -424,6 +424,8 @@ extern "C" uint8_t uart_rx_one_char_block(); #include "flash_hal.h" #endif +extern "C" void user_rf_pre_init(); + extern "C" void ICACHE_FLASH_ATTR user_pre_init(void) { const char *flash_map_str = NULL; @@ -623,16 +625,26 @@ extern "C" void ICACHE_FLASH_ATTR user_pre_init(void) uart_rx_one_char_block(); // Someone said hello - repeat message } while(true); } + /* + The function user_rf_pre_init() is no longer called from SDK 3.0 and up. + The SDK manual and release notes skipped this detail. The 2023 ESP-FAQ + hints at the change with "* Call system_phy_set_powerup_option(3) in + function user_pre_init or user_rf_pre_init" + https://docs.espressif.com/_/downloads/espressif-esp-faq/en/latest/pdf/#page=14 + + Add call to user_rf_pre_init(), so we can still perform early calls like + system_phy_set_rfoption(rf_mode), system_phy_set_powerup_option(2), etc. + + Placement, should this be at the beginning or end of user_pre_init()? + By the end, we have registered the PHY_DATA partition; however, PHY_DATA + read occurs after return and before user_init() is called. + */ + user_rf_pre_init(); } #endif // #if (NONOSDK >= (0x30000)) extern "C" void user_init(void) { -#if (NONOSDK >= (0x30000)) - extern void user_rf_pre_init(); - user_rf_pre_init(); // Stop spoofing logic -#endif - struct rst_info *rtc_info_ptr = system_get_rst_info(); memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo)); diff --git a/cores/esp8266/core_esp8266_phy.cpp b/cores/esp8266/core_esp8266_phy.cpp index 2a324a85f..4657bb008 100644 --- a/cores/esp8266/core_esp8266_phy.cpp +++ b/cores/esp8266/core_esp8266_phy.cpp @@ -320,6 +320,9 @@ extern int IRAM_ATTR __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t return __real_spi_flash_read(addr, dst, size); } +#if (NONOSDK >= (0x30000)) + spoof_init_data = false; +#endif memcpy(dst, phy_init_data, sizeof(phy_init_data)); ((uint8_t*)dst)[107] = __get_adc_mode(); return 0; @@ -340,13 +343,13 @@ extern int __get_adc_mode(void) extern void __run_user_rf_pre_init(void) __attribute__((weak)); extern void __run_user_rf_pre_init(void) { - return; // default do noting + return; // default do nothing } #if (NONOSDK >= (0x30000)) void sdk3_begin_phy_data_spoof(void) { - spoof_init_data = true; + spoof_init_data = true; } #else uint32_t user_rf_cal_sector_set(void) @@ -359,7 +362,9 @@ uint32_t user_rf_cal_sector_set(void) void user_rf_pre_init() { // *((volatile uint32_t*) 0x60000710) = 0; +#if (NONOSDK < (0x30000)) spoof_init_data = false; +#endif int rf_mode = __get_rf_mode(); if (rf_mode >= 0) {