Skip to content

Commit 34d5033

Browse files
committed
Merge branch 'feat/webserver_support_compress_ota' into 'master'
feat(ESPAT-2427): Added the compress ota support for AT+WEBSERVER See merge request application/esp-at!1895
2 parents ff8090d + f5491f4 commit 34d5033

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

components/at/src/at_web_server_cmd.c

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
static char *s_at_web_redirect_url = NULL;
4949
#endif
5050

51+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
52+
#include "bootloader_custom_ota.h"
53+
#include "at_compress_ota.h"
54+
#endif
55+
5156
#define ESP_AT_WEB_SERVER_CHECK(a, str, goto_tag, ...) \
5257
do \
5358
{ \
@@ -1469,13 +1474,17 @@ const esp_partition_t *at_web_get_ota_update_partition(void)
14691474
ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)",
14701475
running->type, running->subtype, running->address);
14711476

1477+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
1478+
update_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, BOOTLOADER_CUSTOM_OTA_PARTITION_SUBTYPE, NULL);
1479+
#else
14721480
update_partition = esp_ota_get_next_update_partition(running);
1473-
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x",
1474-
update_partition->subtype, update_partition->address);
1475-
1476-
if (update_partition->address == running->address) {
1477-
ESP_LOGE(TAG, "The partition to be updated is the current running partition");
1478-
update_partition = NULL;
1481+
#endif
1482+
if (update_partition) {
1483+
ESP_LOGI(TAG, "Next partition found, subtype %d at offset 0x%x", update_partition->subtype, update_partition->address);
1484+
if (update_partition->address == running->address) {
1485+
ESP_LOGE(TAG, "The partition to be updated is the current running partition");
1486+
update_partition = NULL;
1487+
}
14791488
}
14801489

14811490
return update_partition;
@@ -1507,7 +1516,11 @@ static esp_err_t ota_upgrade(httpd_req_t *req)
15071516
int remaining_len = req->content_len;
15081517
int received_len = 0;
15091518
esp_err_t err = ESP_FAIL;
1519+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
1520+
at_compress_ota_handle_t handle;
1521+
#else
15101522
esp_ota_handle_t update_handle = 0;
1523+
#endif
15111524
const esp_partition_t *update_partition = at_web_get_ota_update_partition();
15121525
// check post data size
15131526
if (update_partition->size < total_len) {
@@ -1518,7 +1531,11 @@ static esp_err_t ota_upgrade(httpd_req_t *req)
15181531
memset(buf, 0x0, ESP_AT_WEB_SCRATCH_BUFSIZE * sizeof(char));
15191532

15201533
// start ota
1534+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
1535+
err = at_compress_ota_begin(&handle);
1536+
#else
15211537
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
1538+
#endif
15221539
if (err != ESP_OK) {
15231540
ESP_LOGE(TAG, "ota begin failed (%s)", esp_err_to_name(err));
15241541
goto err_handler;
@@ -1532,19 +1549,35 @@ static esp_err_t ota_upgrade(httpd_req_t *req)
15321549
continue;
15331550
}
15341551
ESP_LOGE(TAG, "Failed to receive post ota data, err = %d", received_len);
1552+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
1553+
at_compress_ota_end(&handle);
1554+
#else
15351555
esp_ota_end(update_handle);
1556+
#endif
15361557
goto err_handler;
15371558
} else { // received successfully
1559+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
1560+
err = at_compress_ota_write(&handle, buf, received_len);
1561+
#else
15381562
err = esp_ota_write(update_handle, buf, received_len);
1563+
#endif
15391564
if (err != ESP_OK) {
15401565
ESP_LOGE(TAG, "ota write failed (%s)", esp_err_to_name(err));
1566+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
1567+
at_compress_ota_end(&handle);
1568+
#else
15411569
esp_ota_end(update_handle);
1570+
#endif
15421571
goto err_handler;
15431572
}
15441573
remaining_len -= received_len;
15451574
}
15461575
}
1576+
#if defined(CONFIG_BOOTLOADER_COMPRESSED_ENABLED) && defined(CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT)
1577+
err = at_compress_ota_end(&handle);
1578+
#else
15471579
err = at_web_ota_end(update_handle, update_partition);
1580+
#endif
15481581
if (err != ESP_OK) {
15491582
goto err_handler;
15501583
}

0 commit comments

Comments
 (0)