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