Skip to main content

esp_idf_sys/
app_desc.rs

1//! This module contains a macro - `esp_app_desc` - that - when invoked - defines
2//! the ESP-IDF `esp_app_desc` application description with default information as per below.
3//!
4//! `esp_app_desc` structure fields as defined by the macro:
5//! - version - from CARGO_PKG_VERSION
6//! - project_name - from CARGO_PKG_NAME
7//! - time - current build time
8//! - date - current build date
9//! - idf_ver - current IDF version from bindings
10//! - app_elf_sha256 - [0; 32]
11//! - min_efuse_blk_rev_full - CONFIG_ESP_EFUSE_BLOCK_REV_MIN_FULL
12//! - secure_version - 0
13//!
14//! If you need a custom definition, don't use the macro but rather - manually define your own
15//! static instance of the `esp_app_desc_t` structure in the `.rodata_desc` link section.
16
17#[macro_export]
18macro_rules! esp_app_desc {
19    () => {
20        // For backwards compatibility
21        $crate::esp_app_desc!(false);
22    };
23    {} => {
24        // New way to call the macro
25        $crate::esp_app_desc!(true);
26    };
27    ($fix_date_time_swap: expr) => {
28        #[no_mangle]
29        #[used]
30        #[link_section = ".rodata_desc"]
31        #[allow(non_upper_case_globals)]
32        pub static esp_app_desc: $crate::esp_app_desc_t = {
33            const fn str_to_cstr_array<const C: usize>(s: &str) -> [::core::ffi::c_char; C] {
34                let bytes = s.as_bytes();
35                assert!(bytes.len() < C);
36
37                let mut ret: [::core::ffi::c_char; C] = [0; C];
38                let mut index = 0;
39                while index < bytes.len() {
40                    ret[index] = bytes[index] as _;
41                    index += 1;
42                }
43
44                ret
45            }
46
47            $crate::esp_app_desc_t {
48                magic_word: $crate::ESP_APP_DESC_MAGIC_WORD,
49                secure_version: 0,
50                reserv1: [0; 2],
51                version: str_to_cstr_array(env!("CARGO_PKG_VERSION")),
52                project_name: str_to_cstr_array(env!("CARGO_PKG_NAME")),
53                #[cfg(all(esp_idf_app_compile_time_date, not(esp_idf_app_reproducible_build)))]
54                time: str_to_cstr_array(if $fix_date_time_swap {
55                    $crate::build_time::build_time_utc!("%H:%M:%S")
56                } else {
57                    $crate::build_time::build_time_utc!("%Y-%m-%d")
58                }),
59                #[cfg(all(esp_idf_app_compile_time_date, not(esp_idf_app_reproducible_build)))]
60                date: str_to_cstr_array(if $fix_date_time_swap {
61                    $crate::build_time::build_time_utc!("%Y-%m-%d")
62                } else {
63                    $crate::build_time::build_time_utc!("%H:%M:%S")
64                }),
65                #[cfg(not(all(
66                    esp_idf_app_compile_time_date,
67                    not(esp_idf_app_reproducible_build)
68                )))]
69                time: [0i8; 16],
70                #[cfg(not(all(
71                    esp_idf_app_compile_time_date,
72                    not(esp_idf_app_reproducible_build)
73                )))]
74                date: [0i8; 16],
75                idf_ver: str_to_cstr_array($crate::const_format::formatcp!(
76                    "{}.{}.{}",
77                    $crate::ESP_IDF_VERSION_MAJOR,
78                    $crate::ESP_IDF_VERSION_MINOR,
79                    $crate::ESP_IDF_VERSION_PATCH
80                )),
81                app_elf_sha256: [0; 32],
82                #[cfg(any(
83                    esp_idf_version_patch_at_least_5_1_7,
84                    esp_idf_version_patch_at_least_5_2_3,
85                    esp_idf_version_at_least_5_3_2,
86                ))]
87                min_efuse_blk_rev_full: $crate::CONFIG_ESP_EFUSE_BLOCK_REV_MIN_FULL as _,
88                #[cfg(any(
89                    esp_idf_version_patch_at_least_5_1_7,
90                    esp_idf_version_patch_at_least_5_2_3,
91                    esp_idf_version_at_least_5_3_2,
92                ))]
93                max_efuse_blk_rev_full: $crate::CONFIG_ESP_EFUSE_BLOCK_REV_MAX_FULL as _,
94                #[cfg(esp_idf_version_at_least_5_4_0)]
95                mmu_page_size: 0,
96                #[cfg(esp_idf_version_at_least_5_4_0)]
97                reserv3: [0; 3],
98                #[cfg(esp_idf_version_at_least_5_4_0)]
99                reserv2: [0; 18],
100                #[cfg(any(
101                    esp_idf_version_patch_at_least_5_1_7,
102                    esp_idf_version_patch_at_least_5_2_3,
103                    esp_idf_version_patch_at_least_5_3_2,
104                ))]
105                reserv2: [0; 19],
106                #[cfg(not(any(
107                    esp_idf_version_patch_at_least_5_1_7,
108                    esp_idf_version_patch_at_least_5_2_3,
109                    esp_idf_version_at_least_5_3_2,
110                )))]
111                reserv2: [0; 20],
112            }
113        };
114    };
115}