Skip to content

Commit da5bfd8

Browse files
mhightower83hasenradball
authored andcommitted
Fix flashinit panic not printing (esp8266#8762)
* fix panic not printing * improve panic to accept 0 lineno * always present detailed error message * Added back lost edit * For SDK v3.0+, adjust conditional build to remove duplicate call to flashinit from user_init.
1 parent b0e23fe commit da5bfd8

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

cores/esp8266/core_esp8266_main.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,9 @@ extern "C" void __disableWiFiAtBootTime (void)
400400

401401
#if FLASH_MAP_SUPPORT
402402
#include "flash_hal.h"
403-
extern "C" bool flashinit (void);
404-
#if (NONOSDK >= (0x30000))
405-
uint32_t __flashindex __attribute__((section(".noinit")));
406-
#else
403+
extern "C" const char *flashinit (void);
407404
uint32_t __flashindex;
408405
#endif
409-
#endif
410406

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

433429
do {
434430
#if FLASH_MAP_SUPPORT
435-
if (!flashinit()) {
436-
flash_map_str = PSTR("flashinit: flash size missing from FLASH_MAP table\n");
431+
flash_map_str = flashinit();
432+
if (flash_map_str) {
437433
continue;
438434
}
439435
#endif
@@ -631,6 +627,11 @@ extern "C" void user_init(void) {
631627

632628
uart_div_modify(0, UART_CLK_FREQ / (115200));
633629

630+
#if FLASH_MAP_SUPPORT && (NONOSDK < (0x30000))
631+
const char *err_msg = flashinit();
632+
if (err_msg) __panic_func(err_msg, 0, NULL);
633+
#endif
634+
634635
init(); // in core_esp8266_wiring.c, inits hw regs and sdk timer
635636

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

654655
#if defined(MMU_IRAM_HEAP)
655656
umm_init_iram();
656-
#endif
657-
#if FLASH_MAP_SUPPORT && (NONOSDK < 0x30000)
658-
if (!flashinit()) {
659-
panic();
660-
}
661657
#endif
662658
preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable.
663659
__disableWiFiAtBootTime(); // default weak function disables WiFi

cores/esp8266/core_esp8266_postmortem.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ void __wrap_system_restart_local() {
140140
}
141141
ets_putc('\n');
142142
}
143+
else if (s_panic_file) {
144+
ets_printf_P(PSTR("\nPanic %S\n"), s_panic_file);
145+
}
143146
else if (s_unhandled_exception) {
144147
ets_printf_P(PSTR("\nUnhandled C++ exception: %S\n"), s_unhandled_exception);
145148
}

cores/esp8266/flash_hal.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,26 @@ extern "C" {
3333
#include <FlashMap.h>
3434

3535
extern uint32_t spi_flash_get_id (void); // <user_interface.h>
36-
extern bool flashinit(void);
36+
extern const char *flashinit(void);
3737
extern uint32_t __flashindex;
3838
extern const flash_map_s __flashdesc[];
3939

40+
#ifndef QUOTE
41+
#define QUOTE(a) __STRINGIFY(a)
42+
#endif
43+
4044
#define FLASH_MAP_SETUP_CONFIG(conf) FLASH_MAP_SETUP_CONFIG_ATTR(,conf)
4145
#define FLASH_MAP_SETUP_CONFIG_ATTR(attr, conf...) \
4246
const flash_map_s __flashdesc[] PROGMEM = conf; \
43-
bool flashinit (void) attr; \
44-
bool flashinit (void) \
47+
const char *flashinit (void) attr; \
48+
const char *flashinit (void) \
4549
{ \
4650
uint32_t flash_chip_size_kb = 1 << (((spi_flash_get_id() >> 16) & 0xff) - 10); \
4751
for (__flashindex = 0; __flashindex < sizeof(__flashdesc) / sizeof(__flashdesc[0]); __flashindex++) \
4852
if (__flashdesc[__flashindex].flash_size_kb == flash_chip_size_kb) \
49-
return true; \
50-
return false; /* configuration not found */ \
53+
return NULL; \
54+
static const char fail_msg[] PROGMEM = __FILE__ ":" QUOTE(__LINE__) " flashinit: configuration not found"; \
55+
return fail_msg; /* configuration not found */ \
5156
}
5257

5358
#define EEPROM_start (__flashdesc[__flashindex].eeprom_start)

0 commit comments

Comments
 (0)