Skip to content

Commit ce07fd5

Browse files
Merge branch 'master' of https://github.com/esp8266/Arduino into gcc9.1
2 parents d2b4e4c + 5762712 commit ce07fd5

File tree

14 files changed

+491
-78
lines changed

14 files changed

+491
-78
lines changed

cores/esp8266/Crypto.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
THE SOFTWARE.
2424
*/
2525

26-
#include <bearssl/bearssl.h>
2726
#include "Crypto.h"
2827
#include <TypeConversion.h>
29-
28+
#include <bearssl/bearssl.h>
3029
#include <assert.h>
3130

3231
namespace TypeCast = experimental::TypeConversion;

cores/esp8266/Crypto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define __ESP8266_ARDUINO_CRYPTO_H__
2828

2929
#include <Arduino.h>
30+
#include <bearssl/bearssl_kdf.h>
3031

3132
namespace experimental
3233
{
@@ -745,8 +746,7 @@ struct HKDF
745746

746747
private:
747748

748-
// Use an opaque type to avoid #include <bearssl/bearssl.h> which drags the lib declarations into userland. The global scope prefix is required for compilation to succeed, it seems.
749-
::br_hkdf_context hkdfContext;
749+
br_hkdf_context hkdfContext;
750750
};
751751

752752

cores/esp8266/spiffs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ What spiffs does not:
4949
- Presently, it does not detect or handle bad blocks.
5050
- One configuration, one binary. There's no generic spiffs binary that handles all types of configurations.
5151

52+
## NOTICE
53+
54+
0.4.0 is under construction. This is a full rewrite and will change the underlying structure. Hence, it will not be compatible with earlier versions of the filesystem. The API is the same, with minor modifications. Some config flags will be removed (as they are mandatory in 0.4.0) and some features might fall away until 0.4.1. If you have any worries or questions, it can be discussed in issue [#179](https://github.com/pellepl/spiffs/issues/179)
5255

5356
## MORE INFO
5457

cores/esp8266/spiffs/spiffs_check.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,17 @@ static s32_t spiffs_delete_obj_lazy(spiffs *fs, spiffs_obj_id obj_id) {
163163
return SPIFFS_OK;
164164
}
165165
SPIFFS_CHECK_RES(res);
166-
u8_t flags = 0xff & ~SPIFFS_PH_FLAG_IXDELE;
166+
u8_t flags = 0xff;
167+
#if SPIFFS_NO_BLIND_WRITES
168+
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
169+
0, SPIFFS_PAGE_TO_PADDR(fs, objix_hdr_pix) + offsetof(spiffs_page_header, flags),
170+
sizeof(flags), &flags);
171+
SPIFFS_CHECK_RES(res);
172+
#endif
173+
flags &= ~SPIFFS_PH_FLAG_IXDELE;
167174
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_UPDT,
168175
0, SPIFFS_PAGE_TO_PADDR(fs, objix_hdr_pix) + offsetof(spiffs_page_header, flags),
169-
sizeof(u8_t),
170-
(u8_t *)&flags);
176+
sizeof(flags), &flags);
171177
return res;
172178
}
173179

@@ -425,10 +431,17 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
425431
// just finalize
426432
SPIFFS_CHECK_DBG("LU: FIXUP: unfinalized page is referred, finalizing\n");
427433
CHECK_CB(fs, SPIFFS_CHECK_LOOKUP, SPIFFS_CHECK_FIX_LOOKUP, p_hdr->obj_id, p_hdr->span_ix);
428-
u8_t flags = 0xff & ~SPIFFS_PH_FLAG_FINAL;
434+
u8_t flags = 0xff;
435+
#if SPIFFS_NO_BLIND_WRITES
436+
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_READ,
437+
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix) + offsetof(spiffs_page_header, flags),
438+
sizeof(flags), &flags);
439+
SPIFFS_CHECK_RES(res);
440+
#endif
441+
flags &= ~SPIFFS_PH_FLAG_FINAL;
429442
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT,
430443
0, SPIFFS_PAGE_TO_PADDR(fs, cur_pix) + offsetof(spiffs_page_header, flags),
431-
sizeof(u8_t), (u8_t*)&flags);
444+
sizeof(flags), &flags);
432445
}
433446
}
434447
}

cores/esp8266/spiffs/spiffs_config.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ typedef uint8_t u8_t;
326326
#define SPIFFS_IX_MAP 1
327327
#endif
328328

