blob: 2001b7f4d1fa9a80e2e91ea25f7c715f32a11da6 [file] [log] [blame]
Mayank Grovered699202017-05-30 20:04:10 +05301/*
lijuang165fcbb2019-07-05 17:50:06 +08002 * Copyright (c) 2017, 2019, The Linux Foundation. All rights reserved.
Mayank Grovered699202017-05-30 20:04:10 +05303 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of The Linux Foundation nor
12 * the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written
14 * permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29#include <fastboot.h>
Monika Singh99c3e042018-03-14 00:52:11 +053030#include <err.h>
Mayank Grovered699202017-05-30 20:04:10 +053031
32extern const char *suffix_slot[];
Mayank Grover6ccc1c92017-07-04 17:36:46 +053033extern const char *suffix_delimiter;
Mayank Grovered699202017-05-30 20:04:10 +053034
35#define SUFFIX_SLOT(part_slot) suffix_slot[(part_slot)]
Monika Singh99c3e042018-03-14 00:52:11 +053036#define MAX_SLOT_SUFFIX_SZ 3
37#define BOOT_DEV_NAME_SIZE_MAX 10
38
39typedef struct {
40 char Suffix[MAX_SLOT_SUFFIX_SZ];
41}Slot;
Mayank Groverc2ccc682017-10-24 19:02:49 +053042#define SET_BIT(p,n) ((p) |= ((uint64_t)0x1 << (n)))
43#define CLR_BIT(p,n) ((p) &= (~(((uint64_t)0x1) << (n))))
Mayank Grovered699202017-05-30 20:04:10 +053044
45enum
46{
47 SLOT_A = 0,
48 SLOT_B = 1,
49 AB_SUPPORTED_SLOTS = 2,
50 INVALID = -1
51};
52
53/* Structure to print get var info */
54struct ab_slot_info
55{
56 char slot_is_unbootable[MAX_GET_VAR_NAME_SIZE];
57 char slot_is_unbootable_rsp[MAX_RSP_SIZE];
58 char slot_is_active[MAX_GET_VAR_NAME_SIZE];
59 char slot_is_active_rsp[MAX_RSP_SIZE];
60 char slot_is_succesful[MAX_GET_VAR_NAME_SIZE];
61 char slot_is_succesful_rsp[MAX_RSP_SIZE];
62 char slot_retry_count[MAX_GET_VAR_NAME_SIZE];
63 char slot_retry_count_rsp[MAX_RSP_SIZE];
64};
65
66/* A/B support API(s) */
67bool partition_multislot_is_supported();/* Check Multislot is supported */
68bool partition_scan_for_multislot(); /* Calling to scan part. table. */
69void partition_mark_active_slot(); /* Marking slot active */
70void partition_reset_attributes(); /* Resetting slot attr. */
71void partition_fill_slot_meta(); /* Fill slot meta infomation */
lijuang165fcbb2019-07-05 17:50:06 +080072void partition_switch_slots(int old_slot, int new_slot, boolean reset_success_bit); /* Switching slots */
Mayank Groverc2ccc682017-10-24 19:02:49 +053073void partition_deactivate_slot(int slot); /* Mark slot unbootable and reset other attributes*/
74void partition_activate_slot(int slot); /* Mark slot bootable and set other attributes*/
Mayank Grovered699202017-05-30 20:04:10 +053075int partition_find_boot_slot(); /* Find bootable partition */
76int partition_find_active_slot(); /* Find current active partition*/
77int partition_fill_partition_meta(); /* Fill partition slot info meta*/
78