1*5b090159SJason Zhu /* 2*5b090159SJason Zhu * Copyright (C) 2016 The Android Open Source Project 3*5b090159SJason Zhu * 4*5b090159SJason Zhu * Permission is hereby granted, free of charge, to any person 5*5b090159SJason Zhu * obtaining a copy of this software and associated documentation 6*5b090159SJason Zhu * files (the "Software"), to deal in the Software without 7*5b090159SJason Zhu * restriction, including without limitation the rights to use, copy, 8*5b090159SJason Zhu * modify, merge, publish, distribute, sublicense, and/or sell copies 9*5b090159SJason Zhu * of the Software, and to permit persons to whom the Software is 10*5b090159SJason Zhu * furnished to do so, subject to the following conditions: 11*5b090159SJason Zhu * 12*5b090159SJason Zhu * The above copyright notice and this permission notice shall be 13*5b090159SJason Zhu * included in all copies or substantial portions of the Software. 14*5b090159SJason Zhu * 15*5b090159SJason Zhu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16*5b090159SJason Zhu * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17*5b090159SJason Zhu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18*5b090159SJason Zhu * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19*5b090159SJason Zhu * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20*5b090159SJason Zhu * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21*5b090159SJason Zhu * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22*5b090159SJason Zhu * SOFTWARE. 23*5b090159SJason Zhu */ 24*5b090159SJason Zhu 256c551138SJason Zhu #ifndef AVB_OPS_USER_H_ 266c551138SJason Zhu #define AVB_OPS_USER_H_ 276c551138SJason Zhu 286c551138SJason Zhu #include <android_avb/libavb.h> 296c551138SJason Zhu #include <android_avb/avb_ab_flow.h> 306c551138SJason Zhu 31*5b090159SJason Zhu /* Allocates an AvbOps instance suitable for use in Android userspace 32*5b090159SJason Zhu * on the device. Returns NULL on OOM. 33*5b090159SJason Zhu * 34*5b090159SJason Zhu * The returned AvbOps has the following characteristics: 35*5b090159SJason Zhu * 36*5b090159SJason Zhu * - The read_from_partition(), write_to_partition(), and 37*5b090159SJason Zhu * get_size_of_partition() operations are implemented, however for 38*5b090159SJason Zhu * these operations to work the fstab file on the device must have a 39*5b090159SJason Zhu * /misc entry using a by-name device file scheme and the containing 40*5b090159SJason Zhu * by-name/ subdirectory must have files for other partitions. 41*5b090159SJason Zhu * 42*5b090159SJason Zhu * - The remaining operations are implemented and never fails and 43*5b090159SJason Zhu * return the following values: 44*5b090159SJason Zhu * - validate_vbmeta_public_key(): always returns |true|. 45*5b090159SJason Zhu * - read_rollback_index(): returns 0 for any roolback index. 46*5b090159SJason Zhu * - write_rollback_index(): no-op. 47*5b090159SJason Zhu * - read_is_device_unlocked(): always returns |true|. 48*5b090159SJason Zhu * - get_unique_guid_for_partition(): always returns the empty string. 49*5b090159SJason Zhu * 50*5b090159SJason Zhu * - The |ab_ops| member will point to a valid AvbABOps instance 51*5b090159SJason Zhu * implemented via libavb_ab/. This should only be used if the AVB 52*5b090159SJason Zhu * A/B stack is used on the device. This is what is used in 53*5b090159SJason Zhu * bootctrl.avb boot control implementation. 54*5b090159SJason Zhu * 55*5b090159SJason Zhu * Free with avb_ops_user_free(). 56*5b090159SJason Zhu */ 576c551138SJason Zhu AvbOps* avb_ops_user_new(void); 58*5b090159SJason Zhu 59*5b090159SJason Zhu /* Frees an AvbOps instance previously allocated with avb_ops_device_new(). */ 606c551138SJason Zhu void avb_ops_user_free(AvbOps* ops); 61*5b090159SJason Zhu 62*5b090159SJason Zhu /** 63*5b090159SJason Zhu * Provided to fastboot to read how many slot in this system. 64*5b090159SJason Zhu * 65*5b090159SJason Zhu * @param slot_count We use parameter slot_count to obtain 66*5b090159SJason Zhu * how many slots in the system. 67*5b090159SJason Zhu * 68*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 69*5b090159SJason Zhu */ 70*5b090159SJason Zhu int avb_read_slot_count(char *slot_count); 71*5b090159SJason Zhu 72*5b090159SJason Zhu /** 73*5b090159SJason Zhu * The android things supply many slots, their name like '_a', '_b'. 74*5b090159SJason Zhu * We can use this function to read current slot is '_a' or '_b'. 75*5b090159SJason Zhu * 76*5b090159SJason Zhu * @slot_suffixes read value '_a' or '_b'. 77*5b090159SJason Zhu * 78*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 79*5b090159SJason Zhu */ 80*5b090159SJason Zhu int avb_read_slot_suffixes(char *slot_suffixes); 81*5b090159SJason Zhu 82*5b090159SJason Zhu /** 83*5b090159SJason Zhu * Use this function to set which slot boot first. 84*5b090159SJason Zhu * 85*5b090159SJason Zhu * @param slot_number set '0' or '1' 86*5b090159SJason Zhu * 87*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 88*5b090159SJason Zhu */ 89*5b090159SJason Zhu int avb_set_slot_active(unsigned int *slot_number); 90*5b090159SJason Zhu 91*5b090159SJason Zhu /** 92*5b090159SJason Zhu * Get current slot: '_a' or '_b'. 93*5b090159SJason Zhu * 94*5b090159SJason Zhu * @param select_slot obtain current slot. 95*5b090159SJason Zhu * 96*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 97*5b090159SJason Zhu */ 98*5b090159SJason Zhu int avb_get_current_slot(char *select_slot); 99*5b090159SJason Zhu 100*5b090159SJason Zhu /** 101*5b090159SJason Zhu * The android things defines permanent attributes to 102*5b090159SJason Zhu * store PSK_public, product id. We can use this function 103*5b090159SJason Zhu * to read them. 104*5b090159SJason Zhu * 105*5b090159SJason Zhu * @param attributes PSK_public, product id.... 106*5b090159SJason Zhu * 107*5b090159SJason Zhu * @param size The size of attributes. 108*5b090159SJason Zhu * 109*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 110*5b090159SJason Zhu */ 111*5b090159SJason Zhu int avb_read_permanent_attributes(uint8_t *attributes, uint32_t size); 112*5b090159SJason Zhu 113*5b090159SJason Zhu /** 114*5b090159SJason Zhu * The android things defines permanent attributes to 115*5b090159SJason Zhu * store PSK_public, product id. We can use this function 116*5b090159SJason Zhu * to write them. 117*5b090159SJason Zhu * 118*5b090159SJason Zhu * @param attributes PSK_public, product id.... 119*5b090159SJason Zhu * 120*5b090159SJason Zhu * @param size The size of attributes. 121*5b090159SJason Zhu * 122*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 123*5b090159SJason Zhu */ 124*5b090159SJason Zhu int avb_write_permanent_attributes(uint8_t *attributes, uint32_t size); 125*5b090159SJason Zhu 126*5b090159SJason Zhu /** 127*5b090159SJason Zhu * The funtion can be use to read the device state to judge 128*5b090159SJason Zhu * whether the device can be flash. 129*5b090159SJason Zhu * 130*5b090159SJason Zhu * @param flash_lock_state A flag indicate the device flash state. 131*5b090159SJason Zhu * 132*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 133*5b090159SJason Zhu */ 134*5b090159SJason Zhu int avb_read_flash_lock_state(uint8_t *flash_lock_state); 135*5b090159SJason Zhu 136*5b090159SJason Zhu /** 137*5b090159SJason Zhu * The function is provided to write device flash state. 138*5b090159SJason Zhu * 139*5b090159SJason Zhu * @param flash_lock_state A flag indicate the device flash state. 140*5b090159SJason Zhu * 141*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 142*5b090159SJason Zhu */ 143*5b090159SJason Zhu int avb_write_flash_lock_state(uint8_t flash_lock_state); 144*5b090159SJason Zhu 145*5b090159SJason Zhu /** 146*5b090159SJason Zhu * The android things use the flag of lock state to indicate 147*5b090159SJason Zhu * whether the device can be booted when verified error. 148*5b090159SJason Zhu * 149*5b090159SJason Zhu * @param lock_state A flag indicate the device lock state. 150*5b090159SJason Zhu * 151*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 152*5b090159SJason Zhu */ 153*5b090159SJason Zhu int avb_read_lock_state(uint8_t *lock_state); 154*5b090159SJason Zhu 155*5b090159SJason Zhu /** 156*5b090159SJason Zhu * The android things use the flag of lock state to indicate 157*5b090159SJason Zhu * whether the device can be booted when verified error. 158*5b090159SJason Zhu * 159*5b090159SJason Zhu * @param lock_state A flag indicate the device lock state. 160*5b090159SJason Zhu * 161*5b090159SJason Zhu * @return 0 if the command succeeded, -1 if it failed 162*5b090159SJason Zhu */ 163*5b090159SJason Zhu int avb_write_lock_state(uint8_t lock_state); 1646c551138SJason Zhu 1656c551138SJason Zhu #endif 166