/* * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */#pragmaonce#include<stdbool.h>#include<esp_err.h>#include"esp_flash_partitions.h"#include"esp_app_format.h"#include"esp_assert.h"5 includes#ifdef__cplusplusextern"C"{#endif#defineESP_ERR_IMAGE_BASE0x2000#defineESP_ERR_IMAGE_FLASH_FAIL(ESP_ERR_IMAGE_BASE+1)#defineESP_ERR_IMAGE_INVALID(ESP_ERR_IMAGE_BASE+2)/* Support for app/bootloader image parsing Can be compiled as part of app or bootloader code.*//* ... */#defineESP_IMAGE_HASH_LEN32/* Length of the appended SHA-256 digest *//* Structure to hold on-flash image metadata */typedefstruct{uint32_tstart_addr;/* Start address of image */esp_image_header_timage;/* Header for entire image */esp_image_segment_header_tsegments[ESP_IMAGE_MAX_SEGMENTS];/* Per-segment header data */uint32_tsegment_data[ESP_IMAGE_MAX_SEGMENTS];/* Data offsets for each segment */uint32_timage_len;/* Length of image on flash, in bytes */uint8_timage_digest[32];/* appended SHA-256 digest */uint32_tsecure_version;/* secure version for anti-rollback, it is covered by sha256 (set if CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK=y) */uint32_tmmu_page_size;/* Flash MMU page size per binary header */}{ ... }esp_image_metadata_t;typedefenum{ESP_IMAGE_VERIFY,/* Verify image contents, not load to memory, load metadata. Print errors. */ESP_IMAGE_VERIFY_SILENT,/* Verify image contents, not load to memory, load metadata. Don't print errors. */#ifdefBOOTLOADER_BUILDESP_IMAGE_LOAD,/* Verify image contents, load to memory, load metadata. Print errors. */ESP_IMAGE_LOAD_NO_VALIDATE,/* Not verify image contents, load to memory, load metadata. Print errors. *//* ... */#endif}{ ... }esp_image_load_mode_t;typedefstruct{esp_partition_pos_tpartition;/*!< Partition of application which worked before goes to the deep sleep. */uint16_treboot_counter;/*!< Reboot counter. Reset only when power is off. */union{struct{uint8_tfactory_reset_state:1;/* True when Factory reset has occurred */uint8_treserve:7;/* Reserve */}{ ... };uint8_tval;}{ ... }flags;uint8_treserve;/*!< Reserve */#ifdefCONFIG_BOOTLOADER_CUSTOM_RESERVE_RTCuint8_tcustom[CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE];/*!< Reserve for custom propose */#endifuint32_tcrc;/*!< Check sum crc32 */}{ ... }rtc_retain_mem_t;ESP_STATIC_ASSERT(offsetof(rtc_retain_mem_t,crc)==sizeof(rtc_retain_mem_t)-sizeof(uint32_t),"CRC field must be the last field of rtc_retain_mem_t structure");#ifdefCONFIG_BOOTLOADER_RESERVE_RTC_MEM#ifdefCONFIG_BOOTLOADER_CUSTOM_RESERVE_RTCESP_STATIC_ASSERT(CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE%4==0,"CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE must be a multiple of 4 bytes");/* The custom field must be the penultimate field */ESP_STATIC_ASSERT(offsetof(rtc_retain_mem_t,custom)==sizeof(rtc_retain_mem_t)-sizeof(uint32_t)-CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE,"custom field in rtc_retain_mem_t structure must be the field before the CRC one");/* ... */#endifESP_STATIC_ASSERT(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE%4==0,"CONFIG_BOOTLOADER_RESERVE_RTC_SIZE must be a multiple of 4 bytes");#ifdefCONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC#defineESP_BOOTLOADER_RESERVE_RTC(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE+CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)#else#defineESP_BOOTLOADER_RESERVE_RTC(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE)#endifESP_STATIC_ASSERT(sizeof(rtc_retain_mem_t)<=ESP_BOOTLOADER_RESERVE_RTC,"Reserved RTC area must exceed size of rtc_retain_mem_t");/* ... */#endif// CONFIG_BOOTLOADER_RESERVE_RTC_MEM/** * @brief Verify an app image. * * If encryption is enabled, data will be transparently decrypted. * * @param mode Mode of operation (verify, silent verify, or load). * @param part Partition to load the app from. * @param[inout] data Pointer to the image metadata structure which is be filled in by this function. * 'start_addr' member should be set (to the start address of the image.) * Other fields will all be initialised by this function. * * Image validation checks: * - Magic byte. * - Partition smaller than 16MB. * - All segments & image fit in partition. * - 8 bit image checksum is valid. * - SHA-256 of image is valid (if image has this appended). * - (Signature) if signature verification is enabled. * * @return * - ESP_OK if verify or load was successful * - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs * - ESP_ERR_IMAGE_INVALID if the image appears invalid. * - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid. *//* ... */esp_err_tesp_image_verify(esp_image_load_mode_tmode,constesp_partition_pos_t*part,esp_image_metadata_t*data);/** * @brief Get metadata of app * * If encryption is enabled, data will be transparently decrypted. * * @param part Partition to load the app from. * @param[out] metadata Pointer to the image metadata structure which is be filled in by this function. * Fields will all be initialised by this function. * * @return * - ESP_OK if filling of metadata was successful *//* ... */esp_err_tesp_image_get_metadata(constesp_partition_pos_t*part,esp_image_metadata_t*metadata);/** * @brief Verify and load an app image (available only in space of bootloader). * * If encryption is enabled, data will be transparently decrypted. * * @param part Partition to load the app from. * @param[inout] data Pointer to the image metadata structure which is be filled in by this function. * 'start_addr' member should be set (to the start address of the image.) * Other fields will all be initialised by this function. * * Image validation checks: * - Magic byte. * - Partition smaller than 16MB. * - All segments & image fit in partition. * - 8 bit image checksum is valid. * - SHA-256 of image is valid (if image has this appended). * - (Signature) if signature verification is enabled. * * @return * - ESP_OK if verify or load was successful * - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs * - ESP_ERR_IMAGE_INVALID if the image appears invalid. * - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid. *//* ... */esp_err_tbootloader_load_image(constesp_partition_pos_t*part,esp_image_metadata_t*data);/** * @brief Load an app image without verification (available only in space of bootloader). * * If encryption is enabled, data will be transparently decrypted. * * @param part Partition to load the app from. * @param[inout] data Pointer to the image metadata structure which is be filled in by this function. * 'start_addr' member should be set (to the start address of the image.) * Other fields will all be initialised by this function. * * @return * - ESP_OK if verify or load was successful * - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs * - ESP_ERR_IMAGE_INVALID if the image appears invalid. * - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid. *//* ... */esp_err_tbootloader_load_image_no_verify(constesp_partition_pos_t*part,esp_image_metadata_t*data);/** * @brief Verify the bootloader image. * * @param[out] If result is ESP_OK and this pointer is non-NULL, it * will be set to the length of the bootloader image. * * @return As per esp_image_load_metadata(). *//* ... */esp_err_tesp_image_verify_bootloader(uint32_t*length);/** * @brief Verify the bootloader image. * * @param[out] Metadata for the image. Only valid if result is ESP_OK. * * @return As per esp_image_load_metadata(). *//* ... */esp_err_tesp_image_verify_bootloader_data(esp_image_metadata_t*data);/** * @brief Get the flash size of the image * * @param app_flash_size The value configured in the image header * @return Actual size, in bytes. *//* ... */intesp_image_get_flash_size(esp_image_flash_size_tapp_flash_size);typedefstruct{uint32_tdrom_addr;uint32_tdrom_load_addr;uint32_tdrom_size;uint32_tirom_addr;uint32_tirom_load_addr;uint32_tirom_size;}{ ... }esp_image_flash_mapping_t;#ifdef__cplusplus}{...}#endif
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.