Replacing encrypted app, causes "No MD5" partition error: why?!

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

Replacing encrypted app, causes "No MD5" partition error: why?!

Postby HighVoltage » Sun Oct 30, 2022 4:51 am

I have set up my ESP32e for flash encryption, and using IDF 4.4.2 environment, did the first plaintext upload, and it got encrypted, and runs fine.

I can update the application source code, rebuild it with idf.py build, then encrypt it with my key and espsecure.py tool, and re-upload it, and it also works.

Now I am trying to upload a bin that was built in Arduino IDE (versus the above, built by IDF environment). I encrypt the bin with my key, and write just the encrypted flash the same way I did above, but now I get "No MD5 found in partition table". I'm not touching the partition table, what does the application flash area have to do with the MD5 for the partition table? I can go back to the IDF built bin again, and the MD5 error disappears. Odd!

Any thought what is going on? How to fix it? Here's a comparison of the sections of the log, success versus broken:

Code: Select all

I (256) boot: Checking flash encryption...
I (257) flash_encrypt: flash encryption is enabled (3 plaintext flashes left)
I (260) boot: Disabling RNG early entropy source...
I (276) cpu_start: Pro cpu up.
...

Code: Select all

I (323) boot: Checking flash encryption...
I (323) flash_encrypt: flash encryption is enabled (3 plaintext flashes left)
I (328) boot: Disabling RNG early entropy source...
E (356) partition: No MD5 found in partition table
E (356) partition: load_partitions returned 0x105

assert failed: esp_ota_get_running_partition esp_ota_ops.c:553 (it != NULL)

Backtrace:0x40083625:0x3ffbca100x4008b40d:0x3ffbca30 0x400906c9:0x3ffbca50 0x400d793e:0x3ffbcb80 0x400d366c:0x3ffbcba0 0x400d3fc8:0x3ffbcbd0 0x40148b7b:0x3ffbcc00 

ELF file SHA256: 0000000000000000

Rebooting...

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby dmitrij999 » Sun Oct 30, 2022 7:40 am

Could you please build your app from ESP-IDF, but with disabling MD5 check?
I think it's the problem with the bootloader

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby HighVoltage » Mon Oct 31, 2022 6:14 am

It's not just my application that has this problem, I have tried using some of the simple arduino samples such as the WiFi scan, and it exhibits the same problem.

I should also note, both my application and the simple arduino WiFiscan example work fine following the same procedure (minus encryption) when I first tested in the IDF environment without flash encryption turned on.

I then turned on Flash encryption with the IDF blink example loaded which encrypted and rebooted fine. I subsequently tried to replace just the app with my encrypted app or the WiFiscan simple example app encrypted. They both give the same MD5 validation error.

I tried searching for the source file that contains the quoted assertion error to investigate what is going on, but it doesn't seem to be available anywhere. Is it?

Of what relevance is the application code to MD5 check for the patition configuration? That kind of dependency sounds like a bug.

Why do you think it is the bootloader?

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby dmitrij999 » Mon Oct 31, 2022 7:03 am

