44 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
55 */
66
7- #ifndef FW_METADATA_H__
8- #define FW_METADATA_H__
7+ #ifndef FW_INFO_H__
8+ #define FW_INFO_H__
99
1010/*
1111 * The package will consist of (firmware | (padding) | validation_info),
3030#include <pm_config.h>
3131#endif
3232
33- #define MAGIC_LEN_WORDS (CONFIG_FW_MAGIC_LEN / sizeof(u32_t))
33+ #define MAGIC_LEN_WORDS (CONFIG_FW_INFO_MAGIC_LEN / sizeof(u32_t))
3434
35- struct fw_abi_info ;
35+ struct fw_info_abi ;
3636
3737/**@brief Function that returns an ABI.
3838 *
@@ -46,14 +46,20 @@ struct fw_abi_info;
4646 * @retval -EBADF index too large.
4747 * @retval -EFAULT abi was NULL.
4848 */
49- typedef int (* fw_abi_getter )(u32_t id , u32_t index ,
50- const struct fw_abi_info * * abi );
51-
52- struct __packed fw_firmware_info {
53- /* Magic value to verify that the struct has the correct type. */
49+ typedef int (* fw_info_abi_getter )(u32_t id , u32_t index ,
50+ const struct fw_info_abi * * abi );
51+
52+ /**
53+ * This is a data structure that is placed at a specific offset inside a
54+ * firmware image so it can be consistently read by external parties. The
55+ * specific offset makes it easy to find, and the magic value at the start
56+ * guarantees that it contains data of a specific format.
57+ */
58+ struct __packed fw_info {
59+ /* Magic value to verify that the struct has the correct format. */
5460 u32_t magic [MAGIC_LEN_WORDS ];
5561
56- /* Size without validation_info pointer and padding . */
62+ /* Size of the firmware image code . */
5763 u32_t firmware_size ;
5864
5965 /* Monotonically increasing version counter.*/
@@ -63,10 +69,10 @@ struct __packed fw_firmware_info {
6369 u32_t firmware_address ;
6470
6571 /* Where to place the getter for the ABI provided to this firmware. */
66- fw_abi_getter * abi_in ;
72+ fw_info_abi_getter * abi_in ;
6773
6874 /* This firmware's ABI getter. */
69- const fw_abi_getter abi_out ;
75+ const fw_info_abi_getter abi_out ;
7076};
7177
7278
@@ -75,23 +81,24 @@ struct __packed fw_firmware_info {
7581 #member " has wrong offset")
7682
7783/* Static asserts to ensure compatibility */
78- OFFSET_CHECK (struct fw_firmware_info , magic , 0 );
79- OFFSET_CHECK (struct fw_firmware_info , firmware_size , CONFIG_FW_MAGIC_LEN );
80- OFFSET_CHECK (struct fw_firmware_info , firmware_version ,
81- (CONFIG_FW_MAGIC_LEN + 4 ));
82- OFFSET_CHECK (struct fw_firmware_info , firmware_address ,
83- (CONFIG_FW_MAGIC_LEN + 8 ));
84+ OFFSET_CHECK (struct fw_info , magic , 0 );
85+ OFFSET_CHECK (struct fw_info , firmware_size , CONFIG_FW_INFO_MAGIC_LEN );
86+ OFFSET_CHECK (struct fw_info , firmware_version ,
87+ (CONFIG_FW_INFO_MAGIC_LEN + 4 ));
88+ OFFSET_CHECK (struct fw_info , firmware_address ,
89+ (CONFIG_FW_INFO_MAGIC_LEN + 8 ));
8490
8591/* For declaring this firmware's firmware info. */
8692#define __fw_info Z_GENERIC_SECTION(.firmware_info) __attribute__((used)) const
8793
88- /* This struct is meant to serve as a header before a list of function pointers
94+ /**
95+ * This struct is meant to serve as a header before a list of function pointers
8996 * (or something else) that constitute the actual ABI. How to use the ABI, such
9097 * as the signatures of all the functions in the list must be unambiguous for an
9198 * ID/version combination.
9299 */
93- struct __packed fw_abi_info {
94- /* Magic value to verify that the struct has the correct type . */
100+ struct __packed fw_info_abi {
101+ /* Magic value to verify that the struct has the correct format . */
95102 u32_t magic [MAGIC_LEN_WORDS ];
96103
97104 /* The id of the ABI. */
@@ -116,10 +123,11 @@ struct __packed fw_abi_info {
116123
117124#define __ext_abi (type , name ) \
118125 OFFSET_CHECK_EXT_ABI(type, magic, 0); \
119- OFFSET_CHECK_EXT_ABI(type, abi_id, CONFIG_FW_MAGIC_LEN); \
120- OFFSET_CHECK_EXT_ABI(type, abi_flags, (CONFIG_FW_MAGIC_LEN + 4)); \
121- OFFSET_CHECK_EXT_ABI(type, abi_version, (CONFIG_FW_MAGIC_LEN + 8)); \
122- OFFSET_CHECK_EXT_ABI(type, abi_len, (CONFIG_FW_MAGIC_LEN + 12)); \
126+ OFFSET_CHECK_EXT_ABI(type, abi_id, CONFIG_FW_INFO_MAGIC_LEN); \
127+ OFFSET_CHECK_EXT_ABI(type, abi_flags, (CONFIG_FW_INFO_MAGIC_LEN + 4)); \
128+ OFFSET_CHECK_EXT_ABI(type, abi_version,\
129+ (CONFIG_FW_INFO_MAGIC_LEN + 8)); \
130+ OFFSET_CHECK_EXT_ABI(type, abi_len, (CONFIG_FW_INFO_MAGIC_LEN + 12)); \
123131 BUILD_ASSERT_MSG((sizeof(type) % 4) == 0, \
124132 "ext_abi " #type " is not word-aligned"); \
125133 extern const type name; \
@@ -130,7 +138,7 @@ struct __packed fw_abi_info {
130138
131139
132140
133- #define ABI_INFO_INIT (id , flags , version , total_size ) \
141+ #define FW_INFO_ABI_INIT (id , flags , version , total_size ) \
134142 { \
135143 .magic = {ABI_INFO_MAGIC}, \
136144 .abi_id = id, \
@@ -192,14 +200,13 @@ static inline bool memeq(const void *expected, const void *actual, u32_t len)
192200 *
193201 * @return pointer if valid, NULL if not.
194202 */
195- static inline const struct fw_firmware_info *
196- fw_check_firmware_info (u32_t fw_info_addr )
203+ static inline const struct fw_info * fw_info_check (u32_t fw_info_addr )
197204{
198- const struct fw_firmware_info * finfo ;
199- const u32_t firmware_info_magic [] = {FIRMWARE_INFO_MAGIC };
205+ const struct fw_info * finfo ;
206+ const u32_t fw_info_magic [] = {FIRMWARE_INFO_MAGIC };
200207
201- finfo = (const struct fw_firmware_info * )(fw_info_addr );
202- if (memeq (finfo -> magic , firmware_info_magic , CONFIG_FW_MAGIC_LEN )) {
208+ finfo = (const struct fw_info * )(fw_info_addr );
209+ if (memeq (finfo -> magic , fw_info_magic , CONFIG_FW_INFO_MAGIC_LEN )) {
203210 return finfo ;
204211 }
205212 return NULL ;
@@ -226,7 +233,7 @@ fw_check_firmware_info(u32_t fw_info_addr)
226233 #define VECTOR_OFFSET 0
227234#endif
228235
229- #define CURRENT_OFFSET (CONFIG_FW_FIRMWARE_INFO_OFFSET + VECTOR_OFFSET)
236+ #define CURRENT_OFFSET (CONFIG_FW_INFO_OFFSET + VECTOR_OFFSET)
230237
231238static const u32_t allowed_offsets [] = {FW_INFO_OFFSET0 , FW_INFO_OFFSET1 ,
232239 FW_INFO_OFFSET2 };
@@ -237,17 +244,16 @@ BUILD_ASSERT_MSG(ARRAY_SIZE(allowed_offsets) == FW_INFO_OFFSET_COUNT,
237244#if (FW_INFO_OFFSET_COUNT != 3 ) || ((CURRENT_OFFSET ) != (FW_INFO_OFFSET0 ) && \
238245 (CURRENT_OFFSET ) != (FW_INFO_OFFSET1 ) && \
239246 (CURRENT_OFFSET ) != (FW_INFO_OFFSET2 ))
240- #error FW_FIRMWARE_INFO_OFFSET not set to one of the allowed values.
247+ #error FW_INFO_OFFSET not set to one of the allowed values.
241248#endif
242249
243250/* Search for the firmware_info structure inside the firmware. */
244- static inline const struct fw_firmware_info *
245- fw_find_firmware_info (u32_t firmware_address )
251+ static inline const struct fw_info * fw_info_find (u32_t firmware_address )
246252{
247- const struct fw_firmware_info * finfo ;
253+ const struct fw_info * finfo ;
248254
249255 for (u32_t i = 0 ; i < FW_INFO_OFFSET_COUNT ; i ++ ) {
250- finfo = fw_check_firmware_info (firmware_address +
256+ finfo = fw_info_check (firmware_address +
251257 allowed_offsets [i ]);
252258 if (finfo ) {
253259 return finfo ;
@@ -257,31 +263,37 @@ fw_find_firmware_info(u32_t firmware_address)
257263}
258264
259265
260- /* Check a fw_abi_info pointer. */
261- static inline bool fw_abi_info_check (const struct fw_abi_info * abi_info )
266+ /* Check a fw_info_abi pointer. */
267+ static inline bool fw_info_abi_check (const struct fw_info_abi * abi_info )
262268{
263269 const u32_t abi_info_magic [] = {ABI_INFO_MAGIC };
264- return ( memeq (abi_info -> magic , abi_info_magic , CONFIG_FW_MAGIC_LEN ) );
270+ return memeq (abi_info -> magic , abi_info_magic , CONFIG_FW_INFO_MAGIC_LEN );
265271}
266272
267273
268- /* Expose ABIs to the firmware at this address. This is meant to be called
269- * immediately before booting the aforementioned firmware since it will likely
270- * corrupt the memory of the running firmware.
274+ /**Expose ABIs to another firmware
275+ *
276+ * Populate the other firmware's @c abi_in with a internal ABI getter function
277+ * which serves all ABIs created with __ext_abi.
278+ *
279+ * @note This is should be called immediately before booting the other firmware
280+ * since it will likely corrupt the memory of the running firmware.
281+ *
282+ * @param[in] fw_info Pointer to the other firmware's information structure.
271283 */
272- void fw_abi_provide (const struct fw_firmware_info * fw_info );
284+ void fw_info_abi_provide (const struct fw_info * fw_info );
273285
274- /* Get a single ABI.
286+ /** Get a single ABI.
275287 *
276288 * @param[in] id Which ABI to get.
277289 * @param[in] index If there are multiple ABIs available with the same ID,
278290 * retrieve the different ones with this.
279291 *
280292 * @return The ABI, or NULL, if it wasn't found.
281293 */
282- const struct fw_abi_info * fw_abi_get (u32_t id , u32_t index );
294+ const struct fw_info_abi * fw_info_abi_get (u32_t id , u32_t index );
283295
284- /* Find an ABI based on a version range.
296+ /** Find an ABI based on a version range.
285297 *
286298 * @param[in] id The ID of the ABI to find.
287299 * @param[in] flags The required flags of the ABI to find. The returned
@@ -291,7 +303,7 @@ const struct fw_abi_info *fw_abi_get(u32_t id, u32_t index);
291303 *
292304 * @return The ABI, or NULL if none was found.
293305 */
294- const struct fw_abi_info * fw_abi_find (u32_t id , u32_t flags , u32_t min_version ,
295- u32_t max_version );
306+ const struct fw_info_abi * fw_info_abi_find (u32_t id , u32_t flags ,
307+ u32_t min_version , u32_t max_version );
296308
297309#endif
0 commit comments