1.git 官方的micropython库(默认在root目录下执行)
git clone https://github.com/micropython/micropython.git
2.对需要的模块进行修改,在ports/esp8266/modules 文件下创建的python文件都会被编译到固件中(bbb.py 到时候引入 import bbb),若是文件夹 lis下的 a.py文件,到时候访问时 import lis.a
3.使用docker安装官方的镜像,进行编译(若第二步git在root下 ,那文件就是 root/micropython 即~/micropython)
DOCKER:
docker run -it --rm -v ~/micropython:$HOME -u $UID -w $PWD larsks/esp-open-sdk bash
进入docker的mpy编译系统之后
make -C mpy-cross
然后 转到ports/esp8266目录进行编译
$ cd ports/esp8266 #转到esp8266目录
$ make submodules #初始化模块
$ make -j BOARD=ESP8266_GENERIC
#进行交叉编译,保存到ports/esp8266下的build-ESP8266_GENERIC文件夹下的firmware.bin固件,若该文件夹存在,则无法编辑,可以先删除
$ exit
#退出docker的mpy编译界面
注意:
1.无法放入非python文件在modules中,modules中的文件无法使用open()去读取
2.若需要对不同esp8266进行编译(esp8266默认4MBFlash ESP01S为1MB 则需要设置)
#在执行make -j BOARD=ESP8266_GENERIC前先设置大小
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_512K
#设置flash为512KB
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_1M
#设置flash为1MB,esp01s编译mpy固件,请选择该语句设置。
全自动设置:
$ cd ~/micropython
#先设置到micropython目录下
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -C mpy-cross
$ cd ports/esp8266
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=ESP8266_GENERIC
Building with Docker
Once you have installed Docker, you can run all of the following build commands inside the Docker container by prefixing them with docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk ...command...
. This will automatically download the Docker image provided by @larsks which contains the full toolchain and SDK.
Then you need to compile the MicroPython cross-compiler (mpy-cross
). From the root of this repository, run:$ docker run –rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -C mpy-cross
Note: The mpy-cross
binary will likely only work inside the Docker container. This will not be a problem if you’re only building ESP8266 firmware, but if you’re also working on other ports then you will need to recompile for your host when switching between ports. To avoid this, use the local toolchain instead.
Then to compile the ESP8266 firmware:
$ cd ports/esp8266
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=ESP8266_GENERIC
全自动设置
1.选择上传的python模块,记录下来,上传到对应的开发板【esp8266 esp32】的modules上面,并在数据库中标记,等待完成编译后删除。
2.shell执行脚本
#esp8266为例子,micropython文件存放在root下【请删除ESP8266_GENERIC】
#! /bin/bash
cd ~/micropython
docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -C mpy-cross
cd ports/esp8266
if [ ! -f "build-ESP8266_GENERIC" ];then
echo "文件不存在,执行编译"
else
rm -rf build-ESP8266_GENERIC
fi
docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=ESP8266_GENERIC