esp_app_format.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /**
  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_ESP32C2 = 0x000C, /*!< chip ID: ESP32-C2 */
  18. #if CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2
  19. ESP_CHIP_ID_ESP32H2 = 0x000E, /*!< chip ID: ESP32-H2 Beta2*/ // ESP32H2-TODO: IDF-3475
  20. #elif CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_1
  21. ESP_CHIP_ID_ESP32H2 = 0x000A, /*!< chip ID: ESP32-H2 Beta1 */
  22. #endif
  23. ESP_CHIP_ID_INVALID = 0xFFFF /*!< Invalid chip ID (we defined it to make sure the esp_chip_id_t is 2 bytes size) */
  24. } __attribute__((packed)) esp_chip_id_t;
  25. /** @cond */
  26. _Static_assert(sizeof(esp_chip_id_t) == 2, "esp_chip_id_t should be 16 bit");
  27. /** @endcond */
  28. /**
  29. * @brief SPI flash mode, used in esp_image_header_t
  30. */
  31. typedef enum {
  32. ESP_IMAGE_SPI_MODE_QIO, /*!< SPI mode QIO */
  33. ESP_IMAGE_SPI_MODE_QOUT, /*!< SPI mode QOUT */
  34. ESP_IMAGE_SPI_MODE_DIO, /*!< SPI mode DIO */
  35. ESP_IMAGE_SPI_MODE_DOUT, /*!< SPI mode DOUT */
  36. ESP_IMAGE_SPI_MODE_FAST_READ, /*!< SPI mode FAST_READ */
  37. ESP_IMAGE_SPI_MODE_SLOW_READ /*!< SPI mode SLOW_READ */
  38. } esp_image_spi_mode_t;
  39. /**
  40. * @brief SPI flash clock division factor.
  41. */
  42. typedef enum {
  43. ESP_IMAGE_SPI_SPEED_DIV_2, /*!< The SPI flash clock frequency is divided by 2 of the clock source */
  44. ESP_IMAGE_SPI_SPEED_DIV_3, /*!< The SPI flash clock frequency is divided by 3 of the clock source */
  45. ESP_IMAGE_SPI_SPEED_DIV_4, /*!< The SPI flash clock frequency is divided by 4 of the clock source */
  46. ESP_IMAGE_SPI_SPEED_DIV_1 = 0xF /*!< The SPI flash clock frequency equals to the clock source */
  47. } esp_image_spi_freq_t;
  48. /**
  49. * @brief Supported SPI flash sizes
  50. */
  51. typedef enum {
  52. ESP_IMAGE_FLASH_SIZE_1MB = 0, /*!< SPI flash size 1 MB */
  53. ESP_IMAGE_FLASH_SIZE_2MB, /*!< SPI flash size 2 MB */
  54. ESP_IMAGE_FLASH_SIZE_4MB, /*!< SPI flash size 4 MB */
  55. ESP_IMAGE_FLASH_SIZE_8MB, /*!< SPI flash size 8 MB */
  56. ESP_IMAGE_FLASH_SIZE_16MB, /*!< SPI flash size 16 MB */
  57. ESP_IMAGE_FLASH_SIZE_32MB, /*!< SPI flash size 32 MB */
  58. ESP_IMAGE_FLASH_SIZE_64MB, /*!< SPI flash size 64 MB */
  59. ESP_IMAGE_FLASH_SIZE_128MB, /*!< SPI flash size 128 MB */
  60. ESP_IMAGE_FLASH_SIZE_MAX /*!< SPI flash size MAX */
  61. } esp_image_flash_size_t;
  62. #define ESP_IMAGE_HEADER_MAGIC 0xE9 /*!< The magic word for the esp_image_header_t structure. */
  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. /** @cond */
  87. _Static_assert(sizeof(esp_image_header_t) == 24, "binary image header should be 24 bytes");
  88. /** @endcond */
  89. /**
  90. * @brief Header of binary image segment
  91. */
  92. typedef struct {
  93. uint32_t load_addr; /*!< Address of segment */
  94. uint32_t data_len; /*!< Length of data */
  95. } esp_image_segment_header_t;
  96. #define ESP_IMAGE_MAX_SEGMENTS 16 /*!< Max count of segments in the image. */