[ota] Partition table update: Fix log messages (#16241)

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Mat931
2026-05-06 14:59:10 +00:00
committed by GitHub
parent 90693fb39a
commit 2864922ac0
4 changed files with 28 additions and 18 deletions
@@ -117,8 +117,8 @@ void ESPHomeOTAComponent::dump_config() {
" Partition table:\n" " Partition table:\n"
" %-12s %-4s %-8s %-10s %-10s", " %-12s %-4s %-8s %-10s %-10s",
"Name", "Type", "Subtype", "Address", "Size"); "Name", "Type", "Subtype", "Address", "Size");
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL); esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, nullptr);
while (it != NULL) { while (it != nullptr) {
const esp_partition_t *partition = esp_partition_get(it); const esp_partition_t *partition = esp_partition_get(it);
ESP_LOGCONFIG(TAG, " %-12s 0x%-2X 0x%-6X 0x%-8" PRIX32 " 0x%-8" PRIX32, partition->label, partition->type, ESP_LOGCONFIG(TAG, " %-12s 0x%-2X 0x%-6X 0x%-8" PRIX32 " 0x%-8" PRIX32, partition->label, partition->type,
partition->subtype, partition->address, partition->size); partition->subtype, partition->address, partition->size);
@@ -20,8 +20,7 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size, ota::OTAType ota_type)
#ifdef USE_OTA_PARTITIONS #ifdef USE_OTA_PARTITIONS
this->ota_type_ = ota_type; this->ota_type_ = ota_type;
if (this->ota_type_ == ota::OTA_TYPE_UPDATE_PARTITION_TABLE) { if (this->ota_type_ == ota::OTA_TYPE_UPDATE_PARTITION_TABLE) {
// Reject any size other than ESP_PARTITION_TABLE_MAX_LEN: under- leaves stale bytes from the // Reject any size other than ESP_PARTITION_TABLE_MAX_LEN
// previous table; over- can't fit the reserved region.
if (image_size != ESP_PARTITION_TABLE_MAX_LEN) { if (image_size != ESP_PARTITION_TABLE_MAX_LEN) {
ESP_LOGE(TAG, "Wrong partition table size: expected %u bytes, got %zu", ESP_PARTITION_TABLE_MAX_LEN, image_size); ESP_LOGE(TAG, "Wrong partition table size: expected %u bytes, got %zu", ESP_PARTITION_TABLE_MAX_LEN, image_size);
return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY;
@@ -11,6 +11,7 @@
#include <esp_ota_ops.h> #include <esp_ota_ops.h>
#include <nvs_flash.h> #include <nvs_flash.h>
#include <cinttypes>
#include <cstring> #include <cstring>
namespace esphome::ota { namespace esphome::ota {
@@ -135,10 +136,20 @@ OTAResponseTypes IDFOTABackend::validate_new_partition_table_(uint32_t running_a
// Rejecting here is non-destructive (no flash op has run yet); the user can safely retry with // Rejecting here is non-destructive (no flash op has run yet); the user can safely retry with
// a different .bin. Log enough info that they can pick the right method without guessing. // a different .bin. Log enough info that they can pick the right method without guessing.
ESP_LOGE(TAG, ESP_LOGE(TAG,
"Running app at 0x%X (%u bytes used) does not fit any compatible slot in the new " "The new partition table must contain a compatible app partition with:\n"
"partition table. Pick a migration method whose size limit is at least %u bytes and " " size: at least %" PRIu32 " bytes (0x%" PRIX32 ")\n"
"retry; no flash content was modified.", " address: one of",
running_app_offset, running_app_size, running_app_size); (uint32_t) running_app_size, (uint32_t) running_app_size);
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, nullptr);
while (it != nullptr) {
const esp_partition_t *partition = esp_partition_get(it);
if (partition->size >= running_app_size) {
ESP_LOGE(TAG, " 0x%" PRIX32, partition->address);
}
it = esp_partition_next(it);
}
esp_partition_iterator_release(it);
ESP_LOGE(TAG, "Upload a different partition table. No flash content was modified.");
return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY;
} }
if (app_partitions_found < 2) { if (app_partitions_found < 2) {
@@ -154,11 +165,11 @@ OTAResponseTypes IDFOTABackend::validate_new_partition_table_(uint32_t running_a
return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY;
} }
if (otadata_overlap) { if (otadata_overlap) {
// Unlikely, the otadata partition is before the start of the first app partition in most cases
ESP_LOGE(TAG, ESP_LOGE(TAG,
"New otadata partition overlaps with the running app at 0x%X (size %u). The chosen " "New otadata partition overlaps with the running app at address: 0x%" PRIX32 ", running app size: %" PRIu32
"partition table is not compatible with this device's current flash layout; pick a " " bytes",
"different migration method.", running_app_offset, (uint32_t) running_app_size);
running_app_offset, running_app_size);
return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY;
} }
@@ -198,8 +209,8 @@ OTAResponseTypes IDFOTABackend::update_partition_table() {
// can leave the device unbootable until it is recovered with a serial flash. // can leave the device unbootable until it is recovered with a serial flash.
ESP_LOGE(TAG, "Starting partition table update.\n" ESP_LOGE(TAG, "Starting partition table update.\n"
" DO NOT REMOVE POWER until the device reboots successfully.\n" " DO NOT REMOVE POWER until the device reboots successfully.\n"
" Loss of power during this operation may render the device unable to boot until\n" " Loss of power during this operation may render the device\n"
" it is recovered via a serial flash."); " unable to boot until it is recovered via a serial flash.");
// One guard over the whole critical section in case an IDF call takes longer than expected on // One guard over the whole critical section in case an IDF call takes longer than expected on
// some chip variant. // some chip variant.
@@ -214,7 +225,7 @@ OTAResponseTypes IDFOTABackend::update_partition_table() {
// which leaves esp_ota_get_running_partition() returning nullptr. // which leaves esp_ota_get_running_partition() returning nullptr.
const esp_partition_t *running_app_part = find_app_partition_at(running_app_offset, running_app_size); const esp_partition_t *running_app_part = find_app_partition_at(running_app_offset, running_app_size);
if (running_app_part == nullptr) { if (running_app_part == nullptr) {
ESP_LOGE(TAG, "Cannot resolve running app partition at offset 0x%X", running_app_offset); ESP_LOGE(TAG, "Cannot resolve running app partition at address 0x%" PRIX32, running_app_offset);
return OTA_RESPONSE_ERROR_PARTITION_TABLE_UPDATE; return OTA_RESPONSE_ERROR_PARTITION_TABLE_UPDATE;
} }
ESP_LOGD(TAG, "Copying running app from 0x%X to 0x%X (size: 0x%X)", running_app_part->address, ESP_LOGD(TAG, "Copying running app from 0x%X to 0x%X (size: 0x%X)", running_app_part->address,
+3 -3
View File
@@ -139,9 +139,9 @@ _ERROR_MESSAGES: dict[int, str] = {
), ),
RESPONSE_ERROR_PARTITION_TABLE_UPDATE: ( RESPONSE_ERROR_PARTITION_TABLE_UPDATE: (
"An error occurred while updating the partition table. The device is now " "An error occurred while updating the partition table. The device is now "
"in a degraded state (NVS handles are invalid; many components will fail) " "in a degraded state and may not be able to boot. Open the logs and retry "
"and may not be able to boot. Check the logs, reboot the device, and " "the partition table update without rebooting the device. If the device "
"retry the update. If the device fails to boot, recover it via a serial flash." "fails to boot, recover it via a serial flash."
), ),
RESPONSE_ERROR_UNKNOWN: "Unknown error from ESP", RESPONSE_ERROR_UNKNOWN: "Unknown error from ESP",
} }