1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #pragma once 7 8 #include <inttypes.h> 9 10 /** 11 * @brief ESP chip ID 12 * 13 */ 14 typedef enum { 15 ESP_CHIP_ID_ESP32 = 0x0000, /*!< chip ID: ESP32 */ 16 ESP_CHIP_ID_ESP32S2 = 0x0002, /*!< chip ID: ESP32-S2 */ 17 ESP_CHIP_ID_ESP32C3 = 0x0005, /*!< chip ID: ESP32-C3 */ 18 ESP_CHIP_ID_ESP32S3 = 0x0009, /*!< chip ID: ESP32-S3 */ 19 ESP_CHIP_ID_ESP32H2 = 0x000A, /*!< chip ID: ESP32-H2 */ // ESP32H2-TODO: IDF-3475 20 ESP_CHIP_ID_INVALID = 0xFFFF /*!< Invalid chip ID (we defined it to make sure the esp_chip_id_t is 2 bytes size) */ 21 } __attribute__((packed)) esp_chip_id_t; 22 23 /** @cond */ 24 _Static_assert(sizeof(esp_chip_id_t) == 2, "esp_chip_id_t should be 16 bit"); 25 /** @endcond */ 26 27 /** 28 * @brief SPI flash mode, used in esp_image_header_t 29 */ 30 typedef enum { 31 ESP_IMAGE_SPI_MODE_QIO, /*!< SPI mode QIO */ 32 ESP_IMAGE_SPI_MODE_QOUT, /*!< SPI mode QOUT */ 33 ESP_IMAGE_SPI_MODE_DIO, /*!< SPI mode DIO */ 34 ESP_IMAGE_SPI_MODE_DOUT, /*!< SPI mode DOUT */ 35 ESP_IMAGE_SPI_MODE_FAST_READ, /*!< SPI mode FAST_READ */ 36 ESP_IMAGE_SPI_MODE_SLOW_READ /*!< SPI mode SLOW_READ */ 37 } esp_image_spi_mode_t; 38 39 /** 40 * @brief SPI flash clock frequency 41 */ 42 typedef enum { 43 ESP_IMAGE_SPI_SPEED_40M, /*!< SPI clock frequency 40 MHz */ 44 ESP_IMAGE_SPI_SPEED_26M, /*!< SPI clock frequency 26 MHz */ 45 ESP_IMAGE_SPI_SPEED_20M, /*!< SPI clock frequency 20 MHz */ 46 ESP_IMAGE_SPI_SPEED_80M = 0xF /*!< SPI clock frequency 80 MHz */ 47 } esp_image_spi_freq_t; 48 49 /** 50 * @brief Supported SPI flash sizes 51 */ 52 typedef enum { 53 ESP_IMAGE_FLASH_SIZE_1MB = 0, /*!< SPI flash size 1 MB */ 54 ESP_IMAGE_FLASH_SIZE_2MB, /*!< SPI flash size 2 MB */ 55 ESP_IMAGE_FLASH_SIZE_4MB, /*!< SPI flash size 4 MB */ 56 ESP_IMAGE_FLASH_SIZE_8MB, /*!< SPI flash size 8 MB */ 57 ESP_IMAGE_FLASH_SIZE_16MB, /*!< SPI flash size 16 MB */ 58 ESP_IMAGE_FLASH_SIZE_MAX /*!< SPI flash size MAX */ 59 } esp_image_flash_size_t; 60 61 #define ESP_IMAGE_HEADER_MAGIC 0xE9 /*!< The magic word for the esp_image_header_t structure. */ 62 63 /** 64 * @brief Main header of binary image 65 */ 66 typedef struct { 67 uint8_t magic; /*!< Magic word ESP_IMAGE_HEADER_MAGIC */ 68 uint8_t segment_count; /*!< Count of memory segments */ 69 uint8_t spi_mode; /*!< flash read mode (esp_image_spi_mode_t as uint8_t) */ 70 uint8_t spi_speed: 4; /*!< flash frequency (esp_image_spi_freq_t as uint8_t) */ 71 uint8_t spi_size: 4; /*!< flash chip size (esp_image_flash_size_t as uint8_t) */ 72 uint32_t entry_addr; /*!< Entry address */ 73 uint8_t wp_pin; /*!< WP pin when SPI pins set via efuse (read by ROM bootloader, 74 * the IDF bootloader uses software to configure the WP 75 * pin and sets this field to 0xEE=disabled) */ 76 uint8_t spi_pin_drv[3]; /*!< Drive settings for the SPI flash pins (read by ROM bootloader) */ 77 esp_chip_id_t chip_id; /*!< Chip identification number */ 78 uint8_t min_chip_rev; /*!< Minimum chip revision supported by image */ 79 uint8_t reserved[8]; /*!< Reserved bytes in additional header space, currently unused */ 80 uint8_t hash_appended; /*!< If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum. 81 * Included in image length. This digest 82 * is separate to secure boot and only used for detecting corruption. 83 * For secure boot signed images, the signature 84 * is appended after this (and the simple hash is included in the signed data). */ 85 } __attribute__((packed)) esp_image_header_t; 86 87 /** @cond */ 88 _Static_assert(sizeof(esp_image_header_t) == 24, "binary image header should be 24 bytes"); 89 /** @endcond */ 90 91 92 /** 93 * @brief Header of binary image segment 94 */ 95 typedef struct { 96 uint32_t load_addr; /*!< Address of segment */ 97 uint32_t data_len; /*!< Length of data */ 98 } esp_image_segment_header_t; 99 100 #define ESP_IMAGE_MAX_SEGMENTS 16 /*!< Max count of segments in the image. */ 101 102 #define ESP_APP_DESC_MAGIC_WORD 0xABCD5432 /*!< The magic word for the esp_app_desc structure that is in DROM. */ 103 104 /** 105 * @brief Description about application. 106 */ 107 typedef struct { 108 uint32_t magic_word; /*!< Magic word ESP_APP_DESC_MAGIC_WORD */ 109 uint32_t secure_version; /*!< Secure version */ 110 uint32_t reserv1[2]; /*!< reserv1 */ 111 char version[32]; /*!< Application version */ 112 char project_name[32]; /*!< Project name */ 113 char time[16]; /*!< Compile time */ 114 char date[16]; /*!< Compile date*/ 115 char idf_ver[32]; /*!< Version IDF */ 116 uint8_t app_elf_sha256[32]; /*!< sha256 of elf file */ 117 uint32_t reserv2[20]; /*!< reserv2 */ 118 } esp_app_desc_t; 119 120 /** @cond */ 121 _Static_assert(sizeof(esp_app_desc_t) == 256, "esp_app_desc_t should be 256 bytes"); 122 /** @endcond */ 123