Skip to content

Commit

Permalink
Support user_rf_pre_init() for SDK v3.0 (#8888)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mhightower83 committed Mar 30, 2023
1 parent 97018a5 commit a76ef29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
22 changes: 17 additions & 5 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
9 changes: 7 additions & 2 deletions cores/esp8266/core_esp8266_phy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit a76ef29

Please sign in to comment.