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