mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-04-29 20:15:13 +00:00
minor optimizations, use EMSESP_Version, only call esp_image_verify() and store the entry for partitions that actually have a value
This commit is contained in:
@@ -26,13 +26,12 @@
|
||||
#include <esp_mac.h>
|
||||
#include "esp_efuse.h"
|
||||
#include <nvs.h>
|
||||
#include <mbedtls/base64.h>
|
||||
#endif
|
||||
|
||||
#include <HTTPClient.h>
|
||||
#include <map>
|
||||
|
||||
#include <semver200.h>
|
||||
#include "EMSESP_Version.h"
|
||||
|
||||
#if defined(EMSESP_TEST)
|
||||
#include "../test/test.h"
|
||||
@@ -338,15 +337,16 @@ void System::get_partition_info() {
|
||||
strftime(time_string, sizeof(time_string), "%FT%T", localtime(&d));
|
||||
p_info.install_date = d > 1500000000L ? time_string : "";
|
||||
|
||||
esp_image_metadata_t meta = {};
|
||||
esp_partition_pos_t part_pos = {.offset = part->address, .size = part->size};
|
||||
if (esp_image_verify(ESP_IMAGE_VERIFY_SILENT, &part_pos, &meta) == ESP_OK) {
|
||||
p_info.size = meta.image_len / 1024; // actual firmware size in KB
|
||||
} else {
|
||||
p_info.size = 0;
|
||||
if (!p_info.version.empty()) {
|
||||
esp_image_metadata_t meta = {};
|
||||
esp_partition_pos_t part_pos = {.offset = part->address, .size = part->size};
|
||||
if (esp_image_verify(ESP_IMAGE_VERIFY_SILENT, &part_pos, &meta) == ESP_OK) {
|
||||
p_info.size = meta.image_len / 1024; // actual firmware size in KB
|
||||
} else {
|
||||
p_info.size = 0;
|
||||
}
|
||||
partition_info_[part->label] = p_info;
|
||||
}
|
||||
|
||||
partition_info_[part->label] = p_info;
|
||||
}
|
||||
|
||||
it = esp_partition_next(it); // loop to next partition
|
||||
@@ -1533,8 +1533,8 @@ bool System::check_upgrade() {
|
||||
settingsVersion = "3.5.0"; // this was the last stable version without version info
|
||||
}
|
||||
|
||||
version::Semver200_version settings_version(settingsVersion);
|
||||
version::Semver200_version this_version(EMSESP_APP_VERSION);
|
||||
version::EMSESP_Version settings_version(settingsVersion);
|
||||
version::EMSESP_Version this_version(EMSESP_APP_VERSION);
|
||||
|
||||
std::string settings_version_type = settings_version.prerelease().empty() ? "" : ("-" + settings_version.prerelease());
|
||||
std::string this_version_type = this_version.prerelease().empty() ? "" : ("-" + this_version.prerelease());
|
||||
@@ -1685,18 +1685,17 @@ void System::exportSettings(const std::string & type, const char * filename, Jso
|
||||
|
||||
File settingsFile = LittleFS.open(filename);
|
||||
if (settingsFile) {
|
||||
JsonDocument jsonDocument;
|
||||
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
||||
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
||||
JsonObject node = output[section].to<JsonObject>();
|
||||
for (JsonPair kvp : jsonDocument.as<JsonObject>()) {
|
||||
node[kvp.key()] = kvp.value();
|
||||
{
|
||||
JsonDocument jsonDocument;
|
||||
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
||||
settingsFile.close(); // close early, we no longer need the file
|
||||
if (error || !jsonDocument.is<JsonObject>()) {
|
||||
LOG_ERROR("Failed to deserialize settings file %s", filename);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("Failed to deserialize settings file %s", filename);
|
||||
output[section].set(jsonDocument.as<JsonObject>());
|
||||
}
|
||||
LOG_DEBUG("Exported %s settings from file %s", section, filename);
|
||||
settingsFile.close();
|
||||
} else {
|
||||
LOG_ERROR("No settings file for %s found", filename);
|
||||
}
|
||||
@@ -1748,20 +1747,24 @@ void System::exportSystemBackup(JsonObject output) {
|
||||
if (file) {
|
||||
JsonDocument jsonDocument;
|
||||
DeserializationError error = deserializeJson(jsonDocument, file);
|
||||
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
||||
JsonObject node = nodes.add<JsonObject>();
|
||||
node["type"] = "customSupport";
|
||||
node["data"] = jsonDocument.as<JsonObject>();
|
||||
file.close(); // close early, we no longer need the file
|
||||
if (!error && jsonDocument.is<JsonObject>()) {
|
||||
JsonObject support_node = nodes.add<JsonObject>();
|
||||
support_node["type"] = "customSupport";
|
||||
support_node["data"].set(jsonDocument.as<JsonObject>());
|
||||
LOG_DEBUG("Exported custom support file %s", EMSESP_CUSTOMSUPPORT_FILE);
|
||||
} else {
|
||||
LOG_ERROR("Failed to deserialize custom support file");
|
||||
}
|
||||
file.close();
|
||||
LOG_DEBUG("Exported custom support file %s", EMSESP_CUSTOMSUPPORT_FILE);
|
||||
}
|
||||
|
||||
// Backup NVS values
|
||||
node = nodes.add<JsonObject>();
|
||||
node["type"] = "nvs";
|
||||
|
||||
const char * nvs_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs1") ? "nvs1" : "nvs"; // nvs1 is on 16MBs
|
||||
// EMSESP::nvs_ is opened on "nvs" (see EMSESP::start), so always read the backup from there.
|
||||
// The old "nvs1" partition may still exist on 16MB boards but has been migrated and emptied.
|
||||
const char * nvs_part = "nvs";
|
||||
nvs_iterator_t it = nullptr;
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
it = nvs_entry_find(nvs_part, "ems-esp", NVS_TYPE_ANY);
|
||||
|
||||
Reference in New Issue
Block a user