1180cc7c6SAlex Deymo /* 2180cc7c6SAlex Deymo * Copyright (C) 2017 The Android Open Source Project 3180cc7c6SAlex Deymo * 4180cc7c6SAlex Deymo * SPDX-License-Identifier: BSD-2-Clause 5180cc7c6SAlex Deymo */ 6180cc7c6SAlex Deymo 7180cc7c6SAlex Deymo #ifndef __ANDROID_AB_H 8180cc7c6SAlex Deymo #define __ANDROID_AB_H 9180cc7c6SAlex Deymo 10180cc7c6SAlex Deymo #include <common.h> 11180cc7c6SAlex Deymo 12180cc7c6SAlex Deymo /* Android standard boot slot names are 'a', 'b', 'c', ... */ 13180cc7c6SAlex Deymo #define ANDROID_BOOT_SLOT_NAME(slot_num) ('a' + (slot_num)) 14180cc7c6SAlex Deymo 15132e9ecaSDayao Ji #define ENUM_MERGE_STATUS_NONE (0) 16132e9ecaSDayao Ji #define ENUM_MERGE_STATUS_UNKNOWN (1) 17132e9ecaSDayao Ji #define ENUM_MERGE_STATUS_SNAPSHOTTED (2) 18132e9ecaSDayao Ji #define ENUM_MERGE_STATUS_MERGING (3) 19132e9ecaSDayao Ji #define ENUM_MERGE_STATUS_CANCELLED (4) 20132e9ecaSDayao Ji #define MISC_VIRTUAL_AB_MAGIC_HEADER (0x56740AB0) 21132e9ecaSDayao Ji 22132e9ecaSDayao Ji struct misc_virtual_ab_message { 23132e9ecaSDayao Ji u8 version; 24132e9ecaSDayao Ji u32 magic; 25132e9ecaSDayao Ji u8 merge_status; 26132e9ecaSDayao Ji u8 source_slot; 27132e9ecaSDayao Ji u8 reserved[57]; 28132e9ecaSDayao Ji u8 reserved2[448]; 29132e9ecaSDayao Ji } __packed; 30132e9ecaSDayao Ji 31180cc7c6SAlex Deymo /** android_ab_select - Select the slot where to boot from. 32180cc7c6SAlex Deymo * On Android devices with more than one boot slot (multiple copies of the 33180cc7c6SAlex Deymo * kernel and system images) selects which slot should be used to boot from and 34180cc7c6SAlex Deymo * registers the boot attempt. This is used in by the new A/B update model where 35180cc7c6SAlex Deymo * one slot is updated in the background while running from the other slot. If 36180cc7c6SAlex Deymo * the selected slot did not successfully boot in the past, a boot attempt is 37180cc7c6SAlex Deymo * registered before returning from this function so it isn't selected 38180cc7c6SAlex Deymo * indefinitely. 39180cc7c6SAlex Deymo * 40180cc7c6SAlex Deymo * @dev_desc: Place to store the device description pointer. 41180cc7c6SAlex Deymo * @part_info: Place to store the partition information. 42180cc7c6SAlex Deymo * @return the slot number (0-based) on success, or -1 on error. 43180cc7c6SAlex Deymo */ 44180cc7c6SAlex Deymo int android_ab_select(struct blk_desc *dev_desc, disk_partition_t *part_info); 45180cc7c6SAlex Deymo 46132e9ecaSDayao Ji /* Read or write the Virtual A/B message from 32KB offset in /misc.*/ 47132e9ecaSDayao Ji int read_misc_virtual_ab_message(struct misc_virtual_ab_message *message); 48132e9ecaSDayao Ji int write_misc_virtual_ab_message(struct misc_virtual_ab_message *message); 49cee2fb0eSJason Zhu 50*e99484b8SZhichao Guo void ab_update_root_partition(void); 51cee2fb0eSJason Zhu int ab_get_slot_suffix(char *slot_suffix); 52cee2fb0eSJason Zhu int ab_is_support_dynamic_partition(struct blk_desc *dev_desc); 53cee2fb0eSJason Zhu int ab_decrease_tries(void); 5466f2fdd9SJason Zhu bool ab_can_find_recovery_part(void); 55cee2fb0eSJason Zhu 56180cc7c6SAlex Deymo #endif 57