Skip to content

Commit

Permalink
Merge branch 'feature/update_compressed_ota_component_for_esp32c2' in…
Browse files Browse the repository at this point in the history
…to 'master'

feat(ESPAT-1717): Updated compressed ota component for esp32-c2

See merge request application/esp-at!1439
  • Loading branch information
xcguang committed Nov 23, 2023
2 parents 2852e38 + 5df2877 commit efced6b
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ if (CONFIG_BOOTLOADER_COMPRESSED_ENABLED)
add_custom_target(ota_image ALL DEPENDS app)
add_custom_command(TARGET ota_image
POST_BUILD
COMMAND ${PYTHON} $ENV{ESP_AT_PROJECT_PATH}/bootloader_components/tools/custom_ota_gen.py -hv v2 -i esp-at.bin
COMMAND ${PYTHON} $ENV{ESP_AT_PROJECT_PATH}/managed_components/espressif__cmake_utilities/scripts/gen_custom_ota.py -hv v2 -i esp-at.bin
COMMAND ${CMAKE_COMMAND} -E copy_directory custom_ota_binaries compressed_ota_image
COMMENT "Creating Compressed image..."
)
Expand Down
4 changes: 0 additions & 4 deletions components/at/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ endif()

set(includes "include")

if (CONFIG_BOOTLOADER_COMPRESSED_ENABLED)
list(APPEND includes "${CMAKE_SOURCE_DIR}/bootloader_components/include")
endif()

