Skip to content

Commit 9b0164a

Browse files
committed
Merge branch 'master' into nosizeconf
2 parents 855dd34 + abdd2bd commit 9b0164a

File tree

150 files changed

+2964
-1320
lines changed

Some content is hidden

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

150 files changed

+2964
-1320
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
[submodule "tools/esptool"]
2020
path = tools/esptool
2121
url = https://github.com/espressif/esptool.git
22+
[submodule "tools/sdk/uzlib"]
23+
path = tools/sdk/uzlib
24+
url = https://github.com/earlephilhower/uzlib.git

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ jobs:
2424
- name: "Platformio (1)"
2525
stage: build
2626
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
27+
install:
28+
- sudo apt-get install python3-pip python3-setuptools
2729
env:
2830
- BUILD_PARITY=even
2931
- name: "Platformio (2)"
3032
stage: build
3133
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
34+
install:
35+
- sudo apt-get install python3-pip python3-setuptools
3236
env:
3337
- BUILD_PARITY=odd
3438

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Arduino core for ESP8266 WiFi chip
33

44
# Quick links
55

6-
- [Latest release documentation](https://arduino-esp8266.readthedocs.io/en/2.6.1/)
6+
- [Latest release documentation](https://arduino-esp8266.readthedocs.io/en/2.6.3/)
77
- [Current "git version" documentation](https://arduino-esp8266.readthedocs.io/en/latest/)
88
- [Install git version](https://arduino-esp8266.readthedocs.io/en/latest/installing.html#using-git-version) ([sources](doc/installing.rst#using-git-version))
99

@@ -36,7 +36,7 @@ Starting with 1.6.4, Arduino allows installation of third-party platform package
3636
#### Latest release [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/)
3737
Boards manager link: `https://arduino.esp8266.com/stable/package_esp8266com_index.json`
3838

39-
Documentation: [https://arduino-esp8266.readthedocs.io/en/2.6.1/](https://arduino-esp8266.readthedocs.io/en/2.6.1/)
39+
Documentation: [https://arduino-esp8266.readthedocs.io/en/2.6.3/](https://arduino-esp8266.readthedocs.io/en/2.6.3/)
4040

4141
### Using git version
4242
[![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino)
@@ -106,7 +106,7 @@ Arduino IDE is developed and maintained by the Arduino team. The IDE is licensed
106106

107107
ESP8266 core includes an xtensa gcc toolchain, which is also under GPL.
108108

109-
Esptool written by Christian Klippel is licensed under GPLv2, currently maintained by Ivan Grokhotkov: https://github.com/igrr/esptool-ck.
109+
Esptool.py was initially created by Fredrik Ahlberg (@themadinventor, @kongo), and is currently maintained by Angus Gratton (@projectgus) under GPL 2.0 license.
110110

111111
Espressif SDK included in this build is under Espressif MIT License.
112112

@@ -124,6 +124,8 @@ ESP8266 core files are licensed under LGPL.
124124

125125
[LittleFS](https://github.com/ARMmbed/littlefs) library written by ARM Limited and released under the [BSD 3-clause license](https://github.com/ARMmbed/littlefs/blob/master/LICENSE.md).
126126

127+
[uzlib](https://github.com/pfalcon/uzlib) library written and (c) 2014-2018 Paul Sokolovsky, licensed under the ZLib license (https://www.zlib.net/zlib_license.html). uzlib is based on: tinf library by Joergen Ibsen (Deflate decompression); Deflate Static Huffman tree routines by Simon Tatham; LZ77 compressor by Paul Sokolovsky; with library integrated and maintained by Paul Sokolovsky.
128+
127129
### Other useful links ###
128130

129131
[Toolchain repo](https://github.com/earlephilhower/esp-quick-toolchain)

boards.txt

+11-9
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,14 @@ generic.menu.led.15=15
414414
generic.menu.led.15.build.led=-DLED_BUILTIN=15
415415
generic.menu.led.16=16
416416
generic.menu.led.16.build.led=-DLED_BUILTIN=16
417-
generic.menu.sdk.nonosdk_191024=nonos-sdk 2.2.1+111 (191024)
418-
generic.menu.sdk.nonosdk_191024.build.sdk=NONOSDK22x_191024
419-
generic.menu.sdk.nonosdk_191105=nonos-sdk 2.2.1+113 (191105)
420-
generic.menu.sdk.nonosdk_191105.build.sdk=NONOSDK22x_191105
421417
generic.menu.sdk.nonosdk_190703=nonos-sdk 2.2.1+100 (190703)
422418
generic.menu.sdk.nonosdk_190703.build.sdk=NONOSDK22x_190703
419+
generic.menu.sdk.nonosdk_191122=nonos-sdk 2.2.1+119 (191122)
420+
generic.menu.sdk.nonosdk_191122.build.sdk=NONOSDK22x_191122
421+
generic.menu.sdk.nonosdk_191105=nonos-sdk 2.2.1+113 (191105)
422+
generic.menu.sdk.nonosdk_191105.build.sdk=NONOSDK22x_191105
423+
generic.menu.sdk.nonosdk_191024=nonos-sdk 2.2.1+111 (191024)
424+
generic.menu.sdk.nonosdk_191024.build.sdk=NONOSDK22x_191024
423425
generic.menu.sdk.nonosdk221=nonos-sdk 2.2.1 (legacy)
424426
generic.menu.sdk.nonosdk221.build.sdk=NONOSDK221
425427
generic.menu.sdk.nonosdk3v0=nonos-sdk pre-3 (180626 known issues)
@@ -6982,18 +6984,18 @@ espectro.menu.eesz.autoflash.upload.maximum_size=1044464
69826984

69836985
##############################################################
69846986
sonoff.name=ITEAD Sonoff
6985-
sonoff.build.board=SONOFF_SV
6987+
sonoff.build.board=ESP8266_SONOFF_SV
69866988
sonoff.build.extra_flags=-DESP8266
69876989
sonoff.build.flash_size=1M
69886990
sonoff.build.variant=itead
69896991
sonoff.menu.BoardModel.sonoffBasic=ITEAD Sonoff Basic
6990-
sonoff.menu.BoardModel.sonoffBasic.build.board=SONOFF_BASIC
6992+
sonoff.menu.BoardModel.sonoffBasic.build.board=ESP8266_SONOFF_BASIC
69916993
sonoff.menu.BoardModel.sonoffS20=ITEAD Sonoff S20
6992-
sonoff.menu.BoardModel.sonoffS20.build.board=SONOFF_S20
6994+
sonoff.menu.BoardModel.sonoffS20.build.board=ESP8266_SONOFF_S20
69936995
sonoff.menu.BoardModel.sonoffSV=ITEAD Sonoff SV
6994-
sonoff.menu.BoardModel.sonoffSV.build.board=SONOFF_SV
6996+
sonoff.menu.BoardModel.sonoffSV.build.board=ESP8266_SONOFF_SV
69956997
sonoff.menu.BoardModel.sonoffTH=ITEAD Sonoff TH
6996-
sonoff.menu.BoardModel.sonoffTH.build.board=SONOFF_TH
6998+
sonoff.menu.BoardModel.sonoffTH.build.board=ESP8266_SONOFF_TH
69976999
sonoff.upload.tool=esptool
69987000
sonoff.upload.maximum_data_size=81920
69997001
sonoff.upload.wait_for_upload_port=true

bootloaders/eboot/Makefile

+23-15
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,57 @@ TARGET_DIR := ./
66

77
TARGET_OBJ_FILES := \
88
eboot.o \
9-
eboot_command.o \
10-
9+
eboot_command.o
1110

1211
TARGET_OBJ_PATHS := $(addprefix $(TARGET_DIR)/,$(TARGET_OBJ_FILES))
1312

13+
UZLIB_PATH := ../../tools/sdk/uzlib/src
14+
UZLIB_FLAGS := -DRUNTIME_BITS_TABLES
15+
1416
CC := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
1517
CXX := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-g++
1618
AR := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-ar
1719
LD := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
1820
OBJDUMP := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-objdump
1921

20-
INC += -I../../tools/sdk/include
22+
INC += -I../../tools/sdk/include -I../../tools/sdk/uzlib/src
23+
2124
CFLAGS += -std=gnu99
2225

23-
CFLAGS += -O0 -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals
26+
CFLAGS += -Os -g -Wall -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals -ffunction-sections -fdata-sections
2427

2528
CFLAGS += $(INC)
2629

27-
LDFLAGS += -nostdlib -Wl,--no-check-sections -umain
30+
CFLAGS += $(UZLIB_FLAGS)
31+
32+
LDFLAGS += -nostdlib -Wl,--no-check-sections -Wl,--gc-sections -umain -Wl,-Map,$(@:.elf=.map)
2833

2934
LD_SCRIPT := -Teboot.ld
3035

31-
APP_OUT:= eboot.elf
32-
APP_AR := eboot.a
33-
APP_FW := eboot.bin
36+
APP_OUT := eboot.elf
37+
APP_AR := eboot.a
38+
APP_FW := eboot.bin
3439

35-
all: $(APP_FW)
3640

37-
$(APP_AR): $(TARGET_OBJ_PATHS)
38-
$(AR) cru $@ $^
41+
all: $(APP_OUT)
3942

43+
tinflate.o: $(UZLIB_PATH)/tinflate.c $(UZLIB_PATH)/uzlib.h $(UZLIB_PATH)/uzlib_conf.h
44+
$(CC) $(CFLAGS) -c -o tinflate.o $(UZLIB_PATH)/tinflate.c
4045

41-
$(APP_OUT): $(APP_AR)
42-
$(LD) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group -Wl,--whole-archive $(APP_AR) -Wl,--end-group -o $@
46+
tinfgzip.o: $(UZLIB_PATH)/tinfgzip.c $(UZLIB_PATH)/uzlib.h $(UZLIB_PATH)/uzlib_conf.h
47+
$(CC) $(CFLAGS) -c -o tinfgzip.o $(UZLIB_PATH)/tinfgzip.c
4348

44-
$(APP_FW): $(APP_OUT)
45-
$(ESPTOOL) -vvv -eo $(APP_OUT) -bo $@ -bs .text -bs .data -bs .rodata -bc -ec || true
49+
$(APP_AR): $(TARGET_OBJ_PATHS) tinflate.o tinfgzip.o
50+
$(AR) cru $@ $^
4651

52+
$(APP_OUT): $(APP_AR) eboot.ld | Makefile
53+
$(LD) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group -Wl,--whole-archive $(APP_AR) -Wl,--end-group -o $@
4754

4855
clean:
4956
rm -f *.o
5057
rm -f $(APP_AR)
5158
rm -f $(APP_OUT)
59+
rm -f *.map
5260

5361

5462
.PHONY: all clean default

bootloaders/eboot/eboot.c

+85-17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <string.h>
1313
#include "flash.h"
1414
#include "eboot_command.h"
15+
#include <uzlib.h>
16+
17+
extern unsigned char _gzip_dict;
1518

1619
#define SWRST do { (*((volatile uint32_t*) 0x60000700)) |= 0x80000000; } while(0);
1720

@@ -24,10 +27,14 @@ int print_version(const uint32_t flash_addr)
2427
if (SPIRead(flash_addr + APP_START_OFFSET + sizeof(image_header_t) + sizeof(section_header_t), &ver, sizeof(ver))) {
2528
return 1;
2629
}
27-
const char* __attribute__ ((aligned (4))) fmtt = "v%08x\n\0\0";
28-
uint32_t fmt[2];
29-
fmt[0] = ((uint32_t*) fmtt)[0];
30-
fmt[1] = ((uint32_t*) fmtt)[1];
30+
char fmt[7];
31+
fmt[0] = 'v';
32+
fmt[1] = '%';
33+
fmt[2] = '0';
34+
fmt[3] = '8';
35+
fmt[4] = 'x';
36+
fmt[5] = '\n';
37+
fmt[6] = 0;
3138
ets_printf((const char*) fmt, ver);
3239
return 0;
3340
}
@@ -80,37 +87,96 @@ int load_app_from_flash_raw(const uint32_t flash_addr)
8087
pos += section_header.size;
8188
}
8289

83-
register uint32_t sp asm("a1") = 0x3ffffff0;
84-
register uint32_t pc asm("a3") = image_header.entry;
85-
__asm__ __volatile__ ("jx a3");
90+
asm volatile("" ::: "memory");
91+
asm volatile ("mov.n a1, %0\n"
92+
"mov.n a3, %1\n"
93+
"jx a3\n" : : "r" (0x3ffffff0), "r" (image_header.entry) );
8694

95+
__builtin_unreachable(); // Save a few bytes by letting GCC know no need to pop regs/return
8796
return 0;
8897
}
8998

99+
uint8_t read_flash_byte(const uint32_t addr)
100+
{
101+
uint8_t __attribute__((aligned(4))) buff[4];
102+
SPIRead(addr & ~3, buff, 4);
103+
return buff[addr & 3];
104+
}
105+
unsigned char __attribute__((aligned(4))) uzlib_flash_read_cb_buff[4096];
106+
uint32_t uzlib_flash_read_cb_addr;
107+
int uzlib_flash_read_cb(struct uzlib_uncomp *m)
108+
{
109+
m->source = uzlib_flash_read_cb_buff;
110+
m->source_limit = uzlib_flash_read_cb_buff + sizeof(uzlib_flash_read_cb_buff);
111+
SPIRead(uzlib_flash_read_cb_addr, uzlib_flash_read_cb_buff, sizeof(uzlib_flash_read_cb_buff));
112+
uzlib_flash_read_cb_addr += sizeof(uzlib_flash_read_cb_buff);
113+
return *(m->source++);
114+
}
90115

116+
unsigned char gzip_dict[32768];
91117

92118
int copy_raw(const uint32_t src_addr,
93119
const uint32_t dst_addr,
94120
const uint32_t size)
95121
{
96122
// require regions to be aligned
97-
if (src_addr & 0xfff != 0 ||
98-
dst_addr & 0xfff != 0) {
123+
if ((src_addr & 0xfff) != 0 ||
124+
(dst_addr & 0xfff) != 0) {
99125
return 1;
100126
}
101127

102128
const uint32_t buffer_size = FLASH_SECTOR_SIZE;
103129
uint8_t buffer[buffer_size];
104-
uint32_t left = ((size+buffer_size-1) & ~(buffer_size-1));
130+
int32_t left = ((size+buffer_size-1) & ~(buffer_size-1));
105131
uint32_t saddr = src_addr;
106132
uint32_t daddr = dst_addr;
107-
108-
while (left) {
133+
struct uzlib_uncomp m_uncomp;
134+
bool gzip = false;
135+
136+
// Check if we are uncompressing a GZIP upload or not
137+
if ((read_flash_byte(saddr) == 0x1f) && (read_flash_byte(saddr + 1) == 0x8b)) {
138+
// GZIP signature matched. Find real size as encoded at the end
139+
left = read_flash_byte(saddr + size - 4);
140+
left += read_flash_byte(saddr + size - 3)<<8;
141+
left += read_flash_byte(saddr + size - 2)<<16;
142+
left += read_flash_byte(saddr + size - 1)<<24;
143+
144+
uzlib_init();
145+
146+
/* all 3 fields below must be initialized by user */
147+
m_uncomp.source = NULL;
148+
m_uncomp.source_limit = NULL;
149+
uzlib_flash_read_cb_addr = src_addr;
150+
m_uncomp.source_read_cb = uzlib_flash_read_cb;
151+
uzlib_uncompress_init(&m_uncomp, gzip_dict, sizeof(gzip_dict));
152+
153+
int res = uzlib_gzip_parse_header(&m_uncomp);
154+
if (res != TINF_OK) {
155+
return 5; // Error uncompress header read
156+
}
157+
gzip = true;
158+
}
159+
while (left > 0) {
109160
if (SPIEraseSector(daddr/buffer_size)) {
110161
return 2;
111162
}
112-
if (SPIRead(saddr, buffer, buffer_size)) {
113-
return 3;
163+
if (!gzip) {
164+
if (SPIRead(saddr, buffer, buffer_size)) {
165+
return 3;
166+
}
167+
} else {
168+
m_uncomp.dest_start = buffer;
169+
m_uncomp.dest = buffer;
170+
int to_read = (left > buffer_size) ? buffer_size : left;
171+
m_uncomp.dest_limit = buffer + to_read;
172+
int res = uzlib_uncompress(&m_uncomp);
173+
if ((res != TINF_DONE) && (res != TINF_OK)) {
174+
return 6;
175+
}
176+
// Fill any remaining with 0xff
177+
for (int i = to_read; i < buffer_size; i++) {
178+
buffer[i] = 0xff;
179+
}
114180
}
115181
if (SPIWrite(daddr, buffer, buffer_size)) {
116182
return 4;
@@ -124,13 +190,12 @@ int copy_raw(const uint32_t src_addr,
124190
}
125191

126192

127-
128-
void main()
193+
int main()
129194
{
130195
int res = 9;
131196
bool clear_cmd = false;
132197
struct eboot_command cmd;
133-
198+
134199
print_version(0);
135200

136201
if (eboot_command_read(&cmd) == 0) {
@@ -172,4 +237,7 @@ void main()
172237
}
173238

174239
while(true){}
240+
241+
__builtin_unreachable();
242+
return 0;
175243
}

bootloaders/eboot/eboot.elf

24 KB
Binary file not shown.

bootloaders/eboot/eboot.ld

+20-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ SECTIONS
6868

6969
.data : ALIGN(4)
7070
{
71+
*(COMMON) /* Global vars */
72+
. = ALIGN(4);
7173
_heap_start = ABSOLUTE(.);
7274
/* _stack_sentry = ALIGN(0x8); */
7375
} >dram0_0_seg :dram0_0_bss_phdr
@@ -150,9 +152,26 @@ SECTIONS
150152
*(.bss)
151153
*(.bss.*)
152154
*(.gnu.linkonce.b.*)
153-
*(COMMON)
154155
. = ALIGN (8);
155156
_bss_end = ABSOLUTE(.);
157+
_free_space = 4096 - 17 - (. - _stext);
158+
/*
159+
The boot loader checksum must be before the CRC, which is written by elf2bin.py.
160+
This leaves 16 bytes after the checksum for the CRC placed at the end of the
161+
4096-byte sector. */
162+
_cs_here = (ALIGN((. + 1), 16) == ALIGN(16)) ? (ALIGN(16) - 1) : (. + 0x0F);
163+
164+
/*
165+
The filling (padding) and values for _crc_size and _crc_val are handled by
166+
elf2bin.py. With this, we give values to the symbols without explicitly
167+
assigning space. This avoids the linkers back *fill* operation that causes
168+
trouble.
169+
170+
The CRC info is stored in last 8 bytes. */
171+
_crc_size = _stext + 4096 - 8;
172+
_crc_val = _stext + 4096 - 4;
173+
ASSERT((4096 > (17 + (. - _stext))), "Error: No space for CS and CRC in bootloader sector.");
174+
ASSERT((_crc_size > _cs_here), "Error: CRC must be located after CS.");
156175
} >iram1_0_seg :iram1_0_phdr
157176

158177
.lit4 : ALIGN(4)

bootloaders/eboot/eboot_command.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int eboot_command_read(struct eboot_command* cmd)
3737
}
3838

3939
uint32_t crc32 = eboot_command_calculate_crc32(cmd);
40-
if (cmd->magic & EBOOT_MAGIC_MASK != EBOOT_MAGIC ||
40+
if ((cmd->magic & EBOOT_MAGIC_MASK) != EBOOT_MAGIC ||
4141
cmd->crc32 != crc32) {
4242
return 1;
4343
}

0 commit comments

Comments
 (0)