2struct.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. *
  5. * Data structure definitions for verified boot, for on-disk / in-eeprom
  6. * data.
  7. */
  8. #ifndef VBOOT_REFERENCE_VBOOT_2STRUCT_H_
  9. #define VBOOT_REFERENCE_VBOOT_2STRUCT_H_
  10. #include <stdint.h>
  11. #include "2crypto.h"
  12. /*
  13. * Key block flags.
  14. *
  15. *The following flags set where the key is valid. Not used by firmware
  16. * verification; only kernel verification.
  17. */
  18. #define VB2_KEY_BLOCK_FLAG_DEVELOPER_0 0x01 /* Developer switch off */
  19. #define VB2_KEY_BLOCK_FLAG_DEVELOPER_1 0x02 /* Developer switch on */
  20. #define VB2_KEY_BLOCK_FLAG_RECOVERY_0 0x04 /* Not recovery mode */
  21. #define VB2_KEY_BLOCK_FLAG_RECOVERY_1 0x08 /* Recovery mode */
  22. #define VB2_GBB_HWID_DIGEST_SIZE 32
  23. /****************************************************************************/
  24. /* Flags for vb2_shared_data.flags */
  25. enum vb2_shared_data_flags {
  26. /* User has explicitly and physically requested recovery */
  27. VB2_SD_FLAG_MANUAL_RECOVERY = (1 << 0),
  28. /* Developer mode is enabled */
  29. /* TODO: should have been VB2_SD_FLAG_DEV_MODE_ENABLED */
  30. VB2_SD_DEV_MODE_ENABLED = (1 << 1),
  31. /*
  32. * TODO: might be nice to add flags for why dev mode is enabled - via
  33. * gbb, virtual dev switch, or forced on for testing.
  34. */
  35. /* Kernel keyblock was verified by signature (not just hash) */
  36. VB2_SD_FLAG_KERNEL_SIGNED = (1 << 2),
  37. /* Software sync needs to update EC-RO, EC-RW, or PD-RW respectively */
  38. VB2_SD_FLAG_ECSYNC_EC_RO = (1 << 3),
  39. VB2_SD_FLAG_ECSYNC_EC_RW = (1 << 4),
  40. VB2_SD_FLAG_ECSYNC_PD_RW = (1 << 5),
  41. /* Software sync says EC / PD running RW */
  42. VB2_SD_FLAG_ECSYNC_EC_IN_RW = (1 << 6),
  43. VB2_SD_FLAG_ECSYNC_PD_IN_RW = (1 << 7),
  44. };
  45. /* Flags for vb2_shared_data.status */
  46. enum vb2_shared_data_status {
  47. /* Reinitialized NV data due to invalid checksum */
  48. VB2_SD_STATUS_NV_REINIT = (1 << 0),
  49. /* NV data has been initialized */
  50. VB2_SD_STATUS_NV_INIT = (1 << 1),
  51. /* Secure data initialized */
  52. VB2_SD_STATUS_SECDATA_INIT = (1 << 2),
  53. /* Chose a firmware slot */
  54. VB2_SD_STATUS_CHOSE_SLOT = (1 << 3),
  55. /* Secure data kernel version space initialized */
  56. VB2_SD_STATUS_SECDATAK_INIT = (1 << 4),
  57. };
  58. /*
  59. * Data shared between vboot API calls. Stored at the start of the work
  60. * buffer.
  61. */
  62. struct vb2_shared_data {
  63. /* Flags; see enum vb2_shared_data_flags */
  64. uint32_t flags;
  65. /* Flags from GBB header */
  66. uint32_t gbb_flags;
  67. /*
  68. * Reason we are in recovery mode this boot (enum vb2_nv_recovery), or
  69. * 0 if we aren't.
  70. */
  71. uint32_t recovery_reason;
  72. /* Firmware slot used last boot (0=A, 1=B) */
  73. uint32_t last_fw_slot;
  74. /* Result of last boot (enum vb2_fw_result) */
  75. uint32_t last_fw_result;
  76. /* Firmware slot used this boot */
  77. uint32_t fw_slot;
  78. /*
  79. * Version for this slot (top 16 bits = key, lower 16 bits = firmware).
  80. *
  81. * TODO: Make this a union to allow getting/setting those versions
  82. * separately?
  83. */
  84. uint32_t fw_version;
  85. /* Version stored in secdata (must be <= fw_version to boot). */
  86. uint32_t fw_version_secdata;
  87. /*
  88. * Status flags for this boot; see enum vb2_shared_data_status. Status
  89. * is "what we've done"; flags above are "decisions we've made".
  90. */
  91. uint32_t status;
  92. /**********************************************************************
  93. * Data from kernel verification stage.
  94. *
  95. * TODO: shouldn't be part of the main struct, since that needlessly
  96. * uses more memory during firmware verification.
  97. */
  98. /*
  99. * Version for the current kernel (top 16 bits = key, lower 16 bits =
  100. * kernel preamble).
  101. *
  102. * TODO: Make this a union to allow getting/setting those versions
  103. * separately?
  104. */
  105. uint32_t kernel_version;
  106. /* Kernel version from secdatak (must be <= kernel_version to boot) */
  107. uint32_t kernel_version_secdatak;
  108. /**********************************************************************
  109. * Temporary variables used during firmware verification. These don't
  110. * really need to persist through to the OS, but there's nowhere else
  111. * we can put them.
  112. */
  113. /* Root key offset and size from GBB header */
  114. uint32_t gbb_rootkey_offset;
  115. uint32_t gbb_rootkey_size;
  116. /* HWID digest from GBB header */
  117. uint8_t gbb_hwid_digest[VB2_GBB_HWID_DIGEST_SIZE];
  118. /* Offset of preamble from start of vblock */
  119. uint32_t vblock_preamble_offset;
  120. /*
  121. * Offset and size of packed data key in work buffer. Size is 0 if
  122. * data key is not stored in the work buffer.
  123. */
  124. uint32_t workbuf_data_key_offset;
  125. uint32_t workbuf_data_key_size;
  126. /*
  127. * Offset and size of firmware preamble in work buffer. Size is 0 if
  128. * preamble is not stored in the work buffer.
  129. */
  130. uint32_t workbuf_preamble_offset;
  131. uint32_t workbuf_preamble_size;
  132. /*
  133. * Offset and size of hash context in work buffer. Size is 0 if
  134. * hash context is not stored in the work buffer.
  135. */
  136. uint32_t workbuf_hash_offset;
  137. uint32_t workbuf_hash_size;
  138. /*
  139. * Current tag we're hashing
  140. *
  141. * For new structs, this is the offset of the vb2_signature struct
  142. * in the work buffer.
  143. *
  144. * TODO: rename to workbuf_hash_sig_offset when vboot1 structs are
  145. * deprecated.
  146. */
  147. uint32_t hash_tag;
  148. /* Amount of data we still expect to hash */
  149. uint32_t hash_remaining_size;
  150. /**********************************************************************
  151. * Temporary variables used during kernel verification. These don't
  152. * really need to persist through to the OS, but there's nowhere else
  153. * we can put them.
  154. *
  155. * TODO: make a union with the firmware verification temp variables,
  156. * or make both of them workbuf-allocated sub-structs, so that we can
  157. * overlap them so kernel variables don't bloat firmware verification
  158. * stage memory requirements.
  159. */
  160. /*
  161. * Offset and size of packed kernel key in work buffer. Size is 0 if
  162. * subkey is not stored in the work buffer. Note that kernel key may
  163. * be inside the firmware preamble.
  164. */
  165. uint32_t workbuf_kernel_key_offset;
  166. uint32_t workbuf_kernel_key_size;
  167. } __attribute__((packed));
  168. /****************************************************************************/
  169. /* Signature at start of the GBB
  170. * Note that if you compile in the signature as is, you are likely to break any
  171. * tools that search for the signature. */
  172. #define VB2_GBB_SIGNATURE "$GBB"
  173. #define VB2_GBB_SIGNATURE_SIZE 4
  174. #define VB2_GBB_XOR_CHARS "****"
  175. /* TODO: can we write a macro to produce this at compile time? */
  176. #define VB2_GBB_XOR_SIGNATURE { 0x0e, 0x6d, 0x68, 0x68 }
  177. /* VB2 GBB struct version */
  178. #define VB2_GBB_MAJOR_VER 1
  179. #define VB2_GBB_MINOR_VER 2
  180. /* v1.2 - added fields for sha256 digest of the HWID */
  181. /* Flags for vb2_gbb_header.flags */
  182. enum vb2_gbb_flag {
  183. /*
  184. * Reduce the dev screen delay to 2 sec from 30 sec to speed up
  185. * factory.
  186. */
  187. VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY = (1 << 0),
  188. /*
  189. * BIOS should load option ROMs from arbitrary PCI devices. We'll never
  190. * enable this ourselves because it executes non-verified code, but if
  191. * a customer wants to void their warranty and set this flag in the
  192. * read-only flash, they should be able to do so.
  193. *
  194. * (TODO: Currently not supported. Mark as deprecated/unused?)
  195. */
  196. VB2_GBB_FLAG_LOAD_OPTION_ROMS = (1 << 1),
  197. /*
  198. * The factory flow may need the BIOS to boot a non-ChromeOS kernel if
  199. * the dev-switch is on. This flag allows that.
  200. *
  201. * (TODO: Currently not supported. Mark as deprecated/unused?)
  202. */
  203. VB2_GBB_FLAG_ENABLE_ALTERNATE_OS = (1 << 2),
  204. /*
  205. * Force dev switch on, regardless of physical/keyboard dev switch
  206. * position.
  207. */
  208. VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON = (1 << 3),
  209. /* Allow booting from USB in dev mode even if dev_boot_usb=0. */
  210. VB2_GBB_FLAG_FORCE_DEV_BOOT_USB = (1 << 4),
  211. /* Disable firmware rollback protection. */
  212. VB2_GBB_FLAG_DISABLE_FW_ROLLBACK_CHECK = (1 << 5),
  213. /* Allow Enter key to trigger dev->tonorm screen transition */
  214. VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM = (1 << 6),
  215. /* Allow booting Legacy OSes in dev mode even if dev_boot_legacy=0. */
  216. VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY = (1 << 7),
  217. /* Allow booting using alternate keys for FAFT servo testing */
  218. VB2_GBB_FLAG_FAFT_KEY_OVERIDE = (1 << 8),
  219. /* Disable EC software sync */
  220. VB2_GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC = (1 << 9),
  221. /* Default to booting legacy OS when dev screen times out */
  222. VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY = (1 << 10),
  223. /* Disable PD software sync */
  224. VB2_GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC = (1 << 11),
  225. /* Disable shutdown on lid closed */
  226. VB2_GBB_FLAG_DISABLE_LID_SHUTDOWN = (1 << 12),
  227. /*
  228. * Allow full fastboot capability in firmware even if
  229. * dev_boot_fastboot_full_cap=0.
  230. */
  231. VB2_GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP = (1 << 13),
  232. /* Enable serial */
  233. VB2_GBB_FLAG_ENABLE_SERIAL = (1 << 14),
  234. };
  235. struct vb2_gbb_header {
  236. /* Fields present in version 1.1 */
  237. uint8_t signature[VB2_GBB_SIGNATURE_SIZE]; /* VB2_GBB_SIGNATURE */
  238. uint16_t major_version; /* See VB2_GBB_MAJOR_VER */
  239. uint16_t minor_version; /* See VB2_GBB_MINOR_VER */
  240. uint32_t header_size; /* Size of GBB header in bytes */
  241. uint32_t flags; /* Flags (see enum vb2_gbb_flag) */
  242. /* Offsets (from start of header) and sizes (in bytes) of components */
  243. uint32_t hwid_offset; /* HWID */
  244. uint32_t hwid_size;
  245. uint32_t rootkey_offset; /* Root key */
  246. uint32_t rootkey_size;
  247. uint32_t bmpfv_offset; /* BMP FV */
  248. uint32_t bmpfv_size;
  249. uint32_t recovery_key_offset; /* Recovery key */
  250. uint32_t recovery_key_size;
  251. /* Added in version 1.2 */
  252. uint8_t hwid_digest[VB2_GBB_HWID_DIGEST_SIZE]; /* SHA-256 of HWID */
  253. /* Pad to match EXPECETED_VB2_GBB_HEADER_SIZE. Initialize to 0. */
  254. uint8_t pad[48];
  255. } __attribute__((packed));
  256. /* The GBB is used outside of vboot_reference, so this size is important. */
  257. #define EXPECTED_VB2_GBB_HEADER_SIZE 128
  258. /*
  259. * Root key hash for Ryu devices only. Contains the hash of the root key.
  260. * This will be embedded somewhere inside the RO part of the firmware, so that
  261. * it can verify the GBB contains only the official root key.
  262. */
  263. #define RYU_ROOT_KEY_HASH_MAGIC "RtKyHash"
  264. #define RYU_ROOT_KEY_HASH_MAGIC_INVCASE "rTkYhASH"
  265. #define RYU_ROOT_KEY_HASH_MAGIC_SIZE 8
  266. #define RYU_ROOT_KEY_HASH_VERSION_MAJOR 1
  267. #define RYU_ROOT_KEY_HASH_VERSION_MINOR 0
  268. struct vb2_ryu_root_key_hash {
  269. /* Magic number (RYU_ROOT_KEY_HASH_MAGIC) */
  270. uint8_t magic[RYU_ROOT_KEY_HASH_MAGIC_SIZE];
  271. /* Version of this struct */
  272. uint16_t header_version_major;
  273. uint16_t header_version_minor;
  274. /*
  275. * Length of this struct, in bytes, including any variable length data
  276. * which follows (there is none, yet).
  277. */
  278. uint32_t struct_size;
  279. /*
  280. * SHA-256 hash digest of the entire root key section from the GBB. If
  281. * all 0 bytes, all root keys will be treated as if matching.
  282. */
  283. uint8_t root_key_hash_digest[32];
  284. };
  285. #define EXPECTED_VB2_RYU_ROOT_KEY_HASH_SIZE 48
  286. #endif /* VBOOT_REFERENCE_VBOOT_2STRUCT_H_ */