Patrick Georgi | 269e932 | 2011-01-21 07:24:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net> |
| 5 | * |
| 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) |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
Patrick Georgi | 269e932 | 2011-01-21 07:24:08 +0000 | [diff] [blame] | 19 | * --------------------------------------------------------------------------- |
| 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * 1. Redistributions of source code must retain the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer. |
| 25 | * 2. Redistributions in binary form must reproduce the above copyright |
| 26 | * notice, this list of conditions and the following disclaimer in the |
| 27 | * documentation and/or other materials provided with the distribution. |
| 28 | * 3. The name of the author may not be used to endorse or promote products |
| 29 | * derived from this software without specific prior written permission. |
| 30 | * |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 32 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 39 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 40 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 41 | * SUCH DAMAGE. |
| 42 | * --------------------------------------------------------------------------- |
| 43 | */ |
| 44 | |
| 45 | #ifndef _CBFS_H_ |
| 46 | #define _CBFS_H_ |
| 47 | |
| 48 | #include "coreboot_tables.h" |
| 49 | |
| 50 | typedef uint64_t u64; |
| 51 | typedef uint32_t u32; |
| 52 | typedef uint16_t u16; |
| 53 | typedef uint8_t u8; |
| 54 | |
| 55 | /** These are standard values for the known compression |
| 56 | alogrithms that coreboot knows about for stages and |
| 57 | payloads. Of course, other CBFS users can use whatever |
| 58 | values they want, as long as they understand them. */ |
| 59 | |
| 60 | #define CBFS_COMPRESS_NONE 0 |
| 61 | #define CBFS_COMPRESS_LZMA 1 |
| 62 | |
| 63 | /** These are standard component types for well known |
| 64 | components (i.e - those that coreboot needs to consume. |
| 65 | Users are welcome to use any other value for their |
| 66 | components */ |
| 67 | |
| 68 | #define CBFS_TYPE_STAGE 0x10 |
| 69 | #define CBFS_TYPE_PAYLOAD 0x20 |
| 70 | #define CBFS_TYPE_OPTIONROM 0x30 |
| 71 | #define CBFS_TYPE_BOOTSPLASH 0x40 |
| 72 | #define CBFS_TYPE_RAW 0x50 |
| 73 | #define CBFS_TYPE_VSA 0x51 |
| 74 | #define CBFS_TYPE_MBI 0x52 |
| 75 | #define CBFS_TYPE_MICROCODE 0x53 |
| 76 | #define CBFS_COMPONENT_CMOS_DEFAULT 0xaa |
| 77 | #define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa |
| 78 | |
| 79 | |
| 80 | /** this is the master cbfs header - it need to be |
| 81 | located somewhere in the bootblock. Where it |
| 82 | actually lives is up to coreboot. A pointer to |
| 83 | this header will live at 0xFFFFFFFc, so we can |
| 84 | easily find it. */ |
| 85 | |
| 86 | #define CBFS_HEADER_MAGIC 0x4F524243 |
| 87 | #define CBFS_HEADPTR_ADDR 0xFFFFFFFc |
Hung-Te Lin | 086842a | 2013-01-04 12:33:03 +0800 | [diff] [blame] | 88 | #define CBFS_HEADER_VERSION1 0x31313131 |
Patrick Georgi | 269e932 | 2011-01-21 07:24:08 +0000 | [diff] [blame] | 89 | |
| 90 | struct cbfs_header { |
| 91 | u32 magic; |
| 92 | u32 version; |
| 93 | u32 romsize; |
| 94 | u32 bootblocksize; |
| 95 | u32 align; |
| 96 | u32 offset; |
| 97 | u32 pad[2]; |
| 98 | } __attribute__((packed)); |
| 99 | |
| 100 | /** This is a component header - every entry in the CBFS |
| 101 | will have this header. |
| 102 | |
| 103 | This is how the component is arranged in the ROM: |
| 104 | |
| 105 | -------------- <- 0 |
| 106 | component header |
| 107 | -------------- <- sizeof(struct component) |
| 108 | component name |
| 109 | -------------- <- offset |
| 110 | data |
| 111 | ... |
| 112 | -------------- <- offset + len |
| 113 | */ |
| 114 | |
| 115 | #define CBFS_FILE_MAGIC "LARCHIVE" |
| 116 | |
| 117 | struct cbfs_file { |
| 118 | char magic[8]; |
| 119 | u32 len; |
| 120 | u32 type; |
| 121 | u32 checksum; |
| 122 | u32 offset; |
| 123 | } __attribute__((packed)); |
| 124 | |
| 125 | /*** Component sub-headers ***/ |
| 126 | |
| 127 | /* Following are component sub-headers for the "standard" |
| 128 | component types */ |
| 129 | |
| 130 | /** This is the sub-header for stage components. Stages are |
| 131 | loaded by coreboot during the normal boot process */ |
| 132 | |
| 133 | struct cbfs_stage { |
| 134 | u32 compression; /** Compression type */ |
| 135 | u64 entry; /** entry point */ |
| 136 | u64 load; /** Where to load in memory */ |
| 137 | u32 len; /** length of data to load */ |
| 138 | u32 memlen; /** total length of object in memory */ |
| 139 | } __attribute__((packed)); |
| 140 | |
| 141 | /** this is the sub-header for payload components. Payloads |
| 142 | are loaded by coreboot at the end of the boot process */ |
| 143 | |
| 144 | struct cbfs_payload_segment { |
| 145 | u32 type; |
| 146 | u32 compression; |
| 147 | u32 offset; |
| 148 | u64 load_addr; |
| 149 | u32 len; |
| 150 | u32 mem_len; |
| 151 | } __attribute__((packed)); |
| 152 | |
| 153 | struct cbfs_payload { |
| 154 | struct cbfs_payload_segment segments; |
| 155 | }; |
| 156 | |
| 157 | #define PAYLOAD_SEGMENT_CODE 0x45444F43 |
| 158 | #define PAYLOAD_SEGMENT_DATA 0x41544144 |
| 159 | #define PAYLOAD_SEGMENT_BSS 0x20535342 |
| 160 | #define PAYLOAD_SEGMENT_PARAMS 0x41524150 |
| 161 | #define PAYLOAD_SEGMENT_ENTRY 0x52544E45 |
| 162 | |
| 163 | struct cbfs_optionrom { |
| 164 | u32 compression; |
| 165 | u32 len; |
| 166 | } __attribute__((packed)); |
| 167 | |
| 168 | #define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file)) |
| 169 | #define CBFS_SUBHEADER(_p) ( (void *) ((((u8 *) (_p)) + ntohl((_p)->offset))) ) |
| 170 | |
| 171 | void * cbfs_get_file(const char *name); |
| 172 | struct cbfs_file *cbfs_find(const char *name); |
| 173 | void *cbfs_find_file(const char *name, unsigned int type, unsigned int *len); |
| 174 | |
| 175 | void open_cbfs(const char *filename); |
| 176 | #endif |