diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index 5236aa0a54..94faff986a 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -177,30 +177,6 @@ esp_err_t bootloader_common_get_sha256_of_partition (uint32_t address, uint32_t return bootloader_sha256_flash_contents(address, size, out_sha_256); } -esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t *partition, esp_app_desc_t *app_desc) -{ - if (partition == NULL || app_desc == NULL || partition->offset == 0) { - return ESP_ERR_INVALID_ARG; - } - - const uint32_t app_desc_offset = sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t); - const uint32_t mmap_size = app_desc_offset + sizeof(esp_app_desc_t); - const uint8_t *image = bootloader_mmap(partition->offset, mmap_size); - if (image == NULL) { - ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", partition->offset, mmap_size); - return ESP_FAIL; - } - - memcpy(app_desc, image + app_desc_offset, sizeof(esp_app_desc_t)); - bootloader_munmap(image); - - if (app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) { - return ESP_ERR_NOT_FOUND; - } - - return ESP_OK; -} - void bootloader_common_vddsdio_configure(void) { #if CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V diff --git a/components/bootloader_support/src/bootloader_common_loader.c b/components/bootloader_support/src/bootloader_common_loader.c index f0c65fadca..cc02754ea7 100644 --- a/components/bootloader_support/src/bootloader_common_loader.c +++ b/components/bootloader_support/src/bootloader_common_loader.c @@ -1,3 +1,17 @@ +// Copyright 2020 Espressif Systems (Shanghai) Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "string.h" #include "sdkconfig.h" #include "esp_err.h" @@ -20,6 +34,7 @@ #include "esp_image_format.h" #include "bootloader_sha.h" #include "sys/param.h" +#include "bootloader_flash_priv.h" #define ESP_PARTITION_HASH_LEN 32 /* SHA-256 digest length */ @@ -97,6 +112,29 @@ int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata, return active_otadata; } +esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t *partition, esp_app_desc_t *app_desc) +{ + if (partition == NULL || app_desc == NULL || partition->offset == 0) { + return ESP_ERR_INVALID_ARG; + } + + const uint32_t app_desc_offset = sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t); + const uint32_t mmap_size = app_desc_offset + sizeof(esp_app_desc_t); + const uint8_t *image = bootloader_mmap(partition->offset, mmap_size); + if (image == NULL) { + ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", partition->offset, mmap_size); + return ESP_FAIL; + } + + memcpy(app_desc, image + app_desc_offset, sizeof(esp_app_desc_t)); + bootloader_munmap(image); + + if (app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) { + return ESP_ERR_NOT_FOUND; + } + + return ESP_OK; +} #if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC )