esp-rs / espflash

Serial flasher utility for Espressif SoCs and modules based on esptool.py
Apache License 2.0
478 stars 117 forks source link

Error while running FlashDeflateBegin command on 2.0.1 #453

Closed Janrupf closed 12 months ago

Janrupf commented 1 year ago

This is probably the same as #195, but I'm not 100% sure.

Writing large binaries to the flash fails when not using the stub.

Example invocation:

$> dd if=/dev/zero of=/tmp/zero.bin bs=8M count=1
1+0 records in
1+0 records out
8388608 bytes (8.4 MB, 8.0 MiB) copied, 0.00464577 s, 1.8 GB/s

$>  ~/.cargo/bin/espflash write-bin --port /dev/ttyUSB3 --baud 921600 --no-stub 0x10000 /tmp/zero.bin
[2023-07-26T15:23:12Z INFO ] Serial port: '/dev/ttyUSB3'
[2023-07-26T15:23:12Z INFO ] Connecting...
Chip type:         esp32 (revision v1.0)
Crystal frequency: 40MHz
Flash size:        16MB
Features:          WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC address:       9c:9c:1f:0b:45:68
Error:   × The bootloader returned an error
  ├─▶ Error while running FlashDeflateBegin command
  ╰─▶ Other

I'm trying to flash without the stub, since I have flash encryption in development mode enabled (so I need the ROM bootloader to transparently encrypt while I'm flashing).

The ESP32 I'm using has 16MB of flash, but I can also reproduce the problem if I reduce the dd size to 2M.

Janrupf commented 1 year ago

I'm more or less clueless what is happening, but here are my observations so far:

Janrupf commented 1 year ago

Alright, I think I figured it out, espflash does not send the SpiSetParams command, I'll hopefully will get a PR ready soon.

georgik commented 1 year ago

I've encountered similar problem during an attempt to flash 4 MB binary on S3-BOX calling flasher.write_bin_to_flash method. The big binary failed with:

Flash error: RomError(RomError { command: FlashDeflateBegin, kind: Other })

I was able to flash smaller file around 1 MB, but it failed with anything bigger than ~2 MB

SergioGasquez commented 1 year ago

Alright, I think I figured it out, espflash does not send the SpiSetParams command, I'll hopefully will get a PR ready soon.

Hello @Janrupf! I was about to take a look at this issue, did you have a chance to look into it?

SergioGasquez commented 1 year ago

Seems like @georgik error is different from the original error of the issue. @georgik issue also happens with big binaries, e.g: spooky-maze-esp32-s3-box.bin and it's the following error:

❯ espflash write-bin 0x0 spooky-maze-esp32-s3-box.bin
[2023-10-06T10:44:53Z INFO ] Serial port: '/dev/ttyACM0'
[2023-10-06T10:44:53Z INFO ] Connecting...
[2023-10-06T10:44:54Z INFO ] Using flash stub
[2023-10-06T10:44:54Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type:         esp32s3 (revision v0.1)
Crystal frequency: 40MHz
Flash size:        16MB
Features:          WiFi, BLE
MAC address:       7c:df:a1:e1:c0:c4
Error: espflash::timeout

  × Error while connecting to device
  ╰─▶ Timeout while running FlashDeflateData command

Increasing the default timeout seems to fix this issue, will investigate a better solution

Edit: This issue is more related to https://github.com/esp-rs/espflash/issues/436

SergioGasquez commented 12 months ago

This should now be fixed with #489, if anyone reencounters the issue, feel free to reopen it