Skip to content

SPI operation failed when flashing .crt being not multiple of 4Β #440

Closed
@alessio-perugini

Description

@alessio-perugini

πŸ‘‹ I was trying to flash a x509 certificate bundle in a .crt format to 0x3c0000 address. Unfortunately, the tool returns the following error:

Error: Γ— The bootloader returned an error
β”œβ”€β–Ά Error while running FlashDeflateEnd command
╰─▢ SPI operation failed

Talking to other guys on the team we hypothesized that we could have some padding problems, so I added a few bytes at the end. Surprisingly making the .crt file multiple of 4 solved the problem, and the espflash worked perfectly!

stat -c %s google.crt

before after
3649 Bytes 3652 Bytes

Steps to reproduce the problem

openssl s_client -showcerts -connect google.com:443 </dev/null | sed -n -e '/-.BEGIN/,/-.END/ p' > google.pem
openssl x509 -outform der -in google.pem -out google.crt
espflash write-bin -p /dev/ttyACM0 -b 921600 0x3C0000 google.crt

[2023-07-03T14:49:58Z INFO ] Serial port: '/dev/ttyACM0'
[2023-07-03T14:49:58Z INFO ] Connecting...
[2023-07-03T14:49:58Z INFO ] Using flash stub
[2023-07-03T14:49:59Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type: esp32s3 (revision v0.1)
Crystal frequency: 40MHz
Flash size: 8MB
Features: WiFi, BLE
MAC address: dc:54:75:c3:01:18
[00:00:00] [========================================] 2/2 0x3C0000 Error: Γ— The bootloader returned an error
β”œβ”€β–Ά Error while running FlashDeflateEnd command
╰─▢ SPI operation failed

Steps to fix the problem

openssl s_client -showcerts -connect google.com:443 </dev/null | sed -n -e '/-.BEGIN/,/-.END/ p' > google.pem
openssl x509 -outform der -in google.pem -out google.crt
dd if=/dev/zero of=google.crt bs=1 count=1 seek=3651
espflash write-bin -p /dev/ttyACM0 -b 921600 0x3C0000 google.crt

[2023-07-03T15:01:31Z INFO ] Serial port: '/dev/ttyACM0'
[2023-07-03T15:01:31Z INFO ] Connecting...
[2023-07-03T15:01:32Z INFO ] Using flash stub
[2023-07-03T15:01:32Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type: esp32s3 (revision v0.1)
Crystal frequency: 40MHz
Flash size: 8MB
Features: WiFi, BLE
MAC address: dc:54:75:c3:01:18
[00:00:00] [========================================] 2/2 0x3C0000

Additional information

I'm running on Ubuntu 22.04

$ uname -a
Linux ale 5.19.0-45-generic #46~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 7 15:06:04 UTC 20 x86_64 x86_64 x86_64 GNU/Linux

$ espflash --version
espflash 2.0.0

I was trying the flash on one the new Arduino Uno R4 WiFi (datasheet)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions