Skip to content

Use esptool.py to handle sketch upload, make python available on Windows, too #5635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 18, 2019

Conversation

earlephilhower
Copy link
Collaborator

Go from esptool-ck to esptool.py for the upload stage because the python version is actively maintained by Espressif, has compression, and will be needed for support of future SDKs.

On Windows installs its own, private copy of Python in the Arduino/tools directory.

On all OSes installs the latest pyserial release in the Arduino dir and uses it to simplify installation and ensure everyone is running the same code. It also installs a copy of esptool.py. No modifications are done, we use releases directly from the source.

For now esptool.exe (actually esptool-ck) and esptool.py get dumped into the same folder, but at some point it should be possible to completely remove esptool-ck.

Esptool-ck is still needed because our bootloader is different (and I think better) than the others that esptool.py depends on for single-file uploads.

No binary changes to the .BIN are done, esptool simply does the write_flash stage.

Runs under Linux (and probably Mac), but I need to boot up a Windows box w/passthrough to ensure the Windows python command line is good.

To test, be sure to run python tools/get.py to get the new tools.

Note that esptool.py does NOT seem to work @921k, only 460K baud (even on boards that are known good at 921K). However, even with the lower baud rate it seems to run faster thanks to either better pipelining or the compression.

Fixes #4982

Earle F. Philhower, III and others added 6 commits January 18, 2019 14:38
Add installation of python on Win32/Win64, and on all systems install
esptool.py and pyserial.
Remove need for binary esptool-ck.exe by implementing the same logic as
esptool-ck uses in Python.  Only image creation is supported, and only
in the Arduino standard mode (with its custom bootloader and ROM
layout).
Remove all references to esptool-ck and use Python on Windows and Linux
for all recipes where possible.
Avoid ugly bash and CMD.exe tricks in platform.txt by using python to
make the core_version header.
Need to make sure Python2 and Python3 compatible and paths are munged
properly to avoid eaccidentally escaping things when calling esptool.py

Able to compile, build a BIN and upload via esptool.py on a Windows
machine without Python installed globally, only as part of the Arduino
tools package.
@earlephilhower earlephilhower changed the title WIP - Use esptool.py to handle sketch upload Use esptool.py to handle sketch upload, make python available on Windows, too Jan 20, 2019
@earlephilhower
Copy link
Collaborator Author

Got a plain Windows with no Python installed to do a full build and upload using python in its own embedded directory, installed by the .JSON file.

Also removed much of the BASH/CMD mess in platform.txt and moved to simpler, more maintainable python scripts (making core_version.h, others).

Since Python can be used on Windows now, removed many of the separate ./windows rules, simplifying things even further.

Will need to update the JAVA plugin to use the perl esptool.py to handle uploads of SPIFFS images, but that's a different repo.

@earlephilhower
Copy link
Collaborator Author

Need to support upload.erase_cmd and move default speeds from 921->460 in boards.txt.

Earle F. Philhower, III added 2 commits January 22, 2019 13:58
Add back in erase support by calling esptool.py twice (since it does not
support chained operations like esptool-ck.exe).
961K doesn't seem to work with esptool, so make 460K the default upload
speed and remove 961K.

Even at this lower speed, esptool.py is much faster to upload (even
before taking into account the compression when doing things like SPIFFS
and code upload).
@earlephilhower earlephilhower mentioned this pull request Jan 23, 2019
Arduino does not support a upload.#.cmd pattern, so we need to do
everything in a single command line.  Make it cleaner by introducing a
Python wrapper script which will run the same executable with different
sets of commands (since we need to erase a block w/a separate invocation
from the real upload).

Update boards.txt to use the new options format, placing the esptool
command as "version" when there is no "erase_flash" or "erase_region" to
be done to keep things simple.
Since esptool.py and pyserial are coming directly from github repos,
there is no need to include them as a tool in package.json.
@earlephilhower
Copy link
Collaborator Author

TODO: Add-back 921K, make it silently revert to 420K (with a note in the code that this goes away next major release)
TODO: Update java uploader plugin

@earlephilhower earlephilhower added this to the 2.6.0 milestone Feb 8, 2019
To enable full backward compatibility, restore the 921k option for
upload speed but silently change it to 460k in the upload.py script.

Add error checking on upload.py
@d-a-v d-a-v merged commit 9790e1c into esp8266:master Feb 18, 2019
@saloid
Copy link
Contributor

