Skip to content

Commit 45a1860

Browse files
committed
Merge pull request #9 from esp8266/esp8266
pull master
2 parents 4c07879 + 2f474f0 commit 45a1860

23 files changed

+526
-239
lines changed

boards.txt

+14-9
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,18 @@ generic.menu.UploadSpeed.512000.upload.speed=512000
6565
generic.menu.UploadSpeed.921600=921600
6666
generic.menu.UploadSpeed.921600.upload.speed=921600
6767

68-
generic.menu.FlashSize.512K=512K (64K SPIFFS)
69-
generic.menu.FlashSize.512K.build.flash_size=512K
70-
generic.menu.FlashSize.512K.build.flash_ld=eagle.flash.512k.ld
71-
generic.menu.FlashSize.512K.build.spiffs_start=0x6B000
72-
generic.menu.FlashSize.512K.build.spiffs_end=0x7B000
73-
generic.menu.FlashSize.512K.build.spiffs_blocksize=4096
74-
generic.menu.FlashSize.512K.upload.maximum_size=434160
68+
generic.menu.FlashSize.512K64=512K (64K SPIFFS)
69+
generic.menu.FlashSize.512K64.build.flash_size=512K
70+
generic.menu.FlashSize.512K64.build.flash_ld=eagle.flash.512k64.ld
71+
generic.menu.FlashSize.512K64.build.spiffs_start=0x6B000
72+
generic.menu.FlashSize.512K64.build.spiffs_end=0x7B000
73+
generic.menu.FlashSize.512K64.build.spiffs_blocksize=4096
74+
generic.menu.FlashSize.512K64.upload.maximum_size=434160
75+
76+
generic.menu.FlashSize.512K0=512K (no SPIFFS)
77+
generic.menu.FlashSize.512K0.build.flash_size=512K
78+
generic.menu.FlashSize.512K0.build.flash_ld=eagle.flash.512k0.ld
79+
generic.menu.FlashSize.512K0.upload.maximum_size=499696
7580

7681
generic.menu.FlashSize.1M512=1M (512K SPIFFS)
7782
generic.menu.FlashSize.1M512.build.flash_size=1M
@@ -410,7 +415,7 @@ thing.build.variant=thing
410415
thing.build.flash_mode=qio
411416
# flash chip: AT25SF041 (512 kbyte, 4Mbit)
412417
thing.build.flash_size=512K
413-
thing.build.flash_ld=eagle.flash.512k.ld
418+
thing.build.flash_ld=eagle.flash.512k64.ld
414419
thing.build.flash_freq=40
415420
thing.build.spiffs_start=0x6B000
416421
thing.build.spiffs_end=0x7B000
@@ -526,7 +531,7 @@ esp210.menu.FlashSize.4M1M.build.spiffs_pagesize=256
526531
# wifio.build.flash_mode=qio
527532
# wifio.build.flash_size=512K
528533
# wifio.build.flash_freq=40
529-
# wifio.build.flash_ld=eagle.flash.512k.ld
534+
# wifio.build.flash_ld=eagle.flash.512k64.ld
530535
# wifio.build.spiffs_start=0x6B000
531536
# wifio.build.spiffs_end=0x7B000
532537
#

cores/esp8266/FS.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ bool FS::format() {
174174
return _impl->format();
175175
}
176176

177+
bool FS::info(uint32_t *total, uint32_t *used){
178+
if (!_impl) {
179+
return false;
180+
}
181+
return _impl->info(total,used);
182+
}
183+
177184
File FS::open(const String& path, const char* mode) {
178185
return open(path.c_str(), mode);
179186
}

cores/esp8266/FS.h

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class FS
9393
bool begin();
9494

9595
bool format();
96+
bool info(uint32_t *total, uint32_t *used);
9697

9798
File open(const char* path, const char* mode);
9899
File open(const String& path, const char* mode);

cores/esp8266/FSImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class FSImpl {
6464
public:
6565
virtual bool begin() = 0;
6666
virtual bool format() = 0;
67+
virtual bool info(uint32_t *total, uint32_t *used) = 0;
6768
virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;
6869
virtual bool exists(const char* path) = 0;
6970
virtual DirImplPtr openDir(const char* path) = 0;

cores/esp8266/spiffs/spiffs.h

+28-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Author: petera
66
*/
77

8-
9-
108
#ifndef SPIFFS_H_
119
#define SPIFFS_H_
1210
#if defined(__cplusplus)
@@ -186,6 +184,11 @@ typedef struct {
186184
// logical size of a page, must be at least
187185
// log_block_size / 8
188186
u32_t log_page_size;
187+
188+
#endif
189+
#if SPIFFS_FILEHDL_OFFSET
190+
// an integer offset added to each file handle
191+
u16_t fh_ix_offset;
189192
#endif
190193
} spiffs_config;
191194

@@ -310,7 +313,7 @@ void SPIFFS_unmount(spiffs *fs);
310313
* @param path the path of the new file
311314
* @param mode ignored, for posix compliance
312315
*/
313-
s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode);
316+
s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode);
314317

