Erase and write to bootloader (SSBL) partition

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

Erase and write to bootloader (SSBL) partition

Postby leschge » Mon Aug 28, 2023 7:53 am

Hello,

I am trying to modify the bootloader partition during runtime, but having troubles with it.
The main goal in the end is to rewrite/flash the SSBL during runtime from for example OTA 0.

But my attempts fail. The device crashes at (it seems) random states when calling esp_partition_erase_range() or esp_partition_write()
with

Code: Select all

abort() was called at PC 0x403789cf on core 1
My attempt is the following, note that the hash calculation returns ESP_OK
Encryption and secure boot is disabled. I use a custom bootloader.

My code running from factory partition:

Code: Select all

 
     const esp_partition_t part_ssbl = {
    		.type = ESP_PARTITION_TYPE_APP,
    		.address = 0x0,
			.size = CONFIG_PARTITION_TABLE_OFFSET
    };

    uint8_t sha_256[64];
    esp_err_t res = esp_partition_get_sha256(&part_ssbl, sha_256);
    ESP_LOGW(TAG,"HASH Res: %s", esp_err_to_name(res));

    res = esp_partition_erase_range(&part_ssbl, 0x1000, 0x1000);
    ESP_LOGW(TAG,"ERASE Res: %s", esp_err_to_name(res));

    uint8 rubbish[64] = {0};
    res = esp_partition_write(&part_ssbl,0x1000,&rubbish,64);
    ESP_LOGW(TAG,"WRITE Res: %s", esp_err_to_name(res));

Edit: Same problem with esp_flash_erase_region(esp_flash_default_chip, 0x1000, 4096);

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Erase and write to bootloader (SSBL) partition

Postby ESP_Sprite » Tue Aug 29, 2023 12:23 am

First of all, doing this in production is terribly dangerous; if something goes wrong during the rewrite, you have an unbootable ESP32.
Secondly, ESP-IDF by default stops you from using the partition API to do dangerous stuff like this, as 99% of the time it's a programmer error. I think there's a menuconfig option to disable this behaviour.

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

Re: Erase and write to bootloader (SSBL) partition

Postby leschge » Tue Aug 29, 2023 2:07 pm

ESP_Sprite wrote:
Tue Aug 29, 2023 12:23 am
First of all, doing this in production is terribly dangerous; if something goes wrong during the rewrite, you have an unbootable ESP32.
Secondly, ESP-IDF by default stops you from using the partition API to do dangerous stuff like this, as 99% of the time it's a programmer error. I think there's a menuconfig option to disable this behaviour.
Thanks for your reply, I am aware of the danger.
The corresponding option is SPI_FLASH_DANGEROUS_WRITE.

Who is online

Users browsing this forum: PhilipK and 98 guests