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