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