blob: 44e3dcde6d91e26c000f92d985f3300d7be1d74a [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.
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 Georgib890a122015-03-26 15:17:45 +010016 * Foundation, Inc.
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000017 */
18
Stefan Reinauer63217582012-10-29 16:52:36 -070019#ifndef __CBFS_H
20#define __CBFS_H
21
Patrick Georgib7b56dd82009-09-14 13:29:27 +000022#include <stdint.h>
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080023
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
Stefan Reinauercfa9b992015-07-04 11:30:59 -070039#if defined(__WIN32) || defined(__WIN64)
40#define __PACKED __attribute__((gcc_struct, packed))
41#else
42#define __PACKED __attribute__((packed))
43#endif
44
Patrick Georgi20624732015-07-17 21:35:46 +020045/* To make CBFS more friendly to ROM, fill -1 (0xFF) instead of zero. */
46#define CBFS_CONTENT_DEFAULT_VALUE (-1)
47
Sol Boucher67a0a862015-03-18 12:36:27 -070048// Alignment (in bytes) to be used when no master header is present
49#define CBFS_ENTRY_ALIGNMENT 64
50
David Hendricks90ca3b62012-11-16 14:48:22 -080051#define CBFS_HEADER_MAGIC 0x4F524243
52#define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC
Hung-Te Lin086842a2013-01-04 12:33:03 +080053#define CBFS_HEADER_VERSION1 0x31313131
54#define CBFS_HEADER_VERSION2 0x31313132
55#define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2
David Hendricks90ca3b62012-11-16 14:48:22 -080056
Patrick Georgi45acb342015-07-14 22:18:23 +020057#define CBFS_ALIGNMENT 64
58
Patrick Georgib7b56dd82009-09-14 13:29:27 +000059struct cbfs_header {
60 uint32_t magic;
61 uint32_t version;
62 uint32_t romsize;
63 uint32_t bootblocksize;
Patrick Georgi45acb342015-07-14 22:18:23 +020064 uint32_t align; /* hard coded to 64 byte */
Patrick Georgib7b56dd82009-09-14 13:29:27 +000065 uint32_t offset;
David Hendricks90ca3b62012-11-16 14:48:22 -080066 uint32_t architecture; /* Version 2 */
67 uint32_t pad[1];
Stefan Reinauercfa9b992015-07-04 11:30:59 -070068} __PACKED;
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000069
David Hendricks90ca3b62012-11-16 14:48:22 -080070#define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF
71#define CBFS_ARCHITECTURE_X86 0x00000001
Gabe Black51edd542013-09-30 23:00:33 -070072#define CBFS_ARCHITECTURE_ARM 0x00000010
Ronald G. Minnich5f431842013-11-12 09:03:33 -080073#define CBFS_ARCHITECTURE_AARCH64 0x0000aa64
Paul Burton33186922014-06-13 23:56:45 +010074#define CBFS_ARCHITECTURE_MIPS 0x00000100
Ronald G. Minnich833bf202014-10-16 10:55:39 +000075#define CBFS_ARCHITECTURE_RISCV 0xc001d0de
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 Georgi5dc01ac2015-07-15 16:40:44 +020091_Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch");
92
Patrick Georgic6a8da72015-07-22 21:32:03 +020093/* The common fields of extended cbfs file attributes.
94 Attributes are expected to start with tag/len, then append their
95 specific fields. */
96struct cbfs_file_attribute {
97 uint32_t tag;
98 /* len covers the whole structure, incl. tag and len */
99 uint32_t len;
100 uint8_t data[0];
101} __PACKED;
102
Patrick Georgi2c615062015-07-15 20:49:00 +0200103/* Depending on how the header was initialized, it may be backed with 0x00 or
104 * 0xff. Support both. */
105#define CBFS_FILE_ATTR_TAG_UNUSED 0
106#define CBFS_FILE_ATTR_TAG_UNUSED2 0xffffffff
Daisuke Nojiri8984a632015-07-09 15:07:45 -0700107#define CBFS_FILE_ATTR_TAG_COMPRESSION 0x42435a4c
108
109struct cbfs_file_attr_compression {
110 uint32_t tag;
111 uint32_t len;
112 /* whole file compression format. 0 if no compression. */
113 uint32_t compression;
114 uint32_t decompressed_size;
115} __PACKED;
Patrick Georgi2c615062015-07-15 20:49:00 +0200116
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000117struct cbfs_stage {
Stefan Reinauera1e48242011-10-21 14:24:57 -0700118 uint32_t compression;
119 uint64_t entry;
120 uint64_t load;
121 uint32_t len;
122 uint32_t memlen;
Stefan Reinauercfa9b992015-07-04 11:30:59 -0700123} __PACKED;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000124
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800125#define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E')
126#define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A')
Wei Hu2ad6ee92014-04-16 22:52:59 -0700127#define PAYLOAD_SEGMENT_BSS makemagic('B', 'S', 'S', ' ')
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800128#define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A')
129#define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R')
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000130
131struct cbfs_payload_segment {
Stefan Reinauera1e48242011-10-21 14:24:57 -0700132 uint32_t type;
133 uint32_t compression;
134 uint32_t offset;
135 uint64_t load_addr;
136 uint32_t len;
137 uint32_t mem_len;
Stefan Reinauercfa9b992015-07-04 11:30:59 -0700138} __PACKED;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000139
140struct cbfs_payload {
141 struct cbfs_payload_segment segments;
Stefan Reinauercfa9b992015-07-04 11:30:59 -0700142} __PACKED;
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000143
144/** These are standard component types for well known
145 components (i.e - those that coreboot needs to consume.
146 Users are welcome to use any other value for their
147 components */
148
Stefan Reinauer800379f2010-03-01 08:34:19 +0000149#define CBFS_COMPONENT_STAGE 0x10
150#define CBFS_COMPONENT_PAYLOAD 0x20
151#define CBFS_COMPONENT_OPTIONROM 0x30
152#define CBFS_COMPONENT_BOOTSPLASH 0x40
153#define CBFS_COMPONENT_RAW 0x50
154#define CBFS_COMPONENT_VSA 0x51
155#define CBFS_COMPONENT_MBI 0x52
156#define CBFS_COMPONENT_MICROCODE 0x53
Martin Rothdde307c2015-03-24 15:54:20 -0600157#define CBFS_COMPONENT_FSP 0x60
158#define CBFS_COMPONENT_MRC 0x61
Patrick Georgia865b172011-01-14 07:40:24 +0000159#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
Martin Rothdde307c2015-03-24 15:54:20 -0600160#define CBFS_COMPONENT_SPD 0xab
161#define CBFS_COMPONENT_MRC_CACHE 0xac
Patrick Georgi24479372011-01-18 13:56:36 +0000162#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000163
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000164/* The deleted type is chosen to be a value
165 * that can be written in a FLASH from all other
Stefan Reinauer14e22772010-04-27 06:56:47 +0000166 * values.
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000167 */
168#define CBFS_COMPONENT_DELETED 0
169
Stefan Reinauer14e22772010-04-27 06:56:47 +0000170/* for all known FLASH, this value can be changed
171 * to all other values. This allows NULL files to be
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000172 * changed without a block erase
173 */
Peter Stuge1d862de2009-04-14 00:08:34 +0000174#define CBFS_COMPONENT_NULL 0xFFFFFFFF
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000175
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800176#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
Patrick Georgi2c615062015-07-15 20:49:00 +0200177
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800178/* cbfs_image.c */
179uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800180uint32_t get_cbfs_compression(const char *name, uint32_t unknown);
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800181
Ronald G. Minnich3fcde222014-02-04 17:35:44 -0800182/* common.c */
183void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file);
184
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800185/* cbfs-mkpayload.c */
186void xdr_segs(struct buffer *output,
187 struct cbfs_payload_segment *segs, int nseg);
Aaron Durbinca630272014-08-05 10:48:20 -0500188void xdr_get_seg(struct cbfs_payload_segment *out,
189 struct cbfs_payload_segment *in);
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800190
Stefan Reinauer63217582012-10-29 16:52:36 -0700191#endif