1/*
2 * Copyright (C) 2015 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#ifndef BOOTINFO_H_
18#define BOOTINFO_H_
19
20#include <stdint.h>
21#include <stdbool.h>
22
23typedef struct BrilloSlotInfo {
24  uint8_t bootable : 1;
25  uint8_t reserved[3];
26} BrilloSlotInfo;
27
28typedef struct BrilloBootInfo {
29  // Used by fs_mgr. Must be NUL terminated.
30  char bootctrl_suffix[4];
31
32  // Magic for identification - must be 'B', 'C', 'c' (short for
33  // "boot_control copy" implementation).
34  uint8_t magic[3];
35
36  // Version of BrilloBootInfo struct, must be 0 or larger.
37  uint8_t version;
38
39  // Currently active slot.
40  uint8_t active_slot;
41
42  // Information about each slot.
43  BrilloSlotInfo slot_info[2];
44
45  uint8_t reserved[15];
46} BrilloBootInfo;
47
48// Loading and saving BrillBootInfo instances.
49bool boot_info_load(BrilloBootInfo *out_info);
50bool boot_info_save(BrilloBootInfo *info);
51
52// Returns non-zero if valid.
53bool boot_info_validate(BrilloBootInfo* info);
54void boot_info_reset(BrilloBootInfo* info);
55
56// Opens partition by |name|, e.g. "misc" or "boot_a" with |flags|
57// (e.g. O_RDONLY or O_RDWR) passed directly to open(2). Returns fd on
58// success and -1 on error.
59int boot_info_open_partition(const char *name, uint64_t *out_size, int flags);
60
61#if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
62_Static_assert(sizeof(BrilloBootInfo) == 32, "BrilloBootInfo has wrong size");
63#endif
64
65#endif  // BOOTINFO_H
66