esp_app_format.h 5.0 KB

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