xref: /rk3399_rockchip-uboot/include/cbfs.h (revision 326ea986ac150acdc7656d57fca647db80b50158)
184cd9327SGabe Black /*
284cd9327SGabe Black  * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
384cd9327SGabe Black  *
4*1a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
584cd9327SGabe Black  */
684cd9327SGabe Black 
784cd9327SGabe Black #ifndef __CBFS_H
884cd9327SGabe Black #define __CBFS_H
984cd9327SGabe Black 
1084cd9327SGabe Black #include <compiler.h>
1184cd9327SGabe Black #include <linux/compiler.h>
1284cd9327SGabe Black 
1384cd9327SGabe Black enum cbfs_result {
1484cd9327SGabe Black 	CBFS_SUCCESS = 0,
1584cd9327SGabe Black 	CBFS_NOT_INITIALIZED,
1684cd9327SGabe Black 	CBFS_BAD_HEADER,
1784cd9327SGabe Black 	CBFS_BAD_FILE,
1884cd9327SGabe Black 	CBFS_FILE_NOT_FOUND
1984cd9327SGabe Black };
2084cd9327SGabe Black 
2184cd9327SGabe Black enum cbfs_filetype {
2284cd9327SGabe Black 	CBFS_TYPE_STAGE = 0x10,
2384cd9327SGabe Black 	CBFS_TYPE_PAYLOAD = 0x20,
2484cd9327SGabe Black 	CBFS_TYPE_OPTIONROM = 0x30,
2584cd9327SGabe Black 	CBFS_TYPE_BOOTSPLASH = 0x40,
2684cd9327SGabe Black 	CBFS_TYPE_RAW = 0x50,
2784cd9327SGabe Black 	CBFS_TYPE_VSA = 0x51,
2884cd9327SGabe Black 	CBFS_TYPE_MBI = 0x52,
2984cd9327SGabe Black 	CBFS_TYPE_MICROCODE = 0x53,
3084cd9327SGabe Black 	CBFS_COMPONENT_CMOS_DEFAULT = 0xaa,
3184cd9327SGabe Black 	CBFS_COMPONENT_CMOS_LAYOUT = 0x01aa
3284cd9327SGabe Black };
3384cd9327SGabe Black 
3484cd9327SGabe Black struct cbfs_header {
3584cd9327SGabe Black 	u32 magic;
3684cd9327SGabe Black 	u32 version;
3784cd9327SGabe Black 	u32 rom_size;
3884cd9327SGabe Black 	u32 boot_block_size;
3984cd9327SGabe Black 	u32 align;
4084cd9327SGabe Black 	u32 offset;
4184cd9327SGabe Black 	u32 pad[2];
4284cd9327SGabe Black } __packed;
4384cd9327SGabe Black 
4484cd9327SGabe Black struct cbfs_fileheader {
4584cd9327SGabe Black 	u8 magic[8];
4684cd9327SGabe Black 	u32 len;
4784cd9327SGabe Black 	u32 type;
4884cd9327SGabe Black 	u32 checksum;
4984cd9327SGabe Black 	u32 offset;
5084cd9327SGabe Black } __packed;
5184cd9327SGabe Black 
5284cd9327SGabe Black struct cbfs_cachenode {
5384cd9327SGabe Black 	struct cbfs_cachenode *next;
5484cd9327SGabe Black 	u32 type;
5584cd9327SGabe Black 	void *data;
5684cd9327SGabe Black 	u32 data_length;
5784cd9327SGabe Black 	char *name;
5884cd9327SGabe Black 	u32 name_length;
5984cd9327SGabe Black 	u32 checksum;
6084cd9327SGabe Black } __packed;
6184cd9327SGabe Black 
6284cd9327SGabe Black extern enum cbfs_result file_cbfs_result;
6384cd9327SGabe Black 
64e3ff797cSSimon Glass /**
65e3ff797cSSimon Glass  * file_cbfs_error() - Return a string describing the most recent error
66e3ff797cSSimon Glass  * condition.
6784cd9327SGabe Black  *
6884cd9327SGabe Black  * @return A pointer to the constant string.
6984cd9327SGabe Black  */
7084cd9327SGabe Black const char *file_cbfs_error(void);
7184cd9327SGabe Black 
72e3ff797cSSimon Glass /**
73e3ff797cSSimon Glass  * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM.
7484cd9327SGabe Black  *
75e3ff797cSSimon Glass  * @end_of_rom: Points to the end of the ROM the CBFS should be read
7684cd9327SGabe Black  *                      from.
7784cd9327SGabe Black  */
7884cd9327SGabe Black void file_cbfs_init(uintptr_t end_of_rom);
7984cd9327SGabe Black 
80e3ff797cSSimon Glass /**
81e3ff797cSSimon Glass  * file_cbfs_get_header() - Get the header structure for the current CBFS.
8284cd9327SGabe Black  *
8384cd9327SGabe Black  * @return A pointer to the constant structure, or NULL if there is none.
8484cd9327SGabe Black  */
8584cd9327SGabe Black const struct cbfs_header *file_cbfs_get_header(void);
8684cd9327SGabe Black 
87e3ff797cSSimon Glass /**
88e3ff797cSSimon Glass  * file_cbfs_get_first() - Get a handle for the first file in CBFS.
8984cd9327SGabe Black  *
9084cd9327SGabe Black  * @return A handle for the first file in CBFS, NULL on error.
9184cd9327SGabe Black  */
9284cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_get_first(void);
9384cd9327SGabe Black 
94e3ff797cSSimon Glass /**
95e3ff797cSSimon Glass  * file_cbfs_get_next() - Get a handle to the file after this one in CBFS.
9684cd9327SGabe Black  *
97e3ff797cSSimon Glass  * @file:		A pointer to the handle to advance.
9884cd9327SGabe Black  */
9984cd9327SGabe Black void file_cbfs_get_next(const struct cbfs_cachenode **file);
10084cd9327SGabe Black 
101e3ff797cSSimon Glass /**
102e3ff797cSSimon Glass  * file_cbfs_find() - Find a file with a particular name in CBFS.
10384cd9327SGabe Black  *
104e3ff797cSSimon Glass  * @name:		The name to search for.
10584cd9327SGabe Black  *
10684cd9327SGabe Black  * @return A handle to the file, or NULL on error.
10784cd9327SGabe Black  */
10884cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find(const char *name);
10984cd9327SGabe Black 
11084cd9327SGabe Black 
11184cd9327SGabe Black /***************************************************************************/
11284cd9327SGabe Black /* All of the functions below can be used without first initializing CBFS. */
11384cd9327SGabe Black /***************************************************************************/
11484cd9327SGabe Black 
115e3ff797cSSimon Glass /**
116e3ff797cSSimon Glass  * file_cbfs_find_uncached() - Find a file with a particular name in CBFS
117e3ff797cSSimon Glass  * without using the heap.
11884cd9327SGabe Black  *
119e3ff797cSSimon Glass  * @end_of_rom:		Points to the end of the ROM the CBFS should be read
12084cd9327SGabe Black  *                      from.
121e3ff797cSSimon Glass  * @name:		The name to search for.
12284cd9327SGabe Black  *
12384cd9327SGabe Black  * @return A handle to the file, or NULL on error.
12484cd9327SGabe Black  */
12584cd9327SGabe Black const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
12684cd9327SGabe Black 						     const char *name);
12784cd9327SGabe Black 
128e3ff797cSSimon Glass /**
129e3ff797cSSimon Glass  * file_cbfs_name() - Get the name of a file in CBFS.
13084cd9327SGabe Black  *
131e3ff797cSSimon Glass  * @file:		The handle to the file.
13284cd9327SGabe Black  *
13384cd9327SGabe Black  * @return The name of the file, NULL on error.
13484cd9327SGabe Black  */
13584cd9327SGabe Black const char *file_cbfs_name(const struct cbfs_cachenode *file);
13684cd9327SGabe Black 
137e3ff797cSSimon Glass /**
138e3ff797cSSimon Glass  * file_cbfs_size() - Get the size of a file in CBFS.
13984cd9327SGabe Black  *
140e3ff797cSSimon Glass  * @file:		The handle to the file.
14184cd9327SGabe Black  *
14284cd9327SGabe Black  * @return The size of the file, zero on error.
14384cd9327SGabe Black  */
14484cd9327SGabe Black u32 file_cbfs_size(const struct cbfs_cachenode *file);
14584cd9327SGabe Black 
146e3ff797cSSimon Glass /**
147e3ff797cSSimon Glass  * file_cbfs_type() - Get the type of a file in CBFS.
14884cd9327SGabe Black  *
149e3ff797cSSimon Glass  * @file:		The handle to the file.
15084cd9327SGabe Black  *
15184cd9327SGabe Black  * @return The type of the file, zero on error.
15284cd9327SGabe Black  */
15384cd9327SGabe Black u32 file_cbfs_type(const struct cbfs_cachenode *file);
15484cd9327SGabe Black 
155e3ff797cSSimon Glass /**
156e3ff797cSSimon Glass  * file_cbfs_read() - Read a file from CBFS into RAM
15784cd9327SGabe Black  *
158e3ff797cSSimon Glass  * @file:		A handle to the file to read.
159e3ff797cSSimon Glass  * @buffer:		Where to read it into memory.
160e3ff797cSSimon Glass  * @maxsize:		Maximum number of bytes to read
16184cd9327SGabe Black  *
16284cd9327SGabe Black  * @return If positive or zero, the number of characters read. If negative, an
16384cd9327SGabe Black  *	   error occurred.
16484cd9327SGabe Black  */
16584cd9327SGabe Black long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
16684cd9327SGabe Black 		    unsigned long maxsize);
16784cd9327SGabe Black 
16884cd9327SGabe Black #endif /* __CBFS_H */
169