esp_app_format.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <inttypes.h>
  8. #include "esp_assert.h"
  9. /**
  10. * @brief ESP chip ID
  11. *
  12. */
  13. typedef enum {
  14. ESP_CHIP_ID_ESP32 = 0x0000, /*!< chip ID: ESP32 */
  15. ESP_CHIP_ID_ESP32S2 = 0x0002, /*!< chip ID: ESP32-S2 */
  16. ESP_CHIP_ID_ESP32C3 = 0x0005, /*!< chip ID: ESP32-C3 */
  17. ESP_CHIP_ID_ESP32S3 = 0x0009, /*!< chip ID: ESP32-S3 */
  18. ESP_CHIP_ID_ESP32C2 = 0x000C, /*!< chip ID: ESP32-C2 */
  19. ESP_CHIP_ID_ESP32C6 = 0x000D, /*!< chip ID: ESP32-C6 */
  20. ESP_CHIP_ID_ESP32H2 = 0x0010, /*!< chip ID: ESP32-H2 */
  21. ESP_CHIP_ID_INVALID = 0xFFFF /*!< Invalid chip ID (we defined it to make sure the esp_chip_id_t is 2 bytes size) */
  22. } __attribute__((packed)) esp_chip_id_t;
  23. /** @cond */
  24. ESP_STATIC_ASSERT(sizeof(esp_chip_id_t) == 2, "esp_chip_id_t should be 16 bit");
  25. /** @endcond */
  26. /**
  27. * @brief SPI flash mode, used in esp_image_header_t
  28. */
  29. typedef enum {
  30. ESP_IMAGE_SPI_MODE_QIO, /*!< SPI mode QIO */
  31. ESP_IMAGE_SPI_MODE_QOUT, /*!< SPI mode QOUT */
  32. ESP_IMAGE_SPI_MODE_DIO, /*!< SPI mode DIO */
  33. ESP_IMAGE_SPI_MODE_DOUT, /*!< SPI mode DOUT */
  34. ESP_IMAGE_SPI_MODE_FAST_READ, /*!< SPI mode FAST_READ */
  35. ESP_IMAGE_SPI_MODE_SLOW_READ /*!< SPI mode SLOW_READ */
  36. } esp_image_spi_mode_t;
  37. /**
  38. * @brief SPI flash clock division factor.
  39. */
  40. typedef enum {
  41. ESP_IMAGE_SPI_SPEED_DIV_2, /*!< The SPI flash clock frequency is divided by 2 of the clock source */
  42. ESP_IMAGE_SPI_SPEED_DIV_3, /*!< The SPI flash clock frequency is divided by 3 of the clock source */
  43. ESP_IMAGE_SPI_SPEED_DIV_4, /*!< The SPI flash clock frequency is divided by 4 of the clock source */
  44. ESP_IMAGE_SPI_SPEED_DIV_1 = 0xF /*!< The SPI flash clock frequency equals to the clock source */
  45. } esp_image_spi_freq_t;
  46. /**
  47. * @brief Supported SPI flash sizes
  48. */
  49. typedef enum {
  50. ESP_IMAGE_FLASH_SIZE_1MB = 0, /*!< SPI flash size 1 MB */
  51. ESP_IMAGE_FLASH_SIZE_2MB, /*!< SPI flash size 2 MB */
  52. ESP_IMAGE_FLASH_SIZE_4MB, /*!< SPI flash size 4 MB */
  53. ESP_IMAGE_FLASH_SIZE_8MB, /*!< SPI flash size 8 MB */
  54. ESP_IMAGE_FLASH_SIZE_16MB, /*!< SPI flash size 16 MB */
  55. ESP_IMAGE_FLASH_SIZE_32MB, /*!< SPI flash size 32 MB */
  56. ESP_IMAGE_FLASH_SIZE_64MB, /*!< SPI flash size 64 MB */
  57. ESP_IMAGE_FLASH_SIZE_128MB, /*!< SPI flash size 128 MB */
  58. ESP_IMAGE_FLASH_SIZE_MAX /*!< SPI flash size MAX */
  59. } esp_image_flash_size_t;
  60. #define ESP_IMAGE_HEADER_MAGIC 0xE9 /*!< The magic word for the esp_image_header_t structure. */
  61. /**
  62. * @brief Main header of binary image
  63. */
  64. typedef struct {
  65. uint8_t magic; /*!< Magic word ESP_IMAGE_HEADER_MAGIC */
  66. uint8_t segment_count; /*!< Count of memory segments */
  67. uint8_t spi_mode; /*!< flash read mode (esp_image_spi_mode_t as uint8_t) */
  68. uint8_t spi_speed: 4; /*!< flash frequency (esp_image_spi_freq_t as uint8_t) */
  69. uint8_t spi_size: 4; /*!< flash chip size (esp_image_flash_size_t as uint8_t) */
  70. uint32_t entry_addr; /*!< Entry address */
  71. uint8_t wp_pin; /*!< WP pin when SPI pins set via efuse (read by ROM bootloader,
  72. * the IDF bootloader uses software to configure the WP
  73. * pin and sets this field to 0xEE=disabled) */
  74. uint8_t spi_pin_drv[3]; /*!< Drive settings for the SPI flash pins (read by ROM bootloader) */
  75. esp_chip_id_t chip_id; /*!< Chip identification number */
  76. uint8_t min_chip_rev; /*!< Minimal chip revision supported by image
  77. * After the Major and Minor revision eFuses were introduced into the chips, this field is no longer used.
  78. * But for compatibility reasons, we keep this field and the data in it.
  79. * Use min_chip_rev_full instead.
  80. * The software interprets this as a Major version for most of the chips and as a Minor version for the ESP32-C3.
  81. */
  82. uint16_t min_chip_rev_full; /*!< Minimal chip revision supported by image, in format: major * 100 + minor */
  83. uint16_t max_chip_rev_full; /*!< Maximal chip revision supported by image, in format: major * 100 + minor */
  84. uint8_t reserved[4]; /*!< Reserved bytes in additional header space, currently unused */
  85. uint8_t hash_appended; /*!< If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum.
  86. * Included in image length. This digest
  87. * is separate to secure boot and only used for detecting corruption.
  88. * For secure boot signed images, the signature
  89. * is appended after this (and the simple hash is included in the signed data). */
  90. } __attribute__((packed)) esp_image_header_t;
  91. /** @cond */
  92. ESP_STATIC_ASSERT(sizeof(esp_image_header_t) == 24, "binary image header should be 24 bytes");
  93. /** @endcond */
  94. /**
  95. * @brief Header of binary image segment
  96. */
  97. typedef struct {
  98. uint32_t load_addr; /*!< Address of segment */
  99. uint32_t data_len; /*!< Length of data */
  100. } esp_image_segment_header_t;
  101. #define ESP_IMAGE_MAX_SEGMENTS 16 /*!< Max count of segments in the image. */