1*288bf522SAndroid Build Coastguard Worker /* 2*288bf522SAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*288bf522SAndroid Build Coastguard Worker * 4*288bf522SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*288bf522SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*288bf522SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*288bf522SAndroid Build Coastguard Worker * 8*288bf522SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*288bf522SAndroid Build Coastguard Worker * 10*288bf522SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*288bf522SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*288bf522SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*288bf522SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*288bf522SAndroid Build Coastguard Worker * limitations under the License. 15*288bf522SAndroid Build Coastguard Worker */ 16*288bf522SAndroid Build Coastguard Worker 17*288bf522SAndroid Build Coastguard Worker #ifndef BOOTINFO_H_ 18*288bf522SAndroid Build Coastguard Worker #define BOOTINFO_H_ 19*288bf522SAndroid Build Coastguard Worker 20*288bf522SAndroid Build Coastguard Worker #include <stdbool.h> 21*288bf522SAndroid Build Coastguard Worker #include <stdint.h> 22*288bf522SAndroid Build Coastguard Worker 23*288bf522SAndroid Build Coastguard Worker typedef struct BrilloSlotInfo { 24*288bf522SAndroid Build Coastguard Worker uint8_t bootable : 1; 25*288bf522SAndroid Build Coastguard Worker uint8_t reserved[3]; 26*288bf522SAndroid Build Coastguard Worker } BrilloSlotInfo; 27*288bf522SAndroid Build Coastguard Worker 28*288bf522SAndroid Build Coastguard Worker typedef struct BrilloBootInfo { 29*288bf522SAndroid Build Coastguard Worker // Used by fs_mgr. Must be NUL terminated. 30*288bf522SAndroid Build Coastguard Worker char bootctrl_suffix[4]; 31*288bf522SAndroid Build Coastguard Worker 32*288bf522SAndroid Build Coastguard Worker // Magic for identification - must be 'B', 'C', 'c' (short for 33*288bf522SAndroid Build Coastguard Worker // "boot_control copy" implementation). 34*288bf522SAndroid Build Coastguard Worker uint8_t magic[3]; 35*288bf522SAndroid Build Coastguard Worker 36*288bf522SAndroid Build Coastguard Worker // Version of BrilloBootInfo struct, must be 0 or larger. 37*288bf522SAndroid Build Coastguard Worker uint8_t version; 38*288bf522SAndroid Build Coastguard Worker 39*288bf522SAndroid Build Coastguard Worker // Currently active slot. 40*288bf522SAndroid Build Coastguard Worker uint8_t active_slot; 41*288bf522SAndroid Build Coastguard Worker 42*288bf522SAndroid Build Coastguard Worker // Information about each slot. 43*288bf522SAndroid Build Coastguard Worker BrilloSlotInfo slot_info[2]; 44*288bf522SAndroid Build Coastguard Worker 45*288bf522SAndroid Build Coastguard Worker uint8_t reserved[15]; 46*288bf522SAndroid Build Coastguard Worker } BrilloBootInfo; 47*288bf522SAndroid Build Coastguard Worker 48*288bf522SAndroid Build Coastguard Worker // Loading and saving BrillBootInfo instances. 49*288bf522SAndroid Build Coastguard Worker bool boot_info_load(BrilloBootInfo* out_info); 50*288bf522SAndroid Build Coastguard Worker bool boot_info_save(BrilloBootInfo* info); 51*288bf522SAndroid Build Coastguard Worker 52*288bf522SAndroid Build Coastguard Worker // Returns non-zero if valid. 53*288bf522SAndroid Build Coastguard Worker bool boot_info_validate(BrilloBootInfo* info); 54*288bf522SAndroid Build Coastguard Worker void boot_info_reset(BrilloBootInfo* info); 55*288bf522SAndroid Build Coastguard Worker 56*288bf522SAndroid Build Coastguard Worker // Opens partition by |name|, e.g. "misc" or "boot_a" with |flags| 57*288bf522SAndroid Build Coastguard Worker // (e.g. O_RDONLY or O_RDWR) passed directly to open(2). Returns fd on 58*288bf522SAndroid Build Coastguard Worker // success and -1 on error. 59*288bf522SAndroid Build Coastguard Worker int boot_info_open_partition(const char* name, uint64_t* out_size, int flags); 60*288bf522SAndroid Build Coastguard Worker 61*288bf522SAndroid Build Coastguard Worker #if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 62*288bf522SAndroid Build Coastguard Worker _Static_assert(sizeof(BrilloBootInfo) == 32, "BrilloBootInfo has wrong size"); 63*288bf522SAndroid Build Coastguard Worker #endif 64*288bf522SAndroid Build Coastguard Worker 65*288bf522SAndroid Build Coastguard Worker #endif // BOOTINFO_H 66