Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +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. |
| 19 | * |
| 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 |
| 26 | * are met: |
| 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. |
| 34 | * |
| 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 |
| 45 | * SUCH DAMAGE. |
| 46 | * --------------------------------------------------------------------------- |
| 47 | */ |
| 48 | |
| 49 | #ifndef _CBFS_H_ |
| 50 | #define _CBFS_H_ |
| 51 | |
| 52 | /** These are standard values for the known compression |
| 53 | alogrithms that coreboot knows about for stages and |
| 54 | payloads. Of course, other LAR users can use whatever |
| 55 | values they want, as long as they understand them. */ |
| 56 | |
| 57 | #define CBFS_COMPRESS_NONE 0 |
| 58 | #define CBFS_COMPRESS_LZMA 1 |
| 59 | #define CBFS_COMPRESS_NRV2B 2 |
| 60 | |
| 61 | /** These are standard component types for well known |
| 62 | components (i.e - those that coreboot needs to consume. |
| 63 | Users are welcome to use any other value for their |
| 64 | components */ |
| 65 | |
| 66 | #define CBFS_TYPE_STAGE 0x10 |
| 67 | #define CBFS_TYPE_PAYLOAD 0x20 |
| 68 | #define CBFS_TYPE_OPTIONROM 0x30 |
| 69 | |
| 70 | /** this is the master cbfs header - it need to be |
| 71 | located somewhere in the bootblock. Where it |
| 72 | actually lives is up to coreboot. A pointer to |
| 73 | this header will live at 0xFFFFFFFc, so we can |
| 74 | easily find it. */ |
| 75 | |
| 76 | #define CBFS_HEADER_MAGIC 0x4F524243 |
| 77 | #define CBFS_HEADPTR_ADDR 0xFFFFFFFc |
| 78 | #define VERSION1 0x31313131 |
| 79 | |
| 80 | struct cbfs_header { |
| 81 | u32 magic; |
| 82 | u32 version; |
| 83 | u32 romsize; |
| 84 | u32 bootblocksize; |
| 85 | u32 align; |
| 86 | u32 offset; |
| 87 | u32 pad[2]; |
| 88 | } __attribute__((packed)); |
| 89 | |
| 90 | /** This is a component header - every entry in the CBFS |
| 91 | will have this header. |
| 92 | |
| 93 | This is how the component is arranged in the ROM: |
| 94 | |
| 95 | -------------- <- 0 |
| 96 | component header |
| 97 | -------------- <- sizeof(struct component) |
| 98 | component name |
| 99 | -------------- <- offset |
| 100 | data |
| 101 | ... |
| 102 | -------------- <- offset + len |
| 103 | */ |
| 104 | |
| 105 | #define CBFS_FILE_MAGIC "LARCHIVE" |
| 106 | |
| 107 | struct cbfs_file { |
| 108 | char magic[8]; |
| 109 | u32 len; |
| 110 | u32 type; |
| 111 | u32 checksum; |
| 112 | u32 offset; |
| 113 | } __attribute__((packed)); |
| 114 | |
| 115 | /*** Component sub-headers ***/ |
| 116 | |
| 117 | /* Following are component sub-headers for the "standard" |
| 118 | component types */ |
| 119 | |
| 120 | /** This is the sub-header for stage components. Stages are |
| 121 | loaded by coreboot during the normal boot process */ |
| 122 | |
| 123 | struct cbfs_stage { |
| 124 | u32 compression; /** Compression type */ |
| 125 | u64 entry; /** entry point */ |
| 126 | u64 load; /** Where to load in memory */ |
| 127 | u32 len; /** length of data to load */ |
| 128 | u32 memlen; /** total length of object in memory */ |
| 129 | } __attribute__((packed)); |
| 130 | |
| 131 | /** this is the sub-header for payload components. Payloads |
| 132 | are loaded by coreboot at the end of the boot process */ |
| 133 | |
| 134 | struct cbfs_payload_segment { |
| 135 | u32 type; |
| 136 | u32 compression; |
| 137 | u32 offset; |
| 138 | u64 load_addr; |
| 139 | u32 len; |
| 140 | u32 mem_len; |
| 141 | } __attribute__((packed)); |
| 142 | |
| 143 | struct cbfs_payload { |
| 144 | struct cbfs_payload_segment segments; |
| 145 | }; |
| 146 | |
| 147 | #define PAYLOAD_SEGMENT_CODE 0x45444F43 |
| 148 | #define PAYLOAD_SEGMENT_DATA 0x41544144 |
| 149 | #define PAYLOAD_SEGMENT_BSS 0x20535342 |
| 150 | #define PAYLOAD_SEGMENT_PARAMS 0x41524150 |
| 151 | #define PAYLOAD_SEGMENT_ENTRY 0x52544E45 |
| 152 | |
| 153 | struct cbfs_optionrom { |
| 154 | u32 compression; |
| 155 | u32 len; |
| 156 | } __attribute__((packed)); |
| 157 | |
| 158 | #define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file)) |
| 159 | #define CBFS_SUBHEADER(_p) ( (void *) ((((u8 *) (_p)) + ntohl((_p)->offset))) ) |
| 160 | |
| 161 | void * cbfs_load_payload(struct lb_memory *lb_mem, const char *name); |
| 162 | void * cbfs_load_stage(const char *name); |
| 163 | int cbfs_execute_stage(const char *name); |
| 164 | void * cbfs_get_file(const char *name); |
| 165 | void *cbfs_load_optionrom(u16 vendor, u16 device, void * dest); |
| 166 | int run_address(void *f); |
| 167 | |
| 168 | #endif |
| 169 | |