Skip to content
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

Encrypted flash write on ESP32 - Invalid (unsupported command 0xd4) (ESPTOOL-743) #921

Closed
1 task done
DCSBL opened this issue Sep 20, 2023 · 13 comments
Closed
1 task done

Comments

@DCSBL
Copy link
Contributor

DCSBL commented Sep 20, 2023

Operating System

macOS 13.4.1

Esptool Version

4.7.dev1 (and tested with 4.6.2)

Python Version

3.9.4

Chip Description

ESP32-WROOM-32E

Device Description

Module on custom PCB, connected to FTDI programmer. Normal reads/writes are working as expected.

Hardware Configuration

Bare minimum, no external peripherals except for power supply or flashing

How is Esptool Run

Terminal in VSCode

Full Esptool Command Line that Was Run

esptool.py -b 460800 --before default_reset --after no_reset --chip esp32 --no-stub write_flash --flash_mode dio --flash_size 4MB --flash_freq 40m 0x121000 cusotm-nvs/bin/custom-1.bin --encrypt-files 0x120000 cusotm-nvs/keys/keys-custom-1.bin

Esptool Output

esptool.py v4.7.dev1
Found 3 serial ports
Serial port /dev/cu.usbserial-02BFRZ28
Connecting....
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 94:3c:c6:e2:b3:c8
Changing baud rate to 460800
Changed.
Enabling default SPI flash mode...
Configuring flash size...
Flash will be erased from 0x00121000 to 0x00124fff...
Erasing flash...
Took 0.05s to erase flash block
Writing at 0x00120000... (25 %)Traceback (most recent call last):
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 37, in <module>
    esptool._main()
  File "~/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/__init__.py", line 1072, in _main
    main()
  File "~/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/__init__.py", line 867, in main
    operation_func(esp, args)
  File "~/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/cmds.py", line 604, in write_flash
    esp.flash_encrypt_block(block, seq)
  File "~/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/loader.py", line 858, in flash_encrypt_block
    self.check_command(
  File "~/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/loader.py", line 436, in check_command
    val, data = self.command(op, data, chk, timeout=timeout)
  File "~/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/loader.py", line 419, in command
    raise UnsupportedCommandError(self, op)
esptool.util.UnsupportedCommandError: Invalid (unsupported) command 0xd4

More Information

I am trying to flash custom NVS, generated by the Manufacturing Utility on a flash-encryption enabled ESP32 in development mode. This works on ESP32S3 but I fail to reproduce this on the ESP32 rev3.

Using ESP-IDF-v5.5.1

Full log using --trace

esptool.py v4.7.dev1 Found 3 serial ports Serial port /dev/cu.usbserial-02BFRZ28 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.104 No serial data received. .TRACE +0.107 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.005 Read 1 bytes: c0 TRACE +0.000 Read 1 bytes: 01 TRACE +0.000 Read 5 bytes: 0804000720 TRACE +0.001 Read 1 bytes: 55 TRACE +0.000 Read 10 bytes: 5500000000c0c0010804 TRACE +0.000 Received full packet: 010804000720555500000000 TRACE +0.001 Read 1 bytes: 00 TRACE +0.000 Read 11 bytes: 0720555500000000c0c001 TRACE +0.000 Received full packet: 010804000720555500000000 TRACE +0.001 Read 1 bytes: 08 TRACE +0.000 Read 10 bytes: 04000720555500000000 TRACE +0.001 Read 1 bytes: c0 TRACE +0.000 Received full packet: 010804000720555500000000 TRACE +0.000 Read 10 bytes: c0010804000720555500 TRACE +0.001 Read 1 bytes: 00 TRACE +0.000 Read 10 bytes: 0000c0c0010804000720 TRACE +0.000 Received full packet: 010804000720555500000000 TRACE +0.001 Read 1 bytes: 55 TRACE +0.000 Read 11 bytes: 5500000000c0c001080400 TRACE +0.000 Received full packet: 010804000720555500000000 TRACE +0.001 Read 1 bytes: 07 TRACE +0.000 Read 10 bytes: 20555500000000c0c001 TRACE +0.000 Received full packet: 010804000720555500000000 TRACE +0.001 Read 1 bytes: 08 TRACE +0.000 Read 10 bytes: 04000720555500000000 TRACE +0.001 Read 1 bytes: c0 TRACE +0.000 Received full packet: 010804000720555500000000 TRACE +0.000 Read 10 bytes: c0010804000720555500 TRACE +0.001 Read 1 bytes: 00 TRACE +0.000 Read 3 bytes: 0000c0 TRACE +0.000 Received full packet: 010804000720555500000000

TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=00100040
TRACE +0.000 Write 14 bytes: c0000a04000000000000100040c0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 11 bytes: 0a0400831df00000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010a0400831df00000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=0ca0f53f
TRACE +0.000 Write 14 bytes: c0000a0400000000000ca0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 11 bytes: 0a040000a2000000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010a040000a2000000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=0ca0f53f
TRACE +0.000 Write 14 bytes: c0000a0400000000000ca0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 1 bytes: 0a
TRACE +0.001 Read 1 bytes: 04
TRACE +0.000 Read 10 bytes: 0000a2000000000000c0
TRACE +0.000 Received full packet: 010a040000a2000000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=14a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000014a0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 6 bytes: 0a0400000010
TRACE +0.001 Read 1 bytes: f0
TRACE +0.000 Read 5 bytes: 00000000c0
TRACE +0.000 Received full packet: 010a0400000010f000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=7c60f63f
TRACE +0.000 Write 14 bytes: c0000a0400000000007c60f63fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04000020049600000000c0
TRACE +0.000 Received full packet: 010a04000020049600000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=14a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000014a0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 6 bytes: 0a0400000010
TRACE +0.001 Read 1 bytes: f0
TRACE +0.000 Read 5 bytes: 00000000c0
TRACE +0.000 Received full packet: 010a0400000010f000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=0ca0f53f
TRACE +0.000 Write 14 bytes: c0000a0400000000000ca0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 11 bytes: 0a040000a2000000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010a040000a2000000000000
Chip is ESP32-D0WD-V3 (revision v3.0)
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=0ca0f53f
TRACE +0.000 Write 14 bytes: c0000a0400000000000ca0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 1 bytes: 0a
TRACE +0.001 Read 1 bytes: 04
TRACE +0.000 Read 10 bytes: 0000a2000000000000c0
TRACE +0.000 Received full packet: 010a040000a2000000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=0ca0f53f
TRACE +0.000 Write 14 bytes: c0000a0400000000000ca0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 7 bytes: 0a040000a20000
TRACE +0.001 Read 1 bytes: 00
TRACE +0.000 Read 4 bytes: 000000c0
TRACE +0.000 Received full packet: 010a040000a2000000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=10a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000010a0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.001 Read 1 bytes: 0a
TRACE +0.000 Read 11 bytes: 04003307000000000000c0
TRACE +0.000 Received full packet: 010a04003307000000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=18a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000018a0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 6 bytes: 0a0400440300
TRACE +0.001 Read 1 bytes: 00
TRACE +0.000 Read 5 bytes: 00000000c0
TRACE +0.000 Received full packet: 010a04004403000000000000
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=1400f43f
TRACE +0.000 Write 14 bytes: c0000a0400000000001400f43fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 11 bytes: 0a04006301000000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010a04006301000000000000
Crystal is 40MHz
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=08a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000008a0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 1 bytes: 0a
TRACE +0.001 Read 1 bytes: 04
TRACE +0.000 Read 10 bytes: 003c942f0000000000c0
TRACE +0.000 Received full packet: 010a04003c942f0000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=04a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000004a0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 6 bytes: 0a0400c8b3e2
TRACE +0.001 Read 1 bytes: c6
TRACE +0.000 Read 5 bytes: 00000000c0
TRACE +0.000 Received full packet: 010a0400c8b3e2c600000000
MAC: 94:3c:c6:e2:b3:c8
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=6cf0f53f
TRACE +0.000 Write 14 bytes: c0000a0400000000006cf0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 11 bytes: 0a040000cc030000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010a040000cc030000000000
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=10a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000010a0f53fc0
TRACE +0.002 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 1 bytes: 0a
TRACE +0.001 Read 1 bytes: 04
TRACE +0.000 Read 10 bytes: 003307000000000000c0
TRACE +0.000 Received full packet: 010a04003307000000000000
Changing baud rate to 460800
TRACE +0.000 command op=0x0f data len=8 wait_response=1 timeout=3.000 data=c4ce060000000000
TRACE +0.000 Write 18 bytes:
c0000f0800000000 00c4ce0600000000 | ................
00c0 | ..
TRACE +0.002 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 7 bytes: 0f040033070000
TRACE +0.001 Read 1 bytes: 00
TRACE +0.000 Read 5 bytes: 000000c020
TRACE +0.000 Received full packet: 010f04003307000000000000
Changed.
Enabling default SPI flash mode...
TRACE +0.071 command op=0x0d data len=8 wait_response=1 timeout=3.000 data=0000000000000000
TRACE +0.000 Write 18 bytes:
c0000d0800000000 0000000000000000 | ................
00c0 | ..
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 1 bytes: 0d
TRACE +0.000 Read 11 bytes: 04003307000000000000c0
TRACE +0.000 Received full packet: 010d04003307000000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=1c20f43f
TRACE +0.000 Write 14 bytes: c0000a0400000000001c20f43fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04004000008000000000c0
TRACE +0.000 Received full packet: 010a04004000008000000000
TRACE +0.013 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=2420f43f
TRACE +0.000 Write 14 bytes: c0000a0400000000002420f43fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04000000007000000000c0
TRACE +0.000 Received full packet: 010a04000000007000000000
TRACE +0.012 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=2c20f43f17000000ffffffff00000000
TRACE +0.000 Write 26 bytes:
c000091000000000 002c20f43f170000 | ........., .?...
00ffffffff000000 00c0 | ..........
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0904000000007000000000c0
TRACE +0.000 Received full packet: 010904000000007000000000
TRACE +0.012 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=1c20f43f00000090ffffffff00000000
TRACE +0.000 Write 26 bytes:
c000091000000000 001c20f43f000000 | .......... .?...
90ffffffff000000 00c0 | ..........
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0904000000007000000000c0
TRACE +0.000 Received full packet: 010904000000007000000000
TRACE +0.012 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=2420f43f9f000070ffffffff00000000
TRACE +0.000 Write 26 bytes:
c000091000000000 002420f43f9f0000 | .........$ .?...
70ffffffff000000 00c0 | p.........
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0904000000007000000000c0
TRACE +0.000 Received full packet: 010904000000007000000000
TRACE +0.012 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=8020f43f00000000ffffffff00000000
TRACE +0.000 Write 26 bytes:
c000091000000000 008020f43f000000 | .......... .?...
00ffffffff000000 00c0 | ..........
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0904000000007000000000c0
TRACE +0.000 Received full packet: 010904000000007000000000
TRACE +0.012 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=0020f43f00000400ffffffff00000000
TRACE +0.000 Write 26 bytes:
c000091000000000 000020f43f000004 | .......... .?...
00ffffffff000000 00c0 | ..........
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 11 bytes: 0904000000007000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010904000000007000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=0020f43f
TRACE +0.000 Write 14 bytes: c0000a0400000000000020f43fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04000000000000000000c0
TRACE +0.000 Received full packet: 010a04000000000000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=8020f43f
TRACE +0.000 Write 14 bytes: c0000a0400000000008020f43fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 9 bytes: 0a0400204017000000
TRACE +0.001 Read 1 bytes: 00
TRACE +0.000 Read 2 bytes: 00c0
TRACE +0.000 Received full packet: 010a04002040170000000000
TRACE +0.012 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=1c20f43f40000080ffffffff00000000
TRACE +0.000 Write 26 bytes:
c000091000000000 001c20f43f400000 | .......... .?@..
80ffffffff000000 00c0 | ..........
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0904002040170000000000c0
TRACE +0.000 Received full packet: 010904002040170000000000
TRACE +0.012 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=2420f43f00000070ffffffff00000000
TRACE +0.000 Write 26 bytes:
c000091000000000 002420f43f000000 | .........$ .?...
70ffffffff000000 00c0 | p.........
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0904002040170000000000c0
TRACE +0.000 Received full packet: 010904002040170000000000
Configuring flash size...
TRACE +0.012 command op=0x0b data len=24 wait_response=1 timeout=3.000 data=
0000000000004000 0000010000100000 | ......@.........
00010000ffff0000 | ........
TRACE +0.000 Write 34 bytes:
c0000b1800000000 0000000000000040 | ...............@
0000000100001000 0000010000ffff00 | ................
00c0 | ..
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0b04002040170000000000c0
TRACE +0.000 Received full packet: 010b04002040170000000000
TRACE +0.011 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=18a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000018a0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04004403000000000000c0
TRACE +0.000 Received full packet: 010a04004403000000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=0ca0f53f
TRACE +0.000 Write 14 bytes: c0000a0400000000000ca0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 8 bytes: 0a040000a2000000
TRACE +0.001 Read 1 bytes: 00
TRACE +0.000 Read 3 bytes: 0000c0
TRACE +0.000 Received full packet: 010a040000a2000000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=14a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000014a0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a0400000010f000000000c0
TRACE +0.000 Received full packet: 010a0400000010f000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=7c60f63f
TRACE +0.000 Write 14 bytes: c0000a0400000000007c60f63fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04000020049600000000c0
TRACE +0.000 Received full packet: 010a04000020049600000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=14a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000014a0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a0400000010f000000000c0
TRACE +0.000 Received full packet: 010a0400000010f000000000
TRACE +0.013 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=18a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000018a0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 11 bytes: 0a04004403000000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Received full packet: 010a04004403000000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=00a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000000a0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04008000110000000000c0
TRACE +0.000 Received full packet: 010a04008000110000000000
TRACE +0.012 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=14a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000014a0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a0400000010f000000000c0
TRACE +0.000 Received full packet: 010a0400000010f000000000
TRACE +0.011 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=00a0f53f
TRACE +0.000 Write 14 bytes: c0000a04000000000000a0f53fc0
TRACE +0.001 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0a04008000110000000000c0
TRACE +0.000 Received full packet: 010a04008000110000000000
Flash will be erased from 0x00121000 to 0x00124fff...
Erasing flash...
TRACE +0.012 command op=0x02 data len=16 wait_response=1 timeout=3.000 data=00100000040000000004000000001200
TRACE +0.000 Write 26 bytes:
c000021000000000 0000100000040000 | ................
0000040000000012 00c0 | ..........
TRACE +0.039 Read 1 bytes: c0
TRACE +0.001 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0204008000110000000000c0
TRACE +0.000 Received full packet: 010204008000110000000000
Took 0.05s to erase flash block
Writing at 0x00120000... (25 %)TRACE +0.013 command op=0xd4 data len=1040 wait_response=1 timeout=3.000 data=
0004000000000000 0000000000000000 | ................
018cb2d44be33469 1443479321745f54 | ....K.4i.CG.!t_T
f788544b4f55cb02 593a375575062894 | ..TKOU..Y:7Uu.(.
13fd258e29ca78c0 f6b9ee5b5a09c10c | ..%.).x....[Z...
660f300188b7bc8f e075914a9aa53dca | f.0......u.J..=.
f0ab3ee1ffffffff ffffffffffffffff | ..>.............
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
TRACE +0.001 Write 1051 bytes:
c000d410047d0000 0000040000000000 | .....}..........
0000000000000000 00018cb2d44be334 | .............K.4
691443479321745f 54f788544b4f55cb | i.CG.!t_T..TKOU.
02593a3755750628 9413fd258e29ca78 | .Y:7Uu.(...%.).x
dbdcf6b9ee5b5a09 c10c660f300188b7 | .....[Z...f.0...
bc8fe075914a9aa5 3dcaf0ab3ee1ffff | ...u.J..=...>...
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffffffffffffff | ................
ffffffffffffffff ffffc0 | ...........
TRACE +0.025 Read 1 bytes: c0
TRACE +0.000 Read 1 bytes: 01
TRACE +0.000 Read 12 bytes: 0204008000110001050000c0
TRACE +0.000 Received full packet: 010204008000110001050000
Traceback (most recent call last):
File "/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 37, in
esptool._main()
File "
/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/init.py", line 1072, in _main
main()
File "/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/init.py", line 867, in main
operation_func(esp, args)
File "
/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/cmds.py", line 604, in write_flash
esp.flash_encrypt_block(block, seq)
File "/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/loader.py", line 858, in flash_encrypt_block
self.check_command(
File "
/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/loader.py", line 436, in check_command
val, data = self.command(op, data, chk, timeout=timeout)
File "~/.espressif/python_env/idf5.1_py3.9_env/lib/python3.9/site-packages/esptool/loader.py", line 419, in command
raise UnsupportedCommandError(self, op)
esptool.util.UnsupportedCommandError: Invalid (unsupported) command 0xd4

Other Steps to Reproduce

  1. Select esp-idf-v5.5.1
  2. Enter examples/security/flash_encryption
  3. Enable flash_encryption (CONFIG_SECURE_FLASH_ENC_ENABLED)
  4. Bootloader won't fit, selected BOOTLOADER_LOG_LEVEL_ERROR to reduce size
  5. run idf.py flash monitor
I (123) cpu_start: Multicore app
I (124) cpu_start: Pro cpu up.
I (124) cpu_start: Starting app cpu, entry point is 0x400811fc
0x400811fc: call_start_cpu1 at ~/esp/esp-idf-v5.1.1/components/esp_system/port/cpu_start.c:154

I (0) cpu_start: App cpu up.
I (142) cpu_start: Pro cpu start user code
I (142) cpu_start: cpu freq: 160000000 Hz
I (142) cpu_start: Application information:
I (146) cpu_start: Project name:     flash_encryption
I (152) cpu_start: App version:      v5.1.1
I (157) cpu_start: Compile time:     Sep 20 2023 16:52:20
I (163) cpu_start: ELF file SHA256:  69aab48f129e12c0...
I (169) cpu_start: ESP-IDF:          v5.1.1
I (174) cpu_start: Min chip rev:     v0.0
I (179) cpu_start: Max chip rev:     v3.99 
I (183) cpu_start: Chip rev:         v3.0
I (188) heap_init: Initializing. RAM available for dynamic allocation:
I (196) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (201) heap_init: At 3FFB2A18 len 0002D5E8 (181 KiB): DRAM
I (208) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (214) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (221) heap_init: At 4008C864 len 0001379C (77 KiB): IRAM
I (228) spi_flash: detected chip: generic
I (231) spi_flash: flash io: dio
W (235) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
W (249) flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)
I (257) app_start: Starting scheduler on CPU0
I (261) app_start: Starting scheduler on CPU1
I (261) main_task: Started on CPU0
I (271) main_task: Calling app_main()

Example to check Flash Encryption status
This is esp32 chip with 2 CPU core(s), WiFi/BT/BLE, silicon revision v3.0, 2MB external flash
FLASH_CRYPT_CNT eFuse value is 1
Flash encryption feature is enabled in DEVELOPMENT mode
Erasing partition "storage" (0x1000 bytes)
Writing data with esp_partition_write:
I (331) example: 0x3ffb4cb0   00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
I (331) example: 0x3ffb4cc0   10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
Reading with esp_partition_read:
I (351) example: 0x3ffb4c90   00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
I (361) example: 0x3ffb4ca0   10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
Reading with esp_flash_read:
I (371) example: 0x3ffb4c90   fb 78 93 6a ef e7 c8 2c  91 70 7d ea cd 77 d4 60  |.x.j...,.p}..w.`|
I (381) example: 0x3ffb4ca0   ca 60 d8 aa 84 b3 eb 75  1d bf 12 0f f4 da 15 de  |.`.....u........|
I (391) nvs: NVS key partition empty, generating keys
I (451) nvs: NVS partition "nvs" is encrypted.
I (471) example: NVS partition "custom_nvs" is encrypted.
I (471) main_task: Returned from app_main()
  1. Tested rewrites idf.py encrypted-flash. Passes (same log output)
  2. Run esptool.py -b 460800 --before default_reset --after no_reset --chip esp32 --no-stub write_flash --flash_mode dio --flash_size 4MB --flash_freq 40m 0x121000 cusotm-nvs/bin/custom-1.bin --encrypt-files 0x120000 cusotm-nvs/keys/keys-custom-1.bin. See esptool output above.

Also, the ESP prints this after a failed write:

...
I (391) nvs: NVS key partition empty, generating keys
I (451) nvs: NVS partition "nvs" is encrypted.
I (471) example: NVS partition "custom_nvs" is encrypted.
...

I Have Read the Troubleshooting Guide

  • I confirm I have read the troubleshooting guide.
@github-actions github-actions bot changed the title Encrypted flash write on ESP32 - Invalid (unsupported command 0xd4 Encrypted flash write on ESP32 - Invalid (unsupported command 0xd4 (ESPTOOL-743) Sep 20, 2023
@DCSBL DCSBL changed the title Encrypted flash write on ESP32 - Invalid (unsupported command 0xd4 (ESPTOOL-743) Encrypted flash write on ESP32 - Invalid (unsupported command 0xd4) Sep 20, 2023
@DCSBL DCSBL changed the title Encrypted flash write on ESP32 - Invalid (unsupported command 0xd4) Encrypted flash write on ESP32 - Invalid (unsupported command 0xd4) (ESPTOOL-743) Sep 20, 2023
@DCSBL
Copy link
Contributor Author

DCSBL commented Sep 25, 2023

We currently have an workaround by flashing all partitions first, including the custom NVS partition, and then let the bootloader encrypt all required partitions.

We suspect this is not an option for mass production.

@radimkarnis
Copy link
Collaborator

Hi @DCSBL,
thanks for the report!

could you please also try older releases of esptool (e.g 4.2.1 or even 3.3.3). This would help to rule out any possible regressions.

I will try to reproduce the issue and investigate more.

@DCSBL
Copy link
Contributor Author

DCSBL commented Sep 25, 2023

Yes, will do this now.

@DCSBL
Copy link
Contributor Author

DCSBL commented Sep 25, 2023

Using esptool==4.2.1 and esptool==3.3.3 I get the following: (added -p /dev/cu.usbserial-02BFRZ28 to the full command.)

esptool.py v3.3.3
Serial port /dev/cu.usbserial-02BFRZ28
Connecting......................................

A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html


Full log with --trace

esptool.py v3.3.3
Serial port /dev/cu.usbserial-02BFRZ28
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.000 Read 12 bytes: 643a30783430303830343034
TRACE +0.000 Read invalid data: 643a30783430303830343034
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.103 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 No serial data received.
.TRACE +0.107 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.091 Read 1 bytes: 1b
TRACE +0.000 Read invalid data: 1b
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.102 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.000 Read 2 bytes: 3530
TRACE +0.000 Read invalid data: 3530
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.105 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.000 Read 4 bytes: 8dbdc995
TRACE +0.000 Read invalid data: 8dbdc995
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.719 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.000 Read 7 bytes: 1b5b305242aa70
TRACE +0.000 Read invalid data: 1b5b305242aa70
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.102 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.000 Read 16 bytes: 6e203030303033414530207d99b185cd
TRACE +0.000 Read invalid data: 6e203030303033414530207d99b185cd
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.106 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.048 Read 1 bytes: 1b
TRACE +0.000 Read invalid data: 1b
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.103 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.104 No serial data received.
.TRACE +0.102 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.105 No serial data received.
.TRACE +0.264 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.000 Read 3 bytes: 3a3078
TRACE +0.000 Read invalid data: 3a3078
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.105 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.101 No serial data received.
.TRACE +0.104 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.091 Read 1 bytes: 1b
TRACE +0.000 Read invalid data: 1b
TRACE +0.000 Remaining data in serial buffer: 5b303b
.TRACE +0.106 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.000 Read 16 bytes: 6d492028353439292063705d270ad181
TRACE +0.000 Read invalid data: 6d492028353439292063705d270ad181
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.102 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.000 Read 12 bytes: 702720402033653830303020
TRACE +0.000 Read invalid data: 702720402033653830303020
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.719 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.000 Read 4 bytes: 202835ae
TRACE +0.000 Read invalid data: 202835ae
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.107 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.000 Read 16 bytes: 2920686561705f696e69743ab2c20212
TRACE +0.000 Read invalid data: 2920686561705f696e69743ab2c20212
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.106 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.044 Read 1 bytes: 1b
TRACE +0.000 Read invalid data: 1b
TRACE +0.000 Remaining data in serial buffer: 5b303b
.TRACE +0.105 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.101 No serial data received.
.TRACE +0.102 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.105 No serial data received.
.TRACE +0.270 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.000 Read 11 bytes: 6c6f61643a307834303038
TRACE +0.000 Read invalid data: 6c6f61643a307834303038
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.105 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 No serial data received.
.TRACE +0.102 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.093 Read 1 bytes: 1b
TRACE +0.000 Read invalid data: 1b
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.103 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.000 Read 16 bytes: 6370755f73746172743a20a2a5b59502
TRACE +0.000 Read invalid data: 6370755f73746172743a20a2a5b59502
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.102 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.000 Read 11 bytes: 636f72655f64756d705f66
TRACE +0.000 Read invalid data: 636f72655f64756d705f66
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.720 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.000 Read 4 bytes: 0982da5b
TRACE +0.000 Read invalid data: 0982da5b
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.107 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.000 Read 18 bytes: 
    52414d1b5b306d0d 0a1b5b302027636f | RAM.[0m...[0 'co
    7265                              | re
TRACE +0.000 Read invalid data: 
    52414d1b5b306d0d 0a1b5b302027636f | RAM.[0m...[0 'co
    7265                              | re
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.103 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.049 Read 1 bytes: 1b
TRACE +0.000 Read invalid data: 1b
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.102 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.105 No serial data received.
.TRACE +0.103 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.105 No serial data received.
.TRACE +0.269 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.000 Read 1 bytes: 2c
TRACE +0.000 Read invalid data: 2c
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.104 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 No serial data received.
.TRACE +0.108 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.087 Read 1 bytes: 1b
TRACE +0.000 Read invalid data: 1b
TRACE +0.000 Remaining data in serial buffer: 
.TRACE +0.103 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.000 Read 13 bytes: 3429206370755f7374617274a2
TRACE +0.000 Read invalid data: 3429206370755f7374617274a2
TRACE +0.000 Remaining data in serial buffer: 025aa509
.TRACE +0.102 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.000 Read 2 bytes: 6d70
TRACE +0.000 Read invalid data: 6d70
TRACE +0.000 Remaining data in serial buffer: 
.

A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html

@radimkarnis
Copy link
Collaborator

Hi @DCSBL,
that is another unrelated issue - your host cannot automatically reset the ESP into download mode with older esptool versions. You can try manually bridging IO0 to GND or pressing and holding the BOOT button while flashing to do this manually. Then the connection should work and the real output will be visible.

@DCSBL
Copy link
Contributor Author

DCSBL commented Sep 25, 2023

Hmm, tried that but didn't work. Let me do that again..

@radimkarnis
Copy link
Collaborator

@DCSBL
Copy link
Contributor Author

DCSBL commented Sep 25, 2023

Ah, that works. But sadly got the same response..

esptool.py v3.3.3
Serial port /dev/cu.usbserial-02BFRZ28
Connecting.........
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 94:3c:c6:e2:ae:6c
Changing baud rate to 460800
Changed.
Enabling default SPI flash mode...
Configuring flash size...
Flash will be erased from 0x003f9000 to 0x003fcfff...
Erasing flash...
Took 0.17s to erase flash block
Wrote 16384 bytes at 0x003f9000 in 0.7 seconds (189.0 kbit/s)...
Hash of data verified.
Erasing flash...
Took 0.05s to erase flash block
Writing at 0x003ff000... (25 %)Traceback (most recent call last):
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 5651, in <module>
    _main()
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 5644, in _main
    main()
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 5076, in main
    operation_func(esp, args)
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 4231, in write_flash
    esp.flash_encrypt_block(block, seq)
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 854, in flash_encrypt_block
    self.check_command(
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 520, in check_command
    val, data = self.command(op, data, chk, timeout=timeout)
  File "~/.espressif/python_env/idf5.1_py3.9_env/bin/esptool.py", line 505, in command
    raise UnsupportedCommandError(self, op)
__main__.UnsupportedCommandError: Invalid (unsupported) command 0xd4

@DCSBL
Copy link
Contributor Author

DCSBL commented Oct 5, 2023

Sorry to bother you, but did you have time to look into this for me? We need to order modules soon.. 🙂

@Harshal5
Copy link
Contributor

Harshal5 commented Oct 5, 2023

Hello @DCSBL ,
Thanks for the report!

The ESP32 ROM does not support the encrypted-writes command. Thus, the need for the esptool's flasher-stub is necessary, so could you retry by just removing the --no-stub flag from the above command in the case of ESP32?

esptool.py -b 460800 --before default_reset --after no_reset --chip esp32 write_flash --flash_mode dio --flash_size 4MB --flash_freq 40m 0x121000 cusotm-nvs/bin/custom-1.bin --encrypt-files 0x120000 cusotm-nvs/keys/keys-custom-1.bin

@DCSBL
Copy link
Contributor Author

DCSBL commented Oct 6, 2023

Yes, that's it! So easy when you know what to do. Thanks!

Closing this as my problem is fixed. But besides that, did I miss any documentation about this behaviour or is there an opportunity to improve something?

@DCSBL DCSBL closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2023
@dobairoland
Copy link
Collaborator

@Harshal5 Thank you for your help!

@Harshal5
Copy link
Contributor

Harshal5 commented Oct 6, 2023

is there an opportunity to improve something?

Yes actually this needs to be documented, shall update the Encrypted Flash Protection docs page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants