mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Allow reboot to smaller OTA partition or factory partition
This commit is contained in:
@@ -17,11 +17,24 @@ void RestartService::restart(AsyncWebServerRequest * request) {
|
|||||||
|
|
||||||
void RestartService::partition(AsyncWebServerRequest * request) {
|
void RestartService::partition(AsyncWebServerRequest * request) {
|
||||||
const esp_partition_t * factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
const esp_partition_t * factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
||||||
if (!factory_partition) {
|
if (factory_partition) {
|
||||||
|
esp_ota_set_boot_partition(factory_partition);
|
||||||
|
request->onDisconnect(RestartService::restartNow);
|
||||||
|
request->send(200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const esp_partition_t * ota_partition = esp_ota_get_next_update_partition(NULL);
|
||||||
|
if (!ota_partition) {
|
||||||
request->send(400); // bad request
|
request->send(400); // bad request
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_ota_set_boot_partition(factory_partition);
|
uint64_t buffer;
|
||||||
|
esp_partition_read(ota_partition, 0, &buffer, 8);
|
||||||
|
if (buffer == 0xFFFFFFFFFFFFFFFF) { // partition empty
|
||||||
|
request->send(400); // bad request
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
esp_ota_set_boot_partition(ota_partition);
|
||||||
request->onDisconnect(RestartService::restartNow);
|
request->onDisconnect(RestartService::restartNow);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,18 @@ void SystemStatus::systemStatus(AsyncWebServerRequest * request) {
|
|||||||
root["psram_size"] = emsesp::EMSESP::system_.PSram();
|
root["psram_size"] = emsesp::EMSESP::system_.PSram();
|
||||||
root["free_psram"] = ESP.getFreePsram() / 1024;
|
root["free_psram"] = ESP.getFreePsram() / 1024;
|
||||||
}
|
}
|
||||||
const esp_partition_t * factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
||||||
root["has_loader"] = factory_partition != NULL;
|
if (partition != NULL) { // factory partition found
|
||||||
|
root["has_loader"] = true;
|
||||||
|
} else { // check for not empty, smaller OTA partition
|
||||||
|
partition = esp_ota_get_next_update_partition(NULL);
|
||||||
|
if (partition) {
|
||||||
|
uint64_t buffer;
|
||||||
|
esp_partition_read(partition, 0, &buffer, 8);
|
||||||
|
const esp_partition_t * running = esp_ota_get_running_partition();
|
||||||
|
root["has_loader"] = (buffer != 0xFFFFFFFFFFFFFFFF && running->size != partition->size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user