I think it's not the bootloader itself.
As your app and bootloader are built with flash encryption on, over there options related to flash encryption are on as well (let's say, caching), and corresponding core peripherals should be initialized, so, both of them are encryption-aware.
And now, you use encryption-aware bootloader and non-encryption-aware app, where bootloader initiates core and peripherals the one way, and app is expecting the core and peripherals initiated the another way

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby dmitrij999 » Mon Oct 31, 2022 8:25 am

As an option, you can try to build the ESP-IDF project without MD5 partitions checking (unset if thru Menuconfig) and replace your app.
If the application from Arduino doesn't work it means that it's non-encryption-aware

ESP_Mahavir
Posts: 190
Joined: Wed Jan 24, 2018 6:51 am

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby ESP_Mahavir » Mon Oct 31, 2022 11:12 am

Please compare `sdkconfig` files carefully between Arduino and IDF build. Please see if `CONFIG_PARTITION_TABLE_MD5` is enabled or not. If this config is enabled then application shall verify the integrity of the partition table binary and it may fail it does not find appropriate MD5 sum appended to it.

Here are some pointers that may help here:

https://github.com/espressif/esp-idf/bl ... #L179-L182
https://docs.espressif.com/projects/esp ... -table-md5

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby HighVoltage » Mon Oct 31, 2022 8:22 pm

dmitrij999 wrote:
Mon Oct 31, 2022 7:03 am
As your app and bootloader are built with flash encryption on, over there options related to flash encryption are on as well (let's say, caching), and corresponding core peripherals should be initialized, so, both of them are encryption-aware.
And now, you use encryption-aware bootloader and non-encryption-aware app, where bootloader initiates core and peripherals the one way, and app is expecting the core and peripherals initiated the another way
.

This "encryption-aware" concept really does not make any sense. You are suggesting if you have a working "plain text" app installed, and then you turn on the built-in encryption process, the working "plain text" app can stop working when it gets auto-encrypted because it may have been built in an environment that is not encryption aware?!

Can you point to where this is documented? Everything I've read implies a working plain-text app will just be encoded by AES and decoded automatically. Nothing suggests that a plain-text app that works is at risk of not working after it gets encrypted.

Otherwise, are you suggesting the onboard auto-encryption is doing something more than an encryption operation? It is doing some magic to turn a non "encryption-aware" application into an "encryption aware" one?

As auto-encryption can happen on board, converting the plain-text app into an encrypted one, it follows that there is no "encryption aware" process relevant to the building of the -application-.

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby HighVoltage » Mon Oct 31, 2022 8:34 pm

The IDF environment I am using has been set up according to the Espressif documention for arduino-lib-builder. Therefore I am using the same sdkconfig provided there. It would have been updated when I run menuconfig, and indeed, I look at it, and it has extra options from the stock arduino one, such as this section

Code: Select all

#
# Security features
#
# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set
# CONFIG_SECURE_BOOT is not set
CONFIG_SECURE_FLASH_ENC_ENABLED=y
CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=y
# CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE is not set

#
# Potentially insecure options
#
# CONFIG_SECURE_BOOT_ALLOW_ROM_BASIC is not set
# CONFIG_SECURE_BOOT_ALLOW_JTAG is not set
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC=y
# CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC is not set
# CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE is not set
# CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED is not set
# end of Potentially insecure options
Curiously, the partition table MD5 option is

Code: Select all

# CONFIG_PARTITION_TABLE_MD5 is not set
I explicitly set it to both "n" and "y" as a test and used the generated arduino bin. The same MD5 error occurs regardless. I also back-copied the revised sdkconfig from the IDF environment to the arduino one and built with that. That bin also still has the MD5 error.

Generating the IDF build with MD5 turned off or on also makes no different.
Last edited by HighVoltage on Mon Oct 31, 2022 9:14 pm, edited 1 time in total.

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby HighVoltage » Mon Oct 31, 2022 8:43 pm

Because I have been trying to get encryption working offline, I am down to just one board that does not have encryption enabled, and I'd like to keep it that way so my development process is not held up. I need to order some more boards.

But, for the ones that have encryption enabled, I would like to test onboard encryption with my applications rather than doing it externally as I've been trying. They report there are still 3 plaintext flashes left.

If I want to set up a new plaintext installation, is it just a matter of setting the FLASH_CRYPT_CNT to 2? ( it is currently at 1 ).

Do I then upload all the bins in plaintext again, or just the application?

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

Re: Replacing encrypted app, causes "No MD5" partition error: why?!

Postby HighVoltage » Tue Nov 01, 2022 3:44 am

I have done some testing in plain text. I could recreate the MD5 boot error in plain text as well when trying to install an arduino-generated application bin. But it's dependent on something in the IDF environment. In one trial project set up in IDF, the arduino-generated application bin will work fine. Then another trial IDF project set up, the same arduino-generated application bin will produce the MD5 error.

I also noticed the menuconfig output to sdkcong for MD5 is only either commented out or set to 'y', but never gets set to 'n'. By the way, where are the defaults that a fresh sdkconfig is generated from? I could not figure that out.

Code: Select all

# CONFIG_PARTITION_TABLE_MD5 is not set

Code: Select all

CONFIG_PARTITION_TABLE_MD5=y
Anyway, it's clear the problem does not seem strictly related to encryption, although maybe when I set up encryption there was some other relevant change.

I also noticed the esptool that gets installed in Arduino IDE through the board manager for ESP32 is version "4.2.1". But in the IDF v4.4.2 environment I installed, it is only at v3.3.2-dev. Why such a dated version? The idf.py tool is up to date in the same environment.

Code: Select all

> esptool.py version
esptool.py v3.3.2-dev
3.3.2-dev

> idf.py --version
ESP-IDF v4.4.2-dirty

Who is online

Users browsing this forum: No registered users and 95 guests