xref: /aosp_15_r20/external/coreboot/Documentation/cbfs.txt (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1*b9411a12SAndroid Build Coastguard Worker
2*b9411a12SAndroid Build Coastguard WorkerReceived: from www.crouse-house.com ([199.45.160.146]
3*b9411a12SAndroid Build Coastguard Worker	for [email protected]; Fri, 19 Dec 2008 23:11:59 +0100
4*b9411a12SAndroid Build Coastguard WorkerFrom: Jordan Crouse <[email protected]>
5*b9411a12SAndroid Build Coastguard Worker
6*b9411a12SAndroid Build Coastguard Worker
7*b9411a12SAndroid Build Coastguard WorkerGreetings.  I apologize for the incompleteness of what I am about to
8*b9411a12SAndroid Build Coastguard Workerdiscuss.  I was planning on working on it leisurely, but my employment
9*b9411a12SAndroid Build Coastguard Workercircumstances changed and I've been trying to get it completed in a
10*b9411a12SAndroid Build Coastguard Workerhurry before I had to leave it behind.
11*b9411a12SAndroid Build Coastguard Worker
12*b9411a12SAndroid Build Coastguard WorkerI've been thinking a lot about LAR lately, and ways to make it more
13*b9411a12SAndroid Build Coastguard Workerextensible and robust.  Marc and I have been trading ideas back and
14*b9411a12SAndroid Build Coastguard Workerforth for a number of months, and over time a clear idea of what I
15*b9411a12SAndroid Build Coastguard Workerwanted to do started to take shape.
16*b9411a12SAndroid Build Coastguard Worker
17*b9411a12SAndroid Build Coastguard WorkerMy goal was to add small things to LAR while retaining the overall
18*b9411a12SAndroid Build Coastguard Workerscheme.  Over time, the scheme evolved slightly, but I think you'll find
19*b9411a12SAndroid Build Coastguard Workerthat it remains true to the original idea.  Below is the beginnings of
20*b9411a12SAndroid Build Coastguard Workeran architecture document - I did it in text form, but if met with
21*b9411a12SAndroid Build Coastguard Workeraclaim, it should be wikified.  This presents what I call CBFS - the
22*b9411a12SAndroid Build Coastguard Workernext generation LAR for next generation coreboot.  Its easier to
23*b9411a12SAndroid Build Coastguard Workerdescribe what it is by describing what changed:
24*b9411a12SAndroid Build Coastguard Worker
25*b9411a12SAndroid Build Coastguard WorkerA header has been added somewhere in the bootblock similar to Carl
26*b9411a12SAndroid Build Coastguard WorkerDaniel's scheme.  In addition to the coreboot information, the header
27*b9411a12SAndroid Build Coastguard Workerreports the size of the ROM, the alignment of the blocks, and the offset
28*b9411a12SAndroid Build Coastguard Workerof the first component in the CBFS.   The master header provides all
29*b9411a12SAndroid Build Coastguard Workerthe information LAR needs plus the magic number information flashrom needs.
30*b9411a12SAndroid Build Coastguard Worker
31*b9411a12SAndroid Build Coastguard WorkerEach "file" (or component, as I style them) now has a type associated
32*b9411a12SAndroid Build Coastguard Workerwith it. The type is used by coreboot to identify the type of file that
33*b9411a12SAndroid Build Coastguard Workerit is loading, and it can also be used by payloads to group items in the
34*b9411a12SAndroid Build Coastguard WorkerCBFS by type (i.e - bayou can ask for all components that are payloads).
35*b9411a12SAndroid Build Coastguard Worker
36*b9411a12SAndroid Build Coastguard WorkerThe header on each "file" (or component, as I like to style them) has
37*b9411a12SAndroid Build Coastguard Workerbeen simplified - We now only store the length, the type, the checksum,
38*b9411a12SAndroid Build Coastguard Workerand the offset to the data.  The name scheme remains the same.  The
39*b9411a12SAndroid Build Coastguard Workeradditional information, which is component specific, has been moved to
40*b9411a12SAndroid Build Coastguard Workerthe component itself (see below).
41*b9411a12SAndroid Build Coastguard Worker
42*b9411a12SAndroid Build Coastguard WorkerThe components are arranged in the ROM aligned along the specified
43*b9411a12SAndroid Build Coastguard Workeralignment from the master header - this is to facilitate partial re-write.
44*b9411a12SAndroid Build Coastguard Worker
45*b9411a12SAndroid Build Coastguard WorkerOther then that, the LAR ideas remain pretty much the same.
46*b9411a12SAndroid Build Coastguard Worker
47*b9411a12SAndroid Build Coastguard WorkerThe plan for moving the metadata to the components is to allow many
48*b9411a12SAndroid Build Coastguard Workerdifferent kinds of components, not all of which are groked by coreboot.
49*b9411a12SAndroid Build Coastguard Worker  However, there are three essential component types that are groked by
50*b9411a12SAndroid Build Coastguard Workercoreboot, and they are defined:
51*b9411a12SAndroid Build Coastguard Worker
52*b9411a12SAndroid Build Coastguard Workerstage - the stage is being parsed from the original ELF, and stored in
53*b9411a12SAndroid Build Coastguard Workerthe ROM as a single blob of binary data.  The load address, start
54*b9411a12SAndroid Build Coastguard Workeraddress, compression type and length are stored in the component sub-header.
55*b9411a12SAndroid Build Coastguard Worker
56*b9411a12SAndroid Build Coastguard Workerpayload - this is essentially SELF in different clothing - same idea as
57*b9411a12SAndroid Build Coastguard WorkerSELF, with the sub-header as above.
58*b9411a12SAndroid Build Coastguard Worker
59*b9411a12SAndroid Build Coastguard Workeroptionrom - This is in flux - right now, the optionrom is stored
60*b9411a12SAndroid Build Coastguard Workerunadulterated and uncompressed, but that is likely to be changed.
61*b9411a12SAndroid Build Coastguard Worker
62*b9411a12SAndroid Build Coastguard WorkerFollowing this email are two replies containing the v3 code and a new
63*b9411a12SAndroid Build Coastguard WorkerROM tool to implement this respectively.  I told you that I was trying
64*b9411a12SAndroid Build Coastguard Workerto get this out before I disappear, and I'm not kidding - the code is
65*b9411a12SAndroid Build Coastguard Workercompile tested and not run-tested.  I hope that somebody will embrace
66*b9411a12SAndroid Build Coastguard Workerthis code and take it the rest of the way, otherwise it will die a
67*b9411a12SAndroid Build Coastguard Workerpretty short death.
68*b9411a12SAndroid Build Coastguard Worker
69*b9411a12SAndroid Build Coastguard WorkerI realize that this will start an awesome flamewar, and I'm looking
70*b9411a12SAndroid Build Coastguard Workerforward to it.  Thanks for listening to me over the years - and good
71*b9411a12SAndroid Build Coastguard Workerluck with coreboot.  When you all make a million dollars, send me a few
72*b9411a12SAndroid Build Coastguard Workerbucks, will you?
73*b9411a12SAndroid Build Coastguard Worker
74*b9411a12SAndroid Build Coastguard WorkerJordan
75*b9411a12SAndroid Build Coastguard Worker
76*b9411a12SAndroid Build Coastguard Workercoreboot CBFS Specification
77*b9411a12SAndroid Build Coastguard WorkerJordan Crouse <[email protected]>
78*b9411a12SAndroid Build Coastguard Worker
79*b9411a12SAndroid Build Coastguard Worker= Introduction =
80*b9411a12SAndroid Build Coastguard Worker
81*b9411a12SAndroid Build Coastguard WorkerThis document describes the coreboot CBFS specification (from here
82*b9411a12SAndroid Build Coastguard Workerreferred to as CBFS).  CBFS is a scheme for managing independent chunks
83*b9411a12SAndroid Build Coastguard Workerof data in a system ROM.  Though not a true filesystem, the style and
84*b9411a12SAndroid Build Coastguard Workerconcepts are similar.
85*b9411a12SAndroid Build Coastguard Worker
86*b9411a12SAndroid Build Coastguard Worker
87*b9411a12SAndroid Build Coastguard Worker= Architecture =
88*b9411a12SAndroid Build Coastguard Worker
89*b9411a12SAndroid Build Coastguard WorkerThe CBFS architecture looks like the following:
90*b9411a12SAndroid Build Coastguard Worker
91*b9411a12SAndroid Build Coastguard Worker/---------------\ <-- Start of ROM
92*b9411a12SAndroid Build Coastguard Worker| /-----------\ | --|
93*b9411a12SAndroid Build Coastguard Worker| | Header    | |   |
94*b9411a12SAndroid Build Coastguard Worker| |-----------| |   |
95*b9411a12SAndroid Build Coastguard Worker| | Name      | |   |-- Component
96*b9411a12SAndroid Build Coastguard Worker| |-----------| |   |
97*b9411a12SAndroid Build Coastguard Worker| |Data       | |   |
98*b9411a12SAndroid Build Coastguard Worker| |..         | |   |
99*b9411a12SAndroid Build Coastguard Worker| \-----------/ | --|
100*b9411a12SAndroid Build Coastguard Worker|               |
101*b9411a12SAndroid Build Coastguard Worker| /-----------\ |
102*b9411a12SAndroid Build Coastguard Worker| | Header    | |
103*b9411a12SAndroid Build Coastguard Worker| |-----------| |
104*b9411a12SAndroid Build Coastguard Worker| | Name      | |
105*b9411a12SAndroid Build Coastguard Worker| |-----------| |
106*b9411a12SAndroid Build Coastguard Worker| |Data       | |
107*b9411a12SAndroid Build Coastguard Worker| |..         | |
108*b9411a12SAndroid Build Coastguard Worker| \-----------/ |
109*b9411a12SAndroid Build Coastguard Worker|               |
110*b9411a12SAndroid Build Coastguard Worker| ...           |
111*b9411a12SAndroid Build Coastguard Worker| /-----------\ |
112*b9411a12SAndroid Build Coastguard Worker| |           | |
113*b9411a12SAndroid Build Coastguard Worker| | Bootblock | |
114*b9411a12SAndroid Build Coastguard Worker| | --------- | |
115*b9411a12SAndroid Build Coastguard Worker| | Reset     | | <- 0xFFFFFFF0
116*b9411a12SAndroid Build Coastguard Worker| \-----------/ |
117*b9411a12SAndroid Build Coastguard Worker\---------------/
118*b9411a12SAndroid Build Coastguard Worker
119*b9411a12SAndroid Build Coastguard Worker
120*b9411a12SAndroid Build Coastguard WorkerThe CBFS architecture consists of a binary associated with a physical
121*b9411a12SAndroid Build Coastguard WorkerROM disk referred hereafter as the ROM. A number of independent of
122*b9411a12SAndroid Build Coastguard Workercomponents, each with a  header prepended on to data are located within
123*b9411a12SAndroid Build Coastguard Workerthe ROM.  The components are nominally arranged sequentially, though they
124*b9411a12SAndroid Build Coastguard Workerare aligned along a pre-defined boundary.
125*b9411a12SAndroid Build Coastguard Worker
126*b9411a12SAndroid Build Coastguard WorkerThe bootblock occupies the last 20k of the ROM.  Within
127*b9411a12SAndroid Build Coastguard Workerthe bootblock is a master header containing information about the ROM
128*b9411a12SAndroid Build Coastguard Workerincluding the size, alignment of the components, and the offset of the
129*b9411a12SAndroid Build Coastguard Workerstart of the first CBFS component within the ROM.
130*b9411a12SAndroid Build Coastguard Worker
131*b9411a12SAndroid Build Coastguard Worker= Master Header =
132*b9411a12SAndroid Build Coastguard Worker
133*b9411a12SAndroid Build Coastguard WorkerThe master header contains essential information about the ROM that is
134*b9411a12SAndroid Build Coastguard Workerused by both the CBFS implementation within coreboot at runtime as well
135*b9411a12SAndroid Build Coastguard Workeras host based utilities to create and manage the ROM.  The master header
136*b9411a12SAndroid Build Coastguard Workerwill be located somewhere within the bootblock (last 20k of the ROM).  A
137*b9411a12SAndroid Build Coastguard Workerpointer to the location of the header will be located at offset
138*b9411a12SAndroid Build Coastguard Worker-4 from the end of the ROM.  This translates to address 0xFFFFFFFC on a
139*b9411a12SAndroid Build Coastguard Workernormal x86 system.  The pointer will be to physical memory somewhere
140*b9411a12SAndroid Build Coastguard Workerbetween - 0xFFFFB000 and 0xFFFFFFF0.  This makes it easier for coreboot
141*b9411a12SAndroid Build Coastguard Workerto locate the header at run time.  Build time utilities will
142*b9411a12SAndroid Build Coastguard Workerneed to read the pointer and do the appropriate math to locate the header.
143*b9411a12SAndroid Build Coastguard Worker
144*b9411a12SAndroid Build Coastguard WorkerThe following is the structure of the master header:
145*b9411a12SAndroid Build Coastguard Worker
146*b9411a12SAndroid Build Coastguard Workerstruct cbfs_header {
147*b9411a12SAndroid Build Coastguard Worker        u32 magic;
148*b9411a12SAndroid Build Coastguard Worker        u32 version;
149*b9411a12SAndroid Build Coastguard Worker        u32 romsize;
150*b9411a12SAndroid Build Coastguard Worker        u32 bootblocksize;
151*b9411a12SAndroid Build Coastguard Worker        u32 align;
152*b9411a12SAndroid Build Coastguard Worker        u32 offset;
153*b9411a12SAndroid Build Coastguard Worker        u32 architecture;
154*b9411a12SAndroid Build Coastguard Worker        u32 pad[1];
155*b9411a12SAndroid Build Coastguard Worker} __packed;
156*b9411a12SAndroid Build Coastguard Worker
157*b9411a12SAndroid Build Coastguard WorkerThe meaning of each member is as follows:
158*b9411a12SAndroid Build Coastguard Worker
159*b9411a12SAndroid Build Coastguard Worker'magic' is a 32 bit number that identifies the ROM as a CBFS type.  The
160*b9411a12SAndroid Build Coastguard Workermagic
161*b9411a12SAndroid Build Coastguard Workernumber is 0x4F524243, which is 'ORBC' in ASCII.
162*b9411a12SAndroid Build Coastguard Worker
163*b9411a12SAndroid Build Coastguard Worker'version' is a version number for CBFS header. cbfs_header structure may be
164*b9411a12SAndroid Build Coastguard Workerdifferent if version is not matched.
165*b9411a12SAndroid Build Coastguard Worker
166*b9411a12SAndroid Build Coastguard Worker'romsize' is the size of the ROM in bytes.  coreboot will subtract 'size' from
167*b9411a12SAndroid Build Coastguard Worker0xFFFFFFFF to locate the beginning of the ROM in memory.
168*b9411a12SAndroid Build Coastguard Worker
169*b9411a12SAndroid Build Coastguard Worker'bootblocksize' is the size of bootblock reserved in firmware image.
170*b9411a12SAndroid Build Coastguard Worker
171*b9411a12SAndroid Build Coastguard Worker'align' is the number of bytes that each component is aligned to within the
172*b9411a12SAndroid Build Coastguard WorkerROM.  This is used to make sure that each component is aligned correctly
173*b9411a12SAndroid Build Coastguard Workerwith
174*b9411a12SAndroid Build Coastguard Workerregards to the erase block sizes on the ROM - allowing one to replace a
175*b9411a12SAndroid Build Coastguard Workercomponent at runtime without disturbing the others.
176*b9411a12SAndroid Build Coastguard Worker
177*b9411a12SAndroid Build Coastguard Worker'offset' is the offset of the first CBFS component (from the start of
178*b9411a12SAndroid Build Coastguard Workerthe ROM).  This is to allow for arbitrary space to be left at the beginning
179*b9411a12SAndroid Build Coastguard Workerof the ROM for things like embedded controller firmware.
180*b9411a12SAndroid Build Coastguard Worker
181*b9411a12SAndroid Build Coastguard Worker'architecture' describes which architecture (x86, arm, ...) this CBFS is created
182*b9411a12SAndroid Build Coastguard Workerfor.
183*b9411a12SAndroid Build Coastguard Worker
184*b9411a12SAndroid Build Coastguard Worker= Bootblock =
185*b9411a12SAndroid Build Coastguard WorkerThe bootblock is a mandatory component in the ROM.  It is located in the
186*b9411a12SAndroid Build Coastguard Workerlast
187*b9411a12SAndroid Build Coastguard Worker20k of the ROM space, and contains, among other things, the location of the
188*b9411a12SAndroid Build Coastguard Workermaster header and the entry point for the loader firmware.  The bootblock
189*b9411a12SAndroid Build Coastguard Workerdoes not have a component header attached to it.
190*b9411a12SAndroid Build Coastguard Worker
191*b9411a12SAndroid Build Coastguard Worker= Components =
192*b9411a12SAndroid Build Coastguard Worker
193*b9411a12SAndroid Build Coastguard WorkerCBFS components are placed in the ROM starting at 'offset' specified in
194*b9411a12SAndroid Build Coastguard Workerthe master header and ending at the bootblock.  Thus the total size
195*b9411a12SAndroid Build Coastguard Workeravailable
196*b9411a12SAndroid Build Coastguard Workerfor components in the ROM is (ROM size - 20k - 'offset').  Each CBFS
197*b9411a12SAndroid Build Coastguard Workercomponent is to be aligned according to the 'align' value in the header.
198*b9411a12SAndroid Build Coastguard WorkerThus, if a component of size 1052 is located at offset 0 with an 'align'
199*b9411a12SAndroid Build Coastguard Workervalue
200*b9411a12SAndroid Build Coastguard Workerof 1024, the next component will be located at offset 2048.
201*b9411a12SAndroid Build Coastguard Worker
202*b9411a12SAndroid Build Coastguard WorkerEach CBFS component will be indexed with a unique ASCII string name of
203*b9411a12SAndroid Build Coastguard Workerunlimited size.
204*b9411a12SAndroid Build Coastguard Worker
205*b9411a12SAndroid Build Coastguard WorkerEach CBFS component starts with a header:
206*b9411a12SAndroid Build Coastguard Worker
207*b9411a12SAndroid Build Coastguard Workerstruct cbfs_file {
208*b9411a12SAndroid Build Coastguard Worker         char magic[8];
209*b9411a12SAndroid Build Coastguard Worker         unsigned int len;
210*b9411a12SAndroid Build Coastguard Worker         unsigned int type;
211*b9411a12SAndroid Build Coastguard Worker         unsigned int checksum;
212*b9411a12SAndroid Build Coastguard Worker         unsigned int offset;
213*b9411a12SAndroid Build Coastguard Worker};
214*b9411a12SAndroid Build Coastguard Worker
215*b9411a12SAndroid Build Coastguard Worker'magic' is a magic value used to identify the header.  During runtime,
216*b9411a12SAndroid Build Coastguard Workercoreboot will scan the ROM looking for this value.  The default magic is
217*b9411a12SAndroid Build Coastguard Workerthe string 'LARCHIVE'.
218*b9411a12SAndroid Build Coastguard Worker
219*b9411a12SAndroid Build Coastguard Worker'len' is the length of the data, not including the size of the header and
220*b9411a12SAndroid Build Coastguard Workerthe size of the name.
221*b9411a12SAndroid Build Coastguard Worker
222*b9411a12SAndroid Build Coastguard Worker'type' is a 32 bit number indicating the type of data that is attached.
223*b9411a12SAndroid Build Coastguard WorkerThe data type is used in a number of ways, as detailed in the section
224*b9411a12SAndroid Build Coastguard Workerbelow.
225*b9411a12SAndroid Build Coastguard Worker
226*b9411a12SAndroid Build Coastguard Worker'checksum' is a 32bit checksum of the entire component, including the
227*b9411a12SAndroid Build Coastguard Workerheader and name.
228*b9411a12SAndroid Build Coastguard Worker
229*b9411a12SAndroid Build Coastguard Worker'offset' is the start of the component data, based off the start of the
230*b9411a12SAndroid Build Coastguard Workerheader.
231*b9411a12SAndroid Build Coastguard WorkerThe difference between the size of the header and offset is the size of the
232*b9411a12SAndroid Build Coastguard Workercomponent name.
233*b9411a12SAndroid Build Coastguard Worker
234*b9411a12SAndroid Build Coastguard WorkerImmediately following the header will be the name of the component,
235*b9411a12SAndroid Build Coastguard Workerwhich will
236*b9411a12SAndroid Build Coastguard Workernull terminated and 16 byte aligned.   The following picture shows the
237*b9411a12SAndroid Build Coastguard Workerstructure of the header:
238*b9411a12SAndroid Build Coastguard Worker
239*b9411a12SAndroid Build Coastguard Worker/--------\  <- start
240*b9411a12SAndroid Build Coastguard Worker| Header |
241*b9411a12SAndroid Build Coastguard Worker|--------|  <- sizeof(struct cbfs_file)
242*b9411a12SAndroid Build Coastguard Worker| Name   |
243*b9411a12SAndroid Build Coastguard Worker|--------|  <- 'offset'
244*b9411a12SAndroid Build Coastguard Worker| Data   |
245*b9411a12SAndroid Build Coastguard Worker| ...    |
246*b9411a12SAndroid Build Coastguard Worker\--------/  <- start + 'offset' + 'len'
247*b9411a12SAndroid Build Coastguard Worker
248*b9411a12SAndroid Build Coastguard Worker== Searching Algorithm ==
249*b9411a12SAndroid Build Coastguard Worker
250*b9411a12SAndroid Build Coastguard WorkerTo locate a specific component in the ROM, one starts at the 'offset'
251*b9411a12SAndroid Build Coastguard Workerspecified in the CBFS master header.  For this example, the offset will
252*b9411a12SAndroid Build Coastguard Workerbe 0.
253*b9411a12SAndroid Build Coastguard Worker
254*b9411a12SAndroid Build Coastguard Worker From that offset, the code should search for the magic string on the
255*b9411a12SAndroid Build Coastguard Workercomponent, jumping 'align' bytes each time.  So, assuming that 'align' is
256*b9411a12SAndroid Build Coastguard Worker16, the code will search for the string 'LARCHIVE' at offset 0, 16, 32, etc.
257*b9411a12SAndroid Build Coastguard WorkerIf the offset ever exceeds the allowable range for CBFS components, then no
258*b9411a12SAndroid Build Coastguard Workercomponent was found.
259*b9411a12SAndroid Build Coastguard Worker
260*b9411a12SAndroid Build Coastguard WorkerUpon recognizing a component, the software then has to search for the
261*b9411a12SAndroid Build Coastguard Workerspecific name of the component.  This is accomplished by comparing the
262*b9411a12SAndroid Build Coastguard Workerdesired name with the string on the component located at
263*b9411a12SAndroid Build Coastguard Workeroffset + sizeof(struct cbfs_file).  If the string matches, then the
264*b9411a12SAndroid Build Coastguard Workercomponent
265*b9411a12SAndroid Build Coastguard Workerhas been located, otherwise the software should add 'offset' + 'len' to
266*b9411a12SAndroid Build Coastguard Workerthe offset and resume the search for the magic value.
267*b9411a12SAndroid Build Coastguard Worker
268*b9411a12SAndroid Build Coastguard Worker== Data Types ==
269*b9411a12SAndroid Build Coastguard Worker
270*b9411a12SAndroid Build Coastguard WorkerThe 'type' member of struct cbfs_file is used to identify the content
271*b9411a12SAndroid Build Coastguard Workerof the component data, and is used by coreboot and other
272*b9411a12SAndroid Build Coastguard Workerrun-time entities to make decisions about how to handle the data.
273*b9411a12SAndroid Build Coastguard Worker
274*b9411a12SAndroid Build Coastguard WorkerThere are three component types that are essential to coreboot, and so
275*b9411a12SAndroid Build Coastguard Workerare defined here.
276*b9411a12SAndroid Build Coastguard Worker
277*b9411a12SAndroid Build Coastguard Worker=== Stages ===
278*b9411a12SAndroid Build Coastguard Worker
279*b9411a12SAndroid Build Coastguard WorkerStages are code loaded by coreboot during the boot process.  They are
280*b9411a12SAndroid Build Coastguard Workeressential to a successful boot.   Stages are comprised of a single blob
281*b9411a12SAndroid Build Coastguard Workerof binary data that is to be loaded into a particular location in memory
282*b9411a12SAndroid Build Coastguard Workerand executed.   The uncompressed header contains information about how
283*b9411a12SAndroid Build Coastguard Workerlarge the data is, and where it should be placed, and what additional memory
284*b9411a12SAndroid Build Coastguard Workerneeds to be cleared.
285*b9411a12SAndroid Build Coastguard Worker
286*b9411a12SAndroid Build Coastguard WorkerStages are assigned a component value of 0x10.  When coreboot sees this
287*b9411a12SAndroid Build Coastguard Workercomponent type, it knows that it should pass the data to a sub-function
288*b9411a12SAndroid Build Coastguard Workerthat will process the stage.
289*b9411a12SAndroid Build Coastguard Worker
290*b9411a12SAndroid Build Coastguard WorkerThe following is the format of a stage component:
291*b9411a12SAndroid Build Coastguard Worker
292*b9411a12SAndroid Build Coastguard Worker/--------\
293*b9411a12SAndroid Build Coastguard Worker| Header |
294*b9411a12SAndroid Build Coastguard Worker|--------|
295*b9411a12SAndroid Build Coastguard Worker| Binary |
296*b9411a12SAndroid Build Coastguard Worker| ..     |
297*b9411a12SAndroid Build Coastguard Worker\--------/
298*b9411a12SAndroid Build Coastguard Worker
299*b9411a12SAndroid Build Coastguard WorkerThe header is defined as:
300*b9411a12SAndroid Build Coastguard Worker
301*b9411a12SAndroid Build Coastguard Workerstruct cbfs_stage {
302*b9411a12SAndroid Build Coastguard Worker         unsigned int compression;
303*b9411a12SAndroid Build Coastguard Worker         unsigned long long entry;
304*b9411a12SAndroid Build Coastguard Worker         unsigned long long load;
305*b9411a12SAndroid Build Coastguard Worker         unsigned int len;
306*b9411a12SAndroid Build Coastguard Worker         unsigned int memlen;
307*b9411a12SAndroid Build Coastguard Worker};
308*b9411a12SAndroid Build Coastguard Worker
309*b9411a12SAndroid Build Coastguard Worker'compression' is an integer defining how the data is compressed.  There
310*b9411a12SAndroid Build Coastguard Workerare three compression types defined by this version of the standard:
311*b9411a12SAndroid Build Coastguard Workernone (0x0), lzma (0x1), and nrv2b (0x02, deprecated), though additional
312*b9411a12SAndroid Build Coastguard Workertypes may be added assuming that coreboot understands how to handle the scheme.
313*b9411a12SAndroid Build Coastguard Worker
314*b9411a12SAndroid Build Coastguard Worker'entry' is a 64 bit value indicating the location where  the program
315*b9411a12SAndroid Build Coastguard Workercounter should jump following the loading of the stage.  This should be
316*b9411a12SAndroid Build Coastguard Workeran absolute physical memory address.
317*b9411a12SAndroid Build Coastguard Worker
318*b9411a12SAndroid Build Coastguard Worker'load' is a 64 bit value indicating where the subsequent data should be
319*b9411a12SAndroid Build Coastguard Workerloaded.  This should be an absolute physical memory address.
320*b9411a12SAndroid Build Coastguard Worker
321*b9411a12SAndroid Build Coastguard Worker'len' is the length of the compressed data in the component.
322*b9411a12SAndroid Build Coastguard Worker
323*b9411a12SAndroid Build Coastguard Worker'memlen' is the amount of memory that will be used by the component when
324*b9411a12SAndroid Build Coastguard Workerit is loaded.
325*b9411a12SAndroid Build Coastguard Worker
326*b9411a12SAndroid Build Coastguard WorkerThe component data will start immediately following the header.
327*b9411a12SAndroid Build Coastguard Worker
328*b9411a12SAndroid Build Coastguard WorkerWhen coreboot loads a stage, it will first zero the memory from 'load' to
329*b9411a12SAndroid Build Coastguard Worker'memlen'.  It will then decompress the component data according to the
330*b9411a12SAndroid Build Coastguard Workerspecified scheme and place it in memory starting at 'load'.  Following that,
331*b9411a12SAndroid Build Coastguard Workerit will jump execution to the address specified by 'entry'.
332*b9411a12SAndroid Build Coastguard WorkerSome components are designed to execute directly from the ROM - coreboot
333*b9411a12SAndroid Build Coastguard Workerknows which components must do that and will act accordingly.
334*b9411a12SAndroid Build Coastguard Worker
335*b9411a12SAndroid Build Coastguard Worker=== Payloads ===
336*b9411a12SAndroid Build Coastguard Worker
337*b9411a12SAndroid Build Coastguard WorkerPayloads are loaded by coreboot following the boot process.
338*b9411a12SAndroid Build Coastguard Worker
339*b9411a12SAndroid Build Coastguard WorkerStages are assigned a component value of 0x20.  When coreboot sees this
340*b9411a12SAndroid Build Coastguard Workercomponent type, it knows that it should pass the data to a sub-function
341*b9411a12SAndroid Build Coastguard Workerthat will process the payload.  Furthermore, other run time
342*b9411a12SAndroid Build Coastguard Workerapplications such as 'bayou' may easily index all available payloads
343*b9411a12SAndroid Build Coastguard Workeron the system by searching for the payload type.
344*b9411a12SAndroid Build Coastguard Worker
345*b9411a12SAndroid Build Coastguard Worker
346*b9411a12SAndroid Build Coastguard WorkerThe following is the format of a stage component:
347*b9411a12SAndroid Build Coastguard Worker
348*b9411a12SAndroid Build Coastguard Worker/-----------\
349*b9411a12SAndroid Build Coastguard Worker| Header    |
350*b9411a12SAndroid Build Coastguard Worker| Segment 1 |
351*b9411a12SAndroid Build Coastguard Worker| Segment 2 |
352*b9411a12SAndroid Build Coastguard Worker| ...       |
353*b9411a12SAndroid Build Coastguard Worker|-----------|
354*b9411a12SAndroid Build Coastguard Worker| Binary    |
355*b9411a12SAndroid Build Coastguard Worker| ..        |
356*b9411a12SAndroid Build Coastguard Worker\-----------/
357*b9411a12SAndroid Build Coastguard Worker
358*b9411a12SAndroid Build Coastguard WorkerThe header is as follows:
359*b9411a12SAndroid Build Coastguard Worker
360*b9411a12SAndroid Build Coastguard Workerstruct cbfs_payload {
361*b9411a12SAndroid Build Coastguard Worker         struct cbfs_payload_segment segments;
362*b9411a12SAndroid Build Coastguard Worker}
363*b9411a12SAndroid Build Coastguard Worker
364*b9411a12SAndroid Build Coastguard WorkerThe header contains a number of segments corresponding to the segments
365*b9411a12SAndroid Build Coastguard Workerthat need to be loaded for the payload.
366*b9411a12SAndroid Build Coastguard Worker
367*b9411a12SAndroid Build Coastguard WorkerThe following is the structure of each segment header:
368*b9411a12SAndroid Build Coastguard Worker
369*b9411a12SAndroid Build Coastguard Workerstruct cbfs_payload_segment {
370*b9411a12SAndroid Build Coastguard Worker         unsigned int type;
371*b9411a12SAndroid Build Coastguard Worker         unsigned int compression;
372*b9411a12SAndroid Build Coastguard Worker         unsigned int offset;
373*b9411a12SAndroid Build Coastguard Worker         unsigned long long load_addr;
374*b9411a12SAndroid Build Coastguard Worker         unsigned int len;
375*b9411a12SAndroid Build Coastguard Worker         unsigned int mem_len;
376*b9411a12SAndroid Build Coastguard Worker};
377*b9411a12SAndroid Build Coastguard Worker
378*b9411a12SAndroid Build Coastguard Worker'type' is the type of segment, one of the following:
379*b9411a12SAndroid Build Coastguard Worker
380*b9411a12SAndroid Build Coastguard WorkerPAYLOAD_SEGMENT_CODE   0x45444F43   The segment contains executable code
381*b9411a12SAndroid Build Coastguard WorkerPAYLOAD_SEGMENT_DATA   0x41544144   The segment contains data
382*b9411a12SAndroid Build Coastguard WorkerPAYLOAD_SEGMENT_BSS    0x20535342   The memory specified by the segment
383*b9411a12SAndroid Build Coastguard Worker                                     should be zeroed
384*b9411a12SAndroid Build Coastguard WorkerPAYLOAD_SEGMENT_PARAMS 0x41524150   The segment contains information for
385*b9411a12SAndroid Build Coastguard Worker                                     the payload
386*b9411a12SAndroid Build Coastguard WorkerPAYLOAD_SEGMENT_ENTRY  0x52544E45   The segment contains the entry point
387*b9411a12SAndroid Build Coastguard Worker		  		    for the payload
388*b9411a12SAndroid Build Coastguard Worker
389*b9411a12SAndroid Build Coastguard Worker'compression' is the compression scheme for the segment.  Each segment can
390*b9411a12SAndroid Build Coastguard Workerbe independently compressed. There are three compression types defined by
391*b9411a12SAndroid Build Coastguard Workerthis version of the standard: none (0x0), lzma (0x1), and nrv2b
392*b9411a12SAndroid Build Coastguard Worker(0x02, deprecated), though additional types may be added assuming that
393*b9411a12SAndroid Build Coastguard Workercoreboot understands how to handle the scheme.
394*b9411a12SAndroid Build Coastguard Worker
395*b9411a12SAndroid Build Coastguard Worker'offset' is the address of the data within the component, starting from
396*b9411a12SAndroid Build Coastguard Workerthe component header.
397*b9411a12SAndroid Build Coastguard Worker
398*b9411a12SAndroid Build Coastguard Worker'load_addr' is a 64 bit value indicating where the segment should be placed
399*b9411a12SAndroid Build Coastguard Workerin memory.
400*b9411a12SAndroid Build Coastguard Worker
401*b9411a12SAndroid Build Coastguard Worker'len' is a 32 bit value indicating the size of the segment within the
402*b9411a12SAndroid Build Coastguard Workercomponent.
403*b9411a12SAndroid Build Coastguard Worker
404*b9411a12SAndroid Build Coastguard Worker'mem_len' is the size of the data when it is placed into memory.
405*b9411a12SAndroid Build Coastguard Worker
406*b9411a12SAndroid Build Coastguard WorkerThe data will located immediately following the last segment.
407*b9411a12SAndroid Build Coastguard Worker
408*b9411a12SAndroid Build Coastguard Worker=== Option ROMS ===
409*b9411a12SAndroid Build Coastguard Worker
410*b9411a12SAndroid Build Coastguard WorkerThe third specified component type will be Option ROMs.  Option ROMS will
411*b9411a12SAndroid Build Coastguard Workerhave component type '0x30'.  They will have no additional header, the
412*b9411a12SAndroid Build Coastguard Workeruncompressed binary data will be located in the data portion of the
413*b9411a12SAndroid Build Coastguard Workercomponent.
414*b9411a12SAndroid Build Coastguard Worker
415*b9411a12SAndroid Build Coastguard Worker=== NULL ===
416*b9411a12SAndroid Build Coastguard Worker
417*b9411a12SAndroid Build Coastguard WorkerThere is a 4th component type ,defined as NULL (0xFFFFFFFF).  This is
418*b9411a12SAndroid Build Coastguard Workerthe "don't care" component type.  This can be used when the component
419*b9411a12SAndroid Build Coastguard Workertype is not necessary (such as when the name of the component is unique.
420*b9411a12SAndroid Build Coastguard Workeri.e. option_table).  It is recommended that all components be assigned a
421*b9411a12SAndroid Build Coastguard Workerunique type, but NULL can be used when the type does not matter.
422