Skip to content

Commit 7089b8c

Browse files
Merge branch 'master' into pgmspace_to_libc
2 parents 912e883 + a501d3c commit 7089b8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4360
-205
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
sudo: false
21
language: bash
32
os: linux
43
dist: trusty

bootloaders/eboot/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ AR := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-ar
1717
LD := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
1818
OBJDUMP := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-objdump
1919

20-
20+
INC += -I../../tools/sdk/include
2121
CFLAGS += -std=gnu99
2222

2323
CFLAGS += -O0 -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals
2424

25+
CFLAGS += $(INC)
26+
2527
LDFLAGS += -nostdlib -Wl,--no-check-sections -umain
2628

2729
LD_SCRIPT := -Teboot.ld

bootloaders/eboot/eboot.elf

24 Bytes
Binary file not shown.

bootloaders/eboot/flash.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
#ifndef FLASH_H
99
#define FLASH_H
1010

11+
12+
/* The geometry defines are placed in the sdk. The .h was factored out for reuse by eboot here.
13+
* Beware: this means that eboot has an external dependency.
14+
* The following .h is placed in tools/sdk/includes
15+
*/
16+
#include <spi_flash_geometry.h>
17+
1118
int SPIEraseBlock(uint32_t block);
1219
int SPIEraseSector(uint32_t sector);
1320
int SPIRead(uint32_t addr, void *dest, size_t size);
1421
int SPIWrite(uint32_t addr, void *src, size_t size);
1522
int SPIEraseAreaEx(const uint32_t start, const uint32_t size);
1623

17-
#define FLASH_SECTOR_SIZE 0x1000
18-
#define FLASH_BLOCK_SIZE 0x10000
19-
#define APP_START_OFFSET 0x1000
2024

