Skip to content

Commit

Permalink
Merge branch 'master' into nosizeconf
Browse files Browse the repository at this point in the history
  • Loading branch information
d-a-v committed Feb 25, 2020
2 parents 855dd34 + abdd2bd commit 9b0164a
Show file tree
Hide file tree
Showing 150 changed files with 2,964 additions and 1,320 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "tools/esptool"]
path = tools/esptool
url = https://github.com/espressif/esptool.git
[submodule "tools/sdk/uzlib"]
path = tools/sdk/uzlib
url = https://github.com/earlephilhower/uzlib.git
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ jobs:
- name: "Platformio (1)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
install:
- sudo apt-get install python3-pip python3-setuptools
env:
- BUILD_PARITY=even
- name: "Platformio (2)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
install:
- sudo apt-get install python3-pip python3-setuptools
env:
- BUILD_PARITY=odd

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Arduino core for ESP8266 WiFi chip

# Quick links

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

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

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

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

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

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

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

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

[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).

[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.

### Other useful links ###

[Toolchain repo](https://github.com/earlephilhower/esp-quick-toolchain)
Expand Down
20 changes: 11 additions & 9 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,14 @@ generic.menu.led.15=15
generic.menu.led.15.build.led=-DLED_BUILTIN=15
generic.menu.led.16=16
generic.menu.led.16.build.led=-DLED_BUILTIN=16
generic.menu.sdk.nonosdk_191024=nonos-sdk 2.2.1+111 (191024)
generic.menu.sdk.nonosdk_191024.build.sdk=NONOSDK22x_191024
generic.menu.sdk.nonosdk_191105=nonos-sdk 2.2.1+113 (191105)
generic.menu.sdk.nonosdk_191105.build.sdk=NONOSDK22x_191105
generic.menu.sdk.nonosdk_190703=nonos-sdk 2.2.1+100 (190703)
generic.menu.sdk.nonosdk_190703.build.sdk=NONOSDK22x_190703
generic.menu.sdk.nonosdk_191122=nonos-sdk 2.2.1+119 (191122)
generic.menu.sdk.nonosdk_191122.build.sdk=NONOSDK22x_191122
generic.menu.sdk.nonosdk_191105=nonos-sdk 2.2.1+113 (191105)
generic.menu.sdk.nonosdk_191105.build.sdk=NONOSDK22x_191105
generic.menu.sdk.nonosdk_191024=nonos-sdk 2.2.1+111 (191024)
generic.menu.sdk.nonosdk_191024.build.sdk=NONOSDK22x_191024
generic.menu.sdk.nonosdk221=nonos-sdk 2.2.1 (legacy)
generic.menu.sdk.nonosdk221.build.sdk=NONOSDK221
generic.menu.sdk.nonosdk3v0=nonos-sdk pre-3 (180626 known issues)
Expand Down Expand Up @@ -6982,18 +6984,18 @@ espectro.menu.eesz.autoflash.upload.maximum_size=1044464

##############################################################
sonoff.name=ITEAD Sonoff
sonoff.build.board=SONOFF_SV
sonoff.build.board=ESP8266_SONOFF_SV
sonoff.build.extra_flags=-DESP8266
sonoff.build.flash_size=1M
sonoff.build.variant=itead
sonoff.menu.BoardModel.sonoffBasic=ITEAD Sonoff Basic
sonoff.menu.BoardModel.sonoffBasic.build.board=SONOFF_BASIC
sonoff.menu.BoardModel.sonoffBasic.build.board=ESP8266_SONOFF_BASIC
sonoff.menu.BoardModel.sonoffS20=ITEAD Sonoff S20
sonoff.menu.BoardModel.sonoffS20.build.board=SONOFF_S20
sonoff.menu.BoardModel.sonoffS20.build.board=ESP8266_SONOFF_S20
sonoff.menu.BoardModel.sonoffSV=ITEAD Sonoff SV
sonoff.menu.BoardModel.sonoffSV.build.board=SONOFF_SV
sonoff.menu.BoardModel.sonoffSV.build.board=ESP8266_SONOFF_SV
sonoff.menu.BoardModel.sonoffTH=ITEAD Sonoff TH
sonoff.menu.BoardModel.sonoffTH.build.board=SONOFF_TH
sonoff.menu.BoardModel.sonoffTH.build.board=ESP8266_SONOFF_TH
sonoff.upload.tool=esptool
sonoff.upload.maximum_data_size=81920
sonoff.upload.wait_for_upload_port=true
Expand Down
38 changes: 23 additions & 15 deletions bootloaders/eboot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,57 @@ TARGET_DIR := ./

TARGET_OBJ_FILES := \
eboot.o \
eboot_command.o \

eboot_command.o

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

UZLIB_PATH := ../../tools/sdk/uzlib/src
UZLIB_FLAGS := -DRUNTIME_BITS_TABLES

CC := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
CXX := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-g++
AR := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
OBJDUMP := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-objdump

INC += -I../../tools/sdk/include
INC += -I../../tools/sdk/include -I../../tools/sdk/uzlib/src

CFLAGS += -std=gnu99

CFLAGS += -O0 -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals
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

CFLAGS += $(INC)

LDFLAGS += -nostdlib -Wl,--no-check-sections -umain
CFLAGS += $(UZLIB_FLAGS)

LDFLAGS += -nostdlib -Wl,--no-check-sections -Wl,--gc-sections -umain -Wl,-Map,$(@:.elf=.map)

LD_SCRIPT := -Teboot.ld

APP_OUT:= eboot.elf
APP_AR := eboot.a
APP_FW := eboot.bin
APP_OUT := eboot.elf
APP_AR := eboot.a
APP_FW := eboot.bin

all: $(APP_FW)

$(APP_AR): $(TARGET_OBJ_PATHS)
$(AR) cru $@ $^
all: $(APP_OUT)

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

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

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

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

clean:
rm -f *.o
rm -f $(APP_AR)
rm -f $(APP_OUT)
rm -f *.map


.PHONY: all clean default
102 changes: 85 additions & 17 deletions bootloaders/eboot/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <string.h>
#include "flash.h"
#include "eboot_command.h"
#include <uzlib.h>

extern unsigned char _gzip_dict;

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

Expand All @@ -24,10 +27,14 @@ int print_version(const uint32_t flash_addr)
if (SPIRead(flash_addr + APP_START_OFFSET + sizeof(image_header_t) + sizeof(section_header_t), &ver, sizeof(ver))) {
return 1;
}
const char* __attribute__ ((aligned (4))) fmtt = "v%08x\n\0\0";
uint32_t fmt[2];
fmt[0] = ((uint32_t*) fmtt)[0];
fmt[1] = ((uint32_t*) fmtt)[1];
char fmt[7];
fmt[0] = 'v';
fmt[1] = '%';
fmt[2] = '0';
fmt[3] = '8';
fmt[4] = 'x';
fmt[5] = '\n';
fmt[6] = 0;
ets_printf((const char*) fmt, ver);
return 0;
}
Expand Down Expand Up @@ -80,37 +87,96 @@ int load_app_from_flash_raw(const uint32_t flash_addr)
pos += section_header.size;
}