329+
// By default SPIFFS in some cases relies on the property of NOR flash that bits
330+
// cannot be set from 0 to 1 by writing and that controllers will ignore such
331+
// bit changes. This results in fewer reads as SPIFFS can in some cases perform
332+
// blind writes, with all bits set to 1 and only those it needs reset set to 0.
333+
// Most of the chips and controllers allow this behavior, so the default is to
334+
// use this technique. If your controller is one of the rare ones that don't,
335+
// turn this option on and SPIFFS will perform a read-modify-write instead.
336+
#ifndef SPIFFS_NO_BLIND_WRITES
337+
#define SPIFFS_NO_BLIND_WRITES 0
338+
#endif
339+
329340
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
330341
// in the api. This function will visualize all filesystem using given printf
331342
// function.
@@ -354,11 +365,20 @@ typedef uint8_t u8_t;
354365
#endif
355366
#endif
356367

368+
#ifndef SPIFFS_SECURE_ERASE
369+
#define SPIFFS_SECURE_ERASE 0
370+
#endif
371+
357372
// Types depending on configuration such as the amount of flash bytes
358373
// given to spiffs file system in total (spiffs_file_system_size),
359374
// the logical block size (log_block_size), and the logical page size
360375
// (log_page_size)
376+
//
377+
// Set SPIFFS_TYPES_OVERRIDE if you wish to have your own
378+
// definitions for these types (for example, if you want them
379+
// to be u32_t)
361380

381+
#ifndef SPIFFS_TYPES_OVERRIDE
362382
// Block index type. Make sure the size of this type can hold
363383
// the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
364384
typedef u16_t spiffs_block_ix;
@@ -373,5 +393,6 @@ typedef u16_t spiffs_obj_id;
373393
// hold the largest possible span index on the system -
374394
// i.e. (spiffs_file_system_size / log_page_size) - 1
375395
typedef u16_t spiffs_span_ix;
396+
#endif
376397

377398
#endif /* SPIFFS_CONFIG_H_ */

cores/esp8266/spiffs/spiffs_nucleus.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,6 @@ s32_t spiffs_page_delete(
879879
spiffs *fs,
880880
spiffs_page_ix pix) {
881881
s32_t res;
882-
spiffs_page_header hdr;
883-
hdr.flags = 0xff & ~(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_USED);
884882
// mark deleted entry in source object lookup
885883
spiffs_obj_id d_obj_id = SPIFFS_OBJ_ID_DELETED;
886884
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_DELE,
@@ -893,12 +891,29 @@ s32_t spiffs_page_delete(
893891
fs->stats_p_deleted++;
894892
fs->stats_p_allocated--;
895893

894+
#if SPIFFS_SECURE_ERASE
895+
// Secure erase
896+
unsigned char data[SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(spiffs_page_header)];
897+
bzero(data, sizeof(data));
898+
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_DELE,
899+
0,
900+
SPIFFS_PAGE_TO_PADDR(fs, pix) + sizeof(spiffs_page_header), sizeof(data), data);
901+
SPIFFS_CHECK_RES(res);
902+
#endif
903+
896904
// mark deleted in source page
905+
u8_t flags = 0xff;
906+
#if SPIFFS_NO_BLIND_WRITES
907+
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_READ,
908+
0, SPIFFS_PAGE_TO_PADDR(fs, pix) + offsetof(spiffs_page_header, flags),
909+
sizeof(flags), &flags);
910+
SPIFFS_CHECK_RES(res);
911+
#endif
912+
flags &= ~(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_USED);
897913
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_DELE,
898914
0,
899915
SPIFFS_PAGE_TO_PADDR(fs, pix) + offsetof(spiffs_page_header, flags),
900-
sizeof(u8_t),
901-
(u8_t *)&hdr.flags);
916+
sizeof(flags), &flags);
902917