saloid commented Feb 20, 2019

Got this error when #5635 and #5796 commits are applied:
exec: "C:\\Users\\Dmytro\\Documents\\Arduino\\hardware\\esp8266com\\esp8266/tools/python/python.exe": file does not exist
This folder really doesn`t exists, but Python is installed and added to PATH (win10 x64)

@d-a-v
Copy link
Collaborator

d-a-v commented Feb 20, 2019

Did you restart get.py ?

@saloid
Copy link
Contributor

saloid commented Feb 20, 2019

I have rebooted computer - it doesn't helps.

@d-a-v
Copy link
Collaborator

d-a-v commented Feb 20, 2019

No need to do that.
Update your git repository and restart tools/get.py.
Then retry.

@saloid
Copy link
Contributor

saloid commented Feb 20, 2019

I have restarted get.py with command python get.py. It has downloaded some files, but in "/tools" folder - arduino ide still can't see them. I have tried to move them to "/tools/python" folder and received new error (same with this issue )
Error:
Traceback (most recent call last): File "C:\Users\Dmytro\Documents\Arduino\hardware\esp8266com\esp8266/tools/upload.py", line 24, in <module> pid = os.fork() AttributeError: module 'os' has no attribute 'fork' AttributeError: module 'os' has no attribute 'fork'

@earlephilhower earlephilhower deleted the esptool.py branch February 21, 2019 17:31
@earlephilhower
Copy link
Collaborator Author

@reaper7, @mcspr, anyone else interested in this:

I've updated the ESP SPIFFS uploader to support esptool.py and done some basic testing. I'd appreciate if people could give it a try and if they find any issues, please comment on the PR in the other repo:

ESP8266FS-0.3.0-3-gf5b5c47.zip

esp8266/arduino-esp8266fs-plugin#53

@reaper7
Copy link
Contributor

reaper7 commented Feb 22, 2019

@earlephilhower - personally I do not use spiffs partitions in my projects but I will try to check it out during the weekend

@pfeerick
Copy link
Contributor

pfeerick commented Feb 23, 2019

On Windows 10 using the latest git version with a NodeMCU board after removing ActivePython to ensure the bundled python was used:

  • Blink test at 115K, 256K and 912K (auto fell back to 460K perfectly) baud worked perfectly
  • ESP8266Webserver at 912K (auto 460K) baud, 4M(1M SPIFFS), full flash erase and sketch only, worked perfectly
  • Installed ESP8266FS-0.3.0-3-gf5b5c47, uploaded SPIFFS data without any issue (after some fool realised it wouldn't work over serial when the serial monitor was active)
  • ArduinoOTA at 921K (460K fallback) baud worked, as did subsequent OTA upload.
  • ESP8266Webserver /w OTA added uploaded OTA worked fine, as did SPIFFS OTA, once device was visible to the Arduino IDE

@earlephilhower
Copy link
Collaborator Author

Thanks for the update, guys!

@projectgus
Copy link

Hi @earlephilhower,

esptool.py maintainer here. Sorry I'm a bit late to the party on this one, but I'm glad that esptool.py is useful for the Arduino esp8266 project!

Note that esptool.py does NOT seem to work @921k, only 460K baud (even on boards that are known good at 921K). However, even with the lower baud rate it seems to run faster thanks to either better pipelining or the compression.

Just wanted to say, this was news to me. If anyone has any details about specific hardware that does this (hardware setup descriptions, output from esptool.py failing at 921600 and another tool succeeding at 921600) then please send issues this way!

As of a few versions ago, esptool.py uses a heuristic to estimate the baud rate shift and try to account for inaccuracies between the host & the device's exact baud rate. This heuristic was more reliable than the old method for all of the hardware I tested with at the time, but maybe I didn't test enough hardware!

@earlephilhower
Copy link
Collaborator Author

Howdy @projectgus,

Thanks for the tool. It's made build-test cycles much faster in the core here.

For the baud rate issue, I am seeing the same kind of behavior across multiple "D1 Mini" (clone? hard to say, but probably) boards from 2 batches. It starts comms, seems to negotiate an
acceptable rate of 921K, then ends up failing during the stub upload.

420K runs 100% of the time and seems to do so for everyone so far.

The old esptool-ck.exe at 921k worked fine on this hardware/board (but had other issues and would often take multiple tries to get initial connections going, but once connected the upload did go through at 921k, or at least it said it did).

I'm running the D1 minis on an X79 server motherboard off the internal INTC USB ports, and Ubuntu 18.04.

If you'd like, I can remove the comment about not working at 921K above. Didn't mean to complain, at 420K it's still way faster than the uncompressed one, by 10x+ for mostly empty SPIFFS filesystems, in fact!

Sketch uses 386620 bytes (37%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27940 bytes (34%) of dynamic memory, leaving 53980 bytes for local variables. Maximum is 81920 bytes.
/home/earle/Arduino/hardware/esp8266com/esp8266/tools/python/python /home/earle/Arduino/hardware/esp8266com/esp8266/tools/upload.py --chip esp8266 --port /dev/ttyUSB0 --baud 921600 --trace version --end --chip esp8266 --port /dev/ttyUSB0 --baud 921600 --trace write_flash 0x0 /tmp/arduino_build_455347/bcs.ino.bin --end 
esptool.py v2.6
2.6
esptool.py v2.6
Serial port /dev/ttyUSB0
Connecting...TRACE +0.000 command op=0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
TRACE +0.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
TRACE +0.100 Timed out waiting for packet header
.TRACE +0.050 command op=0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
TRACE +0.000 Write 46 bytes: 
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
TRACE +0.007 Read 1 bytes: c0
TRACE +0.000 Read 31 bytes: 
    0108020007071220 0000c0c001080200 | ....... ........
    070712200000c0c0 01080200070712   | ... ...........
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.002 Read 1 bytes: 20
TRACE +0.000 Read 31 bytes: 
    0000c0c001080200 070712200000c0c0 | ........... ....
    0108020007071220 0000c0c0010802   | ....... .......
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.002 Read 1 bytes: 00
TRACE +0.000 Read 31 bytes: 
    070712200000c0c0 0108020007071220 | ... ........... 
    0000c0c001080200 070712200000c0   | ........... ...
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.000 Received full packet: 01080200070712200000

TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5c00f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005c00f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200940160000000c0
TRACE +0.000 Received full packet: 010a0200940160000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5800f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005800f03fc0
TRACE +0.005 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a020000b000170000c0
TRACE +0.000 Received full packet: 010a020000b000170000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5400f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005400f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200b42300020000c0
TRACE +0.000 Received full packet: 010a0200b42300020000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5000f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005000f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200000016a60000c0
TRACE +0.000 Received full packet: 010a0200000016a60000
Chip is ESP8266EX
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5c00f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005c00f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200940160000000c0
TRACE +0.000 Received full packet: 010a0200940160000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5800f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005800f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a020000b000170000c0
TRACE +0.000 Received full packet: 010a020000b000170000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5400f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005400f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200b42300020000c0
TRACE +0.000 Received full packet: 010a0200b42300020000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5000f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005000f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200000016a60000c0
TRACE +0.000 Received full packet: 010a0200000016a60000
Features: WiFi
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5000f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005000f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200000016a60000c0
TRACE +0.000 Received full packet: 010a0200000016a60000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5400f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005400f03fc0
TRACE +0.005 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200b42300020000c0
TRACE +0.000 Received full packet: 010a0200b42300020000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=5c00f03f
TRACE +0.000 Write 14 bytes: c0000a0400000000005c00f03fc0
TRACE +0.004 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 010a0200940160000000c0
TRACE +0.000 Received full packet: 010a0200940160000000
MAC: 60:01:94:23:b4:a6
Uploading stub...
TRACE +0.000 command op=0x05 data len=16 wait_response=1 timeout=3.000 data=6c1f0000020000000018000000e01040
TRACE +0.000 Write 26 bytes: 
    c000051000000000 006c1f0000020000 | .........l......
    000018000000e010 40c0             | ........@.
TRACE +0.006 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 01050200940160000000c0
TRACE +0.000 Received full packet: 01050200940160000000
TRACE +0.002 command op=0x07 data len=6160 wait_response=1 timeout=3.000 data=
    0018000000000000 0000000000000000 | ................
    a810004001ffff46 460000000080fe3f | [email protected]......?
    4f484149a4abff3f 0cabfe3f80800000 | OHAI...?...?....
    f4f910400c000060 0000000100000100 | ...@...`........
    00100000ffff0000 8c80000010400000 | .............@..
    0000ffff00400000 0080fe3f9c2bff3f | .....@.....?.+.?
    a02bff3f10270000 14000060ffff0f00 | .+.?.'.....`....
    a4abff3fa4abff3f a42bff3fb4abff3f | ...?...?.+.?...?
    0080000020290000 f88dfe3f5880fe3f | .... ).....?X..?
    a8abff3f98aeff3f 989bfe3f84aeff3f | ...?...?...?...?
    801b0000a00d0000 0008000020090000 | ............ ...
