Reading encrypted flash with Esptool - Confusion about empty space
Posted: Wed Oct 15, 2025 10:02 pm
Hi,
We have a device using ESP32. We have turned on secure boot V2 and flash encryption with a device-generated flash encryption key. For development, we use flash encryption in "development" mode so we can re-flash easily, although for production we enable "production" mode to lock it down.
I have been doing some tests which involve downloading the flash contents from the device to a PC with esptool:
My understanding is that the read-flash command can't decrypt the encrypted flash contents during the transfer, so I would expect the entire file of downloaded data to be "gibberish", including the empty parts of the flash, because "decoding" the empty data (0xFF) will result in garbage data.
However, when I examine the file I generated with read-flash, the empty sections are still 0xFF. E.g., here is the start of the bootloader:
The bootloader binary data looks to be encrypted as expected.
Why is the empty space coming out as 0xff?
Does the hardware flash decryption somehow know which areas of the flash are not used, and so avoid trying to "decrypt" them?
We have a device using ESP32. We have turned on secure boot V2 and flash encryption with a device-generated flash encryption key. For development, we use flash encryption in "development" mode so we can re-flash easily, although for production we enable "production" mode to lock it down.
I have been doing some tests which involve downloading the flash contents from the device to a PC with esptool:
Code: Select all
esptool.exe -p COMx -b 2000000 read-flash 0 8M flash-complete.binHowever, when I examine the file I generated with read-flash, the empty sections are still 0xFF. E.g., here is the start of the bootloader:
Code: Select all
ff, ff, ff, ff, ff, ff, ff, ff,
ff, ff, ff, ff, ff, ff, ff, ff,
ff, ff, ff, ff, ff, ff, ff, ff,
ff, ff, ff, ff, ff, ff, ff, ff,
ff, ff, ff, ff, ff, ff, ff, ff,
ff, ff, ff, ff, ff, ff, ff, ff,
ca, 0e, 4c, 2a, 19, 87, 5b, 18, # 00001000: Bootloader binary starts here.
f2, 13, 9c, 9d, da, eb, 97, 7a,
ec, b2, 19, 16, f4, e7, 16, 1e,
ab, ea, e0, 96, df, 4e, 76, 29,
6a, ee, 5a, 9e, 87, fb, 7b, 7a,
9c, e9, 8e, 4c, b1, dc, a9, 52,
9c, 61, fd, 1b, d7, 19, 4a, 17,
Why is the empty space coming out as 0xff?
Does the hardware flash decryption somehow know which areas of the flash are not used, and so avoid trying to "decrypt" them?