SPIFFS: Fix PR review comments.

* Enable SPIFFS_USE_MAGIC
 * Enable SPIFFS_USE_MAGIC_LENGTH
 * Enable SPIFFS_FILEHDL_OFFSET
 * Rebuild mkspiffs if spiffs_config.h is changed
 * Emulate NOR flash in mkspiffs
 * Build spiffs image in 'flash' and 'test' targets
This commit is contained in:
sheinz 2016-07-22 14:09:50 +03:00
parent 0ec47b5de9
commit d69b8390d4
6 changed files with 44 additions and 39 deletions

View file

@ -94,6 +94,8 @@ int32_t esp_spiffs_mount()
config.hal_write_f = esp_spiffs_write;
config.hal_erase_f = esp_spiffs_erase;
config.fh_ix_offset = 3;
printf("SPIFFS size: %d\n", SPIFFS_SIZE);
printf("SPIFFS memory, work_buf_size=%d, fds_buf_size=%d, cache_buf_size=%d\n",
work_buf.size, fds_buf.size, cache_buf.size);
@ -109,15 +111,11 @@ int32_t esp_spiffs_mount()
return err;
}
#define FD_OFFSET 3
// This implementation replaces implementation in core/newlib_syscals.c
long _write_r(struct _reent *r, int fd, const char *ptr, int len )
{
if(fd != r->_stdout->_file) {
long ret = SPIFFS_write(&fs, (spiffs_file)(fd - FD_OFFSET),
(char*)ptr, len);
return ret;
return SPIFFS_write(&fs, (spiffs_file)fd, (char*)ptr, len);
}
for(int i = 0; i < len; i++) {
/* Auto convert CR to CRLF, ignore other LFs (compatible with Espressif SDK behaviour) */
@ -136,8 +134,7 @@ long _read_r( struct _reent *r, int fd, char *ptr, int len )
int ch, i;
if(fd != r->_stdin->_file) {
long ret = SPIFFS_read(&fs, (spiffs_file)(fd - FD_OFFSET), ptr, len);
return ret;
return SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
}
uart_rxfifo_wait(0, 1);
for(i = 0; i < len; i++) {
@ -157,17 +154,15 @@ int _open_r(struct _reent *r, const char *pathname, int flags, int mode)
if (flags & O_TRUNC) spiffs_flags |= SPIFFS_TRUNC;
if (flags & O_RDONLY) spiffs_flags |= SPIFFS_RDONLY;
if (flags & O_WRONLY) spiffs_flags |= SPIFFS_WRONLY;
if (flags & O_EXCL) spiffs_flags |= SPIFFS_EXCL;
/* if (flags & O_DIRECT) spiffs_flags |= SPIFFS_DIRECT; no support in newlib */
int ret = SPIFFS_open(&fs, pathname, spiffs_flags, mode);
if (ret > 0) {
return ret + FD_OFFSET;
}
return ret;
return SPIFFS_open(&fs, pathname, spiffs_flags, mode);
}
int _close_r(struct _reent *r, int fd)
{
return SPIFFS_close(&fs, (spiffs_file)(fd - FD_OFFSET));
return SPIFFS_close(&fs, (spiffs_file)fd);
}
int _unlink_r(struct _reent *r, const char *path)
@ -180,7 +175,7 @@ int _fstat_r(struct _reent *r, int fd, void *buf)
spiffs_stat s;
struct stat *sb = (struct stat*)buf;
int result = SPIFFS_fstat(&fs, (spiffs_file)(fd - FD_OFFSET), &s);
int result = SPIFFS_fstat(&fs, (spiffs_file)fd, &s);
sb->st_size = s.size;
return result;
@ -199,5 +194,5 @@ int _stat_r(struct _reent *r, const char *pathname, void *buf)
off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence)
{
return SPIFFS_lseek(&fs, (spiffs_file)(fd - FD_OFFSET), offset, whence);
return SPIFFS_lseek(&fs, (spiffs_file)fd, offset, whence);
}