Browse Source

esp8266/esp_init_data: Auto-initialize system params with vendor SDK 2.0.0.

SDK 2.0.0 goes into boot loop if a firmware is programmed over erased flash,
causing problems with user experience. This change implements behavior
similar to older SDKs': if clean flash is detected, default system
parameters are used.
pull/2531/head
Paul Sokolovsky 8 years ago
parent
commit
20d0271863
  1. 1
      esp8266/Makefile
  2. 2
      esp8266/esp8266.ld
  3. 80
      esp8266/esp_init_data.c

1
esp8266/Makefile

@ -65,6 +65,7 @@ SRC_C = \
main.c \ main.c \
help.c \ help.c \
esp_mphal.c \ esp_mphal.c \
esp_init_data.c \
gccollect.c \ gccollect.c \
lexerstr32.c \ lexerstr32.c \
uart.c \ uart.c \

2
esp8266/esp8266.ld

@ -20,7 +20,7 @@ PHDRS
irom0_0_phdr PT_LOAD; irom0_0_phdr PT_LOAD;
} }
ENTRY(call_user_start) ENTRY(firmware_start)
EXTERN(_DebugExceptionVector) EXTERN(_DebugExceptionVector)
EXTERN(_DoubleExceptionVector) EXTERN(_DoubleExceptionVector)
EXTERN(_KernelExceptionVector) EXTERN(_KernelExceptionVector)

80
esp8266/esp_init_data.c

@ -0,0 +1,80 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include "ets_sys.h"
#include "etshal.h"
#include "esp_mphal.h"
#include "user_interface.h"
#include "extmod/misc.h"
uint32_t SPIRead(uint32_t offset, void *buf, uint32_t len);
uint32_t SPIWrite(uint32_t offset, const void *buf, uint32_t len);
uint32_t SPIEraseSector(int sector);
NORETURN void call_user_start(void);
void ets_printf(const char *fmt, ...);
extern char flashchip;
static const uint8_t default_init_data[] __attribute__((aligned(4))) = {
0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void firmware_start(void) {
// For SDK 1.5.2, either address has shifted and not mirrored in
// eagle.rom.addr.v6.ld, or extra initial member was added.
SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
char buf[128];
SPIRead(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
/*for (int i = 0; i < sizeof(buf); i++) {
static char hexf[] = "%x ";
ets_printf(hexf, buf[i]);
}*/
bool inited = false;
for (int i = 0; i < sizeof(buf); i++) {
if (buf[i] != 0xff) {
inited = true;
break;
}
}
if (!inited) {
static char msg[] = "Writing init data\n";
ets_printf(msg);
SPIRead((uint32_t)&default_init_data - 0x40200000, buf, sizeof(buf));
SPIWrite(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
}
asm("j call_user_start");
}
Loading…
Cancel
Save