Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
5261fb19
Commit
5261fb19
authored
May 21, 2015
by
HuangRui
Browse files
Update spiffs to latest.
parent
c66cced7
Changes
9
Hide whitespace changes
Inline
Side-by-side
app/Makefile
View file @
5261fb19
...
@@ -53,11 +53,11 @@ TARGET_LDFLAGS = \
...
@@ -53,11 +53,11 @@ TARGET_LDFLAGS = \
--text-section-literals
--text-section-literals
ifeq
($(FLAVOR),debug)
ifeq
($(FLAVOR),debug)
TARGET_LDFLAGS
+=
-g
-O
2
TARGET_LDFLAGS
+=
-g
-O
s
endif
endif
ifeq
($(FLAVOR),release)
ifeq
($(FLAVOR),release)
TARGET_LDFLAGS
+=
-
g
-O0
TARGET_LDFLAGS
+=
-
Os
endif
endif
LD_FILE
=
$(LDDIR)
/eagle.app.v6.ld
LD_FILE
=
$(LDDIR)
/eagle.app.v6.ld
...
...
app/platform/flash_api.c
View file @
5261fb19
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
* 2014-12-31
* 2014-12-31
*******************************************************************************/
*******************************************************************************/
#include "user_config.h"
#include "user_config.h"
#include "osapi.h"
#include "flash_api.h"
#include "flash_api.h"
#include "spi_flash.h"
#include "c_stdio.h"
#include "c_stdio.h"
static
volatile
const
uint8_t
flash_init_data
[
128
]
ICACHE_STORE_ATTR
ICACHE_RODATA_ATTR
=
static
volatile
const
uint8_t
flash_init_data
[
128
]
ICACHE_STORE_ATTR
ICACHE_RODATA_ATTR
=
...
@@ -103,43 +103,40 @@ uint8_t flash_rom_get_size_type(void)
...
@@ -103,43 +103,40 @@ uint8_t flash_rom_get_size_type(void)
uint32_t
flash_rom_get_size_byte
(
void
)
uint32_t
flash_rom_get_size_byte
(
void
)
{
{
static
uint32_t
flash_size
=
0
;
static
uint32_t
flash_size
=
0
;
if
(
flash_
size
==
0
)
switch
(
flash_
rom_getinfo
().
size
)
{
{
switch
(
flash_rom_getinfo
().
size
)
case
SIZE_2MBIT
:
{
// 2Mbit, 256kByte
case
SIZE_2MBIT
:
flash_size
=
256
*
1024
;
// 2Mbit, 256kByte
break
;
flash_size
=
256
*
1024
;
case
SIZE_4MBIT
:
break
;
// 4Mbit, 512kByte
case
SIZE_4MBIT
:
flash_size
=
512
*
1024
;
// 4Mbit, 512kByte
break
;
flash_size
=
512
*
1024
;
case
SIZE_8MBIT
:
break
;
// 8Mbit, 1MByte
case
SIZE_8MBIT
:
flash_size
=
1
*
1024
*
1024
;
// 8Mbit, 1MByte
break
;
flash_size
=
1
*
1024
*
1024
;
case
SIZE_16MBIT
:
break
;
// 16Mbit, 2MByte
case
SIZE_16MBIT
:
flash_size
=
2
*
1024
*
1024
;
// 16Mbit, 2MByte
break
;
flash_size
=
2
*
1024
*
1024
;
case
SIZE_32MBIT
:
break
;
// 32Mbit, 4MByte
case
SIZE_32MBIT
:
flash_size
=
4
*
1024
*
1024
;
// 32Mbit, 4MByte
break
;
flash_size
=
4
*
1024
*
1024
;
case
SIZE_64MBIT
:
break
;
// 64Mbit, 8MByte
case
SIZE_64MBIT
:
flash_size
=
8
*
1024
*
1024
;
// 64Mbit, 8MByte
break
;
flash_size
=
8
*
1024
*
1024
;
case
SIZE_128MBIT
:
break
;
// 128Mbit, 16MByte
case
SIZE_128MBIT
:
flash_size
=
16
*
1024
*
1024
;
// 128Mbit, 16MByte
break
;
flash_size
=
16
*
1024
*
1024
;
default:
break
;
// Unknown flash size, fall back mode.
default:
flash_size
=
512
*
1024
;
// Unknown flash size, fall back mode.
break
;
flash_size
=
512
*
1024
;
break
;
}
}
}
return
flash_size
;
return
flash_size
;
}
}
...
@@ -149,21 +146,21 @@ bool flash_rom_set_size_type(uint8_t size)
...
@@ -149,21 +146,21 @@ bool flash_rom_set_size_type(uint8_t size)
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DB
G
(
"
\n
BEGIN SET FLASH HEADER
\n
"
);
FLASH_DEBU
G
(
"
\n
BEGIN SET FLASH HEADER
\n
"
);
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_read
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_read
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
{
{
((
SPIFlashInfo
*
)(
&
data
[
0
]))
->
size
=
size
;
((
SPIFlashInfo
*
)(
&
data
[
0
]))
->
size
=
size
;
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
(
0
*
SPI_FLASH_SEC_SIZE
))
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
(
0
*
SPI_FLASH_SEC_SIZE
))
{
{
NODE_DB
G
(
"
\n
ERASE SUCCESS
\n
"
);
FLASH_DEBU
G
(
"
\n
ERASE SUCCESS
\n
"
);
}
}
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
{
{
NODE_DB
G
(
"
\n
WRITE SUCCESS, %u
\n
"
,
size
);
FLASH_DEBU
G
(
"
\n
WRITE SUCCESS, %u
\n
"
,
size
);
}
}
}
}
NODE_DB
G
(
"
\n
END SET FLASH HEADER
\n
"
);
FLASH_DEBU
G
(
"
\n
END SET FLASH HEADER
\n
"
);
return
true
;
return
true
;
}
}
...
@@ -281,7 +278,7 @@ bool flash_rom_set_speed(uint32_t speed)
...
@@ -281,7 +278,7 @@ bool flash_rom_set_speed(uint32_t speed)
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DB
G
(
"
\n
BEGIN SET FLASH HEADER
\n
"
);
FLASH_DEBU
G
(
"
\n
BEGIN SET FLASH HEADER
\n
"
);
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
uint8_t
speed_type
=
SPEED_40MHZ
;
uint8_t
speed_type
=
SPEED_40MHZ
;
if
(
speed
<
26700000
)
if
(
speed
<
26700000
)
...
@@ -305,14 +302,14 @@ bool flash_rom_set_speed(uint32_t speed)
...
@@ -305,14 +302,14 @@ bool flash_rom_set_speed(uint32_t speed)
((
SPIFlashInfo
*
)(
&
data
[
0
]))
->
speed
=
speed_type
;
((
SPIFlashInfo
*
)(
&
data
[
0
]))
->
speed
=
speed_type
;
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
(
0
*
SPI_FLASH_SEC_SIZE
))
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
(
0
*
SPI_FLASH_SEC_SIZE
))
{
{
NODE_DB
G
(
"
\n
ERASE SUCCESS
\n
"
);
FLASH_DEBU
G
(
"
\n
ERASE SUCCESS
\n
"
);
}
}
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
{
{
NODE_DB
G
(
"
\n
WRITE SUCCESS, %u
\n
"
,
speed_type
);
FLASH_DEBU
G
(
"
\n
WRITE SUCCESS, %u
\n
"
,
speed_type
);
}
}
}
}
NODE_DB
G
(
"
\n
END SET FLASH HEADER
\n
"
);
FLASH_DEBU
G
(
"
\n
END SET FLASH HEADER
\n
"
);
return
true
;
return
true
;
}
}
...
@@ -393,7 +390,7 @@ uint8_t byte_of_aligned_array(const uint8_t *aligned_array, uint32_t index)
...
@@ -393,7 +390,7 @@ uint8_t byte_of_aligned_array(const uint8_t *aligned_array, uint32_t index)
{
{
if
(
(((
uint32_t
)
aligned_array
)
%
4
)
!=
0
)
if
(
(((
uint32_t
)
aligned_array
)
%
4
)
!=
0
)
{
{
NODE_DB
G
(
"aligned_array is not 4-byte aligned.
\n
"
);
FLASH_DEBU
G
(
"aligned_array is not 4-byte aligned.
\n
"
);
return
0
;
return
0
;
}
}
volatile
uint32_t
v
=
((
uint32_t
*
)
aligned_array
)[
index
/
4
];
volatile
uint32_t
v
=
((
uint32_t
*
)
aligned_array
)[
index
/
4
];
...
@@ -405,7 +402,7 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index)
...
@@ -405,7 +402,7 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index)
{
{
if
(
(((
uint32_t
)
aligned_array
)
%
4
)
!=
0
)
if
(
(((
uint32_t
)
aligned_array
)
%
4
)
!=
0
)
{
{
NODE_DB
G
(
"aligned_array is not 4-byte aligned.
\n
"
);
FLASH_DEBU
G
(
"aligned_array is not 4-byte aligned.
\n
"
);
return
0
;
return
0
;
}
}
volatile
uint32_t
v
=
((
uint32_t
*
)
aligned_array
)[
index
/
2
];
volatile
uint32_t
v
=
((
uint32_t
*
)
aligned_array
)[
index
/
2
];
...
...
app/platform/flash_api.h
View file @
5261fb19
#ifndef __FLASH_API_H__
#ifndef __FLASH_API_H__
#define __FLASH_API_H__
#define __FLASH_API_H__
#include "ets_sys.h"
#include "user_config.h"
#include "user_config.h"
#include "cpu_esp8266.h"
#include "user_interface.h"
#include "spi_flash.h"
#define FLASH_ADDRESS_START_MAP (INTERNAL_FLASH_START_ADDRESS)
#define FLASH_ADDRESS_START_MAP (INTERNAL_FLASH_START_ADDRESS)
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
#define FLASH_SIZE_8MBYTE (FLASH_SIZE_64MBIT / 8)
#define FLASH_SIZE_8MBYTE (FLASH_SIZE_64MBIT / 8)
#define FLASH_SIZE_16MBYTE (FLASH_SIZE_128MBIT/ 8)
#define FLASH_SIZE_16MBYTE (FLASH_SIZE_128MBIT/ 8)
#define FLASH_DEBUG
#define FLASH_SAFEMODE_ENTER() \
#define FLASH_SAFEMODE_ENTER() \
do { \
do { \
extern SpiFlashChip * flashchip; \
extern SpiFlashChip * flashchip; \
...
@@ -85,7 +87,7 @@ typedef struct
...
@@ -85,7 +87,7 @@ typedef struct
}
size
:
4
;
}
size
:
4
;
uint32_t
entry_point
;
uint32_t
entry_point
;
uint32_t
memory_offset
;
uint32_t
memory_offset
;
uint32_t
segment_size
;
uint32_t
segment_size
;
}
ICACHE_STORE_TYPEDEF_ATTR
SPIFlashInfo
;
}
ICACHE_STORE_TYPEDEF_ATTR
SPIFlashInfo
;
uint32_t
flash_detect_size_byte
(
void
);
uint32_t
flash_detect_size_byte
(
void
);
...
...
app/spiffs/spiffs.c
View file @
5261fb19
#include "c_stdio.h"
#include "c_stdio.h"
#include "platform.h"
#include "platform.h"
#include "spiffs.h"
#include "spiffs.h"
#undef NODE_DBG
#define NODE_DBG c_printf
spiffs
fs
;
spiffs
fs
;
#define LOG_PAGE_SIZE 256
#define LOG_PAGE_SIZE
(
256
*2)
static
u8_t
spiffs_work_buf
[
LOG_PAGE_SIZE
*
2
];
static
u8_t
spiffs_work_buf
[
LOG_PAGE_SIZE
*
2
];
static
u8_t
spiffs_fds
[
32
*
4
];
static
u8_t
spiffs_fds
[
32
*
4
];
...
@@ -51,9 +49,9 @@ void myspiffs_mount() {
...
@@ -51,9 +49,9 @@ void myspiffs_mount() {
cfg
.
phys_addr
&=
0xFFFFC000
;
// align to 4 sector.
cfg
.
phys_addr
&=
0xFFFFC000
;
// align to 4 sector.
cfg
.
phys_size
=
INTERNAL_FLASH_SIZE
-
(
(
u32_t
)
cfg
.
phys_addr
-
INTERNAL_FLASH_START_ADDRESS
);
cfg
.
phys_size
=
INTERNAL_FLASH_SIZE
-
(
(
u32_t
)
cfg
.
phys_addr
-
INTERNAL_FLASH_START_ADDRESS
);
cfg
.
phys_erase_block
=
INTERNAL_FLASH_SECTOR_SIZE
;
// according to datasheet
cfg
.
phys_erase_block
=
INTERNAL_FLASH_SECTOR_SIZE
;
// according to datasheet
cfg
.
log_block_size
=
INTERNAL_FLASH_SECTOR_SIZE
;
// let us not complicate things
cfg
.
log_block_size
=
INTERNAL_FLASH_SECTOR_SIZE
*
16
;
// let us not complicate things
cfg
.
log_page_size
=
LOG_PAGE_SIZE
;
// as we said
cfg
.
log_page_size
=
LOG_PAGE_SIZE
;
// as we said
NODE
_DBG
(
"fs.start:%x,max:%x
\n
"
,
cfg
.
phys_addr
,
cfg
.
phys_size
);
SPIFFS
_DBG
(
"fs.start:%x,max:%x
\n
"
,
cfg
.
phys_addr
,
cfg
.
phys_size
);
cfg
.
hal_read_f
=
my_spiffs_read
;
cfg
.
hal_read_f
=
my_spiffs_read
;
cfg
.
hal_write_f
=
my_spiffs_write
;
cfg
.
hal_write_f
=
my_spiffs_write
;
...
@@ -68,7 +66,7 @@ void myspiffs_mount() {
...
@@ -68,7 +66,7 @@ void myspiffs_mount() {
sizeof
(
spiffs_cache
),
sizeof
(
spiffs_cache
),
// myspiffs_check_callback);
// myspiffs_check_callback);
0
);
0
);
NODE
_DBG
(
"mount res: %i
\n
"
,
res
);
SPIFFS
_DBG
(
"mount res: %i
\n
"
,
res
);
}
}
void
myspiffs_unmount
()
{
void
myspiffs_unmount
()
{
...
@@ -79,10 +77,13 @@ void myspiffs_unmount() {
...
@@ -79,10 +77,13 @@ void myspiffs_unmount() {
// Returns 1 if OK, 0 for error
// Returns 1 if OK, 0 for error
int
myspiffs_format
(
void
)
int
myspiffs_format
(
void
)
{
{
#if 0
#if 1
SPIFFS_unmount(&fs);
myspiffs_unmount
();
myspiffs_mount
();
myspiffs_unmount
();
if
(
0
==
SPIFFS_format
(
&
fs
))
if
(
0
==
SPIFFS_format
(
&
fs
))
{
{
myspiffs_mount
();
return
1
;
return
1
;
}
}
else
else
...
@@ -97,7 +98,7 @@ int myspiffs_format( void )
...
@@ -97,7 +98,7 @@ int myspiffs_format( void )
sect_first
=
platform_flash_get_sector_of_address
(
sect_first
);
sect_first
=
platform_flash_get_sector_of_address
(
sect_first
);
sect_last
=
INTERNAL_FLASH_SIZE
+
INTERNAL_FLASH_START_ADDRESS
-
4
;
sect_last
=
INTERNAL_FLASH_SIZE
+
INTERNAL_FLASH_START_ADDRESS
-
4
;
sect_last
=
platform_flash_get_sector_of_address
(
sect_last
);
sect_last
=
platform_flash_get_sector_of_address
(
sect_last
);
NODE
_DBG
(
"sect_first: %x, sect_last: %x
\n
"
,
sect_first
,
sect_last
);
SPIFFS
_DBG
(
"sect_first: %x, sect_last: %x
\n
"
,
sect_first
,
sect_last
);
while
(
sect_first
<=
sect_last
)
while
(
sect_first
<=
sect_last
)
if
(
platform_flash_erase_sector
(
sect_first
++
)
==
PLATFORM_ERR
)
if
(
platform_flash_erase_sector
(
sect_first
++
)
==
PLATFORM_ERR
)
return
0
;
return
0
;
...
@@ -116,7 +117,11 @@ int myspiffs_check( void )
...
@@ -116,7 +117,11 @@ int myspiffs_check( void )
}
}
int
myspiffs_open
(
const
char
*
name
,
int
flags
){
int
myspiffs_open
(
const
char
*
name
,
int
flags
){
return
(
int
)
SPIFFS_open
(
&
fs
,
(
char
*
)
name
,
(
spiffs_flags
)
flags
,
0
);
int
res
=
SPIFFS_open
(
&
fs
,
(
char
*
)
name
,
(
spiffs_flags
)
flags
,
0
);
if
(
res
<
0
)
{
SPIFFS_DBG
(
"open errno %i
\n
"
,
SPIFFS_errno
(
&
fs
));
}
return
res
;
}
}
int
myspiffs_close
(
int
fd
){
int
myspiffs_close
(
int
fd
){
...
@@ -130,17 +135,17 @@ size_t myspiffs_write( int fd, const void* ptr, size_t len ){
...
@@ -130,17 +135,17 @@ size_t myspiffs_write( int fd, const void* ptr, size_t len ){
return len;
return len;
}
}
#endif
#endif
int
res
=
SPIFFS_write
(
&
fs
,
(
spiffs_file
)
fd
,
(
void
*
)
ptr
,
(
size_t
)
len
);
int
res
=
SPIFFS_write
(
&
fs
,
(
spiffs_file
)
fd
,
(
void
*
)
ptr
,
len
);
if
(
res
<
0
)
{
if
(
res
<
0
)
{
NODE
_DBG
(
"write errno %i
\n
"
,
SPIFFS_errno
(
&
fs
));
SPIFFS
_DBG
(
"write errno %i
\n
"
,
SPIFFS_errno
(
&
fs
));
return
0
;
return
0
;
}
}
return
res
;
return
res
;
}
}
size_t
myspiffs_read
(
int
fd
,
void
*
ptr
,
size_t
len
){
size_t
myspiffs_read
(
int
fd
,
void
*
ptr
,
size_t
len
){
int
res
=
SPIFFS_read
(
&
fs
,
(
spiffs_file
)
fd
,
ptr
,
(
size_t
)
len
);
int
res
=
SPIFFS_read
(
&
fs
,
(
spiffs_file
)
fd
,
ptr
,
len
);
if
(
res
<
0
)
{
if
(
res
<
0
)
{
NODE
_DBG
(
"read errno %i
\n
"
,
SPIFFS_errno
(
&
fs
));
SPIFFS
_DBG
(
"read errno %i
\n
"
,
SPIFFS_errno
(
&
fs
));
return
0
;
return
0
;
}
}
return
res
;
return
res
;
...
@@ -160,7 +165,7 @@ int myspiffs_getc( int fd ){
...
@@ -160,7 +165,7 @@ int myspiffs_getc( int fd ){
if
(
!
myspiffs_eof
(
fd
)){
if
(
!
myspiffs_eof
(
fd
)){
res
=
SPIFFS_read
(
&
fs
,
(
spiffs_file
)
fd
,
&
c
,
1
);
res
=
SPIFFS_read
(
&
fs
,
(
spiffs_file
)
fd
,
&
c
,
1
);
if
(
res
!=
1
)
{
if
(
res
!=
1
)
{
NODE
_DBG
(
"getc errno %i
\n
"
,
SPIFFS_errno
(
&
fs
));
SPIFFS
_DBG
(
"getc errno %i
\n
"
,
SPIFFS_errno
(
&
fs
));
return
(
int
)
EOF
;
return
(
int
)
EOF
;
}
else
{
}
else
{
return
(
int
)
c
;
return
(
int
)
c
;
...
@@ -193,13 +198,13 @@ void test_spiffs() {
...
@@ -193,13 +198,13 @@ void test_spiffs() {
// Surely, I've mounted spiffs before entering here
// Surely, I've mounted spiffs before entering here
spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0)
NODE
_DBG("errno %i\n", SPIFFS_errno(&fs));
if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0)
SPIFFS
_DBG("errno %i\n", SPIFFS_errno(&fs));
SPIFFS_close(&fs, fd);
SPIFFS_close(&fs, fd);
fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0)
NODE
_DBG("errno %i\n", SPIFFS_errno(&fs));
if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0)
SPIFFS
_DBG("errno %i\n", SPIFFS_errno(&fs));
SPIFFS_close(&fs, fd);
SPIFFS_close(&fs, fd);
NODE
_DBG("--> %s <--\n", buf);
SPIFFS
_DBG("--> %s <--\n", buf);
}
}
#endif
#endif
app/spiffs/spiffs.h
View file @
5261fb19
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
#if defined(__cplusplus)
#if defined(__cplusplus)
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "eagle_soc.h"
#include "c_stdio.h"
#include "c_stdio.h"
#include "spiffs_config.h"
#include "spiffs_config.h"
...
@@ -53,6 +53,7 @@ extern "C" {
...
@@ -53,6 +53,7 @@ extern "C" {
#define SPIFFS_ERR_TEST -10100
#define SPIFFS_ERR_TEST -10100
#define SPIFFS_WDT_CLEAR(no_arg) WRITE_PERI_REG(0x60000914, 0x73)
// spiffs file descriptor index type. must be signed
// spiffs file descriptor index type. must be signed
typedef
s16_t
spiffs_file
;
typedef
s16_t
spiffs_file
;
...
...
app/spiffs/spiffs_config.h
View file @
5261fb19
...
@@ -30,7 +30,7 @@ typedef uint8_t u8_t;
...
@@ -30,7 +30,7 @@ typedef uint8_t u8_t;
// Set generic spiffs debug output call.
// Set generic spiffs debug output call.
#ifndef SPIFFS_DGB
#ifndef SPIFFS_DGB
#define SPIFFS_DBG(...) c_printf(__VA_ARGS__)
#define SPIFFS_DBG(...)
//
c_printf(__VA_ARGS__)
#endif
#endif
// Set spiffs debug output call for garbage collecting.
// Set spiffs debug output call for garbage collecting.
#ifndef SPIFFS_GC_DGB
#ifndef SPIFFS_GC_DGB
...
@@ -124,7 +124,7 @@ typedef uint8_t u8_t;
...
@@ -124,7 +124,7 @@ typedef uint8_t u8_t;
// not on mount point. If not, SPIFFS_format must be called prior to mounting
// not on mount point. If not, SPIFFS_format must be called prior to mounting
// again.
// again.
#ifndef SPIFFS_USE_MAGIC
#ifndef SPIFFS_USE_MAGIC
#define SPIFFS_USE_MAGIC (
0
)
#define SPIFFS_USE_MAGIC (
1
)
#endif
#endif
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
...
@@ -169,7 +169,7 @@ typedef uint8_t u8_t;
...
@@ -169,7 +169,7 @@ typedef uint8_t u8_t;
// Enable this if your target needs aligned data for index tables
// Enable this if your target needs aligned data for index tables
#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
0
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
1
#endif
#endif
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
...
...
app/spiffs/spiffs_hydrogen.c
View file @
5261fb19
...
@@ -936,6 +936,7 @@ s32_t SPIFFS_vis(spiffs *fs) {
...
@@ -936,6 +936,7 @@ s32_t SPIFFS_vis(spiffs *fs) {
int
cur_entry
=
0
;
int
cur_entry
=
0
;
while
(
res
==
SPIFFS_OK
&&
obj_lookup_page
<
(
int
)
SPIFFS_OBJ_LOOKUP_PAGES
(
fs
))
{
while
(
res
==
SPIFFS_OK
&&
obj_lookup_page
<
(
int
)
SPIFFS_OBJ_LOOKUP_PAGES
(
fs
))
{
SPIFFS_WDT_CLEAR
();
int
entry_offset
=
obj_lookup_page
*
entries_per_page
;
int
entry_offset
=
obj_lookup_page
*
entries_per_page
;
res
=
_spiffs_rd
(
fs
,
SPIFFS_OP_T_OBJ_LU
|
SPIFFS_OP_C_READ
,
res
=
_spiffs_rd
(
fs
,
SPIFFS_OP_T_OBJ_LU
|
SPIFFS_OP_C_READ
,
0
,
bix
*
SPIFFS_CFG_LOG_BLOCK_SZ
(
fs
)
+
SPIFFS_PAGE_TO_PADDR
(
fs
,
obj_lookup_page
),
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
),
fs
->
lu_work
);
0
,
bix
*
SPIFFS_CFG_LOG_BLOCK_SZ
(
fs
)
+
SPIFFS_PAGE_TO_PADDR
(
fs
,
obj_lookup_page
),
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
),
fs
->
lu_work
);
...
...
app/spiffs/spiffs_nucleus.c
View file @
5261fb19
...
@@ -155,6 +155,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
...
@@ -155,6 +155,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
// check each block
// check each block
while
(
res
==
SPIFFS_OK
&&
entry_count
>
0
)
{
while
(
res
==
SPIFFS_OK
&&
entry_count
>
0
)
{
int
obj_lookup_page
=
cur_entry
/
entries_per_page
;
int
obj_lookup_page
=
cur_entry
/
entries_per_page
;
SPIFFS_WDT_CLEAR
();
// check each object lookup page
// check each object lookup page
while
(
res
==
SPIFFS_OK
&&
obj_lookup_page
<
(
int
)
SPIFFS_OBJ_LOOKUP_PAGES
(
fs
))
{
while
(
res
==
SPIFFS_OK
&&
obj_lookup_page
<
(
int
)
SPIFFS_OBJ_LOOKUP_PAGES
(
fs
))
{
int
entry_offset
=
obj_lookup_page
*
entries_per_page
;
int
entry_offset
=
obj_lookup_page
*
entries_per_page
;
...
@@ -165,6 +166,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
...
@@ -165,6 +166,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
cur_entry
-
entry_offset
<
entries_per_page
&&
// for non-last obj lookup pages
cur_entry
-
entry_offset
<
entries_per_page
&&
// for non-last obj lookup pages
cur_entry
<
(
int
)
SPIFFS_OBJ_LOOKUP_MAX_ENTRIES
(
fs
))
// for last obj lookup page
cur_entry
<
(
int
)
SPIFFS_OBJ_LOOKUP_MAX_ENTRIES
(
fs
))
// for last obj lookup page
{
{
SPIFFS_WDT_CLEAR
();
if
((
flags
&
SPIFFS_VIS_CHECK_ID
)
==
0
||
obj_lu_buf
[
cur_entry
-
entry_offset
]
==
obj_id
)
{
if
((
flags
&
SPIFFS_VIS_CHECK_ID
)
==
0
||
obj_lu_buf
[
cur_entry
-
entry_offset
]
==
obj_id
)
{
if
(
block_ix
)
*
block_ix
=
cur_block
;
if
(
block_ix
)
*
block_ix
=
cur_block
;
if
(
lu_entry
)
*
lu_entry
=
cur_entry
;
if
(
lu_entry
)
*
lu_entry
=
cur_entry
;
...
@@ -301,6 +303,7 @@ s32_t spiffs_obj_lu_scan(
...
@@ -301,6 +303,7 @@ s32_t spiffs_obj_lu_scan(
spiffs_obj_id
erase_count_min
=
SPIFFS_OBJ_ID_FREE
;
spiffs_obj_id
erase_count_min
=
SPIFFS_OBJ_ID_FREE
;
spiffs_obj_id
erase_count_max
=
0
;
spiffs_obj_id
erase_count_max
=
0
;
while
(
bix
<
fs
->
block_count
)
{
while
(
bix
<
fs
->
block_count
)
{
SPIFFS_WDT_CLEAR
();
#if SPIFFS_USE_MAGIC
#if SPIFFS_USE_MAGIC
spiffs_obj_id
magic
;
spiffs_obj_id
magic
;
res
=
_spiffs_rd
(
fs
,
res
=
_spiffs_rd
(
fs
,
...
@@ -802,6 +805,7 @@ void spiffs_cb_object_event(
...
@@ -802,6 +805,7 @@ void spiffs_cb_object_event(
u32_t
i
;
u32_t
i
;
spiffs_fd
*
fds
=
(
spiffs_fd
*
)
fs
->
fd_space
;
spiffs_fd
*
fds
=
(
spiffs_fd
*
)
fs
->
fd_space
;
for
(
i
=
0
;
i
<
fs
->
fd_count
;
i
++
)
{
for
(
i
=
0
;
i
<
fs
->
fd_count
;
i
++
)
{
SPIFFS_WDT_CLEAR
();
spiffs_fd
*
cur_fd
=
&
fds
[
i
];
spiffs_fd
*
cur_fd
=
&
fds
[
i
];
if
(
cur_fd
->
file_nbr
==
0
||
(
cur_fd
->
obj_id
&
~
SPIFFS_OBJ_ID_IX_FLAG
)
!=
obj_id
)
continue
;
if
(
cur_fd
->
file_nbr
==
0
||
(
cur_fd
->
obj_id
&
~
SPIFFS_OBJ_ID_IX_FLAG
)
!=
obj_id
)
continue
;
if
(
spix
==
0
)
{
if
(
spix
==
0
)
{
...
@@ -918,9 +922,9 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
...
@@ -918,9 +922,9 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
// write all data
// write all data
while
(
res
==
SPIFFS_OK
&&
written
<
len
)
{
while
(
res
==
SPIFFS_OK
&&
written
<
len
)
{
SPIFFS_WDT_CLEAR
();
// calculate object index page span index
// calculate object index page span index
cur_objix_spix
=
SPIFFS_OBJ_IX_ENTRY_SPAN_IX
(
fs
,
data_spix
);
cur_objix_spix
=
SPIFFS_OBJ_IX_ENTRY_SPAN_IX
(
fs
,
data_spix
);
// handle storing and loading of object indices
// handle storing and loading of object indices
if
(
cur_objix_spix
!=
prev_objix_spix
)
{
if
(
cur_objix_spix
!=
prev_objix_spix
)
{
// new object index page
// new object index page
...
@@ -1150,6 +1154,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
...
@@ -1150,6 +1154,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
// write all data
// write all data
while
(
res
==
SPIFFS_OK
&&
written
<
len
)
{
while
(
res
==
SPIFFS_OK
&&
written
<
len
)
{
SPIFFS_WDT_CLEAR
();
// calculate object index page span index
// calculate object index page span index
cur_objix_spix
=
SPIFFS_OBJ_IX_ENTRY_SPAN_IX
(
fs
,
data_spix
);
cur_objix_spix
=
SPIFFS_OBJ_IX_ENTRY_SPAN_IX
(
fs
,
data_spix
);
...
@@ -1627,6 +1632,7 @@ s32_t spiffs_object_read(
...
@@ -1627,6 +1632,7 @@ s32_t spiffs_object_read(
spiffs_page_object_ix
*
objix
=
(
spiffs_page_object_ix
*
)
fs
->
work
;
spiffs_page_object_ix
*
objix
=
(
spiffs_page_object_ix
*
)
fs
->
work
;
while
(
cur_offset
<
offset
+
len
)
{
while
(
cur_offset
<
offset
+
len
)
{
SPIFFS_WDT_CLEAR
();
cur_objix_spix
=
SPIFFS_OBJ_IX_ENTRY_SPAN_IX
(
fs
,
data_spix
);
cur_objix_spix
=
SPIFFS_OBJ_IX_ENTRY_SPAN_IX
(
fs
,
data_spix
);
if
(
prev_objix_spix
!=
cur_objix_spix
)
{
if
(
prev_objix_spix
!=
cur_objix_spix
)
{
// load current object index (header) page
// load current object index (header) page
...
@@ -1775,6 +1781,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
...
@@ -1775,6 +1781,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
state
.
compaction
=
0
;
state
.
compaction
=
0
;
state
.
conflicting_name
=
conflicting_name
;
state
.
conflicting_name
=
conflicting_name
;
while
(
res
==
SPIFFS_OK
&&
free_obj_id
==
SPIFFS_OBJ_ID_FREE
)
{
while
(
res
==
SPIFFS_OK
&&
free_obj_id
==
SPIFFS_OBJ_ID_FREE
)
{
SPIFFS_WDT_CLEAR
();
if
(
state
.
max_obj_id
-
state
.
min_obj_id
<=
(
spiffs_obj_id
)
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
)
*
8
)
{
if
(
state
.
max_obj_id
-
state
.
min_obj_id
<=
(
spiffs_obj_id
)
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
)
*
8
)
{
// possible to represent in bitmap
// possible to represent in bitmap
u32_t
i
,
j
;
u32_t
i
,
j
;
...
@@ -1787,6 +1794,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
...
@@ -1787,6 +1794,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
SPIFFS_CHECK_RES
(
res
);
SPIFFS_CHECK_RES
(
res
);
// traverse bitmask until found free obj_id
// traverse bitmask until found free obj_id
for
(
i
=
0
;
i
<
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
);
i
++
)
{
for
(
i
=
0
;
i
<
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
);
i
++
)
{
SPIFFS_WDT_CLEAR
();
u8_t
mask
=
fs
->
work
[
i
];
u8_t
mask
=
fs
->
work
[
i
];
if
(
mask
==
0xff
)
{
if
(
mask
==
0xff
)
{
continue
;
continue
;
...
@@ -1808,6 +1816,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
...
@@ -1808,6 +1816,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
u8_t
min_count
=
0xff
;
u8_t
min_count
=
0xff
;
for
(
i
=
0
;
i
<
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
)
/
sizeof
(
u8_t
);
i
++
)
{
for
(
i
=
0
;
i
<
SPIFFS_CFG_LOG_PAGE_SZ
(
fs
)
/
sizeof
(
u8_t
);
i
++
)
{
SPIFFS_WDT_CLEAR
();
if
(
map
[
i
]
<
min_count
)
{
if
(
map
[
i
]
<
min_count
)
{
min_count
=
map
[
i
];
min_count
=
map
[
i
];
min_i
=
i
;
min_i
=
i
;
...
@@ -1860,6 +1869,7 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd) {
...
@@ -1860,6 +1869,7 @@ s32_t spiffs_fd_find_new(spiffs *fs, spiffs_fd **fd) {
u32_t
i
;
u32_t
i
;
spiffs_fd
*
fds
=
(
spiffs_fd
*
)
fs
->
fd_space
;
spiffs_fd
*
fds
=
(
spiffs_fd
*
)
fs
->
fd_space
;
for
(
i
=
0
;
i
<
fs
->
fd_count
;
i
++
)
{
for
(
i
=
0
;
i
<
fs
->
fd_count
;
i
++
)
{
SPIFFS_WDT_CLEAR
();
spiffs_fd
*
cur_fd
=
&
fds
[
i
];
spiffs_fd
*
cur_fd
=
&
fds
[
i
];
if
(
cur_fd
->
file_nbr
==
0
)
{
if
(
cur_fd
->
file_nbr
==
0
)
{
cur_fd
->
file_nbr
=
i
+
1
;
cur_fd
->
file_nbr
=
i
+
1
;
...
...
app/user/user_main.c
View file @
5261fb19
...
@@ -61,13 +61,15 @@ void nodemcu_init(void)
...
@@ -61,13 +61,15 @@ void nodemcu_init(void)
#if defined(FLASH_SAFE_API)
#if defined(FLASH_SAFE_API)
if
(
flash_safe_get_size_byte
()
!=
flash_rom_get_size_byte
())
{
if
(
flash_safe_get_size_byte
()
!=
flash_rom_get_size_byte
())
{
NODE_ERR
(
"Self adjust flash size.
\n
"
);
NODE_ERR
(
"File system initialization ...
\n
"
);
NODE_ERR
(
"This will take a minute, don't power off.
\n
"
);
// Fit hardware real flash size.
// Fit hardware real flash size.
flash_rom_set_size_byte
(
flash_safe_get_size_byte
());
flash_rom_set_size_byte
(
flash_safe_get_size_byte
());
// Flash init data at FLASHSIZE - 0x04000 Byte.
// Flash init data at FLASHSIZE - 0x04000 Byte.
flash_init_data_default
();
flash_init_data_default
();
// Flash blank data at FLASHSIZE - 0x02000 Byte.
// Flash blank data at FLASHSIZE - 0x02000 Byte.
flash_init_data_blank
();
flash_init_data_blank
();
if
(
!
fs_format
()
)
if
(
!
fs_format
()
)
{
{
NODE_ERR
(
"
\n
i*** ERROR ***: unable to format. FS might be compromised.
\n
"
);
NODE_ERR
(
"
\n
i*** ERROR ***: unable to format. FS might be compromised.
\n
"
);
...
@@ -76,7 +78,8 @@ void nodemcu_init(void)
...
@@ -76,7 +78,8 @@ void nodemcu_init(void)
else
{
else
{
NODE_ERR
(
"format done.
\n
"
);
NODE_ERR
(
"format done.
\n
"
);
}
}
fs_unmount
();
// mounted by format.
// Unmount filesystem because mounted by format.
fs_unmount
();
}
}
#endif // defined(FLASH_SAFE_API)
#endif // defined(FLASH_SAFE_API)
...
@@ -102,6 +105,22 @@ void nodemcu_init(void)
...
@@ -102,6 +105,22 @@ void nodemcu_init(void)
// test_romfs();
// test_romfs();
#elif defined ( BUILD_SPIFFS )
#elif defined ( BUILD_SPIFFS )
fs_mount
();
fs_mount
();
if
(
SPIFFS_mounted
==
0
)
{
NODE_ERR
(
"File system broken, formating ...
\n
"
);
NODE_ERR
(
"This will take a minute, don't power off.
\n
"
);
if
(
!
fs_format
()
)
{
NODE_ERR
(
"
\n
i*** ERROR ***: unable to format. FS might be compromised.
\n
"
);
NODE_ERR
(
"It is advised to re-flash the NodeMCU image.
\n
"
);
}
else
{
NODE_ERR
(
"format done.
\n
"
);
}
// Ensure filesystem mounted.
fs_unmount
();
fs_mount
();
}
// test_spiffs();
// test_spiffs();
#endif
#endif
// endpoint_setup();
// endpoint_setup();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment