Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 1 | /* |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 2 | * cbfstool |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 18 | */ |
| 19 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 20 | #ifndef _CBFS_H_ |
| 21 | #define _CBFS_H_ |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 22 | |
| 23 | /** These are standard values for the known compression |
| 24 | alogrithms that coreboot knows about for stages and |
| 25 | payloads. Of course, other LAR users can use whatever |
| 26 | values they want, as long as they understand them. */ |
| 27 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 28 | #define CBFS_COMPRESS_NONE 0 |
| 29 | #define CBFS_COMPRESS_LZMA 1 |
| 30 | #define CBFS_COMPRESS_NRV2B 2 |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 31 | |
| 32 | /** These are standard component types for well known |
| 33 | components (i.e - those that coreboot needs to consume. |
| 34 | Users are welcome to use any other value for their |
| 35 | components */ |
| 36 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 37 | #define CBFS_COMPONENT_STAGE 0x10 |
| 38 | #define CBFS_COMPONENT_PAYLOAD 0x20 |
| 39 | #define CBFS_COMPONENT_OPTIONROM 0x30 |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 40 | |
Ronald G. Minnich | 83b8f0c | 2009-05-08 19:23:00 +0000 | [diff] [blame] | 41 | /* The deleted type is chosen to be a value |
| 42 | * that can be written in a FLASH from all other |
| 43 | * values. |
| 44 | */ |
| 45 | #define CBFS_COMPONENT_DELETED 0 |
| 46 | |
| 47 | /* for all known FLASH, this value can be changed |
| 48 | * to all other values. This allows NULL files to be |
| 49 | * changed without a block erase |
| 50 | */ |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 51 | #define CBFS_COMPONENT_NULL 0xFFFFFFFF |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 52 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 53 | /** this is the master cbfs header - it need to be |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 54 | located somewhere in the bootblock. Where it |
| 55 | actually lives is up to coreboot. A pointer to |
| 56 | this header will live at 0xFFFFFFF4, so we can |
| 57 | easily find it. */ |
| 58 | |
| 59 | #define HEADER_MAGIC 0x4F524243 |
| 60 | |
| 61 | /* this is a version that gives the right answer in any endian-ness */ |
| 62 | #define VERSION1 0x31313131 |
| 63 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 64 | struct cbfs_header { |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 65 | unsigned int magic; |
| 66 | unsigned int version; |
| 67 | unsigned int romsize; |
| 68 | unsigned int bootblocksize; |
| 69 | unsigned int align; |
| 70 | unsigned int offset; |
| 71 | unsigned int pad[2]; |
| 72 | } __attribute__ ((packed)); |
| 73 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 74 | /** This is a component header - every entry in the CBFS |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 75 | will have this header. |
| 76 | |
| 77 | This is how the component is arranged in the ROM: |
| 78 | |
| 79 | -------------- <- 0 |
| 80 | component header |
| 81 | -------------- <- sizeof(struct component) |
| 82 | component name |
| 83 | -------------- <- offset |
| 84 | data |
| 85 | ... |
| 86 | -------------- <- offset + len |
| 87 | */ |
| 88 | |
| 89 | #define COMPONENT_MAGIC "LARCHIVE" |
| 90 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 91 | struct cbfs_file { |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 92 | char magic[8]; |
| 93 | unsigned int len; |
| 94 | unsigned int type; |
| 95 | unsigned int checksum; |
| 96 | unsigned int offset; |
| 97 | } __attribute__ ((packed)); |
| 98 | |
| 99 | /*** Component sub-headers ***/ |
| 100 | |
| 101 | /* Following are component sub-headers for the "standard" |
| 102 | component types */ |
| 103 | |
| 104 | /** This is the sub-header for stage components. Stages are |
| 105 | loaded by coreboot during the normal boot process */ |
| 106 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 107 | struct cbfs_stage { |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 108 | unsigned int compression; /** Compression type */ |
| 109 | unsigned long long entry; /** entry point */ |
| 110 | unsigned long long load; /** Where to load in memory */ |
| 111 | unsigned int len; /** length of data to load */ |
| 112 | unsigned int memlen; /** total length of object in memory */ |
| 113 | } __attribute__ ((packed)); |
| 114 | |
| 115 | /** this is the sub-header for payload components. Payloads |
| 116 | are loaded by coreboot at the end of the boot process */ |
| 117 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 118 | struct cbfs_payload_segment { |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 119 | unsigned int type; |
| 120 | unsigned int compression; |
| 121 | unsigned int offset; |
| 122 | unsigned long long load_addr; |
| 123 | unsigned int len; |
| 124 | unsigned int mem_len; |
| 125 | } __attribute__ ((packed)); |
| 126 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 127 | struct cbfs_payload { |
| 128 | struct cbfs_payload_segment segments; |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | #define PAYLOAD_SEGMENT_CODE 0x45444F43 |
| 132 | #define PAYLOAD_SEGMENT_DATA 0x41544144 |
| 133 | #define PAYLOAD_SEGMENT_BSS 0x20535342 |
| 134 | #define PAYLOAD_SEGMENT_PARAMS 0x41524150 |
| 135 | #define PAYLOAD_SEGMENT_ENTRY 0x52544E45 |
| 136 | |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 137 | #define CBFS_NAME(_c) (((unsigned char *) (_c)) + sizeof(struct cbfs_file)) |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 138 | |
| 139 | #endif |