315318
/**
316319
* Opens/creates a file.
@@ -321,7 +324,7 @@ s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode);
321324
* SPIFFS_WR_ONLY, SPIFFS_RDWR, SPIFFS_DIRECT
322325
* @param mode ignored, for posix compliance
323326
*/
324-
spiffs_file SPIFFS_open(spiffs *fs, char *path, spiffs_flags flags, spiffs_mode mode);
327+
spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode);
325328

326329

327330
/**
@@ -360,13 +363,14 @@ s32_t SPIFFS_read(spiffs *fs, spiffs_file fh, void *buf, s32_t len);
360363
s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len);
361364

362365
/**
363-
* Moves the read/write file offset
366+
* Moves the read/write file offset. Resulting offset is returned or negative if error.
367+
* lseek(fs, fd, 0, SPIFFS_SEEK_CUR) will thus return current offset.
364368
* @param fs the file system struct
365369
* @param fh the filehandle
366370
* @param offs how much/where to move the offset
367371
* @param whence if SPIFFS_SEEK_SET, the file offset shall be set to offset bytes
368372
* if SPIFFS_SEEK_CUR, the file offset shall be set to its current location plus offset
369-
* if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offset
373+
* if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offse, which should be negative
370374
*/
371375
s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence);
372376

@@ -375,7 +379,7 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence);
375379
* @param fs the file system struct
376380
* @param path the path of the file to remove
377381
*/
378-
s32_t SPIFFS_remove(spiffs *fs, char *path);
382+
s32_t SPIFFS_remove(spiffs *fs, const char *path);
379383

380384
/**
381385
* Removes a file by filehandle
@@ -390,7 +394,7 @@ s32_t SPIFFS_fremove(spiffs *fs, spiffs_file fh);
390394
* @param path the path of the file to stat
391395
* @param s the stat struct to populate
392396
*/
393-
s32_t SPIFFS_stat(spiffs *fs, char *path, spiffs_stat *s);
397+
s32_t SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s);
394398

395399
/**
396400
* Gets file status by filehandle
@@ -420,7 +424,7 @@ s32_t SPIFFS_close(spiffs *fs, spiffs_file fh);
420424
* @param old path of file to rename
421425
* @param newPath new path of file
422426
*/
423-
s32_t SPIFFS_rename(spiffs *fs, char *old, char *newPath);
427+
s32_t SPIFFS_rename(spiffs *fs, const char *old, const char *newPath);
424428

425429
/**
426430
* Returns last error of last file operation.
@@ -443,7 +447,7 @@ void SPIFFS_clearerr(spiffs *fs);
443447
* @param name the name of the directory
444448
* @param d pointer the directory stream to be populated
445449
*/
446-
spiffs_DIR *SPIFFS_opendir(spiffs *fs, char *name, spiffs_DIR *d);
450+
spiffs_DIR *SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d);
447451

448452
/**
449453
* Closes a directory stream
@@ -544,6 +548,20 @@ s32_t SPIFFS_gc_quick(spiffs *fs, u16_t max_free_pages);
544548
*/
545549
s32_t SPIFFS_gc(spiffs *fs, u32_t size);
546550

