xref: /openbmc/u-boot/include/cbfs.h (revision 83d290c5)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
284cd9327SGabe Black /*
384cd9327SGabe Black  * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
484cd9327SGabe Black  */
584cd9327SGabe Black 
684cd9327SGabe Black #ifndef __CBFS_H
784cd9327SGabe Black #define __CBFS_H
884cd9327SGabe Black 
984cd9327SGabe Black #include <compiler.h>
1084cd9327SGabe Black #include <linux/compiler.h>
1184cd9327SGabe Black 
1284cd9327SGabe Black enum cbfs_result {
1384cd9327SGabe Black 	CBFS_SUCCESS = 0,
1484cd9327SGabe Black 	CBFS_NOT_INITIALIZED,
1584cd9327SGabe Black 	CBFS_BAD_HEADER,
1684cd9327SGabe Black 	CBFS_BAD_FILE,
1784cd9327SGabe Black 	CBFS_FILE_NOT_FOUND
1884cd9327SGabe Black };
1984cd9327SGabe Black 
2084cd9327SGabe Black enum cbfs_filetype {
2184cd9327SGabe Black 	CBFS_TYPE_STAGE = 0x10,
2284cd9327SGabe Black 	CBFS_TYPE_PAYLOAD = 0x20,
2384cd9327SGabe Black 	CBFS_TYPE_OPTIONROM = 0x30,
2484cd9327SGabe Black 	CBFS_TYPE_BOOTSPLASH = 0x40,
2584cd9327SGabe Black 	CBFS_TYPE_RAW = 0x50,
2684cd9327SGabe Black 	CBFS_TYPE_VSA = 0x51,
2784cd9327SGabe Black 	CBFS_TYPE_MBI = 0x52,
2884cd9327SGabe Black 	CBFS_TYPE_MICROCODE = 0x53,
2984cd9327SGabe Black 	CBFS_COMPONENT_CMOS_DEFAULT = 0xaa,
3084cd9327SGabe Black 	CBFS_COMPONENT_CMOS_LAYOUT = 0x01aa
3184cd9327SGabe Black };
3284cd9327SGabe Black 
3384cd9327SGabe Black struct cbfs_header {
3484cd9327SGabe Black 	u32 magic;
3584cd9327SGabe Black 	u32 version;
3684cd9327SGabe Black 	u32 rom_size;
3784cd9327SGabe Black 	u32 boot_block_size;
3884cd9327SGabe Black 	u32 align;
3984cd9327SGabe Black 	u32 offset;
4084cd9327SGabe Black 	u32 pad[2];
4184cd9327SGabe Black } __packed;
4284cd9327SGabe Black 
4384cd9327SGabe Black struct cbfs_fileheader {
4484cd9327SGabe Black 	u8 magic[8];
4584cd9327SGabe Black 	u32 len;
4684cd9327SGabe Black 	u32 type;
4784cd9327SGabe Black 	u32 checksum;
4884cd9327SGabe Black 	u32 offset;
4984cd9327SGabe Black } __packed;
5084cd9327SGabe Black 
5184cd9327SGabe Black struct cbfs_cachenode {
5284cd9327SGabe Black 	struct cbfs_cachenode *next;
5384cd9327SGabe Black 	u32 type;
5484cd9327SGabe Black 	void *data;
5584cd9327SGabe Black 	u32 data_length;
5684cd9327SGabe Black 	char *name;
5784cd9327SGabe Black 	u32 name_length;
5884cd9327SGabe Black 	u32 checksum;
5984cd9327SGabe Black } __packed;
6084cd9327SGabe Black 
6184cd9327SGabe Black extern enum cbfs_result file_cbfs_result;
6284cd9327SGabe Black 
63e3ff797cSSimon Glass /**
64e3ff797cSSimon Glass  * file_cbfs_error() - Return a string describing the most recent error
65e3ff797cSSimon Glass  * condition.
6684cd9327SGabe Black  *
6784cd9327SGabe Black  * @return A pointer to the constant string.
6884cd9327SGabe Black  */
6984cd9327SGabe Black const char *file_cbfs_error(void);
7084cd9327SGabe Black 
71e3ff797cSSimon Glass /**
72e3ff797cSSimon Glass  * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM.
7384cd9327SGabe Black  *
74e3ff797cSSimon Glass  * @end_of_rom: Points to the end of the ROM the CBFS should be read
7584cd9327SGabe Black  *                      from.
7684cd9327SGabe Black  */
7784cd9327SGabe Black void file_cbfs_init(uintptr_t end_of_rom);
7884cd9327SGabe Black 
79e3ff797cSSimon Glass /**
80e3ff797cSSimon Glass  * file_cbfs_get_header() - Get the header structure for the current CBFS.
8184cd9327SGabe Black  *
8284cd9327SGabe Black  * @return A pointer to the constant structure, or NULL if there is none.
8384cd9327SGabe Black  */
8484cd9327SGabe Black const struct cbfs_header *file_cbfs_get_header(void);
8584cd9327SGabe Black 
86e3ff797cSSimon Glass /**
87e3ff797cSSimon Glass  * file_cbfs_get_first() - Get a handle for the first file in CBFS.
8884cd9327SGabe Black  *
8984cd9327SGabe Black  * @return A handle for the first file in CBFS, NULL on error.
9084cd9327SGabe Black  */
9184cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_get_first(void);
9284cd9327SGabe Black 
93e3ff797cSSimon Glass /**
94e3ff797cSSimon Glass  * file_cbfs_get_next() - Get a handle to the file after this one in CBFS.
9584cd9327SGabe Black  *
96e3ff797cSSimon Glass  * @file:		A pointer to the handle to advance.
9784cd9327SGabe Black  */
9884cd9327SGabe Black void file_cbfs_get_next(const struct cbfs_cachenode **file);
9984cd9327SGabe Black 
100e3ff797cSSimon Glass /**
101e3ff797cSSimon Glass  * file_cbfs_find() - Find a file with a particular name in CBFS.
10284cd9327SGabe Black  *
103e3ff797cSSimon Glass  * @name:		The name to search for.
10484cd9327SGabe Black  *
10584cd9327SGabe Black  * @return A handle to the file, or NULL on error.
10684cd9327SGabe Black  */
10784cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find(const char *name);
10884cd9327SGabe Black 
10984cd9327SGabe Black 
11084cd9327SGabe Black /***************************************************************************/
11184cd9327SGabe Black /* All of the functions below can be used without first initializing CBFS. */
11284cd9327SGabe Black /***************************************************************************/
11384cd9327SGabe Black 
114e3ff797cSSimon Glass /**
115e3ff797cSSimon Glass  * file_cbfs_find_uncached() - Find a file with a particular name in CBFS
116e3ff797cSSimon Glass  * without using the heap.
11784cd9327SGabe Black  *
118e3ff797cSSimon Glass  * @end_of_rom:		Points to the end of the ROM the CBFS should be read
11984cd9327SGabe Black  *                      from.
120e3ff797cSSimon Glass  * @name:		The name to search for.
12184cd9327SGabe Black  *
12284cd9327SGabe Black  * @return A handle to the file, or NULL on error.
12384cd9327SGabe Black  */
12484cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
12584cd9327SGabe Black 						     const char *name);
12684cd9327SGabe Black 
127e3ff797cSSimon Glass /**
128e3ff797cSSimon Glass  * file_cbfs_name() - Get the name of a file in CBFS.
12984cd9327SGabe Black  *
130e3ff797cSSimon Glass  * @file:		The handle to the file.
13184cd9327SGabe Black  *
13284cd9327SGabe Black  * @return The name of the file, NULL on error.
13384cd9327SGabe Black  */
13484cd9327SGabe Black const char *file_cbfs_name(const struct cbfs_cachenode *file);
13584cd9327SGabe Black 
136e3ff797cSSimon Glass /**
137e3ff797cSSimon Glass  * file_cbfs_size() - Get the size of a file in CBFS.
13884cd9327SGabe Black  *
139e3ff797cSSimon Glass  * @file:		The handle to the file.
14084cd9327SGabe Black  *
14184cd9327SGabe Black  * @return The size of the file, zero on error.
14284cd9327SGabe Black  */
14384cd9327SGabe Black u32 file_cbfs_size(const struct cbfs_cachenode *file);
14484cd9327SGabe Black 
145e3ff797cSSimon Glass /**
146e3ff797cSSimon Glass  * file_cbfs_type() - Get the type of a file in CBFS.
14784cd9327SGabe Black  *
148e3ff797cSSimon Glass  * @file:		The handle to the file.
14984cd9327SGabe Black  *
15084cd9327SGabe Black  * @return The type of the file, zero on error.
15184cd9327SGabe Black  */
15284cd9327SGabe Black u32 file_cbfs_type(const struct cbfs_cachenode *file);
15384cd9327SGabe Black 
154e3ff797cSSimon Glass /**
155e3ff797cSSimon Glass  * file_cbfs_read() - Read a file from CBFS into RAM
15684cd9327SGabe Black  *
157e3ff797cSSimon Glass  * @file:		A handle to the file to read.
158e3ff797cSSimon Glass  * @buffer:		Where to read it into memory.
159e3ff797cSSimon Glass  * @maxsize:		Maximum number of bytes to read
16084cd9327SGabe Black  *
16184cd9327SGabe Black  * @return If positive or zero, the number of characters read. If negative, an
16284cd9327SGabe Black  *	   error occurred.
16384cd9327SGabe Black  */
16484cd9327SGabe Black long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
16584cd9327SGabe Black 		    unsigned long maxsize);
16684cd9327SGabe Black 
16784cd9327SGabe Black #endif /* __CBFS_H */
168