15#if DETWS_ENABLE_PARTITION_MONITOR
23const char *detws_partition_kind(uint8_t type, uint8_t subtype)
29 if (subtype >= 0x10 && subtype <= 0x1F)
58static int json_append(
char *out,
size_t cap,
size_t *pos,
const char *fmt, ...)
64 int w = vsnprintf(out + *pos, cap - *pos, fmt, ap);
66 if (w < 0 || (
size_t)w >= cap - *pos)
72int detws_partition_json(
const DetwsPartitionInfo *parts, uint8_t count,
char *out,
size_t cap)
80 if (json_append(out, cap, &pos,
"{\"partitions\":[") != 0)
82 for (uint8_t i = 0; i < count; i++)
84 const DetwsPartitionInfo *p = &parts[i];
85 if (json_append(out, cap, &pos,
86 "%s{\"label\":\"%s\",\"kind\":\"%s\",\"type\":%u,\"subtype\":%u,\"addr\":%u,\"size\":%u,"
88 i ?
"," :
"", p->label, detws_partition_kind(p->type, p->subtype), (unsigned)p->type,
89 (unsigned)p->subtype, (unsigned)p->address, (unsigned)p->size,
90 p->running ?
"true" :
"false") != 0)
93 if (json_append(out, cap, &pos,
"]}") != 0)
100#include <esp_ota_ops.h>
101#include <esp_partition.h>
103uint8_t detws_partition_collect(DetwsPartitionInfo *out, uint8_t max)
105 if (!out || max == 0)
107 const esp_partition_t *running = esp_ota_get_running_partition();
109 esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
110 for (; it != NULL && n < max; it = esp_partition_next(it))
112 const esp_partition_t *p = esp_partition_get(it);
113 DetwsPartitionInfo *d = &out[n++];
114 strncpy(d->label, p->label,
sizeof(d->label) - 1);
115 d->label[
sizeof(d->label) - 1] =
'\0';
116 d->type = (uint8_t)p->type;
117 d->subtype = (uint8_t)p->subtype;
118 d->address = p->address;
120 d->running = (running != NULL && p->address == running->address);
122 esp_partition_iterator_release(it);
128uint8_t detws_partition_collect(DetwsPartitionInfo *, uint8_t)
Flash partition-map monitor (DETWS_ENABLE_PARTITION_MONITOR).