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 /* Allocates an AvbOps instance suitable for use in Android userspace 32 * on the device. Returns NULL on OOM. 33 * 34 * The returned AvbOps has the following characteristics: 35 * 36 * - The read_from_partition(), write_to_partition(), and 37 * get_size_of_partition() operations are implemented, however for 38 * these operations to work the fstab file on the device must have a 39 * /misc entry using a by-name device file scheme and the containing 40 * by-name/ subdirectory must have files for other partitions. 41 * 42 * - The remaining operations are implemented and never fails and 43 * return the following values: 44 * - validate_vbmeta_public_key(): always returns |true|. 45 * - read_rollback_index(): returns 0 for any roolback index. 46 * - write_rollback_index(): no-op. 47 * - read_is_device_unlocked(): always returns |true|. 48 * - get_unique_guid_for_partition(): always returns the empty string. 49 * 50 * - The |ab_ops| member will point to a valid AvbABOps instance 51 * implemented via libavb_ab/. This should only be used if the AVB 52 * A/B stack is used on the device. This is what is used in 53 * bootctrl.avb boot control implementation. 54 * 55 * Free with avb_ops_user_free(). 56 */ 57 AvbOps* avb_ops_user_new(void); 58 59 /* Frees an AvbOps instance previously allocated with avb_ops_device_new(). */ 60 void avb_ops_user_free(AvbOps* ops); 61 62 /** 63 * Provided to fastboot to read how many slot in this system. 64 * 65 * @param slot_count We use parameter slot_count to obtain 66 * how many slots in the system. 67 * 68 * @return 0 if the command succeeded, -1 if it failed 69 */ 70 int avb_read_slot_count(char *slot_count); 71 72 /** 73 * The android things supply many slots, their name like '_a', '_b'. 74 * We can use this function to read current slot is '_a' or '_b'. 75 * 76 * @slot_suffixes read value '_a' or '_b'. 77 * 78 * @return 0 if the command succeeded, -1 if it failed 79 */ 80 int avb_read_slot_suffixes(char *slot_suffixes); 81 82 /** 83 * Use this function to set which slot boot first. 84 * 85 * @param slot_number set '0' or '1' 86 * 87 * @return 0 if the command succeeded, -1 if it failed 88 */ 89 int avb_set_slot_active(unsigned int *slot_number); 90 91 /** 92 * Get current slot: '_a' or '_b'. 93 * 94 * @param select_slot obtain current slot. 95 * 96 * @return 0 if the command succeeded, -1 if it failed 97 */ 98 int avb_get_current_slot(char *select_slot); 99 100 /** 101 * The android things defines permanent attributes to 102 * store PSK_public, product id. We can use this function 103 * to read them. 104 * 105 * @param attributes PSK_public, product id.... 106 * 107 * @param size The size of attributes. 108 * 109 * @return 0 if the command succeeded, -1 if it failed 110 */ 111 int avb_read_permanent_attributes(uint8_t *attributes, uint32_t size); 112 113 /** 114 * The android things defines permanent attributes to 115 * store PSK_public, product id. We can use this function 116 * to write them. 117 * 118 * @param attributes PSK_public, product id.... 119 * 120 * @param size The size of attributes. 121 * 122 * @return 0 if the command succeeded, -1 if it failed 123 */ 124 int avb_write_permanent_attributes(uint8_t *attributes, uint32_t size); 125 126 /** 127 * The funtion can be use to read the device state to judge 128 * whether the device can be flash. 129 * 130 * @param flash_lock_state A flag indicate the device flash state. 131 * 132 * @return 0 if the command succeeded, -1 if it failed 133 */ 134 int avb_read_flash_lock_state(uint8_t *flash_lock_state); 135 136 /** 137 * The function is provided to write device flash state. 138 * 139 * @param flash_lock_state A flag indicate the device flash state. 140 * 141 * @return 0 if the command succeeded, -1 if it failed 142 */ 143 int avb_write_flash_lock_state(uint8_t flash_lock_state); 144 145 /** 146 * The android things use the flag of lock state to indicate 147 * whether the device can be booted when verified error. 148 * 149 * @param lock_state A flag indicate the device lock state. 150 * 151 * @return 0 if the command succeeded, -1 if it failed 152 */ 153 int avb_read_lock_state(uint8_t *lock_state); 154 155 /** 156 * The android things use the flag of lock state to indicate 157 * whether the device can be booted when verified error. 158 * 159 * @param lock_state A flag indicate the device lock state. 160 * 161 * @return 0 if the command succeeded, -1 if it failed 162 */ 163 int avb_write_lock_state(uint8_t lock_state); 164 165 #endif 166