Mayank Grover | ed69920 | 2017-05-30 20:04:10 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 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 Singh | 99c3e04 | 2018-03-14 00:52:11 +0530 | [diff] [blame] | 30 | #include <err.h> |
Mayank Grover | ed69920 | 2017-05-30 20:04:10 +0530 | [diff] [blame] | 31 | |
| 32 | extern const char *suffix_slot[]; |
Mayank Grover | 6ccc1c9 | 2017-07-04 17:36:46 +0530 | [diff] [blame] | 33 | extern const char *suffix_delimiter; |
Mayank Grover | ed69920 | 2017-05-30 20:04:10 +0530 | [diff] [blame] | 34 | |
| 35 | #define SUFFIX_SLOT(part_slot) suffix_slot[(part_slot)] |
Monika Singh | 99c3e04 | 2018-03-14 00:52:11 +0530 | [diff] [blame] | 36 | #define MAX_SLOT_SUFFIX_SZ 3 |
| 37 | #define BOOT_DEV_NAME_SIZE_MAX 10 |
| 38 | |
| 39 | typedef struct { |
| 40 | char Suffix[MAX_SLOT_SUFFIX_SZ]; |
| 41 | }Slot; |
Mayank Grover | c2ccc68 | 2017-10-24 19:02:49 +0530 | [diff] [blame] | 42 | #define SET_BIT(p,n) ((p) |= ((uint64_t)0x1 << (n))) |
| 43 | #define CLR_BIT(p,n) ((p) &= (~(((uint64_t)0x1) << (n)))) |
Mayank Grover | ed69920 | 2017-05-30 20:04:10 +0530 | [diff] [blame] | 44 | |
| 45 | enum |
| 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 */ |
| 54 | struct 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) */ |
| 67 | bool partition_multislot_is_supported();/* Check Multislot is supported */ |
| 68 | bool partition_scan_for_multislot(); /* Calling to scan part. table. */ |
| 69 | void partition_mark_active_slot(); /* Marking slot active */ |
| 70 | void partition_reset_attributes(); /* Resetting slot attr. */ |
| 71 | void partition_fill_slot_meta(); /* Fill slot meta infomation */ |
| 72 | void partition_switch_slots(); /* Switching slots */ |
Mayank Grover | c2ccc68 | 2017-10-24 19:02:49 +0530 | [diff] [blame] | 73 | void partition_deactivate_slot(int slot); /* Mark slot unbootable and reset other attributes*/ |
| 74 | void partition_activate_slot(int slot); /* Mark slot bootable and set other attributes*/ |
Mayank Grover | ed69920 | 2017-05-30 20:04:10 +0530 | [diff] [blame] | 75 | int partition_find_boot_slot(); /* Find bootable partition */ |
| 76 | int partition_find_active_slot(); /* Find current active partition*/ |
| 77 | int partition_fill_partition_meta(); /* Fill partition slot info meta*/ |
| 78 | |