Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
10#ifdef __cplusplus
11extern "C" {
12#endif /* __cplusplus */
13
14/*
15 * Corresponds to the definitions in scripts/west_commands/bindesc.py.
16 * Do not change without syncing the definitions in both files!
17 */
18#define BINDESC_MAGIC 0xb9863e5a7ea46046
19#define BINDESC_ALIGNMENT 4
20#define BINDESC_TYPE_UINT 0x0
21#define BINDESC_TYPE_STR 0x1
22#define BINDESC_TYPE_BYTES 0x2
23#define BINDESC_TYPE_DESCRIPTORS_END 0xf
24
31/*
32 * Corresponds to the definitions in scripts/west_commands/bindesc.py.
33 * Do not change without syncing the definitions in both files!
34 */
35
37#define BINDESC_ID_APP_VERSION_STRING 0x800
38
40#define BINDESC_ID_APP_VERSION_MAJOR 0x801
41
43#define BINDESC_ID_APP_VERSION_MINOR 0x802
44
46#define BINDESC_ID_APP_VERSION_PATCHLEVEL 0x803
47
49#define BINDESC_ID_APP_VERSION_NUMBER 0x804
50
52#define BINDESC_ID_KERNEL_VERSION_STRING 0x900
53
55#define BINDESC_ID_KERNEL_VERSION_MAJOR 0x901
56
58#define BINDESC_ID_KERNEL_VERSION_MINOR 0x902
59
61#define BINDESC_ID_KERNEL_VERSION_PATCHLEVEL 0x903
62
64#define BINDESC_ID_KERNEL_VERSION_NUMBER 0x904
65
67#define BINDESC_ID_BUILD_TIME_YEAR 0xa00
68
70#define BINDESC_ID_BUILD_TIME_MONTH 0xa01
71
73#define BINDESC_ID_BUILD_TIME_DAY 0xa02
74
76#define BINDESC_ID_BUILD_TIME_HOUR 0xa03
77
79#define BINDESC_ID_BUILD_TIME_MINUTE 0xa04
80
82#define BINDESC_ID_BUILD_TIME_SECOND 0xa05
83
85#define BINDESC_ID_BUILD_TIME_UNIX 0xa06
86
88#define BINDESC_ID_BUILD_DATE_TIME_STRING 0xa07
89
91#define BINDESC_ID_BUILD_DATE_STRING 0xa08
92
94#define BINDESC_ID_BUILD_TIME_STRING 0xa09
95
97#define BINDESC_ID_HOST_NAME 0xb00
98
100#define BINDESC_ID_C_COMPILER_NAME 0xb01
101
103#define BINDESC_ID_C_COMPILER_VERSION 0xb02
104
106#define BINDESC_ID_CXX_COMPILER_NAME 0xb03
107
109#define BINDESC_ID_CXX_COMPILER_VERSION 0xb04
110
111#define BINDESC_TAG_DESCRIPTORS_END BINDESC_TAG(DESCRIPTORS_END, 0x0fff)
112
117/*
118 * Utility macro to generate a tag from a type and an ID
119 *
120 * type - Type of the descriptor, UINT, STR or BYTES
121 * id - Unique ID for the descriptor, must fit in 12 bits
122 */
123#define BINDESC_TAG(type, id) ((BINDESC_TYPE_##type & 0xf) << 12 | (id & 0x0fff))
124
129#if !IS_ENABLED(_LINKER)
130
131#include <zephyr/sys/byteorder.h>
132
137/*
138 * Utility macro to get the name of a bindesc entry
139 */
140#define BINDESC_NAME(name) bindesc_entry_##name
141
142/* Convenience helper for declaring a binary descriptor entry. */
143#define __BINDESC_ENTRY_DEFINE(name) \
144 __aligned(BINDESC_ALIGNMENT) const struct bindesc_entry BINDESC_NAME(name) \
145 __in_section(_bindesc_entry, static, name) __used __noasan
146
165#define BINDESC_STR_DEFINE(name, id, value) \
166 __BINDESC_ENTRY_DEFINE(name) = { \
167 .tag = BINDESC_TAG(STR, id), \
168 .len = (uint16_t)sizeof(value), \
169 .data = value, \
170 }
171
186#define BINDESC_UINT_DEFINE(name, id, value) \
187 __BINDESC_ENTRY_DEFINE(name) = { \
188 .tag = BINDESC_TAG(UINT, id), \
189 .len = (uint16_t)sizeof(uint32_t), \
190 .data = sys_uint32_to_array(value), \
191 }
192
211#define BINDESC_BYTES_DEFINE(name, id, value) \
212 __BINDESC_ENTRY_DEFINE(name) = { \
213 .tag = BINDESC_TAG(BYTES, id), \
214 .len = (uint16_t)sizeof((uint8_t [])__DEBRACKET value), \
215 .data = __DEBRACKET value, \
216 }
217
227#define BINDESC_GET_STR(name) BINDESC_NAME(name).data
228
238#define BINDESC_GET_UINT(name) *(uint32_t *)&(BINDESC_NAME(name).data)
239
252#define BINDESC_GET_BYTES(name) BINDESC_NAME(name).data
253
263#define BINDESC_GET_SIZE(name) BINDESC_NAME(name).len
264
269/*
270 * An entry of the binary descriptor header. Each descriptor is
271 * described by one of these entries.
272 */
280} __packed;
281
282/*
283 * We're assuming that `struct bindesc_entry` has a specific layout in
284 * memory, so it's worth making sure that the layout is really what we
285 * think it is. If these assertions fail for your toolchain/platform,
286 * please open a bug report.
287 */
288BUILD_ASSERT(offsetof(struct bindesc_entry, tag) == 0, "Incorrect memory layout");
289BUILD_ASSERT(offsetof(struct bindesc_entry, len) == 2, "Incorrect memory layout");
290BUILD_ASSERT(offsetof(struct bindesc_entry, data) == 4, "Incorrect memory layout");
291
292#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_STRING)
293extern const struct bindesc_entry BINDESC_NAME(kernel_version_string);
294#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_STRING) */
295
296#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MAJOR)
297extern const struct bindesc_entry BINDESC_NAME(kernel_version_major);
298#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MAJOR) */
299
300#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MINOR)
301extern const struct bindesc_entry BINDESC_NAME(kernel_version_minor);
302#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MINOR) */
303
304#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL)
305extern const struct bindesc_entry BINDESC_NAME(kernel_version_patchlevel);
306#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL) */
307
308#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_NUMBER)
309extern const struct bindesc_entry BINDESC_NAME(kernel_version_number);
310#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_NUMBER) */
311
312#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_STRING)
313extern const struct bindesc_entry BINDESC_NAME(app_version_string);
314#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_STRING) */
315
316#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MAJOR)
317extern const struct bindesc_entry BINDESC_NAME(app_version_major);
318#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MAJOR) */
319
320#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MINOR)
321extern const struct bindesc_entry BINDESC_NAME(app_version_minor);
322#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MINOR) */
323
324#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL)
325extern const struct bindesc_entry BINDESC_NAME(app_version_patchlevel);
326#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL) */
327
328#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_NUMBER)
329extern const struct bindesc_entry BINDESC_NAME(app_version_number);
330#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_NUMBER) */
331
332#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_YEAR)
333extern const struct bindesc_entry BINDESC_NAME(build_time_year);
334#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_YEAR) */
335
336#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MONTH)
337extern const struct bindesc_entry BINDESC_NAME(build_time_month);
338#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MONTH) */
339
340#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_DAY)
341extern const struct bindesc_entry BINDESC_NAME(build_time_day);
342#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_DAY) */
343
344#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_HOUR)
345extern const struct bindesc_entry BINDESC_NAME(build_time_hour);
346#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_HOUR) */
347
348#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MINUTE)
349extern const struct bindesc_entry BINDESC_NAME(build_time_minute);
350#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MINUTE) */
351
352#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_SECOND)
353extern const struct bindesc_entry BINDESC_NAME(build_time_second);
354#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_SECOND) */
355
356#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_UNIX)
357extern const struct bindesc_entry BINDESC_NAME(build_time_unix);
358#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_UNIX) */
359
360#if IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_TIME_STRING)
361extern const struct bindesc_entry BINDESC_NAME(build_date_time_string);
362#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_TIME_STRING) */
363
364#if IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_STRING)
365extern const struct bindesc_entry BINDESC_NAME(build_date_string);
366#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_STRING) */
367
368#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_STRING)
369extern const struct bindesc_entry BINDESC_NAME(build_time_string);
370#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_STRING) */
371
372#if IS_ENABLED(CONFIG_BINDESC_HOST_NAME)
373extern const struct bindesc_entry BINDESC_NAME(host_name);
374#endif /* IS_ENABLED(CONFIG_BINDESC_HOST_NAME) */
375
376#if IS_ENABLED(CONFIG_BINDESC_C_COMPILER_NAME)
377extern const struct bindesc_entry BINDESC_NAME(c_compiler_name);
378#endif /* IS_ENABLED(CONFIG_BINDESC_C_COMPILER_NAME) */
379
380#if IS_ENABLED(CONFIG_BINDESC_C_COMPILER_VERSION)
381extern const struct bindesc_entry BINDESC_NAME(c_compiler_version);
382#endif /* IS_ENABLED(CONFIG_BINDESC_C_COMPILER_VERSION) */
383
384#if IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_NAME)
385extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_name);
386#endif /* IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_NAME) */
387
388#if IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_VERSION)
389extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_version);
390#endif /* IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_VERSION) */
391
392#endif /* !IS_ENABLED(_LINKER) */
393
394#ifdef __cplusplus
395}
396#endif
397
398#endif /* ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_ */
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Definition: bindesc.h:273
uint8_t data[]
Value of the entry.
Definition: bindesc.h:279
uint16_t tag
Tag of the entry.
Definition: bindesc.h:275
uint16_t len
Length of the descriptor data.
Definition: bindesc.h:277
Byte order helpers.