Skip to content

Commit e09e6e8

Browse files
authored
Merge branch 'master' into pr-dns-forwarder
2 parents ff5d79a + 32470fb commit e09e6e8

File tree

23 files changed

+149
-149
lines changed

23 files changed

+149
-149
lines changed

.github/workflows/pull-request.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ jobs:
154154
mod: 42 # Picked at random to give 4-5 builds and exit.
155155
rem: 13
156156
run: |
157-
sudo apt-get install python3-pip python3-setuptools
157+
sudo apt update
158+
sudo apt install python3-pip python3-setuptools
158159
PATH=/home/runner/.local/bin:$PATH bash ./tests/platformio.sh
159160
160161
@@ -174,7 +175,8 @@ jobs:
174175
TRAVIS_BUILD_DIR: ${{ github.workspace }}
175176
TRAVIS_TAG: ${{ github.ref }}
176177
run: |
177-
sudo apt-get install valgrind lcov
178+
sudo apt update
179+
sudo apt install valgrind lcov
178180
bash ./tests/ci/host_test.sh
179181
180182
@@ -194,7 +196,8 @@ jobs:
194196
TRAVIS_BUILD_DIR: ${{ github.workspace }}
195197
TRAVIS_TAG: ${{ github.ref }}
196198
run: |
197-
sudo apt-get install python3-pip python3-setuptools
199+
sudo apt update
200+
sudo apt install python3-pip python3-setuptools
198201
# GitHub CI installs pip3 and setuptools outside the path.
199202
# Update the path to include them and run.
200203
PATH=/home/runner/.local/bin:$PATH pip3 install --user -r doc/requirements.txt
@@ -217,7 +220,8 @@ jobs:
217220
TRAVIS_BUILD_DIR: ${{ github.workspace }}
218221
TRAVIS_TAG: ${{ github.ref }}
219222
run: |
220-
sudo apt-get install astyle
223+
sudo apt update
224+
sudo apt install astyle
221225
bash ./tests/ci/style_check.sh
222226
223227

