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 #ifndef AVB_OPS_USER_H_ 26 #define AVB_OPS_USER_H_ 27 28 #include <android_avb/libavb.h> 29 #include <android_avb/avb_ab_flow.h> 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* Allocates an AvbOps instance suitable for use in Android userspace 36 * on the device. Returns NULL on OOM. 37 * 38 * The returned AvbOps has the following characteristics: 39 * 40 * - The read_from_partition(), write_to_partition(), and 41 * get_size_of_partition() operations are implemented, however for 42 * these operations to work the fstab file on the device must have a 43 * /misc entry using a by-name device file scheme and the containing 44 * by-name/ subdirectory must have files for other partitions. 45 * 46 * - The remaining operations are implemented and never fails and 47 * return the following values: 48 * - validate_vbmeta_public_key(): always returns |true|. 49 * - read_rollback_index(): returns 0 for any roolback index. 50 * - write_rollback_index(): no-op. 51 * - read_is_device_unlocked(): always returns |true|. 52 * - get_unique_guid_for_partition(): always returns the empty string. 53 * 54 * - The |ab_ops| member will point to a valid AvbABOps instance 55 * implemented via libavb_ab/. This should only be used if the AVB 56 * A/B stack is used on the device. This is what is used in 57 * bootctrl.avb boot control implementation. 58 * 59 * Free with avb_ops_user_free(). 60 */ 61 AvbOps* avb_ops_user_new(void); 62 63 /* Frees an AvbOps instance previously allocated with avb_ops_device_new(). */ 64 void avb_ops_user_free(AvbOps* ops); 65 66 struct preloaded_partition { 67 uint8_t *addr; 68 size_t size; // 0 means the partition hasn't yet been preloaded 69 }; 70 71 struct AvbOpsData { 72 struct AvbOps *ops; 73 const char *iface; 74 const char *devnum; 75 const char *slot_suffix; 76 struct preloaded_partition boot; 77 struct preloaded_partition vendor_boot; 78 struct preloaded_partition init_boot; 79 struct preloaded_partition resource; 80 }; 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif /* AVB_OPS_USER_H_ */ 87