esp_app_format.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include <inttypes.h>
  15. /**
  16. * @brief ESP chip ID
  17. *
  18. */
  19. typedef enum {
  20. ESP_CHIP_ID_ESP32 = 0x0000, /*!< chip ID: ESP32 */
  21. ESP_CHIP_ID_ESP32S2 = 0x0002, /*!< chip ID: ESP32-S2 */
  22. ESP_CHIP_ID_ESP32S3 = 0x0004, /*!< chip ID: ESP32-S3 */
  23. ESP_CHIP_ID_ESP32C3 = 0x0005, /*!< chip ID: ESP32-C3 */
  24. ESP_CHIP_ID_INVALID = 0xFFFF /*!< Invalid chip ID (we defined it to make sure the esp_chip_id_t is 2 bytes size) */
  25. } __attribute__((packed)) esp_chip_id_t;
  26. /** @cond */
  27. _Static_assert(sizeof(esp_chip_id_t) == 2, "esp_chip_id_t should be 16 bit");
  28. /** @endcond */
  29. /**
  30. * @brief SPI flash mode, used in esp_image_header_t
  31. */
  32. typedef enum {
  33. ESP_IMAGE_SPI_MODE_QIO, /*!< SPI mode QIO */
  34. ESP_IMAGE_SPI_MODE_QOUT, /*!< SPI mode QOUT */
  35. ESP_IMAGE_SPI_MODE_DIO, /*!< SPI mode DIO */
  36. ESP_IMAGE_SPI_MODE_DOUT, /*!< SPI mode DOUT */
  37. ESP_IMAGE_SPI_MODE_FAST_READ, /*!< SPI mode FAST_READ */
  38. ESP_IMAGE_SPI_MODE_SLOW_READ /*!< SPI mode SLOW_READ */
  39. } esp_image_spi_mode_t;
  40. /**
  41. * @brief SPI flash clock frequency
  42. */
  43. typedef enum {
  44. ESP_IMAGE_SPI_SPEED_40M, /*!< SPI clock frequency 40 MHz */
  45. ESP_IMAGE_SPI_SPEED_26M, /*!< SPI clock frequency 26 MHz */
  46. ESP_IMAGE_SPI_SPEED_20M, /*!< SPI clock frequency 20 MHz */
  47. ESP_IMAGE_SPI_SPEED_80M = 0xF /*!< SPI clock frequency 80 MHz */
  48. } esp_image_spi_freq_t;
  49. /**
  50. * @brief Supported SPI flash sizes
  51. */
  52. typedef enum {
  53. ESP_IMAGE_FLASH_SIZE_1MB = 0, /*!< SPI flash size 1 MB */
  54. ESP_IMAGE_FLASH_SIZE_2MB, /*!< SPI flash size 2 MB */
  55. ESP_IMAGE_FLASH_SIZE_4MB, /*!< SPI flash size 4 MB */
  56. ESP_IMAGE_FLASH_SIZE_8MB, /*!< SPI flash size 8 MB */
  57. ESP_IMAGE_FLASH_SIZE_16MB, /*!< SPI flash size 16 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; /*!< Minimum chip revision supported by image */
  77. uint8_t reserved[8]; /*!< Reserved bytes in additional header space, currently unused */
  78. uint8_t hash_appended; /*!< If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum.
  79. * Included in image length. This digest
  80. * is separate to secure boot and only used for detecting corruption.
  81. * For secure boot signed images, the signature
  82. * is appended after this (and the simple hash is included in the signed data). */
  83. } __attribute__((packed)) esp_image_header_t;
  84. /** @cond */
  85. _Static_assert(sizeof(esp_image_header_t) == 24, "binary image header should be 24 bytes");
  86. /** @endcond */
  87. /**
  88. * @brief Header of binary image segment
  89. */
  90. typedef struct {
  91. uint32_t load_addr; /*!< Address of segment */
  92. uint32_t data_len; /*!< Length of data */
  93. } esp_image_segment_header_t;
  94. #define ESP_IMAGE_MAX_SEGMENTS 16 /*!< Max count of segments in the image. */
  95. #define ESP_APP_DESC_MAGIC_WORD 0xABCD5432 /*!< The magic word for the esp_app_desc structure that is in DROM. */
  96. /**
  97. * @brief Description about application.
  98. */
  99. typedef struct {
  100. uint32_t magic_word; /*!< Magic word ESP_APP_DESC_MAGIC_WORD */
  101. uint32_t secure_version; /*!< Secure version */
  102. uint32_t reserv1[2]; /*!< reserv1 */
  103. char version[32]; /*!< Application version */
  104. char project_name[32]; /*!< Project name */
  105. char time[16]; /*!< Compile time */
  106. char date[16]; /*!< Compile date*/
  107. char idf_ver[32]; /*!< Version IDF */
  108. uint8_t app_elf_sha256[32]; /*!< sha256 of elf file */
  109. uint32_t reserv2[20]; /*!< reserv2 */
  110. } esp_app_desc_t;
  111. /** @cond */
  112. _Static_assert(sizeof(esp_app_desc_t) == 256, "esp_app_desc_t should be 256 bytes");
  113. /** @endcond */