When the programm is linked against some libs of the SKD like libpwm or libssl and turned into a OTA image, the ESP crashes with Fatal Exception (0) right after the bootloader stage
This only occurs with OTA image. The same code compiled for FOTA boots and works as excpected.
No functions of these libs are even called (their sole presence causes the crash)
Using the linker option gc-section to remove usused code inlfuence this behavior (the linkage against a different library cause the Fatal Exception)
Detected on SDK 2.2 and 3.0, on all the three ESP8266 tested, 2MBytes 512+512 flash map (definitively a software bug)
I suspect some misaligned data, or that Esptool fails to correctly generate a "vesion=2" image for OTA.
It may be related to the issues mentionning that the order in which the libs are linked can make a software crashes.
The exception pointer resulting from the code below is ecp1=0x40210c54, but In my numerous previous tests it was always around ecp1= 0x401000xx, i.e. at the very begining of the code...
Here is a minimal code reproducing the bug:
/*
* Debuging app that crashes with fatal exception when compiled fo OTA.
* Compiled fo non-OTA: works
* Compiled for OTA (bootloader 1.7): fatal exception right after boot. Due to PWM lib ?
*/
#include "osapi.h"
#include "os_type.h"
#include "user_interface.h"
#include "gpio.h"
#include "pwm.h"
#include "espconn.h"
#include "driver/i2c_master.h"
void PostInitCb(void);
uint32 user_rf_cal_sector_set(void);
void user_init(void);
/**
* @brief Called when system is fully initialized.
*/
void PostInitCb(void)
{
os_printf("PostInitCb() !\n");
/* Force references to functions from the libs without calling them */
volatile bool tt = false;
if(tt)
{
pwm_start(); /* Uncommented: crash ! */
gpio_init(); /* Uncommented or commented: works ok */
espconn_secure_set_size(ESPCONN_CLIENT, 5120); /* Uncommented or commented: depends on gc-section */
i2c_master_gpio_init(); /* Uncommented or commented: works ok */
}
}
/**
* @brief Was present in IoT_Demo/user/user_main.c on which this code is based...
*/
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
os_printf("BB!\n");
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
rf_cal_sec = 1024 - 5;
break;
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
/**
* @brief Main entry point of our programm
*/
void user_init(void)
{
os_printf("AA!\n");
system_init_done_cb(PostInitCb);
}
My Xtensa compiler command looks like:
I then use esptool elf2image -version=2 to convert the elf to binaries.
And last but not least, the disasembled file around the address pointed by ecp1:
(If I understand well, the address pointed does not exist/is not aligned !)
Hello all,
I suspect some misaligned data, or that Esptool fails to correctly generate a "vesion=2" image for OTA. It may be related to the issues mentionning that the order in which the libs are linked can make a software crashes. The exception pointer resulting from the code below is
ecp1=0x40210c54
, but In my numerous previous tests it was always around ecp1= 0x401000xx, i.e. at the very begining of the code...Here is a minimal code reproducing the bug:
My Xtensa compiler command looks like: I then use esptool elf2image -version=2 to convert the elf to binaries.
And last but not least, the disasembled file around the address pointed by ecp1: (If I understand well, the address pointed does not exist/is not aligned !)
I would love an insight from you <3 !