blob: d77504a2bb7032102edee28012bc379b612ad0dd [file] [log] [blame]
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +00001/*
Patrick Georgib7b56dd82009-09-14 13:29:27 +00002 * Copyright (C) 2009 coresystems GmbH
3 * written by Patrick Georgi <patrick.georgi@coresystems.de>
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +00004 *
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.
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000013 */
14
Stefan Reinauer63217582012-10-29 16:52:36 -070015#ifndef __CBFS_H
16#define __CBFS_H
17
Patrick Georgi89f20342015-10-01 15:54:04 +020018#include "common.h"
Patrick Georgib7b56dd82009-09-14 13:29:27 +000019#include <stdint.h>
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080020
Patrick Georgi89f20342015-10-01 15:54:04 +020021#include <vb2_api.h>
22
Patrick Georgi2c615062015-07-15 20:49:00 +020023/* cbfstool will fail when trying to build a cbfs_file header that's larger
24 * than MAX_CBFS_FILE_HEADER_BUFFER. 1K should give plenty of room. */
25#define MAX_CBFS_FILE_HEADER_BUFFER 1024
26
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080027/* create a magic number in host-byte order.
28 * b3 is the high order byte.
29 * in the coreboot tools, we go with the 32-bit
30 * magic number convention.
31 * This was an inline func but that breaks anything
32 * that uses it in a case statement.
33 */
34
35#define makemagic(b3, b2, b1, b0)\
36 (((b3)<<24) | ((b2) << 16) | ((b1) << 8) | (b0))
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000037
Stefan Reinauercfa9b992015-07-04 11:30:59 -070038#if defined(__WIN32) || defined(__WIN64)
39#define __PACKED __attribute__((gcc_struct, packed))
40#else
41#define __PACKED __attribute__((packed))
42#endif
43
Patrick Georgi20624732015-07-17 21:35:46 +020044/* To make CBFS more friendly to ROM, fill -1 (0xFF) instead of zero. */
45#define CBFS_CONTENT_DEFAULT_VALUE (-1)
46
Sol Boucher67a0a862015-03-18 12:36:27 -070047// Alignment (in bytes) to be used when no master header is present
48#define CBFS_ENTRY_ALIGNMENT 64
49
David Hendricks90ca3b62012-11-16 14:48:22 -080050#define CBFS_HEADER_MAGIC 0x4F524243
51#define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC
Hung-Te Lin086842a2013-01-04 12:33:03 +080052#define CBFS_HEADER_VERSION1 0x31313131
53#define CBFS_HEADER_VERSION2 0x31313132
54#define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2
David Hendricks90ca3b62012-11-16 14:48:22 -080055
Patrick Georgi45acb342015-07-14 22:18:23 +020056#define CBFS_ALIGNMENT 64
57
Patrick Georgib7b56dd82009-09-14 13:29:27 +000058struct cbfs_header {
59 uint32_t magic;
60 uint32_t version;
61 uint32_t romsize;
62 uint32_t bootblocksize;
Patrick Georgi45acb342015-07-14 22:18:23 +020063 uint32_t align; /* hard coded to 64 byte */
Patrick Georgib7b56dd82009-09-14 13:29:27 +000064 uint32_t offset;
David Hendricks90ca3b62012-11-16 14:48:22 -080065 uint32_t architecture; /* Version 2 */
66 uint32_t pad[1];
Stefan Reinauercfa9b992015-07-04 11:30:59 -070067} __PACKED;
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000068
David Hendricks90ca3b62012-11-16 14:48:22 -080069#define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF
70#define CBFS_ARCHITECTURE_X86 0x00000001
Gabe Black51edd542013-09-30 23:00:33 -070071#define CBFS_ARCHITECTURE_ARM 0x00000010
Ronald G. Minnich5f431842013-11-12 09:03:33 -080072#define CBFS_ARCHITECTURE_AARCH64 0x0000aa64
Paul Burton33186922014-06-13 23:56:45 +010073#define CBFS_ARCHITECTURE_MIPS 0x00000100
Ronald G. Minnich833bf202014-10-16 10:55:39 +000074#define CBFS_ARCHITECTURE_RISCV 0xc001d0de
Ronald G. Minniched4aa042015-12-11 18:19:52 +000075#define CBFS_ARCHITECTURE_PPC64 0x407570ff
David Hendricks90ca3b62012-11-16 14:48:22 -080076
Hung-Te Lineab2c812013-01-29 01:56:17 +080077#define CBFS_FILE_MAGIC "LARCHIVE"
78
Patrick Georgib7b56dd82009-09-14 13:29:27 +000079struct cbfs_file {
Stefan Reinauera1e48242011-10-21 14:24:57 -070080 uint8_t magic[8];
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020081 /* length of file data */
Patrick Georgib7b56dd82009-09-14 13:29:27 +000082 uint32_t len;
83 uint32_t type;
Patrick Georgi2c615062015-07-15 20:49:00 +020084 /* offset to struct cbfs_file_attribute or 0 */
Patrick Georgi0d618af2015-07-15 18:28:23 +020085 uint32_t attributes_offset;
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020086 /* length of header incl. variable data */
Patrick Georgib7b56dd82009-09-14 13:29:27 +000087 uint32_t offset;
Patrick Georgic569b8b2015-07-15 16:42:38 +020088 char filename[];
Stefan Reinauercfa9b992015-07-04 11:30:59 -070089} __PACKED;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000090
Patrick Georgiab5754d2015-09-01 18:20:20 +020091#if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020092_Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch");
Patrick Georgi57c67e52015-09-01 12:37:41 +020093#endif
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020094
Patrick Georgic6a8da72015-07-22 21:32:03 +020095/* The common fields of extended cbfs file attributes.
96 Attributes are expected to start with tag/len, then append their
97 specific fields. */
98struct 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 Georgi2c615062015-07-15 20:49:00 +0200105/* 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 Nojiri8984a632015-07-09 15:07:45 -0700109#define CBFS_FILE_ATTR_TAG_COMPRESSION 0x42435a4c
Patrick Georgi89f20342015-10-01 15:54:04 +0200110#define CBFS_FILE_ATTR_TAG_HASH 0x68736148
Daisuke Nojiri8984a632015-07-09 15:07:45 -0700111
112struct cbfs_file_attr_compression {
113 uint32_t tag;
114 uint32_t len;
115 /* whole file compression format. 0 if no compression. */
116 uint32_t compression;
117 uint32_t decompressed_size;
118} __PACKED;
Patrick Georgi2c615062015-07-15 20:49:00 +0200119
Patrick Georgi89f20342015-10-01 15:54:04 +0200120struct cbfs_file_attr_hash {
121 uint32_t tag;
122 uint32_t len;
123 uint32_t hash_type;
124 /* hash_data is len - sizeof(struct) bytes */
125 uint8_t hash_data[];
126} __PACKED;
127
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000128struct cbfs_stage {
Stefan Reinauera1e48242011-10-21 14:24:57 -0700129 uint32_t compression;
130 uint64_t entry;
131 uint64_t load;
132 uint32_t len;
133 uint32_t memlen;
Stefan Reinauercfa9b992015-07-04 11:30:59 -0700134} __PACKED;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000135
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800136#define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E')
137#define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A')
Wei Hu2ad6ee92014-04-16 22:52:59 -0700138#define PAYLOAD_SEGMENT_BSS makemagic('B', 'S', 'S', ' ')
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800139#define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A')
140#define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R')
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000141
142struct cbfs_payload_segment {
Stefan Reinauera1e48242011-10-21 14:24:57 -0700143 uint32_t type;
144 uint32_t compression;
145 uint32_t offset;
146 uint64_t load_addr;
147 uint32_t len;
148 uint32_t mem_len;
Stefan Reinauercfa9b992015-07-04 11:30:59 -0700149} __PACKED;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000150
151struct cbfs_payload {
152 struct cbfs_payload_segment segments;
Stefan Reinauercfa9b992015-07-04 11:30:59 -0700153} __PACKED;
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000154
155/** These are standard component types for well known
156 components (i.e - those that coreboot needs to consume.
157 Users are welcome to use any other value for their
158 components */
159
Patrick Georgi239c7422015-09-09 20:11:26 +0200160#define CBFS_COMPONENT_BOOTBLOCK 0x01
161#define CBFS_COMPONENT_CBFSHEADER 0x02
Stefan Reinauer800379f2010-03-01 08:34:19 +0000162#define CBFS_COMPONENT_STAGE 0x10
163#define CBFS_COMPONENT_PAYLOAD 0x20
164#define CBFS_COMPONENT_OPTIONROM 0x30
165#define CBFS_COMPONENT_BOOTSPLASH 0x40
166#define CBFS_COMPONENT_RAW 0x50
167#define CBFS_COMPONENT_VSA 0x51
168#define CBFS_COMPONENT_MBI 0x52
169#define CBFS_COMPONENT_MICROCODE 0x53
Martin Rothdde307c2015-03-24 15:54:20 -0600170#define CBFS_COMPONENT_FSP 0x60
171#define CBFS_COMPONENT_MRC 0x61
Pratik Prajapatifb128732015-09-02 13:46:30 -0700172#define CBFS_COMPONENT_MMA 0x62
173#define CBFS_COMPONENT_EFI 0x63
Patrick Georgia865b172011-01-14 07:40:24 +0000174#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
Martin Rothdde307c2015-03-24 15:54:20 -0600175#define CBFS_COMPONENT_SPD 0xab
176#define CBFS_COMPONENT_MRC_CACHE 0xac
Patrick Georgi24479372011-01-18 13:56:36 +0000177#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000178
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000179/* The deleted type is chosen to be a value
180 * that can be written in a FLASH from all other
Stefan Reinauer14e22772010-04-27 06:56:47 +0000181 * values.
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000182 */
183#define CBFS_COMPONENT_DELETED 0
184
Stefan Reinauer14e22772010-04-27 06:56:47 +0000185/* for all known FLASH, this value can be changed
186 * to all other values. This allows NULL files to be
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000187 * changed without a block erase
188 */
Peter Stuge1d862de2009-04-14 00:08:34 +0000189#define CBFS_COMPONENT_NULL 0xFFFFFFFF
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000190
Patrick Georgidc37dab2015-09-09 16:46:00 +0200191struct typedesc_t {
192 uint32_t type;
193 const char *name;
194};
195
196static struct typedesc_t filetypes[] unused = {
Patrick Georgi239c7422015-09-09 20:11:26 +0200197 {CBFS_COMPONENT_BOOTBLOCK, "bootblock"},
198 {CBFS_COMPONENT_CBFSHEADER, "cbfs header"},
Patrick Georgidc37dab2015-09-09 16:46:00 +0200199 {CBFS_COMPONENT_STAGE, "stage"},
200 {CBFS_COMPONENT_PAYLOAD, "payload"},
201 {CBFS_COMPONENT_OPTIONROM, "optionrom"},
202 {CBFS_COMPONENT_BOOTSPLASH, "bootsplash"},
203 {CBFS_COMPONENT_RAW, "raw"},
204 {CBFS_COMPONENT_VSA, "vsa"},
205 {CBFS_COMPONENT_MBI, "mbi"},
206 {CBFS_COMPONENT_MICROCODE, "microcode"},
207 {CBFS_COMPONENT_FSP, "fsp"},
208 {CBFS_COMPONENT_MRC, "mrc"},
209 {CBFS_COMPONENT_CMOS_DEFAULT, "cmos_default"},
210 {CBFS_COMPONENT_CMOS_LAYOUT, "cmos_layout"},
211 {CBFS_COMPONENT_SPD, "spd"},
212 {CBFS_COMPONENT_MRC_CACHE, "mrc_cache"},
Pratik Prajapatifb128732015-09-02 13:46:30 -0700213 {CBFS_COMPONENT_MMA, "mma"},
214 {CBFS_COMPONENT_EFI, "efi"},
Patrick Georgidc37dab2015-09-09 16:46:00 +0200215 {CBFS_COMPONENT_DELETED, "deleted"},
216 {CBFS_COMPONENT_NULL, "null"}
217};
218
Patrick Georgi89f20342015-10-01 15:54:04 +0200219static const struct typedesc_t types_cbfs_hash[] unused = {
220 {VB2_HASH_INVALID, "none"},
221 {VB2_HASH_SHA1, "sha1"},
222 {VB2_HASH_SHA256, "sha256"},
223 {VB2_HASH_SHA512, "sha512"},
224 {0, NULL}
225};
226
227static size_t widths_cbfs_hash[] unused = {
228 [VB2_HASH_INVALID] = 0,
229 [VB2_HASH_SHA1] = 20,
230 [VB2_HASH_SHA256] = 32,
231 [VB2_HASH_SHA512] = 64,
232};
233
234#define CBFS_NUM_SUPPORTED_HASHES ARRAY_SIZE(widths_cbfs_hash)
235
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800236#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
Patrick Georgi2c615062015-07-15 20:49:00 +0200237
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800238/* cbfs_image.c */
239uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800240uint32_t get_cbfs_compression(const char *name, uint32_t unknown);
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800241
Ronald G. Minnich3fcde222014-02-04 17:35:44 -0800242/* common.c */
243void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file);
244
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800245/* cbfs-mkpayload.c */
246void xdr_segs(struct buffer *output,
247 struct cbfs_payload_segment *segs, int nseg);
Aaron Durbinca630272014-08-05 10:48:20 -0500248void xdr_get_seg(struct cbfs_payload_segment *out,
249 struct cbfs_payload_segment *in);
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800250
Stefan Reinauer63217582012-10-29 16:52:36 -0700251#endif