ESP32-S3 partition 0 invalid magic number

cartoon
Posts: 5
Joined: Fri Feb 17, 2023 5:53 pm

ESP32-S3 partition 0 invalid magic number

Postby cartoon » Mon Jul 24, 2023 3:01 pm

Hi,
I'm trying to setup my ESP32-S3 devkit to test out flash encryption. I seem to be stuck at the 2nd stage bootloader, where it's spitting out this information.

Code: Select all

Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3970,len:0x29a4
load:0x403c9700,len:0xbcc
load:0x403cc700,len:0x45bc
entry 0x403c9954
(36) boot: ESP-IDF 4.4.4 2nd stage bootloader
(37) boot: compile time 10:42:51
(37) boot: chip revision: v0.1
(38) boot_comm: chip revision: 1, min. bootloader chip revision: 0
(45) boot.esp32s3: Boot SPI Speed : 80MHz
(50) boot.esp32s3: SPI Mode       : DIO
(55) boot.esp32s3: SPI Flash Size : 8MB
(60) boot: Enabling RNG early entropy source...
(65) flash_parts: partition 0 invalid magic number 0xbe09
(71) boot: Failed to verify partition table
(76) boot: load partition table error!
Here are the steps I am taking:
1. espsecure.exe generate_flash_encryption_key --keylen 512 key.bin
2. espefuse.exe --port COM26 burn_key BLOCK_KEY0 key.bin XTS_AES_256_KEY
3. espefuse.exe --port COM26 burn_efuse SPI_BOOT_CRYPT_CNT
4. espsecure.exe encrypt_flash_data --aes_xts --keyfile key.bin --address 0x00000 --output bootloader-encrypted.bin bootloader.bin
5. espsecure.exe encrypt_flash_data --aes_xts --keyfile key.bin --address 0x80000 --output partitions-encrypted.bin partitions.bin
6. esptool.exe --chip esp32s3 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0x0 bootloader-encrypted.bin 0x10000 partitions-encrypted.bin

Here is my partition table

Code: Select all

nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
factory,  app,  factory, 0x10000, 0x200000,
app0,     app,  ota_0,   0x210000,0x200000,
app1,     app,  ota_1,   0x410000,0x200000,
spiffs,   data, spiffs,  0x610000,0x1df000, encrypted
nvs_key,  data, nvs_keys,0x7ef000,0x1000, encrypted
coredump, data, coredump,0x7f0000,0x10000, encrypted
I've tried to increase the partition table offset from 0x8000 to 0x10000 (and modify partitions accordingly), but it does not seem to make any difference with respect to the boot error.
The online docs lists this as an example under "flash encryption>possible failures", but the description doesn't match my situation since I confirmed the partition table is indeed encrypted.
https://docs.espressif.com/projects/esp ... e-failures

Can someone give me any advice on how to get past this error?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32-S3 partition 0 invalid magic number

Postby ESP_igrr » Mon Jul 24, 2023 3:40 pm

Just something to check: there seems to be an inconsistency in partition table offset in these two commands:

Code: Select all

5. espsecure.exe encrypt_flash_data --aes_xts --keyfile key.bin --address 0x80000 --output partitions-encrypted.bin partitions.bin
6. esptool.exe --chip esp32s3 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0x0 bootloader-encrypted.bin 0x10000 partitions-encrypted.bin
in the first one you are encrypting the partition for flashing to address 0x80000 and in the second one you are flashing it to 0x10000.

cartoon
Posts: 5
Joined: Fri Feb 17, 2023 5:53 pm

Re: ESP32-S3 partition 0 invalid magic number

Postby cartoon » Mon Jul 24, 2023 6:23 pm

:oops:
Thank you so much for spotting that.
I had the address as 0x00000 for the bootloader, and just was lazily changing the leading digit to an 8 without realizing there were one too many.
Partition table successfully verified now.

Code: Select all

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x403cdd16
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3970,len:0x29a4
load:0x403c9700,len:0xbcc
load:0x403cc700,len:0x45bc
entry 0x403c9954
I (38) boot: ESP-IDF 4.4.4 2nd stage bootloader
I (38) boot: compile time 13:54:20
I (39) boot: chip revision: v0.1
I (40) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (47) boot.esp32s3: Boot SPI Speed : 80MHz
I (52) boot.esp32s3: SPI Mode       : DIO
I (57) boot.esp32s3: SPI Flash Size : 8MB
I (61) boot: Enabling RNG early entropy source...
I (67) boot: Partition Table:
I (70) boot: ## Label            Usage          Type ST Offset   Length
I (78) boot:  0 nvs              WiFi data        01 02 00009000 00005000
I (85) boot:  1 otadata          OTA data         01 00 0000e000 00002000
I (93) boot:  2 factory          factory app      00 00 00010000 00200000
I (100) boot:  3 app0             OTA app          00 10 00210000 00200000
I (108) boot:  4 app1             OTA app          00 11 00410000 00200000
I (115) boot:  5 spiffs           Unknown data     01 82 00610000 001df000
I (123) boot:  6 nvs_key          NVS keys         01 04 007ef000 00001000
I (130) boot:  7 coredump         Unknown data     01 03 007f0000 00010000
I (138) boot: End of partition table

Who is online

Users browsing this forum: No registered users and 195 guests