Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flashinit panic not printing #8762

Merged
merged 11 commits into from
Dec 22, 2022
20 changes: 8 additions & 12 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,9 @@ extern "C" void __disableWiFiAtBootTime (void)

#if FLASH_MAP_SUPPORT
#include "flash_hal.h"
extern "C" bool flashinit (void);
#if (NONOSDK >= (0x30000))
uint32_t __flashindex __attribute__((section(".noinit")));
#else
extern "C" const char *flashinit (void);
uint32_t __flashindex;
#endif
#endif

#if (NONOSDK >= (0x30000))
#undef ETS_PRINTF
Expand All @@ -432,8 +428,8 @@ extern "C" void ICACHE_FLASH_ATTR user_pre_init(void)

do {
#if FLASH_MAP_SUPPORT
if (!flashinit()) {
flash_map_str = PSTR("flashinit: flash size missing from FLASH_MAP table\n");
flash_map_str = flashinit();
if (flash_map_str) {
continue;
}
#endif
Expand Down Expand Up @@ -631,6 +627,11 @@ extern "C" void user_init(void) {

uart_div_modify(0, UART_CLK_FREQ / (115200));

#if FLASH_MAP_SUPPORT && (NONOSDK < (0x30000))
const char *err_msg = flashinit();
if (err_msg) __panic_func(err_msg, 0, NULL);
#endif

init(); // in core_esp8266_wiring.c, inits hw regs and sdk timer

initVariant();
Expand All @@ -653,11 +654,6 @@ extern "C" void user_init(void) {

#if defined(MMU_IRAM_HEAP)
umm_init_iram();
#endif
#if FLASH_MAP_SUPPORT && (NONOSDK < 0x30000)
if (!flashinit()) {
panic();
}
#endif
preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable.
__disableWiFiAtBootTime(); // default weak function disables WiFi
Expand Down
3 changes: 3 additions & 0 deletions cores/esp8266/core_esp8266_postmortem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ void __wrap_system_restart_local() {
}
ets_putc('\n');
}
else if (s_panic_file) {
ets_printf_P(PSTR("\nPanic %S\n"), s_panic_file);
}
else if (s_unhandled_exception) {
ets_printf_P(PSTR("\nUnhandled C++ exception: %S\n"), s_unhandled_exception);
}
Expand Down
15 changes: 10 additions & 5 deletions cores/esp8266/flash_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,26 @@ extern "C" {
#include <FlashMap.h>

extern uint32_t spi_flash_get_id (void); // <user_interface.h>
extern bool flashinit(void);
extern const char *flashinit(void);
extern uint32_t __flashindex;
extern const flash_map_s __flashdesc[];

#ifndef QUOTE
#define QUOTE(a) __STRINGIFY(a)
#endif

#define FLASH_MAP_SETUP_CONFIG(conf) FLASH_MAP_SETUP_CONFIG_ATTR(,conf)
#define FLASH_MAP_SETUP_CONFIG_ATTR(attr, conf...) \
const flash_map_s __flashdesc[] PROGMEM = conf; \
bool flashinit (void) attr; \
bool flashinit (void) \
const char *flashinit (void) attr; \
const char *flashinit (void) \
{ \
uint32_t flash_chip_size_kb = 1 << (((spi_flash_get_id() >> 16) & 0xff) - 10); \
for (__flashindex = 0; __flashindex < sizeof(__flashdesc) / sizeof(__flashdesc[0]); __flashindex++) \
if (__flashdesc[__flashindex].flash_size_kb == flash_chip_size_kb) \
return true; \
return false; /* configuration not found */ \
return NULL; \
static const char fail_msg[] PROGMEM = __FILE__ ":" QUOTE(__LINE__) " flashinit: configuration not found"; \
return fail_msg; /* configuration not found */ \
}

#define EEPROM_start (__flashdesc[__flashindex].eeprom_start)
Expand Down