bootloaders/eboot/eboot.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ int copy_raw(const uint32_t src_addr,
159159
gzip = true;
160160
}
161161
while (left > 0) {
162-
if (!verify) {
163-
if (SPIEraseSector(daddr/buffer_size)) {
164-
return 2;
165-
}
166-
}
167162
if (!gzip) {
168163
if (SPIRead(saddr, buffer, buffer_size)) {
169164
return 3;
@@ -190,8 +185,25 @@ int copy_raw(const uint32_t src_addr,
190185
return 9;
191186
}
192187
} else {
193-
if (SPIWrite(daddr, buffer, buffer_size)) {
194-
return 4;
188+
// Special treatment for address 0 (bootloader). Only erase and
189+
// rewrite if the data is different (i.e. very rarely).
190+
bool skip = false;
191+
if (daddr == 0) {
192+
if (SPIRead(daddr, buffer2, buffer_size)) {
193+
return 4;
194+
}
195+
if (!memcmp(buffer2, buffer, buffer_size)) {
196+
ets_putc('B'); // Note we skipped the bootloader in output
197+
skip = true; // And skip erase/write
198+
}
199+
}
200+
if (!skip) {
201+
if (SPIEraseSector(daddr/buffer_size)) {
202+
return 2;
203+
}
204+
if (SPIWrite(daddr, buffer, buffer_size)) {
205+
return 4;
206+
}
195207
}
196208
}
197209
saddr += buffer_size;

bootloaders/eboot/eboot.elf

432 Bytes
Binary file not shown.

cores/esp8266/IPAddress.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ IPAddress::IPAddress() {
3232
}
3333

3434
bool IPAddress::isSet () const {
35-
return !ip_addr_isany(&_ip);
35+
return !ip_addr_isany(&_ip) && ((*this) != IPADDR_NONE);
3636
}
3737

3838
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) {
@@ -183,6 +183,10 @@ bool IPAddress::isValid(const char* arg) {
183183
const IPAddress INADDR_ANY; // generic "0.0.0.0" for IPv4 & IPv6
184184
const IPAddress INADDR_NONE(255,255,255,255);
185185

186+
void IPAddress::clear() {
187+
(*this) = INADDR_ANY;
188+
}
189+
186190
/**************************************/
187191

188192
#if LWIP_IPV6

cores/esp8266/IPAddress.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class IPAddress: public Printable {
125125
virtual size_t printTo(Print& p) const;
126126
String toString() const;
127127

128+
void clear();
129+
128130
/*
129131
check if input string(arg) is a valid IPV4 address or not.
130132
return true on valid.

cores/esp8266/Updater.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ bool UpdaterClass::end(bool evenIfRemaining){
282282
return false;
283283
}
284284
free(sig);
285+
_size = binSize; // Adjust size to remove signature, not part of bin payload
286+
285287
#ifdef DEBUG_UPDATER
286288
DEBUG_UPDATER.printf_P(PSTR("[Updater] Signature matches\n"));
287289
#endif

cores/esp8266/coredecls.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ extern "C" {
1212
#include <stdint.h>
1313
#include <cont.h> // g_pcont declaration
1414

15-
extern bool timeshift64_is_set;
16-
extern uint32_t sntp_real_timestamp;
17-
1815
bool can_yield();
1916
void esp_yield();
2017
void esp_schedule();

cores/esp8266/sntp-lwip2.cpp

Lines changed: 0 additions & 93 deletions
This file was deleted.

cores/esp8266/sntp-lwip2.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

cores/esp8266/time.cpp

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@
1414
* License along with this library; if not, write to the Free Software
1515
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1616
*
17+
* reworked for newlib and lwIP-v2:
18+
* time source is SNTP/settimeofday()
19+
* system time is micros64() / NONOS-SDK's system_get_time()
20+
* synchronisation of the two through timeshift64
1721
*/
1822

1923
#include <stdlib.h>
2024
#include <../include/time.h> // See issue #6714
2125
#include <sys/time.h>
2226
#include <sys/reent.h>
23-
#include "sntp.h"
24-
#include "coredecls.h"
27+
#include <errno.h>
2528

26-
#include <Arduino.h> // configTime()
29+
#include <sntp.h> // nonos-sdk
30+
#include <coredecls.h>
31+
#include <Schedule.h>
2732

28-
#include "sntp-lwip2.h"
33+
#include <Arduino.h> // configTime()
2934

3035
extern "C" {
3136

@@ -42,16 +47,11 @@ extern struct tm* sntp_localtime(const time_t *clock);
4247
extern uint64_t micros64();
4348
extern void sntp_set_daylight(int daylight);
4449

45-
// time gap in seconds from 01.01.1900 (NTP time) to 01.01.1970 (UNIX time)
46-
#define DIFF1900TO1970 2208988800UL
47-
48-
bool timeshift64_is_set = false;
4950
static uint64_t timeshift64 = 0;
5051

5152
void tune_timeshift64 (uint64_t now_us)
5253
{
5354
timeshift64 = now_us - micros64();
54-
timeshift64_is_set = true;
5555
}
5656

5757
static void setServer(int id, const char* name_or_ip)
@@ -73,7 +73,8 @@ int clock_gettime(clockid_t unused, struct timespec *tp)
7373
return 0;
7474
}
7575

76-
// backport Espressif api
76+
///////////////////////////////////////////
77+
// backport legacy nonos-sdk Espressif api
7778

7879
bool sntp_set_timezone_in_seconds (int32_t timezone_sec)
7980
{
@@ -93,16 +94,20 @@ char* sntp_get_real_time(time_t t)
9394

9495
uint32 sntp_get_current_timestamp()
9596
{
96-
return sntp_real_timestamp;
97+
return time(nullptr);
9798
}
9899

100+
// backport legacy nonos-sdk Espressif api
101+
///////////////////////////////////////////
102+
99103
time_t time(time_t * t)
100104
{
105+
time_t currentTime_s = (micros64() + timeshift64) / 1000000ULL;
101106
if (t)
102107
{
103-
*t = sntp_real_timestamp;
108+
*t = currentTime_s;
104109
}
105-
return sntp_real_timestamp;
110+
return currentTime_s;
106111
}
107112

108113
int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
@@ -111,8 +116,6 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
111116
(void) tzp;
112117
if (tp)
113118
{
114-
if (!timeshift64_is_set)
115-
tune_timeshift64(sntp_real_timestamp * 1000000ULL);
116119
uint64_t currentTime_us = timeshift64 + micros64();
117120
tp->tv_sec = currentTime_us / 1000000ULL;
118121
tp->tv_usec = currentTime_us % 1000000ULL;
@@ -146,7 +149,7 @@ void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, c
146149
newlib inspection and internal structure hacking
147150
(no sprintf, no sscanf, -7584 flash bytes):
148151
149-
***/
152+
*** hack starts here: ***/
150153

151154
static char gmt[] = "GMT";
152155

@@ -169,12 +172,12 @@ void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, c
169172
tzr->offset = -_timezone;
170173
}
171174

175+
/*** end of hack ***/
176+
172177
// sntp servers
173178
setServer(0, server1);
174179
setServer(1, server2);
175180
setServer(2, server3);
176-
177-
/*** end of posix replacement ***/
178181
}
179182

180183
void setTZ(const char* tz){
@@ -197,3 +200,35 @@ void configTime(const char* tz, const char* server1, const char* server2, const
197200
sntp_init();
198201
}
199202

203+
static TrivialCB _settimeofday_cb;
204+
205+
void settimeofday_cb (TrivialCB&& cb)
206+
{
207+
_settimeofday_cb = std::move(cb);
208+
}
209+
210+
void settimeofday_cb (const TrivialCB& cb)
211+
{
212+
_settimeofday_cb = cb;
213+
}
214+
215+
extern "C" {
216+
217+
#include <lwip/apps/sntp.h>
218+
219+
int settimeofday(const struct timeval* tv, const struct timezone* tz)
220+
{
221+
if (tz || !tv)
222+
// tz is obsolete (cf. man settimeofday)
223+
return EINVAL;
224+
225+
// reset time subsystem
226+
tune_timeshift64(tv->tv_sec * 1000000ULL + tv->tv_usec);
227+
228+
if (_settimeofday_cb)
229+
schedule_recurrent_function_us([](){ _settimeofday_cb(); return false; }, 0);
230+
231+
return 0;
232+
}
233+
234+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy