cbfs.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
  4. */
  5. #ifndef __CBFS_H
  6. #define __CBFS_H
  7. #include <compiler.h>
  8. #include <linux/compiler.h>
  9. enum cbfs_result {
  10. CBFS_SUCCESS = 0,
  11. CBFS_NOT_INITIALIZED,
  12. CBFS_BAD_HEADER,
  13. CBFS_BAD_FILE,
  14. CBFS_FILE_NOT_FOUND
  15. };
  16. enum cbfs_filetype {
  17. CBFS_TYPE_BOOTBLOCK = 0x01,
  18. CBFS_TYPE_CBFSHEADER = 0x02,
  19. CBFS_TYPE_STAGE = 0x10,
  20. CBFS_TYPE_PAYLOAD = 0x20,
  21. CBFS_TYPE_FIT = 0x21,
  22. CBFS_TYPE_OPTIONROM = 0x30,
  23. CBFS_TYPE_BOOTSPLASH = 0x40,
  24. CBFS_TYPE_RAW = 0x50,
  25. CBFS_TYPE_VSA = 0x51,
  26. CBFS_TYPE_MBI = 0x52,
  27. CBFS_TYPE_MICROCODE = 0x53,
  28. CBFS_TYPE_FSP = 0x60,
  29. CBFS_TYPE_MRC = 0x61,
  30. CBFS_TYPE_MMA = 0x62,
  31. CBFS_TYPE_EFI = 0x63,
  32. CBFS_TYPE_STRUCT = 0x70,
  33. CBFS_TYPE_CMOS_DEFAULT = 0xaa,
  34. CBFS_TYPE_SPD = 0xab,
  35. CBFS_TYPE_MRC_CACHE = 0xac,
  36. CBFS_TYPE_CMOS_LAYOUT = 0x01aa
  37. };
  38. enum {
  39. CBFS_HEADER_MAGIC = 0x4f524243,
  40. };
  41. /**
  42. * struct cbfs_header - header at the start of a CBFS region
  43. *
  44. * All fields use big-endian format.
  45. *
  46. * @magic: Magic number (CBFS_HEADER_MAGIC)
  47. */
  48. struct cbfs_header {
  49. u32 magic;
  50. u32 version;
  51. u32 rom_size;
  52. u32 boot_block_size;
  53. u32 align;
  54. u32 offset;
  55. u32 pad[2];
  56. } __packed;
  57. struct cbfs_fileheader {
  58. u8 magic[8];
  59. u32 len;
  60. u32 type;
  61. /* offset to struct cbfs_file_attribute or 0 */
  62. u32 attributes_offset;
  63. u32 offset;
  64. } __packed;
  65. struct cbfs_cachenode {
  66. struct cbfs_cachenode *next;
  67. void *data;
  68. char *name;
  69. u32 type;
  70. u32 data_length;
  71. u32 name_length;
  72. u32 attributes_offset;
  73. };
  74. extern enum cbfs_result file_cbfs_result;
  75. /**
  76. * file_cbfs_error() - Return a string describing the most recent error
  77. * condition.
  78. *
  79. * @return A pointer to the constant string.
  80. */
  81. const char *file_cbfs_error(void);
  82. /**
  83. * cbfs_get_result() - Get the result of the last CBFS operation
  84. *
  85. *@return last result
  86. */
  87. enum cbfs_result cbfs_get_result(void);
  88. /**
  89. * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM.
  90. *
  91. * @end_of_rom: Points to the end of the ROM the CBFS should be read
  92. * from.
  93. */
  94. void file_cbfs_init(uintptr_t end_of_rom);
  95. /**
  96. * file_cbfs_get_header() - Get the header structure for the current CBFS.
  97. *
  98. * @return A pointer to the constant structure, or NULL if there is none.
  99. */
  100. const struct cbfs_header *file_cbfs_get_header(void);
  101. /**
  102. * file_cbfs_get_first() - Get a handle for the first file in CBFS.
  103. *
  104. * @return A handle for the first file in CBFS, NULL on error.
  105. */
  106. const struct cbfs_cachenode *file_cbfs_get_first(void);
  107. /**
  108. * file_cbfs_get_next() - Get a handle to the file after this one in CBFS.
  109. *
  110. * @file: A pointer to the handle to advance.
  111. */
  112. void file_cbfs_get_next(const struct cbfs_cachenode **file);
  113. /**
  114. * file_cbfs_find() - Find a file with a particular name in CBFS.
  115. *
  116. * @name: The name to search for.
  117. *
  118. * @return A handle to the file, or NULL on error.
  119. */
  120. const struct cbfs_cachenode *file_cbfs_find(const char *name);
  121. struct cbfs_priv *priv;
  122. /**
  123. * cbfs_find_file() - Find a file in a given CBFS
  124. *
  125. * @cbfs: CBFS to look in (use cbfs_init_mem() to set it up)
  126. * @name: Filename to look for
  127. * @return pointer to CBFS node if found, else NULL
  128. */
  129. const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *cbfs,
  130. const char *name);
  131. /**
  132. * cbfs_init_mem() - Set up a new CBFS
  133. *
  134. * @base: Base address of CBFS
  135. * @size: Size of CBFS in bytes
  136. * @cbfsp: Returns a pointer to CBFS on success
  137. * @return 0 if OK, -ve on error
  138. */
  139. int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp);
  140. /***************************************************************************/
  141. /* All of the functions below can be used without first initializing CBFS. */
  142. /***************************************************************************/
  143. /**
  144. * file_cbfs_find_uncached() - Find a file with a particular name in CBFS
  145. * without using the heap.
  146. *
  147. * @end_of_rom: Points to the end of the ROM the CBFS should be read
  148. * from.
  149. * @name: The name to search for.
  150. *
  151. * @return A handle to the file, or NULL on error.
  152. */
  153. const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
  154. const char *name);
  155. /**
  156. * file_cbfs_name() - Get the name of a file in CBFS.
  157. *
  158. * @file: The handle to the file.
  159. *
  160. * @return The name of the file, NULL on error.
  161. */
  162. const char *file_cbfs_name(const struct cbfs_cachenode *file);
  163. /**
  164. * file_cbfs_size() - Get the size of a file in CBFS.
  165. *
  166. * @file: The handle to the file.
  167. *
  168. * @return The size of the file, zero on error.
  169. */
  170. u32 file_cbfs_size(const struct cbfs_cachenode *file);
  171. /**
  172. * file_cbfs_type() - Get the type of a file in CBFS.
  173. *
  174. * @file: The handle to the file.
  175. *
  176. * @return The type of the file, zero on error.
  177. */
  178. u32 file_cbfs_type(const struct cbfs_cachenode *file);
  179. /**
  180. * file_cbfs_read() - Read a file from CBFS into RAM
  181. *
  182. * @file: A handle to the file to read.
  183. * @buffer: Where to read it into memory.
  184. * @maxsize: Maximum number of bytes to read
  185. *
  186. * @return If positive or zero, the number of characters read. If negative, an
  187. * error occurred.
  188. */
  189. long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
  190. unsigned long maxsize);
  191. #endif /* __CBFS_H */