1 /*
2  * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <stddef.h>
12 #include "esp_err.h"
13 #include "esp_assert.h"
14 
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
20 #define ESP_APP_DESC_MAGIC_WORD (0xABCD5432)  /*!< The magic word for the esp_app_desc structure that is in DROM. */
21 
22 /**
23  * @brief Description about application.
24  */
25 typedef struct {
26     uint32_t magic_word;        /*!< Magic word ESP_APP_DESC_MAGIC_WORD */
27     uint32_t secure_version;    /*!< Secure version */
28     uint32_t reserv1[2];        /*!< reserv1 */
29     char version[32];           /*!< Application version */
30     char project_name[32];      /*!< Project name */
31     char time[16];              /*!< Compile time */
32     char date[16];              /*!< Compile date*/
33     char idf_ver[32];           /*!< Version IDF */
34     uint8_t app_elf_sha256[32]; /*!< sha256 of elf file */
35     uint32_t reserv2[20];       /*!< reserv2 */
36 } esp_app_desc_t;
37 
38 /** @cond */
39 ESP_STATIC_ASSERT(sizeof(esp_app_desc_t) == 256, "esp_app_desc_t should be 256 bytes");
40 ESP_STATIC_ASSERT(offsetof(esp_app_desc_t, secure_version) == 4, "secure_version field must be at 4 offset");
41 /** @endcond */
42 
43 /**
44  * @brief   Return esp_app_desc structure. This structure includes app version.
45  *
46  * Return description for running app.
47  * @return Pointer to esp_app_desc structure.
48  */
49 const esp_app_desc_t *esp_app_get_description(void);
50 
51 /**
52  * @brief   Fill the provided buffer with SHA256 of the ELF file, formatted as hexadecimal, null-terminated.
53  * If the buffer size is not sufficient to fit the entire SHA256 in hex plus a null terminator,
54  * the largest possible number of bytes will be written followed by a null.
55  * @param dst   Destination buffer
56  * @param size  Size of the buffer
57  * @return      Number of bytes written to dst (including null terminator)
58  */
59 int esp_app_get_elf_sha256(char* dst, size_t size);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64