2125
typedef struct {
2226
unsigned char magic;
@@ -25,7 +29,7 @@ typedef struct {
2529
/* SPI Flash Interface (0 = QIO, 1 = QOUT, 2 = DIO, 0x3 = DOUT) */
2630
unsigned char flash_mode;
2731

28-
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M,
32+
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M, 8 = 8M, 9 = 16M
2933
Low four bits: 0 = 40MHz, 1= 26MHz, 2 = 20MHz, 0xf = 80MHz */
3034
unsigned char flash_size_freq;
3135

cores/esp8266/Esp.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,43 @@ uint64_t EspClass::deepSleepMax()
132132

133133
}
134134

135+
/*
136+
Layout of RTC Memory is as follows:
137+
Ref: Espressif doc 2C-ESP8266_Non_OS_SDK_API_Reference, section 3.3.23 (system_rtc_mem_write)
138+
139+
|<------system data (256 bytes)------->|<-----------------user data (512 bytes)--------------->|
140+
141+
SDK function signature:
142+
bool system_rtc_mem_read (
143+
uint32 des_addr,
144+
void * src_addr,
145+
uint32 save_size
146+
)
147+
148+
The system data section can't be used by the user, so:
149+
des_addr must be >=64 (i.e.: 256/4) and <192 (i.e.: 768/4)
150+
src_addr is a pointer to data
151+
save_size is the number of bytes to write
152+
153+
For the method interface:
154+
offset is the user block number (block size is 4 bytes) must be >= 0 and <128
155+
data is a pointer to data, 4-byte aligned
156+
size is number of bytes in the block pointed to by data
157+
158+
Same for write
159+
160+
Note: If the Updater class is in play, e.g.: the application uses OTA, the eboot
161+
command will be stored into the first 128 bytes of user data, then it will be
162+
retrieved by eboot on boot. That means that user data present there will be lost.
163+
Ref:
164+
- discussion in PR #5330.
165+
- https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
166+
- Arduino/bootloaders/eboot/eboot_command.h RTC_MEM definition
167+
*/
168+
135169
bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
136170
{
137-
if (size + offset > 512) {
171+
if (offset * 4 + size > 512 || size == 0) {
138172
return false;
139173
} else {
140174
return system_rtc_mem_read(64 + offset, data, size);
@@ -143,13 +177,15 @@ bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
143177

144178
bool EspClass::rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size)
145179
{
146-
if (size + offset > 512) {
180+
if (offset * 4 + size > 512 || size == 0) {
147181
return false;
148182
} else {
149183
return system_rtc_mem_write(64 + offset, data, size);
150184
}
151185
}
152186

187+
188+
153189
extern "C" void __real_system_restart_local();
154190
void EspClass::reset(void)
155191
{
@@ -165,6 +201,7 @@ void EspClass::restart(void)
165201
uint16_t EspClass::getVcc(void)
166202
{
167203
InterruptLock lock;
204+
(void)lock;
168205
return system_get_vdd33();
169206
}
170207

cores/esp8266/FSImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class DirImpl {
6262

6363
class FSImpl {
6464
public:
65+
virtual ~FSImpl () { }
6566
virtual bool begin() = 0;
6667
virtual void end() = 0;
6768
virtual bool format() = 0;

cores/esp8266/MD5Builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class MD5Builder {
3434
void add(const uint8_t * data, const uint16_t len);
3535
void add(const char * data){ add((const uint8_t*)data, strlen(data)); }
3636
void add(char * data){ add((const char*)data); }
37-
void add(const String data){ add(data.c_str()); }
37+
void add(const String& data){ add(data.c_str()); }
3838
void addHexString(const char * data);
3939
void addHexString(char * data){ addHexString((const char*)data); }
40-
void addHexString(const String data){ addHexString(data.c_str()); }
40+
void addHexString(const String& data){ addHexString(data.c_str()); }
4141
bool addStream(Stream & stream, const size_t maxLen);
4242
void calculate(void);
4343
void getBytes(uint8_t * output);

cores/esp8266/PolledTimeout.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#ifndef __POLLEDTIMING_H__
2+
#define __POLLEDTIMING_H__
3+
4+
5+
/*
6+
PolledTimeout.h - Encapsulation of a polled Timeout
7+
8+
Copyright (c) 2018 Daniel Salazar. All rights reserved.
9+
This file is part of the esp8266 core for Arduino environment.
10+
11+
This library is free software; you can redistribute it and/or
12+
modify it under the terms of the GNU Lesser General Public
13+
License as published by the Free Software Foundation; either
14+
version 2.1 of the License, or (at your option) any later version.
15+
16+
This library is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
Lesser General Public License for more details.
20+
21+
You should have received a copy of the GNU Lesser General Public
22+
License along with this library; if not, write to the Free Software
23+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24+
*/
25+
26+
27+
28+
namespace esp8266
29+
{
30+
31+
32+
namespace polledTimeout
33+
{
34+
35+
namespace YieldPolicy
36+
{
37+
38+
struct DoNothing
39+
{
40+
static void execute() {}
41+
};
42+
43+
struct YieldOrSkip
44+
{
45+
static void execute() {delay(0);}
46+
};
47+
48+
} //YieldPolicy
49+
50+
51+
template <bool PeriodicT, typename YieldPolicyT = YieldPolicy::DoNothing>
52+
class timeoutTemplate
53+
{
54+
public:
55+
using timeType = decltype(millis());
56+
57+
timeoutTemplate(timeType timeout)
58+
: _timeout(timeout), _start(millis())
59+
{}
60+
61+
bool expired()
62+
{
63+
YieldPolicyT::execute(); //in case of DoNothing: gets optimized away
64+
if(PeriodicT) //in case of false: gets optimized away
65+
return expiredRetrigger();
66+
return expiredOneShot();
67+
}
68+
69+
operator bool()
70+
{
71+
return expired();
72+
}
73+
74+
void reset(timeType newTimeout)
75+
{
76+
_timeout = newTimeout;
77+
reset();
78+
}
79+
80+
void reset()
81+
{
82+
_start = millis();
83+
}
84+
85+
protected:
86+
bool checkExpired(timeType t) const
87+
{
88+
return (t - _start) >= _timeout;
89+
}
90+
91+
bool expiredRetrigger()
92+
{
93+
timeType current = millis();
94+
if(checkExpired(current))
95+
{
96+
unsigned long n = (current - _start) / _timeout; //how many _timeouts periods have elapsed, will usually be 1 (current - _start >= _timeout)
97+
_start += n * _timeout;
98+
return true;
99+
}
100+
return false;
101+
}
102+
103+
bool expiredOneShot() const
104+
{
105+
return checkExpired(millis());
106+
}
107+
108+
timeType _timeout;
109+
timeType _start;
110+
};
111+
112+
using oneShot = polledTimeout::timeoutTemplate<false>;
113+
using periodic = polledTimeout::timeoutTemplate<true>;
114+
115+
} //polledTimeout
116+
117+
118+
/* A 1-shot timeout that auto-yields when in CONT can be built as follows:
119+
* using oneShotYield = esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::YieldOrSkip>;
120+
*
121+
* Other policies can be implemented by the user, e.g.: simple yield that panics in SYS, and the polledTimeout types built as needed as shown above, without modifying this file.
122+
*/
123+
124+
}//esp8266
125+
126+
#endif

cores/esp8266/Updater.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "Updater.h"
22
#include "Arduino.h"
33
#include "eboot_command.h"
4-
#include "interrupts.h"
5-
#include "esp8266_peri.h"
4+
#include <interrupts.h>
5+
#include <esp8266_peri.h>
66

77
//#define DEBUG_UPDATER Serial
88

@@ -84,21 +84,21 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
8484

8585
wifi_set_sleep_type(NONE_SLEEP_T);
8686

87-
uint32_t updateStartAddress = 0;
87+
uintptr_t updateStartAddress = 0;
8888
if (command == U_FLASH) {
8989
//size of current sketch rounded to a sector
90-
uint32_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
90+
size_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
9191
//address of the end of the space available for sketch and update
92-
uint32_t updateEndAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
92+
uintptr_t updateEndAddress = (uintptr_t)&_SPIFFS_start - 0x40200000;
9393
//size of the update rounded to a sector
94-
uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
94+
size_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
9595
//address where we will start writing the update
9696
updateStartAddress = (updateEndAddress > roundedSize)? (updateEndAddress - roundedSize) : 0;
9797

9898
#ifdef DEBUG_UPDATER
99-
DEBUG_UPDATER.printf("[begin] roundedSize: 0x%08X (%d)\n", roundedSize, roundedSize);
100-
DEBUG_UPDATER.printf("[begin] updateEndAddress: 0x%08X (%d)\n", updateEndAddress, updateEndAddress);
101-
DEBUG_UPDATER.printf("[begin] currentSketchSize: 0x%08X (%d)\n", currentSketchSize, currentSketchSize);
99+
DEBUG_UPDATER.printf("[begin] roundedSize: 0x%08zX (%zd)\n", roundedSize, roundedSize);
100+
DEBUG_UPDATER.printf("[begin] updateEndAddress: 0x%08zX (%zd)\n", updateEndAddress, updateEndAddress);
101+
DEBUG_UPDATER.printf("[begin] currentSketchSize: 0x%08zX (%zd)\n", currentSketchSize, currentSketchSize);
102102
#endif
103103

104104
//make sure that the size of both sketches is less than the total space (updateEndAddress)
@@ -108,7 +108,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
108108
}
109109
}
110110
else if (command == U_SPIFFS) {
111-
updateStartAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
111+
updateStartAddress = (uintptr_t)&_SPIFFS_start - 0x40200000;
112112
}
113113
else {
114114
// unknown command
@@ -133,7 +133,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
133133
#ifdef DEBUG_UPDATER
134134
DEBUG_UPDATER.printf("[begin] _startAddress: 0x%08X (%d)\n", _startAddress, _startAddress);
135135
DEBUG_UPDATER.printf("[begin] _currentAddress: 0x%08X (%d)\n", _currentAddress, _currentAddress);
136-
DEBUG_UPDATER.printf("[begin] _size: 0x%08X (%d)\n", _size, _size);
136+
DEBUG_UPDATER.printf("[begin] _size: 0x%08zX (%zd)\n", _size, _size);
137137
#endif
138138

139139
_md5.begin();
@@ -159,7 +159,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
159159

160160
if(hasError() || (!isFinished() && !evenIfRemaining)){
161161
#ifdef DEBUG_UPDATER
162-
DEBUG_UPDATER.printf("premature end: res:%u, pos:%u/%u\n", getError(), progress(), _size);
162+
DEBUG_UPDATER.printf("premature end: res:%u, pos:%zu/%zu\n", getError(), progress(), _size);
163163
#endif
164164

165165
_reset();
@@ -199,10 +199,10 @@ bool UpdaterClass::end(bool evenIfRemaining){
199199
eboot_command_write(&ebcmd);
200200

201201
#ifdef DEBUG_UPDATER
202-
DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08X\n", _startAddress, _size);
202+
DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08zX\n", _startAddress, _size);
203203
}
204204
else if (_command == U_SPIFFS) {
205-
DEBUG_UPDATER.printf("SPIFFS: address:0x%08X, size:0x%08X\n", _startAddress, _size);
205+
DEBUG_UPDATER.printf("SPIFFS: address:0x%08X, size:0x%08zX\n", _startAddress, _size);
206206
#endif
207207
}
208208

0 commit comments

Comments
 (0)