bootinfo.h 1.9 KB

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