esp_app_format.h 5.3 KB

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