Zephyr API Documentation 3.7.99
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_APP_BUILD_VERSION 0x805
56
58#define BINDESC_ID_KERNEL_VERSION_STRING 0x900
59
61#define BINDESC_ID_KERNEL_VERSION_MAJOR 0x901
62
64#define BINDESC_ID_KERNEL_VERSION_MINOR 0x902
65
67#define BINDESC_ID_KERNEL_VERSION_PATCHLEVEL 0x903
68
70#define BINDESC_ID_KERNEL_VERSION_NUMBER 0x904
71
73#define BINDESC_ID_KERNEL_BUILD_VERSION 0x905
74
76#define BINDESC_ID_BUILD_TIME_YEAR 0xa00
77
79#define BINDESC_ID_BUILD_TIME_MONTH 0xa01
80
82#define BINDESC_ID_BUILD_TIME_DAY 0xa02
83
85#define BINDESC_ID_BUILD_TIME_HOUR 0xa03
86
88#define BINDESC_ID_BUILD_TIME_MINUTE 0xa04
89
91#define BINDESC_ID_BUILD_TIME_SECOND 0xa05
92
94#define BINDESC_ID_BUILD_TIME_UNIX 0xa06
95
97#define BINDESC_ID_BUILD_DATE_TIME_STRING 0xa07
98
100#define BINDESC_ID_BUILD_DATE_STRING 0xa08
101
103#define BINDESC_ID_BUILD_TIME_STRING 0xa09
104
106#define BINDESC_ID_HOST_NAME 0xb00
107
109#define BINDESC_ID_C_COMPILER_NAME 0xb01
110
112#define BINDESC_ID_C_COMPILER_VERSION 0xb02
113
115#define BINDESC_ID_CXX_COMPILER_NAME 0xb03
116
118#define BINDESC_ID_CXX_COMPILER_VERSION 0xb04
119
120#define BINDESC_TAG_DESCRIPTORS_END BINDESC_TAG(DESCRIPTORS_END, 0x0fff)
121
126/*
127 * Utility macro to generate a tag from a type and an ID
128 *
129 * type - Type of the descriptor, UINT, STR or BYTES
130 * id - Unique ID for the descriptor, must fit in 12 bits
131 */
132#define BINDESC_TAG(type, id) ((BINDESC_TYPE_##type & 0xf) << 12 | (id & 0x0fff))
133
138#if !defined(_LINKER)
139
140#include <zephyr/sys/byteorder.h>
141
146/*
147 * Utility macro to get the name of a bindesc entry
148 */
149#define BINDESC_NAME(name) bindesc_entry_##name
150
151/* Convenience helper for declaring a binary descriptor entry. */
152#define __BINDESC_ENTRY_DEFINE(name) \
153 __aligned(BINDESC_ALIGNMENT) const struct bindesc_entry BINDESC_NAME(name) \
154 __in_section(_bindesc_entry, static, name) __used __noasan
155
174#define BINDESC_STR_DEFINE(name, id, value) \
175 __BINDESC_ENTRY_DEFINE(name) = { \
176 .tag = BINDESC_TAG(STR, id), \
177 .len = (uint16_t)sizeof(value), \
178 .data = value, \
179 }
180
195#define BINDESC_UINT_DEFINE(name, id, value) \
196 __BINDESC_ENTRY_DEFINE(name) = { \
197 .tag = BINDESC_TAG(UINT, id), \
198 .len = (uint16_t)sizeof(uint32_t), \
199 .data = sys_uint32_to_array(value), \
200 }
201
220#define BINDESC_BYTES_DEFINE(name, id, value) \
221 __BINDESC_ENTRY_DEFINE(name) = { \
222 .tag = BINDESC_TAG(BYTES, id), \
223 .len = (uint16_t)sizeof((uint8_t [])__DEBRACKET value), \
224 .data = __DEBRACKET value, \
225 }
226
236#define BINDESC_GET_STR(name) BINDESC_NAME(name).data
237
247#define BINDESC_GET_UINT(name) *(uint32_t *)&(BINDESC_NAME(name).data)
248
261#define BINDESC_GET_BYTES(name) BINDESC_NAME(name).data
262
272#define BINDESC_GET_SIZE(name) BINDESC_NAME(name).len
273
274/*
275 * An entry of the binary descriptor header. Each descriptor is
276 * described by one of these entries.
277 */
278struct bindesc_entry {
280 uint16_t tag;
282 uint16_t len;
284 uint8_t data[];
285} __packed;
286
287/*
288 * We're assuming that `struct bindesc_entry` has a specific layout in
289 * memory, so it's worth making sure that the layout is really what we
290 * think it is. If these assertions fail for your toolchain/platform,
291 * please open a bug report.
292 */
293BUILD_ASSERT(offsetof(struct bindesc_entry, tag) == 0, "Incorrect memory layout");
294BUILD_ASSERT(offsetof(struct bindesc_entry, len) == 2, "Incorrect memory layout");
295BUILD_ASSERT(offsetof(struct bindesc_entry, data) == 4, "Incorrect memory layout");
296
297#if defined(CONFIG_BINDESC_KERNEL_VERSION_STRING)
298extern const struct bindesc_entry BINDESC_NAME(kernel_version_string);
299#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_STRING) */
300
301#if defined(CONFIG_BINDESC_KERNEL_VERSION_MAJOR)
302extern const struct bindesc_entry BINDESC_NAME(kernel_version_major);
303#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_MAJOR) */
304
305#if defined(CONFIG_BINDESC_KERNEL_VERSION_MINOR)
306extern const struct bindesc_entry BINDESC_NAME(kernel_version_minor);
307#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_MINOR) */
308
309#if defined(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL)
310extern const struct bindesc_entry BINDESC_NAME(kernel_version_patchlevel);
311#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL) */
312
313#if defined(CONFIG_BINDESC_KERNEL_VERSION_NUMBER)
314extern const struct bindesc_entry BINDESC_NAME(kernel_version_number);
315#endif /* defined(CONFIG_BINDESC_KERNEL_VERSION_NUMBER) */
316
317#if defined(CONFIG_BINDESC_KERNEL_BUILD_VERSION)
318extern const struct bindesc_entry BINDESC_NAME(kernel_build_version);
319#endif /* defined(CONFIG_BINDESC_KERNEL_BUILD_VERSION) */
320
321#if defined(CONFIG_BINDESC_APP_VERSION_STRING)
322extern const struct bindesc_entry BINDESC_NAME(app_version_string);
323#endif /* defined(CONFIG_BINDESC_APP_VERSION_STRING) */
324
325#if defined(CONFIG_BINDESC_APP_VERSION_MAJOR)
326extern const struct bindesc_entry BINDESC_NAME(app_version_major);
327#endif /* defined(CONFIG_BINDESC_APP_VERSION_MAJOR) */
328
329#if defined(CONFIG_BINDESC_APP_VERSION_MINOR)
330extern const struct bindesc_entry BINDESC_NAME(app_version_minor);
331#endif /* defined(CONFIG_BINDESC_APP_VERSION_MINOR) */
332
333#if defined(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL)
334extern const struct bindesc_entry BINDESC_NAME(app_version_patchlevel);
335#endif /* defined(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL) */
336
337#if defined(CONFIG_BINDESC_APP_VERSION_NUMBER)
338extern const struct bindesc_entry BINDESC_NAME(app_version_number);
339#endif /* defined(CONFIG_BINDESC_APP_VERSION_NUMBER) */
340
341#if defined(CONFIG_BINDESC_APP_BUILD_VERSION)
342extern const struct bindesc_entry BINDESC_NAME(app_build_version);
343#endif /* defined(CONFIG_BINDESC_APP_BUILD_VERSION) */
344
345#if defined(CONFIG_BINDESC_BUILD_TIME_YEAR)
346extern const struct bindesc_entry BINDESC_NAME(build_time_year);
347#endif /* defined(CONFIG_BINDESC_BUILD_TIME_YEAR) */
348
349#if defined(CONFIG_BINDESC_BUILD_TIME_MONTH)
350extern const struct bindesc_entry BINDESC_NAME(build_time_month);
351#endif /* defined(CONFIG_BINDESC_BUILD_TIME_MONTH) */
352
353#if defined(CONFIG_BINDESC_BUILD_TIME_DAY)
354extern const struct bindesc_entry BINDESC_NAME(build_time_day);
355#endif /* defined(CONFIG_BINDESC_BUILD_TIME_DAY) */
356
357#if defined(CONFIG_BINDESC_BUILD_TIME_HOUR)
358extern const struct bindesc_entry BINDESC_NAME(build_time_hour);
359#endif /* defined(CONFIG_BINDESC_BUILD_TIME_HOUR) */
360
361#if defined(CONFIG_BINDESC_BUILD_TIME_MINUTE)
362extern const struct bindesc_entry BINDESC_NAME(build_time_minute);
363#endif /* defined(CONFIG_BINDESC_BUILD_TIME_MINUTE) */
364
365#if defined(CONFIG_BINDESC_BUILD_TIME_SECOND)
366extern const struct bindesc_entry BINDESC_NAME(build_time_second);
367#endif /* defined(CONFIG_BINDESC_BUILD_TIME_SECOND) */
368
369#if defined(CONFIG_BINDESC_BUILD_TIME_UNIX)
370extern const struct bindesc_entry BINDESC_NAME(build_time_unix);
371#endif /* defined(CONFIG_BINDESC_BUILD_TIME_UNIX) */
372
373#if defined(CONFIG_BINDESC_BUILD_DATE_TIME_STRING)
374extern const struct bindesc_entry BINDESC_NAME(build_date_time_string);
375#endif /* defined(CONFIG_BINDESC_BUILD_DATE_TIME_STRING) */
376
377#if defined(CONFIG_BINDESC_BUILD_DATE_STRING)
378extern const struct bindesc_entry BINDESC_NAME(build_date_string);
379#endif /* defined(CONFIG_BINDESC_BUILD_DATE_STRING) */
380
381#if defined(CONFIG_BINDESC_BUILD_TIME_STRING)
382extern const struct bindesc_entry BINDESC_NAME(build_time_string);
383#endif /* defined(CONFIG_BINDESC_BUILD_TIME_STRING) */
384
385#if defined(CONFIG_BINDESC_HOST_NAME)
386extern const struct bindesc_entry BINDESC_NAME(host_name);
387#endif /* defined(CONFIG_BINDESC_HOST_NAME) */
388
389#if defined(CONFIG_BINDESC_C_COMPILER_NAME)
390extern const struct bindesc_entry BINDESC_NAME(c_compiler_name);
391#endif /* defined(CONFIG_BINDESC_C_COMPILER_NAME) */
392
393#if defined(CONFIG_BINDESC_C_COMPILER_VERSION)
394extern const struct bindesc_entry BINDESC_NAME(c_compiler_version);
395#endif /* defined(CONFIG_BINDESC_C_COMPILER_VERSION) */
396
397#if defined(CONFIG_BINDESC_CXX_COMPILER_NAME)
398extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_name);
399#endif /* defined(CONFIG_BINDESC_CXX_COMPILER_NAME) */
400
401#if defined(CONFIG_BINDESC_CXX_COMPILER_VERSION)
402extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_version);
403#endif /* defined(CONFIG_BINDESC_CXX_COMPILER_VERSION) */
404
405#endif /* !defined(_LINKER) */
406
411#ifdef __cplusplus
412}
413#endif
414
415#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.