cbfs.h 3.9 KB

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