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
3c6ebea0
Commit
3c6ebea0
authored
Jan 06, 2015
by
HuangRui
Browse files
Use safe flash options.
parent
7e51c5d6
Changes
3
Show whitespace changes
Inline
Side-by-side
app/platform/flash_api.c
View file @
3c6ebea0
...
@@ -71,10 +71,10 @@ bool flash_set_size(uint8_t size)
...
@@ -71,10 +71,10 @@ bool flash_set_size(uint8_t size)
// 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 ...
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
SPIRead
(
0
,
data
,
sizeof
(
data
));
spi_flash_read
(
0
,
(
uint32
*
)
data
,
sizeof
(
data
));
SPIFlashInfo
*
p_spi_flash_info
=
(
SPIFlashInfo
*
)(
data
);
SPIFlashInfo
*
p_spi_flash_info
=
(
SPIFlashInfo
*
)(
data
);
p_spi_flash_info
->
size
=
size
;
p_spi_flash_info
->
size
=
size
;
SPIE
rase
S
ector
(
0
);
spi_flash_e
rase
_s
ector
(
0
);
spi_flash_write
(
0
,
(
uint32
*
)
data
,
sizeof
(
data
));
spi_flash_write
(
0
,
(
uint32
*
)
data
,
sizeof
(
data
));
//p_spi_flash_info = flash_get_info();
//p_spi_flash_info = flash_get_info();
//p_spi_flash_info->size = size;
//p_spi_flash_info->size = size;
...
@@ -175,14 +175,14 @@ uint32_t flash_get_speed(void)
...
@@ -175,14 +175,14 @@ uint32_t flash_get_speed(void)
bool
flash_init_data_written
(
void
)
bool
flash_init_data_written
(
void
)
{
{
// FLASH SEC - 4
// FLASH SEC - 4
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// It will init system data to default!
uint32_t
data
[
2
]
ICACHE_STORE_ATTR
;
uint32_t
data
[
2
]
ICACHE_STORE_ATTR
;
SPIRead
((
flash_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
data
,
sizeof
(
data
));
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_read
((
flash_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
data
,
sizeof
(
data
)))
if
(
data
[
0
]
==
0xFFFFFFFF
&&
data
[
1
]
==
0xFFFFFFFF
)
{
{
if
(
data
[
0
]
==
0xFFFFFFFF
&&
data
[
1
]
==
0xFFFFFFFF
)
{
return
false
;
return
false
;
}
}
}
return
true
;
return
true
;
}
}
...
@@ -192,10 +192,15 @@ bool flash_init_data_default(void)
...
@@ -192,10 +192,15 @@ bool flash_init_data_default(void)
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// Reboot required!!!
// It will init system data to default!
// It will init system data to default!
bool
result
=
false
;
SPIEraseSector
((
flash_get_sec_num
()
-
4
));
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
((
flash_get_sec_num
()
-
4
)))
spi_flash_write
((
flash_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
flash_init_data
,
128
);
{
return
true
;
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
((
flash_get_sec_num
()
-
4
)
*
SPI_FLASH_SEC_SIZE
,
(
uint32
*
)
flash_init_data
,
128
))
{
result
=
true
;
}
}
return
result
;
}
}
bool
flash_init_data_blank
(
void
)
bool
flash_init_data_blank
(
void
)
...
@@ -204,14 +209,19 @@ bool flash_init_data_blank(void)
...
@@ -204,14 +209,19 @@ bool flash_init_data_blank(void)
// Dangerous, here are dinosaur infested!!!!!
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// Reboot required!!!
// It will init system config to blank!
// It will init system config to blank!
SPIEraseSector
((
flash_get_sec_num
()
-
2
));
bool
result
=
false
;
SPIEraseSector
((
flash_get_sec_num
()
-
1
));
if
((
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
((
flash_get_sec_num
()
-
2
)))
&&
return
true
;
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
((
flash_get_sec_num
()
-
1
))))
{
result
=
true
;
}
return
result
;
}
}
bool
flash_self_destruct
(
void
)
bool
flash_self_destruct
(
void
)
{
{
// Erase your flash. Good bye!
//
Dangerous,
Erase your flash. Good bye!
SPIEraseChip
();
SPIEraseChip
();
return
true
;
return
true
;
}
}
app/platform/flash_api.h
View file @
3c6ebea0
...
@@ -5,6 +5,28 @@
...
@@ -5,6 +5,28 @@
#include "cpu_esp8266.h"
#include "cpu_esp8266.h"
#define FLASH_MAP_START_ADDRESS (INTERNAL_FLASH_START_ADDRESS)
#define FLASH_MAP_START_ADDRESS (INTERNAL_FLASH_START_ADDRESS)
/******************************************************************************
* ROM Function definition
* Note: It is unsafe to use ROM function, but it may efficient.
* SPIEraseSector
* unknown SPIEraseSector(uint16 sec);
* The 1st parameter is flash sector number.
* SPIRead (Unsafe)
* unknown SPIRead(uint32_t src_addr, uint32_t *des_addr, uint32_t size);
* The 1st parameter is source addresses.
* The 2nd parameter is destination addresses.
* The 3rd parameter is size.
* Note: Sometimes it have no effect, may be need a delay or other option(lock or unlock, etc.) with known reason.
* SPIWrite (Unsafe)
* unknown SPIWrite(uint32_t des_addr, uint32_t *src_addr, uint32_t size);
* The 1st parameter is destination addresses.
* The 2nd parameter is source addresses.
* The 3rd parameter is size.
* Note: Sometimes it have no effect, may be need a delay or other option(lock or unlock, etc.) with known reason.
*******************************************************************************/
typedef
struct
typedef
struct
{
{
uint8_t
unknown0
;
uint8_t
unknown0
;
...
...
app/user/user_main.c
View file @
3c6ebea0
...
@@ -83,9 +83,12 @@ void user_init(void)
...
@@ -83,9 +83,12 @@ void user_init(void)
return
;
return
;
}
}
if
(
!
flash_init_data_written
()){
if
(
!
flash_init_data_written
()
){
NODE_ERR
(
"Restore init data.
\n
"
);
NODE_ERR
(
"Restore init data.
\n
"
);
// Flash init data at FLASHSIZE - 0x04000 Byte.
flash_init_data_default
();
flash_init_data_default
();
// Flash blank data at FLASHSIZE - 0x02000 Byte.
flash_init_data_blank
();
}
}
#if defined( BUILD_WOFS )
#if defined( BUILD_WOFS )
...
...
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