PlatformIO Community

Is there a way to port an esp-idf component to the arduino-esp framework?

Hi,
I’m not sure if this is the right place to ask this but is there a guide or something similar to port/update some components of the arduino-esp framework using the latest esp-idf?

I’m askimg this because the “mdns” component on arduino is broken and only really recent changes in the esp-idf fixed the issues.

When looking through the folders it seems like mdns.c and mdns.h got compiled into mdns.a in the esp-arduino framework.

Is there a way to compile said component from the esp-idf and just “drag and drop” it to the arduino framework?

This is only a temporary fix, until someone properly ports it over.

I’m thankful for any pointers in the right direction :slight_smile:

Have you tried this? If all function APIs stayed the same and only internal fixes were made, and those fixes don’t depend on some bleeding edge newly other added component in ESP-IDF that Arduino-ESP32 doesn’t have, try to replace the tools/sdk/esp32/lib/libmdns.a in <home folder>/.platformio/packages/framework-arduinoespressif32 with an libmdns.a obtained from your latest ESP-IDF build.

1 Like

Yeah from the github commit the fixes where only internal null checks inside of the functions and there wasn’t any additional call to new functions or new functions.

My main question is how to actually obtain the .a file from the latest esp-idf. When I build stuff using it I only get .o files in it’s build folder. (are they interchangeable? or is the .a something else?)

Thanks for answering! :slight_smile:

Hm… I thought the .a files would fall out of a normal ESP-IDF build. Have you made sure that no such .a file exists by using the file search?

Otherwise, the canonical way to generate the libmdns.a (and all other lib files) is to use https://github.com/espressif/esp32-arduino-lib-builder. The main builder script has an -I option for the ESP-IDF branch to use. You can see which one the latest Arduino-ESP32 uses in History for tools/sdk/esp32/lib - espressif/arduino-esp32 · GitHub.

1 Like

I couldn’t find any mdns related .a files in there :frowning:

Thanks for the links, that was the thing I was searching for :slight_smile: !

On an unrelated note:
Does plattformIO use the latest https://github.com/espressif/arduino-esp32 ? because while looking for the other stuff I saw that it only uses an older version. Do new versions first need a port to platformIO, or why is that?

PlatformIO uses stable releases and does not grab unverified, untested versions from their bleeding edge repository. That would be a total disaster for stability. The PlatformIO staffs updates these packages in the internal registry when a new version is released and updates platform-espressif32 accordingly, see Releases · platformio/platform-espressif32 · GitHub. The latest version uses the latest stable version v2.0.3.

Of course, PlatformIO gives you the opportunity to source any package from any source. So with platform_packages,

platform_packages = 
    framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#master

in the platformio.ini it would source it from the Git.

1 Like

Notice how when you download arduino-esp32/libmdns.a at master · espressif/arduino-esp32 · GitHub and open it e.g. in 7zip, the archive file is just a combination of three .o object files

image

So if you find those three object files, you can invoke the archiver (xtensa-esp32-elf-ar) to manually create the archive. Those tools are in <home folder>/.platformio/packages/toolchain-xtensa-esp32/bin, with instructions at UNIX ar Examples: How To Create, View, Extract, Modify C Archive Files (*.a)

xtensa-esp32-elf-ar cr libmdns.a mdns.c.o mdns_console.c.o mbdns_networking_lwip.c.o
# for rebuilding symbol table
xtensa-esp32-elf-ranlib libmdns.a

(they might be called .o or .obj files).

1 Like

Thanks for everything, after some attempts I managed to get the esp32-arduino-lib-builder running.

It sadly seems like a lot more was changed in the background, so a simple drag and drop doesn’t really work :frowning: I will probably try and backport it when I have more time, or just wait until someone else does it first :smiley:

for anyone finding this thread here is the issue on github:

The fix in mdns.c looks trivial: mdns: Fix null-service issue when parsing packets · espressif/esp-idf@a57be7b · GitHub.

Since we know what ESP-IDF version Arduino-ESP32 is using, it should be trivial to fork ESP-IDF from that, patch in that commit that adds like 4 lines, and use the esp32 lib builder to regenerate the libraries. Then nothing major should have changed.

I’ll give that a try.

Okay back here after a bit of sleep.
The reason it didn’t work was because I had some left over stuff in my test project that broke the compilation (like a copy of the mdns folder).

I kind of forgot that, but now the libraries generated using esp32-arduino-lib-builder work.

I’m currently in the process of checking out if the fix actually fixed the issue :slight_smile:

1 Like

okay so last message for now:
just copy and pasting the lines didn’t fix the issue :frowning:
However replacing the whole mdns folder with the latest one fixed the issue :smiley: I either copied something wrong or there were a few other changes that also helped out here. :slight_smile:

I’m now using the esp-idf v4.4.1 with the mdns component from master and also the arduino-esp32 v2.0.3 (as this supports 4.4.1 which is the closest thing to master right now).

So yeah thanks for all the help! :smiley: I didn’t knew the tools for generating those .a files existed, :slight_smile:

Great, so you have afixed libmdns.a now? Could you share it with the people in the issue?

(Or all archives if needed)

yeah I have, though I’m not sure if this is the “correct” way to fix the issue (on there someone mentioned backporting something to the 4.4 branch), but sharing this probably won’t really hurt.

Hi,
I got another question that is to some degree related to this issue, is there a way to create a offline “framework” so to speak?

You said that with this:

platform_packages =
framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.3

I can pull and use a version from github, is there a way to specify a local folder (that is in the same path as the other frameworks just a copy with the name framework-arduinoespressif32@myownltsversion)?

Just use the file:// or symlink:// (latter won’t create a copy) instead of https://. This is a documented feature.

1 Like