Zephyr API Documentation  3.6.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
33/*
34 * Corresponds to the definitions in scripts/west_commands/bindesc.py.
35 * Do not change without syncing the definitions in both files!
36 */
37
39#define BINDESC_ID_APP_VERSION_STRING 0x800
40
42#define BINDESC_ID_APP_VERSION_MAJOR 0x801
43
45#define BINDESC_ID_APP_VERSION_MINOR 0x802
46
48#define BINDESC_ID_APP_VERSION_PATCHLEVEL 0x803
49
51#define BINDESC_ID_APP_VERSION_NUMBER 0x804
52
54#define BINDESC_ID_KERNEL_VERSION_STRING 0x900
55
57#define BINDESC_ID_KERNEL_VERSION_MAJOR 0x901
58
60#define BINDESC_ID_KERNEL_VERSION_MINOR 0x902
61
63#define BINDESC_ID_KERNEL_VERSION_PATCHLEVEL 0x903
64
66#define BINDESC_ID_KERNEL_VERSION_NUMBER 0x904
67
69#define BINDESC_ID_BUILD_TIME_YEAR 0xa00
70
72#define BINDESC_ID_BUILD_TIME_MONTH 0xa01
73
75#define BINDESC_ID_BUILD_TIME_DAY 0xa02
76
78#define BINDESC_ID_BUILD_TIME_HOUR 0xa03
79
81#define BINDESC_ID_BUILD_TIME_MINUTE 0xa04
82
84#define BINDESC_ID_BUILD_TIME_SECOND 0xa05
85
87#define BINDESC_ID_BUILD_TIME_UNIX 0xa06
88
90#define BINDESC_ID_BUILD_DATE_TIME_STRING 0xa07
91
93#define BINDESC_ID_BUILD_DATE_STRING 0xa08
94
96#define BINDESC_ID_BUILD_TIME_STRING 0xa09
97
99#define BINDESC_ID_HOST_NAME 0xb00
100
102#define BINDESC_ID_C_COMPILER_NAME 0xb01
103
105#define BINDESC_ID_C_COMPILER_VERSION 0xb02
106
108#define BINDESC_ID_CXX_COMPILER_NAME 0xb03
109
111#define BINDESC_ID_CXX_COMPILER_VERSION 0xb04
112
113#define BINDESC_TAG_DESCRIPTORS_END BINDESC_TAG(DESCRIPTORS_END, 0x0fff)
114
119/*
120 * Utility macro to generate a tag from a type and an ID
121 *
122 * type - Type of the descriptor, UINT, STR or BYTES
123 * id - Unique ID for the descriptor, must fit in 12 bits
124 */
125#define BINDESC_TAG(type, id) ((BINDESC_TYPE_##type & 0xf) << 12 | (id & 0x0fff))
126
131#if !IS_ENABLED(_LINKER)
132
133#include <zephyr/sys/byteorder.h>
134
139/*
140 * Utility macro to get the name of a bindesc entry
141 */
142#define BINDESC_NAME(name) bindesc_entry_##name
143
144/* Convenience helper for declaring a binary descriptor entry. */
145#define __BINDESC_ENTRY_DEFINE(name) \
146 __aligned(BINDESC_ALIGNMENT) const struct bindesc_entry BINDESC_NAME(name) \
147 __in_section(_bindesc_entry, static, name) __used __noasan
148
167#define BINDESC_STR_DEFINE(name, id, value) \
168 __BINDESC_ENTRY_DEFINE(name) = { \
169 .tag = BINDESC_TAG(STR, id), \
170 .len = (uint16_t)sizeof(value), \
171 .data = value, \
172 }
173
188#define BINDESC_UINT_DEFINE(name, id, value) \
189 __BINDESC_ENTRY_DEFINE(name) = { \
190 .tag = BINDESC_TAG(UINT, id), \
191 .len = (uint16_t)sizeof(uint32_t), \
192 .data = sys_uint32_to_array(value), \
193 }
194
213#define BINDESC_BYTES_DEFINE(name, id, value) \
214 __BINDESC_ENTRY_DEFINE(name) = { \
215 .tag = BINDESC_TAG(BYTES, id), \
216 .len = (uint16_t)sizeof((uint8_t [])__DEBRACKET value), \
217 .data = __DEBRACKET value, \
218 }
219
229#define BINDESC_GET_STR(name) BINDESC_NAME(name).data
230
240#define BINDESC_GET_UINT(name) *(uint32_t *)&(BINDESC_NAME(name).data)
241
254#define BINDESC_GET_BYTES(name) BINDESC_NAME(name).data
255
265#define BINDESC_GET_SIZE(name) BINDESC_NAME(name).len
266
271/*
272 * An entry of the binary descriptor header. Each descriptor is
273 * described by one of these entries.
274 */
282} __packed;
283
284/*
285 * We're assuming that `struct bindesc_entry` has a specific layout in
286 * memory, so it's worth making sure that the layout is really what we
287 * think it is. If these assertions fail for your toolchain/platform,
288 * please open a bug report.
289 */
290BUILD_ASSERT(offsetof(struct bindesc_entry, tag) == 0, "Incorrect memory layout");
291BUILD_ASSERT(offsetof(struct bindesc_entry, len) == 2, "Incorrect memory layout");
292BUILD_ASSERT(offsetof(struct bindesc_entry, data) == 4, "Incorrect memory layout");
293
294#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_STRING)
295extern const struct bindesc_entry BINDESC_NAME(kernel_version_string);
296#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_STRING) */
297
298#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MAJOR)
299extern const struct bindesc_entry BINDESC_NAME(kernel_version_major);
300#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MAJOR) */
301
302#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MINOR)
303extern const struct bindesc_entry BINDESC_NAME(kernel_version_minor);
304#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_MINOR) */
305
306#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL)
307extern const struct bindesc_entry BINDESC_NAME(kernel_version_patchlevel);
308#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL) */
309
310#if IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_NUMBER)
311extern const struct bindesc_entry BINDESC_NAME(kernel_version_number);
312#endif /* IS_ENABLED(CONFIG_BINDESC_KERNEL_VERSION_NUMBER) */
313
314#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_STRING)
315extern const struct bindesc_entry BINDESC_NAME(app_version_string);
316#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_STRING) */
317
318#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MAJOR)
319extern const struct bindesc_entry BINDESC_NAME(app_version_major);
320#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MAJOR) */
321
322#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MINOR)
323extern const struct bindesc_entry BINDESC_NAME(app_version_minor);
324#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_MINOR) */
325
326#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL)
327extern const struct bindesc_entry BINDESC_NAME(app_version_patchlevel);
328#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL) */
329
330#if IS_ENABLED(CONFIG_BINDESC_APP_VERSION_NUMBER)
331extern const struct bindesc_entry BINDESC_NAME(app_version_number);
332#endif /* IS_ENABLED(CONFIG_BINDESC_APP_VERSION_NUMBER) */
333
334#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_YEAR)
335extern const struct bindesc_entry BINDESC_NAME(build_time_year);
336#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_YEAR) */
337
338#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MONTH)
339extern const struct bindesc_entry BINDESC_NAME(build_time_month);
340#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MONTH) */
341
342#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_DAY)
343extern const struct bindesc_entry BINDESC_NAME(build_time_day);
344#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_DAY) */
345
346#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_HOUR)
347extern const struct bindesc_entry BINDESC_NAME(build_time_hour);
348#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_HOUR) */
349
350#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MINUTE)
351extern const struct bindesc_entry BINDESC_NAME(build_time_minute);
352#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_MINUTE) */
353
354#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_SECOND)
355extern const struct bindesc_entry BINDESC_NAME(build_time_second);
356#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_SECOND) */
357
358#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_UNIX)
359extern const struct bindesc_entry BINDESC_NAME(build_time_unix);
360#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_UNIX) */
361
362#if IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_TIME_STRING)
363extern const struct bindesc_entry BINDESC_NAME(build_date_time_string);
364#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_TIME_STRING) */
365
366#if IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_STRING)
367extern const struct bindesc_entry BINDESC_NAME(build_date_string);
368#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_DATE_STRING) */
369
370#if IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_STRING)
371extern const struct bindesc_entry BINDESC_NAME(build_time_string);
372#endif /* IS_ENABLED(CONFIG_BINDESC_BUILD_TIME_STRING) */
373
374#if IS_ENABLED(CONFIG_BINDESC_HOST_NAME)
375extern const struct bindesc_entry BINDESC_NAME(host_name);
376#endif /* IS_ENABLED(CONFIG_BINDESC_HOST_NAME) */
377
378#if IS_ENABLED(CONFIG_BINDESC_C_COMPILER_NAME)
379extern const struct bindesc_entry BINDESC_NAME(c_compiler_name);
380#endif /* IS_ENABLED(CONFIG_BINDESC_C_COMPILER_NAME) */
381
382#if IS_ENABLED(CONFIG_BINDESC_C_COMPILER_VERSION)
383extern const struct bindesc_entry BINDESC_NAME(c_compiler_version);
384#endif /* IS_ENABLED(CONFIG_BINDESC_C_COMPILER_VERSION) */
385
386#if IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_NAME)
387extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_name);
388#endif /* IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_NAME) */
389
390#if IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_VERSION)
391extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_version);
392#endif /* IS_ENABLED(CONFIG_BINDESC_CXX_COMPILER_VERSION) */
393
394#endif /* !IS_ENABLED(_LINKER) */
395
396#ifdef __cplusplus
397}
398#endif
399
400#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:275
uint8_t data[]
Value of the entry.
Definition: bindesc.h:281
uint16_t tag
Tag of the entry.
Definition: bindesc.h:277
uint16_t len
Length of the descriptor data.
Definition: bindesc.h:279
Byte order helpers.
Macro utilities.