blob: 0bded53b444079413ca6d43cd681996ab8c2ce83 [file] [log] [blame]
Patrick Georgi55189c92020-05-10 20:09:31 +02001/* SPDX-License-Identifier: GPL-2.0-only or BSD-3-Clause */
Patrick Georgi269e9322011-01-21 07:24:08 +00002
3#ifndef _CBFS_H_
4#define _CBFS_H_
5
6#include "coreboot_tables.h"
7
8typedef uint64_t u64;
9typedef uint32_t u32;
10typedef uint16_t u16;
11typedef uint8_t u8;
12
13/** These are standard values for the known compression
Patrick Georgi220c2092020-01-30 12:58:08 +010014 algorithms that coreboot knows about for stages and
Patrick Georgi269e9322011-01-21 07:24:08 +000015 payloads. Of course, other CBFS users can use whatever
16 values they want, as long as they understand them. */
17
18#define CBFS_COMPRESS_NONE 0
19#define CBFS_COMPRESS_LZMA 1
Julius Werner09f29212015-09-29 13:51:35 -070020#define CBFS_COMPRESS_LZ4 2
Patrick Georgi269e9322011-01-21 07:24:08 +000021
22/** These are standard component types for well known
23 components (i.e - those that coreboot needs to consume.
24 Users are welcome to use any other value for their
25 components */
26
Julius Werner00572622022-05-26 20:29:42 -070027#define CBFS_TYPE_STAGE 0x10
28#define CBFS_TYPE_SELF 0x20
29#define CBFS_TYPE_FIT_PAYLOAD 0x21
30#define CBFS_TYPE_OPTIONROM 0x30
31#define CBFS_TYPE_BOOTSPLASH 0x40
32#define CBFS_TYPE_RAW 0x50
33#define CBFS_TYPE_VSA 0x51
34#define CBFS_TYPE_MBI 0x52
35#define CBFS_TYPE_MICROCODE 0x53
Patrick Georgi269e9322011-01-21 07:24:08 +000036#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
37#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
38
39
40/** this is the master cbfs header - it need to be
41 located somewhere in the bootblock. Where it
42 actually lives is up to coreboot. A pointer to
43 this header will live at 0xFFFFFFFc, so we can
44 easily find it. */
45
46#define CBFS_HEADER_MAGIC 0x4F524243
47#define CBFS_HEADPTR_ADDR 0xFFFFFFFc
Hung-Te Lin086842a2013-01-04 12:33:03 +080048#define CBFS_HEADER_VERSION1 0x31313131
Patrick Georgi269e9322011-01-21 07:24:08 +000049
50struct cbfs_header {
51 u32 magic;
52 u32 version;
53 u32 romsize;
54 u32 bootblocksize;
55 u32 align;
56 u32 offset;
57 u32 pad[2];
58} __attribute__((packed));
59
60/** This is a component header - every entry in the CBFS
61 will have this header.
62
63 This is how the component is arranged in the ROM:
64
65 -------------- <- 0
66 component header
67 -------------- <- sizeof(struct component)
68 component name
69 -------------- <- offset
70 data
71 ...
72 -------------- <- offset + len
73*/
74
75#define CBFS_FILE_MAGIC "LARCHIVE"
76
77struct cbfs_file {
78 char magic[8];
79 u32 len;
80 u32 type;
81 u32 checksum;
82 u32 offset;
83} __attribute__((packed));
84
85/*** Component sub-headers ***/
86
87/* Following are component sub-headers for the "standard"
88 component types */
89
90/** This is the sub-header for stage components. Stages are
91 loaded by coreboot during the normal boot process */
92
93struct cbfs_stage {
94 u32 compression; /** Compression type */
95 u64 entry; /** entry point */
96 u64 load; /** Where to load in memory */
97 u32 len; /** length of data to load */
98 u32 memlen; /** total length of object in memory */
99} __attribute__((packed));
100
101/** this is the sub-header for payload components. Payloads
102 are loaded by coreboot at the end of the boot process */
103
104struct cbfs_payload_segment {
105 u32 type;
106 u32 compression;
107 u32 offset;
108 u64 load_addr;
109 u32 len;
110 u32 mem_len;
111} __attribute__((packed));
112
113struct cbfs_payload {
114 struct cbfs_payload_segment segments;
115};
116
117#define PAYLOAD_SEGMENT_CODE 0x45444F43
118#define PAYLOAD_SEGMENT_DATA 0x41544144
119#define PAYLOAD_SEGMENT_BSS 0x20535342
120#define PAYLOAD_SEGMENT_PARAMS 0x41524150
121#define PAYLOAD_SEGMENT_ENTRY 0x52544E45
122
123struct cbfs_optionrom {
124 u32 compression;
125 u32 len;
126} __attribute__((packed));
127
128#define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file))
129#define CBFS_SUBHEADER(_p) ( (void *) ((((u8 *) (_p)) + ntohl((_p)->offset))) )
130
131void * cbfs_get_file(const char *name);
132struct cbfs_file *cbfs_find(const char *name);
133void *cbfs_find_file(const char *name, unsigned int type, unsigned int *len);
134
135void open_cbfs(const char *filename);
136#endif