....
    ea5559d2ed04dcb4 e8a27ce2e0e5dbdc | .UY.......|.....
    e08293ed08460300 0c0c060100000000 | .....F..........
    cd05dd0c7cde313a fa62212b2823d066 | ....|.1:.b!+(#.f
    dbdcd022dbdcdaff d119fa29c0       | ...".......).
TRACE +0.577 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 01070200940160000000c0
TRACE +0.000 Received full packet: 01070200940160000000
TRACE +0.001 command op=0x07 data len=1916 wait_response=1 timeout=3.000 data=
    6c07000001000000 0000000000000000 | l...............
    23380d7119facac3 703cc00c1562612b | #8.q....p<...ba+
    0c0262d380602583 0b5e505e20505f05 | ..b..`%..^P^ P_.
    c90d5022208c72cd 072d07053400c90d | ..P" .r..-..4...
    82212bc105facc48 d68e01460300283c | .!+....H...F..(<
    1642ffa61e02c663 fbc6faff22a0c729 | .B.....c...."..)
    5cc60300ccce283c cc128658fa22a0c8 | \.....(<...X."..
    86020000283c8c12 0655fa22a0c9295c | ....(<...U."..)\
    0653fa00282c8c12 0651fa21f6f90121 | .S..(,...Q.!...!
    fac000000126fac0 0000864cfac83ccc | .....&.....L..<.
....
    29032d050df00000 42a0dd4792090c12 | ).-.....B..G....
    290322a0db0df000 7cf20df0         | ).".....|...
TRACE +0.014 Write 1996 bytes: 
    c000077c075e0000 006c070000010000 | ...|.^...l......
    0000000000000000 0023380d7119faca | .........#8.q...
    c3703cdbdc0c1562 612b0c0262d38060 | .p<....ba+..b..`
....
    03460800000042a0 dc4792090c122903 | .F....B..G....).
    2d050df0000042a0 dd4792090c122903 | -.....B..G....).
    22a0dbdd0df0007c f20df0c0         | "......|....
