2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * This file is dual-licensed. You can choose between:
7 * - The GNU GPL, version 2, as published by the Free Software Foundation
8 * - The revised BSD license (without advertising clause)
10 * ---------------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
23 * ---------------------------------------------------------------------------
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. The name of the author may not be used to endorse or promote products
33 * derived from this software without specific prior written permission.
35 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * ---------------------------------------------------------------------------
52 /** These are standard values for the known compression
53 alogrithms that coreboot knows about for stages and
54 payloads. Of course, other CBFS users can use whatever
55 values they want, as long as they understand them. */
57 #define CBFS_COMPRESS_NONE 0
58 #define CBFS_COMPRESS_LZMA 1
60 /** These are standard component types for well known
61 components (i.e - those that coreboot needs to consume.
62 Users are welcome to use any other value for their
65 #define CBFS_TYPE_STAGE 0x10
66 #define CBFS_TYPE_PAYLOAD 0x20
67 #define CBFS_TYPE_OPTIONROM 0x30
68 #define CBFS_TYPE_BOOTSPLASH 0x40
69 #define CBFS_TYPE_RAW 0x50
70 #define CBFS_TYPE_VSA 0x51
71 #define CBFS_TYPE_MBI 0x52
72 #define CBFS_TYPE_MICROCODE 0x53
73 #define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
74 #define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
77 /** this is the master cbfs header - it need to be
78 located somewhere in the bootblock. Where it
79 actually lives is up to coreboot. A pointer to
80 this header will live at 0xFFFFFFFc, so we can
83 #define CBFS_HEADER_MAGIC 0x4F524243
84 #define CBFS_HEADPTR_ADDR 0xFFFFFFFc
85 #define VERSION1 0x31313131
91 uint32_t bootblocksize;
95 } __attribute__((packed));
97 /** This is a component header - every entry in the CBFS
98 will have this header.
100 This is how the component is arranged in the ROM:
104 -------------- <- sizeof(struct component)
106 -------------- <- offset
109 -------------- <- offset + len
112 #define CBFS_FILE_MAGIC "LARCHIVE"
120 } __attribute__((packed));
122 /*** Component sub-headers ***/
124 /* Following are component sub-headers for the "standard"
127 /** This is the sub-header for stage components. Stages are
128 loaded by coreboot during the normal boot process */
131 uint32_t compression; /** Compression type */
132 uint64_t entry; /** entry point */
133 uint64_t load; /** Where to load in memory */
134 uint32_t len; /** length of data to load */
135 uint32_t memlen; /** total length of object in memory */
136 } __attribute__((packed));
138 /** this is the sub-header for payload components. Payloads
139 are loaded by coreboot at the end of the boot process */
141 struct cbfs_payload_segment {
143 uint32_t compression;
148 } __attribute__((packed));
150 struct cbfs_payload {
151 struct cbfs_payload_segment segments;
154 #define PAYLOAD_SEGMENT_CODE 0x45444F43
155 #define PAYLOAD_SEGMENT_DATA 0x41544144
156 #define PAYLOAD_SEGMENT_BSS 0x20535342
157 #define PAYLOAD_SEGMENT_PARAMS 0x41524150
158 #define PAYLOAD_SEGMENT_ENTRY 0x52544E45
160 struct cbfs_optionrom {
161 uint32_t compression;
163 } __attribute__((packed));
165 #define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file))
166 #define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
168 /* returns pointer to file inside CBFS or NULL */
169 struct cbfs_file *cbfs_find(const char *name);
171 /* returns pointer to file data inside CBFS */
172 void *cbfs_get_file(const char *name);
174 /* returns pointer to file data inside CBFS after if type is correct */
175 void *cbfs_find_file(const char *name, int type);
177 /* returns 0 on success, -1 on failure */
178 int cbfs_decompress(int algo, void *src, void *dst, int len);