551+
/**
552+
* Check if EOF reached.
553+
* @param fs the file system struct
554+
* @param fh the filehandle of the file to check
555+
*/
556+
s32_t SPIFFS_eof(spiffs *fs, spiffs_file fh);
557+
558+
/**
559+
* Get position in file.
560+
* @param fs the file system struct
561+
* @param fh the filehandle of the file to check
562+
*/
563+
s32_t SPIFFS_tell(spiffs *fs, spiffs_file fh);
564+
547565
#if SPIFFS_TEST_VISUALISATION
548566
/**
549567
* Prints out a visualization of the filesystem.

cores/esp8266/spiffs/spiffs_check.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
440440
}
441441

442442
static s32_t spiffs_lookup_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block, int cur_entry,
443-
u32_t user_data, void *user_p) {
444-
(void)user_data;
445-
(void)user_p;
443+
const void *user_const_p, void *user_var_p) {
444+
(void)user_const_p;
445+
(void)user_var_p;
446446
s32_t res = SPIFFS_OK;
447447
spiffs_page_header p_hdr;
448448
spiffs_page_ix cur_pix = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, cur_block, cur_entry);
@@ -873,11 +873,11 @@ static int spiffs_object_index_search(spiffs *fs, spiffs_obj_id obj_id) {
873873
}
874874

875875
static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block,
876-
int cur_entry, u32_t user_data, void *user_p) {
877-
(void)user_data;
876+
int cur_entry, const void *user_const_p, void *user_var_p) {
877+
(void)user_const_p;
878878
s32_t res_c = SPIFFS_VIS_COUNTINUE;
879879
s32_t res = SPIFFS_OK;
880-
u32_t *log_ix = (u32_t *)user_p;
880+
u32_t *log_ix = (u32_t*)user_var_p;
881881
spiffs_obj_id *obj_table = (spiffs_obj_id *)fs->work;
882882

883883
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS,
@@ -977,8 +977,8 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) {
977977
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
978978
u32_t obj_id_log_ix = 0;
979979
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS, 0, 0);
980-
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, 0, &obj_id_log_ix,
981-
0, 0);
980+
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, &obj_id_log_ix,
981+
0, 0, 0);
982982
if (res == SPIFFS_VIS_END) {
983983
res = SPIFFS_OK;
984984
}

cores/esp8266/spiffs/spiffs_config.h

+24-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define c_printf ets_printf
2020
#define c_memset memset
2121

22-
typedef signed short file_t;
22+
typedef int16_t file_t;
2323
typedef int32_t s32_t;
2424
typedef uint32_t u32_t;
2525
typedef int16_t s16_t;
@@ -46,20 +46,20 @@ typedef uint8_t u8_t;
4646
// compile time switches
4747

4848
// Set generic spiffs debug output call.
49-
#ifndef SPIFFS_DGB
50-
#define SPIFFS_DBG(...) //c_printf(__VA_ARGS__)
49+
#ifndef SPIFFS_DBG
50+
#define SPIFFS_DBG(...) //printf(__VA_ARGS__)
5151
#endif
5252
// Set spiffs debug output call for garbage collecting.
53-
#ifndef SPIFFS_GC_DGB
54-
#define SPIFFS_GC_DBG(...) //c_printf(__VA_ARGS__)
53+
#ifndef SPIFFS_GC_DBG
54+
#define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
5555
#endif
5656
// Set spiffs debug output call for caching.
57-
#ifndef SPIFFS_CACHE_DGB
58-
#define SPIFFS_CACHE_DBG(...) //c_printf(__VA_ARGS__)
57+
#ifndef SPIFFS_CACHE_DBG
58+
#define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
5959
#endif
6060
// Set spiffs debug output call for system consistency checks.
61-
#ifndef SPIFFS_CHECK_DGB
62-
#define SPIFFS_CHECK_DBG(...) //c_printf(__VA_ARGS__)
61+
#ifndef SPIFFS_CHECK_DBG
62+
#define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
6363
#endif
6464

6565
// Enable/disable API functions to determine exact number of bytes
@@ -189,6 +189,21 @@ typedef uint8_t u8_t;
189189
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
190190
#endif
191191

192+
// Enable this if you want the HAL callbacks to be called with the spiffs struct
193+
#ifndef SPIFFS_HAL_CALLBACK_EXTRA
194+
#define SPIFFS_HAL_CALLBACK_EXTRA 0
195+
#endif
196+
197+
// Enable this if you want to add an integer offset to all file handles
198+
// (spiffs_file). This is useful if running multiple instances of spiffs on
199+
// same target, in order to recognise to what spiffs instance a file handle
200+
// belongs.
201+
// NB: This adds config field fh_ix_offset in the configuration struct when
202+
// mounting, which must be defined.
203+
#ifndef SPIFFS_FILEHDL_OFFSET
204+
#define SPIFFS_FILEHDL_OFFSET 0
205+
#endif
206+
192207
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
193208
// in the api. This function will visualize all filesystem using given printf
194209
// function.

cores/esp8266/spiffs/spiffs_gc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ s32_t spiffs_gc_quick(
3636
int cur_entry = 0;
3737
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
3838

39-
SPIFFS_GC_DBG("gc_quick: running\n", cur_block);
39+
SPIFFS_GC_DBG("gc_quick: running\n");
4040
#if SPIFFS_GC_STATS
4141
fs->stats_gc_runs++;
4242
#endif
@@ -255,7 +255,7 @@ s32_t spiffs_gc_find_candidate(
255255
// align cand_scores on s32_t boundary
256256
#pragma GCC diagnostic push
257257
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
258-
cand_scores = (s32_t*)(((u32_t)cand_scores + sizeof(s32_t) - 1) & ~(sizeof(s32_t) - 1));
258+
cand_scores = (s32_t*)(((ptrdiff_t)cand_scores + sizeof(ptrdiff_t) - 1) & ~(sizeof(ptrdiff_t) - 1));
259259
#pragma GCC diagnostic pop
260260

261261
*block_candidates = cand_blocks;

0 commit comments

Comments
 (0)