Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 1 | /* |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 2 | * Copyright (C) 2009 coresystems GmbH |
| 3 | * written by Patrick Georgi <patrick.georgi@coresystems.de> |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 16 | * Foundation, Inc. |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 19 | #ifndef __CBFS_H |
| 20 | #define __CBFS_H |
| 21 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 22 | #include <stdint.h> |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 23 | |
Patrick Georgi | 2c61506 | 2015-07-15 20:49:00 +0200 | [diff] [blame] | 24 | /* cbfstool will fail when trying to build a cbfs_file header that's larger |
| 25 | * than MAX_CBFS_FILE_HEADER_BUFFER. 1K should give plenty of room. */ |
| 26 | #define MAX_CBFS_FILE_HEADER_BUFFER 1024 |
| 27 | |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 28 | /* create a magic number in host-byte order. |
| 29 | * b3 is the high order byte. |
| 30 | * in the coreboot tools, we go with the 32-bit |
| 31 | * magic number convention. |
| 32 | * This was an inline func but that breaks anything |
| 33 | * that uses it in a case statement. |
| 34 | */ |
| 35 | |
| 36 | #define makemagic(b3, b2, b1, b0)\ |
| 37 | (((b3)<<24) | ((b2) << 16) | ((b1) << 8) | (b0)) |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 38 | |
Stefan Reinauer | cfa9b99 | 2015-07-04 11:30:59 -0700 | [diff] [blame] | 39 | #if defined(__WIN32) || defined(__WIN64) |
| 40 | #define __PACKED __attribute__((gcc_struct, packed)) |
| 41 | #else |
| 42 | #define __PACKED __attribute__((packed)) |
| 43 | #endif |
| 44 | |
Patrick Georgi | 2062473 | 2015-07-17 21:35:46 +0200 | [diff] [blame] | 45 | /* To make CBFS more friendly to ROM, fill -1 (0xFF) instead of zero. */ |
| 46 | #define CBFS_CONTENT_DEFAULT_VALUE (-1) |
| 47 | |
Sol Boucher | 67a0a86 | 2015-03-18 12:36:27 -0700 | [diff] [blame] | 48 | // Alignment (in bytes) to be used when no master header is present |
| 49 | #define CBFS_ENTRY_ALIGNMENT 64 |
| 50 | |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 51 | #define CBFS_HEADER_MAGIC 0x4F524243 |
| 52 | #define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC |
Hung-Te Lin | 086842a | 2013-01-04 12:33:03 +0800 | [diff] [blame] | 53 | #define CBFS_HEADER_VERSION1 0x31313131 |
| 54 | #define CBFS_HEADER_VERSION2 0x31313132 |
| 55 | #define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2 |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 56 | |
Patrick Georgi | 45acb34 | 2015-07-14 22:18:23 +0200 | [diff] [blame] | 57 | #define CBFS_ALIGNMENT 64 |
| 58 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 59 | struct cbfs_header { |
| 60 | uint32_t magic; |
| 61 | uint32_t version; |
| 62 | uint32_t romsize; |
| 63 | uint32_t bootblocksize; |
Patrick Georgi | 45acb34 | 2015-07-14 22:18:23 +0200 | [diff] [blame] | 64 | uint32_t align; /* hard coded to 64 byte */ |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 65 | uint32_t offset; |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 66 | uint32_t architecture; /* Version 2 */ |
| 67 | uint32_t pad[1]; |
Stefan Reinauer | cfa9b99 | 2015-07-04 11:30:59 -0700 | [diff] [blame] | 68 | } __PACKED; |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 69 | |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 70 | #define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF |
| 71 | #define CBFS_ARCHITECTURE_X86 0x00000001 |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 72 | #define CBFS_ARCHITECTURE_ARM 0x00000010 |
Ronald G. Minnich | 5f43184 | 2013-11-12 09:03:33 -0800 | [diff] [blame] | 73 | #define CBFS_ARCHITECTURE_AARCH64 0x0000aa64 |
Paul Burton | 3318692 | 2014-06-13 23:56:45 +0100 | [diff] [blame] | 74 | #define CBFS_ARCHITECTURE_MIPS 0x00000100 |
Ronald G. Minnich | 833bf20 | 2014-10-16 10:55:39 +0000 | [diff] [blame] | 75 | #define CBFS_ARCHITECTURE_RISCV 0xc001d0de |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 76 | |
Hung-Te Lin | eab2c81 | 2013-01-29 01:56:17 +0800 | [diff] [blame] | 77 | #define CBFS_FILE_MAGIC "LARCHIVE" |
| 78 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 79 | struct cbfs_file { |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 80 | uint8_t magic[8]; |
Patrick Georgi | 5dc01ac | 2015-07-15 16:40:44 +0200 | [diff] [blame] | 81 | /* length of file data */ |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 82 | uint32_t len; |
| 83 | uint32_t type; |
Patrick Georgi | 2c61506 | 2015-07-15 20:49:00 +0200 | [diff] [blame] | 84 | /* offset to struct cbfs_file_attribute or 0 */ |
Patrick Georgi | 0d618af | 2015-07-15 18:28:23 +0200 | [diff] [blame] | 85 | uint32_t attributes_offset; |
Patrick Georgi | 5dc01ac | 2015-07-15 16:40:44 +0200 | [diff] [blame] | 86 | /* length of header incl. variable data */ |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 87 | uint32_t offset; |
Patrick Georgi | c569b8b | 2015-07-15 16:42:38 +0200 | [diff] [blame] | 88 | char filename[]; |
Stefan Reinauer | cfa9b99 | 2015-07-04 11:30:59 -0700 | [diff] [blame] | 89 | } __PACKED; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 90 | |
Patrick Georgi | ab5754d | 2015-09-01 18:20:20 +0200 | [diff] [blame] | 91 | #if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 |
Patrick Georgi | 5dc01ac | 2015-07-15 16:40:44 +0200 | [diff] [blame] | 92 | _Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch"); |
Patrick Georgi | 57c67e5 | 2015-09-01 12:37:41 +0200 | [diff] [blame] | 93 | #endif |
Patrick Georgi | 5dc01ac | 2015-07-15 16:40:44 +0200 | [diff] [blame] | 94 | |
Patrick Georgi | c6a8da7 | 2015-07-22 21:32:03 +0200 | [diff] [blame] | 95 | /* The common fields of extended cbfs file attributes. |
| 96 | Attributes are expected to start with tag/len, then append their |
| 97 | specific fields. */ |
| 98 | struct cbfs_file_attribute { |
| 99 | uint32_t tag; |
| 100 | /* len covers the whole structure, incl. tag and len */ |
| 101 | uint32_t len; |
| 102 | uint8_t data[0]; |
| 103 | } __PACKED; |
| 104 | |
Patrick Georgi | 2c61506 | 2015-07-15 20:49:00 +0200 | [diff] [blame] | 105 | /* Depending on how the header was initialized, it may be backed with 0x00 or |
| 106 | * 0xff. Support both. */ |
| 107 | #define CBFS_FILE_ATTR_TAG_UNUSED 0 |
| 108 | #define CBFS_FILE_ATTR_TAG_UNUSED2 0xffffffff |
Daisuke Nojiri | 8984a63 | 2015-07-09 15:07:45 -0700 | [diff] [blame] | 109 | #define CBFS_FILE_ATTR_TAG_COMPRESSION 0x42435a4c |
| 110 | |
| 111 | struct cbfs_file_attr_compression { |
| 112 | uint32_t tag; |
| 113 | uint32_t len; |
| 114 | /* whole file compression format. 0 if no compression. */ |
| 115 | uint32_t compression; |
| 116 | uint32_t decompressed_size; |
| 117 | } __PACKED; |
Patrick Georgi | 2c61506 | 2015-07-15 20:49:00 +0200 | [diff] [blame] | 118 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 119 | struct cbfs_stage { |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 120 | uint32_t compression; |
| 121 | uint64_t entry; |
| 122 | uint64_t load; |
| 123 | uint32_t len; |
| 124 | uint32_t memlen; |
Stefan Reinauer | cfa9b99 | 2015-07-04 11:30:59 -0700 | [diff] [blame] | 125 | } __PACKED; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 126 | |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 127 | #define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E') |
| 128 | #define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A') |
Wei Hu | 2ad6ee9 | 2014-04-16 22:52:59 -0700 | [diff] [blame] | 129 | #define PAYLOAD_SEGMENT_BSS makemagic('B', 'S', 'S', ' ') |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 130 | #define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A') |
| 131 | #define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R') |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 132 | |
| 133 | struct cbfs_payload_segment { |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 134 | uint32_t type; |
| 135 | uint32_t compression; |
| 136 | uint32_t offset; |
| 137 | uint64_t load_addr; |
| 138 | uint32_t len; |
| 139 | uint32_t mem_len; |
Stefan Reinauer | cfa9b99 | 2015-07-04 11:30:59 -0700 | [diff] [blame] | 140 | } __PACKED; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 141 | |
| 142 | struct cbfs_payload { |
| 143 | struct cbfs_payload_segment segments; |
Stefan Reinauer | cfa9b99 | 2015-07-04 11:30:59 -0700 | [diff] [blame] | 144 | } __PACKED; |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 145 | |
| 146 | /** These are standard component types for well known |
| 147 | components (i.e - those that coreboot needs to consume. |
| 148 | Users are welcome to use any other value for their |
| 149 | components */ |
| 150 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 151 | #define CBFS_COMPONENT_STAGE 0x10 |
| 152 | #define CBFS_COMPONENT_PAYLOAD 0x20 |
| 153 | #define CBFS_COMPONENT_OPTIONROM 0x30 |
| 154 | #define CBFS_COMPONENT_BOOTSPLASH 0x40 |
| 155 | #define CBFS_COMPONENT_RAW 0x50 |
| 156 | #define CBFS_COMPONENT_VSA 0x51 |
| 157 | #define CBFS_COMPONENT_MBI 0x52 |
| 158 | #define CBFS_COMPONENT_MICROCODE 0x53 |
Martin Roth | dde307c | 2015-03-24 15:54:20 -0600 | [diff] [blame] | 159 | #define CBFS_COMPONENT_FSP 0x60 |
| 160 | #define CBFS_COMPONENT_MRC 0x61 |
Patrick Georgi | a865b17 | 2011-01-14 07:40:24 +0000 | [diff] [blame] | 161 | #define CBFS_COMPONENT_CMOS_DEFAULT 0xaa |
Martin Roth | dde307c | 2015-03-24 15:54:20 -0600 | [diff] [blame] | 162 | #define CBFS_COMPONENT_SPD 0xab |
| 163 | #define CBFS_COMPONENT_MRC_CACHE 0xac |
Patrick Georgi | 2447937 | 2011-01-18 13:56:36 +0000 | [diff] [blame] | 164 | #define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 165 | |
Ronald G. Minnich | 83b8f0c | 2009-05-08 19:23:00 +0000 | [diff] [blame] | 166 | /* The deleted type is chosen to be a value |
| 167 | * that can be written in a FLASH from all other |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 168 | * values. |
Ronald G. Minnich | 83b8f0c | 2009-05-08 19:23:00 +0000 | [diff] [blame] | 169 | */ |
| 170 | #define CBFS_COMPONENT_DELETED 0 |
| 171 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 172 | /* for all known FLASH, this value can be changed |
| 173 | * to all other values. This allows NULL files to be |
Ronald G. Minnich | 83b8f0c | 2009-05-08 19:23:00 +0000 | [diff] [blame] | 174 | * changed without a block erase |
| 175 | */ |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 176 | #define CBFS_COMPONENT_NULL 0xFFFFFFFF |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 177 | |
Stefan Reinauer | db5b893 | 2013-01-18 15:53:22 -0800 | [diff] [blame] | 178 | #define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) ) |
Patrick Georgi | 2c61506 | 2015-07-15 20:49:00 +0200 | [diff] [blame] | 179 | |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 180 | /* cbfs_image.c */ |
| 181 | uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value); |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 182 | uint32_t get_cbfs_compression(const char *name, uint32_t unknown); |
Stefan Reinauer | db5b893 | 2013-01-18 15:53:22 -0800 | [diff] [blame] | 183 | |
Ronald G. Minnich | 3fcde22 | 2014-02-04 17:35:44 -0800 | [diff] [blame] | 184 | /* common.c */ |
| 185 | void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file); |
| 186 | |
Ronald G. Minnich | 818f369 | 2014-02-04 08:29:35 -0800 | [diff] [blame] | 187 | /* cbfs-mkpayload.c */ |
| 188 | void xdr_segs(struct buffer *output, |
| 189 | struct cbfs_payload_segment *segs, int nseg); |
Aaron Durbin | ca63027 | 2014-08-05 10:48:20 -0500 | [diff] [blame] | 190 | void xdr_get_seg(struct cbfs_payload_segment *out, |
| 191 | struct cbfs_payload_segment *in); |
Ronald G. Minnich | 818f369 | 2014-02-04 08:29:35 -0800 | [diff] [blame] | 192 | |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 193 | #endif |