TRACE +0.192 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 01070200940160000000c0
TRACE +0.000 Received full packet: 01070200940160000000
TRACE +0.000 command op=0x05 data len=16 wait_response=1 timeout=3.000 data=000300000100000000180000a4abff3f
TRACE +0.000 Write 26 bytes: 
    c000051000000000 0000030000010000 | ................
    0000180000a4abff 3fc0             | ........?.
TRACE +0.006 Read 1 bytes: c0
TRACE +0.000 Read 11 bytes: 01050200940160000000c0
TRACE +0.000 Received full packet: 01050200940160000000
TRACE +0.000 command op=0x07 data len=784 wait_response=1 timeout=3.000 data=
    0003000000000000 0000000000000000 | ................
    a42bff3f05050400 0203070003030b00 | .+.?............
    57e610408ce61040 d2e6104093e71040 | W..@...@...@...@
    b9f61040ebe71040 3ce8104092e81040 | ...@...@<..@...@
    b9f6104084e91040 04ea1040c1ea1040 | ...@...@...@...@
    b9f61040b9f61040 5feb1040b9f61040 | ...@...@_..@...@
    3cee104017ef1040 4fef1040b9f61040 | <..@...@O..@...@
    b9f61040fdef1040 b9f61040fcf01040 | ...@...@...@...@
    a3f1104009f31040 dbf31040b4f41040 | ...@...@...@...@
    b9f61040b9f61040 b9f61040b9f61040 | ...@...@...@...@
    e3f51040b9f61040 a8f6104087ec1040 | ...@...@...@...@
    5de710402bf51040 abe91040fae81040 | ]..@+..@...@...@
    a1e9104037f61040 80f61040b9f61040 | ...@7..@...@...@
    b9f61040b9f61040 b9f61040b9f61040 | ...@...@...@...@
    b9f61040b9f61040 b9f6104023e91040 | ...@...@...@#..@
    59e9104041f51040 0100000002000000 | Y..@A..@........
    0300000004000000 0500000007000000 | ................
    090000000d000000 1100000019000000 | ................
    2100000031000000 4100000061000000 | !...1...A...a...
    81000000c1000000 0101000081010000 | ................
    0102000001030000 0104000001060000 | ................
    01080000010c0000 0110000001180000 | ................
    0120000001300000 0140000001600000 | . ...0...@...`..
    0000000000000000 0000000000000000 | ................
    0000000000000000 0100000001000000 | ................
    0200000002000000 0300000003000000 | ................
    0400000004000000 0500000005000000 | ................
    0600000006000000 0700000007000000 | ................
    0800000008000000 0900000009000000 | ................
    0a0000000a000000 0b0000000b000000 | ................
    0c0000000c000000 0d0000000d000000 | ................
    0000000000000000 0300000004000000 | ................
    0500000006000000 0700000008000000 | ................
    090000000a000000 0b0000000d000000 | ................
    0f00000011000000 1300000017000000 | ................
    1b0000001f000000 230000002b000000 | ........#...+...
    330000003b000000 4300000053000000 | 3...;...C...S...
    6300000073000000 83000000a3000000 | c...s...........
    c3000000e3000000 0201000000000000 | ................
    0000000000000000 0000000000000000 | ................
    0000000000000000 0000000000000000 | ................
    0000000001000000 0100000001000000 | ................
    0100000002000000 0200000002000000 | ................
    0200000003000000 0300000003000000 | ................
    0300000004000000 0400000004000000 | ................
    0400000005000000 0500000005000000 | ................
    0500000000000000 0000000000000000 | ................
    1011120008070906 0a050b040c030d02 | ................
    0e010f0001010000 0100000004000000 | ................
TRACE +0.006 Write 795 bytes: 
    c000071003710000 0000030000000000 | .....q..........
    0000000000000000 00a42bff3f050504 | ..........+.?...
    000203070003030b 0057e610408ce610 | .........W..@...
    40d2e6104093e710 40b9f61040ebe710 | @...@...@...@...
    403ce8104092e810 40b9f6104084e910 | @<..@...@...@...
    4004ea1040c1ea10 40b9f61040b9f610 | @...@...@...@...
    405feb1040b9f610 403cee104017ef10 | @_..@...@<..@...
    404fef1040b9f610 40b9f61040fdef10 | @O..@...@...@...
    40b9f61040fcf010 40a3f1104009f310 | @...@...@...@...
    40dbddf31040b4f4 1040b9f61040b9f6 | @....@...@...@..
    1040b9f61040b9f6 1040e3f51040b9f6 | .@...@...@...@..
    1040a8f6104087ec 10405de710402bf5 | .@...@...@]..@+.
    1040abe91040fae8 1040a1e9104037f6 | .@...@...@...@7.
    104080f61040b9f6 1040b9f61040b9f6 | .@...@...@...@..
    1040b9f61040b9f6 1040b9f61040b9f6 | .@...@...@...@..
    1040b9f6104023e9 104059e9104041f5 | .@...@#..@Y..@A.
    1040010000000200 0000030000000400 | .@..............
    0000050000000700 0000090000000d00 | ................
    0000110000001900 0000210000003100 | ..........!...1.
    0000410000006100 000081000000c100 | ..A...a.........
    0000010100008101 0000010200000103 | ................
    0000010400000106 000001080000010c | ................
    0000011000000118 0000012000000130 | ........... ...0
    0000014000000160 0000000000000000 | ...@...`........
    0000000000000000 0000000000000000 | ................
    0000010000000100 0000020000000200 | ................
    0000030000000300 0000040000000400 | ................
    0000050000000500 0000060000000600 | ................
    0000070000000700 0000080000000800 | ................
    0000090000000900 00000a0000000a00 | ................
    00000b0000000b00 00000c0000000c00 | ................
    00000d0000000d00 0000000000000000 | ................
    0000030000000400 0000050000000600 | ................
    0000070000000800 0000090000000a00 | ................
    00000b0000000d00 00000f0000001100 | ................
    0000130000001700 00001b0000001f00 | ................
    0000230000002b00 0000330000003b00 | ..#...+...3...;.
    0000430000005300 0000630000007300 | ..C...S...c...s.
    000083000000a300 0000c3000000e300 | ................
    0000020100000000 0000000000000000 | ................
    0000000000000000 0000000000000000 | ................
    0000000000000000 0000000000000100 | ................
    0000010000000100 0000010000000200 | ................
    0000020000000200 0000020000000300 | ................
    0000030000000300 0000030000000400 | ................
    0000040000000400 0000040000000500 | ................
    0000050000000500 0000050000000000 | ................
    0000000000000000 0000101112000807 | ................
    09060a050b040c03 0d020e010f000101 | ................
