Skip to content

Commit a76ef29

Browse files
authored
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.
1 parent 97018a5 commit a76ef29

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cores/esp8266/core_esp8266_main.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ extern "C" uint8_t uart_rx_one_char_block();
424424
#include "flash_hal.h"
425425
#endif
426426

427+
extern "C" void user_rf_pre_init();
428+
427429
extern "C" void ICACHE_FLASH_ATTR user_pre_init(void)
428430
{
429431
const char *flash_map_str = NULL;
@@ -623,16 +625,26 @@ extern "C" void ICACHE_FLASH_ATTR user_pre_init(void)
623625
uart_rx_one_char_block(); // Someone said hello - repeat message
624626
} while(true);
625627
}
628+
/*
629+
The function user_rf_pre_init() is no longer called from SDK 3.0 and up.
630+
The SDK manual and release notes skipped this detail. The 2023 ESP-FAQ
631+
hints at the change with "* Call system_phy_set_powerup_option(3) in
632+
function user_pre_init or user_rf_pre_init"
633+
https://docs.espressif.com/_/downloads/espressif-esp-faq/en/latest/pdf/#page=14
634+
635+
Add call to user_rf_pre_init(), so we can still perform early calls like
636+
system_phy_set_rfoption(rf_mode), system_phy_set_powerup_option(2), etc.
637+
638+
Placement, should this be at the beginning or end of user_pre_init()?
639+
By the end, we have registered the PHY_DATA partition; however, PHY_DATA
640+
read occurs after return and before user_init() is called.
641+
*/
642+
user_rf_pre_init();
626643
}
627644
#endif // #if (NONOSDK >= (0x30000))
628645

629646
extern "C" void user_init(void) {
630647

631-
#if (NONOSDK >= (0x30000))
632-
extern void user_rf_pre_init();
633-
user_rf_pre_init(); // Stop spoofing logic
634-
#endif
635-
636648
struct rst_info *rtc_info_ptr = system_get_rst_info();
637649
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
638650

cores/esp8266/core_esp8266_phy.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ extern int IRAM_ATTR __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t
320320
return __real_spi_flash_read(addr, dst, size);
321321
}
322322

323+
#if (NONOSDK >= (0x30000))
324+
spoof_init_data = false;
325+
#endif
323326
memcpy(dst, phy_init_data, sizeof(phy_init_data));
324327
((uint8_t*)dst)[107] = __get_adc_mode();
325328
return 0;
@@ -340,13 +343,13 @@ extern int __get_adc_mode(void)
340343
extern void __run_user_rf_pre_init(void) __attribute__((weak));
341344
extern void __run_user_rf_pre_init(void)
342345
{
343-
return; // default do noting
346+
return; // default do nothing
344347
}
345348

346349
#if (NONOSDK >= (0x30000))
347350
void sdk3_begin_phy_data_spoof(void)
348351
{
349-
spoof_init_data = true;
352+
spoof_init_data = true;
350353
}
351354
#else
352355
uint32_t user_rf_cal_sector_set(void)
@@ -359,7 +362,9 @@ uint32_t user_rf_cal_sector_set(void)
359362
void user_rf_pre_init()
360363
{
361364
// *((volatile uint32_t*) 0x60000710) = 0;
365+
#if (NONOSDK < (0x30000))
362366
spoof_init_data = false;
367+
#endif
363368

364369
int rf_mode = __get_rf_mode();
365370
if (rf_mode >= 0) {

0 commit comments

Comments
 (0)