mirror of
https://github.com/esphome/esphome.git
synced 2025-01-15 20:21:36 +01:00
[debug] Add partition table logging to dump_config
This enhances the `DebugComponent` by adding functionality to log detailed partition table information during the `dump_config()` process. The partition table details are displayed in a clean, aligned format, providing developers with clear insights into the device's flash memory layout. #### **Features:** 1. Logs the following attributes for each partition: - Name - Type - Subtype - Start Address - Size 2. Uses the `esp_partition` API for ESP32 devices running either Arduino or ESP-IDF. 3. Ensures alignment of columns for improved readability. #### **Example Log Output:** ``` [23:37:05][C][debug:033]: Partition table: [23:37:05][C][debug:034]: Name Type Subtype Address Size [23:37:05][C][debug:038]: nvs 1 2 0x00009000 0x00005000 [23:37:05][C][debug:038]: otadata 1 0 0x0000E000 0x00002000 [23:37:05][C][debug:038]: app0 0 16 0x00010000 0x003C0000 [23:37:05][C][debug:038]: app1 0 17 0x003D0000 0x003C0000 [23:37:05][C][debug:038]: eeprom 1 153 0x00790000 0x00001000 [23:37:05][C][debug:038]: spiffs 1 130 0x00791000 0x0000F000 ``` #### **Why This Change is Useful:** 1. **Improved Debugging:** Developers can verify partition configurations directly from logs, without requiring physical access or external tools. 2. **Diagnostic Aid:** Identifies potential issues related to insufficient partition sizes or incorrect layouts. 3. **Consistency:** Provides a clear and formatted output to improve log readability. #### **Implementation Details:** - **Platform-Specific:** The feature is implemented for ESP32 devices using the ESP-IDF framework. - **Formatted Output:** Ensures aligned columns using fixed-width formatting for better clarity.
This commit is contained in:
parent
387bde665e
commit
b2a3161cf3
@ -50,6 +50,10 @@ void DebugComponent::dump_config() {
|
||||
this->reset_reason_->publish_state(get_reset_reason_());
|
||||
}
|
||||
#endif // USE_TEXT_SENSOR
|
||||
|
||||
#ifdef USE_ESP32
|
||||
this->log_partition_info_(); // Log partition information for ESP32
|
||||
#endif // USE_ESP32
|
||||
}
|
||||
|
||||
void DebugComponent::loop() {
|
||||
|
@ -55,6 +55,20 @@ class DebugComponent : public PollingComponent {
|
||||
#endif // USE_ESP32
|
||||
#endif // USE_SENSOR
|
||||
|
||||
#ifdef USE_ESP32
|
||||
/**
|
||||
* @brief Logs information about the device's partition table.
|
||||
*
|
||||
* This function iterates through the ESP32's partition table and logs details
|
||||
* about each partition, including its name, type, subtype, starting address,
|
||||
* and size. The information is useful for diagnosing issues related to flash
|
||||
* memory or verifying the partition configuration dynamically at runtime.
|
||||
*
|
||||
* Only available when compiled for ESP32 platforms.
|
||||
*/
|
||||
void log_partition_info_();
|
||||
#endif // USE_ESP32
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
text_sensor::TextSensor *device_info_{nullptr};
|
||||
text_sensor::TextSensor *reset_reason_{nullptr};
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <esp_heap_caps.h>
|
||||
#include <esp_system.h>
|
||||
#include <esp_chip_info.h>
|
||||
#include <esp_partition.h>
|
||||
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
#include <esp32/rom/rtc.h>
|
||||
@ -28,6 +29,23 @@ namespace debug {
|
||||
|
||||
static const char *const TAG = "debug";
|
||||
|
||||
void DebugComponent::log_partition_info_() {
|
||||
ESP_LOGCONFIG(TAG, "Partition table:");
|
||||
ESP_LOGCONFIG(TAG, " %-12s %-4s %-8s %-10s %-10s", "Name", "Type", "Subtype", "Address", "Size");
|
||||
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
while (it != NULL) {
|
||||
const esp_partition_t *partition = esp_partition_get(it);
|
||||
ESP_LOGCONFIG(TAG, " %-12s %-4d %-8d 0x%08X 0x%08X",
|
||||
partition->label,
|
||||
partition->type,
|
||||
partition->subtype,
|
||||
partition->address,
|
||||
partition->size);
|
||||
it = esp_partition_next(it);
|
||||
}
|
||||
esp_partition_iterator_release(it);
|
||||
}
|
||||
|
||||
std::string DebugComponent::get_reset_reason_() {
|
||||
std::string reset_reason;
|
||||
switch (esp_reset_reason()) {
|
||||
|
Loading…
Reference in New Issue
Block a user