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