xref: /rk3399_rockchip-uboot/include/android_avb/rk_avb_ops_user.h (revision 1f25ada2a8eccef6ea3d9844a40d05d7ce7027d4)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #ifndef RK_AVB_OPS_USER_H_
8 #define RK_AVB_OPS_USER_H_
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /* rk used */
15 #define PERM_ATTR_DIGEST_SIZE 32
16 #define PERM_ATTR_TOTAL_SIZE  1052
17 #define VBOOT_KEY_HASH_SIZE   32
18 #define ANDROID_VBOOT_LOCK 0
19 #define ANDROID_VBOOT_UNLOCK 1
20 #define SLOT_NUM 2
21 #define CURR_SYSTEM_SLOT_SUFFIX "ab"
22 #define VBMETA_MAX_SIZE 65536
23 #define ROLLBACK_MAX_SIZE 20
24 #define LOCK_MASK 0x1
25 #define UNLOCK_DISABLE_MASK 0x2
26 #define VBOOT_STATE_SIZE    300
27 #define PERM_ATTR_SUCCESS_FLAG 1
28 /* soc-v use the rsa2048 */
29 #define VBOOT_KEY_SIZE   256
30 
31 /**
32  * Provided to fastboot to read how many slot in this system.
33  *
34  * @param slot_count  We use parameter slot_count to obtain
35  *                    how many slots in the system.
36  *
37  * @return 0 if the command succeeded, -1 if it failed
38  */
39 int rk_avb_read_slot_count(char *slot_count);
40 
41 /**
42  * The android things supply many slots, their name like '_a', '_b'.
43  * We can use this function to read current slot is '_a' or '_b'.
44  *
45  * @slot_suffixes  read value '_a' or '_b'.
46  *
47  * @return 0 if the command succeeded, -1 if it failed
48  */
49 int rk_avb_read_slot_suffixes(char *slot_suffixes);
50 
51 /**
52  * Use this function to set which slot boot first.
53  *
54  * @param slot_number set '0' or '1'
55  *
56  * @return 0 if the command succeeded, -1 if it failed
57  */
58 int rk_avb_set_slot_active(unsigned int *slot_number);
59 
60 /**
61  * Get current slot: '_a' or '_b'.
62  *
63  * @param select_slot  obtain current slot.
64  *
65  * @return 0 if the command succeeded, -1 if it failed
66  */
67 int rk_avb_get_current_slot(char *select_slot);
68 
69 /**
70  * The android things defines permanent attributes to
71  * store PSK_public, product id. We can use this function
72  * to read them.
73  *
74  * @param attributes  PSK_public, product id....
75  *
76  * @param size        The size of attributes.
77  *
78  * @return 0 if the command succeeded, -1 if it failed
79  */
80 int rk_avb_read_permanent_attributes(uint8_t *attributes, uint32_t size);
81 
82 /**
83  * The android things defines permanent attributes to
84  * store PSK_public, product id. We can use this function
85  * to write them.
86  *
87  * @param attributes  PSK_public, product id....
88  *
89  * @param size        The size of attributes.
90  *
91  * @return 0 if the command succeeded, -1 if it failed
92  */
93 int rk_avb_write_permanent_attributes(uint8_t *attributes, uint32_t size);
94 
95 /**
96  * The funtion can be use to read the device state to judge
97  * whether the device can be flash.
98  *
99  * @param flash_lock_state  A flag indicate the device flash state.
100  *
101  * @return 0 if the command succeeded, -1 if it failed
102  */
103 int rk_avb_read_flash_lock_state(uint8_t *flash_lock_state);
104 
105 /**
106  * The function is provided to write device flash state.
107  *
108  * @param flash_lock_state   A flag indicate the device flash state.
109  *
110  * @return 0 if the command succeeded, -1 if it failed
111  */
112 int rk_avb_write_flash_lock_state(uint8_t flash_lock_state);
113 
114 /**
115  * The android things use the flag of lock state to indicate
116  * whether the device can be booted when verified error.
117  *
118  * @param lock_state  A flag indicate the device lock state.
119  *
120  * @return 0 if the command succeeded, -1 if it failed
121  */
122 int rk_avb_read_lock_state(uint8_t *lock_state);
123 
124 /**
125  * The android things use the flag of lock state to indicate
126  * whether the device can be booted when verified error.
127  *
128  * @param lock_state   A flag indicate the device lock state.
129  *
130  * @return 0 if the command succeeded, -1 if it failed
131  */
132 int rk_avb_write_lock_state(uint8_t lock_state);
133 
134 /**
135  * The android things uses fastboot to flash the permanent attributes.
136  * And if them were written, there must have a flag to indicate.
137  *
138  * @param flag   indicate the permanent attributes have been written
139  *               or not.
140  *
141  * @return 0 if the command succeeded, -1 if it failed
142  */
143 int rk_avb_read_perm_attr_flag(uint8_t *flag);
144 
145 /**
146  * The android things uses fastboot to flash the permanent attributes.
147  * And if them were written, there must have a flag to indicate.
148  *
149  * @param flag   We can call this function to write the flag '1'
150  *               to indicate the permanent attributes has been
151  *               written.
152  *
153  * @return 0 if the command succeeded, -1 if it failed
154  */
155 int rk_avb_write_perm_attr_flag(uint8_t flag);
156 
157 /**
158  * The android things require the soc-v key hash to be flashed
159  * using the fastboot. So the function can be used in fastboot
160  * to flash the key hash.
161  *
162  * @param buf    The vboot key hash data.
163  *
164  * @param length The length of key hash.
165  *
166  * @return 0 if the command succeeded, -1 if it failed
167  */
168 int rk_avb_read_vbootkey_hash(uint8_t *buf, uint8_t length);
169 
170 /**
171  * The android things require the soc-v key hash to be flashed
172  * using the fastboot. So the function can be used in fastboot
173  * to flash the key hash.
174  *
175  * @param buf    The vboot key hash data.
176  *
177  * @param length The length of key hash.
178  *
179  * @return 0 if the command succeeded, -1 if it failed
180  */
181 int rk_avb_write_vbootkey_hash(uint8_t *buf, uint8_t length);
182 
183 /**
184  * U-boot close the optee client when start kernel
185  * to prevent the optee client being invoking by other
186  * program.
187  *
188  * @return 0 if the command succeeded, -1 if it failed
189  */
190 int rk_avb_close_optee_client(void);
191 
192 /**
193  * read the permanent attributes hash.
194  *
195  * @param buf    The permanent attributes hash data.
196  *
197  * @param length The length of permanent attributes hash.
198  *
199  * @return 0 if the command succeeded, -1 if it failed
200  */
201 int rk_avb_read_attribute_hash(uint8_t *buf, uint8_t length);
202 
203 /**
204  * Write the permanent attributes hash.
205  *
206  * @param buf    The permanent attributes hash data.
207  *
208  * @param length The length of permanent attributes hash.
209  *
210  * @return 0 if the command succeeded, -1 if it failed
211  */
212 int rk_avb_write_attribute_hash(uint8_t *buf, uint8_t length);
213 
214 /**
215  * Get the avb vboot state
216  *
217  * @param buf    store the vboot state.
218  *
219  * @return 0 if the command succeeded, -1 if it failed
220  */
221 void rk_avb_get_at_vboot_state(char *buf);
222 
223 /**
224  * Get ab information from misc partition
225  *
226  * @param ab_data    the struct of ab information
227  *
228  * @return 0 if the command succeeded, -1 if it failed
229  */
230 int rk_avb_get_ab_info(AvbABData* ab_data);
231 
232 /**
233  * Get the information whether the partition has slot
234  *
235  * @param the partition name
236  *
237  * @return 0 if the partition has slot, -1 if not
238  */
239 int rk_avb_get_part_has_slot_info(const char *base_name);
240 
241 AvbABFlowResult rk_avb_ab_slot_select(AvbABOps* ab_ops,char select_slot[]);
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif /* RK_AVB_OPS_USER_H_ */
248