xref: /aosp_15_r20/external/coreboot/util/nvramtool/cbfs.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only or BSD-3-Clause */
2 
3 #ifndef _CBFS_H_
4 #define _CBFS_H_
5 
6 #include "coreboot_tables.h"
7 
8 typedef uint64_t u64;
9 typedef uint32_t u32;
10 typedef uint16_t u16;
11 typedef uint8_t u8;
12 
13 /** These are standard values for the known compression
14     algorithms that coreboot knows about for stages and
15     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
20 #define CBFS_COMPRESS_LZ4   2
21 
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 
27 #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
36 #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
48 #define CBFS_HEADER_VERSION1 0x31313131
49 
50 struct 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 
77 struct 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 
93 struct 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 
104 struct 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 
113 struct 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 
123 struct 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 
131 void * cbfs_get_file(const char *name);
132 struct cbfs_file *cbfs_find(const char *name);
133 void *cbfs_find_file(const char *name, unsigned int type, unsigned int *len);
134 
135 void open_cbfs(const char *filename);
136 #endif
137