2018-05-04

# 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).

# opam-cross-esp32

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.

# ocaml-esp32

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

# mirage-esp32

Stubs and OS interface for esp32 platform. Available here

# mirage

Adds an esp32 target in mirage configuration tool. It's not working as intended though. Available here

# hello_mirage

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.

  • Update bigarray META to remove unix dependency.
  • Update mirage-profile META to remove ppx_tools_versioned dependency.
  • num-esp32 needs to be built twice
  • mirage config -t esp32 needs to be worked on, and should generate the correct jbuild file.
  • esp32-idf-headers doesn't install every headers in the root as intended. A mv include/* . and mv includes/* . in <switch>/xtensa-esp32-elf/xtensa-esp32-elf/include is needed to finish the installation.