Docker image

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Docker image

Post by marfis » Sun May 08, 2016 9:00 pm

I'm on OSX and had some troubles installing the 8266 toolchain. So I thought I gave Docker a try. I came up with this Dockerfile https://gist.github.com/hoihu/bebcb1952 ... 7e235d2fc4 that builds and installs the espopen toolchain and builds micropython for the 8266. Maybe that is helpful for other people who had problems installing the toolchain..

To install (assuming you have docker already installed), copy the dockerfile into a directory and run:

Code: Select all

docker build -t espopen .
be warned: this takes some time to complete - but eventually you should have a a "espopen" docker image that you can use to cross compile your micropython firmware for the ESP8266.

Usage:

Code: Select all

docker run -it espopen bash
opens a bash shell as user "xtensa". From there you can do the usual staff like git update, make etc.

At the moment it's not possible to flash the 8266 board from the container (using the --device argument to share the serial port did not work on my machine). But you can share the resulting firmware file with the /user directory and flash as usual with the native esptool script.

I'm still learning to use docker so any feedback/improvement comments are welcome!

Photon Peddler
Posts: 7
Joined: Tue Jul 08, 2014 5:30 pm
Location: Connecticut, USA

Re: Docker image

Post by Photon Peddler » Mon May 09, 2016 3:14 am

This is great! Thank you.

Based on instructions on Stack Overflow, installation was easy on a Mac with Homebrew:

Code: Select all

$ brew cask install dockertoolbox
...
$ docker-machine create --driver "virtualbox" Docker
...
$ docker-machine start Docker
...
$ eval $(docker-machine env Docker)
$ mkdir ~/Desktop/ESP8266
$ cd ~/Desktop/ESP8266
<Copy Dockerfile to Desktop/ESP8266.>
$ docker build -t espopen .
<Takes an hour or two to build...>
$ docker run -it -v ~/Desktop/ESP8266:/mnt/host espopen bash
<In Docker container now.>
$ cp build/firmware-combined.bin /mnt/host/
$ exit
<No longer in Docker container.>

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Docker image

Post by marfis » Mon May 09, 2016 5:13 am

Glad to see it has worked for you.

I forgot to mention one obvious thing: The dockerfile can be used on any OS where docker runs. So Windows users might also try it out... The container itself runs on ubuntu14.04.

It might also be useful on linux since the container provides a separation of your development infrastructure(s) and helps to investigate compatibility issues (e.g. different linux versions).

chrisgp
Posts: 41
Joined: Fri Apr 01, 2016 5:29 pm

Re: Docker image

Post by chrisgp » Tue Oct 04, 2016 8:32 pm

The Dockerfile looks like it is out of date and fails to build. I modified it enough to get it to work for me. I just had to tweak the installed dependencies and add a compilation step for mpy-cross

Code: Select all

FROM ubuntu:14.04

# Don't ask user options when installing
env DEBIAN_FRONTEND noninteractive
RUN echo APT::Install-Recommends "0"; >> /etc/apt/apt.conf
RUN echo APT::Install-Suggests "0"; >> /etc/apt/apt.conf

# multiverse is required by unrar
RUN apt-get -y update && apt-get install -y \
    git \ 
    software-properties-common \
    python-software-properties \
    && add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu precise multiverse" 
    
RUN apt-get update && apt-get install -y \
    unrar-free \
    make \
    autoconf \
    automake \
    libtool \
    libtool \
    gcc \
    g++ \ 
    gperf \
    flex \
    bison \
    texinfo \
    gawk \
    ncurses-dev \
    libexpat-dev \
    python-dev \
    python \
    python-serial \
    sed \
    unzip \
    bash \
    help2man \
    wget \
    bzip2

## Clean apt cache
RUN apt-get -y autoremove && \
    apt-get -y clean && \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /tmp/*

# create user xtensa
RUN useradd -ms /bin/bash xtensa
USER xtensa
WORKDIR /home/xtensa

ENV PATH /home/xtensa/esp-open-sdk/xtensa-lx106-elf/bin:$PATH

# GIT checkout and make toolchain
RUN git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
WORKDIR /home/xtensa/esp-open-sdk
RUN make

## if you want to build the 8266 uPy fw:
WORKDIR /home/xtensa
RUN git clone --recursive https://github.com/micropython/micropython.git
WORKDIR /home/xtensa/micropython
run make -C mpy-cross
WORKDIR /home/xtensa/micropython/esp8266
RUN make axtls
RUN make

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Docker image

Post by marfis » Wed Oct 05, 2016 3:36 am

I have also inluded this change and restructered things slightly. I missed to post an update, sorry:

https://github.com/hoihu/projects/tree/ ... er/esp8266

there is a readme that explains things.

Regarding flashing via RFC2217 (tcp-serial bridge). unfortunatly, using the huzzah boards this does not work without tinkering the HW autoreset circuit (well- just remove it, it is causing a raise conditions if the control lines have a delay). I described this on the adafruit support here:
https://forums.adafruit.com/viewtopic.p ... 93#p483993

basically as I understand adafruit the circuit is there to support the arduino monitor program... well...

So unfortunately you have to settle to copy over your build files to the host machine by sharing volumes (as described in the readme) and flash from there.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Docker image

Post by marfis » Wed Oct 05, 2016 4:42 am

I just saw that I haven't added the mpy-cross target... I 'll update this asap.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Docker image

Post by marfis » Wed Oct 05, 2016 7:04 pm

pushed a fix to resolve mpy-cross build

electronicsguy
Posts: 7
Joined: Thu Oct 22, 2015 1:22 am
Contact:

Re: Docker image

Post by electronicsguy » Tue Jan 31, 2017 1:47 pm

Great effort. Could you explain why I should use Docker though, instead of just installing the tool-chain once say on my linux machine?

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Docker image

Post by marfis » Wed Feb 01, 2017 6:22 am

numerous points.. a lot of them you'll find on google.

it isolates your cross dependencies. you can run an ubuntu image on osx similar like a VM but without the additional overhead of a full fledged VM.

The dockerfile is also self-describing. if you ever need to reinstall your system, just use the dockerfile and you are fine. basically replaces any "installation how-to notes".

Need to test the toolchain on another OS/linux/python version? no problem.

there are disadvantages too. you need to keep track of your running images. the files from the docker container cannot be edited with your favorite editor since they are not visible e.g. in finder (you can use a shared folder to steer around this issue). not every program is suitable to be run in a container (for example any graphical programs that need a GUI).

Post Reply