Skip to content

Commit 818cb2c

Browse files
authored
Merge pull request #3 from esp8266/master
Update
2 parents 98e2fbc + cc1cc0b commit 818cb2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2435
-899
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ ESP8266 core files are licensed under LGPL.
135135
[SoftwareSerial repo](https://github.com/plerup/espsoftwareserial)
136136

137137
[Serial Monitor Arduino IDE plugin](https://github.com/mytrain/arduino-esp8266-serial-plugin) Original discussion [here](https://github.com/esp8266/Arduino/issues/1360), quick download [there](http://mytrain.fr/cms//images/mytrain/private/ESP8266SM.v3.zip).
138+
139+
[FTP Client/Server Library](https://github.com/dplasa/FTPClientServer)

bootloaders/eboot/eboot.c

+30-68
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <string.h>
1313
#include "flash.h"
1414
#include "eboot_command.h"
15-
#include "spi_vendors.h"
1615
#include <uzlib.h>
1716

1817
extern unsigned char _gzip_dict;
@@ -115,10 +114,12 @@ int uzlib_flash_read_cb(struct uzlib_uncomp *m)
115114
}
116115

117116
unsigned char gzip_dict[32768];
117+
uint8_t buffer2[FLASH_SECTOR_SIZE]; // no room for this on the stack
118118

119119
int copy_raw(const uint32_t src_addr,
120120
const uint32_t dst_addr,
121-
const uint32_t size)
121+
const uint32_t size,
122+
const bool verify)
122123
{
123124
// require regions to be aligned
124125
if ((src_addr & 0xfff) != 0 ||
@@ -158,8 +159,10 @@ int copy_raw(const uint32_t src_addr,
158159
gzip = true;
159160
}
160161
while (left > 0) {
161-
if (SPIEraseSector(daddr/buffer_size)) {
162-
return 2;
162+
if (!verify) {
163+
if (SPIEraseSector(daddr/buffer_size)) {
164+
return 2;
165+
}
163166
}
164167
if (!gzip) {
165168
if (SPIRead(saddr, buffer, buffer_size)) {
@@ -179,8 +182,17 @@ int copy_raw(const uint32_t src_addr,
179182
buffer[i] = 0xff;
180183
}
181184
}
182-
if (SPIWrite(daddr, buffer, buffer_size)) {
183-
return 4;
185+
if (verify) {
186+
if (SPIRead(daddr, buffer2, buffer_size)) {
187+
return 4;
188+
}
189+
if (memcmp(buffer, buffer2, buffer_size)) {
190+
return 9;
191+
}
192+
} else {
193+
if (SPIWrite(daddr, buffer, buffer_size)) {
194+
return 4;
195+
}
184196
}
185197
saddr += buffer_size;
186198
daddr += buffer_size;
@@ -190,29 +202,6 @@ int copy_raw(const uint32_t src_addr,
190202
return 0;
191203
}
192204

193-
//#define XMC_SUPPORT
194-
#ifdef XMC_SUPPORT
195-
// Define a few SPI0 registers we need access to
196-
#define ESP8266_REG(addr) *((volatile uint32_t *)(0x60000000+(addr)))
197-
#define SPI0CMD ESP8266_REG(0x200)
198-
#define SPI0CLK ESP8266_REG(0x218)
199-
#define SPI0C ESP8266_REG(0x208)
200-
#define SPI0W0 ESP8266_REG(0x240)
201-
202-
#define SPICMDRDID (1 << 28)
203-
204-
/* spi_flash_get_id()
205-
Returns the flash chip ID - same as the SDK function.
206-
We need our own version as the SDK isn't available here.
207-
*/
208-
uint32_t __attribute__((noinline)) spi_flash_get_id() {
209-
SPI0W0=0;
210-
SPI0CMD=SPICMDRDID;
211-
while (SPI0CMD) {}
212-
return SPI0W0;
213-
}
214-
#endif // XMC_SUPPORT
215-
216205
int main()
217206
{
218207
int res = 9;
@@ -235,47 +224,20 @@ int main()
235224
if (cmd.action == ACTION_COPY_RAW) {
236225
ets_putc('c'); ets_putc('p'); ets_putc(':');
237226

238-
#ifdef XMC_SUPPORT
239-
// save the flash access speed registers
240-
uint32_t spi0clk = SPI0CLK;
241-
uint32_t spi0c = SPI0C;
242-
243-
uint32_t vendor = spi_flash_get_id() & 0x000000ff;
244-
if (vendor == SPI_FLASH_VENDOR_XMC) {
245-
uint32_t flashinfo=0;
246-
if (SPIRead(0, &flashinfo, 4)) {
247-
// failed to read the configured flash speed.
248-
// Do not change anything,
249-
} else {
250-
// select an appropriate flash speed
251-
// Register values are those used by ROM
252-
switch ((flashinfo >> 24) & 0x0f) {
253-
case 0x0: // 40MHz, slow to 20
254-
case 0x1: // 26MHz, slow to 20
255-
SPI0CLK = 0x00003043;
256-
SPI0C = 0x00EAA313;
257-
break;
258-
case 0x2: // 20MHz, no change
259-
break;
260-
case 0xf: // 80MHz, slow to 26
261-
SPI0CLK = 0x00002002;
262-
SPI0C = 0x00EAA202;
263-
break;
264-
default:
265-
break;
266-
}
267-
}
268-
}
269-
#endif // XMC_SUPPORT
270227
ets_wdt_disable();
271-
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
228+
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2], false);
272229
ets_wdt_enable();
273-
274-
#ifdef XMC_SUPPORT
275-
// restore the saved flash access speed registers
276-
SPI0CLK = spi0clk;
277-
SPI0C = spi0c;
278-
#endif
230+
231+
ets_putc('0'+res); ets_putc('\n');
232+
233+
// Verify the copy
234+
ets_putc('c'); ets_putc('m'); ets_putc('p'); ets_putc(':');
235+
if (res == 0) {
236+
ets_wdt_disable();
237+
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2], true);
238+
ets_wdt_enable();
239+
}
240+
279241
ets_putc('0'+res); ets_putc('\n');
280242
if (res == 0) {
281243
cmd.action = ACTION_LOAD_APP;

bootloaders/eboot/eboot.elf

1020 Bytes
Binary file not shown.

cores/esp8266/CallBackList.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CallBackList
6464
}
6565

6666
template<typename... Args>
67-
void execute(Args... params) {
67+
int execute(Args... params) {
6868
for(auto it = std::begin(callBackEventList); it != std::end(callBackEventList); ) {
6969
CallBackHandler &handler = *it;
7070
if (handler->allowRemove() && handler.unique()) {
@@ -75,6 +75,7 @@ class CallBackList
7575
++it;
7676
}
7777
}
78+
return callBackEventList.size();
7879
}
7980
};
8081

cores/esp8266/Esp-frag.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,28 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
2929
// Having getFreeHeap()=sum(hole-size), fragmentation is given by
3030
// 100 * (1 - sqrt(sum(hole-size²)) / sum(hole-size))
3131

32-
umm_info(NULL, 0);
32+
umm_info(NULL, false);
3333
uint8_t block_size = umm_block_size();
34-
uint32_t fh = ummHeapInfo.freeBlocks * block_size;
3534
if (hfree)
36-
*hfree = fh;
35+
*hfree = ummHeapInfo.freeBlocks * block_size;
3736
if (hmax)
38-
*hmax = ummHeapInfo.maxFreeContiguousBlocks * block_size;
39-
if (hfrag)
40-
*hfrag = 100 - (sqrt32(ummHeapInfo.freeSize2) * 100) / fh;
37+
*hmax = (uint16_t)ummHeapInfo.maxFreeContiguousBlocks * block_size;
38+
if (hfrag) {
39+
if (ummHeapInfo.freeBlocks) {
40+
*hfrag = 100 - (sqrt32(ummHeapInfo.freeBlocksSquared) * 100) / ummHeapInfo.freeBlocks;
41+
} else {
42+
*hfrag = 0;
43+
}
44+
}
4145
}
4246

4347
uint8_t EspClass::getHeapFragmentation()
4448
{
49+
#ifdef UMM_INLINE_METRICS
50+
return (uint8_t)umm_fragmentation_metric();
51+
#else
4552
uint8_t hfrag;
4653
getHeapStats(nullptr, nullptr, &hfrag);
4754
return hfrag;
55+
#endif
4856
}

cores/esp8266/core_esp8266_postmortem.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ static void ets_printf_P(const char *str, ...) {
9292
}
9393
}
9494

95+
static void cut_here() {
96+
ets_putc('\n');
97+
for (auto i = 0; i < 15; i++ ) {
98+
ets_putc('-');
99+
}
100+
ets_printf_P(PSTR(" CUT HERE FOR EXCEPTION DECODER "));
101+
for (auto i = 0; i < 15; i++ ) {
102+
ets_putc('-');
103+
}
104+
ets_putc('\n');
105+
}
106+
95107
void __wrap_system_restart_local() {
96108
register uint32_t sp asm("a1");
97109
uint32_t sp_dump = sp;
@@ -113,6 +125,8 @@ void __wrap_system_restart_local() {
113125

114126
ets_install_putc1(&uart_write_char_d);
115127

128+
cut_here();
129+
116130
if (s_panic_line) {
117131
ets_printf_P(PSTR("\nPanic %S:%d %S"), s_panic_file, s_panic_line, s_panic_func);
118132
if (s_panic_what) {
@@ -193,6 +207,8 @@ void __wrap_system_restart_local() {
193207
#endif
194208
}
195209

210+
cut_here();
211+
196212
custom_crash_callback( &rst_info, sp_dump + offset, stack_end );
197213

198214
ets_delay_us(10000);

cores/esp8266/core_esp8266_spi_utils.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static SpiOpResult PRECACHE_ATTR
5252
_SPICommand(volatile uint32_t spiIfNum,
5353
uint32_t spic,uint32_t spiu,uint32_t spiu1,uint32_t spiu2,
5454
uint32_t *data,uint32_t writeWords,uint32_t readWords)
55-
{
55+
{
5656
if (spiIfNum>1)
5757
return SPI_RESULT_ERR;
5858

@@ -69,8 +69,11 @@ _SPICommand(volatile uint32_t spiIfNum,
6969
volatile SpiFlashChip *fchip=flashchip;
7070
volatile uint32_t spicmdusr=SPICMDUSR;
7171

72+
uint32_t saved_ps=0;
73+
7274
if (!spiIfNum) {
73-
// Only need to precache when using SPI0
75+
// Only need to disable interrupts and precache when using SPI0
76+
saved_ps = xt_rsil(15);
7477
PRECACHE_START();
7578
Wait_SPI_Idlep((SpiFlashChip *)fchip);
7679
}
@@ -116,6 +119,9 @@ _SPICommand(volatile uint32_t spiIfNum,
116119
SPIREG(SPI0C) = oldSPI0C;
117120

118121
PRECACHE_END();
122+
if (!spiIfNum) {
123+
xt_wsr_ps(saved_ps);
124+
}
119125
return (timeout>0 ? SPI_RESULT_OK : SPI_RESULT_TIMEOUT);
120126
}
121127

cores/esp8266/heap.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
#undef realloc
2121
#undef free
2222

23-
#elif defined(DEBUG_ESP_OOM)
23+
#elif defined(DEBUG_ESP_OOM) || defined(UMM_INTEGRITY_CHECK)
2424
#define UMM_MALLOC(s) umm_malloc(s)
2525
#define UMM_CALLOC(n,s) umm_calloc(n,s)
2626
#define UMM_REALLOC_FL(p,s,f,l) umm_realloc(p,s)
@@ -314,7 +314,7 @@ size_t ICACHE_RAM_ATTR xPortWantedSizeAlign(size_t size)
314314

315315
void system_show_malloc(void)
316316
{
317-
umm_info(NULL, 1);
317+
umm_info(NULL, true);
318318
}
319319

320320
};

cores/esp8266/spiffs/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ What spiffs does not:
4949
- Presently, it does not detect or handle bad blocks.
5050
- One configuration, one binary. There's no generic spiffs binary that handles all types of configurations.
5151

52+
## NOTICE
53+
54+
0.4.0 is under construction. This is a full rewrite and will change the underlying structure. Hence, it will not be compatible with earlier versions of the filesystem. The API is the same, with minor modifications. Some config flags will be removed (as they are mandatory in 0.4.0) and some features might fall away until 0.4.1. If you have any worries or questions, it can be discussed in issue [#179](https://github.com/pellepl/spiffs/issues/179)
5255

5356
## MORE INFO
5457

cores/esp8266/spiffs/spiffs_check.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,17 @@ static s32_t spiffs_delete_obj_lazy(spiffs *fs, spiffs_obj_id obj_id) {
163163
return SPIFFS_OK;
164164
}
165165
SPIFFS_CHECK_RES(res);
166-
u8_t flags = 0xff & ~SPIFFS_PH_FLAG_IXDELE;
166+
u8_t flags = 0xff;
167+
#if SPIFFS_NO_BLIND_WRITES
168+
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
169+
0, SPIFFS_PAGE_TO_PADDR(fs, objix_hdr_pix) + offsetof(spiffs_page_header, flags),
170+
sizeof(flags), &flags);
171+
SPIFFS_CHECK_RES(res);
172+
#endif
173+
flags &= ~SPIFFS_PH_FLAG_IXDELE;
167174
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_UPDT,
168175
0, SPIFFS_PAGE_TO_PADDR(fs, objix_hdr_pix) + offsetof(spiffs_page_header, flags),
169-
sizeof(u8_t),
170-
(u8_t *)&flags);
176+
sizeof(flags), &flags);
171177
return res;
172178
}
173179

@@ -425,10 +431,17 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
425431
// just finalize
426432
SPIFFS_CHECK_DBG("LU: FIXUP: unfinalized page is referred, finalizing\n");
427433
CHECK_CB(fs, SPIFFS_CHECK_LOOKUP, SPIFFS_CHECK_FIX_LOOKUP, p_hdr->obj_id, p_hdr->span_ix);
428-
u8_t flags = 0xff & ~SPIFFS_PH_FLAG_FINAL;
434+
u8_t flags = 0xff;
435+
#if SPIFFS_NO_BLIND_WRITES
436+
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_READ,
437+
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix) + offsetof(spiffs_page_header, flags),
438+
sizeof(flags), &flags);
439+
SPIFFS_CHECK_RES(res);
440+
#endif
441+
flags &= ~SPIFFS_PH_FLAG_FINAL;
429442
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT,
430443
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix) + offsetof(spiffs_page_header, flags),
431-
sizeof(u8_t), (u8_t*)&flags);
444+
sizeof(flags), &flags);
432445
}
433446
}
434447
}

