Skip to content

Commit 5661ec0

Browse files
authored
Merge branch 'master' into wifi_mesh_update_2.2
2 parents fba4ac1 + c3796a4 commit 5661ec0

File tree

21 files changed

+1170
-134
lines changed

21 files changed

+1170
-134
lines changed

README.md

Lines changed: 2 additions & 0 deletions
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

Lines changed: 30 additions & 68 deletions
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/core_esp8266_spi_utils.cpp

Lines changed: 8 additions & 2 deletions
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/spiffs/README.md

Lines changed: 3 additions & 0 deletions
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

Lines changed: 18 additions & 5 deletions
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

Lines changed: 21 additions & 0 deletions
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_ */

cores/esp8266/spiffs/spiffs_nucleus.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,6 @@ s32_t spiffs_page_delete(
879879
spiffs *fs,
880880
spiffs_page_ix pix) {
881881
s32_t res;
882-
spiffs_page_header hdr;
883-
hdr.flags = 0xff & ~(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_USED);
884882
// mark deleted entry in source object lookup
885883
spiffs_obj_id d_obj_id = SPIFFS_OBJ_ID_DELETED;
886884
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_DELE,
@@ -893,12 +891,29 @@ s32_t spiffs_page_delete(
893891
fs->stats_p_deleted++;
894892
fs->stats_p_allocated--;
895893

894+
#if SPIFFS_SECURE_ERASE
895+
// Secure erase
896+
unsigned char data[SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(spiffs_page_header)];
897+
bzero(data, sizeof(data));
898+
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_DELE,
899+
0,
900+
SPIFFS_PAGE_TO_PADDR(fs, pix) + sizeof(spiffs_page_header), sizeof(data), data);
901+
SPIFFS_CHECK_RES(res);
902+
#endif
903+
896904
// mark deleted in source page
905+
u8_t flags = 0xff;
906+
#if SPIFFS_NO_BLIND_WRITES
907+
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_READ,
908+
0, SPIFFS_PAGE_TO_PADDR(fs, pix) + offsetof(spiffs_page_header, flags),
909+
sizeof(flags), &flags);
910+
SPIFFS_CHECK_RES(res);
911+
#endif
912+
flags &= ~(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_USED);
897913
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_DELE,
898914
0,
899915
SPIFFS_PAGE_TO_PADDR(fs, pix) + offsetof(spiffs_page_header, flags),
900-
sizeof(u8_t),
901-
(u8_t *)&hdr.flags);
916+
sizeof(flags), &flags);
902917

903918
return res;
904919
}
@@ -2027,7 +2042,7 @@ s32_t spiffs_object_read(
20272042
// remaining data in page
20282043
len_to_read = MIN(len_to_read, SPIFFS_DATA_PAGE_SIZE(fs) - (cur_offset % SPIFFS_DATA_PAGE_SIZE(fs)));
20292044
// remaining data in file
2030-
len_to_read = MIN(len_to_read, fd->size);
2045+
len_to_read = MIN(len_to_read, fd->size - cur_offset);
20312046
SPIFFS_DBG("read: offset:" _SPIPRIi " rd:" _SPIPRIi " data spix:" _SPIPRIsp " is data_pix:" _SPIPRIpg " addr:" _SPIPRIad "\n", cur_offset, len_to_read, data_spix, data_pix,
20322047
(u32_t)(SPIFFS_PAGE_TO_PADDR(fs, data_pix) + sizeof(spiffs_page_header) + (cur_offset % SPIFFS_DATA_PAGE_SIZE(fs))));
20332048
if (len_to_read <= 0) {

cores/esp8266/spiffs/spiffs_nucleus.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ extern "C" {
147147

148148

149149

150-
#if defined(__GNUC__) || defined(__clang__)
151-
/* For GCC and clang */
150+
#if defined(__GNUC__) || defined(__clang__) || defined(__TI_COMPILER_VERSION__)
151+
/* For GCC, clang and TI compilers */
152152
#define SPIFFS_PACKED __attribute__((packed))
153153
#elif defined(__ICCARM__) || defined(__CC_ARM)
154154
/* For IAR ARM and Keil MDK-ARM compilers */
@@ -266,8 +266,8 @@ extern "C" {
266266
#define SPIFFS_FH_OFFS(fs, fh) ((fh) != 0 ? ((fh) + (fs)->cfg.fh_ix_offset) : 0)
267267
#define SPIFFS_FH_UNOFFS(fs, fh) ((fh) != 0 ? ((fh) - (fs)->cfg.fh_ix_offset) : 0)
268268
#else
269-
#define SPIFFS_FH_OFFS(fs, fh) (fh)
270-
#define SPIFFS_FH_UNOFFS(fs, fh) (fh)
269+
#define SPIFFS_FH_OFFS(fs, fh) ((spiffs_file)(fh))
270+
#define SPIFFS_FH_UNOFFS(fs, fh) ((spiffs_file)(fh))
271271
#endif
272272

273273

cores/esp8266/time.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, c
175175
tzr->d = 0;
176176
tzr->s = 0;
177177
tzr->change = 0;
178-
tzr->offset = _timezone;
178+
tzr->offset = -_timezone;
179179
}
180180

181181
// sntp servers

cores/esp8266/umm_malloc/umm_local.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ void ICACHE_FLASH_ATTR print_stats(int force);
4848

4949

5050
int ICACHE_FLASH_ATTR umm_info_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
51-
#define UMM_INFO_PRINTF(fmt, ...) umm_info_safe_printf_P(PSTR(fmt), ##__VA_ARGS__)
51+
#define UMM_INFO_PRINTF(fmt, ...) umm_info_safe_printf_P(PSTR4(fmt), ##__VA_ARGS__)
52+
// use PSTR4() instead of PSTR() to ensure 4-bytes alignment in Flash, whatever the default alignment of PSTR_ALIGN
5253

5354

5455
#endif

0 commit comments

Comments
 (0)