[PUYA] Add PUYA patch v3 to check if patch is applied

See: https://github.com/letscontrolit/ESPEasy/pull/2005#issuecomment-436442587
Made by @uzi18
This commit is contained in:
TD-er
2018-11-07 11:25:12 +01:00
parent f7c7d176f1
commit 19b59359e0
4 changed files with 84 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
PATCH=puya_v2.patch
PATCH=puya_v3.patch
for DIR in ~/.platformio/packages/framework-arduinoespressif8266*/; do
+61
View File
@@ -0,0 +1,61 @@
diff -urN 2.3.0.orig/cores/esp8266/Esp.cpp 2.3.0/cores/esp8266/Esp.cpp
--- 2.3.0.orig/cores/esp8266/Esp.cpp 2016-06-21 08:06:45.000000000 +0000
+++ 2.3.0/cores/esp8266/Esp.cpp 2018-11-06 22:48:55.371201979 +0000
@@ -507,11 +507,33 @@
return rc == 0;
}
+bool EspClass::flashIsPuya(){
+ return ((flash_chip_id & 0x000000ff) == 0x85) // 0x146085 PUYA
+}
+
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
- ets_isr_mask(FLASH_INT_MASK);
- int rc = spi_flash_write(offset, (uint32_t*) data, size);
- ets_isr_unmask(FLASH_INT_MASK);
- return rc == 0;
+ static uint32_t flash_chip_id = 0;
+
+ if (flash_chip_id == 0)
+ flash_chip_id = getFlashChipId();
+ ets_isr_mask(FLASH_INT_MASK);
+ int rc;
+ uint32_t* ptr = data;
+ if (flashIsPuya()) {
+ static uint32_t read_buf[SPI_FLASH_SEC_SIZE / 4];
+ rc = spi_flash_read(offset, read_buf, size);
+ if (rc != 0) {
+ ets_isr_unmask(FLASH_INT_MASK);
+ return false;
+ }
+ for (size_t i = 0; i < size / 4; ++i) {
+ read_buf[i] &= data[i];
+ }
+ ptr = read_buf;
+ }
+ rc = spi_flash_write(offset, ptr, size);
+ ets_isr_unmask(FLASH_INT_MASK);
+ return rc == 0;
}
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {
diff -urN 2.3.0.orig/cores/esp8266/Esp.h 2.3.0/cores/esp8266/Esp.h
--- 2.3.0.orig/cores/esp8266/Esp.h 2016-06-21 08:06:45.000000000 +0000
+++ 2.3.0/cores/esp8266/Esp.h 2018-11-06 22:49:47.711992085 +0000
@@ -23,6 +23,8 @@
#include <Arduino.h>
+#define PUYASUPPORT
+
/**
* AVR macros for WDT managment
*/
@@ -132,6 +134,7 @@
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
+ bool flashIsPuya();
uint32_t getSketchSize();
String getSketchMD5();
uint32_t getFreeSketchSpace();
+4
View File
@@ -1125,6 +1125,10 @@ String getSystemLibraryString() {
result += F(", LWIP: ");
result += getLWIPversion();
#endif
#ifdef PUYASUPPORT
result += F(" PUYA support");
#endif
return result;
}
+18 -9
View File
@@ -5863,15 +5863,24 @@ void handle_sysinfo() {
uint32_t flashChipId = ESP.getFlashChipId();
// Set to HEX may be something like 0x1640E0.
// Where manufacturer is 0xE0 and device is 0x4016.
TXBuffer += F("Vendor: ");
TXBuffer += formatToHex(flashChipId & 0xFF);
if ((flashChipId & 0x000000ff) == 0x85) { // 0x146085 PUYA
TXBuffer += F(" (PUYA)");
TXBuffer += F(HTML_SYMBOL_WARNING);
}
TXBuffer += F(" Device: ");
uint32_t flashDevice = (flashChipId & 0xFF00) | ((flashChipId >> 16) & 0xFF);
TXBuffer += formatToHex(flashDevice);
TXBuffer += F("Vendor: ");
TXBuffer += formatToHex(flashChipId & 0xFF);
#ifdef PUYASUPPORT
if (Esp.flashIsPuya()) {
TXBuffer += F(" (PUYA, supported)");
}
#else
if ((flashChipId & 0x000000ff) == 0x85) // 0x146085 PUYA
{
TXBuffer += F(" (PUYA");
TXBuffer += F(HTML_SYMBOL_WARNING);
TXBuffer += ')';
}
#endif
TXBuffer += F(" Device: ");
uint32_t flashDevice = (flashChipId & 0xFF00) | ((flashChipId >> 16) & 0xFF);
TXBuffer += formatToHex(flashDevice);
#endif
uint32_t realSize = getFlashRealSizeInBytes();
uint32_t ideSize = ESP.getFlashChipSize();