First, the video!
What has been achieved
After a long way of hacking and debugging my native code emitter in the OCaml compiler, I’ve finally come to build and run the first example in Mirage unikernels! I’m able to build a whole Mirage project and run it on an ESP32 with 4Mb of extended RAM. It’s more of a proof of concept, this probably doesn’t work out of the box as I hacked a lot of things on the way. I tried to explain what I did in the bottom of this article but maybe I forgot some steps.
The whole example size is:
- Flash code: 917942 bytes
- Flash rodata: 473868 bytes
- Static data-RAM: 66324 bytes (36.7% used)
- Static instruction-RAM: 43661 bytes (33.3% used)
I’ll be working on getting runtime informations in order to see how hard it would be to run Mirage unikernels on ESP32 without additional RAM. Right now it goes out of memory in the startup code, as it tries to allocate 128kb of frame table (whereas 178kb of dynamic memory is available in total).
Every mirage package needed to build a hello world example has been ported in this
opam-cross-esp32 OPAM repository. It’s available on Github.
There are some other packages for ESP32 development:
- esp32-toolchain-gcc: xtensa-esp32-elf- prefixed binutils set up in path, located in (xtensa-esp32-elf) subdirectory in the switch.
- ocaml-esp32: the cross-compiler, needed to build almost every other package. It’s installed in a subdirectory (esp32-sysroot) in the switch.
- esp32-idf-headers: updates the compiler include path to contain the ESP32 IDF headers.
- mirage-esp32: mirage runtime implementation for esp32.
- ctypes-esp32: ctypes implementation for esp32, using libffi. But it’s useless as dynamic linking is not supported.. I will use cstubs generation in the future.
The compiler has now a full native backend to esp32 targets. It’s indeed subject to a lot of optimizations as it’s a first running draft. Available here
Stubs and OS interface for esp32 platform. Available here
Adds an esp32 target in mirage configuration tool. It’s not working as intended though. Available here
The first mirage sample to fully run on ESP32. Available here
There remains hacks to do, and it’s not intended to work out-of-the-box right now.
bigarrayMETA to remove
mirage-profileMETA to remove
num-esp32needs to be built twice
mirage config -t esp32needs to be worked on, and should generate the correct jbuild file.
esp32-idf-headersdoesn’t install every headers in the root as intended. A
mv include/* .and
mv includes/* .in
<switch>/xtensa-esp32-elf/xtensa-esp32-elf/includeis needed to finish the installation.