Skip to content

Commit

Permalink
add save areas for FLASH_4MB_C1
Browse files Browse the repository at this point in the history
  • Loading branch information
MaBecker committed Feb 27, 2017
1 parent 096b745 commit 6421b97
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -585,7 +585,7 @@ endif


ifdef FLASH_4MB_C1
ESP_FLASH_MAX ?= 917504 # max bin file: 896KB
ESP_FLASH_MAX ?= 909312 # max bin file: 888KB
ESP_FLASH_SIZE ?= 6 # 6->4MB (1024KB+1024KB)
ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
Expand Down
12 changes: 11 additions & 1 deletion boards/ESP8266_BOARD.py
Expand Up @@ -12,7 +12,7 @@
# Buttons, and other in-built peripherals are. It is used to build documentation as well
# as various source and header files for Espruino.
# ----------------------------------------------------------------------------------------

import os;
import pinutils;
info = {
'name' : "ESP8266",
Expand Down Expand Up @@ -49,6 +49,16 @@
'flash_available' : 468, # firmware can be up to this size
},
};

if (os.environ.has_key("FLASH_4MB_C1")):
chip['saved_code'] = {
'address' : 0xF8000,
'page_size' : 4096,
'pages' : 5,
'flash_available' : 888, # firmware can be up to this size
};


devices = {
};

Expand Down
17 changes: 14 additions & 3 deletions libs/network/esp8266/jswrap_esp8266_network.c
Expand Up @@ -1144,6 +1144,7 @@ void jswrap_ESP8266_wifi_save(JsVar *what) {
uint32_t flashBlock[256];
Esp8266_config *conf=(Esp8266_config *)flashBlock;
os_memset(flashBlock, 0, sizeof(flashBlock));
uint32_t map = system_get_flash_size_map();

conf->length = 1024;
conf->version = 24;
Expand Down Expand Up @@ -1182,8 +1183,13 @@ void jswrap_ESP8266_wifi_save(JsVar *what) {

conf->crc = crc32((uint8_t*)flashBlock, sizeof(flashBlock));
DBG("Wifi.save: len=%d vers=%d crc=0x%08lx\n", conf->length, conf->version, conf->crc);
jshFlashErasePage(0x7B000);
jshFlashWrite(conf, 0x7B000, sizeof(flashBlock));
if (map == 6 ) {
jshFlashErasePage(0xFD000);
jshFlashWrite(conf, 0xFD000, sizeof(flashBlock));
} else {
jshFlashErasePage(0x7B000);
jshFlashWrite(conf, 0x7B000, sizeof(flashBlock));
}
DBGV("< Wifi.save: write completed\n");
}

Expand All @@ -1202,7 +1208,12 @@ void jswrap_ESP8266_wifi_restore(void) {
uint32_t flashBlock[256];
Esp8266_config *conf=(Esp8266_config *)flashBlock;
os_memset(flashBlock, 0, sizeof(flashBlock));
jshFlashRead(flashBlock, 0x7B000, sizeof(flashBlock));
uint32_t map = system_get_flash_size_map();
if (map == 6 ) {
jshFlashRead(flashBlock, 0xFD000, sizeof(flashBlock));
} else {
jshFlashRead(flashBlock, 0x7B000, sizeof(flashBlock));
}
DBG("Wifi.restore: len=%d vers=%d crc=0x%08lx\n", conf->length, conf->version, conf->crc);
uint32_t crcRd = conf->crc;
conf->crc = 0;
Expand Down

0 comments on commit 6421b97

Please sign in to comment.