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 0x600
28#define FW_INFO_OFFSET4 0x800
29#define FW_INFO_OFFSET5 0xe00
30#define FW_INFO_OFFSET6 0x1000
31#define FW_INFO_OFFSET_COUNT 7
32
44struct __packed fw_info_ext_api {
45 /* Magic value to verify that the struct has the correct format.
46 * The magic value will change whenever the format changes.
47 */
48 uint32_t magic[MAGIC_LEN_WORDS];
49
50 /* The length of this header plus everything after this header. Must be
51 * word-aligned.
52 */
53 uint32_t ext_api_len;
54
55 /* The id of the EXT_API. */
56 uint32_t ext_api_id;
57
58 /* Flags specifying properties of the EXT_API. */
59 uint32_t ext_api_flags;
60
61 /* The version of this EXT_API. */
63};
64
65/* Check and provide a pointer to a fw_info_ext_api structure.
66 *
67 * @return pointer if valid, NULL if not.
68 */
69static inline const struct fw_info_ext_api *fw_info_ext_api_check(
70 uint32_t ext_api_addr)
71{
72 const struct fw_info_ext_api *ext_api;
73 const uint32_t ext_api_magic[] = {EXT_API_MAGIC};
74
75 ext_api = (const struct fw_info_ext_api *)(ext_api_addr);
76 if (memcmp(ext_api->magic, ext_api_magic, CONFIG_FW_INFO_MAGIC_LEN)
77 == 0) {
78 return ext_api;
79 }
80 return NULL;
81}
82
83
100struct __packed fw_info_ext_api_request {
101 /* The requested EXT_API. This struct defines the requested ID as well
102 * as the minimum required version and the flags that must be set.
103 */
104 struct fw_info_ext_api request;
105
106 /* The maximum accepted version. */
108
109 /* This EXT_API is required. I.e. having this EXT_API available is a
110 * hard requirement.
111 */
112 uint32_t required;
113
114 /* Where to place a pointer to the EXT_API. */
115 const struct fw_info_ext_api **ext_api;
116};
117
118
127struct __packed fw_info {
128 /* Magic value to verify that the struct has the correct format.
129 * The magic value will change whenever the format changes.
130 */
131 uint32_t magic[MAGIC_LEN_WORDS];
132
133 /* Total size of this fw_info struct including the EXT_API lists. */
134 uint32_t total_size;
135
136 /* Size of the firmware image code. */
137 uint32_t size;
138
139 /* Monotonically increasing version counter.*/
140 uint32_t version;
141
142 /* The address of the start of the image. */
143 uint32_t address;
144
145 /* The address of the boot point (vector table) of the firmware. */
146 uint32_t boot_address;
147
148 /* Value that can be modified to invalidate the firmware. Has the value
149 * CONFIG_FW_INFO_VALID_VAL when valid.
150 */
151 uint32_t valid;
152
153 /* Reserved values (set to 0) */
154 uint32_t reserved[4];
155
156 /* The number of EXT_APIs in the @ref ext_apis list. */
157 uint32_t ext_api_num;
158
159 /* The number of EXT_API requests in the @ref ext_apis list. */
161
162 /* A list of @ref ext_api_num EXT_APIs followed by @ref
163 * ext_api_request_num EXT_API requests. Since the entries have
164 * different lengths, the @ref ext_api_len of an entry is used to find
165 * the next entry. To get to the EXT_API requests, first iterate over
166 * all EXT_APIs.
167 */
168 const struct fw_info_ext_api ext_apis[];
169};
170
171/* Check and provide a pointer to a firmware_info structure.
172 *
173 * @return pointer if valid, NULL if not.
174 */
175static inline const struct fw_info *fw_info_check(uint32_t fw_info_addr)
176{
177 const struct fw_info *finfo;
178 const uint32_t fw_info_magic[] = {FIRMWARE_INFO_MAGIC};
179
180 finfo = (const struct fw_info *)(fw_info_addr);
181 if (memcmp(finfo->magic, fw_info_magic, CONFIG_FW_INFO_MAGIC_LEN)
182 == 0) {
183 return finfo;
184 }
185 return NULL;
186}
187
188/* The actual fw_info struct offset accounting for any space in front of the
189 * image, e.g. when there's a header.
190 */
191#define FW_INFO_CURRENT_OFFSET (CONFIG_FW_INFO_OFFSET + FW_INFO_VECTOR_OFFSET)
192
193/* Array for run time usage. */
199
200
208static inline const struct fw_info *fw_info_find(uint32_t firmware_address)
209{
210 const struct fw_info *finfo;
211
212 for (uint32_t i = 0; i < FW_INFO_OFFSET_COUNT; i++) {
213 finfo = fw_info_check(firmware_address +
215 if (finfo) {
216 return finfo;
217 }
218 }
219 return NULL;
220}
221
222typedef bool (*fw_info_ext_api_provide_t)(const struct fw_info *fwinfo,
223 bool provide);
224
231
232#ifdef __cplusplus
233}
234#endif
235
238#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:194
#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:222
#define FW_INFO_OFFSET6
Definition fw_info_bare.h:30
#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:69
#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:208
#define FW_INFO_OFFSET5
Definition fw_info_bare.h:29
#define FW_INFO_OFFSET_COUNT
Definition fw_info_bare.h:31
static const struct fw_info * fw_info_check(uint32_t fw_info_addr)
Definition fw_info_bare.h:175
fw_info_ext_api_provide_t ext_api_provide
Definition fw_info_bare.h:229
Structure describing the EXT_API_PROVIDE EXT_API.
Definition fw_info_bare.h:228
uint32_t required
Definition fw_info_bare.h:112
uint32_t ext_api_max_version
Definition fw_info_bare.h:107
const struct fw_info_ext_api ** ext_api
Definition fw_info_bare.h:115
Definition fw_info_bare.h:100
uint32_t ext_api_version
Definition fw_info_bare.h:62
uint32_t magic[(CONFIG_FW_INFO_MAGIC_LEN/sizeof(uint32_t))]
Definition fw_info_bare.h:48
uint32_t ext_api_id
Definition fw_info_bare.h:56
uint32_t ext_api_flags
Definition fw_info_bare.h:59
uint32_t ext_api_len
Definition fw_info_bare.h:53
Definition fw_info_bare.h:44
uint32_t valid
Definition fw_info_bare.h:151
uint32_t ext_api_num
Definition fw_info_bare.h:157
uint32_t magic[(CONFIG_FW_INFO_MAGIC_LEN/sizeof(uint32_t))]
Definition fw_info_bare.h:131
uint32_t version
Definition fw_info_bare.h:140
uint32_t boot_address
Definition fw_info_bare.h:146
uint32_t size
Definition fw_info_bare.h:137
uint32_t total_size
Definition fw_info_bare.h:134
uint32_t ext_api_request_num
Definition fw_info_bare.h:160
uint32_t address
Definition fw_info_bare.h:143
Definition fw_info_bare.h:127