Skip to content

Commit ece9c86

Browse files
authored
Merge pull request esp8266#53 from esp8266/master
update
2 parents 25a4b5f + d1b70df commit ece9c86

File tree

4 files changed

+25
-33
lines changed

4 files changed

+25
-33
lines changed

cores/esp8266/Esp.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ uint32_t EspClass::getSketchSize() {
494494

495495
image_header_t image_header;
496496
uint32_t pos = APP_START_OFFSET;
497-
if (spi_flash_read(pos, (uint32_t*) &image_header, sizeof(image_header))) {
497+
if (spi_flash_read(pos, (uint32_t*) &image_header, sizeof(image_header)) != SPI_FLASH_RESULT_OK) {
498498
return 0;
499499
}
500500
pos += sizeof(image_header);
@@ -506,7 +506,7 @@ uint32_t EspClass::getSketchSize() {
506506
++section_index)
507507
{
508508
section_header_t section_header = {0, 0};
509-
if (spi_flash_read(pos, (uint32_t*) &section_header, sizeof(section_header))) {
509+
if (spi_flash_read(pos, (uint32_t*) &section_header, sizeof(section_header)) != SPI_FLASH_RESULT_OK) {
510510
return 0;
511511
}
512512
pos += sizeof(section_header);
@@ -579,24 +579,25 @@ bool EspClass::flashEraseSector(uint32_t sector) {
579579
#if PUYA_SUPPORT
580580
static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
581581
if (data == nullptr) {
582-
return 1; // SPI_FLASH_RESULT_ERR
582+
return SPI_FLASH_RESULT_ERR;
583583
}
584584
// PUYA flash chips need to read existing data, update in memory and write modified data again.
585585
static uint32_t *flash_write_puya_buf = nullptr;
586-
int rc = 0;
587-
uint32_t* ptr = data;
588586

589587
if (flash_write_puya_buf == nullptr) {
590588
flash_write_puya_buf = (uint32_t*) malloc(PUYA_BUFFER_SIZE);
591589
// No need to ever free this, since the flash chip will never change at runtime.
592590
if (flash_write_puya_buf == nullptr) {
593591
// Memory could not be allocated.
594-
return 1; // SPI_FLASH_RESULT_ERR
592+
return SPI_FLASH_RESULT_ERR;
595593
}
596594
}
595+
596+
SpiFlashOpResult rc = SPI_FLASH_RESULT_OK;
597+
uint32_t* ptr = data;
597598
size_t bytesLeft = size;
598599
uint32_t pos = offset;
599-
while (bytesLeft > 0 && rc == 0) {
600+
while (bytesLeft > 0 && rc == SPI_FLASH_RESULT_OK) {
600601
size_t bytesNow = bytesLeft;
601602
if (bytesNow > PUYA_BUFFER_SIZE) {
602603
bytesNow = PUYA_BUFFER_SIZE;
@@ -605,8 +606,8 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
605606
bytesLeft = 0;
606607
}
607608
rc = spi_flash_read(pos, flash_write_puya_buf, bytesNow);
608-
if (rc != 0) {
609-
return rc;
609+
if (rc != SPI_FLASH_RESULT_OK) {
610+
return (int)rc;
610611
}
611612
for (size_t i = 0; i < bytesNow / 4; ++i) {
612613
flash_write_puya_buf[i] &= *ptr;
@@ -615,12 +616,12 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
615616
rc = spi_flash_write(pos, flash_write_puya_buf, bytesNow);
616617
pos += bytesNow;
617618
}
618-
return rc;
619+
return (int)rc;
619620
}
620621
#endif
621622

622623
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
623-
int rc = 0;
624+
SpiFlashOpResult rc = SPI_FLASH_RESULT_OK;
624625
#if PUYA_SUPPORT
625626
if (getFlashChipVendorId() == SPI_FLASH_VENDOR_PUYA) {
626627
rc = spi_flash_write_puya(offset, data, size);
@@ -630,12 +631,12 @@ bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
630631
{
631632
rc = spi_flash_write(offset, data, size);
632633
}
633-
return rc == 0;
634+
return rc == SPI_FLASH_RESULT_OK;
634635
}
635636

636637
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {
637-
int rc = spi_flash_read(offset, (uint32_t*) data, size);
638-
return rc == 0;
638+
auto rc = spi_flash_read(offset, (uint32_t*) data, size);
639+
return rc == SPI_FLASH_RESULT_OK;
639640
}
640641

641642
String EspClass::getSketchMD5()

libraries/EEPROM/EEPROM.cpp

+7-18
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ void EEPROMClass::begin(size_t size) {
7171

7272
_size = size;
7373

74-
noInterrupts();
75-
auto ret = spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
76-
interrupts();
77-
if (ret != SPI_FLASH_RESULT_OK) {
78-
DEBUGV("EEPROMClass::begin spi_flash_read failed, %d\n", (int)ret);
74+
if (!ESP.flashRead(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size)) {
75+
DEBUGV("EEPROMClass::begin flash read failed\n");
7976
}
8077

8178
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
@@ -128,30 +125,22 @@ void EEPROMClass::write(int const address, uint8_t const value) {
128125
}
129126

130127
bool EEPROMClass::commit() {
131-
bool ret = false;
132128
if (!_size)
133129
return false;
134130
if(!_dirty)
135131
return true;
136132
if(!_data)
137133
return false;
138134

139-
noInterrupts();
140-
auto flashret = spi_flash_erase_sector(_sector);
141-
if (flashret == SPI_FLASH_RESULT_OK) {
142-
flashret = spi_flash_write(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
143-
if (flashret == SPI_FLASH_RESULT_OK) {
135+
if (ESP.flashEraseSector(_sector)) {
136+
if (ESP.flashWrite(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size)) {
144137
_dirty = false;
145-
ret = true;
138+
return true;
146139
}
147140
}
148-
interrupts();
149141

150-
if (flashret != SPI_FLASH_RESULT_OK) {
151-
DEBUGV("EEPROMClass::commit failed, %d\n", (int)flashret);
152-
}
153-
154-
return ret;
142+
DEBUGV("EEPROMClass::commit failed\n");
143+
return false;
155144
}
156145

157146
uint8_t * EEPROMClass::getDataPtr() {

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
263263
http.setTimeout(_httpClientTimeout);
264264
http.setFollowRedirects(_followRedirects);
265265
http.setUserAgent(F("ESP8266-http-Update"));
266+
http.addHeader(F("x-ESP8266-Chip-ID"), String(ESP.getChipId()));
266267
http.addHeader(F("x-ESP8266-STA-MAC"), WiFi.macAddress());
267268
http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress());
268269
http.addHeader(F("x-ESP8266-free-space"), String(ESP.getFreeSketchSpace()));

platform.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ tools.esptool.cmd={runtime.platform.path}/tools/python3/python3
137137
tools.esptool.network_cmd={runtime.platform.path}/tools/python3/python3
138138

139139
tools.esptool.upload.protocol=esp
140-
tools.esptool.upload.params.verbose=--trace
140+
# esptool.py --trace option is a debug option, not a verbose option
141+
tools.esptool.upload.params.verbose=
141142
tools.esptool.upload.params.quiet=
142143

143144
# First, potentially perform an erase or nothing

0 commit comments

Comments
 (0)