blob: f0c215d0d767e9441f44fb038ef8b46e68de00c8 [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>
Werner Zehe9995f12016-01-14 13:22:37 +01004 * Copyright (C) 2016 Siemens AG
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +00005 *
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.
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000014 */
15
Stefan Reinauer63217582012-10-29 16:52:36 -070016#ifndef __CBFS_H
17#define __CBFS_H
18
Patrick Georgi89f20342015-10-01 15:54:04 +020019#include "common.h"
Patrick Georgib7b56dd82009-09-14 13:29:27 +000020#include <stdint.h>
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080021
Patrick Georgi89f20342015-10-01 15:54:04 +020022#include <vb2_api.h>
23
Patrick Georgi2c615062015-07-15 20:49:00 +020024/* 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. Minnicha8a133d2013-12-30 13:16:18 -080028/* 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. Minnich5d01ec02009-03-31 11:57:36 +000038
Patrick Georgi20624732015-07-17 21:35:46 +020039/* To make CBFS more friendly to ROM, fill -1 (0xFF) instead of zero. */
40#define CBFS_CONTENT_DEFAULT_VALUE (-1)
41
Sol Boucher67a0a862015-03-18 12:36:27 -070042// Alignment (in bytes) to be used when no master header is present
43#define CBFS_ENTRY_ALIGNMENT 64
44
David Hendricks90ca3b62012-11-16 14:48:22 -080045#define CBFS_HEADER_MAGIC 0x4F524243
46#define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC
Hung-Te Lin086842a2013-01-04 12:33:03 +080047#define CBFS_HEADER_VERSION1 0x31313131
48#define CBFS_HEADER_VERSION2 0x31313132
49#define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2
David Hendricks90ca3b62012-11-16 14:48:22 -080050
Patrick Georgi45acb342015-07-14 22:18:23 +020051#define CBFS_ALIGNMENT 64
52
Patrick Georgib7b56dd82009-09-14 13:29:27 +000053struct cbfs_header {
54 uint32_t magic;
55 uint32_t version;
56 uint32_t romsize;
57 uint32_t bootblocksize;
Patrick Georgi45acb342015-07-14 22:18:23 +020058 uint32_t align; /* hard coded to 64 byte */
Patrick Georgib7b56dd82009-09-14 13:29:27 +000059 uint32_t offset;
David Hendricks90ca3b62012-11-16 14:48:22 -080060 uint32_t architecture; /* Version 2 */
61 uint32_t pad[1];
Stefan Reinauer6a001132017-07-13 02:20:27 +020062} __packed;
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000063
David Hendricks90ca3b62012-11-16 14:48:22 -080064#define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF
65#define CBFS_ARCHITECTURE_X86 0x00000001
Gabe Black51edd542013-09-30 23:00:33 -070066#define CBFS_ARCHITECTURE_ARM 0x00000010
Ronald G. Minnich5f431842013-11-12 09:03:33 -080067#define CBFS_ARCHITECTURE_AARCH64 0x0000aa64
Julius Wernerf96d9052019-08-16 15:35:39 -070068#define CBFS_ARCHITECTURE_MIPS 0x00000100 /* deprecated */
Ronald G. Minnich833bf202014-10-16 10:55:39 +000069#define CBFS_ARCHITECTURE_RISCV 0xc001d0de
Ronald G. Minniched4aa042015-12-11 18:19:52 +000070#define CBFS_ARCHITECTURE_PPC64 0x407570ff
David Hendricks90ca3b62012-11-16 14:48:22 -080071
Hung-Te Lineab2c812013-01-29 01:56:17 +080072#define CBFS_FILE_MAGIC "LARCHIVE"
73
Patrick Georgib7b56dd82009-09-14 13:29:27 +000074struct cbfs_file {
Stefan Reinauera1e48242011-10-21 14:24:57 -070075 uint8_t magic[8];
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020076 /* length of file data */
Patrick Georgib7b56dd82009-09-14 13:29:27 +000077 uint32_t len;
78 uint32_t type;
Patrick Georgi2c615062015-07-15 20:49:00 +020079 /* offset to struct cbfs_file_attribute or 0 */
Patrick Georgi0d618af2015-07-15 18:28:23 +020080 uint32_t attributes_offset;
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020081 /* length of header incl. variable data */
Patrick Georgib7b56dd82009-09-14 13:29:27 +000082 uint32_t offset;
Patrick Georgic569b8b2015-07-15 16:42:38 +020083 char filename[];
Stefan Reinauer6a001132017-07-13 02:20:27 +020084} __packed;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000085
Patrick Georgiab5754d2015-09-01 18:20:20 +020086#if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020087_Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch");
Patrick Georgi57c67e52015-09-01 12:37:41 +020088#endif
Patrick Georgi5dc01ac2015-07-15 16:40:44 +020089
Patrick Georgic6a8da72015-07-22 21:32:03 +020090/* The common fields of extended cbfs file attributes.
91 Attributes are expected to start with tag/len, then append their
92 specific fields. */
93struct cbfs_file_attribute {
94 uint32_t tag;
95 /* len covers the whole structure, incl. tag and len */
96 uint32_t len;
97 uint8_t data[0];
Stefan Reinauer6a001132017-07-13 02:20:27 +020098} __packed;
Patrick Georgic6a8da72015-07-22 21:32:03 +020099
Patrick Georgi2c615062015-07-15 20:49:00 +0200100/* Depending on how the header was initialized, it may be backed with 0x00 or
101 * 0xff. Support both. */
102#define CBFS_FILE_ATTR_TAG_UNUSED 0
103#define CBFS_FILE_ATTR_TAG_UNUSED2 0xffffffff
Daisuke Nojiri8984a632015-07-09 15:07:45 -0700104#define CBFS_FILE_ATTR_TAG_COMPRESSION 0x42435a4c
Patrick Georgi89f20342015-10-01 15:54:04 +0200105#define CBFS_FILE_ATTR_TAG_HASH 0x68736148
Daisuke Nojiriff906fb2017-10-30 17:38:04 -0700106#define CBFS_FILE_ATTR_TAG_POSITION 0x42435350 /* PSCB */
Werner Zehe9995f12016-01-14 13:22:37 +0100107#define CBFS_FILE_ATTR_TAG_ALIGNMENT 0x42434c41 /* ALCB */
Daisuke Nojiriff906fb2017-10-30 17:38:04 -0700108#define CBFS_FILE_ATTR_TAG_PADDING 0x47444150 /* PDNG */
Philipp Deppenwiese7ba58712018-11-20 13:54:49 +0100109#define CBFS_FILE_ATTR_TAG_IBB 0x32494242 /* Initial BootBlock */
Daisuke Nojiri8984a632015-07-09 15:07:45 -0700110
111struct 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;
Stefan Reinauer6a001132017-07-13 02:20:27 +0200117} __packed;
Patrick Georgi2c615062015-07-15 20:49:00 +0200118
Patrick Georgi89f20342015-10-01 15:54:04 +0200119struct cbfs_file_attr_hash {
120 uint32_t tag;
121 uint32_t len;
122 uint32_t hash_type;
123 /* hash_data is len - sizeof(struct) bytes */
124 uint8_t hash_data[];
Stefan Reinauer6a001132017-07-13 02:20:27 +0200125} __packed;
Patrick Georgi89f20342015-10-01 15:54:04 +0200126
Werner Zehe9995f12016-01-14 13:22:37 +0100127struct cbfs_file_attr_position {
128 uint32_t tag;
129 uint32_t len;
130 uint32_t position;
Stefan Reinauer6a001132017-07-13 02:20:27 +0200131} __packed;
Werner Zehe9995f12016-01-14 13:22:37 +0100132
133struct cbfs_file_attr_align {
134 uint32_t tag;
135 uint32_t len;
136 uint32_t alignment;
Stefan Reinauer6a001132017-07-13 02:20:27 +0200137} __packed;
Werner Zehe9995f12016-01-14 13:22:37 +0100138
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000139struct cbfs_stage {
Stefan Reinauera1e48242011-10-21 14:24:57 -0700140 uint32_t compression;
141 uint64_t entry;
142 uint64_t load;
143 uint32_t len;
144 uint32_t memlen;
Stefan Reinauer6a001132017-07-13 02:20:27 +0200145} __packed;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000146
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800147#define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E')
148#define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A')
Wei Hu2ad6ee92014-04-16 22:52:59 -0700149#define PAYLOAD_SEGMENT_BSS makemagic('B', 'S', 'S', ' ')
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800150#define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A')
151#define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R')
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000152
153struct cbfs_payload_segment {
Stefan Reinauera1e48242011-10-21 14:24:57 -0700154 uint32_t type;
155 uint32_t compression;
156 uint32_t offset;
157 uint64_t load_addr;
158 uint32_t len;
159 uint32_t mem_len;
Stefan Reinauer6a001132017-07-13 02:20:27 +0200160} __packed;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000161
162struct cbfs_payload {
163 struct cbfs_payload_segment segments;
Stefan Reinauer6a001132017-07-13 02:20:27 +0200164} __packed;
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000165
166/** These are standard component types for well known
167 components (i.e - those that coreboot needs to consume.
168 Users are welcome to use any other value for their
169 components */
170
Patrick Georgi239c7422015-09-09 20:11:26 +0200171#define CBFS_COMPONENT_BOOTBLOCK 0x01
172#define CBFS_COMPONENT_CBFSHEADER 0x02
Stefan Reinauer800379f2010-03-01 08:34:19 +0000173#define CBFS_COMPONENT_STAGE 0x10
Patrick Rudolph4f5bed52018-05-02 09:44:08 +0200174#define CBFS_COMPONENT_SELF 0x20
Patrick Rudolph7ee05ed2018-04-26 09:35:13 +0200175#define CBFS_COMPONENT_FIT 0x21
Stefan Reinauer800379f2010-03-01 08:34:19 +0000176#define CBFS_COMPONENT_OPTIONROM 0x30
177#define CBFS_COMPONENT_BOOTSPLASH 0x40
178#define CBFS_COMPONENT_RAW 0x50
179#define CBFS_COMPONENT_VSA 0x51
180#define CBFS_COMPONENT_MBI 0x52
181#define CBFS_COMPONENT_MICROCODE 0x53
Martin Rothdde307c2015-03-24 15:54:20 -0600182#define CBFS_COMPONENT_FSP 0x60
183#define CBFS_COMPONENT_MRC 0x61
Pratik Prajapatifb128732015-09-02 13:46:30 -0700184#define CBFS_COMPONENT_MMA 0x62
185#define CBFS_COMPONENT_EFI 0x63
Julius Wernerf975e552016-08-19 15:43:06 -0700186#define CBFS_COMPONENT_STRUCT 0x70
Patrick Georgia865b172011-01-14 07:40:24 +0000187#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
Martin Rothdde307c2015-03-24 15:54:20 -0600188#define CBFS_COMPONENT_SPD 0xab
189#define CBFS_COMPONENT_MRC_CACHE 0xac
Patrick Georgi24479372011-01-18 13:56:36 +0000190#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000191
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000192/* The deleted type is chosen to be a value
193 * that can be written in a FLASH from all other
Stefan Reinauer14e22772010-04-27 06:56:47 +0000194 * values.
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000195 */
196#define CBFS_COMPONENT_DELETED 0
197
Stefan Reinauer14e22772010-04-27 06:56:47 +0000198/* for all known FLASH, this value can be changed
199 * to all other values. This allows NULL files to be
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000200 * changed without a block erase
201 */
Peter Stuge1d862de2009-04-14 00:08:34 +0000202#define CBFS_COMPONENT_NULL 0xFFFFFFFF
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000203
Patrick Georgidc37dab2015-09-09 16:46:00 +0200204static struct typedesc_t filetypes[] unused = {
Patrick Georgi239c7422015-09-09 20:11:26 +0200205 {CBFS_COMPONENT_BOOTBLOCK, "bootblock"},
206 {CBFS_COMPONENT_CBFSHEADER, "cbfs header"},
Patrick Georgidc37dab2015-09-09 16:46:00 +0200207 {CBFS_COMPONENT_STAGE, "stage"},
Ronald G. Minnichc6d13492018-05-15 18:05:07 -0700208 {CBFS_COMPONENT_SELF, "simple elf"},
Patrick Rudolph7ee05ed2018-04-26 09:35:13 +0200209 {CBFS_COMPONENT_FIT, "fit"},
Patrick Georgidc37dab2015-09-09 16:46:00 +0200210 {CBFS_COMPONENT_OPTIONROM, "optionrom"},
211 {CBFS_COMPONENT_BOOTSPLASH, "bootsplash"},
212 {CBFS_COMPONENT_RAW, "raw"},
213 {CBFS_COMPONENT_VSA, "vsa"},
214 {CBFS_COMPONENT_MBI, "mbi"},
215 {CBFS_COMPONENT_MICROCODE, "microcode"},
216 {CBFS_COMPONENT_FSP, "fsp"},
217 {CBFS_COMPONENT_MRC, "mrc"},
218 {CBFS_COMPONENT_CMOS_DEFAULT, "cmos_default"},
219 {CBFS_COMPONENT_CMOS_LAYOUT, "cmos_layout"},
220 {CBFS_COMPONENT_SPD, "spd"},
221 {CBFS_COMPONENT_MRC_CACHE, "mrc_cache"},
Pratik Prajapatifb128732015-09-02 13:46:30 -0700222 {CBFS_COMPONENT_MMA, "mma"},
223 {CBFS_COMPONENT_EFI, "efi"},
Julius Wernerf975e552016-08-19 15:43:06 -0700224 {CBFS_COMPONENT_STRUCT, "struct"},
Patrick Georgidc37dab2015-09-09 16:46:00 +0200225 {CBFS_COMPONENT_DELETED, "deleted"},
226 {CBFS_COMPONENT_NULL, "null"}
227};
228
Patrick Georgi89f20342015-10-01 15:54:04 +0200229static const struct typedesc_t types_cbfs_hash[] unused = {
230 {VB2_HASH_INVALID, "none"},
231 {VB2_HASH_SHA1, "sha1"},
232 {VB2_HASH_SHA256, "sha256"},
233 {VB2_HASH_SHA512, "sha512"},
234 {0, NULL}
235};
236
237static size_t widths_cbfs_hash[] unused = {
238 [VB2_HASH_INVALID] = 0,
239 [VB2_HASH_SHA1] = 20,
240 [VB2_HASH_SHA256] = 32,
241 [VB2_HASH_SHA512] = 64,
242};
243
244#define CBFS_NUM_SUPPORTED_HASHES ARRAY_SIZE(widths_cbfs_hash)
245
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800246#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
Patrick Georgi2c615062015-07-15 20:49:00 +0200247
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800248/* cbfs_image.c */
249uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800250uint32_t get_cbfs_compression(const char *name, uint32_t unknown);
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800251
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800252/* cbfs-mkpayload.c */
253void xdr_segs(struct buffer *output,
254 struct cbfs_payload_segment *segs, int nseg);
Aaron Durbinca630272014-08-05 10:48:20 -0500255void xdr_get_seg(struct cbfs_payload_segment *out,
256 struct cbfs_payload_segment *in);
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800257
Stefan Reinauer63217582012-10-29 16:52:36 -0700258#endif