# ESP8266 Software

This document describes how to build the ESP8266 micropython port,
flash that firmware onto the chip, modify the firmware to include
your own scripts, etc.

## Installing MicroPython

We will need the source code of the micropython distribution when
we want to include our own scripts and the toolchain to cross compile
it all:

```
$ git clone https://github.com/micropython/micropython.git
$ git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
```

Follow the instructions in `esp-open-sdk` in order to install its dependencies.
To build the ESP SDK: `cd esp-open-sdk && make`. More details and configuration
options in the `README`. Add the directory containing the built executables
to your PATH:
```
export PATH=/path/to/esp-open-sdk/xtensa-lx106-elf/bin:$PATH
```
(Last time Tim built esp-open-sdk from scratch on archlinux was revision
b1929e33f41c4bd9.)

Switch to the MicroPython directory: `cd .. && cd micropython`

Update/fetch all required submodules: `git submodule update --init` and compile
some top-level code with `make -C mpy-cross`. Now switch to the `esp8266`
subdirectory and build the firmware: `cd esp8266 && make axtls && make`.
Check the `build/` subdirectory for your new firmware.

## Flash firmware onto esp8266

More detailed instructions in the MicroPython documentation. This is an
abridged version:
```
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 micropython/esp8266/build/firmware-combined.bin
```
This will flash the firmware in the `esp8266/` subdirectory of micropython onto
your chip. If this is the first time you are flashing new firmware the docs
recommend you first run `esptool.py --port /dev/ttyUSB0 erase_flash`.

To connect to your newly flashed chip run (and after hit the RST button):
```
$ screen /dev/ttyUSB0 115200
MicroPython v1.8.7-219-g0c821f7d on 2017-02-14; ESP module with ESP8266
Type "help()" for more information.
>>>
```
which should welcome you with a message similar to this. Including today's date
as the date on which the firmware was built.

Add documentation on flashing ESP8266s
Add documentation on flashing ESP8266s