register uint32_t sp asm("a1") = 0x3ffffff0;
register uint32_t pc asm("a3") = image_header.entry;
__asm__ __volatile__ ("jx a3");
asm volatile("" ::: "memory");
asm volatile ("mov.n a1, %0\n"
"mov.n a3, %1\n"
"jx a3\n" : : "r" (0x3ffffff0), "r" (image_header.entry) );

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

uint8_t read_flash_byte(const uint32_t addr)
{
uint8_t __attribute__((aligned(4))) buff[4];
SPIRead(addr & ~3, buff, 4);
return buff[addr & 3];
}
unsigned char __attribute__((aligned(4))) uzlib_flash_read_cb_buff[4096];
uint32_t uzlib_flash_read_cb_addr;
int uzlib_flash_read_cb(struct uzlib_uncomp *m)
{
m->source = uzlib_flash_read_cb_buff;
m->source_limit = uzlib_flash_read_cb_buff + sizeof(uzlib_flash_read_cb_buff);
SPIRead(uzlib_flash_read_cb_addr, uzlib_flash_read_cb_buff, sizeof(uzlib_flash_read_cb_buff));
uzlib_flash_read_cb_addr += sizeof(uzlib_flash_read_cb_buff);
return *(m->source++);
}

unsigned char gzip_dict[32768];

