├── .gitmodules ├── Makefile ├── README.md ├── c_types-c99.patch └── crosstool-config-overrides /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "crosstool-NG"] 2 | path = crosstool-NG 3 | url = https://github.com/jcmvbkbc/crosstool-NG 4 | branch = lx106-g++ 5 | [submodule "lx106-hal"] 6 | path = lx106-hal 7 | url = https://github.com/tommie/lx106-hal 8 | [submodule "esptool"] 9 | path = esptool 10 | url = https://github.com/themadinventor/esptool 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TOP = $(PWD) 2 | TOOLCHAIN = $(TOP)/xtensa-lx106-elf 3 | VENDOR_SDK = 1.0.0 4 | 5 | UNZIP = unzip -q -o 6 | 7 | VENDOR_SDK_ZIP = $(VENDOR_SDK_ZIP_$(VENDOR_SDK)) 8 | VENDOR_SDK_DIR = $(VENDOR_SDK_DIR_$(VENDOR_SDK)) 9 | 10 | VENDOR_SDK_ZIP_1.0.0 = esp_iot_sdk_v1.0.0_15_03_20.zip 11 | VENDOR_SDK_DIR_1.0.0 = esp_iot_sdk_v1.0.0 12 | VENDOR_SDK_ZIP_0.9.6b1 = esp_iot_sdk_v0.9.6_b1_15_02_15.zip 13 | VENDOR_SDK_DIR_0.9.6b1 = esp_iot_sdk_v0.9.6_b1 14 | VENDOR_SDK_ZIP_0.9.5 = esp_iot_sdk_v0.9.5_15_01_23.zip 15 | VENDOR_SDK_DIR_0.9.5 = esp_iot_sdk_v0.9.5 16 | VENDOR_SDK_ZIP_0.9.4 = esp_iot_sdk_v0.9.4_14_12_19.zip 17 | VENDOR_SDK_DIR_0.9.4 = esp_iot_sdk_v0.9.4 18 | VENDOR_SDK_ZIP_0.9.3 = esp_iot_sdk_v0.9.3_14_11_21.zip 19 | VENDOR_SDK_DIR_0.9.3 = esp_iot_sdk_v0.9.3 20 | VENDOR_SDK_ZIP_0.9.2 = esp_iot_sdk_v0.9.2_14_10_24.zip 21 | VENDOR_SDK_DIR_0.9.2 = esp_iot_sdk_v0.9.2 22 | STANDALONE = y 23 | 24 | .PHONY: crosstool-NG toolchain libhal libcirom sdk 25 | 26 | all: esptool libcirom standalone sdk sdk_patch $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc 27 | @echo 28 | @echo "Xtensa toolchain is built, to use it:" 29 | @echo 30 | @echo 'export PATH=$(TOOLCHAIN)/bin:$$PATH' 31 | @echo 32 | ifneq ($(STANDALONE),y) 33 | @echo "Espressif ESP8266 SDK is installed. Toolchain contains only Open Source components" 34 | @echo "To link external proprietary libraries add:" 35 | @echo 36 | @echo "xtensa-lx106-elf-gcc -I$(TOP)/sdk/include -L$(TOP)/sdk/lib" 37 | @echo 38 | else 39 | @echo "Espressif ESP8266 SDK is installed, its libraries and headers are merged with the toolchain" 40 | @echo 41 | endif 42 | 43 | esptool: toolchain 44 | cp esptool/esptool.py $(TOOLCHAIN)/bin/ 45 | 46 | $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libcirom.a: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libc.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc 47 | @echo "Creating irom version of libc..." 48 | $(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy --rename-section .text=.irom0.text \ 49 | --rename-section .literal=.irom0.literal $(<) $(@); 50 | 51 | libcirom: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libcirom.a 52 | 53 | sdk_patch: .sdk_patch_$(VENDOR_SDK) 54 | 55 | .sdk_patch_1.0.0: 56 | patch -d $(VENDOR_SDK_DIR_1.0.0) -p1 < c_types-c99.patch 57 | @touch $@ 58 | 59 | .sdk_patch_0.9.6b1: 60 | patch -d $(VENDOR_SDK_DIR_0.9.6b1) -p1 < c_types-c99.patch 61 | @touch $@ 62 | 63 | .sdk_patch_0.9.5: sdk095_patch1.zip esp_iot_sdk_v0.9.5/.dir 64 | $(UNZIP) $< 65 | mv libmain_fix_0.9.5.a $(VENDOR_SDK_DIR)/lib/libmain.a 66 | mv user_interface.h $(VENDOR_SDK_DIR)/include/ 67 | patch -d $(VENDOR_SDK_DIR_0.9.5) -p1 < c_types-c99.patch 68 | @touch $@ 69 | 70 | .sdk_patch_0.9.4: 71 | patch -d $(VENDOR_SDK_DIR_0.9.4) -p1 < c_types-c99.patch 72 | @touch $@ 73 | 74 | .sdk_patch_0.9.3: esp_iot_sdk_v0.9.3_14_11_21_patch1.zip esp_iot_sdk_v0.9.3/.dir 75 | $(UNZIP) $< 76 | @touch $@ 77 | 78 | .sdk_patch_0.9.2: FRM_ERR_PATCH.rar esp_iot_sdk_v0.9.2/.dir 79 | unrar x -o+ $< 80 | cp FRM_ERR_PATCH/*.a $(VENDOR_SDK_DIR)/lib/ 81 | @touch $@ 82 | 83 | standalone: sdk sdk_patch toolchain 84 | ifeq ($(STANDALONE),y) 85 | @echo "Installing vendor SDK headers into toolchain sysroot" 86 | @cp -Rf sdk/include/* $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/include/ 87 | @echo "Installing vendor SDK libs into toolchain sysroot" 88 | @cp -Rf sdk/lib/* $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/ 89 | @echo "Installing vendor SDK linker scripts into toolchain sysroot" 90 | @sed -e 's/\r//' sdk/ld/eagle.app.v6.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.ld 91 | @sed -e 's/\r//' sdk/ld/eagle.rom.addr.v6.ld >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.rom.addr.v6.ld 92 | endif 93 | 94 | FRM_ERR_PATCH.rar: 95 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=10" 96 | esp_iot_sdk_v0.9.3_14_11_21_patch1.zip: 97 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=73" 98 | sdk095_patch1.zip: 99 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=190" 100 | 101 | sdk: $(VENDOR_SDK_DIR)/.dir 102 | ln -snf $(VENDOR_SDK_DIR) sdk 103 | 104 | $(VENDOR_SDK_DIR)/.dir: $(VENDOR_SDK_ZIP) 105 | $(UNZIP) $^ 106 | -mv License $(VENDOR_SDK_DIR) 107 | touch $@ 108 | 109 | esp_iot_sdk_v1.0.0_15_03_20.zip: 110 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=250" 111 | 112 | esp_iot_sdk_v0.9.6_b1_15_02_15.zip: 113 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=220" 114 | 115 | esp_iot_sdk_v0.9.5_15_01_23.zip: 116 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=189" 117 | 118 | esp_iot_sdk_v0.9.4_14_12_19.zip: 119 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=111" 120 | 121 | esp_iot_sdk_v0.9.3_14_11_21.zip: 122 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=72" 123 | 124 | esp_iot_sdk_v0.9.2_14_10_24.zip: 125 | wget --content-disposition "http://bbs.espressif.com/download/file.php?id=9" 126 | 127 | libhal: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a 128 | 129 | $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc 130 | make -C lx106-hal -f ../Makefile _libhal 131 | 132 | _libhal: 133 | autoreconf -i 134 | PATH=$(TOOLCHAIN)/bin:$(PATH) ./configure --host=xtensa-lx106-elf --prefix=$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr 135 | PATH=$(TOOLCHAIN)/bin:$(PATH) make 136 | PATH=$(TOOLCHAIN)/bin:$(PATH) make install 137 | 138 | 139 | toolchain: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc 140 | 141 | $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc: crosstool-NG/ct-ng 142 | make -C crosstool-NG -f ../Makefile _toolchain 143 | 144 | _toolchain: 145 | ./ct-ng xtensa-lx106-elf 146 | sed -r -i.org s%CT_PREFIX_DIR=.*%CT_PREFIX_DIR="$(TOOLCHAIN)"% .config 147 | sed -r -i s%CT_INSTALL_DIR_RO=y%"#"CT_INSTALL_DIR_RO=y% .config 148 | cat ../crosstool-config-overrides >> .config 149 | ./ct-ng build 150 | 151 | 152 | crosstool-NG: crosstool-NG/ct-ng 153 | 154 | crosstool-NG/ct-ng: crosstool-NG/bootstrap 155 | make -C crosstool-NG -f ../Makefile _ct-ng 156 | 157 | _ct-ng: 158 | ./bootstrap 159 | ./configure --prefix=`pwd` 160 | make MAKELEVEL=0 161 | make install MAKELEVEL=0 162 | 163 | crosstool-NG/bootstrap: 164 | @echo "You cloned without --recursive, fetching submodules for you." 165 | git submodule update --init --recursive 166 | 167 | 168 | clean: clean-sdk 169 | make -C crosstool-NG clean MAKELEVEL=0 170 | -rm -rf $(TOOLCHAIN) 171 | 172 | clean-sdk: 173 | rm -rf $(VENDOR_SDK_DIR) 174 | rm -f sdk 175 | rm -f .sdk_patch_$(VENDOR_SDK) 176 | 177 | clean-sysroot: 178 | rm -rf $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/* 179 | rm -rf $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/include/* 180 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | esp-open-sdk 2 | ------------ 3 | 4 | This repository provides the integration scripts to build a complete 5 | standalone SDK (with toolchain) for software development with the 6 | Espressif ESP8266 and ESP8266EX chips. 7 | 8 | The complete SDK consists of: 9 | 10 | 1. Xtensa lx106 architecture toolchain (100% OpenSource), based on 11 | following projects: 12 | * https://github.com/jcmvbkbc/crosstool-NG 13 | * https://github.com/jcmvbkbc/gcc-xtensa 14 | * https://github.com/jcmvbkbc/newlib-xtensa 15 | * https://github.com/tommie/lx106-hal 16 | 17 | The source code above originates from work done directly by Tensilica Inc., 18 | Cadence Design Systems, Inc, and/or their contractors. 19 | 20 | 2. ESP8266 IoT SDK from Espressif Systems. This component is only 21 | partially open source, (some libraries are provided as binary blobs). 22 | * http://bbs.espressif.com/viewforum.php?f=5 23 | 24 | OpenSource components of the SDK are based on: 25 | * lwIP, http://savannah.nongnu.org/projects/lwip/ 26 | * Contiki, http://www.contiki-os.org/ 27 | * axTLS, http://axtls.sourceforge.net/ 28 | * wpa_supplicant, http://w1.fi/wpa_supplicant/ (source withheld by Espressif) 29 | * net80211/ieee80211 (FreeBSD WiFi stack), 30 | http://www.unix.com/man-page/freebsd/9/NET80211 31 | (source withheld by Espressif) 32 | 33 | Building 34 | ======== 35 | 36 | To build the standalone SDK and toolchain, you need a GNU/POSIX system 37 | (Linux, BSD, MacOSX, Windows with Cygwin) with the standard GNU development 38 | tools installed: gcc, binutils, flex, bison, etc. For Ubuntu 14.04 39 | run: 40 | 41 | ``` 42 | $ sudo apt-get install make unrar autoconf automake libtool gcc g++ gperf \ 43 | flex bison texinfo gawk ncurses-dev libexpat-dev python sed 44 | ``` 45 | 46 | For other Debian/Ubuntu versions, dependencies may be somewhat different. 47 | E.g. you may need to install libtool-bin, etc. 48 | 49 | The project can be built in two modes: 50 | 51 | 1. Where the toolchain and tools are kept separate from the vendor IoT SDK 52 | which contains binary blobs. This makes licensing more clear, and helps 53 | facilitate upgrades to vendor SDK releases. 54 | 55 | 2. A completely standalone ESP8266 SDK with the vendor SDK files merged 56 | into the toolchain. This mode makes it easier to build software (no 57 | additinal `-I` and `-L` flags are needed), but redistributability of 58 | this build is unclear and upgrades to newer vendor IoT SDK releases are 59 | complicated. This mode is default for local builds. Note that if you 60 | want to redistribute the binary toolchain built with this mode, you 61 | should: 62 | 63 | 1. Make it clear to your users that the release is bound to a 64 | particular vendor IoT SDK and provide instructions how to upgrade 65 | to a newer vendor IoT SDK releases. 66 | 2. Abide by licensing terms of the vendor IoT SDK. 67 | 68 | To build the separated SDK: 69 | 70 | ``` 71 | $ make STANDALONE=n 72 | ``` 73 | 74 | To build the standalone SDK: 75 | 76 | ``` 77 | $ make STANDALONE=y 78 | ``` 79 | 80 | This will download all necessary components and compile them. Once done, 81 | the toolchain (with the Xtensa HAL library) will be available in the 82 | `xtensa-lx106-elf/` directory. Add its `bin/` subdirectory to your 83 | `$PATH` to execute `xtensa-lx106-elf-gcc` and other tools. 84 | 85 | ESP8266 SDK will be installed in `sdk/`. If you chose the non-standalone 86 | SDK, run the compiler with the corresponding include and lib dir flags: 87 | 88 | ``` 89 | $ xtensa-lx106-elf-gcc -I$(THISDIR)/sdk/include -L$(THISDIR)/sdk/lib 90 | ``` 91 | 92 | The extra -I and -L flags are not needed when using the standalone SDK. 93 | 94 | Pulling updates 95 | =============== 96 | The project is updated from time to time, to update and prepare to 97 | build a new SDK, run: 98 | 99 | ``` 100 | $ make clean 101 | $ git pull 102 | $ git submodule update 103 | ``` 104 | 105 | If you don't issue `make clean` (which causes toolchain and SDK to be 106 | rebuilt from scratch on next `make`), you risk getting broken/inconsistent 107 | results. 108 | 109 | Additional configuration 110 | ======================== 111 | 112 | You can build a statically linked toolchain by uncommenting 113 | `CT_STATIC_TOOLCHAIN=y` in the file `crosstool-config-overrides`. More 114 | fine-tunable options may be available in that file and/or Makefile. 115 | -------------------------------------------------------------------------------- /c_types-c99.patch: -------------------------------------------------------------------------------- 1 | This patch fixes vendor SDK header "c_types.h" for C99 compatibility. 2 | 3 | diff -ur esp_iot_sdk_v0.9.4.org/include/c_types.h esp_iot_sdk_v0.9.4/include/c_types.h 4 | --- esp_iot_sdk_v0.9.4.org/include/c_types.h 2014-12-19 18:07:46.000000000 +0200 5 | +++ esp_iot_sdk_v0.9.4/include/c_types.h 2015-01-17 19:43:49.258975759 +0200 6 | @@ -6,6 +6,9 @@ 7 | #ifndef _C_TYPES_H_ 8 | #define _C_TYPES_H_ 9 | 10 | +#include 11 | +#include 12 | +#if 0 13 | typedef unsigned char uint8_t; 14 | typedef signed char sint8_t; 15 | typedef signed char int8_t; 16 | @@ -20,6 +23,7 @@ 17 | typedef unsigned long long u_int64_t; 18 | typedef float real32_t; 19 | typedef double real64_t; 20 | +#endif 21 | 22 | typedef unsigned char uint8; 23 | typedef unsigned char u8; 24 | @@ -78,10 +82,10 @@ 25 | #endif /* ICACHE_FLASH */ 26 | 27 | #ifndef __cplusplus 28 | -typedef unsigned char bool; 29 | +//typedef unsigned char bool; 30 | #define BOOL bool 31 | -#define true (1) 32 | -#define false (0) 33 | +//#define true (1) 34 | +//#define false (0) 35 | #define TRUE true 36 | #define FALSE false 37 | 38 | -------------------------------------------------------------------------------- /crosstool-config-overrides: -------------------------------------------------------------------------------- 1 | # Building static toolchain causes problems on some distros which 2 | # by default don't install static libs for all required dependencies 3 | #CT_STATIC_TOOLCHAIN=y 4 | CT_LIBC_NEWLIB_ENABLE_TARGET_OPTSPACE=y 5 | 6 | --------------------------------------------------------------------------------