Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
bindesc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Yonatan Schachter
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_
8#define ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_
9
11
12#ifdef __cplusplus
13extern "C" {
14#endif /* __cplusplus */
15
16/*
17 * Corresponds to the definitions in scripts/west_commands/bindesc.py.
18 * Do not change without syncing the definitions in both files!
19 */
20#define BINDESC_MAGIC 0xb9863e5a7ea46046
21#define BINDESC_ALIGNMENT 4
22#define BINDESC_TYPE_UINT 0x0
23#define BINDESC_TYPE_STR 0x1
24#define BINDESC_TYPE_BYTES 0x2
25#define BINDESC_TYPE_DESCRIPTORS_END 0xf
26
34/*
35 * Corresponds to the definitions in scripts/west_commands/bindesc.py.
36 * Do not change without syncing the definitions in both files!
37 */
38
40#define BINDESC_ID_APP_VERSION_STRING 0x800
41
43#define BINDESC_ID_APP_VERSION_MAJOR 0x801
44
46#define BINDESC_ID_APP_VERSION_MINOR 0x802
47
49#define BINDESC_ID_APP_VERSION_PATCHLEVEL 0x803
50
52#define BINDESC_ID_APP_VERSION_NUMBER 0x804
53
55#define BINDESC_ID_KERNEL_VERSION_STRING 0x900
56
58#define BINDESC_ID_KERNEL_VERSION_MAJOR 0x901
59
61#define BINDESC_ID_KERNEL_VERSION_MINOR 0x902
62
64#define BINDESC_ID_KERNEL_VERSION_PATCHLEVEL 0x903
65
67#define BINDESC_ID_KERNEL_VERSION_NUMBER 0x904
68
70#define BINDESC_ID_BUILD_TIME_YEAR 0xa00
71
73#define BINDESC_ID_BUILD_TIME_MONTH 0xa01
74
76#define BINDESC_ID_BUILD_TIME_DAY 0xa02
77
79#define BINDESC_ID_BUILD_TIME_HOUR 0xa03
80
82#define BINDESC_ID_BUILD_TIME_MINUTE 0xa04
83
85#define BINDESC_ID_BUILD_TIME_SECOND 0xa05
86
88#define BINDESC_ID_BUILD_TIME_UNIX 0xa06
89
91#define BINDESC_ID_BUILD_DATE_TIME_STRING 0xa07
92
94#define BINDESC_ID_BUILD_DATE_STRING 0xa08
95
97#define BINDESC_ID_BUILD_TIME_STRING 0xa09
98
100#define BINDESC_ID_HOST_NAME 0xb00
101
103#define BINDESC_ID_C_COMPILER_NAME 0xb01
104
106#define BINDESC_ID_C_COMPILER_VERSION 0xb02
107
109#define BINDESC_ID_CXX_COMPILER_NAME 0xb03
110
112#define BINDESC_ID_CXX_COMPILER_VERSION 0xb04
113
114#define BINDESC_TAG_DESCRIPTORS_END BINDESC_TAG(DESCRIPTORS_END, 0x0fff)
115
120/*
121 * Utility macro to generate a tag from a type and an ID
122 *
123 * type - Type of the descriptor, UINT, STR or BYTES
124 * id - Unique ID for the descriptor, must fit in 12 bits
125 */
126#define BINDESC_TAG(type, id) ((BINDESC_TYPE_##type & 0xf) << 12 | (id & 0x0fff))
127
132#if !defined(_LINKER)
133
134#include <zephyr/sys/byteorder.h>
135
140/*
141 * Utility macro to get the name of a bindesc entry
142 */
143#define BINDESC_NAME(name) bindesc_entry_##name
144
145/* Convenience helper for declaring a binary descriptor entry. */
146#define __BINDESC_ENTRY_DEFINE(name) \
147 __aligned(BINDESC_ALIGNMENT) const struct bindesc_entry BINDESC_NAME(name) \
148 __in_section(_bindesc_entry, static, name) __used __noasan
149
168#define BINDESC_STR_DEFINE(name, id, value) \
169 __BINDESC_ENTRY_DEFINE(name) = { \
170 .tag = BINDESC_TAG(STR, id), \
171 .len = (uint16_t)sizeof(value), \
172 .data = value, \
173 }
174
189#define BINDESC_UINT_DEFINE(name, id, value) \
190 __BINDESC_ENTRY_DEFINE(name) = { \
191 .tag = BINDESC_TAG(UINT, id), \
192 .len = (uint16_t)sizeof(uint32_t), \
193 .data = sys_uint32_to_array(value), \
194 }
195
214#define BINDESC_BYTES_DEFINE(name, id, value) \
215 __BINDESC_ENTRY_DEFINE(name) = { \
216 .tag = BINDESC_TAG(BYTES, id), \
217 .len = (uint16_t)sizeof((uint8_t [])__DEBRACKET value), \
218 .data = __DEBRACKET value, \
219 }
220
230#define BINDESC_GET_STR(name) BINDESC_NAME(name).data
231
241#define BINDESC_GET_UINT(name) *(uint32_t *)&(BINDESC_NAME(name).data)
242
255#define BINDESC_GET_BYTES(name) BINDESC_NAME(name).data
256
266#define BINDESC_GET_SIZE(name) BINDESC_NAME(name).len
267
268/*
269 * An entry of the binary descriptor header. Each descriptor is
270 * described by one of these entries.
271 */
272struct bindesc_entry {
274 uint16_t tag;
276 uint16_t len;
278 uint8_t data[];
279} __packed;
280
281/*
282 * We're assuming that `struct bindesc_entry` has a specific layout in
283 * memory, so it's worth making sure that the layout is really what we
284 * think it is. If these assertions fail for your toolchain/platform,
285 * please open a bug report.
286 */
287BUILD_ASSERT(offsetof(struct bindesc_entry, tag) == 0, "Incorrect memory layout");
288BUILD_ASSERT(offsetof(struct bindesc_entry, len) == 2, "Incorrect memory layout");
289BUILD_ASSERT(offsetof(struct bindesc_entry, data) == 4, "Incorrect memory layout");
290
291#if defined(CONFIG_BINDESC_KERNEL_VERSION_STRING)
292extern const struct bindesc_entry BINDESC_NAME(kernel_version_string);
293#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_STRING) */
294
295#if defined(CONFIG_BINDESC_KERNEL_VERSION_MAJOR)
296extern const struct bindesc_entry BINDESC_NAME(kernel_version_major);
297#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_MAJOR) */
298
299#if defined(CONFIG_BINDESC_KERNEL_VERSION_MINOR)
300extern const struct bindesc_entry BINDESC_NAME(kernel_version_minor);
301#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_MINOR) */
302
303#if defined(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL)
304extern const struct bindesc_entry BINDESC_NAME(kernel_version_patchlevel);
305#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL) */
306
307#if defined(CONFIG_BINDESC_KERNEL_VERSION_NUMBER)
308extern const struct bindesc_entry BINDESC_NAME(kernel_version_number);
309#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_NUMBER) */
310
311#if defined(CONFIG_BINDESC_APP_VERSION_STRING)
312extern const struct bindesc_entry BINDESC_NAME(app_version_string);
313#endif /* defined(CONFIG_BINDESC_APP_VERSION_STRING) */
314
315#if defined(CONFIG_BINDESC_APP_VERSION_MAJOR)
316extern const struct bindesc_entry BINDESC_NAME(app_version_major);
317#endif /* defined(CONFIG_BINDESC_APP_VERSION_MAJOR) */
318
319#if defined(CONFIG_BINDESC_APP_VERSION_MINOR)
320extern const struct bindesc_entry BINDESC_NAME(app_version_minor);
321#endif /* defined(CONFIG_BINDESC_APP_VERSION_MINOR) */
322
323#if defined(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL)
324extern const struct bindesc_entry BINDESC_NAME(app_version_patchlevel);
325#endif /* defined(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL) */
326
327#if defined(CONFIG_BINDESC_APP_VERSION_NUMBER)
328extern const struct bindesc_entry BINDESC_NAME(app_version_number);
329#endif /* defined(CONFIG_BINDESC_APP_VERSION_NUMBER) */
330
331#if defined(CONFIG_BINDESC_BUILD_TIME_YEAR)
332extern const struct bindesc_entry BINDESC_NAME(build_time_year);
333#endif /* defined(CONFIG_BINDESC_BUILD_TIME_YEAR) */
334
335#if defined(CONFIG_BINDESC_BUILD_TIME_MONTH)
336extern const struct bindesc_entry BINDESC_NAME(build_time_month);
337#endif /* defined(CONFIG_BINDESC_BUILD_TIME_MONTH) */
338
339#if defined(CONFIG_BINDESC_BUILD_TIME_DAY)
340extern const struct bindesc_entry BINDESC_NAME(build_time_day);
341#endif /* defined(CONFIG_BINDESC_BUILD_TIME_DAY) */
342
343#if defined(CONFIG_BINDESC_BUILD_TIME_HOUR)
344extern const struct bindesc_entry BINDESC_NAME(build_time_hour);
345#endif /* defined(CONFIG_BINDESC_BUILD_TIME_HOUR) */
346
347#if defined(CONFIG_BINDESC_BUILD_TIME_MINUTE)
348extern const struct bindesc_entry BINDESC_NAME(build_time_minute);
349#endif /* defined(CONFIG_BINDESC_BUILD_TIME_MINUTE) */
350
351#if defined(CONFIG_BINDESC_BUILD_TIME_SECOND)
352extern const struct bindesc_entry BINDESC_NAME(build_time_second);
353#endif /* defined(CONFIG_BINDESC_BUILD_TIME_SECOND) */
354
355#if defined(CONFIG_BINDESC_BUILD_TIME_UNIX)
356extern const struct bindesc_entry BINDESC_NAME(build_time_unix);
357#endif /* defined(CONFIG_BINDESC_BUILD_TIME_UNIX) */
358
359#if defined(CONFIG_BINDESC_BUILD_DATE_TIME_STRING)
360extern const struct bindesc_entry BINDESC_NAME(build_date_time_string);
361#endif /* defined(CONFIG_BINDESC_BUILD_DATE_TIME_STRING) */
362
363#if defined(CONFIG_BINDESC_BUILD_DATE_STRING)
364extern const struct bindesc_entry BINDESC_NAME(build_date_string);
365#endif /* defined(CONFIG_BINDESC_BUILD_DATE_STRING) */
366
367#if defined(CONFIG_BINDESC_BUILD_TIME_STRING)
368extern const struct bindesc_entry BINDESC_NAME(build_time_string);
369#endif /* defined(CONFIG_BINDESC_BUILD_TIME_STRING) */
370
371#if defined(CONFIG_BINDESC_HOST_NAME)
372extern const struct bindesc_entry BINDESC_NAME(host_name);
373#endif /* defined(CONFIG_BINDESC_HOST_NAME) */
374
375#if defined(CONFIG_BINDESC_C_COMPILER_NAME)
376extern const struct bindesc_entry BINDESC_NAME(c_compiler_name);
377#endif /* defined(CONFIG_BINDESC_C_COMPILER_NAME) */
378
379#if defined(CONFIG_BINDESC_C_COMPILER_VERSION)
380extern const struct bindesc_entry BINDESC_NAME(c_compiler_version);
381#endif /* defined(CONFIG_BINDESC_C_COMPILER_VERSION) */
382
383#if defined(CONFIG_BINDESC_CXX_COMPILER_NAME)
384extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_name);
385#endif /* defined(CONFIG_BINDESC_CXX_COMPILER_NAME) */
386
387#if defined(CONFIG_BINDESC_CXX_COMPILER_VERSION)
388extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_version);
389#endif /* defined(CONFIG_BINDESC_CXX_COMPILER_VERSION) */
390
391#endif /* !defined(_LINKER) */
392
397#ifdef __cplusplus
398}
399#endif
400
401#endif /* ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_ */
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Byte order helpers.
Macro utilities.