int copy_raw(const uint32_t src_addr,
const uint32_t dst_addr,
const uint32_t size)
{
// require regions to be aligned
if (src_addr & 0xfff != 0 ||
dst_addr & 0xfff != 0) {
if ((src_addr & 0xfff) != 0 ||
(dst_addr & 0xfff) != 0) {
return 1;
}

const uint32_t buffer_size = FLASH_SECTOR_SIZE;
uint8_t buffer[buffer_size];
uint32_t left = ((size+buffer_size-1) & ~(buffer_size-1));
int32_t left = ((size+buffer_size-1) & ~(buffer_size-1));
uint32_t saddr = src_addr;
uint32_t daddr = dst_addr;

while (left) {
struct uzlib_uncomp m_uncomp;
bool gzip = false;

// Check if we are uncompressing a GZIP upload or not
if ((read_flash_byte(saddr) == 0x1f) && (read_flash_byte(saddr + 1) == 0x8b)) {
// GZIP signature matched. Find real size as encoded at the end
left = read_flash_byte(saddr + size - 4);
left += read_flash_byte(saddr + size - 3)<<8;
left += read_flash_byte(saddr + size - 2)<<16;
left += read_flash_byte(saddr + size - 1)<<24;

uzlib_init();

/* all 3 fields below must be initialized by user */
m_uncomp.source = NULL;
m_uncomp.source_limit = NULL;
uzlib_flash_read_cb_addr = src_addr;
m_uncomp.source_read_cb = uzlib_flash_read_cb;
uzlib_uncompress_init(&m_uncomp, gzip_dict, sizeof(gzip_dict));

int res = uzlib_gzip_parse_header(&m_uncomp);
if (res != TINF_OK) {
return 5; // Error uncompress header read
}
gzip = true;
}
while (left > 0) {
if (SPIEraseSector(daddr/buffer_size)) {
return 2;
}
if (SPIRead(saddr, buffer, buffer_size)) {
return 3;
if (!gzip) {
if (SPIRead(saddr, buffer, buffer_size)) {
return 3;
}
} else {
m_uncomp.dest_start = buffer;
m_uncomp.dest = buffer;
int to_read = (left > buffer_size) ? buffer_size : left;
m_uncomp.dest_limit = buffer + to_read;
int res = uzlib_uncompress(&m_uncomp);
if ((res != TINF_DONE) && (res != TINF_OK)) {
return 6;
}
// Fill any remaining with 0xff
for (int i = to_read; i < buffer_size; i++) {
buffer[i] = 0xff;
}
}
if (SPIWrite(daddr, buffer, buffer_size)) {
return 4;
Expand All @@ -124,13 +190,12 @@ int copy_raw(const uint32_t src_addr,
}



void main()
int main()
{
int res = 9;
bool clear_cmd = false;
struct eboot_command cmd;

print_version(0);

if (eboot_command_read(&cmd) == 0) {
Expand Down Expand Up @@ -172,4 +237,7 @@ void main()
}

while(true){}

__builtin_unreachable();
return 0;
}
Binary file modified bootloaders/eboot/eboot.elf
Binary file not shown.
21 changes: 20 additions & 1 deletion bootloaders/eboot/eboot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ SECTIONS

.data : ALIGN(4)
{
*(COMMON) /* Global vars */
. = ALIGN(4);
_heap_start = ABSOLUTE(.);
/* _stack_sentry = ALIGN(0x8); */
} >dram0_0_seg :dram0_0_bss_phdr
Expand Down Expand Up @@ -150,9 +152,26 @@ SECTIONS
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN (8);
_bss_end = ABSOLUTE(.);
_free_space = 4096 - 17 - (. - _stext);
/*
The boot loader checksum must be before the CRC, which is written by elf2bin.py.
This leaves 16 bytes after the checksum for the CRC placed at the end of the
4096-byte sector. */
_cs_here = (ALIGN((. + 1), 16) == ALIGN(16)) ? (ALIGN(16) - 1) : (. + 0x0F);

/*
The filling (padding) and values for _crc_size and _crc_val are handled by
elf2bin.py. With this, we give values to the symbols without explicitly
assigning space. This avoids the linkers back *fill* operation that causes
trouble.

The CRC info is stored in last 8 bytes. */
_crc_size = _stext + 4096 - 8;
_crc_val = _stext + 4096 - 4;
ASSERT((4096 > (17 + (. - _stext))), "Error: No space for CS and CRC in bootloader sector.");
ASSERT((_crc_size > _cs_here), "Error: CRC must be located after CS.");
} >iram1_0_seg :iram1_0_phdr

.lit4 : ALIGN(4)
Expand Down
2 changes: 1 addition & 1 deletion bootloaders/eboot/eboot_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int eboot_command_read(struct eboot_command* cmd)
}

uint32_t crc32 = eboot_command_calculate_crc32(cmd);
if (cmd->magic & EBOOT_MAGIC_MASK != EBOOT_MAGIC ||
if ((cmd->magic & EBOOT_MAGIC_MASK) != EBOOT_MAGIC ||
cmd->crc32 != crc32) {
return 1;
}
Expand Down
Loading

0 comments on commit 9b0164a

Please sign in to comment.