mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
Created Compiling esp32 port with docker (markdown)
76
Compiling-esp32-port-with-docker.md
Normal file
76
Compiling-esp32-port-with-docker.md
Normal file
@@ -0,0 +1,76 @@
|
||||
The esp32 port requires a configured ESP IDF development environment to compile. Espressif provide a docker container that has this all set up and ready to go which can be used to simplify building the firmware, particularly if you want to try building under different IDF versions.
|
||||
|
||||
This script can be used as a wrapper to automate the process of running the compile inside the appropriate docker container without needing any additional configuration of your pc. This works with linux or windows/wsl2 with the official docker tools installed.
|
||||
|
||||
``` bash
|
||||
cat << "EOF" > ~/.local/bin
|
||||
#!/bin/bash
|
||||
SCRIPTPATH=$(readlink --canonicalize-existing "${BASH_SOURCE[0]}")
|
||||
|
||||
# Wrapper script to build / flash esp32 boards inside the official ESP IDF docker container
|
||||
# Examples
|
||||
# esp-compile <IDF_VER> <BOARD> <port to deploy>
|
||||
# esp-compile v5.0.4 ESP32_GENERIC /dev/ttyACM0
|
||||
# esp-compile v5.2.2 ESP32_GENERIC
|
||||
# esp-compile v5.2.2 ESP32_GENERIC_C3 /dev/ttyACM0
|
||||
# esp-compile v5.2.2 ESP32_GENERIC_C3 clean
|
||||
|
||||
|
||||
if [ ! -f /.dockerenv ]; then
|
||||
# If not running in docker container, parse arguments then re-run this same script inside a new esp idf container
|
||||
|
||||
if [ "$1" == "" ]; then echo "$0 IDF_VER BOARD <DEPLOY_PORT> <clean>"; exit; fi
|
||||
IDF_VER=$1
|
||||
BOARD=$2
|
||||
DEPLOY_PORT=$3
|
||||
CLEAN=$([ "${@: -1}" == "clean" ] && echo "1")
|
||||
CD=$(pwd)
|
||||
|
||||
docker run -it --rm \
|
||||
-e BOARD=$BOARD -e CLEAN=$CLEAN -e DEPLOY_PORT=$DEPLOY_PORT -e UID=$(id -u) \
|
||||
-v "$CD":"$CD" -v"$SCRIPTPATH":"$SCRIPTPATH" -v /sys/bus:/sys/bus -v /dev:/dev \
|
||||
--net=host --privileged -w "$CD" espressif/idf:$IDF_VER bash "$SCRIPTPATH"
|
||||
|
||||
else
|
||||
# Now we're running inside the IDF container
|
||||
|
||||
if [ "$(id -u)" != "$UID" ]; then
|
||||
# create new user with ID that matches the user who called this script (who should own the source tree)
|
||||
useradd -ms /bin/bash -g root -G sudo -u $UID esp;
|
||||
# now re-run this script as that new user
|
||||
# this ensures that created binary files are owned by the calling user
|
||||
su esp -m -c "$SCRIPTPATH"
|
||||
|
||||
else
|
||||
# Now we're inside the container, running as the target user
|
||||
. /opt/esp/entrypoint.sh
|
||||
export HOME=/tmp
|
||||
|
||||
# inform git that we're in a trusted environemnt (container)
|
||||
git config --global --add safe.directory '*';
|
||||
|
||||
if [ ! -e mpy-cross/build/mpy-cross ]; then
|
||||
make -C mpy-cross
|
||||
fi
|
||||
|
||||
if [ "$CLEAN" == "1" ]; then
|
||||
make -C ports/esp32 BOARD=$BOARD clean
|
||||
|
||||
else
|
||||
# Build the firmware
|
||||
make -C ports/esp32 BOARD=$BOARD submodules
|
||||
|
||||
if [ "$DEPLOY_PORT" == "" ]; then
|
||||
# Just build the firmware
|
||||
make -C ports/esp32 BOARD=$BOARD
|
||||
else
|
||||
# build and flash the firmware
|
||||
make -C ports/esp32 BOARD=$BOARD deploy PORT=$DEPLOY_PORT
|
||||
fi
|
||||
|
||||
fi # end of build
|
||||
fi # end of user
|
||||
fi # end of container
|
||||
EOF
|
||||
chmod +x ~/.local/bin
|
||||
```
|
||||
Reference in New Issue
Block a user