1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 #ifndef __GBL_EFI_AB_SLOT_PROTOCOL_H__ 19 #define __GBL_EFI_AB_SLOT_PROTOCOL_H__ 20 21 #include "system_table.h" 22 #include "types.h" 23 24 typedef enum GBL_EFI_SLOT_MERGE_STATUS { 25 GBL_EFI_SLOT_MERGE_STATUS_NONE = 0, 26 GBL_EFI_SLOT_MERGE_STATUS_UNKNOWN, 27 GBL_EFI_SLOT_MERGE_STATUS_SNAPSHOTTED, 28 GBL_EFI_SLOT_MERGE_STATUS_MERGING, 29 GBL_EFI_SLOT_MERGE_STATUS_CANCELLED, 30 } GblEfiSlotMergeStatus; 31 32 typedef enum GBL_EFI_UNBOOTABLE_REASON { 33 GBL_EFI_UNKNOWN_REASON = 0, 34 GBL_EFI_NO_MORE_TRIES, 35 GBL_EFI_SYSTEM_UPDATE, 36 GBL_EFI_USER_REQUESTED, 37 GBL_EFI_VERIFICATION_FAILURE, 38 } GblEfiUnbootableReason; 39 40 // We are currently following 41 // https://cs.android.com/android/platform/superproject/main/+/main:system/core/bootstat/bootstat.cpp;l=229 42 // for boot reason code. 43 // 44 // But we may want to revisit this since GBL mostly just cares normal, 45 // bootloader, fastbootd, recovery mode. 46 typedef enum GBL_EFI_BOOT_REASON { 47 EMPTY_BOOT_REASON = 0, 48 UNKNOWN_EFI_BOOT_REASON = 1, 49 WATCHDOG = 14, 50 KERNEL_PANIC = 15, 51 RECOVERY = 3, 52 BOOTLOADER = 55, 53 COLD = 56, 54 HARD = 57, 55 WARM = 58, 56 SHUTDOWN, 57 REBOOT = 18, 58 FASTBOOTD = 196, 59 } GblEfiBootReason; 60 61 typedef struct { 62 // One UTF-8 encoded single character 63 uint32_t suffix; 64 // Any value other than those explicitly enumerated in EFI_UNBOOTABLE_REASON 65 // will be interpreted as UNKNOWN_REASON. 66 uint32_t unbootable_reason; 67 uint8_t priority; 68 uint8_t tries; 69 // Value of 1 if slot has successfully booted. 70 uint8_t successful; 71 } GblEfiSlotInfo; 72 73 typedef struct { 74 // Value of 1 if persistent metadata tracks slot unbootable reasons. 75 uint8_t unbootable_metadata; 76 uint8_t max_retries; 77 uint8_t slot_count; 78 // See GblEFiSlotMergeStatus for enum values. 79 uint8_t merge_status; 80 } GblEfiSlotMetadataBlock; 81 82 typedef struct GblEfiABSlotProtocol { 83 // Currently must contain 0x00010000 84 uint32_t version; 85 // Slot metadata query methods 86 EfiStatus (*load_boot_data)(struct GblEfiABSlotProtocol*, 87 GblEfiSlotMetadataBlock* /* out param*/); 88 EfiStatus (*get_slot_info)(struct GblEfiABSlotProtocol*, uint8_t, 89 GblEfiSlotInfo* /* out param */); 90 EfiStatus (*get_current_slot)(struct GblEfiABSlotProtocol*, 91 GblEfiSlotInfo* /* out param */); 92 EfiStatus (*get_next_slot)(struct GblEfiABSlotProtocol*, bool, 93 GblEfiSlotInfo* /* out param */); 94 // Slot metadata manipulation methods 95 EfiStatus (*set_active_slot)(struct GblEfiABSlotProtocol*, uint8_t); 96 EfiStatus (*set_slot_unbootable)(struct GblEfiABSlotProtocol*, uint8_t, 97 uint32_t); 98 EfiStatus (*reinitialize)(struct GblEfiABSlotProtocol*); 99 // Miscellaneous methods 100 EfiStatus (*get_boot_reason)(struct GblEfiABSlotProtocol*, 101 uint32_t* /* out param */, 102 size_t* /* in-out param */, 103 uint8_t* /* out param*/); 104 EfiStatus (*set_boot_reason)(struct GblEfiABSlotProtocol*, uint32_t, size_t, 105 const uint8_t*); 106 EfiStatus (*flush)(struct GblEfiABSlotProtocol*); 107 } GblEfiABSlotProtocol; 108 109 #endif // __GBL_EFI_AB_SLOT_PROTOCOL_H__ 110