nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
fw_info_bare.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef FW_INFO_BARE_H__
8#define FW_INFO_BARE_H__
9
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include <stdint.h>
19#include <string.h>
20
21#define MAGIC_LEN_WORDS (CONFIG_FW_INFO_MAGIC_LEN / sizeof(uint32_t))
22
23/* The supported offsets for the fw_info struct. */
24#define FW_INFO_OFFSET0 0x0
25#define FW_INFO_OFFSET1 0x200
26#define FW_INFO_OFFSET2 0x400
27#define FW_INFO_OFFSET3 0x800
28#define FW_INFO_OFFSET4 0x1000
29#define FW_INFO_OFFSET_COUNT 5
30
42struct __packed fw_info_ext_api {
43 /* Magic value to verify that the struct has the correct format.
44 * The magic value will change whenever the format changes.
45 */
46 uint32_t magic[MAGIC_LEN_WORDS];
47
48 /* The length of this header plus everything after this header. Must be
49 * word-aligned.
50 */
51 uint32_t ext_api_len;
52
53 /* The id of the EXT_API. */
54 uint32_t ext_api_id;
55
56 /* Flags specifying properties of the EXT_API. */
57 uint32_t ext_api_flags;
58
59 /* The version of this EXT_API. */
61};
62
63/* Check and provide a pointer to a fw_info_ext_api structure.
64 *
65 * @return pointer if valid, NULL if not.
66 */
67static inline const struct fw_info_ext_api *fw_info_ext_api_check(
68 uint32_t ext_api_addr)
69{
70 const struct fw_info_ext_api *ext_api;
71 const uint32_t ext_api_magic[] = {EXT_API_MAGIC};
72
73 ext_api = (const struct fw_info_ext_api *)(ext_api_addr);
74 if (memcmp(ext_api->magic, ext_api_magic, CONFIG_FW_INFO_MAGIC_LEN)
75 == 0) {
76 return ext_api;
77 }
78 return NULL;
79}
80
81
98struct __packed fw_info_ext_api_request {
99 /* The requested EXT_API. This struct defines the requested ID as well
100 * as the minimum required version and the flags that must be set.
101 */
102 struct fw_info_ext_api request;
103
104 /* The maximum accepted version. */
106
107 /* This EXT_API is required. I.e. having this EXT_API available is a
108 * hard requirement.
109 */
110 uint32_t required;
111
112 /* Where to place a pointer to the EXT_API. */
113 const struct fw_info_ext_api **ext_api;
114};
115
116
125struct __packed fw_info {
126 /* Magic value to verify that the struct has the correct format.
127 * The magic value will change whenever the format changes.
128 */
129 uint32_t magic[MAGIC_LEN_WORDS];
130
131 /* Total size of this fw_info struct including the EXT_API lists. */
132 uint32_t total_size;
133
134 /* Size of the firmware image code. */
135 uint32_t size;
136
137 /* Monotonically increasing version counter.*/
138 uint32_t version;
139
140 /* The address of the start of the image. */
141 uint32_t address;
142
143 /* The address of the boot point (vector table) of the firmware. */
144 uint32_t boot_address;
145
146 /* Value that can be modified to invalidate the firmware. Has the value
147 * CONFIG_FW_INFO_VALID_VAL when valid.
148 */
149 uint32_t valid;
150
151 /* Reserved values (set to 0) */
152 uint32_t reserved[4];
153
154 /* The number of EXT_APIs in the @ref ext_apis list. */
155 uint32_t ext_api_num;
156
157 /* The number of EXT_API requests in the @ref ext_apis list. */
159
160 /* A list of @ref ext_api_num EXT_APIs followed by @ref
161 * ext_api_request_num EXT_API requests. Since the entries have
162 * different lengths, the @ref ext_api_len of an entry is used to find
163 * the next entry. To get to the EXT_API requests, first iterate over
164 * all EXT_APIs.
165 */
166 const struct fw_info_ext_api ext_apis[];
167};
168
169/* Check and provide a pointer to a firmware_info structure.
170 *
171 * @return pointer if valid, NULL if not.
172 */
173static inline const struct fw_info *fw_info_check(uint32_t fw_info_addr)
174{
175 const struct fw_info *finfo;
176 const uint32_t fw_info_magic[] = {FIRMWARE_INFO_MAGIC};
177
178 finfo = (const struct fw_info *)(fw_info_addr);
179 if (memcmp(finfo->magic, fw_info_magic, CONFIG_FW_INFO_MAGIC_LEN)
180 == 0) {
181 return finfo;
182 }
183 return NULL;
184}
185
186/* The actual fw_info struct offset accounting for any space in front of the
187 * image, e.g. when there's a header.
188 */
189#define FW_INFO_CURRENT_OFFSET (CONFIG_FW_INFO_OFFSET + FW_INFO_VECTOR_OFFSET)
190
191/* Array for run time usage. */
196
197
205static inline const struct fw_info *fw_info_find(uint32_t firmware_address)
206{
207 const struct fw_info *finfo;
208
209 for (uint32_t i = 0; i < FW_INFO_OFFSET_COUNT; i++) {
210 finfo = fw_info_check(firmware_address +
212 if (finfo) {
213 return finfo;
214 }
215 }
216 return NULL;
217}
218
219typedef bool (*fw_info_ext_api_provide_t)(const struct fw_info *fwinfo,
220 bool provide);
221
228
229#ifdef __cplusplus
230}
231#endif
232
235#endif /* FW_INFO_BARE_H__ */
#define MAGIC_LEN_WORDS
Definition fw_info_bare.h:21
#define FW_INFO_OFFSET2
Definition fw_info_bare.h:26
static const uint32_t fw_info_allowed_offsets[]
Definition fw_info_bare.h:192
#define FW_INFO_OFFSET0
Definition fw_info_bare.h:24
bool(* fw_info_ext_api_provide_t)(const struct fw_info *fwinfo, bool provide)
Definition fw_info_bare.h:219
#define FW_INFO_OFFSET1
Definition fw_info_bare.h:25
static const struct fw_info_ext_api * fw_info_ext_api_check(uint32_t ext_api_addr)
Definition fw_info_bare.h:67
#define FW_INFO_OFFSET3
Definition fw_info_bare.h:27
#define FW_INFO_OFFSET4
Definition fw_info_bare.h:28
static const struct fw_info * fw_info_find(uint32_t firmware_address)
Definition fw_info_bare.h:205
#define FW_INFO_OFFSET_COUNT
Definition fw_info_bare.h:29
static const struct fw_info * fw_info_check(uint32_t fw_info_addr)
Definition fw_info_bare.h:173
fw_info_ext_api_provide_t ext_api_provide
Definition fw_info_bare.h:226
Structure describing the EXT_API_PROVIDE EXT_API.
Definition fw_info_bare.h:225
uint32_t required
Definition fw_info_bare.h:110
uint32_t ext_api_max_version
Definition fw_info_bare.h:105
const struct fw_info_ext_api ** ext_api
Definition fw_info_bare.h:113
Definition fw_info_bare.h:98
uint32_t ext_api_version
Definition fw_info_bare.h:60
uint32_t magic[(CONFIG_FW_INFO_MAGIC_LEN/sizeof(uint32_t))]
Definition fw_info_bare.h:46
uint32_t ext_api_id
Definition fw_info_bare.h:54
uint32_t ext_api_flags
Definition fw_info_bare.h:57
uint32_t ext_api_len
Definition fw_info_bare.h:51
Definition fw_info_bare.h:42
uint32_t valid
Definition fw_info_bare.h:149
uint32_t ext_api_num
Definition fw_info_bare.h:155
uint32_t magic[(CONFIG_FW_INFO_MAGIC_LEN/sizeof(uint32_t))]
Definition fw_info_bare.h:129
uint32_t version
Definition fw_info_bare.h:138
uint32_t boot_address
Definition fw_info_bare.h:144
uint32_t size
Definition fw_info_bare.h:135
uint32_t total_size
Definition fw_info_bare.h:132
uint32_t ext_api_request_num
Definition fw_info_bare.h:158
uint32_t address
Definition fw_info_bare.h:141
Definition fw_info_bare.h:125