xref: /OK3568_Linux_fs/u-boot/include/android_avb/avb_ab_ops.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 /*
26 #if !defined(AVB_INSIDE_LIBAVB_AB_H) && !defined(AVB_COMPILATION)
27 #error \
28     "Never include this file directly, include libavb_ab/libavb_ab.h instead."
29 #endif
30 */
31 
32 #ifndef AVB_AB_OPS_H_
33 #define AVB_AB_OPS_H_
34 
35 #include <android_avb/libavb.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 struct AvbABOps;
42 typedef struct AvbABOps AvbABOps;
43 
44 struct AvbABData;
45 
46 /* High-level operations/functions/methods for A/B that are platform
47  * dependent.
48  */
49 struct AvbABOps {
50   /* Operations from libavb. */
51   AvbOps* ops;
52 
53   /* Reads A/B metadata from persistent storage. Returned data is
54    * properly byteswapped. Returns AVB_IO_RESULT_OK on success, error
55    * code otherwise.
56    *
57    * If the data read is invalid (e.g. wrong magic or CRC checksum
58    * failure), the metadata shoule be reset using avb_ab_data_init()
59    * and then written to persistent storage.
60    *
61    * Implementations will typically want to use avb_ab_data_read()
62    * here to use the 'misc' partition for persistent storage.
63    */
64   AvbIOResult (*read_ab_metadata)(AvbABOps* ab_ops, struct AvbABData* data);
65 
66   /* Writes A/B metadata to persistent storage. This will byteswap and
67    * update the CRC as needed. Returns AVB_IO_RESULT_OK on success,
68    * error code otherwise.
69    *
70    * Implementations will typically want to use avb_ab_data_write()
71    * here to use the 'misc' partition for persistent storage.
72    */
73   AvbIOResult (*write_ab_metadata)(AvbABOps* ab_ops,
74                                    const struct AvbABData* data);
75 };
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif /* AVB_AB_OPS_H_ */
82