15b090159SJason Zhu /* 25b090159SJason Zhu * Copyright (C) 2016 The Android Open Source Project 35b090159SJason Zhu * 45b090159SJason Zhu * Permission is hereby granted, free of charge, to any person 55b090159SJason Zhu * obtaining a copy of this software and associated documentation 65b090159SJason Zhu * files (the "Software"), to deal in the Software without 75b090159SJason Zhu * restriction, including without limitation the rights to use, copy, 85b090159SJason Zhu * modify, merge, publish, distribute, sublicense, and/or sell copies 95b090159SJason Zhu * of the Software, and to permit persons to whom the Software is 105b090159SJason Zhu * furnished to do so, subject to the following conditions: 115b090159SJason Zhu * 125b090159SJason Zhu * The above copyright notice and this permission notice shall be 135b090159SJason Zhu * included in all copies or substantial portions of the Software. 145b090159SJason Zhu * 155b090159SJason Zhu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 165b090159SJason Zhu * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 175b090159SJason Zhu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 185b090159SJason Zhu * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 195b090159SJason Zhu * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 205b090159SJason Zhu * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 215b090159SJason Zhu * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 225b090159SJason Zhu * SOFTWARE. 235b090159SJason Zhu */ 245b090159SJason 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 3137a7bc39SJason Zhu #ifdef __cplusplus 3237a7bc39SJason Zhu extern "C" { 3337a7bc39SJason Zhu #endif 34f74d184aSJason Zhu 355b090159SJason Zhu /* Allocates an AvbOps instance suitable for use in Android userspace 365b090159SJason Zhu * on the device. Returns NULL on OOM. 375b090159SJason Zhu * 385b090159SJason Zhu * The returned AvbOps has the following characteristics: 395b090159SJason Zhu * 405b090159SJason Zhu * - The read_from_partition(), write_to_partition(), and 415b090159SJason Zhu * get_size_of_partition() operations are implemented, however for 425b090159SJason Zhu * these operations to work the fstab file on the device must have a 435b090159SJason Zhu * /misc entry using a by-name device file scheme and the containing 445b090159SJason Zhu * by-name/ subdirectory must have files for other partitions. 455b090159SJason Zhu * 465b090159SJason Zhu * - The remaining operations are implemented and never fails and 475b090159SJason Zhu * return the following values: 485b090159SJason Zhu * - validate_vbmeta_public_key(): always returns |true|. 495b090159SJason Zhu * - read_rollback_index(): returns 0 for any roolback index. 505b090159SJason Zhu * - write_rollback_index(): no-op. 515b090159SJason Zhu * - read_is_device_unlocked(): always returns |true|. 525b090159SJason Zhu * - get_unique_guid_for_partition(): always returns the empty string. 535b090159SJason Zhu * 545b090159SJason Zhu * - The |ab_ops| member will point to a valid AvbABOps instance 555b090159SJason Zhu * implemented via libavb_ab/. This should only be used if the AVB 565b090159SJason Zhu * A/B stack is used on the device. This is what is used in 575b090159SJason Zhu * bootctrl.avb boot control implementation. 585b090159SJason Zhu * 595b090159SJason Zhu * Free with avb_ops_user_free(). 605b090159SJason Zhu */ 616c551138SJason Zhu AvbOps* avb_ops_user_new(void); 625b090159SJason Zhu 635b090159SJason Zhu /* Frees an AvbOps instance previously allocated with avb_ops_device_new(). */ 646c551138SJason Zhu void avb_ops_user_free(AvbOps* ops); 655b090159SJason Zhu 6648cf108aSJoseph Chen struct preloaded_partition { 6748cf108aSJoseph Chen uint8_t *addr; 6848cf108aSJoseph Chen size_t size; // 0 means the partition hasn't yet been preloaded 6948cf108aSJoseph Chen }; 7048cf108aSJoseph Chen 7148cf108aSJoseph Chen struct AvbOpsData { 7248cf108aSJoseph Chen struct AvbOps *ops; 7348cf108aSJoseph Chen const char *iface; 7448cf108aSJoseph Chen const char *devnum; 7548cf108aSJoseph Chen const char *slot_suffix; 76*be9d6521SXuhui Lin /* Record partition name(either boot or recovery) */ 77*be9d6521SXuhui Lin const char *boot_partition; 7848cf108aSJoseph Chen struct preloaded_partition boot; 7948cf108aSJoseph Chen struct preloaded_partition vendor_boot; 8048cf108aSJoseph Chen struct preloaded_partition init_boot; 8136e836f2SJoseph Chen struct preloaded_partition resource; 8248cf108aSJoseph Chen }; 8348cf108aSJoseph Chen 8437a7bc39SJason Zhu #ifdef __cplusplus 8537a7bc39SJason Zhu } 866c551138SJason Zhu #endif 8737a7bc39SJason Zhu 8837a7bc39SJason Zhu #endif /* AVB_OPS_USER_H_ */ 89