0x0 编译前须知

环境:Ubuntu 18.04 WSL
最好有梯子,配合proxychains来编译,或者直接使用vultr的机子来。
建议不要用root用户

0x01 配置必要环境

sudo apt install gcc make git wget curl flex bison gperf python-serial libncurses5-dev python3-pip python-pip python python3

0x02 下载代码及相关工具

mkdir micropython
cd micropython
git clone --recursive https://github.com/espressif/esp-idf.git
git clone --depth=50 --branch=master https://github.com/micropython/micropython.git 
curl -L https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz | tar zxf 
wget https://cdn.jsdelivr.net/gh/ITJoker233/Blog/esp32-cam.tar.xz
mkdir esp32-cam
tar -xzvf esp32-cam.tar.gz -C esp32-cam
sudo pip3 install 'pyparsing<2.4' pyserial

0x03 linux 环境变量里添加路径

cd
export PATH="$PWD/micropython/xtensa-esp32-elf/bin:~/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export ESPIDF="$PWD/micropython/esp-idf"
export MPTD="$PWD/micropython/esp32-cam"

0x04 编译mpy-cross

cd micropython/micropython
make -C mpy-cross

0x05 esp-idf切换到v4.0,并更新子模块

cd ..
git -C esp-idf checkout $(grep "ESPIDF_SUPHASH_V4 :=" micropython/ports/esp32/Makefile | cut -d " " -f 3)
git -C esp-idf submodule update --init
git -C micropython submodule update --init
cd esp-idf/components
git clone https://github.com/espressif/esp32-camera.git

0x06 编译esp32-cam

cd ../..
make -C micropython/ports/esp32 submodules -j4
cp -r micropython/ports/esp32 micropython/ports/esp32-cam
cd micropython/ports/esp32-cam
cp $MPTD/Makefile .
cp $MPTD/modcamera.c .
cp $MPTD/mpconfigport.h .
cp $MPTD/boards/manifest.py ./boards/manifest.py
cp $MPTD/boards/sdkconfig.base ./boards/sdkconfig.base
make clean
make V=1 -j4

如果没有报错应该大功告成了 XD....

如果出现编译错误,例如缺少xxx.c文件,尝试修改编译目录下的Makefile,具体思路如下:

对比Makefile

$MPTD/Makefile #我的提供的文件
../esp32/Makefile  #esp32目录下的Makefile

搜索关键词cam,大概会有12处可以匹配到。
然后把那整行或整段的添加到相应的位置。