Skip to main content
Custom made - Sometimes, it is nice to be able to build custom made things. Thanks to Damien George and all the clever people at micropython.org for making it easy. So that, to custom build a micropython is not that difficult.

Why do you want to build customize firmware anyway? Well, you might want to include some functionalities of your own and removed some functionalities from the standard distribution.

The choices are there for you to make.

I have a few changes that I want to make in micropython.
  1. version header -kaki5 (pronounce kaki-lima)
  2. an additional thread cleanup function for esp32
  3. add frozen modules CryptoXo and uasyncio
  4. remove help, upip, and webrepl
  5. camera C module for esp32 camera board

These are accomplished by modifying and adding files.
  1. py/makeversionhdr.py
  2. py/modthread.c
  3. extra/CryptoXo.py, extra/uasyncio.py, and manifest.py
  4. mpconfigport.h
  5. main.c and modcamera.c

I also want to remove some modules specifically, help, upip, and webrepl from esp32, esp23-cam and esp8266 firmware, to reduce their built size.

Modification to Makefile, mpconfigport.h, mpthreadport.c, and boards/sdkconfig.base are needed for some specific ports.

I have made simple scripts, to clone micropython and esp-idf, patch the
necessary files for custom build and run make for ports listed under:

  1. esp32-cam
  2. esp32
  3. esp8266
  4. esp8266_512K
  5. unix
  6. windows

The scripts mpb.py will create a working directory for today in YYYYMMDD format. Git clone micropython under this directory. Copy and all ports for custom build and patch files using copy 'cp -rfv' files from Custommade_Template directory.

I know that I am abusing the GIT server as an FTP server by cloning the whole micropython master branch each time. Those who know git will probably say, "why not use git pull?" The whole micropython source is about 75 megabytes, which is not that large. It is simpler this way.

After running the mpb.py and if everything went ok, then you can run mpc.py. This script will copy all compiled firmware and micropython binary files to a staging area.

The script mpb.py will ask you to run esp.py script if a valid version of esp-if is not available. The esp.py will download and update the correct
esp-idf together with the camera component.

There are a few things you need to change in these files. The value of mpc_dir is the directory path where you want to copy your compiled binaries. You also need to change PATH values at a different stage of the build script. For esp32 you need xtensa-esp32-elf tools and for esp8266 you need xtensa-lx106-elf.

I have packed all the necessary files in a zip file, custommade.zip. You can download it from GitHub. Unzipping this zip file, a top directory MP will be created. You can then cd MP and run mpb.py. If needed, you may have to run esp.py to fix esp-if dependency. After you have a valid esp-idf installed, you can run mpb.py again so that you can make your custom build MicroPython.

Mind you, I did all this just for fun. I have not studied the micropython build structure and mechanism in detail. Future distributions may not build using this setup. I can not guarantee the usefulness and correctness of the compiled binaries, either.

I have flashed and run some simple test scripts on a few esp8266, esp32 and esp32-cam boards. They work. I have not done any rigorous testing, just that they boot up ok, import modules, and run simple test scripts.

You'd be better off downloading the official firmware from micropython.org if a standard firmware is what you need.

Comments

  1. Thank you for this information. I just installed one of your newest Micropython firmware builds from github om my AI-Thinker ESP32-CAM and it works fine. Does this method as described above still apply for building Micropython for ESP32-CAM? I would like to try it by myself.

    ReplyDelete

Post a Comment

Popular posts from this blog

Multi-threading : I previously used an uasyncio webcam server. This time around, I am testing a multi-thread webcam server. The result is promising. A multi-thread server seems to give a better throughput. The program logic is simpler when compared to the server based on uasyncio. The server is a four threaded application, two for port 80, one for port 81, and port 82 runs on the main thread, which blocks the REPL.  You can start a dedicated thread for port 82 if you do not want to block the REPL. I found pix/7 gives the best performance. A spe/2 will reduce the image size but give you a grayscale image. Please see my previous blog if all these seem mysterious to you. I have compiled a new firmware, MicroPython v1.11-571-g7e374d231.  You can download the new firmware from my repository at GitHub. The soft reset is not functioning properly. You need to do a hard reset. I also include four new functions in modcamera.c: pixformat agcgain aelevels aecvalue The pixformat chan
Micropython - v1.11-498 introduced a few changes in the source-code directory structure. Changes to specific files, as previously described in esp32-cam , will no longer work. A simple working summary on how to build esp32-cam firmware is described below: Make a recursive copy of ports/esp32 to ports/esp32-cam, and you will need to modify the following files: 1) ports/esp32-cam/main.c 2) ports/esp32-cam/Makefile 3) ports/esp32-cam/modcamera.c 4) ports/esp32-cam/mpconfigport.h 5) ports/esp32-cam/boards/manifest.py 6) ports/esp32-cam/boards/sdkconfig.base Or, you can just download a precompiled Micropython v1.11-498 from firmware.bin at GitHub if you want to save some work. However, I encourage you to compile the firmware yourself. You will learn a lot and you can choose to modify anything to your liking. The modcamera.c includes something new. The still photo was taken using these settings; pix =8, con =2, qua =10, and spe =2. You will understand those parameters, later