PicoLibc adds hooks for ESP8266/ESP32 builds

Keith Packard has been putting in a lot of work over the past few months on PicoLibc, his lightweight libc replacement, which is specifically aimed at memory-limited embedded systems.  Keith has been steadily increasing the functionality of PicoLibc and has attracted some additional contributors along the way.  One of those contributors, Jonathan McDowell in Belfast, has just added the hooks for compiling xtensa-lx106-elf binaries.  Jonathan notes that it has been tested on an ESP8266 with the 2.2.1 + 3.0.1 Espressif NONOS SDKs + GCC 9.2.1 from Debian.

Over at CNX Software, Siji Sunny recently put together a (non-ESP specific) description of how to configure, compile and build code using PicoLibc under Linux, so it should now be possible (with Jonathan’s additions) to cross-compile for the ESP8266 using that handy guide.  In the meantime, Keith is continuing with additional work on integration of the ESP8266 and ESP32 targets.

ESP-SDK missing includes and libs…

Espressif seem to take a minimalistic approach to publishing new versions of their SDK …if you’ve seen stuff before in a previous version of the SDK, you may not get it (even though you still need it) in the latest version that they publish.  This usually manifests itself as complaints from the compiler such as “stdio.h not found“, or a linker error “Cannot find -lhal“.   My fix for this is particularly inelegant and clunky; I simply copied the missing includes from an old version of the SDK into a directory called “extra_includes” and likewise with the library files, a directory named “extra_libs” and I modify the Makefile of every project I git-clone to include those extra directories as required.

The obvious issue with this is that every project needs to be modified not only when cloning, but on any subsequent git-pull where the source Makefile has been updated by the author.  A simpler fix would be to check the contents of each new revision of the SDK and link in the missing components from the existing “extra” directories (linking rather than copying so that it’s easy to identify those files and remove them, if necessary, at some later date and also because linking has the beneficial property of not overwriting a file if it already exists).  What I should do is bang together a shell script to make linking into a new version of the SDK a semi-automatic process (but, as one of my current ESP8266 heroes, Sprite_tm, is fond of saying in his comments, /* I can't be arsed. */).

Martin Harizanov, who’s work I mentioned in a previous blog, has a slightly different method for the includes.  He ships an extra include file, include/espmissingincludes.h, with his projects, which has all of the missing function prototypes defined in it.

Of course, the best method to resolve the issue would be for Espressif to ship the whole SDK as a complete revision instead of in dribs-and-drabs.