idf_component_register (
SRCS ${srcs}
INCLUDE_DIRS ${includes}
Expand Down
10 changes: 10 additions & 0 deletions components/at/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## IDF Component Manager Manifest File
dependencies:
espressif/mdns:
version: "^1.0.0"
espressif/esp_websocket_client:
version: "^1.0.1"
espressif/bootloader_support_plus:
version: "==0.2.1"
rules:
- if: "target in [esp32c2, esp32c3]"
26 changes: 13 additions & 13 deletions components/at/src/at_compress_ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static esp_err_t at_compress_image_header_check(at_compress_ota_handle_t *handle
return ESP_FAIL;
}

uint32_t head_len = sizeof(compressed_img_header->header_v2);
uint32_t head_len = sizeof(bootloader_custom_ota_header_t);

// check the magic number of compressed image
if (memcmp(compressed_img_header, AT_COMPRESSED_IMAGE_MAGIC_NUMBER, strlen(AT_COMPRESSED_IMAGE_MAGIC_NUMBER))) {
Expand All @@ -90,26 +90,26 @@ static esp_err_t at_compress_image_header_check(at_compress_ota_handle_t *handle
}

// check the header version compressed image
if (compressed_img_header->header.version != 2) {
ESP_LOGE(TAG, "Compressed image has invalid header version (expected:2, saw:%d)", compressed_img_header->header.version);
if (compressed_img_header->version != 2) {
ESP_LOGE(TAG, "Compressed image has invalid header version (expected:2, saw:%d)", compressed_img_header->version);
return ESP_FAIL;
}

// check the size of compressed image, make sure the partition can hold on the compressed image
if (compressed_img_header->header.length + head_len <= handle->partition->size) {
handle->compressed_img_size = compressed_img_header->header.length + head_len;
if (compressed_img_header->length + head_len <= handle->partition->size) {
handle->compressed_img_size = compressed_img_header->length + head_len;
handle->image_header_checked = true;
ESP_LOGD(TAG, "Compressed image header check succeeded, image size: %d", handle->compressed_img_size);
} else {
ESP_LOGE(TAG, "Compressed image overlength, image size:%d > psize:%d (0x%x)",
compressed_img_header->header.length + head_len, handle->partition->size, handle->partition->size);
compressed_img_header->length + head_len, handle->partition->size, handle->partition->size);
return ESP_FAIL;
}

// check the crc32 of compressed image header
uint32_t header_crc = esp_rom_crc32_le(0, (const uint8_t *)compressed_img_header, offsetof(bootloader_custom_ota_header_t, header_v2.crc32));
if (header_crc != compressed_img_header->header_v2.crc32) {
ESP_LOGE(TAG, "Unmatched compressed image header crc (expected:0x%x saw:0x%x)", compressed_img_header->header_v2.crc32, header_crc);
uint32_t header_crc = esp_rom_crc32_le(0, (const uint8_t *)compressed_img_header, offsetof(bootloader_custom_ota_header_t, crc32));
if (header_crc != compressed_img_header->crc32) {
ESP_LOGE(TAG, "Unmatched compressed image header crc (expected:0x%x saw:0x%x)", compressed_img_header->crc32, header_crc);
return ESP_FAIL;
}

Expand All @@ -127,8 +127,8 @@ static esp_err_t at_compress_image_body_check(at_compress_ota_handle_t *handle,
}

uint32_t had_read_len = 0;
uint32_t img_body_len = compressed_img_header->header.length;
uint32_t head_len = sizeof(compressed_img_header->header_v2);
uint32_t img_body_len = compressed_img_header->length;
uint32_t head_len = sizeof(bootloader_custom_ota_header_t);

md5_context_t md5_context;
esp_rom_md5_init(&md5_context);
Expand All @@ -145,7 +145,7 @@ static esp_err_t at_compress_image_body_check(at_compress_ota_handle_t *handle,
uint8_t digest[16] = {0};
esp_rom_md5_final(digest, &md5_context);

if (!memcmp(compressed_img_header->header.md5, digest, sizeof(digest))) {
if (!memcmp(compressed_img_header->md5, digest, sizeof(digest))) {
ESP_LOGD(TAG, "Compressed image MD5 check succeeded");
ret = ESP_OK;
} else {
Expand All @@ -169,7 +169,7 @@ esp_err_t at_compress_ota_write(at_compress_ota_handle_t *handle, const void *da
}

if (!handle->image_header_checked) {
uint32_t head_len = sizeof(bootloader_custom_ota_header_v2_t);
uint32_t head_len = sizeof(bootloader_custom_ota_header_t);
if (size >= head_len) {
if (at_compress_image_header_check(handle, (bootloader_custom_ota_header_t *)data) != ESP_OK) {
return ESP_FAIL;
Expand Down
2 changes: 1 addition & 1 deletion components/rainmaker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (DEFINED ENV{AT_RAINMAKER_SUPPORT})
set(require_components nvs_flash at esp_rainmaker esp_schedule json_generator json_parser rmaker_common wifi_provisioning)
set(require_components nvs_flash at esp_rainmaker esp_schedule json_generator json_parser rmaker_common wifi_provisioning bootloader_support_plus)

idf_component_register(SRCS at_rainmaker.c
PRIV_REQUIRES ${require_components})
Expand Down
8 changes: 4 additions & 4 deletions main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
espressif/mdns:
version: "^1.0.0"
espressif/esp_websocket_client:
version: "^1.0.1"
espressif/cmake_utilities:
version: "==0.4.8"
rules:
- if: "target in esp32c2"
1 change: 1 addition & 0 deletions module_config/module_esp32c2-2mb/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
# Bootloader config
CONFIG_BOOTLOADER_WDT_ENABLE=y
CONFIG_BOOTLOADER_COMPRESSED_ENABLED=y
CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT=y

# Partition Table
CONFIG_PARTITION_TABLE_CUSTOM=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
# Bootloader config
CONFIG_BOOTLOADER_WDT_ENABLE=y
CONFIG_BOOTLOADER_COMPRESSED_ENABLED=y
CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT=y

# Partition Table
CONFIG_PARTITION_TABLE_CUSTOM=y
Expand Down
5 changes: 0 additions & 5 deletions module_config/module_esp32c2-2mb/submodules

This file was deleted.

2 changes: 2 additions & 0 deletions module_config/module_esp32c3_rainmaker/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
# Bootloader config
CONFIG_BOOTLOADER_WDT_ENABLE=y
CONFIG_BOOTLOADER_WDT_TIME_MS=20000
CONFIG_BOOTLOADER_COMPRESSED_ENABLED=y
CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT=y

# Partition Table
CONFIG_PARTITION_TABLE_CUSTOM=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
# Bootloader config
CONFIG_BOOTLOADER_WDT_ENABLE=y
CONFIG_BOOTLOADER_WDT_TIME_MS=20000
CONFIG_BOOTLOADER_COMPRESSED_ENABLED=y
CONFIG_ENABLE_LEGACY_ESP_BOOTLOADER_PLUS_V2_SUPPORT=y

# Partition Table
CONFIG_PARTITION_TABLE_CUSTOM=y
Expand Down
6 changes: 0 additions & 6 deletions module_config/module_esp32c3_rainmaker/submodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
url = https://github.com/espressif/esp-rainmaker.git
branch = master
commit = c7c95052c6a89f445967073cf6fce90278554628

[submodule "bootloader_components"]
path = bootloader_components
url = https://github.com/espressif/esp-bootloader-plus.git
branch = master
commit = fa4814f526669069d4cb28be0b229ba6952fdc38
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ setuptools>=21

cryptography>=2.1.4,<35
pycryptodome==3.15.0
idf-component-manager==1.3.2
idf-component-manager==1.4.1

# ESP-AT requirements
pyyaml
Expand Down

0 comments on commit efced6b

Please sign in to comment.