cbfs.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef __CBFS_H
  7. #define __CBFS_H
  8. #include <compiler.h>
  9. #include <linux/compiler.h>
  10. enum cbfs_result {
  11. CBFS_SUCCESS = 0,
  12. CBFS_NOT_INITIALIZED,
  13. CBFS_BAD_HEADER,
  14. CBFS_BAD_FILE,
  15. CBFS_FILE_NOT_FOUND
  16. };
  17. enum cbfs_filetype {
  18. CBFS_TYPE_STAGE = 0x10,
  19. CBFS_TYPE_PAYLOAD = 0x20,
  20. CBFS_TYPE_OPTIONROM = 0x30,
  21. CBFS_TYPE_BOOTSPLASH = 0x40,
  22. CBFS_TYPE_RAW = 0x50,
  23. CBFS_TYPE_VSA = 0x51,
  24. CBFS_TYPE_MBI = 0x52,
  25. CBFS_TYPE_MICROCODE = 0x53,
  26. CBFS_COMPONENT_CMOS_DEFAULT = 0xaa,
  27. CBFS_COMPONENT_CMOS_LAYOUT = 0x01aa
  28. };
  29. struct cbfs_header {
  30. u32 magic;
  31. u32 version;
  32. u32 rom_size;
  33. u32 boot_block_size;
  34. u32 align;
  35. u32 offset;
  36. u32 pad[2];
  37. } __packed;
  38. struct cbfs_fileheader {
  39. u8 magic[8];
  40. u32 len;
  41. u32 type;
  42. u32 checksum;
  43. u32 offset;
  44. } __packed;
  45. struct cbfs_cachenode {
  46. struct cbfs_cachenode *next;
  47. u32 type;
  48. void *data;
  49. u32 data_length;
  50. char *name;
  51. u32 name_length;
  52. u32 checksum;
  53. } __packed;
  54. extern enum cbfs_result file_cbfs_result;
  55. /**
  56. * file_cbfs_error() - Return a string describing the most recent error
  57. * condition.
  58. *
  59. * @return A pointer to the constant string.
  60. */
  61. const char *file_cbfs_error(void);
  62. /**
  63. * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM.
  64. *
  65. * @end_of_rom: Points to the end of the ROM the CBFS should be read
  66. * from.
  67. */
  68. void file_cbfs_init(uintptr_t end_of_rom);
  69. /**
  70. * file_cbfs_get_header() - Get the header structure for the current CBFS.
  71. *
  72. * @return A pointer to the constant structure, or NULL if there is none.
  73. */
  74. const struct cbfs_header *file_cbfs_get_header(void);
  75. /**
  76. * file_cbfs_get_first() - Get a handle for the first file in CBFS.
  77. *
  78. * @return A handle for the first file in CBFS, NULL on error.
  79. */
  80. const struct cbfs_cachenode *file_cbfs_get_first(void);
  81. /**
  82. * file_cbfs_get_next() - Get a handle to the file after this one in CBFS.
  83. *
  84. * @file: A pointer to the handle to advance.
  85. */
  86. void file_cbfs_get_next(const struct cbfs_cachenode **file);
  87. /**
  88. * file_cbfs_find() - Find a file with a particular name in CBFS.
  89. *
  90. * @name: The name to search for.
  91. *
  92. * @return A handle to the file, or NULL on error.
  93. */
  94. const struct cbfs_cachenode *file_cbfs_find(const char *name);
  95. /***************************************************************************/
  96. /* All of the functions below can be used without first initializing CBFS. */
  97. /***************************************************************************/
  98. /**
  99. * file_cbfs_find_uncached() - Find a file with a particular name in CBFS
  100. * without using the heap.
  101. *
  102. * @end_of_rom: Points to the end of the ROM the CBFS should be read
  103. * from.
  104. * @name: The name to search for.
  105. *
  106. * @return A handle to the file, or NULL on error.
  107. */
  108. const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
  109. const char *name);
  110. /**
  111. * file_cbfs_name() - Get the name of a file in CBFS.
  112. *
  113. * @file: The handle to the file.
  114. *
  115. * @return The name of the file, NULL on error.
  116. */
  117. const char *file_cbfs_name(const struct cbfs_cachenode *file);
  118. /**
  119. * file_cbfs_size() - Get the size of a file in CBFS.
  120. *
  121. * @file: The handle to the file.
  122. *
  123. * @return The size of the file, zero on error.
  124. */
  125. u32 file_cbfs_size(const struct cbfs_cachenode *file);
  126. /**
  127. * file_cbfs_type() - Get the type of a file in CBFS.
  128. *
  129. * @file: The handle to the file.
  130. *
  131. * @return The type of the file, zero on error.
  132. */
  133. u32 file_cbfs_type(const struct cbfs_cachenode *file);
  134. /**
  135. * file_cbfs_read() - Read a file from CBFS into RAM
  136. *
  137. * @file: A handle to the file to read.
  138. * @buffer: Where to read it into memory.
  139. * @maxsize: Maximum number of bytes to read
  140. *
  141. * @return If positive or zero, the number of characters read. If negative, an
  142. * error occurred.
  143. */
  144. long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
  145. unsigned long maxsize);
  146. #endif /* __CBFS_H */