7#ifndef ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_
8#define ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_
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
27#define BINDESC_ENTRY_HEADER_SIZE (sizeof(struct bindesc_entry))
42#define BINDESC_ID_APP_VERSION_STRING 0x800
45#define BINDESC_ID_APP_VERSION_MAJOR 0x801
48#define BINDESC_ID_APP_VERSION_MINOR 0x802
51#define BINDESC_ID_APP_VERSION_PATCHLEVEL 0x803
54#define BINDESC_ID_APP_VERSION_NUMBER 0x804
57#define BINDESC_ID_APP_BUILD_VERSION 0x805
60#define BINDESC_ID_KERNEL_VERSION_STRING 0x900
63#define BINDESC_ID_KERNEL_VERSION_MAJOR 0x901
66#define BINDESC_ID_KERNEL_VERSION_MINOR 0x902
69#define BINDESC_ID_KERNEL_VERSION_PATCHLEVEL 0x903
72#define BINDESC_ID_KERNEL_VERSION_NUMBER 0x904
75#define BINDESC_ID_KERNEL_BUILD_VERSION 0x905
78#define BINDESC_ID_BUILD_TIME_YEAR 0xa00
81#define BINDESC_ID_BUILD_TIME_MONTH 0xa01
84#define BINDESC_ID_BUILD_TIME_DAY 0xa02
87#define BINDESC_ID_BUILD_TIME_HOUR 0xa03
90#define BINDESC_ID_BUILD_TIME_MINUTE 0xa04
93#define BINDESC_ID_BUILD_TIME_SECOND 0xa05
96#define BINDESC_ID_BUILD_TIME_UNIX 0xa06
99#define BINDESC_ID_BUILD_DATE_TIME_STRING 0xa07
102#define BINDESC_ID_BUILD_DATE_STRING 0xa08
105#define BINDESC_ID_BUILD_TIME_STRING 0xa09
108#define BINDESC_ID_HOST_NAME 0xb00
111#define BINDESC_ID_C_COMPILER_NAME 0xb01
114#define BINDESC_ID_C_COMPILER_VERSION 0xb02
117#define BINDESC_ID_CXX_COMPILER_NAME 0xb03
120#define BINDESC_ID_CXX_COMPILER_VERSION 0xb04
122#define BINDESC_TAG_DESCRIPTORS_END BINDESC_TAG(DESCRIPTORS_END, 0x0fff)
134#define BINDESC_TAG(type, id) ((BINDESC_TYPE_##type & 0xf) << 12 | (id & 0x0fff))
141#define BINDESC_GET_TAG_TYPE(tag) ((tag >> 12) & 0xf)
147#if !defined(_LINKER) || defined(__DOXYGEN__)
159#define BINDESC_NAME(name) bindesc_entry_##name
162#define __BINDESC_ENTRY_DEFINE(name) \
163 __aligned(BINDESC_ALIGNMENT) const struct bindesc_entry BINDESC_NAME(name) \
164 __in_section(_bindesc_entry, static, name) __used __noasan
184#define BINDESC_STR_DEFINE(name, id, value) \
185 __BINDESC_ENTRY_DEFINE(name) = { \
186 .tag = BINDESC_TAG(STR, id), \
187 .len = (uint16_t)sizeof(value), \
190 BUILD_ASSERT(sizeof(value) <= CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE, \
191 "Bindesc " STRINGIFY(name) " exceeded maximum size, consider reducing the" \
192 " size or changing CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE. ")
208#define BINDESC_UINT_DEFINE(name, id, value) \
209 __BINDESC_ENTRY_DEFINE(name) = { \
210 .tag = BINDESC_TAG(UINT, id), \
211 .len = (uint16_t)sizeof(uint32_t), \
212 .data = sys_uint32_to_array(value), \
233#define BINDESC_BYTES_DEFINE(name, id, value) \
234 __BINDESC_ENTRY_DEFINE(name) = { \
235 .tag = BINDESC_TAG(BYTES, id), \
236 .len = (uint16_t)sizeof((uint8_t [])__DEBRACKET value), \
237 .data = __DEBRACKET value, \
239 BUILD_ASSERT(sizeof((uint8_t [])__DEBRACKET value) <= \
240 CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE, \
241 "Bindesc " STRINGIFY(name) " exceeded maximum size, consider reducing the" \
242 " size or changing CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE. ")
253#define BINDESC_GET_STR(name) BINDESC_NAME(name).data
264#define BINDESC_GET_UINT(name) *(uint32_t *)&(BINDESC_NAME(name).data)
278#define BINDESC_GET_BYTES(name) BINDESC_NAME(name).data
289#define BINDESC_GET_SIZE(name) BINDESC_NAME(name).len
314BUILD_ASSERT(offsetof(
struct bindesc_entry, tag) == 0,
"Incorrect memory layout");
315BUILD_ASSERT(offsetof(
struct bindesc_entry, len) == 2,
"Incorrect memory layout");
316BUILD_ASSERT(offsetof(
struct bindesc_entry, data) == 4,
"Incorrect memory layout");
326#if IS_ENABLED(CONFIG_BINDESC_READ_FLASH)
327 const struct device *flash_device;
403 const struct device *flash_device);
468 size_t *result_size);
488#if defined(CONFIG_BINDESC_KERNEL_VERSION_STRING)
489extern const struct bindesc_entry BINDESC_NAME(kernel_version_string);
492#if defined(CONFIG_BINDESC_KERNEL_VERSION_MAJOR)
493extern const struct bindesc_entry BINDESC_NAME(kernel_version_major);
496#if defined(CONFIG_BINDESC_KERNEL_VERSION_MINOR)
497extern const struct bindesc_entry BINDESC_NAME(kernel_version_minor);
500#if defined(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL)
501extern const struct bindesc_entry BINDESC_NAME(kernel_version_patchlevel);
504#if defined(CONFIG_BINDESC_KERNEL_VERSION_NUMBER)
505extern const struct bindesc_entry BINDESC_NAME(kernel_version_number);
508#if defined(CONFIG_BINDESC_KERNEL_BUILD_VERSION)
509extern const struct bindesc_entry BINDESC_NAME(kernel_build_version);
512#if defined(CONFIG_BINDESC_APP_VERSION_STRING)
513extern const struct bindesc_entry BINDESC_NAME(app_version_string);
516#if defined(CONFIG_BINDESC_APP_VERSION_MAJOR)
517extern const struct bindesc_entry BINDESC_NAME(app_version_major);
520#if defined(CONFIG_BINDESC_APP_VERSION_MINOR)
521extern const struct bindesc_entry BINDESC_NAME(app_version_minor);
524#if defined(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL)
525extern const struct bindesc_entry BINDESC_NAME(app_version_patchlevel);
528#if defined(CONFIG_BINDESC_APP_VERSION_NUMBER)
529extern const struct bindesc_entry BINDESC_NAME(app_version_number);
532#if defined(CONFIG_BINDESC_APP_BUILD_VERSION)
533extern const struct bindesc_entry BINDESC_NAME(app_build_version);
536#if defined(CONFIG_BINDESC_BUILD_TIME_YEAR)
537extern const struct bindesc_entry BINDESC_NAME(build_time_year);
540#if defined(CONFIG_BINDESC_BUILD_TIME_MONTH)
541extern const struct bindesc_entry BINDESC_NAME(build_time_month);
544#if defined(CONFIG_BINDESC_BUILD_TIME_DAY)
545extern const struct bindesc_entry BINDESC_NAME(build_time_day);
548#if defined(CONFIG_BINDESC_BUILD_TIME_HOUR)
549extern const struct bindesc_entry BINDESC_NAME(build_time_hour);
552#if defined(CONFIG_BINDESC_BUILD_TIME_MINUTE)
553extern const struct bindesc_entry BINDESC_NAME(build_time_minute);
556#if defined(CONFIG_BINDESC_BUILD_TIME_SECOND)
557extern const struct bindesc_entry BINDESC_NAME(build_time_second);
560#if defined(CONFIG_BINDESC_BUILD_TIME_UNIX)
561extern const struct bindesc_entry BINDESC_NAME(build_time_unix);
564#if defined(CONFIG_BINDESC_BUILD_DATE_TIME_STRING)
565extern const struct bindesc_entry BINDESC_NAME(build_date_time_string);
568#if defined(CONFIG_BINDESC_BUILD_DATE_STRING)
569extern const struct bindesc_entry BINDESC_NAME(build_date_string);
572#if defined(CONFIG_BINDESC_BUILD_TIME_STRING)
573extern const struct bindesc_entry BINDESC_NAME(build_time_string);
576#if defined(CONFIG_BINDESC_HOST_NAME)
580#if defined(CONFIG_BINDESC_C_COMPILER_NAME)
581extern const struct bindesc_entry BINDESC_NAME(c_compiler_name);
584#if defined(CONFIG_BINDESC_C_COMPILER_VERSION)
585extern const struct bindesc_entry BINDESC_NAME(c_compiler_version);
588#if defined(CONFIG_BINDESC_CXX_COMPILER_NAME)
589extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_name);
592#if defined(CONFIG_BINDESC_CXX_COMPILER_VERSION)
593extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_version);
#define BINDESC_ALIGNMENT
Definition bindesc.h:21
int bindesc_open_memory_mapped_flash(struct bindesc_handle *handle, size_t offset)
Open an image's binary descriptors for reading, from a memory mapped flash.
int bindesc_find_str(struct bindesc_handle *handle, uint16_t id, const char **result)
Find a specific descriptor of type string.
int(* bindesc_callback_t)(const struct bindesc_entry *entry, void *user_data)
Callback type to be called on descriptors found during a walk.
Definition bindesc.h:348
int bindesc_open_flash(struct bindesc_handle *handle, size_t offset, const struct device *flash_device)
Open an image's binary descriptors for reading, from flash.
int bindesc_get_size(struct bindesc_handle *handle, size_t *result)
Get the size of an image's binary descriptors.
int bindesc_foreach(struct bindesc_handle *handle, bindesc_callback_t callback, void *user_data)
Walk the binary descriptors and run a user defined callback on each of them.
int bindesc_find_uint(struct bindesc_handle *handle, uint16_t id, const uint32_t **result)
Find a specific descriptor of type uint.
int bindesc_open_ram(struct bindesc_handle *handle, const uint8_t *address, size_t max_size)
Open an image's binary descriptors for reading, from RAM.
int bindesc_find_bytes(struct bindesc_handle *handle, uint16_t id, const uint8_t **result, size_t *result_size)
Find a specific descriptor of type bytes.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
uint8_t data[]
Value of the entry.
Definition bindesc.h:305
uint16_t tag
Tag of the entry.
Definition bindesc.h:301
uint16_t len
Length of the descriptor data.
Definition bindesc.h:303
const uint8_t * address
Definition bindesc.h:319
@ BINDESC_HANDLE_TYPE_RAM
Definition bindesc.h:321
@ BINDESC_HANDLE_TYPE_MEMORY_MAPPED_FLASH
Definition bindesc.h:322
@ BINDESC_HANDLE_TYPE_FLASH
Definition bindesc.h:323
size_t size_limit
Definition bindesc.h:325
enum bindesc_handle::@68 type
Runtime device structure (in ROM) per driver instance.
Definition device.h:411