Skip to content

Commit 09879f9

Browse files
jimmodpgeorge
authored andcommitted
esp8266/README: Update build instructions to match ci.sh.
The existing non-Docker instructions are basically impossible to follow because the esp-open-sdk does not compile. Update these instructions to use the exact toolchain that our CI uses. Also split the Docker from non-Docker instructions, to avoid confusion about which commands need to be prefixed. Signed-off-by: Jim Mussared <[email protected]>
1 parent 6dcfb25 commit 09879f9

File tree

1 file changed

+86
-30
lines changed

1 file changed

+86
-30
lines changed

ports/esp8266/README.md

Lines changed: 86 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,60 +27,116 @@ Documentation is available at http://docs.micropython.org/en/latest/esp8266/quic
2727
Build instructions
2828
------------------
2929

30-
You need the esp-open-sdk toolchain (which provides both the compiler and libraries), which
31-
you can obtain using one of the following two options:
32-
33-
- Use a Docker image with a pre-built toolchain (**recommended**).
34-
To use this, install Docker, then prepend
35-
`docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk ` to the start
36-
of the mpy-cross and firmware `make` commands below. This will run the commands using the
37-
toolchain inside the container but using the files on your local filesystem.
38-
39-
- or, install the esp-open-sdk directly on your PC, which can be found at
40-
<https://github.com/pfalcon/esp-open-sdk>. Clone this repository and
41-
run `make` in its directory to build and install the SDK locally. Make sure
42-
to add toolchain bin directory to your PATH. Read esp-open-sdk's README for
43-
additional important information on toolchain setup.
44-
If you use this approach, then the command below will work exactly.
45-
46-
Add the external dependencies to the MicroPython repository checkout:
30+
You need the esp-open-sdk toolchain, which provides both the compiler and libraries.
31+
32+
There are two ways to do this:
33+
- By running the toolchain in [Docker](https://www.docker.com/) (**recommended**).
34+
- By installing a pre-built toolchain and adding it to your `$PATH`.
35+
36+
Regardless of which toolchain you use, the first step is to make sure required
37+
submodules are available:
38+
4739
```bash
4840
$ make -C ports/esp8266 submodules
4941
```
42+
5043
See the README in the repository root for more information about external
5144
dependencies.
5245

53-
The MicroPython cross-compiler must be built to pre-compile some of the
54-
built-in scripts to bytecode. This can be done using:
46+
__Building with Docker__
47+
48+
Once you have installed Docker, you can run all of the following build
49+
commands inside the Docker container by prefixing them with `docker
50+
run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk ...command...`.
51+
This will automatically download the Docker image provided by @larsks which
52+
contains the full toolchain and SDK.
53+
54+
Then you need to compile the MicroPython cross-compiler (`mpy-cross`). From
55+
the root of this repository, run:
56+
5557
```bash
56-
$ make -C mpy-cross
58+
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -C mpy-cross
59+
```
60+
61+
**Note:** The `mpy-cross` binary will likely only work inside the Docker
62+
container. This will not be a problem if you're only building ESP8266
63+
firmware, but if you're also working on other ports then you will need to
64+
recompile for your host when switching between ports. To avoid this, use
65+
the local toolchain instead.
66+
67+
Then to compile the ESP8266 firmware:
68+
69+
```
70+
$ cd ports/esp8266
71+
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=GENERIC
72+
```
73+
74+
This will produce binary images in the `build-GENERIC/` subdirectory.
75+
Substitute the board for whichever board you're using.
76+
77+
__Building with a local toolchain__
78+
79+
First download the pre-built toolchain (thanks to @jepler from Adafruit). You
80+
will need to find somewhere to put it in your filesystem, e.g. `~/espressif`.
81+
Create that directory first if necessary.
82+
83+
```
84+
$ cd ~/espressif # Change as necessary
85+
$ wget https://github.com/jepler/esp-open-sdk/releases/download/2018-06-10/xtensa-lx106-elf-standalone.tar.gz
86+
$ tar zxvf xtensa-lx106-elf-standalone.tar.gz
87+
$ rm xtensa-lx106-elf/bin/esptool.py # Use system version of esptool.py instead.
88+
```
89+
90+
Then append this to your `$PATH` variable so the compiler binaries can be
91+
found:
92+
93+
```
94+
$ export "PATH=$HOME/espressif/xtensa-lx106-elf/bin/:$PATH"
5795
```
58-
(Prepend the Docker command if using Docker, see above)
5996

60-
Then, to build MicroPython for the ESP8266, just run:
97+
(You will need to do this each time you start a new terminal)
98+
99+
Then you need to compile the MicroPython cross-compiler (`mpy-cross`). From
100+
the root of this repository, run:
101+
61102
```bash
103+
$ make -C mpy-cross
104+
```
105+
106+
Then to compile the ESP8266 firmware:
107+
108+
```
62109
$ cd ports/esp8266
63-
$ make
110+
$ make -j BOARD=GENERIC
64111
```
65-
(Prepend the Docker command if using Docker, see above)
66112

67-
This will produce binary images in the `build-GENERIC/` subdirectory. If you
68-
install MicroPython to your module for the first time, or after installing any
69-
other firmware, you should erase flash completely:
113+
This will produce binary images in the `build-GENERIC/` subdirectory.
114+
Substitute the board for whichever board you're using.
115+
116+
117+
Installing MicroPython
118+
----------------------
119+
120+
To communicate with the board you will need to install `esptool.py`. This can
121+
be obtained from your system package manager or from PyPi via `pip`.
122+
123+
If you install MicroPython to your module for the first time, or after
124+
installing any other firmware, you should erase flash completely:
125+
70126
```bash
71127
$ esptool.py --port /dev/ttyXXX erase_flash
72128
```
73129

74-
You can install esptool.py either from your system package manager or from PyPi.
75-
76130
Erasing the flash is also useful as a troubleshooting measure, if a module doesn't
77131
behave as expected.
78132

79133
To flash MicroPython image to your ESP8266, use:
80134
```bash
81135
$ make deploy
82136
```
83-
(This should not be run inside Docker as it will need access to the serial port.)
137+
138+
(If using the Docker instructions above, do not run this command via Docker as
139+
it will need access to the serial port. Run it directly instead.)
84140

85141
This will use the `esptool.py` script to download the images. You must have
86142
your ESP module in the bootloader mode, and connected to a serial port on your PC.

0 commit comments

Comments
 (0)