Traceback (most recent call last):
    0000010000000400 0000c0           | ...........
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/upload.py", line 25, in <module>
TRACE +0.078 Read 1 bytes: c0
    esptool.main(fakeargs)
TRACE +0.000 Read 11 bytes: 01070200940160000000c0
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 2694, in main
TRACE +0.000 Received full packet: 01070200940160000000
Running stub...
    detect_flash_size(esp, args)
TRACE +0.000 command op=0x06 data len=8 wait_response=1 timeout=0.050 data=0000000004e01040
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 2073, in detect_flash_size
TRACE +0.000 Write 18 bytes: 
    c000060800000000 000000000004e010 | ................
    40c0                              | @.
TRACE +0.007 Read 1 bytes: c0
TRACE +0.000 Read 17 bytes: 
    0106020094016000 0000c0c04f484149 | ......`.....OHAI
    c0                                | .
TRACE +0.000 Received full packet: 01060200940160000000
    flash_id = esp.flash_id()
TRACE +0.000 Received full packet: 4f484149
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 567, in flash_id
Stub running...
    return self.run_spiflash_command(SPIFLASH_RDID, b"", 24)
Changing baud rate to 921600
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 812, in run_spiflash_command
TRACE +0.000 command op=0x0f data len=8 wait_response=1 timeout=3.000 data=00100e0000c20100
TRACE +0.000 Write 18 bytes: 
    c0000f0800000000 0000100e0000c201 | ................
    old_spi_usr = self.read_reg(SPI_USR_REG)
    00c0                              | ..
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 475, in read_reg
TRACE +0.005 Read 1 bytes: c0
    val, data = self.command(self.ESP_READ_REG, struct.pack('<I', addr))
TRACE +0.000 Read 11 bytes: 010f0200000000000000c0
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 332, in command
TRACE +0.000 Received full packet: 010f0200000000000000
    p = self.read()
Changed.
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 277, in read
Configuring flash size...
    return next(self._slip_reader)
TRACE +0.051 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=1c020060
  File "/home/earle/Arduino/hardware/esp8266com/esp8266/tools/esptool/esptool.py", line 1877, in slip_reader
TRACE +0.000 Write 14 bytes: c0000a0400000000001c020060c0
TRACE +3.003 Timed out waiting for packet header
    raise FatalError("Timed out waiting for packet %s" % waiting_for)
esptool.FatalError: Timed out waiting for packet header
esptool.FatalError: Timed out waiting for packet header

@projectgus
Copy link

Hi @earlephilhower ,

Thanks for the all these details!

For the baud rate issue, I am seeing the same kind of behavior across multiple "D1 Mini" (clone? hard to say, but probably) boards from 2 batches. It starts comms, seems to negotiate an
acceptable rate of 921K, then ends up failing during the stub upload.

I had one of these floating around and I can confirm this is the case. At 460800 all of the test_esptool.py tests pass, except for the "high speed flashing" test which explicitly sets 921600bps and then fails.

But esptool-ck passes at 921600.

I don't have time to debug right now, but I'll open an issue to track this.

If you'd like, I can remove the comment about not working at 921K above. Didn't mean to complain, at 420K it's still way faster than the uncompressed one, by 10x+ for mostly empty SPIFFS filesystems, in fact!

That's great to hear. No need to remove anything at all. I just appreciate knowing about the difference, so we can hopefully fix it.

pfeerick added a commit to pfeerick/platform-espressif8266 that referenced this pull request Sep 8, 2019
As of esp8266/Arduino#5635 the
esp8266/Arduino core has defaulted to 460800 baud for
serial uploads and also silently limits the highest
supported upload rate of 921600 to 460800.

https://github.com./esp8266/Arduino/blob/77c4f5e5cfb2286d6862621bd78120f027d10a9f/tools/upload.py#L29

sed -i "s/\"speed\".*/\"speed\": 460800/g" *.json
@matthijskooijman matthijskooijman mentioned this pull request Oct 5, 2019
5 tasks
maciekn added a commit to maciekn/vscode-esp8266fs that referenced this pull request Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement compressed stub for sketch upload
7 participants