13#ifndef ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_
14#define ZEPHYR_INCLUDE_ZEPHYR_BINDESC_H_
34#define BINDESC_MAGIC 0xb9863e5a7ea46046
36#define BINDESC_ALIGNMENT 4
40#define BINDESC_TYPE_UINT 0x0
41#define BINDESC_TYPE_STR 0x1
42#define BINDESC_TYPE_BYTES 0x2
43#define BINDESC_TYPE_DESCRIPTORS_END 0xf
48#define BINDESC_ENTRY_HEADER_SIZE (sizeof(struct bindesc_entry))
63#define BINDESC_ID_APP_VERSION_STRING 0x800
66#define BINDESC_ID_APP_VERSION_MAJOR 0x801
69#define BINDESC_ID_APP_VERSION_MINOR 0x802
72#define BINDESC_ID_APP_VERSION_PATCHLEVEL 0x803
75#define BINDESC_ID_APP_VERSION_NUMBER 0x804
78#define BINDESC_ID_APP_BUILD_VERSION 0x805
81#define BINDESC_ID_KERNEL_VERSION_STRING 0x900
84#define BINDESC_ID_KERNEL_VERSION_MAJOR 0x901
87#define BINDESC_ID_KERNEL_VERSION_MINOR 0x902
90#define BINDESC_ID_KERNEL_VERSION_PATCHLEVEL 0x903
93#define BINDESC_ID_KERNEL_VERSION_NUMBER 0x904
96#define BINDESC_ID_KERNEL_BUILD_VERSION 0x905
99#define BINDESC_ID_BUILD_TIME_YEAR 0xa00
102#define BINDESC_ID_BUILD_TIME_MONTH 0xa01
105#define BINDESC_ID_BUILD_TIME_DAY 0xa02
108#define BINDESC_ID_BUILD_TIME_HOUR 0xa03
111#define BINDESC_ID_BUILD_TIME_MINUTE 0xa04
114#define BINDESC_ID_BUILD_TIME_SECOND 0xa05
117#define BINDESC_ID_BUILD_TIME_UNIX 0xa06
120#define BINDESC_ID_BUILD_DATE_TIME_STRING 0xa07
123#define BINDESC_ID_BUILD_DATE_STRING 0xa08
126#define BINDESC_ID_BUILD_TIME_STRING 0xa09
129#define BINDESC_ID_HOST_NAME 0xb00
132#define BINDESC_ID_C_COMPILER_NAME 0xb01
135#define BINDESC_ID_C_COMPILER_VERSION 0xb02
138#define BINDESC_ID_CXX_COMPILER_NAME 0xb03
141#define BINDESC_ID_CXX_COMPILER_VERSION 0xb04
144#define BINDESC_TAG_DESCRIPTORS_END BINDESC_TAG(DESCRIPTORS_END, 0x0fff)
156#define BINDESC_TAG(type, id) ((BINDESC_TYPE_##type & 0xf) << 12 | (id & 0x0fff))
163#define BINDESC_GET_TAG_TYPE(tag) ((tag >> 12) & 0xf)
169#if !defined(_LINKER) || defined(__DOXYGEN__)
181#define BINDESC_NAME(name) bindesc_entry_##name
184#define __BINDESC_ENTRY_DEFINE(name) \
185 __aligned(BINDESC_ALIGNMENT) const struct bindesc_entry BINDESC_NAME(name) \
186 __in_section(_bindesc_entry, static, name) __used __noasan
206#define BINDESC_STR_DEFINE(name, id, value) \
207 __BINDESC_ENTRY_DEFINE(name) = { \
208 .tag = BINDESC_TAG(STR, id), \
209 .len = (uint16_t)sizeof(value), \
212 BUILD_ASSERT(sizeof(value) <= CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE, \
213 "Bindesc " STRINGIFY(name) " exceeded maximum size, consider reducing the" \
214 " size or changing CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE. ")
230#define BINDESC_UINT_DEFINE(name, id, value) \
231 __BINDESC_ENTRY_DEFINE(name) = { \
232 .tag = BINDESC_TAG(UINT, id), \
233 .len = (uint16_t)sizeof(uint32_t), \
234 .data = sys_uint32_to_array(value), \
255#define BINDESC_BYTES_DEFINE(name, id, value) \
256 __BINDESC_ENTRY_DEFINE(name) = { \
257 .tag = BINDESC_TAG(BYTES, id), \
258 .len = (uint16_t)sizeof((uint8_t [])__DEBRACKET value), \
259 .data = __DEBRACKET value, \
261 BUILD_ASSERT(sizeof((uint8_t [])__DEBRACKET value) <= \
262 CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE, \
263 "Bindesc " STRINGIFY(name) " exceeded maximum size, consider reducing the" \
264 " size or changing CONFIG_BINDESC_DEFINE_MAX_DATA_SIZE. ")
275#define BINDESC_GET_STR(name) BINDESC_NAME(name).data
286#define BINDESC_GET_UINT(name) *(uint32_t *)&(BINDESC_NAME(name).data)
300#define BINDESC_GET_BYTES(name) BINDESC_NAME(name).data
311#define BINDESC_GET_SIZE(name) BINDESC_NAME(name).len
343BUILD_ASSERT(offsetof(
struct bindesc_entry, tag) == 0,
"Incorrect memory layout");
344BUILD_ASSERT(offsetof(
struct bindesc_entry, len) == 2,
"Incorrect memory layout");
345BUILD_ASSERT(offsetof(
struct bindesc_entry, data) == 4,
"Incorrect memory layout");
355 BINDESC_HANDLE_TYPE_RAM,
356 BINDESC_HANDLE_TYPE_MEMORY_MAPPED_FLASH,
357 BINDESC_HANDLE_TYPE_FLASH,
360#if IS_ENABLED(CONFIG_BINDESC_READ_FLASH)
361 const struct device *flash_device;
433 const struct device *flash_device);
498 size_t *result_size);
518#if defined(CONFIG_BINDESC_KERNEL_VERSION_STRING)
519extern const struct bindesc_entry BINDESC_NAME(kernel_version_string);
522#if defined(CONFIG_BINDESC_KERNEL_VERSION_MAJOR)
523extern const struct bindesc_entry BINDESC_NAME(kernel_version_major);
526#if defined(CONFIG_BINDESC_KERNEL_VERSION_MINOR)
527extern const struct bindesc_entry BINDESC_NAME(kernel_version_minor);
530#if defined(CONFIG_BINDESC_KERNEL_VERSION_PATCHLEVEL)
531extern const struct bindesc_entry BINDESC_NAME(kernel_version_patchlevel);
534#if defined(CONFIG_BINDESC_KERNEL_VERSION_NUMBER)
535extern const struct bindesc_entry BINDESC_NAME(kernel_version_number);
538#if defined(CONFIG_BINDESC_KERNEL_BUILD_VERSION)
539extern const struct bindesc_entry BINDESC_NAME(kernel_build_version);
542#if defined(CONFIG_BINDESC_APP_VERSION_STRING)
543extern const struct bindesc_entry BINDESC_NAME(app_version_string);
546#if defined(CONFIG_BINDESC_APP_VERSION_MAJOR)
547extern const struct bindesc_entry BINDESC_NAME(app_version_major);
550#if defined(CONFIG_BINDESC_APP_VERSION_MINOR)
551extern const struct bindesc_entry BINDESC_NAME(app_version_minor);
554#if defined(CONFIG_BINDESC_APP_VERSION_PATCHLEVEL)
555extern const struct bindesc_entry BINDESC_NAME(app_version_patchlevel);
558#if defined(CONFIG_BINDESC_APP_VERSION_NUMBER)
559extern const struct bindesc_entry BINDESC_NAME(app_version_number);
562#if defined(CONFIG_BINDESC_APP_BUILD_VERSION)
563extern const struct bindesc_entry BINDESC_NAME(app_build_version);
566#if defined(CONFIG_BINDESC_BUILD_TIME_YEAR)
567extern const struct bindesc_entry BINDESC_NAME(build_time_year);
570#if defined(CONFIG_BINDESC_BUILD_TIME_MONTH)
571extern const struct bindesc_entry BINDESC_NAME(build_time_month);
574#if defined(CONFIG_BINDESC_BUILD_TIME_DAY)
575extern const struct bindesc_entry BINDESC_NAME(build_time_day);
578#if defined(CONFIG_BINDESC_BUILD_TIME_HOUR)
579extern const struct bindesc_entry BINDESC_NAME(build_time_hour);
582#if defined(CONFIG_BINDESC_BUILD_TIME_MINUTE)
583extern const struct bindesc_entry BINDESC_NAME(build_time_minute);
586#if defined(CONFIG_BINDESC_BUILD_TIME_SECOND)
587extern const struct bindesc_entry BINDESC_NAME(build_time_second);
590#if defined(CONFIG_BINDESC_BUILD_TIME_UNIX)
591extern const struct bindesc_entry BINDESC_NAME(build_time_unix);
594#if defined(CONFIG_BINDESC_BUILD_DATE_TIME_STRING)
595extern const struct bindesc_entry BINDESC_NAME(build_date_time_string);
598#if defined(CONFIG_BINDESC_BUILD_DATE_STRING)
599extern const struct bindesc_entry BINDESC_NAME(build_date_string);
602#if defined(CONFIG_BINDESC_BUILD_TIME_STRING)
603extern const struct bindesc_entry BINDESC_NAME(build_time_string);
606#if defined(CONFIG_BINDESC_HOST_NAME)
610#if defined(CONFIG_BINDESC_C_COMPILER_NAME)
611extern const struct bindesc_entry BINDESC_NAME(c_compiler_name);
614#if defined(CONFIG_BINDESC_C_COMPILER_VERSION)
615extern const struct bindesc_entry BINDESC_NAME(c_compiler_version);
618#if defined(CONFIG_BINDESC_CXX_COMPILER_NAME)
619extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_name);
622#if defined(CONFIG_BINDESC_CXX_COMPILER_VERSION)
623extern const struct bindesc_entry BINDESC_NAME(cxx_compiler_version);
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:376
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.
#define BINDESC_ALIGNMENT
Required memory alignment for binary descriptor entries.
Definition bindesc.h:36
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Structure for a binary descriptor entry.
Definition bindesc.h:327
uint8_t data[]
Value of the entry.
Definition bindesc.h:333
uint16_t tag
Tag of the entry.
Definition bindesc.h:329
uint16_t len
Length of the descriptor data.
Definition bindesc.h:331
Handle for reading binary descriptors from firmware images.
Definition bindesc.h:351
Runtime device structure (in ROM) per driver instance.
Definition device.h:510