forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbl_storage.h
115 lines (97 loc) · 2.86 KB
/
bl_storage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#ifndef BL_STORAGE_H_
#define BL_STORAGE_H_
#include <zephyr/types.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#define EHASHFF 113 /* A hash contains too many 0xFs. */
/** @defgroup bl_storage Bootloader storage (protected data).
* @{
*/
/**
* @brief Function for reading address of slot 0.
*
* @return Address of slot 0.
*/
uint32_t s0_address_read(void);
/**
* @brief Function for reading address of slot 1.
*
* @return Address of slot 1.
*/
uint32_t s1_address_read(void);
/**
* @brief Function for reading number of public key data slots.
*
* @return Number of public key data slots.
*/
uint32_t num_public_keys_read(void);
/**
* @brief Function for reading number of public key data slots.
*
* @retval 0 if all keys are ok
* @retval -EHASHFF if one or more keys contains an aligned 0xFFFF.
*/
int verify_public_keys(void);
/**
* @brief Function for reading public key data.
*
* @param[in] key_idx Index of key.
* @param[out] p_buf Pointer to area where key data will be stored.
* @param[in] buf_size Size of buffer, in bytes, provided in p_buf.
*
* @return Number of bytes written to p_buf is successful.
* @retval -EINVAL Key has been invalidated.
* @retval -ENOMEM The provided buffer is too small.
* @retval -EFAULT key_idx is too large. There is no key with that index.
*/
int public_key_data_read(uint32_t key_idx, uint8_t *p_buf, size_t buf_size);
/**
* @brief Function for invalidating a public key.
*
* The public key will no longer be returned by @ref public_key_data_read.
*
* @param[in] key_idx Index of key.
*/
void invalidate_public_key(uint32_t key_idx);
/**
* @brief Get the number of monotonic counter slots.
*
* @return The number of slots. If the provision page does not contain the
* information, 0 is returned.
*/
uint16_t num_monotonic_counter_slots(void);
/**
* @brief Get the current HW monotonic counter.
*
* @return The current value of the counter.
*/
uint16_t get_monotonic_counter(void);
/**
* @brief Set the current HW monotonic counter.
*
* @note FYI for users looking at the values directly in flash:
* Values are stored with their bits flipped. This is to squeeze one more
* value out of the counter.
*
* @param[in] new_counter The new counter value. Must be larger than the
* current value.
*
* @retval 0 The counter was updated successfully.
* @retval -EINVAL @p new_counter is invalid (must be larger than current
* counter, and cannot be 0xFFFF).
* @retval -ENOMEM There are no more free counter slots (see
* @option{CONFIG_SB_NUM_VER_COUNTER_SLOTS}).
*/
int set_monotonic_counter(uint16_t new_counter);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* BL_STORAGE_H_ */