ESP32 with Flash Encryption enabled - partition 0 invalid magic number 0x6e9

I have an app that has been working on the ESP32 Dev Kits for some time but I want to start encrypting it going forward.

However, when I enable Flash Encryption via menuconfig, build and upload it, I get this error on first upload:

image

I am using custom partitions, so here is my partitions.csv:

# Name,   Type, SubType, Offset,   Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap,,,,
nvs,data,nvs,,16K,
otadata,data,ota,,8K,
phy_init,data,phy,,4K,
factory,app,factory,,1M,
ota_0,app,ota_0,,1M,
ota_1,app,ota_1,,1M,

In platform.io and menuconfig, offset is set at 0x10000.

platform.ini is as follows:

[env:esp32dev]
platform = https://github.com/platformio/platform-espressif32.git
board = esp32dev
framework = arduino
                     espidf
monitor_speed = 115200
monitor_filters = direct
board_build.partitions = partitions.csv
build_flags = 
    -I include
    -I include/util
    -D CONFIG_PARTITION_TABLE_OFFSET=0x10000

platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#idf-release/v4.0

lib_deps =  ArduinoJson

Logging is set at warning as info creates a bootloader that’s too large.

I have run pio run -t erase and pio run -t clean before the uploads.

Any idea what I’m missing?

Thanks

I’ll answer my own question. Turns out misunderstood the offset and kept pointing it to the app partition, instead of realizing its referring to the actual partition table location.