bloblist.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * This provides a standard way of passing information between boot phases
  4. * (TPL -> SPL -> U-Boot proper.)
  5. *
  6. * A list of blobs of data, tagged with their owner. The list resides in memory
  7. * and can be updated by SPL, U-Boot, etc.
  8. *
  9. * Copyright 2018 Google, Inc
  10. * Written by Simon Glass <sjg@chromium.org>
  11. */
  12. #ifndef __BLOBLIST_H
  13. #define __BLOBLIST_H
  14. enum {
  15. BLOBLIST_VERSION = 0,
  16. BLOBLIST_MAGIC = 0xb00757a3,
  17. BLOBLIST_ALIGN = 16,
  18. };
  19. /* Supported tags - add new ones to tag_name in bloblist.c */
  20. enum bloblist_tag_t {
  21. BLOBLISTT_NONE = 0,
  22. /* Vendor-specific tags are permitted here */
  23. BLOBLISTT_EC_HOSTEVENT, /* Chromium OS EC host-event mask */
  24. BLOBLISTT_SPL_HANDOFF, /* Hand-off info from SPL */
  25. BLOBLISTT_VBOOT_CTX, /* Chromium OS verified boot context */
  26. BLOBLISTT_VBOOT_HANDOFF, /* Chromium OS internal handoff info */
  27. /*
  28. * Advanced Configuration and Power Interface Global Non-Volatile
  29. * Sleeping table. This forms part of the ACPI tables passed to Linux.
  30. */
  31. BLOBLISTT_ACPI_GNVS,
  32. BLOBLISTT_INTEL_VBT, /* Intel Video-BIOS table */
  33. BLOBLISTT_TPM2_TCG_LOG, /* TPM v2 log space */
  34. BLOBLISTT_TCPA_LOG, /* TPM log space */
  35. BLOBLISTT_ACPI_TABLES, /* ACPI tables for x86 */
  36. BLOBLISTT_SMBIOS_TABLES, /* SMBIOS tables for x86 */
  37. BLOBLISTT_COUNT
  38. };
  39. /**
  40. * struct bloblist_hdr - header for the bloblist
  41. *
  42. * This is stored at the start of the bloblist which is always on a 16-byte
  43. * boundary. Records follow this header. The bloblist normally stays in the
  44. * same place in memory as SPL and U-Boot execute, but it can be safely moved
  45. * around.
  46. *
  47. * None of the bloblist structures contain pointers but it is possible to put
  48. * pointers inside a bloblist record if desired. This is not encouraged,
  49. * since it can make part of the bloblist inaccessible if the pointer is
  50. * no-longer valid. It is better to just store all the data inside a bloblist
  51. * record.
  52. *
  53. * Each bloblist record is aligned to a 16-byte boundary and follows immediately
  54. * from the last.
  55. *
  56. * @version: BLOBLIST_VERSION
  57. * @hdr_size: Size of this header, normally sizeof(struct bloblist_hdr). The
  58. * first bloblist_rec starts at this offset from the start of the header
  59. * @flags: Space for BLOBLISTF_... flags (none yet)
  60. * @magic: BLOBLIST_MAGIC
  61. * @size: Total size of all records (non-zero if valid) including this header.
  62. * The bloblist extends for this many bytes from the start of this header.
  63. * @alloced: Total size allocated for this bloblist. When adding new records,
  64. * the bloblist can grow up to this size. This starts out as
  65. * sizeof(bloblist_hdr) since we need at least that much space to store a
  66. * valid bloblist
  67. * @spare: Spare space (for future use)
  68. * @chksum: CRC32 for the entire bloblist allocated area. Since any of the
  69. * blobs can be altered after being created, this checksum is only valid
  70. * when the bloblist is finalised before jumping to the next stage of boot.
  71. * Note: @chksum is last to make it easier to exclude it from the checksum
  72. * calculation.
  73. */
  74. struct bloblist_hdr {
  75. u32 version;
  76. u32 hdr_size;
  77. u32 flags;
  78. u32 magic;
  79. u32 size;
  80. u32 alloced;
  81. u32 spare;
  82. u32 chksum;
  83. };
  84. /**
  85. * struct bloblist_rec - record for the bloblist
  86. *
  87. * NOTE: Only exported for testing purposes. Do not use this struct.
  88. *
  89. * The bloblist contains a number of records each consisting of this record
  90. * structure followed by the data contained. Each records is 16-byte aligned.
  91. *
  92. * @tag: Tag indicating what the record contains
  93. * @hdr_size: Size of this header, normally sizeof(struct bloblist_rec). The
  94. * record's data starts at this offset from the start of the record
  95. * @size: Size of record in bytes, excluding the header size. This does not
  96. * need to be aligned (e.g. 3 is OK).
  97. * @spare: Spare space for other things
  98. */
  99. struct bloblist_rec {
  100. u32 tag;
  101. u32 hdr_size;
  102. u32 size;
  103. u32 spare;
  104. };
  105. /**
  106. * bloblist_find() - Find a blob
  107. *
  108. * Searches the bloblist and returns the blob with the matching tag
  109. *
  110. * @tag: Tag to search for (enum bloblist_tag_t)
  111. * @size: Expected size of the blob, or 0 for any size
  112. * @return pointer to blob if found, or NULL if not found, or a blob was found
  113. * but it is the wrong size
  114. */
  115. void *bloblist_find(uint tag, int size);
  116. /**
  117. * bloblist_add() - Add a new blob
  118. *
  119. * Add a new blob to the bloblist
  120. *
  121. * This should only be called if you konw there is no existing blob for a
  122. * particular tag. It is typically safe to call in the first phase of U-Boot
  123. * (e.g. TPL or SPL). After that, bloblist_ensure() should be used instead.
  124. *
  125. * @tag: Tag to add (enum bloblist_tag_t)
  126. * @size: Size of the blob
  127. * @align: Alignment of the blob (in bytes), 0 for default
  128. * @return pointer to the newly added block, or NULL if there is not enough
  129. * space for the blob
  130. */
  131. void *bloblist_add(uint tag, int size, int align);
  132. /**
  133. * bloblist_ensure_size() - Find or add a blob
  134. *
  135. * Find an existing blob, or add a new one if not found
  136. *
  137. * @tag: Tag to add (enum bloblist_tag_t)
  138. * @size: Size of the blob
  139. * @blobp: Returns a pointer to blob on success
  140. * @align: Alignment of the blob (in bytes), 0 for default
  141. * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
  142. * of space, or -ESPIPE it exists but has the wrong size
  143. */
  144. int bloblist_ensure_size(uint tag, int size, int align, void **blobp);
  145. /**
  146. * bloblist_ensure() - Find or add a blob
  147. *
  148. * Find an existing blob, or add a new one if not found
  149. *
  150. * @tag: Tag to add (enum bloblist_tag_t)
  151. * @size: Size of the blob
  152. * @return pointer to blob, or NULL if it is missing and could not be added due
  153. * to lack of space, or it exists but has the wrong size
  154. */
  155. void *bloblist_ensure(uint tag, int size);
  156. /**
  157. * bloblist_ensure_size_ret() - Find or add a blob
  158. *
  159. * Find an existing blob, or add a new one if not found
  160. *
  161. * @tag: Tag to add (enum bloblist_tag_t)
  162. * @sizep: Size of the blob to create; returns size of actual blob
  163. * @blobp: Returns a pointer to blob on success
  164. * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
  165. * of space
  166. */
  167. int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp);
  168. /**
  169. * bloblist_new() - Create a new, empty bloblist of a given size
  170. *
  171. * @addr: Address of bloblist
  172. * @size: Initial size for bloblist
  173. * @flags: Flags to use for bloblist
  174. * @return 0 if OK, -EFAULT if addr is not aligned correctly, -ENOSPC is the
  175. * area is not large enough
  176. */
  177. int bloblist_new(ulong addr, uint size, uint flags);
  178. /**
  179. * bloblist_check() - Check if a bloblist exists
  180. *
  181. * @addr: Address of bloblist
  182. * @size: Expected size of blobsize, or 0 to detect the size
  183. * @return 0 if OK, -ENOENT if the magic number doesn't match (indicating that
  184. * there problem is no bloblist at the given address), -EPROTONOSUPPORT
  185. * if the version does not match, -EIO if the checksum does not match,
  186. * -EFBIG if the expected size does not match the detected size, -ENOSPC
  187. * if the size is not large enough to hold the headers
  188. */
  189. int bloblist_check(ulong addr, uint size);
  190. /**
  191. * bloblist_finish() - Set up the bloblist for the next U-Boot part
  192. *
  193. * This sets the correct checksum for the bloblist. This ensures that the
  194. * bloblist will be detected correctly by the next phase of U-Boot.
  195. *
  196. * @return 0
  197. */
  198. int bloblist_finish(void);
  199. /**
  200. * bloblist_get_stats() - Get information about the bloblist
  201. *
  202. * This returns useful information about the bloblist
  203. */
  204. void bloblist_get_stats(ulong *basep, ulong *sizep, ulong *allocedp);
  205. /**
  206. * bloblist_show_stats() - Show information about the bloblist
  207. *
  208. * This shows useful information about the bloblist on the console
  209. */
  210. void bloblist_show_stats(void);
  211. /**
  212. * bloblist_show_list() - Show a list of blobs in the bloblist
  213. *
  214. * This shows a list of blobs, showing their address, size and tag.
  215. */
  216. void bloblist_show_list(void);
  217. /**
  218. * bloblist_tag_name() - Get the name for a tag
  219. *
  220. * @tag: Tag to check
  221. * @return name of tag, or "invalid" if an invalid tag is provided
  222. */
  223. const char *bloblist_tag_name(enum bloblist_tag_t tag);
  224. /**
  225. * bloblist_init() - Init the bloblist system with a single bloblist
  226. *
  227. * This uses CONFIG_BLOBLIST_ADDR and CONFIG_BLOBLIST_SIZE to set up a bloblist
  228. * for use by U-Boot.
  229. */
  230. int bloblist_init(void);
  231. #endif /* __BLOBLIST_H */