After linking, esptool runs twice. On Linux, it's a Python script, python3 /long/path/esptool.py. But on Mac, it's an executable.
$ time ~/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/esptool --chip esp32 elf2image --flash_mode dio --flash_freq 80m --flash_size 4MB --elf-sha256-offset 0xb0 -o /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.bin /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.elf
esptool.py v4.6
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
real 0m7.646s
user 0m0.161s
sys 0m0.120s
0.28 seconds doing work, and over 7 seconds doing... nothing. It's run twice, once for elf2image, and then again for merge_bin
$ time ~/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/esptool --chip esp32 merge_bin -o /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.merged.bin --fill-flash-size 4MB --flash_mode keep --flash_freq keep --flash_size keep 0x1000 /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.bootloader.bin 0x8000 /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.partitions.bin 0xe000 ~/Library/Arduino15/packages/esp32/hardware/esp32/3.0.5/tools/partitions/boot_app0.bin 0x10000 /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.bin
esptool.py v4.6
Wrote 0x400000 bytes to file /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.merged.bin, ready to flash to offset 0x0
real 0m7.609s
user 0m0.137s
sys 0m0.124s
totaling a half-second of work and almost 15 seconds of nothing. It takes the same amount of time to print the usage
$ time ~/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/esptool
esptool.py v4.6
usage: esptool [-h]
...
--connect-attempts CONNECT_ATTEMPTS
Number of attempts to connect, negative or 0 for infinite. Default: 7.
real 0m7.695s
user 0m0.144s
sys 0m0.128s
Getting the plain script to run wasn't too difficult
cd ~/dev
git clone git@github.com:espressif/esptool.git
cd esptool/
git checkout v4.6
python3 -m pip install pyserial
You may need to install pyserial (one reason it is distributed as an executable?)
$ time python3 ~/dev/esptool/esptool.py --chip esp32 elf2image --flash_mode dio --flash_freq 80m --flash_size 4MB --elf-sha256-offset 0xb0 -o /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.bin /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.elf
esptool.py v4.6
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
real 0m0.155s
user 0m0.114s
sys 0m0.032s
$ time python3 ~/dev/esptool/esptool.py --chip esp32 merge_bin -o /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.merged.bin --fill-flash-size 4MB --flash_mode keep --flash_freq keep --flash_size keep 0x1000 /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.bootloader.bin 0x8000 /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.partitions.bin 0xe000 ~/Library/Arduino15/packages/esp32/hardware/esp32/3.0.5/tools/partitions/boot_app0.bin 0x10000 /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.bin
esptool.py v4.6
Wrote 0x400000 bytes to file /private/var/folders/x_/yv8yw5dj7qdg7vw05b8xzgtw0000gn/T/arduino/sketches/FD07796727C8EF11316CF0BBA2DD3C53/t1363459.ino.merged.bin, ready to flash to offset 0x0
real 0m0.125s
user 0m0.084s
sys 0m0.031s
esptool also runs once for elf2image at the beginning prepare stage, making that slow too. I have it added it under Settings | Privacy & Security | Developer Tools. No noticeable effect.
$ file ~/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/esptool
/Users/kenb4/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/esptool: Mach-O 64-bit executable x86_64
$ ls -l@ ~/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/esptool
-rwxr-xr-x@ 1 kenb4 staff 5971680 Oct 15 14:07 /Users/kenb4/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/esptool
com.apple.provenance 11
There is some talk on the internet that running an executable the first time on a Mac is slow, but this is slow every time. The provenance attribute may indicate it has cleared quarantine.
How about replacing the executable with a shell script to run the Python script?
cd ~/Library/Arduino15/packages/esp32/tools/esptool_py/4.6/
mv esptool esptool.x86
printf '#!/bin/bash\npython3 ~/dev/esptool/esptool.py "$@"\n' > esptool.sh
chmod a+x esptool.sh
ln -s esptool.sh esptool
|
--clean |
cached |
| prepare |
0.952 |
0.954 |
| detecting libraries |
0.714 |
0.823 |
| function prototypes |
0.797 |
0.838 |
| compiling sketch |
0.850 |
0.864 |
| compiling libraries |
0.001 |
0.001 |
| compiling core |
15.046 |
0.119 |
| linking |
2.169 |
2.062 |
| final |
0.619 |
0.669 |
| -------- |
|
|
| Total |
21.148 |
6.330 |
Much better. BTW, the upload (for a different almost-empty sketch) was
Changing baud rate to 1500000
...
Wrote 279184 bytes (156282 compressed) at 0x00010000 in 2.8 seconds (effective 796.5 kbit/s)...