blob: f50280107b001d0699e1f4d33bdf5a777338a16a [file] [log] [blame]
Gabe Black84cd9322012-10-12 14:26:11 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Gabe Black84cd9322012-10-12 14:26:11 +00005 */
6
7#ifndef __CBFS_H
8#define __CBFS_H
9
10#include <compiler.h>
11#include <linux/compiler.h>
12
13enum 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
21enum 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
34struct 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
44struct cbfs_fileheader {
45 u8 magic[8];
46 u32 len;
47 u32 type;
48 u32 checksum;
49 u32 offset;
50} __packed;
51
52struct 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
62extern enum cbfs_result file_cbfs_result;
63
Simon Glasse3ff7972012-11-05 12:16:25 +000064/**
65 * file_cbfs_error() - Return a string describing the most recent error
66 * condition.
Gabe Black84cd9322012-10-12 14:26:11 +000067 *
68 * @return A pointer to the constant string.
69 */
70const char *file_cbfs_error(void);
71
Simon Glasse3ff7972012-11-05 12:16:25 +000072/**
73 * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM.
Gabe Black84cd9322012-10-12 14:26:11 +000074 *
Simon Glasse3ff7972012-11-05 12:16:25 +000075 * @end_of_rom: Points to the end of the ROM the CBFS should be read
Gabe Black84cd9322012-10-12 14:26:11 +000076 * from.
77 */
78void file_cbfs_init(uintptr_t end_of_rom);
79
Simon Glasse3ff7972012-11-05 12:16:25 +000080/**
81 * file_cbfs_get_header() - Get the header structure for the current CBFS.
Gabe Black84cd9322012-10-12 14:26:11 +000082 *
83 * @return A pointer to the constant structure, or NULL if there is none.
84 */
85const struct cbfs_header *file_cbfs_get_header(void);
86
Simon Glasse3ff7972012-11-05 12:16:25 +000087/**
88 * file_cbfs_get_first() - Get a handle for the first file in CBFS.
Gabe Black84cd9322012-10-12 14:26:11 +000089 *
90 * @return A handle for the first file in CBFS, NULL on error.
91 */
92const struct cbfs_cachenode *file_cbfs_get_first(void);
93
Simon Glasse3ff7972012-11-05 12:16:25 +000094/**
95 * file_cbfs_get_next() - Get a handle to the file after this one in CBFS.
Gabe Black84cd9322012-10-12 14:26:11 +000096 *
Simon Glasse3ff7972012-11-05 12:16:25 +000097 * @file: A pointer to the handle to advance.
Gabe Black84cd9322012-10-12 14:26:11 +000098 */
99void file_cbfs_get_next(const struct cbfs_cachenode **file);
100
Simon Glasse3ff7972012-11-05 12:16:25 +0000101/**
102 * file_cbfs_find() - Find a file with a particular name in CBFS.
Gabe Black84cd9322012-10-12 14:26:11 +0000103 *
Simon Glasse3ff7972012-11-05 12:16:25 +0000104 * @name: The name to search for.
Gabe Black84cd9322012-10-12 14:26:11 +0000105 *
106 * @return A handle to the file, or NULL on error.
107 */
108const 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
Simon Glasse3ff7972012-11-05 12:16:25 +0000115/**
116 * file_cbfs_find_uncached() - Find a file with a particular name in CBFS
117 * without using the heap.
Gabe Black84cd9322012-10-12 14:26:11 +0000118 *
Simon Glasse3ff7972012-11-05 12:16:25 +0000119 * @end_of_rom: Points to the end of the ROM the CBFS should be read
Gabe Black84cd9322012-10-12 14:26:11 +0000120 * from.
Simon Glasse3ff7972012-11-05 12:16:25 +0000121 * @name: The name to search for.
Gabe Black84cd9322012-10-12 14:26:11 +0000122 *
123 * @return A handle to the file, or NULL on error.
124 */
125const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
126 const char *name);
127
Simon Glasse3ff7972012-11-05 12:16:25 +0000128/**
129 * file_cbfs_name() - Get the name of a file in CBFS.
Gabe Black84cd9322012-10-12 14:26:11 +0000130 *
Simon Glasse3ff7972012-11-05 12:16:25 +0000131 * @file: The handle to the file.
Gabe Black84cd9322012-10-12 14:26:11 +0000132 *
133 * @return The name of the file, NULL on error.
134 */
135const char *file_cbfs_name(const struct cbfs_cachenode *file);
136
Simon Glasse3ff7972012-11-05 12:16:25 +0000137/**
138 * file_cbfs_size() - Get the size of a file in CBFS.
Gabe Black84cd9322012-10-12 14:26:11 +0000139 *
Simon Glasse3ff7972012-11-05 12:16:25 +0000140 * @file: The handle to the file.
Gabe Black84cd9322012-10-12 14:26:11 +0000141 *
142 * @return The size of the file, zero on error.
143 */
144u32 file_cbfs_size(const struct cbfs_cachenode *file);
145
Simon Glasse3ff7972012-11-05 12:16:25 +0000146/**
147 * file_cbfs_type() - Get the type of a file in CBFS.
Gabe Black84cd9322012-10-12 14:26:11 +0000148 *
Simon Glasse3ff7972012-11-05 12:16:25 +0000149 * @file: The handle to the file.
Gabe Black84cd9322012-10-12 14:26:11 +0000150 *
151 * @return The type of the file, zero on error.
152 */
153u32 file_cbfs_type(const struct cbfs_cachenode *file);
154
Simon Glasse3ff7972012-11-05 12:16:25 +0000155/**
156 * file_cbfs_read() - Read a file from CBFS into RAM
Gabe Black84cd9322012-10-12 14:26:11 +0000157 *
Simon Glasse3ff7972012-11-05 12:16:25 +0000158 * @file: A handle to the file to read.
159 * @buffer: Where to read it into memory.
160 * @maxsize: Maximum number of bytes to read
Gabe Black84cd9322012-10-12 14:26:11 +0000161 *
162 * @return If positive or zero, the number of characters read. If negative, an
Simon Glasse3ff7972012-11-05 12:16:25 +0000163 * error occurred.
Gabe Black84cd9322012-10-12 14:26:11 +0000164 */
165long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
166 unsigned long maxsize);
167
168#endif /* __CBFS_H */