@@ -113,6 +113,47 @@ name is the Kconfig name (with ``CONFIG_BINDESC_`` removed) in lower case. For e
113
113
``CONFIG_BINDESC_KERNEL_VERSION_STRING `` creates a descriptor that can be
114
114
accessed using ``BINDESC_GET_STR(kernel_version_string) ``.
115
115
116
+ Reading Descriptors
117
+ ===================
118
+ It's also possible to read and parse binary descriptors from an application.
119
+ This can be useful both for an image trying to read its own descriptors, and for
120
+ an image trying to read another image's descriptors. Reading can be performed through
121
+ one of three backends:
122
+
123
+ #. RAM - assuming the descriptors have been copied to RAM (e.g. by a bootloader), they
124
+ can be read from the buffer they reside in.
125
+
126
+ #. Memory mapped flash - If the flash where the image to be read resides in flash and is
127
+ accessible through the program's address space, it can be read directly from flash.
128
+ This option uses the least amount of RAM, but will not work if the flash is not memory mapped,
129
+ and is not recommended to read a bootloader's descriptors for security concerns.
130
+
131
+ #. Flash - Using an internal buffer, the descriptors are read one by one using the flash API,
132
+ and given to the user while they're in the buffer.
133
+
134
+ To enable reading descriptors, enable :kconfig:option: `CONFIG_BINDESC_READ `. The three backends are
135
+ enabled by these Kconfig symbols, respectively: :kconfig:option: `CONFIG_BINDESC_READ_RAM `,
136
+ :kconfig:option: `CONFIG_BINDESC_READ_MEMORY_MAPPED_FLASH `, and :kconfig:option: `CONFIG_BINDESC_READ_FLASH `.
137
+
138
+ To read the descriptors, a handle to the descriptors should first be initialized:
139
+
140
+ .. code-block :: c
141
+
142
+ struct bindesc_handle handle;
143
+
144
+ /* Assume buffer holds a copy of the descriptors */
145
+ bindesc_open_ram(&handle, buffer);
146
+
147
+ The ``bindesc_open_* `` functions are the only functions concerned with the backend used.
148
+ The rest of the API is agnostic to where the data is. After the handle has been initialized,
149
+ it can be used with the rest of the API:
150
+
151
+ .. code-block :: c
152
+
153
+ char *version;
154
+ bindesc_find_str(&handle, BINDESC_ID_KERNEL_VERSION_STRING, &version);
155
+ printk("Kernel version: %s\n", version);
156
+
116
157
west bindesc tool
117
158
=================
118
159
``west `` is able to parse and display binary descriptors from a given executable image.
@@ -123,3 +164,5 @@ API Reference
123
164
*************
124
165
125
166
.. doxygengroup :: bindesc_define
167
+
168
+ .. doxygengroup :: bindesc_read
0 commit comments