From b13e76816b47029ea5120e73bedb307b3e9c9f63 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Sun, 12 Mar 2023 10:46:44 -0700 Subject: [PATCH 1/3] 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. --- cores/esp8266/core_esp8266_main.cpp | 21 +++++++++++++++++++-- cores/esp8266/core_esp8266_phy.cpp | 7 +++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index ccacc95e01..a4ff9c0a08 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,14 +625,29 @@ 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 already registered the PHY_DATA partition. + SDK v2.2 called user_rf_pre_init() after reading PHY_DATA. + */ + 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 + extern void sdk3_end_phy_data_spoof(void); + sdk3_end_phy_data_spoof(); #endif struct rst_info *rtc_info_ptr = system_get_rst_info(); diff --git a/cores/esp8266/core_esp8266_phy.cpp b/cores/esp8266/core_esp8266_phy.cpp index 2a324a85f9..6a90d2bd17 100644 --- a/cores/esp8266/core_esp8266_phy.cpp +++ b/cores/esp8266/core_esp8266_phy.cpp @@ -348,6 +348,11 @@ void sdk3_begin_phy_data_spoof(void) { spoof_init_data = true; } + +void sdk3_end_phy_data_spoof(void) +{ + spoof_init_data = false; +} #else uint32_t user_rf_cal_sector_set(void) { @@ -359,7 +364,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) { From eba42d87319087e77f30d84173e39fd9c54d8887 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Mon, 13 Mar 2023 09:33:54 -0700 Subject: [PATCH 2/3] Update comment --- cores/esp8266/core_esp8266_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index a4ff9c0a08..5daeaeac01 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -636,8 +636,8 @@ extern "C" void ICACHE_FLASH_ATTR user_pre_init(void) 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 already registered the PHY_DATA partition. - SDK v2.2 called user_rf_pre_init() after reading PHY_DATA. + 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(); } From 9cb0e9be022359ef996db58b003cfcb4f0b5a13a Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Mon, 27 Mar 2023 20:08:34 -0700 Subject: [PATCH 3/3] 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 | 5 ----- cores/esp8266/core_esp8266_phy.cpp | 12 +++++------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 5daeaeac01..f034f46524 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -645,11 +645,6 @@ extern "C" void ICACHE_FLASH_ATTR user_pre_init(void) extern "C" void user_init(void) { -#if (NONOSDK >= (0x30000)) - extern void sdk3_end_phy_data_spoof(void); - sdk3_end_phy_data_spoof(); -#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 6a90d2bd17..4657bb0081 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,18 +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; -} - -void sdk3_end_phy_data_spoof(void) -{ - spoof_init_data = false; + spoof_init_data = true; } #else uint32_t user_rf_cal_sector_set(void)