From 6dd651647ae259fce9be308a24fb6f56a4babb15 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Fri, 29 Sep 2017 21:01:56 +0200 Subject: [PATCH] Sonoff customized firmware --- sonoff/Makefile | 42 +++++++++++++++++++++++++++++++++ sonoff/Makefile-user.mk | 16 +++++++++++++ sonoff/app/application.cpp | 10 ++++++++ sonoff/include/user_config.h | 45 ++++++++++++++++++++++++++++++++++++ sonoff/rboot.rom0.ld | 11 +++++++++ sonoff/rboot.rom1.ld | 11 +++++++++ 6 files changed, 135 insertions(+) create mode 100644 sonoff/Makefile create mode 100644 sonoff/Makefile-user.mk create mode 100644 sonoff/app/application.cpp create mode 100644 sonoff/include/user_config.h create mode 100644 sonoff/rboot.rom0.ld create mode 100644 sonoff/rboot.rom1.ld diff --git a/sonoff/Makefile b/sonoff/Makefile new file mode 100644 index 0000000..ab74ca2 --- /dev/null +++ b/sonoff/Makefile @@ -0,0 +1,42 @@ +##################################################################### +#### Please don't change this file. Use Makefile-user.mk instead #### +##################################################################### +# Including user Makefile. +# Should be used to set project-specific parameters +include ./Makefile-user.mk + +# Important parameters check. +# We need to make sure SMING_HOME and ESP_HOME variables are set. +# You can use Makefile-user.mk in each project or use enviromental variables to set it globally. + +ifndef SMING_HOME +$(error SMING_HOME is not set. Please configure it in Makefile-user.mk) +endif +ifndef ESP_HOME +$(error ESP_HOME is not set. Please configure it in Makefile-user.mk) +endif + +# Include main Sming Makefile +ifeq ($(RBOOT_ENABLED), 1) +include $(SMING_HOME)/Makefile-rboot.mk +else +include $(SMING_HOME)/Makefile-project.mk +endif + +$(APP_AR): $(OBJ) + $(vecho) "AR $@" + + @echo "char* BUILD_ID = \"$(shell git rev-parse --short HEAD)-$(shell TZ=UTC date +%Y%m%d-%H%M%S)\";" > $(BUILD_BASE)/ver.c + cat $(BUILD_BASE)/ver.c + $(CC) -c $(BUILD_BASE)/ver.c -o $(BUILD_BASE)/ver.o + + $(Q) $(AR) cru $@ $^ $(BUILD_BASE)/ver.o + +ota: all + -mkdir ../master/ota/$(DEVICE) >/dev/null + cp -r out/firmware/* ../master/ota/$(DEVICE) + python ../master/client.py $(DEVICE) control ota + +remoteota: all + scp -r out/firmware/rom*.bin root@sound:/var/www/api/1/ota/$(DEVICE)/ + python ../master/remoteclient.py $(DEVICE) \$$implementation/ota true diff --git a/sonoff/Makefile-user.mk b/sonoff/Makefile-user.mk new file mode 100644 index 0000000..7882794 --- /dev/null +++ b/sonoff/Makefile-user.mk @@ -0,0 +1,16 @@ +MODULES = app ../spejsiot ../spejsiot/endpoints +DISABLE_SPIFFS = 1 +USER_CFLAGS = -I../common +#ENABLE_SSL = 1 +RBOOT_ENABLED = 1 +RBOOT_BIG_FLASH = 0 +RBOOT_TWO_ROMS = 1 +RBOOT_RTC_ENABLED = 1 +# these next options only needed when using two rom mode +RBOOT_ROM_0 ?= rom0 +RBOOT_LD_0 ?= rboot.rom0.ld +RBOOT_ROM_1 ?= rom1 +RBOOT_LD_1 ?= rboot.rom1.ld + +SPI_SIZE = 1M +SPI_MODE = dout diff --git a/sonoff/app/application.cpp b/sonoff/app/application.cpp new file mode 100644 index 0000000..6890903 --- /dev/null +++ b/sonoff/app/application.cpp @@ -0,0 +1,10 @@ +#include +#include + +SpejsNode node("switch"); + +void init() { + node.statusLED.config(13, LOW); + node.init(); + node.registerEndpoint("relay", new OutputEndpoint(12)); +} diff --git a/sonoff/include/user_config.h b/sonoff/include/user_config.h new file mode 100644 index 0000000..1c6ac36 --- /dev/null +++ b/sonoff/include/user_config.h @@ -0,0 +1,45 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + // UART config + #define SERIAL_BAUD_RATE 115200 + + // ESP SDK config + #define LWIP_OPEN_SRC + #define USE_US_TIMER + + // Default types + #define __CORRECT_ISO_CPP_STDLIB_H_PROTO + #include + #include + + // Override c_types.h include and remove buggy espconn + #define _C_TYPES_H_ + #define _NO_ESPCON_ + + // Updated, compatible version of c_types.h + // Just removed types declared in + #include + + // System API declarations + #include + + // C++ Support + #include + // Extended string conversion for compatibility + #include + // Network base API + #include + + // Beta boards + #define BOARD_ESP01 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sonoff/rboot.rom0.ld b/sonoff/rboot.rom0.ld new file mode 100644 index 0000000..db2b1f8 --- /dev/null +++ b/sonoff/rboot.rom0.ld @@ -0,0 +1,11 @@ +/* Linker Script for rboot */ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40202010, len = (512K - 0x2010) +} + +INCLUDE "common.ld" diff --git a/sonoff/rboot.rom1.ld b/sonoff/rboot.rom1.ld new file mode 100644 index 0000000..23976cd --- /dev/null +++ b/sonoff/rboot.rom1.ld @@ -0,0 +1,11 @@ +/* Linker Script for rboot */ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40202010+512K, len = (512K - 0x2010) +} + +INCLUDE "common.ld"