|
|
@@ -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 )
|
|
|
|