esp_app_format.h 5.4 KB

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