Search code examples
arduinoesp8266esp32esp-idfesptool

What does "stub" mean in the context of ESP32 and esptool option --no-stub?


I want to program a board with an esp32 on it using esp-prog and esptool. When I do that I get the following error:

...
Crystal is 40MHz
MAC: c8:2b:96:b8:e7:e0
Uploading stub...
Running stub...
Traceback (most recent call last):
File "/home/martin/workspace/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 3470, in <module> _main()
...

But if I use esptool with the option --no-stub, I can program the board without an error. So what is this stub? For what is it for and what does it mean to use --no-stub?


Solution

  • In software development, a stub is a piece of code or a program which is used in place of another. They often simulate the behavior of the original feature and sometimes they are used as a temporaro substitute for undeveloped code.

    In the case of esptool, it uses a stub loader, which basically replaces the original bootloader used in the ESP to load your program via serial port to the ROM of your ESP32 device.

    Basically this stub bootloader has the same behavior as the original bootloader, but it uses some UART routines which are more heavily optimised to load the ROM code.

    Using --no-stub you will be using the original ESP32 bootloader, which is known to be slower at flashing the program and at some other operations. There are some commands which can only be used in the esptool bootloader, but if you are not using any optional commands to boot your code, it is safe to use --no-stub