1 /** @file
2   The firmware file related definitions in PI.
3 
4   Copyright (c) 2006 - 2008, Intel Corporation
5   All rights reserved. This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13   @par Revision Reference:
14   PI Version 1.0
15 
16 **/
17 
18 
19 #ifndef __PI_FIRMWARE_FILE_H__
20 #define __PI_FIRMWARE_FILE_H__
21 
22 #include <gpxe/efi/ProcessorBind.h>
23 
24 #pragma pack(1)
25 ///
26 /// Used to verify the integrity of the file.
27 ///
28 typedef union {
29   struct {
30     UINT8   Header;
31     UINT8   File;
32   } Checksum;
33   UINT16    Checksum16;
34 } EFI_FFS_INTEGRITY_CHECK;
35 
36 typedef UINT8 EFI_FV_FILETYPE;
37 typedef UINT8 EFI_FFS_FILE_ATTRIBUTES;
38 typedef UINT8 EFI_FFS_FILE_STATE;
39 
40 ///
41 /// File Types Definitions
42 ///
43 #define EFI_FV_FILETYPE_ALL                   0x00
44 #define EFI_FV_FILETYPE_RAW                   0x01
45 #define EFI_FV_FILETYPE_FREEFORM              0x02
46 #define EFI_FV_FILETYPE_SECURITY_CORE         0x03
47 #define EFI_FV_FILETYPE_PEI_CORE              0x04
48 #define EFI_FV_FILETYPE_DXE_CORE              0x05
49 #define EFI_FV_FILETYPE_PEIM                  0x06
50 #define EFI_FV_FILETYPE_DRIVER                0x07
51 #define EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER  0x08
52 #define EFI_FV_FILETYPE_APPLICATION           0x09
53 #define EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE 0x0B
54 #define EFI_FV_FILETYPE_OEM_MIN               0xc0
55 #define EFI_FV_FILETYPE_OEM_MAX               0xdf
56 #define EFI_FV_FILETYPE_DEBUG_MIN             0xe0
57 #define EFI_FV_FILETYPE_DEBUG_MAX             0xef
58 #define EFI_FV_FILETYPE_FFS_MIN               0xf0
59 #define EFI_FV_FILETYPE_FFS_MAX               0xff
60 #define EFI_FV_FILETYPE_FFS_PAD               0xf0
61 ///
62 /// FFS File Attributes.
63 ///
64 #define FFS_ATTRIB_FIXED              0x04
65 #define FFS_ATTRIB_DATA_ALIGNMENT     0x38
66 #define FFS_ATTRIB_CHECKSUM           0x40
67 
68 ///
69 /// FFS File State Bits.
70 ///
71 #define EFI_FILE_HEADER_CONSTRUCTION  0x01
72 #define EFI_FILE_HEADER_VALID         0x02
73 #define EFI_FILE_DATA_VALID           0x04
74 #define EFI_FILE_MARKED_FOR_UPDATE    0x08
75 #define EFI_FILE_DELETED              0x10
76 #define EFI_FILE_HEADER_INVALID       0x20
77 
78 
79 ///
80 /// Each file begins with the header that describe the
81 /// contents and state of the files.
82 ///
83 typedef struct {
84   EFI_GUID                Name;
85   EFI_FFS_INTEGRITY_CHECK IntegrityCheck;
86   EFI_FV_FILETYPE         Type;
87   EFI_FFS_FILE_ATTRIBUTES Attributes;
88   UINT8                   Size[3];
89   EFI_FFS_FILE_STATE      State;
90 } EFI_FFS_FILE_HEADER;
91 
92 
93 typedef UINT8 EFI_SECTION_TYPE;
94 
95 ///
96 /// Pseudo type. It is
97 /// used as a wild card when retrieving sections. The section
98 /// type EFI_SECTION_ALL matches all section types.
99 ///
100 #define EFI_SECTION_ALL                   0x00
101 
102 ///
103 /// Encapsulation section Type values
104 ///
105 #define EFI_SECTION_COMPRESSION           0x01
106 
107 #define EFI_SECTION_GUID_DEFINED          0x02
108 
109 ///
110 /// Leaf section Type values
111 ///
112 #define EFI_SECTION_PE32                  0x10
113 #define EFI_SECTION_PIC                   0x11
114 #define EFI_SECTION_TE                    0x12
115 #define EFI_SECTION_DXE_DEPEX             0x13
116 #define EFI_SECTION_VERSION               0x14
117 #define EFI_SECTION_USER_INTERFACE        0x15
118 #define EFI_SECTION_COMPATIBILITY16       0x16
119 #define EFI_SECTION_FIRMWARE_VOLUME_IMAGE 0x17
120 #define EFI_SECTION_FREEFORM_SUBTYPE_GUID 0x18
121 #define EFI_SECTION_RAW                   0x19
122 #define EFI_SECTION_PEI_DEPEX             0x1B
123 
124 ///
125 /// Common section header
126 ///
127 typedef struct {
128   UINT8             Size[3];
129   EFI_SECTION_TYPE  Type;
130 } EFI_COMMON_SECTION_HEADER;
131 
132 ///
133 /// Leaf section type that contains an
134 /// IA-32 16-bit executable image.
135 ///
136 typedef EFI_COMMON_SECTION_HEADER EFI_COMPATIBILITY16_SECTION;
137 
138 ///
139 /// CompressionType of EFI_COMPRESSION_SECTION.
140 ///
141 #define EFI_NOT_COMPRESSED        0x00
142 #define EFI_STANDARD_COMPRESSION  0x01
143 ///
144 /// An encapsulation section type in which the
145 /// section data is compressed.
146 ///
147 typedef struct {
148   EFI_COMMON_SECTION_HEADER   CommonHeader;
149   UINT32                      UncompressedLength;
150   UINT8                       CompressionType;
151 } EFI_COMPRESSION_SECTION;
152 
153 ///
154 /// Leaf section which could be used to determine the dispatch order of DXEs.
155 ///
156 typedef EFI_COMMON_SECTION_HEADER EFI_DXE_DEPEX_SECTION;
157 
158 ///
159 /// Leaf section which contains a PI FV.
160 ///
161 typedef EFI_COMMON_SECTION_HEADER EFI_FIRMWARE_VOLUME_IMAGE_SECTION;
162 
163 ///
164 /// Leaf section which contains a single GUID.
165 ///
166 typedef struct {
167   EFI_COMMON_SECTION_HEADER   CommonHeader;
168   EFI_GUID                    SubTypeGuid;
169 } EFI_FREEFORM_SUBTYPE_GUID_SECTION;
170 
171 ///
172 /// Attributes of EFI_GUID_DEFINED_SECTION
173 ///
174 #define EFI_GUIDED_SECTION_PROCESSING_REQUIRED  0x01
175 #define EFI_GUIDED_SECTION_AUTH_STATUS_VALID    0x02
176 ///
177 /// Leaf section which is encapsulation defined by specific GUID
178 ///
179 typedef struct {
180   EFI_COMMON_SECTION_HEADER   CommonHeader;
181   EFI_GUID                    SectionDefinitionGuid;
182   UINT16                      DataOffset;
183   UINT16                      Attributes;
184 } EFI_GUID_DEFINED_SECTION;
185 
186 ///
187 /// Leaf section which contains PE32+ image.
188 ///
189 typedef EFI_COMMON_SECTION_HEADER EFI_PE32_SECTION;
190 
191 
192 ///
193 /// Leaf section which used to determine the dispatch order of PEIMs.
194 ///
195 typedef EFI_COMMON_SECTION_HEADER EFI_PEI_DEPEX_SECTION;
196 
197 ///
198 /// Leaf section which constains the position-independent-code image.
199 ///
200 typedef EFI_COMMON_SECTION_HEADER EFI_TE_SECTION;
201 
202 ///
203 /// Leaf section which contains an array of zero or more bytes.
204 ///
205 typedef EFI_COMMON_SECTION_HEADER EFI_RAW_SECTION;
206 
207 ///
208 /// Leaf section which contains a unicode string that
209 /// is human readable file name.
210 ///
211 typedef struct {
212   EFI_COMMON_SECTION_HEADER   CommonHeader;
213 
214   ///
215   /// Array of unicode string.
216   ///
217   CHAR16                      FileNameString[1];
218 } EFI_USER_INTERFACE_SECTION;
219 
220 
221 ///
222 /// Leaf section which contains a numeric build number and
223 /// an optional unicode string that represents the file revision.
224 ///
225 typedef struct {
226   EFI_COMMON_SECTION_HEADER   CommonHeader;
227   UINT16                      BuildNumber;
228 
229   ///
230   /// Array of unicode string.
231   ///
232   CHAR16                      VersionString[1];
233 } EFI_VERSION_SECTION;
234 
235 
236 #define SECTION_SIZE(SectionHeaderPtr) \
237     ((UINT32) (*((UINT32 *) ((EFI_COMMON_SECTION_HEADER *) SectionHeaderPtr)->Size) & 0x00ffffff))
238 
239 #pragma pack()
240 
241 #endif
242 
243