Skip to content

Commit dd365fa

Browse files
oyvindronningstadhakonfam
authored andcommitted
fw_metadata: Rename fw_metadata to fw_info
Including configs, functions, types etc. Signed-off-by: Øyvind Rønningstad <[email protected]>
1 parent 7f0bdbb commit dd365fa

File tree

27 files changed

+261
-245
lines changed

27 files changed

+261
-245
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ subsys/debug/CMakeLists.txt @nordic-krch
6464
/subsys/dfu/ @hakonfam @sigvartmh
6565
/subsys/enhanced_shockburst/ @Raane @lemrey
6666
/subsys/event_manager/ @pdunaj
67-
/subsys/fw_metadata/ @hakonfam
67+
/subsys/fw_info/ @hakonfam
6868
/subsys/net/ @rlubos
6969
/subsys/nfc/ @grochu @anangl
7070
/subsys/partition_manager/ @hakonfam

include/bl_crypto.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define BOOTLOADER_CRYPTO_H__
99

1010
#include <zephyr/types.h>
11-
#include <fw_metadata.h>
11+
#include <fw_info.h>
1212

1313
/* Placeholder defines. Values should be updated, if no existing errors can be
1414
* used instead. */
@@ -155,14 +155,14 @@ EXT_ABI_FUNCTION(int, bl_secp256r1_validate, const u8_t *hash,
155155
const u8_t *public_key);
156156

157157
struct bl_rot_verify_abi {
158-
struct fw_abi_info header;
158+
struct fw_info_abi header;
159159
struct {
160160
bl_root_of_trust_verify_t bl_root_of_trust_verify;
161161
} abi;
162162
};
163163

164164
struct bl_sha256_abi {
165-
struct fw_abi_info header;
165+
struct fw_info_abi header;
166166
struct {
167167
bl_sha256_init_t bl_sha256_init;
168168
bl_sha256_update_t bl_sha256_update;
@@ -173,7 +173,7 @@ struct bl_sha256_abi {
173173
};
174174

175175
struct bl_secp256r1_abi {
176-
struct fw_abi_info header;
176+
struct fw_info_abi header;
177177
struct {
178178
bl_secp256r1_validate_t bl_secp256r1_validate;
179179
} abi;

include/bl_validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#define BL_VALIDATION_H__
99

1010
#include <stdbool.h>
11-
#include <fw_metadata.h>
11+
#include <fw_info.h>
1212

1313
bool bl_validate_firmware_local(u32_t fw_address,
14-
const struct fw_firmware_info *fw_info);
14+
const struct fw_info *fwinfo);
1515

1616
#endif /* BL_VALIDATION_H__ */

include/fw_metadata.h renamed to include/fw_info.h

Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
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),
@@ -30,9 +30,9 @@
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

231238
static 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

include/secure_services.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include <stddef.h>
2424
#include <zephyr/types.h>
25-
#include <fw_metadata.h>
25+
#include <fw_info.h>
2626

2727
#ifdef __cplusplus
2828
extern "C" {
@@ -75,7 +75,7 @@ int spm_request_read(void *destination, u32_t addr, size_t len);
7575
* @retval -EINVAL If info is NULL.
7676
* @retval -EFAULT If no info is found.
7777
*/
78-
int spm_firmware_info(u32_t fw_address, struct fw_firmware_info *info);
78+
int spm_firmware_info(u32_t fw_address, struct fw_info *info);
7979

8080
#ifdef __cplusplus
8181
}

samples/bootloader/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <pm_config.h>
1414
#include <bl_validation.h>
1515
#include <bl_crypto.h>
16-
#include <fw_metadata.h>
16+
#include <fw_info.h>
1717
#include <drivers/fprotect.h>
1818
#include <provision.h>
1919
#ifdef CONFIG_UART_NRFX
@@ -44,7 +44,7 @@ extern u32_t _vector_table_pointer;
4444
#define VTOR SCB->VTOR
4545
#endif
4646

47-
static void boot_from(const struct fw_firmware_info *fw_info)
47+
static void boot_from(const struct fw_info *fw_info)
4848
{
4949
u32_t *vector_table = (u32_t *)fw_info->firmware_address;
5050

@@ -99,7 +99,7 @@ static void boot_from(const struct fw_firmware_info *fw_info)
9999

100100
VTOR = fw_info->firmware_address;
101101

102-
fw_abi_provide(fw_info);
102+
fw_info_abi_provide(fw_info);
103103

104104
/* Set MSP to the new address and clear any information from PSP */
105105
__set_MSP(vector_table[0]);
@@ -121,8 +121,8 @@ void main(void)
121121

122122
u32_t s0_addr = s0_address_read();
123123
u32_t s1_addr = s1_address_read();
124-
const struct fw_firmware_info *s0_info = fw_find_firmware_info(s0_addr);
125-
const struct fw_firmware_info *s1_info = fw_find_firmware_info(s1_addr);
124+
const struct fw_info *s0_info = fw_info_find(s0_addr);
125+
const struct fw_info *s1_info = fw_info_find(s1_addr);
126126

127127
if (!s1_info || (s0_info->firmware_version >=
128128
s1_info->firmware_version)) {

samples/nrf9160/secure_services/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <secure_services.h>
1111
#include <kernel.h>
1212
#include <pm_config.h>
13-
#include <fw_metadata.h>
13+
#include <fw_info.h>
1414

1515
void print_hex_number(u8_t *num, size_t len)
1616
{
@@ -29,7 +29,7 @@ void print_random_number(u8_t *num, size_t len)
2929

3030
void main(void)
3131
{
32-
struct fw_firmware_info info_app;
32+
struct fw_info info_app;
3333
const int sleep_time_s = 5;
3434
const int random_number_count = 16;
3535
const int random_number_len = 144;

samples/nrf9160/spm/prj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
55
#
66
CONFIG_IS_SPM=y
7-
CONFIG_FW_METADATA=y
7+
CONFIG_FW_INFO=y
88
CONFIG_GPIO=n

subsys/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (CONFIG_NRFXLIB_NFC OR
2828
add_subdirectory(nfc)
2929
endif()
3030

31-
add_subdirectory_ifdef(CONFIG_FW_METADATA fw_metadata)
31+
add_subdirectory_ifdef(CONFIG_FW_INFO fw_info)
3232
add_subdirectory_ifdef(CONFIG_SHELL_BT_NUS shell)
3333

3434
add_subdirectory(debug)

subsys/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ rsource "profiler/Kconfig"
2323

2424
rsource "spm/Kconfig"
2525

26-
rsource "fw_metadata/Kconfig"
26+
rsource "fw_info/Kconfig"
2727

2828
rsource "debug/Kconfig"
2929

0 commit comments

Comments
 (0)