Skip to content

Commit afff569

Browse files
Merge branch 'master' of https://github.com/esp8266/Arduino into gcc9.1
2 parents 4ffe519 + db75d2c commit afff569

File tree

19 files changed

+151
-48
lines changed

19 files changed

+151
-48
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ Also known as latest git or master branch.
4848

4949
### Using PlatformIO
5050

51-
[PlatformIO](https://platformio.org?utm_source=github&utm_medium=arduino-esp8266) is an open source ecosystem for IoT
51+
[PlatformIO](https://platformio.org?utm_source=arduino-esp8266) is an open source ecosystem for IoT
5252
development with a cross-platform build system, a library manager, and full support
5353
for Espressif (ESP8266) development. It works on the following popular host operating systems: macOS, Windows,
5454
Linux 32/64, and Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard).
5555

56-
- [What is PlatformIO?](https://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=github&utm_medium=arduino-esp8266)
57-
- [PlatformIO IDE](https://platformio.org/platformio-ide?utm_source=github&utm_medium=arduino-esp8266)
58-
- [PlatformIO Core](https://docs.platformio.org/en/latest/core.html?utm_source=github&utm_medium=arduino-esp8266) (command line tool)
59-
- [Advanced usage](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=github&utm_medium=arduino-esp8266) -
56+
- [What is PlatformIO?](https://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=arduino-esp8266)
57+
- [PlatformIO IDE](https://platformio.org/platformio-ide?utm_source=arduino-esp8266)
58+
- [PlatformIO Core](https://docs.platformio.org/en/latest/core.html?utm_source=arduino-esp8266) (command line tool)
59+
- [Advanced usage](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266) -
6060
custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version
61-
- [Integration with Cloud and Standalone IDEs](https://docs.platformio.org/en/latest/ide.html?utm_source=github&utm_medium=arduino-esp8266) -
61+
- [Integration with Cloud and Standalone IDEs](https://docs.platformio.org/en/latest/ide.html?utm_source=arduino-esp8266) -
6262
Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode
63-
- [Project Examples](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=github&utm_medium=arduino-esp8266#examples)
63+
- [Project Examples](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266#examples)
6464

6565
### Building with make
6666

bootloaders/eboot/eboot.elf

4 Bytes
Binary file not shown.

cores/esp8266/StackThunk.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include <stdint.h>
2828
#include <stdlib.h>
29+
#include <stdio.h>
30+
#include "pgmspace.h"
31+
#include "debug.h"
2932
#include "StackThunk.h"
3033
#include <ets_sys.h>
3134

@@ -46,6 +49,11 @@ void stack_thunk_add_ref()
4649
stack_thunk_refcnt++;
4750
if (stack_thunk_refcnt == 1) {
4851
stack_thunk_ptr = (uint32_t *)malloc(_stackSize * sizeof(uint32_t));
52+
if (!stack_thunk_ptr) {
53+
// This is a fatal error, stop the sketch
54+
DEBUGV("Unable to allocate BearSSL stack\n");
55+
abort();
56+
}
4957
stack_thunk_top = stack_thunk_ptr + _stackSize - 1;
5058
stack_thunk_save = NULL;
5159
stack_thunk_repaint();

cores/esp8266/Updater.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Updater.h"
22
#include "eboot_command.h"
33
#include <esp8266_peri.h>
4+
#include "StackThunk.h"
45

56
//#define DEBUG_UPDATER Serial
67

@@ -40,6 +41,14 @@ UpdaterClass::UpdaterClass()
4041
{
4142
#if ARDUINO_SIGNING
4243
installSignature(&esp8266::updaterSigningHash, &esp8266::updaterSigningVerifier);
44+
stack_thunk_add_ref();
45+
#endif
46+
}
47+
48+
UpdaterClass::~UpdaterClass()
49+
{
50+
#if ARDUINO_SIGNING
51+
stack_thunk_del_ref();
4352
#endif
4453
}
4554

@@ -199,14 +208,14 @@ bool UpdaterClass::end(bool evenIfRemaining){
199208
#ifdef DEBUG_UPDATER
200209
DEBUG_UPDATER.println(F("no update"));
201210
#endif
211+
_reset();
202212
return false;
203213
}
204214

205215
if(hasError() || (!isFinished() && !evenIfRemaining)){
206216
#ifdef DEBUG_UPDATER
207217
DEBUG_UPDATER.printf_P(PSTR("premature end: res:%u, pos:%zu/%zu\n"), getError(), progress(), _size);
208218
#endif
209-
210219
_reset();
211220
return false;
212221
}
@@ -226,6 +235,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
226235
#endif
227236
if (sigLen != _verify->length()) {
228237
_setError(UPDATE_ERROR_SIGN);
238+
_reset();
229239
return false;
230240
}
231241

@@ -251,6 +261,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
251261
uint8_t *sig = (uint8_t*)malloc(sigLen);
252262
if (!sig) {
253263
_setError(UPDATE_ERROR_SIGN);
264+
_reset();
254265
return false;
255266
}
256267
ESP.flashRead(_startAddress + binSize, (uint32_t *)sig, sigLen);
@@ -262,9 +273,12 @@ bool UpdaterClass::end(bool evenIfRemaining){
262273
DEBUG_UPDATER.printf("\n");
263274
#endif
264275
if (!_verify->verify(_hash, (void *)sig, sigLen)) {
276+
free(sig);
265277
_setError(UPDATE_ERROR_SIGN);
278+
_reset();
266279
return false;
267280
}
281+
free(sig);
268282
#ifdef DEBUG_UPDATER
269283
DEBUG_UPDATER.printf_P(PSTR("[Updater] Signature matches\n"));
270284
#endif

cores/esp8266/Updater.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class UpdaterClass {
5353
typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;
5454

5555
UpdaterClass();
56+
~UpdaterClass();
5657

5758
/* Optionally add a cryptographic signature verification hash and method */
5859
void installSignature(UpdaterHashClass *hash, UpdaterVerifyClass *verify) { _hash = hash; _verify = verify; }

doc/installing.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,20 @@ Instructions - Other OS
230230
cd hardware\esp8266com\esp8266
231231
git status
232232
git pull
233+
234+
Using PlatformIO
235+
----------------
236+
237+
`PlatformIO <https://platformio.org?utm_source=arduino-esp8266>`__
238+
is an open source ecosystem for IoT development with a cross-platform
239+
build system, a library manager, and full support for Espressif
240+
(ESP8266) development. It works on the following popular host operating
241+
systems: macOS, Windows, Linux 32/64, and Linux ARM (like Raspberry Pi,
242+
BeagleBone, CubieBoard).
243+
244+
- `What is PlatformIO? <https://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=arduino-esp8266>`__
245+
- `PlatformIO IDE <https://platformio.org/platformio-ide?utm_source=arduino-esp8266>`__
246+
- `PlatformIO Core <https://docs.platformio.org/en/latest/core.html?utm_source=arduino-esp8266>`__ (command line tool)
247+
- `Advanced usage <https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266>`__ - custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version
248+
- `Integration with Cloud and Standalone IDEs <https://docs.platformio.org/en/latest/ide.html?utm_source=arduino-esp8266>`__ - Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode
249+
- `Project Examples <https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266#examples>`__

libraries/ESP8266SSDP/ESP8266SSDP.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static const char _ssdp_notify_template[] PROGMEM =
6969

7070
static const char _ssdp_packet_template[] PROGMEM =
7171
"%s" // _ssdp_response_template / _ssdp_notify_template
72-
"CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
72+
"CACHE-CONTROL: max-age=%u\r\n" // _interval
7373
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
7474
"USN: %s\r\n" // _uuid
7575
"%s: %s\r\n" // "NT" or "ST", _deviceType
@@ -130,6 +130,7 @@ SSDPClass::SSDPClass() :
130130
_timer(0),
131131
_port(80),
132132
_ttl(SSDP_MULTICAST_TTL),
133+
_interval(SSDP_INTERVAL),
133134
_respondToAddr(0,0,0,0),
134135
_respondToPort(0),
135136
_pending(false),
@@ -241,7 +242,7 @@ void SSDPClass::_send(ssdp_method_t method) {
241242
int len = snprintf_P(buffer, sizeof(buffer),
242243
_ssdp_packet_template,
243244
valueBuffer,
244-
SSDP_INTERVAL,
245+
_interval,
245246
_modelName,
246247
_modelNumber,
247248
_uuid,
@@ -428,7 +429,7 @@ void SSDPClass::_update() {
428429
if (_pending && (millis() - _process_time) > _delay) {
429430
_pending = false; _delay = 0;
430431
_send(NONE);
431-
} else if(_notify_time == 0 || (millis() - _notify_time) > (SSDP_INTERVAL * 1000L)){
432+
} else if(_notify_time == 0 || (millis() - _notify_time) > (_interval * 1000L)){
432433
_notify_time = millis();
433434
_st_is_uuid = false;
434435
_send(NOTIFY);
@@ -493,11 +494,14 @@ void SSDPClass::setManufacturerURL(const char *url) {
493494
strlcpy(_manufacturerURL, url, sizeof(_manufacturerURL));
494495
}
495496

496-
497497
void SSDPClass::setTTL(const uint8_t ttl) {
498498
_ttl = ttl;
499499
}
500500

501+
void SSDPClass::setInterval(uint32_t interval) {
502+
_interval = interval;
503+
}
504+
501505
void SSDPClass::_onTimerStatic(SSDPClass* self) {
502506
self->_update();
503507
}

libraries/ESP8266SSDP/ESP8266SSDP.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class SSDPClass{
7171
void setUUID(const String& uuid) { setUUID(uuid.c_str()); }
7272
void setUUID(const char *uuid);
7373

74-
void setName(const String& name) { setName(name.c_str()); }
74+
void setName(const String& name) { setName(name.c_str()); }
7575
void setName(const char *name);
7676
void setURL(const String& url) { setURL(url.c_str()); }
7777
void setURL(const char *url);
7878
void setSchemaURL(const String& url) { setSchemaURL(url.c_str()); }
7979
void setSchemaURL(const char *url);
80-
void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); }
80+
void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); }
8181
void setSerialNumber(const char *serialNumber);
8282
void setSerialNumber(const uint32_t serialNumber);
8383
void setModelName(const String& name) { setModelName(name.c_str()); }
@@ -92,6 +92,7 @@ class SSDPClass{
9292
void setManufacturerURL(const char *url);
9393
void setHTTPPort(uint16_t port);
9494
void setTTL(uint8_t ttl);
95+
void setInterval(uint32_t interval);
9596

9697
protected:
9798
void _send(ssdp_method_t method);
@@ -104,6 +105,7 @@ class SSDPClass{
104105
SSDPTimer* _timer;
105106
uint16_t _port;
106107
uint8_t _ttl;
108+
uint32_t _interval;
107109

108110
IPAddress _respondToAddr;
109111
uint16_t _respondToPort;

libraries/ESP8266WiFi/src/BearSSLHelpers.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,9 @@ uint32_t SigningVerifier::length()
870870
}
871871
}
872872

873-
bool SigningVerifier::verify(UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) {
874-
if (!_pubKey || !hash || !signature || signatureLen != length()) return false;
875-
873+
// We need to use the 2nd stack to do a verification, so do the thunk
874+
// directly inside the class function for ease of use.
875+
extern "C" bool SigningVerifier_verify(PublicKey *_pubKey, UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) {
876876
if (_pubKey->isRSA()) {
877877
bool ret;
878878
unsigned char vrf[hash->len()];
@@ -890,6 +890,20 @@ bool SigningVerifier::verify(UpdaterHashClass *hash, const void *signature, uint
890890
}
891891
};
892892

893+
#if !CORE_MOCK
894+
make_stack_thunk(SigningVerifier_verify);
895+
extern "C" bool thunk_SigningVerifier_verify(PublicKey *_pubKey, UpdaterHashClass *hash, const void *signature, uint32_t signatureLen);
896+
#endif
897+
898+
bool SigningVerifier::verify(UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) {
899+
if (!_pubKey || !hash || !signature || signatureLen != length()) return false;
900+
#if !CORE_MOCK
901+
return thunk_SigningVerifier_verify(_pubKey, hash, signature, signatureLen);
902+
#else
903+
return SigningVerifier_verify(_pubKey, hash, signature, signatureLen);
904+
#endif
905+
}
906+
893907
#if !CORE_MOCK
894908

895909
// Second stack thunked helpers

0 commit comments

Comments
 (0)