On upgrading my projects to the latest SDK, I was annoyed that I had to upload the esp_init_data_default.bin file to different locations dependent on flash size/module I was using.
I have modules in the field that need to be upgraded, and I cannot always guarantee that they're the same flash sizes either, or dont want to have that problem down the line anyway.
As such, I just added the init data to user_rf_pre_init() with the following code, if its not found then it'll update itself:
const uint32 esp_init_data_default[] = {
0x02040005,0x02050505,0x05040005,0x05050405,0xFFFDFE04,0xE0F0F0F0,
0x0AE1E0E0,0x00F8FFFF,0x4E52F8F8,0x3840444A,0x01010000,0x03030302,
0x00000001,0x00020000,0x00000000,0x00000000,0x000A0AE1,0x00000000,
0x93010000,0x00000043,0x00000000,0x00000000,0x00000000,0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000,0x00010000,0x00000000,
0x00000000,0x00000000};
void user_rf_pre_init() {
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0, addr, rfCalData;
os_printf("\nUser preinit: ");
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 8;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
addr = ((rf_cal_sec) * SPI_FLASH_SEC_SIZE)+0x1000;
spi_flash_read(addr, &rfCalData, 4);
if (rfCalData == 0xFFFFFFFF) {
os_printf("Storing rfcal init data @ address=0x%08X\n", addr);
spi_flash_erase_sector(rf_cal_sec);
spi_flash_write(addr, (uint32 *)esp_init_data_default, sizeof(esp_init_data_default));
} else {
os_printf("RF init data present\n");
}
}