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