903918
return res;
904919
}
@@ -2027,7 +2042,7 @@ s32_t spiffs_object_read(
20272042
// remaining data in page
20282043
len_to_read = MIN(len_to_read, SPIFFS_DATA_PAGE_SIZE(fs) - (cur_offset % SPIFFS_DATA_PAGE_SIZE(fs)));
20292044
// remaining data in file
2030-
len_to_read = MIN(len_to_read, fd->size);
2045+
len_to_read = MIN(len_to_read, fd->size - cur_offset);
20312046
SPIFFS_DBG("read: offset:" _SPIPRIi " rd:" _SPIPRIi " data spix:" _SPIPRIsp " is data_pix:" _SPIPRIpg " addr:" _SPIPRIad "\n", cur_offset, len_to_read, data_spix, data_pix,
20322047
(u32_t)(SPIFFS_PAGE_TO_PADDR(fs, data_pix) + sizeof(spiffs_page_header) + (cur_offset % SPIFFS_DATA_PAGE_SIZE(fs))));
20332048
if (len_to_read <= 0) {

cores/esp8266/spiffs/spiffs_nucleus.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ extern "C" {
147147

148148

149149

150-
#if defined(__GNUC__) || defined(__clang__)
151-
/* For GCC and clang */
150+
#if defined(__GNUC__) || defined(__clang__) || defined(__TI_COMPILER_VERSION__)
151+
/* For GCC, clang and TI compilers */
152152
#define SPIFFS_PACKED __attribute__((packed))
153153
#elif defined(__ICCARM__) || defined(__CC_ARM)
154154
/* For IAR ARM and Keil MDK-ARM compilers */
@@ -266,8 +266,8 @@ extern "C" {
266266
#define SPIFFS_FH_OFFS(fs, fh) ((fh) != 0 ? ((fh) + (fs)->cfg.fh_ix_offset) : 0)
267267
#define SPIFFS_FH_UNOFFS(fs, fh) ((fh) != 0 ? ((fh) - (fs)->cfg.fh_ix_offset) : 0)
268268
#else
269-
#define SPIFFS_FH_OFFS(fs, fh) (fh)
270-
#define SPIFFS_FH_UNOFFS(fs, fh) (fh)
269+
#define SPIFFS_FH_OFFS(fs, fh) ((spiffs_file)(fh))
270+
#define SPIFFS_FH_UNOFFS(fs, fh) ((spiffs_file)(fh))
271271
#endif
272272

273273

cores/esp8266/umm_malloc/umm_local.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ void ICACHE_FLASH_ATTR print_stats(int force);
4848

4949

5050
int ICACHE_FLASH_ATTR umm_info_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
51-
#define UMM_INFO_PRINTF(fmt, ...) umm_info_safe_printf_P(PSTR(fmt), ##__VA_ARGS__)
51+
#define UMM_INFO_PRINTF(fmt, ...) umm_info_safe_printf_P(PSTR4(fmt), ##__VA_ARGS__)
52+
// use PSTR4() instead of PSTR() to ensure 4-bytes alignment in Flash, whatever the default alignment of PSTR_ALIGN
5253

5354

5455
#endif
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
reuseConnectionV2.ino
3+
4+
Created on: 22.11.2015
5+
6+
This example reuses the http connection and also restores the connection if the connection is lost
7+
*/
8+
9+
10+
#include <ESP8266WiFi.h>
11+
#include <ESP8266WiFiMulti.h>
12+
#include <ESP8266HTTPClient.h>
13+
14+
#ifndef STASSID
15+
#define STASSID "your-ssid"
16+
#define STAPSK "your-password"
17+
#endif
18+
19+
ESP8266WiFiMulti WiFiMulti;
20+
21+
HTTPClient http;
22+
WiFiClient client;
23+
24+
void setup() {
25+
26+
Serial.begin(115200);
27+
// Serial.setDebugOutput(true);
28+
29+
Serial.println();
30+
Serial.println();
31+
Serial.println("Connecting to WiFi...");
32+
33+
WiFi.mode(WIFI_STA);
34+
WiFiMulti.addAP(STASSID, STAPSK);
35+
36+
// wait for WiFi connection
37+
while ((WiFiMulti.run() != WL_CONNECTED)) {
38+
Serial.write('.');
39+
delay(500);
40+
}
41+
Serial.println(" connected to WiFi");
42+
43+
// allow reuse (if server supports it)
44+
http.setReuse(true);
45+
46+
47+
http.begin(client, "http://jigsaw.w3.org/HTTP/connection.html");
48+
//http.begin(client, "jigsaw.w3.org", 80, "/HTTP/connection.html");
49+
}
50+
51+
int pass = 0;
52+
53+
void loop() {
54+
// First 10 loop()s, retrieve the URL
55+
if (pass < 10) {
56+
pass++;
57+
Serial.printf("Reuse connection example, GET url for the %d time\n", pass);
58+
int httpCode = http.GET();
59+
if (httpCode > 0) {
60+
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
61+
62+
// file found at server
63+
if (httpCode == HTTP_CODE_OK) {
64+
http.writeToStream(&Serial);
65+
}
66+
} else {
67+
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
68+
// Something went wrong with the connection, try to reconnect
69+
http.end();
70+
http.begin(client, "http://jigsaw.w3.org/HTTP/connection.html");
71+
//http.begin(client, "jigsaw.w3.org", 80, "/HTTP/connection.html");
72+
}
73+
74+
if (pass == 10) {
75+
http.end();
76+
Serial.println("Done testing");
77+
} else {
78+
Serial.println("\n\n\nWait 5 second...\n");
79+
delay(5000);
80+
}
81+
}
82+
}

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ void HTTPClient::disconnect(bool preserveClient)
457457
#endif
458458
}
459459
} else {
460+
if (!preserveClient && _client) { // Also destroy _client if not connected()
461+
_client = nullptr;
462+
}
463+
460464
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp is closed\n");
461465
}
462466
}
@@ -970,7 +974,9 @@ int HTTPClient::writeToStream(Stream * stream)
970974
return returnError(HTTPC_ERROR_NO_STREAM);
971975
}
972976

