2nvstorage.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. * Non-volatile storage routines
  6. */
  7. #ifndef VBOOT_REFERENCE_VBOOT_2NVSTORAGE_H_
  8. #define VBOOT_REFERENCE_VBOOT_2NVSTORAGE_H_
  9. enum vb2_nv_param {
  10. /*
  11. * Parameter values have been reset to defaults (flag for firmware).
  12. * 0=clear; 1=set.
  13. */
  14. VB2_NV_FIRMWARE_SETTINGS_RESET = 0,
  15. /*
  16. * Parameter values have been reset to defaults (flag for kernel).
  17. * 0=clear; 1=set.
  18. */
  19. VB2_NV_KERNEL_SETTINGS_RESET,
  20. /* Request debug reset on next S3->S0 transition. 0=clear; 1=set. */
  21. VB2_NV_DEBUG_RESET_MODE,
  22. /* Firmware slot to try next. 0=A, 1=B */
  23. VB2_NV_TRY_NEXT,
  24. /*
  25. * Number of times to try booting RW firmware slot B before slot A.
  26. * Valid range: 0-15.
  27. *
  28. * For VB2, number of times to try booting the slot indicated by
  29. * VB2_NV_TRY_NEXT. On a 1->0 transition of try count, VB2_NV_TRY_NEXT
  30. * will be set to the other slot.
  31. */
  32. VB2_NV_TRY_COUNT,
  33. /*
  34. * Request recovery mode on next boot; see 2recovery_reason.h for
  35. * currently defined reason codes. 8-bit value.
  36. */
  37. VB2_NV_RECOVERY_REQUEST,
  38. /*
  39. * Localization index for screen bitmaps displayed by firmware.
  40. * 8-bit value.
  41. */
  42. VB2_NV_LOCALIZATION_INDEX,
  43. /* Field reserved for kernel/user-mode use; 32-bit value. */
  44. VB2_NV_KERNEL_FIELD,
  45. /* Allow booting from USB in developer mode. 0=no, 1=yes. */
  46. VB2_NV_DEV_BOOT_USB,
  47. /* Allow booting of legacy OSes in developer mode. 0=no, 1=yes. */
  48. VB2_NV_DEV_BOOT_LEGACY,
  49. /* Only boot Google-signed images in developer mode. 0=no, 1=yes. */
  50. VB2_NV_DEV_BOOT_SIGNED_ONLY,
  51. /*
  52. * Allow full fastboot capability in firmware in developer mode.
  53. * 0=no, 1=yes.
  54. */
  55. VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP,
  56. /* Set default boot mode (see vb2_dev_default_boot) */
  57. VB2_NV_DEV_DEFAULT_BOOT,
  58. /*
  59. * Set by userspace to request that RO firmware disable dev-mode on the
  60. * next boot. This is likely only possible if the dev-switch is
  61. * virtual.
  62. */
  63. VB2_NV_DISABLE_DEV_REQUEST,
  64. /*
  65. * Set and cleared by vboot to request that the video Option ROM be
  66. * loaded at boot time, so that BIOS screens can be displayed. 0=no,
  67. * 1=yes.
  68. */
  69. VB2_NV_OPROM_NEEDED,
  70. /* Request that the firmware clear the TPM owner on the next boot. */
  71. VB2_NV_CLEAR_TPM_OWNER_REQUEST,
  72. /* Flag that TPM owner was cleared on request. */
  73. VB2_NV_CLEAR_TPM_OWNER_DONE,
  74. /* TPM requested a reboot already. */
  75. VB2_NV_TPM_REQUESTED_REBOOT,
  76. /* More details on recovery reason */
  77. VB2_NV_RECOVERY_SUBCODE,
  78. /* Request that NVRAM be backed up at next boot if possible. */
  79. VB2_NV_BACKUP_NVRAM_REQUEST,
  80. /* Firmware slot tried this boot (0=A, 1=B) */
  81. VB2_NV_FW_TRIED,
  82. /* Result of trying that firmware (see vb2_fw_result) */
  83. VB2_NV_FW_RESULT,
  84. /* Firmware slot tried previous boot (0=A, 1=B) */
  85. VB2_NV_FW_PREV_TRIED,
  86. /* Result of trying that firmware (see vb2_fw_result) */
  87. VB2_NV_FW_PREV_RESULT,
  88. /* Request wipeout of the device by the app. */
  89. VB2_NV_REQ_WIPEOUT,
  90. /* Fastboot: Unlock in firmware, 0=disabled, 1=enabled. */
  91. VB2_NV_FASTBOOT_UNLOCK_IN_FW,
  92. /* Boot system when AC detected (0=no, 1=yes). */
  93. VB2_NV_BOOT_ON_AC_DETECT,
  94. /* Try to update the EC-RO image after updating the EC-RW image(0=no, 1=yes). */
  95. VB2_NV_TRY_RO_SYNC,
  96. /* Cut off battery and shutdown on next boot. */
  97. VB2_NV_BATTERY_CUTOFF_REQUEST,
  98. };
  99. /* Set default boot in developer mode */
  100. enum vb2_dev_default_boot {
  101. /* Default to boot from disk*/
  102. VB2_DEV_DEFAULT_BOOT_DISK = 0,
  103. /* Default to boot from USB */
  104. VB2_DEV_DEFAULT_BOOT_USB= 1,
  105. /* Default to boot legacy OS */
  106. VB2_DEV_DEFAULT_BOOT_LEGACY = 2,
  107. };
  108. /* Firmware result codes for VB2_NV_FW_RESULT and VB2_NV_FW_PREV_RESULT */
  109. enum vb2_fw_result {
  110. /* Unknown */
  111. VB2_FW_RESULT_UNKNOWN = 0,
  112. /* Trying a new slot, but haven't reached success/failure */
  113. VB2_FW_RESULT_TRYING = 1,
  114. /* Successfully booted to the OS */
  115. VB2_FW_RESULT_SUCCESS = 2,
  116. /* Known failure */
  117. VB2_FW_RESULT_FAILURE = 3,
  118. };
  119. /**
  120. * Check the CRC of the non-volatile storage context.
  121. *
  122. * Use this if reading from non-volatile storage may be flaky, and you want to
  123. * retry reading it several times.
  124. *
  125. * This may be called before vb2_context_init().
  126. *
  127. * @param ctx Context pointer
  128. * @return VB2_SUCCESS, or non-zero error code if error.
  129. */
  130. int vb2_nv_check_crc(const struct vb2_context *ctx);
  131. /**
  132. * Initialize the non-volatile storage context and verify its CRC.
  133. *
  134. * @param ctx Context pointer
  135. */
  136. void vb2_nv_init(struct vb2_context *ctx);
  137. /**
  138. * Read a non-volatile value.
  139. *
  140. * @param ctx Context pointer
  141. * @param param Parameter to read
  142. * @return The value of the parameter. If you somehow force an invalid
  143. * parameter number, returns 0.
  144. */
  145. uint32_t vb2_nv_get(struct vb2_context *ctx, enum vb2_nv_param param);
  146. /**
  147. * Write a non-volatile value.
  148. *
  149. * Ignores writes to unknown params.
  150. *
  151. * @param ctx Context pointer
  152. * @param param Parameter to write
  153. * @param value New value
  154. */
  155. void vb2_nv_set(struct vb2_context *ctx,
  156. enum vb2_nv_param param,
  157. uint32_t value);
  158. #endif /* VBOOT_REFERENCE_VBOOT_2NVSTORAGE_H_ */