xref: /openbmc/u-boot/include/cbfs.h (revision 7e40d0a3)
183d290c5STom 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 {
21*881bb9abSBin Meng 	CBFS_TYPE_BOOTBLOCK = 0x01,
22*881bb9abSBin Meng 	CBFS_TYPE_CBFSHEADER = 0x02,
2384cd9327SGabe Black 	CBFS_TYPE_STAGE = 0x10,
2484cd9327SGabe Black 	CBFS_TYPE_PAYLOAD = 0x20,
25*881bb9abSBin Meng 	CBFS_TYPE_FIT = 0x21,
2684cd9327SGabe Black 	CBFS_TYPE_OPTIONROM = 0x30,
2784cd9327SGabe Black 	CBFS_TYPE_BOOTSPLASH = 0x40,
2884cd9327SGabe Black 	CBFS_TYPE_RAW = 0x50,
2984cd9327SGabe Black 	CBFS_TYPE_VSA = 0x51,
3084cd9327SGabe Black 	CBFS_TYPE_MBI = 0x52,
3184cd9327SGabe Black 	CBFS_TYPE_MICROCODE = 0x53,
32*881bb9abSBin Meng 	CBFS_TYPE_FSP = 0x60,
33*881bb9abSBin Meng 	CBFS_TYPE_MRC = 0x61,
34*881bb9abSBin Meng 	CBFS_TYPE_MMA = 0x62,
35*881bb9abSBin Meng 	CBFS_TYPE_EFI = 0x63,
36*881bb9abSBin Meng 	CBFS_TYPE_STRUCT = 0x70,
3714fdf91eSBin Meng 	CBFS_TYPE_CMOS_DEFAULT = 0xaa,
38*881bb9abSBin Meng 	CBFS_TYPE_SPD = 0xab,
39*881bb9abSBin Meng 	CBFS_TYPE_MRC_CACHE = 0xac,
4014fdf91eSBin Meng 	CBFS_TYPE_CMOS_LAYOUT = 0x01aa
4184cd9327SGabe Black };
4284cd9327SGabe Black 
4384cd9327SGabe Black struct cbfs_header {
4484cd9327SGabe Black 	u32 magic;
4584cd9327SGabe Black 	u32 version;
4684cd9327SGabe Black 	u32 rom_size;
4784cd9327SGabe Black 	u32 boot_block_size;
4884cd9327SGabe Black 	u32 align;
4984cd9327SGabe Black 	u32 offset;
5084cd9327SGabe Black 	u32 pad[2];
5184cd9327SGabe Black } __packed;
5284cd9327SGabe Black 
5384cd9327SGabe Black struct cbfs_fileheader {
5484cd9327SGabe Black 	u8 magic[8];
5584cd9327SGabe Black 	u32 len;
5684cd9327SGabe Black 	u32 type;
5784cd9327SGabe Black 	u32 checksum;
5884cd9327SGabe Black 	u32 offset;
5984cd9327SGabe Black } __packed;
6084cd9327SGabe Black 
6184cd9327SGabe Black struct cbfs_cachenode {
6284cd9327SGabe Black 	struct cbfs_cachenode *next;
6384cd9327SGabe Black 	u32 type;
6484cd9327SGabe Black 	void *data;
6584cd9327SGabe Black 	u32 data_length;
6684cd9327SGabe Black 	char *name;
6784cd9327SGabe Black 	u32 name_length;
6884cd9327SGabe Black 	u32 checksum;
6984cd9327SGabe Black } __packed;
7084cd9327SGabe Black 
7184cd9327SGabe Black extern enum cbfs_result file_cbfs_result;
7284cd9327SGabe Black 
73e3ff797cSSimon Glass /**
74e3ff797cSSimon Glass  * file_cbfs_error() - Return a string describing the most recent error
75e3ff797cSSimon Glass  * condition.
7684cd9327SGabe Black  *
7784cd9327SGabe Black  * @return A pointer to the constant string.
7884cd9327SGabe Black  */
7984cd9327SGabe Black const char *file_cbfs_error(void);
8084cd9327SGabe Black 
81e3ff797cSSimon Glass /**
82e3ff797cSSimon Glass  * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM.
8384cd9327SGabe Black  *
84e3ff797cSSimon Glass  * @end_of_rom: Points to the end of the ROM the CBFS should be read
8584cd9327SGabe Black  *                      from.
8684cd9327SGabe Black  */
8784cd9327SGabe Black void file_cbfs_init(uintptr_t end_of_rom);
8884cd9327SGabe Black 
89e3ff797cSSimon Glass /**
90e3ff797cSSimon Glass  * file_cbfs_get_header() - Get the header structure for the current CBFS.
9184cd9327SGabe Black  *
9284cd9327SGabe Black  * @return A pointer to the constant structure, or NULL if there is none.
9384cd9327SGabe Black  */
9484cd9327SGabe Black const struct cbfs_header *file_cbfs_get_header(void);
9584cd9327SGabe Black 
96e3ff797cSSimon Glass /**
97e3ff797cSSimon Glass  * file_cbfs_get_first() - Get a handle for the first file in CBFS.
9884cd9327SGabe Black  *
9984cd9327SGabe Black  * @return A handle for the first file in CBFS, NULL on error.
10084cd9327SGabe Black  */
10184cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_get_first(void);
10284cd9327SGabe Black 
103e3ff797cSSimon Glass /**
104e3ff797cSSimon Glass  * file_cbfs_get_next() - Get a handle to the file after this one in CBFS.
10584cd9327SGabe Black  *
106e3ff797cSSimon Glass  * @file:		A pointer to the handle to advance.
10784cd9327SGabe Black  */
10884cd9327SGabe Black void file_cbfs_get_next(const struct cbfs_cachenode **file);
10984cd9327SGabe Black 
110e3ff797cSSimon Glass /**
111e3ff797cSSimon Glass  * file_cbfs_find() - Find a file with a particular name in CBFS.
11284cd9327SGabe Black  *
113e3ff797cSSimon Glass  * @name:		The name to search for.
11484cd9327SGabe Black  *
11584cd9327SGabe Black  * @return A handle to the file, or NULL on error.
11684cd9327SGabe Black  */
11784cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find(const char *name);
11884cd9327SGabe Black 
11984cd9327SGabe Black 
12084cd9327SGabe Black /***************************************************************************/
12184cd9327SGabe Black /* All of the functions below can be used without first initializing CBFS. */
12284cd9327SGabe Black /***************************************************************************/
12384cd9327SGabe Black 
124e3ff797cSSimon Glass /**
125e3ff797cSSimon Glass  * file_cbfs_find_uncached() - Find a file with a particular name in CBFS
126e3ff797cSSimon Glass  * without using the heap.
12784cd9327SGabe Black  *
128e3ff797cSSimon Glass  * @end_of_rom:		Points to the end of the ROM the CBFS should be read
12984cd9327SGabe Black  *                      from.
130e3ff797cSSimon Glass  * @name:		The name to search for.
13184cd9327SGabe Black  *
13284cd9327SGabe Black  * @return A handle to the file, or NULL on error.
13384cd9327SGabe Black  */
13484cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
13584cd9327SGabe Black 						     const char *name);
13684cd9327SGabe Black 
137e3ff797cSSimon Glass /**
138e3ff797cSSimon Glass  * file_cbfs_name() - Get the name of a file in CBFS.
13984cd9327SGabe Black  *
140e3ff797cSSimon Glass  * @file:		The handle to the file.
14184cd9327SGabe Black  *
14284cd9327SGabe Black  * @return The name of the file, NULL on error.
14384cd9327SGabe Black  */
14484cd9327SGabe Black const char *file_cbfs_name(const struct cbfs_cachenode *file);
14584cd9327SGabe Black 
146e3ff797cSSimon Glass /**
147e3ff797cSSimon Glass  * file_cbfs_size() - Get the size of a file in CBFS.
14884cd9327SGabe Black  *
149e3ff797cSSimon Glass  * @file:		The handle to the file.
15084cd9327SGabe Black  *
15184cd9327SGabe Black  * @return The size of the file, zero on error.
15284cd9327SGabe Black  */
15384cd9327SGabe Black u32 file_cbfs_size(const struct cbfs_cachenode *file);
15484cd9327SGabe Black 
155e3ff797cSSimon Glass /**
156e3ff797cSSimon Glass  * file_cbfs_type() - Get the type of a file in CBFS.
15784cd9327SGabe Black  *
158e3ff797cSSimon Glass  * @file:		The handle to the file.
15984cd9327SGabe Black  *
16084cd9327SGabe Black  * @return The type of the file, zero on error.
16184cd9327SGabe Black  */
16284cd9327SGabe Black u32 file_cbfs_type(const struct cbfs_cachenode *file);
16384cd9327SGabe Black 
164e3ff797cSSimon Glass /**
165e3ff797cSSimon Glass  * file_cbfs_read() - Read a file from CBFS into RAM
16684cd9327SGabe Black  *
167e3ff797cSSimon Glass  * @file:		A handle to the file to read.
168e3ff797cSSimon Glass  * @buffer:		Where to read it into memory.
169e3ff797cSSimon Glass  * @maxsize:		Maximum number of bytes to read
17084cd9327SGabe Black  *
17184cd9327SGabe Black  * @return If positive or zero, the number of characters read. If negative, an
17284cd9327SGabe Black  *	   error occurred.
17384cd9327SGabe Black  */
17484cd9327SGabe Black long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
17584cd9327SGabe Black 		    unsigned long maxsize);
17684cd9327SGabe Black 
17784cd9327SGabe Black #endif /* __CBFS_H */
178