1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright (C) 2017 The Android Open Source Project 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * SPDX-License-Identifier: BSD-2-Clause 5*4882a593Smuzhiyun */ 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun #ifndef __ANDROID_AB_H 8*4882a593Smuzhiyun #define __ANDROID_AB_H 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #include <common.h> 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun /* Android standard boot slot names are 'a', 'b', 'c', ... */ 13*4882a593Smuzhiyun #define ANDROID_BOOT_SLOT_NAME(slot_num) ('a' + (slot_num)) 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun #define ENUM_MERGE_STATUS_NONE (0) 16*4882a593Smuzhiyun #define ENUM_MERGE_STATUS_UNKNOWN (1) 17*4882a593Smuzhiyun #define ENUM_MERGE_STATUS_SNAPSHOTTED (2) 18*4882a593Smuzhiyun #define ENUM_MERGE_STATUS_MERGING (3) 19*4882a593Smuzhiyun #define ENUM_MERGE_STATUS_CANCELLED (4) 20*4882a593Smuzhiyun #define MISC_VIRTUAL_AB_MAGIC_HEADER (0x56740AB0) 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun struct misc_virtual_ab_message { 23*4882a593Smuzhiyun u8 version; 24*4882a593Smuzhiyun u32 magic; 25*4882a593Smuzhiyun u8 merge_status; 26*4882a593Smuzhiyun u8 source_slot; 27*4882a593Smuzhiyun u8 reserved[57]; 28*4882a593Smuzhiyun u8 reserved2[448]; 29*4882a593Smuzhiyun } __packed; 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun /** android_ab_select - Select the slot where to boot from. 32*4882a593Smuzhiyun * On Android devices with more than one boot slot (multiple copies of the 33*4882a593Smuzhiyun * kernel and system images) selects which slot should be used to boot from and 34*4882a593Smuzhiyun * registers the boot attempt. This is used in by the new A/B update model where 35*4882a593Smuzhiyun * one slot is updated in the background while running from the other slot. If 36*4882a593Smuzhiyun * the selected slot did not successfully boot in the past, a boot attempt is 37*4882a593Smuzhiyun * registered before returning from this function so it isn't selected 38*4882a593Smuzhiyun * indefinitely. 39*4882a593Smuzhiyun * 40*4882a593Smuzhiyun * @dev_desc: Place to store the device description pointer. 41*4882a593Smuzhiyun * @part_info: Place to store the partition information. 42*4882a593Smuzhiyun * @return the slot number (0-based) on success, or -1 on error. 43*4882a593Smuzhiyun */ 44*4882a593Smuzhiyun int android_ab_select(struct blk_desc *dev_desc, disk_partition_t *part_info); 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun /* Read or write the Virtual A/B message from 32KB offset in /misc.*/ 47*4882a593Smuzhiyun int read_misc_virtual_ab_message(struct misc_virtual_ab_message *message); 48*4882a593Smuzhiyun int write_misc_virtual_ab_message(struct misc_virtual_ab_message *message); 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun void ab_update_root_partition(void); 51*4882a593Smuzhiyun int ab_get_slot_suffix(char *slot_suffix); 52*4882a593Smuzhiyun int ab_is_support_dynamic_partition(struct blk_desc *dev_desc); 53*4882a593Smuzhiyun int ab_decrease_tries(void); 54*4882a593Smuzhiyun bool ab_can_find_recovery_part(void); 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun #endif 57