Skip to content

Commit

Permalink
use 0x200000 as save section and 0x300000 as flash section
Browse files Browse the repository at this point in the history
  • Loading branch information
MaBecker committed Feb 27, 2017
1 parent e4fe775 commit 81204d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -585,7 +585,7 @@ endif


ifdef FLASH_4MB_C1
ESP_FLASH_MAX ?= 909312 # max bin file: 888KB
ESP_FLASH_MAX ?= 933888 # max bin file: 912KB
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
6 changes: 3 additions & 3 deletions boards/ESP8266_BOARD.py
Expand Up @@ -52,10 +52,10 @@

if (os.environ.has_key("FLASH_4MB_C1")):
chip['saved_code'] = {
'address' : 0xF8000,
'address' : 0x201000, # first page is used for wifi save
'page_size' : 4096,
'pages' : 5,
'flash_available' : 888, # firmware can be up to this size
'pages' : 255,
'flash_available' : 912, # firmware can be up to this size
};


Expand Down
14 changes: 7 additions & 7 deletions libs/network/esp8266/jswrap_esp8266_network.c
Expand Up @@ -1182,10 +1182,10 @@ 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);
DBG("Wifi.save: len=%d vers=%d crc=0x%08lx\n", conf->length, conf->version, (long unsigned int) conf->crc);
if (map == 6 ) {
jshFlashErasePage(0xFD000);
jshFlashWrite(conf, 0xFD000, sizeof(flashBlock));
jshFlashErasePage( 0x200000);
jshFlashWrite(conf,0x200000, sizeof(flashBlock));
} else {
jshFlashErasePage(0x7B000);
jshFlashWrite(conf, 0x7B000, sizeof(flashBlock));
Expand All @@ -1210,11 +1210,11 @@ void jswrap_ESP8266_wifi_restore(void) {
os_memset(flashBlock, 0, sizeof(flashBlock));
uint32_t map = system_get_flash_size_map();
if (map == 6 ) {
jshFlashRead(flashBlock, 0xFD000, sizeof(flashBlock));
jshFlashRead(flashBlock, 0x200000, 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);
DBG("Wifi.restore: len=%d vers=%d crc=0x%08lx\n", conf->length, conf->version, (long unsigned int) conf->crc);
uint32_t crcRd = conf->crc;
conf->crc = 0;
uint32_t crcCalc = crc32((uint8_t*)flashBlock, sizeof(flashBlock));
Expand All @@ -1226,7 +1226,7 @@ void jswrap_ESP8266_wifi_restore(void) {
conf->phyMode > PHY_MODE_11N || conf->sleepType > MODEM_SLEEP_T ||
conf->mode > STATIONAP_MODE) {
DBG("Wifi.restore cannot restore: version read=%d exp=%d, crc read=0x%08lx cacl=0x%08lx\n",
conf->version, 24, crcRd, crcCalc);
conf->version, 24, (long unsigned int) crcRd, (long unsigned int) crcCalc);
wifi_set_phy_mode(PHY_MODE_11N);
wifi_set_opmode_current(SOFTAP_MODE);
return;
Expand Down Expand Up @@ -1558,7 +1558,7 @@ static void sntpSync(void *arg) {
DBG("NTP time: null\n");
} else {
if (ntpTime-sysTime != 0) {
DBG("NTP time: %ld delta=%ld %s\n", ntpTime, ntpTime-sysTime, sntp_get_real_time(ntpTime));
DBG("NTP time: %ld delta=%ld %s\n", (long unsigned int) ntpTime, (long unsigned int)ntpTime-sysTime, sntp_get_real_time(ntpTime));
}
jswrap_interactive_setTime((JsVarFloat)ntpTime);
}
Expand Down
7 changes: 7 additions & 0 deletions targets/esp8266/jshardware.c
Expand Up @@ -1266,6 +1266,13 @@ static void addFlashArea(JsVar *jsFreeFlash, uint32_t addr, uint32_t length) {
JsVar *jshFlashGetFree() {
JsVar *jsFreeFlash = jsvNewEmptyArray();
if (!jsFreeFlash) return 0;

uint32_t map = system_get_flash_size_map();
if ( map == 6 ) {
addFlashArea(jsFreeFlash, 0x300000, 0x300000-0x4000);
return jsFreeFlash;
}

// Area reserved for EEPROM
addFlashArea(jsFreeFlash, 0x77000, 0x1000);

Expand Down

0 comments on commit 81204d6

Please sign in to comment.