973-
if(!connected()) {
977+
// Only return error if not connected and no data available, because otherwise ::getString() will return an error instead of an empty
978+
// string when the server returned a http code 204 (no content)
979+
if(!connected() && _transferEncoding != HTTPC_TE_IDENTITY && _size > 0) {
974980
return returnError(HTTPC_ERROR_NOT_CONNECTED);
975981
}
976982

@@ -979,11 +985,13 @@ int HTTPClient::writeToStream(Stream * stream)
979985
int ret = 0;
980986

981987
if(_transferEncoding == HTTPC_TE_IDENTITY) {
982-
ret = writeToStreamDataBlock(stream, len);
988+
if(len > 0) {
989+
ret = writeToStreamDataBlock(stream, len);
983990

984-
// have we an error?
985-
if(ret < 0) {
986-
return returnError(ret);
991+
// have we an error?
992+
if(ret < 0) {
993+
return returnError(ret);
994+
}
987995
}
988996
} else if(_transferEncoding == HTTPC_TE_CHUNKED) {
989997
int size = 0;
@@ -1198,12 +1206,8 @@ bool HTTPClient::hasHeader(const char* name)
11981206
*/
11991207
bool HTTPClient::connect(void)
12001208
{
1201-
if(connected()) {
1202-
if(_reuse) {
1203-
DEBUG_HTTPCLIENT("[HTTP-Client] connect: already connected, reusing connection\n");
1204-
} else {
1205-
DEBUG_HTTPCLIENT("[HTTP-Client] connect: already connected, try reuse!\n");
1206-
}
1209+
if(_reuse && _canReuse && connected()) {
1210+
DEBUG_HTTPCLIENT("[HTTP-Client] connect: already connected, reusing connection\n");
12071211
while(_client->available() > 0) {
12081212
_client->read();
12091213
}
@@ -1334,22 +1338,21 @@ int HTTPClient::handleHeaderResponse()
13341338
while(connected()) {
13351339
size_t len = _client->available();
13361340
if(len > 0) {
1341+
int headerSeparator = -1;
13371342
String headerLine = _client->readStringUntil('\n');
13381343

13391344
lastDataTime = millis();
13401345

13411346
DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] RX: '%s'\n", headerLine.c_str());
13421347

13431348
if (headerLine.startsWith(F("HTTP/1."))) {
1344-
if (_canReuse) {
1345-
_canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0');
1346-
}
1347-
_returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
1348-
continue;
1349-
}
13501349

1351-
int headerSeparator = headerLine.indexOf(':');
1352-
if (headerSeparator > 0) {
1350+
constexpr auto httpVersionIdx = sizeof "HTTP/1." - 1;
1351+
_canReuse = _canReuse && (headerLine[httpVersionIdx] != '0');
1352+
_returnCode = headerLine.substring(httpVersionIdx + 2, headerLine.indexOf(' ', httpVersionIdx + 2)).toInt();
1353+
_canReuse = _canReuse && (_returnCode > 0) && (_returnCode < 500);
1354+
1355+
} else if ((headerSeparator = headerLine.indexOf(':')) > 0) {
13531356
String headerName = headerLine.substring(0, headerSeparator);
13541357
String headerValue = headerLine.substring(headerSeparator + 1);
13551358
headerValue.trim();

0 commit comments

Comments
 (0)