Unable to flash image once Secure Boot / Flash Encryption has been enabled

andreko
Posts: 12
Joined: Tue May 09, 2023 10:29 am

Unable to flash image once Secure Boot / Flash Encryption has been enabled

Postby andreko » Fri Jun 30, 2023 1:51 pm

Hi I followed the documentation to enable Secure Boot and Flash Encryption for my ESP32-C2 platform.
I choose development mode to be able to still download plain text images using the UART downloader.
The flashing of the initial image succeeded. I see in the traces from the bootloader that secure boot and flash encryption is enabled and that bootloader and image are verified successfully. This of course also works after several reboots.

Next step was to slightly modify my image and flash it again using the command idf.py flash

What I get is an error during that execution telling me:

Code: Select all

esptool.util.UnsupportedCommandError: This command (0xa) is not supported in Sec
ure Download Mode
As I have no clue what 0xa stands for as a command I see no chance to find the issue. Can someone shed a light on this and maybe even has a solution for it?

many thanks for your feedback

Here the full command output:

Code: Select all

C:\WorkingArea\mitteWorkspace\helloWorldFirmware>idf.py flash monitor
Executing action: flash
Serial port COM24
Connecting.......................
COM24 failed to connect: Failed to connect to Espressif device: No serial data r
eceived.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/
latest/troubleshooting.html
Serial port COM20
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying agai
n...
Connecting....
Detecting chip type... ESP32-C2
Running ninja in directory C:\WorkingArea\mitteWorkspace\helloWorldFirmware\bui
ld
Executing "ninja flash"...
[1/5] cmd.exe /C "cd /D C:\WorkingArea\mitteWorkspace\helloWorldFirmware\build\
esp-idf\esptool_py && python C:/WorkingArea/mitteTools/Espressif-IDF/esp-idf/com
ponents/partition_table/check_sizes.py --offset 0xc000 partition --type app C:/W
orkingArea/mitteWorkspace/helloWorldFirmware/build/partition_table/partition-ta
ble.bin C:/WorkingArea/mitteWorkspace/helloWorldFirmware/build/helloWorldFirmw
are.bin"
helloWorldFirmware.bin binary size 0x69000 bytes. Smallest app partition is 0x1
00000 bytes. 0x97000 bytes (59%) free.
[2/5] Performing build step for 'bootloader'
[1/1] cmd.exe /C "cd /D C:\WorkingArea\mitteWorkspace\helloWorldFirmware\build\
bootloader\esp-idf\esptool_py && python C:/WorkingArea/mitteTools/Espressif-IDF/
esp-idf/components/partition_table/check_sizes.py --offset 0xc000 bootloader 0x0
 C:/WorkingArea/mitteWorkspace/helloWorldFirmware/build/bootloader/bootloader.b
in"
Bootloader binary size 0xb000 bytes. 0x1000 bytes (8%) free.
[2/3] cmd.exe /C "cd /D C:\WorkingArea\mitteTools\Espressif-IDF\esp-idf\componen
ts\esptool_py && C:\Users\AK\.espressif\tools\cmake\3.24.0\bin\cmake.ex
e -D IDF_PATH=C:/WorkingArea/mitteTools/Espressif-IDF/esp-idf -D SERIAL_TOOL=pyt
hon;;C:/WorkingArea/mitteTools/Espressif-IDF/esp-idf/components/esptool_py/espto
ol/esptool.py;--chip;esp32c2 -D SERIAL_TOOL_ARGS=--before=default_reset;--after=
no_reset;--no-stub;write_flash;@flash_args -D WORKING_DIRECTORY=C:/WorkingArea/m
itteWorkspace/helloWorldFirmware/build -P C:/WorkingArea/mitteTools/Espressif-I
DF/esp-idf/components/esptool_py/run_serial_tool.cmake"
esptool esp32c2 -p COM20 -b 460800 --before=default_reset --after=no_reset --no-
stub write_flash --flash_mode dio --flash_freq 60m --flash_size 2MB 0x20000 mitt
eInsideFirmware.bin 0xc000 partition_table/partition-table.bin
esptool.py v4.5.1
Serial port COM20
Traceback (most recent call last):
  File "C:\Program Files\Python3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\__main__.py", line 9, in <module>
    esptool._main()
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\__init__.py", line 1032, in _main
    main()
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\__init__.py", line 674, in main
    esp = esp or get_default_connected_device(
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\__init__.py", line 921, in get_default_connected_device
    _esp.connect(before, connect_attempts)
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\loader.py", line 691, in connect
    self._post_connect()
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\targets\esp32c2.py", line 113, in _post_connect
    if self.get_chip_revision() == 0:
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\targets\esp32.py", line 183, in get_chip_revision
Connecting....
    return self.get_major_chip_version() * 100 + self.get_minor_chip_version()  
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\targets\esp32c2.py", line 83, in get_major_chip_version
    return (self.read_reg(self.EFUSE_BLOCK2_ADDR + (4 * num_word)) >> 20) & 0x3 
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\loader.py", line 705, in read_reg
    val, data = self.command(
  File "C:\Users\AK\.espressif\python_env\idf5.2_py3.8_env\lib\site-pac
kages\esptool\loader.py", line 418, in command
    raise UnsupportedCommandError(self, op)
esptool.util.UnsupportedCommandError: This command (0xa) is not supported in Sec
ure Download Mode
CMake Error at run_serial_tool.cmake:66 (message):

  python;;C:/WorkingArea/mitteTools/Espressif-IDF/esp-idf/components/esptool_py/
esptool/esptool.py;--chip;esp32c2
  failed.



FAILED: CMakeFiles/flash C:/WorkingArea/mitteWorkspace/helloWorldFirmware/build
/CMakeFiles/flash
cmd.exe /C "cd /D C:\WorkingArea\mitteTools\Espressif-IDF\esp-idf\components\esp
tool_py && C:\Users\AK\.espressif\tools\cmake\3.24.0\bin\cmake.exe -D I
DF_PATH=C:/WorkingArea/mitteTools/Espressif-IDF/esp-idf -D SERIAL_TOOL=python;;C
:/WorkingArea/mitteTools/Espressif-IDF/esp-idf/components/esptool_py/esptool/esp
tool.py;--chip;esp32c2 -D SERIAL_TOOL_ARGS=--before=default_reset;--after=no_res
et;--no-stub;write_flash;@flash_args -D WORKING_DIRECTORY=C:/WorkingArea/mitteWo
rkspace/helloWorldFirmware/build -P C:/WorkingArea/mitteTools/Espressif-IDF/esp
-idf/components/esptool_py/run_serial_tool.cmake"
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the C:\WorkingArea\mi
tteWorkspace\helloWorldFirmware\build\log\idf_py_stderr_output_2892 and C:\Work
ingArea\mitteWorkspace\helloWorldFirmware\build\log\idf_py_stdout_output_2892 

andreko
Posts: 12
Joined: Tue May 09, 2023 10:29 am

Re: Unable to flash image once Secure Boot / Flash Encryption has been enabled

Postby andreko » Fri Jun 30, 2023 2:21 pm

One addition: found this command in the documentation of flash encryption in the chaper to re-flash updated partitions

Code: Select all

idf.py encrypted-app-flash monitor


But it creates the same problem

Who is online

Users browsing this forum: Bing [Bot] and 101 guests