8000 esp8266/esp_init_data: Auto-initialize system params with vendor SDK … · ladyada/circuitpython@20d0271 · GitHub
[go: up one dir, main page]

Skip to content

Commit 20d0271

Browse files
committed
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.
1 parent 542f05d commit 20d0271

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

esp8266/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ SRC_C = \
6565
main.c \
6666
help.c \
6767
esp_mphal.c \
68+
esp_init_data.c \
6869
gccollect.c \
6970
lexerstr32.c \
7071
uart.c \

esp8266/esp8266.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PHDRS
2020
irom0_0_phdr PT_LOAD;
2121
}
2222

23-
ENTRY(call_user_start)
23+
ENTRY(firmware_start)
2424
EXTERN(_DebugExceptionVector)
2525
EXTERN(_DoubleExceptionVector)
2626
EXTERN(_KernelExceptionVector)

esp8266/esp_init_data.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Paul Sokolovsky
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stdio.h>
28+
#include "ets_sys.h"
29+
#include "etshal.h"
30+
#include "esp_mphal.h"
31+
#include "user_interface.h"
32+
#include "extmod/misc.h"
33+
34+
uint32_t SPIRead(uint32_t offset, void *buf, uint32_t len);
35+
uint32_t SPIWrite(uint32_t offset, const void *buf, uint32_t len);
36+
uint32_t SPIEraseSector(int sector);
37+
NORETURN void call_user_start(void);
38+
void ets_printf(const char *fmt, ...);
39+
extern char flashchip;
40+
41+
static const uint8_t default_init_data[] __attribute__((aligned(4))) = {
42+
0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
43+
0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
44+
0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
45+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46+
0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
47+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49+
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
50+
};
51+
52+
void firmware_start(void) {
53+
// For SDK 1.5.2, either address has shifted and not mirrored in
54+
// eagle.rom.addr.v6.ld, or extra initial member was added.
55+
SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
56+
57+
char buf[128];
58+
SPIRead(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
59+
/*for (int i = 0; i < sizeof(buf); i++) {
60+
static char hexf[] = "%x ";
61+
ets_printf(hexf, buf[i]);
62+
}*/
63+
64+
bool inited = false;
65+
for (int i = 0; i < sizeof(buf); i++) {
66+
if (buf[i] != 0xff) {
67+
inited = true;
68+
break;
69+
}
70+
}
71+
72+
if (!inited) {
73+
static char msg[] = "Writing init data\n";
74+
ets_printf(msg);
75+
SPIRead((uint32_t)&default_init_data - 0x40200000, buf, sizeof(buf));
76+
SPIWrite(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
77+
}
78+
79+
asm("j call_user_start");
80+
}

0 commit comments

Comments
 (0)
0