cores/esp8266/spiffs/spiffs_config.h

+21
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ typedef uint8_t u8_t;
326326
#define SPIFFS_IX_MAP 1
327327
#endif
328328

329+
// By default SPIFFS in some cases relies on the property of NOR flash that bits
330+
// cannot be set from 0 to 1 by writing and that controllers will ignore such
331+
// bit changes. This results in fewer reads as SPIFFS can in some cases perform
332+
// blind writes, with all bits set to 1 and only those it needs reset set to 0.
333+
// Most of the chips and controllers allow this behavior, so the default is to
334+
// use this technique. If your controller is one of the rare ones that don't,
335+
// turn this option on and SPIFFS will perform a read-modify-write instead.
336+
#ifndef SPIFFS_NO_BLIND_WRITES
337+
#define SPIFFS_NO_BLIND_WRITES 0
338+
#endif
339+
329340
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
330341
// in the api. This function will visualize all filesystem using given printf
331342
// function.
@@ -354,11 +365,20 @@ typedef uint8_t u8_t;
354365
#endif
355366
#endif
356367

368+
#ifndef SPIFFS_SECURE_ERASE
369+
#define SPIFFS_SECURE_ERASE 0
370+
#endif
371+
357372
// Types depending on configuration such as the amount of flash bytes
358373
// given to spiffs file system in total (spiffs_file_system_size),
359374
// the logical block size (log_block_size), and the logical page size
360375
// (log_page_size)
376+
//
377+
// Set SPIFFS_TYPES_OVERRIDE if you wish to have your own
378+
// definitions for these types (for example, if you want them
379+
// to be u32_t)
361380

381+
#ifndef SPIFFS_TYPES_OVERRIDE
362382
// Block index type. Make sure the size of this type can hold
363383
// the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
364384
typedef u16_t spiffs_block_ix;
@@ -373,5 +393,6 @@ typedef u16_t spiffs_obj_id;
373393
// hold the largest possible span index on the system -
374394
// i.e. (spiffs_file_system_size / log_page_size) - 1
375395
typedef u16_t spiffs_span_ix;
396+
#endif
376397

377398
#endif /* SPIFFS_CONFIG_H_ */

0 commit comments

Comments
 (0)