Install ESP8266 SDK toolchain on Linux (Ubuntu 14.10 Desktop)
It seems that a large part of the ESP8266 community has moved to the esp-open-sdk toolchain. And for a reason: the esp-open-sdk is much easier to install and update. Besides that, the esp-open-sdk replaes many of the proprietary libraries with open source versions.
Just as an exercise, I decided to give this toolchain a try as well, starting with a bare Ubuntu 14.04 (Desktop) installation as its foundation again. It was my goal to make the same blinky run, but this time through the use of the esp-open-sdk toolchain.
By installing the toolchain you can create your own firmware for ESP8266 SOC. Here is the instructions to successfully install the toolchain and ESP8266 SDK. I am using Ubuntu 14.10 desktop.
Install the necessary tools by using the following commands
32-Bit Debian (Linux)
1 2 3 4 |
apt-get install git autoconf build-essential gperf bison flex texinfo libtool libncurses5-dev wget gawk libc6-dev-i386 python-serial libexpat-dev mkdir /opt/Espressif chown $username /opt/Espressif/ |
64-bit Debian (Linux)
1 2 3 4 |
apt-get install git autoconf build-essential gperf bison flex texinfo libtool libncurses5-dev wget gawk libc6-dev-amd64 python-serial libexpat-dev mkdir /opt/Espressif chown $username /opt/Espressif/ |
(replace $username with the name of the local user)
Install the Xtensa crosstool-NG (as local user)
1 2 3 4 5 6 7 |
cd /opt/Espressif git clone -b lx106 git://github.com/jcmvbkbc/crosstool-NG.git cd crosstool-NG ./bootstrap && ./configure --prefix=`pwd` && make && make install ./ct-ng xtensa-lx106-elf ./ct-ng build PATH=$PWD/builds/xtensa-lx106-elf/bin:$PATH |
1 |
Setting up the Espressif SDK
1 2 3 4 5 6 7 |
cd /opt/Espressif wget -O esp_iot_sdk_v0.9.3_14_11_21.zip https://github.com/esp8266/esp8266-wiki/raw/master/sdk/esp_iot_sdk_v0.9.3_14_11_21.zip wget -O esp_iot_sdk_v0.9.3_14_11_21_patch1.zip https://github.com/esp8266/esp8266-wiki/raw/master/sdk/esp_iot_sdk_v0.9.3_14_11_21_patch1.zip unzip esp_iot_sdk_v0.9.3_14_11_21.zip unzip esp_iot_sdk_v0.9.3_14_11_21_patch1.zip mv esp_iot_sdk_v0.9.3 ESP8266_SDK mv License ESP8266_SDK/ |
Patching
1 2 3 4 |
cd /opt/Espressif/ESP8266_SDK sed -i -e 's/xt-ar/xtensa-lx106-elf-ar/' -e 's/xt-xcc/xtensa-lx106-elf-gcc/' -e 's/xt-objcopy/xtensa-lx106-elf-objcopy/' Makefile mv examples/IoT_Demo . |
Installing Xtensa libraries and headers
1 2 3 4 5 6 |
cd /opt/Espressif/ESP8266_SDK wget -O lib/libc.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libc.a wget -O lib/libhal.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libhal.a wget -O include.tgz https://github.com/esp8266/esp8266-wiki/raw/master/include.tgz tar -xvzf include.tgz |
These are binary libraries from the Xtensa SDK.
Installing the ESP image tool
1 2 3 4 |
cd /opt/Espressif wget -O esptool_0.0.2-1_i386.deb https://github.com/esp8266/esp8266-wiki/raw/master/deb/esptool_0.0.2-1_i386.deb dpkg -i esptool_0.0.2-1_i386.deb |
Installing the ESP upload tool
1 2 3 4 |
cd /opt/Espressif git clone https://github.com/themadinventor/esptool esptool-py ln -s $PWD/esptool-py/esptool.py crosstool-NG/builds/xtensa-lx106-elf/bin/ |
Add the PATH variable
1 2 |
export PATH=/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/:$PATH |
Example 1
Blinky, A Community Example
1 2 3 4 5 |
cd /opt/Espressif git clone https://github.com/esp8266/source-code-examples.git cd source-code-examples/blinky make |
You have two built files; firmware/0x00000.bin
and firmware/0x40000.bin
. That’s it! Move on to Uploading to a device, unless you want to try building the examples provided by Espressif.
Uploading
To upload to the module, configure the following pins:
Pin | Level | Description |
---|---|---|
CH_PD | High | Enables the chip |
GPIO0 | Low | Selects UART download boot mode |
GPIO2 | High | Selects UART download boot mode |
GPIO15 | Low | If availble. Selects UART download boot mode |
Uploading the Blinky Example to ESP8266
1 2 3 |
cd /opt/Espressif/source-code-examples/blinky make ESPPORT=/dev/ttyUSB0 flash |
Your device should start toggling GPIO2 a second or so after make
completes.
Example 2
Compiling Espressif’s Examples
Choose one of the examples to build. Either the AT demo, pre-programmed in a lot of devices, or the IoT demo included with the ESP IoT SDK.
The IoT Demo
1 2 3 |
cd /opt/Espressif/ESP8266_SDK/IoT_Demo make |
Preparing the Firmware Image
1 2 3 4 |
cd .output/eagle/debug/image esptool -eo eagle.app.v6.out -bo eagle.app.v6.flash.bin -bs .text -bs .data -bs .rodata -bc -ec xtensa-lx106-elf-objcopy --only-section .irom0.text -O binary eagle.app.v6.out eagle.app.v6.irom0text.bin |
Now you have two files in .output/eagle/debug/image/
One with the application code and data (called eagle.app.v6.flash.bin
)
and
One with SDK code (called eagle.app.v6.irom0text.bin
).
Uploading the IoT Demo to ESP8266
1 2 3 4 |
cd /opt/Espressif/ESP8266_SDK/IoT_Demo cd .output/eagle/debug/image /opt/Espressif/esptool-py/esptool.py --port /dev/ttyUSB0 write_flash 0x00000 eagle.app.v6.flash.bin 0x40000 eagle.app.v6.irom0text.bin |
The procedure is similar for the AT Demo, but the directory is from the make path.
All Commands
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# Install commands for ESp8266 SDK and Toolchain # Ubuntu 14.10 Desktop sudo apt-get -y install git autoconf build-essential gperf bison flex texinfo libtool libncurses5-dev wget gawk libc6-dev-amd64 python-serial libexpat-dev sudo mkdir /opt/Espressif sudo chown $username /opt/Espressif/ cd /opt/Espressif git clone -b lx106 git://github.com/jcmvbkbc/crosstool-NG.git cd crosstool-NG ./bootstrap && ./configure --prefix=`pwd` && make && make install ./ct-ng xtensa-lx106-elf ./ct-ng build PATH=$PWD/builds/xtensa-lx106-elf/bin:$PATH wget -O esp_iot_sdk_v0.9.3_14_11_21.zip https://github.com/esp8266/esp8266-wiki/raw/master/sdk/esp_iot_sdk_v0.9.3_14_11_21.zip wget -O esp_iot_sdk_v0.9.3_14_11_21_patch1.zip https://github.com/esp8266/esp8266-wiki/raw/master/sdk/esp_iot_sdk_v0.9.3_14_11_21_patch1.zip unzip esp_iot_sdk_v0.9.3_14_11_21.zip unzip esp_iot_sdk_v0.9.3_14_11_21_patch1.zip mv esp_iot_sdk_v0.9.3 ESP8266_SDK mv License ESP8266_SDK/ cd /opt/Espressif/ESP8266_SDK sed -i -e 's/xt-ar/xtensa-lx106-elf-ar/' -e 's/xt-xcc/xtensa-lx106-elf-gcc/' -e 's/xt-objcopy/xtensa-lx106-elf-objcopy/' Makefile mv examples/IoT_Demo . cd /opt/Espressif/ESP8266_SDK wget -O lib/libc.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libc.a wget -O lib/libhal.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libhal.a wget -O include.tgz https://github.com/esp8266/esp8266-wiki/raw/master/include.tgz tar -xvzf include.tgz cd /opt/Espressif wget -O esptool_0.0.2-1_i386.deb https://github.com/esp8266/esp8266-wiki/raw/master/deb/esptool_0.0.2-1_i386.deb dpkg -i esptool_0.0.2-1_i386.deb cd /opt/Espressif git clone https://github.com/themadinventor/esptool esptool-py ln -s $PWD/esptool-py/esptool.py crosstool-NG/builds/xtensa-lx106-elf/bin/ export PATH=/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/:$PATH |
More Examples
More examples, like Blinky, can be found on GitHub, https://github.com/esp8266/source-code-examples.