]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/EfiRom/EfiRom.h
65c77c4034804a45101b594c9a7934666c0ee7ca
[mirror_edk2.git] / BaseTools / Source / C / EfiRom / EfiRom.h
1 /** @file
2
3 Copyright (c) 1999-2008 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 EfiRom.h
16
17 Abstract:
18
19 This file contains the relevant declarations required
20 to generate Option Rom File
21
22 **/
23
24 #ifndef __EFI_ROM_H__
25 #define __EFI_ROM_H__
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30
31 #include <Common/UefiBaseTypes.h>
32 #include <IndustryStandard/PeImage.h> // for PE32 structure definitions
33
34 #include <IndustryStandard/pci22.h> // for option ROM header structures
35 #include <IndustryStandard/pci30.h>
36
37 #include "Compress.h"
38 #include "CommonLib.h"
39
40 //
41 // Version of this utility
42 //
43 #define UTILITY_NAME "EfiRom"
44 #define UTILITY_MAJOR_VERSION 0
45 #define UTILITY_MINOR_VERSION 1
46
47 //
48 // Define the max length of a filename
49 //
50 #define MAX_PATH 200
51
52 //
53 // Define the default file extension name
54 //
55 #define DEFAULT_OUTPUT_EXTENSION ".rom"
56
57 //
58 // Max size for an option ROM image
59 //
60 #define MAX_OPTION_ROM_SIZE (1024 * 1024 * 16) // 16MB
61
62 //
63 // Values for the indicator field in the PCI data structure
64 //
65 #define INDICATOR_LAST 0x80 // last file in series of files
66
67 //
68 // Masks for the FILE_LIST.FileFlags field
69 //
70 #define FILE_FLAG_BINARY 0x01
71 #define FILE_FLAG_EFI 0x02
72 #define FILE_FLAG_COMPRESS 0x04
73
74 //
75 // Use this linked list structure to keep track of all the filenames
76 // specified on the command line.
77 //
78 typedef struct _FILE_LIST {
79 struct _FILE_LIST *Next;
80 CHAR8 *FileName;
81 UINT32 FileFlags;
82 UINT32 ClassCode;
83 UINT16 CodeRevision;
84 } FILE_LIST;
85
86 //
87 // Use this to track our command-line options
88 //
89 typedef struct {
90 CHAR8 OutFileName[MAX_PATH];
91 INT8 NoLast;
92 UINT16 ClassCode;
93 UINT16 PciRevision;
94 UINT16 VendId;
95 UINT16 DevId;
96 UINT8 VendIdValid;
97 UINT8 DevIdValid;
98 INT8 Verbose;
99 INT8 Quiet;
100 INT8 Debug;
101 INT8 Pci23;
102 INT8 Pci30;
103 INT8 DumpOption;
104 // INT8 Help;
105 // INT8 Version;
106 FILE_LIST *FileList;
107 } OPTIONS;
108
109 //
110 // Make a global structure to keep track of command-line options
111 //
112 static OPTIONS mOptions;
113
114 //
115 // Use these to convert from machine type value to a named type
116 //
117 typedef struct {
118 UINT16 Value;
119 CHAR8 *Name;
120 } STRING_LOOKUP;
121
122 //
123 // Machine Types
124 //
125 static STRING_LOOKUP mMachineTypes[] = {
126 { EFI_IMAGE_MACHINE_IA32, "IA32" },
127 { EFI_IMAGE_MACHINE_IA64, "IA64" },
128 { EFI_IMAGE_MACHINE_EBC, "EBC" },
129 { 0, NULL }
130 };
131
132 //
133 // Subsystem Types
134 //
135 static STRING_LOOKUP mSubsystemTypes[] = {
136 { EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION, "EFI application" },
137 { EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, "EFI boot service driver" },
138 { EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER, "EFI runtime driver" },
139 { 0, NULL }
140 };
141
142 //
143 // Function prototypes
144 //
145 static
146 void
147 Version (
148 VOID
149 )
150 /*++
151
152 Routine Description:
153
154 Displays the utility version to STDOUT
155
156 Arguments:
157
158 None
159
160 Returns:
161
162 None
163
164 --*/
165 ;
166
167 static
168 void
169 Usage (
170 VOID
171 )
172 /*++
173
174 Routine Description:
175
176 Displays the utility usage syntax to STDOUT
177
178 Arguments:
179
180 None
181
182 Returns:
183
184 None
185
186 --*/
187 ;
188
189 static
190 int
191 ParseCommandLine (
192 int Argc,
193 char *Argv[],
194 OPTIONS *Options
195 )
196 /*++
197
198 Routine Description:
199
200 Given the Argc/Argv program arguments, and a pointer to an options structure,
201 parse the command-line options and check their validity.
202
203 Arguments:
204
205 Argc - standard C main() argument count
206 Argv[] - standard C main() argument list
207 Options - pointer to a structure to store the options in
208
209 Returns:
210
211 STATUS_SUCCESS success
212 non-zero otherwise
213
214 --*/
215 ;
216
217 static
218 int
219 CheckPE32File (
220 FILE *Fptr,
221 UINT16 *MachineType,
222 UINT16 *SubSystem
223 )
224 /*++
225
226 Routine Description:
227
228 Given the Argc/Argv program arguments, and a pointer to an options structure,
229 parse the command-line options and check their validity.
230
231 Arguments:
232
233 Argc - standard C main() argument count
234 Argv[] - standard C main() argument list
235 Options - pointer to a structure to store the options in
236
237 Returns:
238
239 STATUS_SUCCESS success
240 non-zero otherwise
241
242 --*/
243 ;
244
245 static
246 int
247 ProcessEfiFile (
248 FILE *OutFptr,
249 FILE_LIST *InFile,
250 UINT16 VendId,
251 UINT16 DevId,
252 UINT32 *Size
253 )
254 /*++
255
256 Routine Description:
257
258 Process a PE32 EFI file.
259
260 Arguments:
261
262 OutFptr - file pointer to output binary ROM image file we're creating
263 InFile - structure contains information on the PE32 file to process
264 VendId - vendor ID as required in the option ROM header
265 DevId - device ID as required in the option ROM header
266 Size - pointer to where to return the size added to the output file
267
268 Returns:
269
270 0 - successful
271
272 --*/
273 ;
274
275 static
276 int
277 ProcessBinFile (
278 FILE *OutFptr,
279 FILE_LIST *InFile,
280 UINT32 *Size
281 )
282 /*++
283
284 Routine Description:
285
286 Process a binary input file.
287
288 Arguments:
289
290 OutFptr - file pointer to output binary ROM image file we're creating
291 InFile - structure contains information on the binary file to process
292 Size - pointer to where to return the size added to the output file
293
294 Returns:
295
296 0 - successful
297
298 --*/
299 ;
300
301 static
302 void
303 DumpImage (
304 FILE_LIST *InFile
305 )
306 /*++
307
308 Routine Description:
309
310 Dump the headers of an existing option ROM image
311
312 Arguments:
313
314 InFile - the file name of an existing option ROM image
315
316 Returns:
317
318 none
319
320 --*/
321 ;
322
323 char *
324 GetMachineTypeStr (
325 UINT16 MachineType
326 )
327 /*++
328
329 Routine Description:
330
331 GC_TODO: Add function description
332
333 Arguments:
334
335 MachineType - GC_TODO: add argument description
336
337 Returns:
338
339 GC_TODO: add return values
340
341 --*/
342 ;
343
344 static
345 char *
346 GetSubsystemTypeStr (
347 UINT16 SubsystemType
348 )
349 /*++
350
351 Routine Description:
352
353 GC_TODO: Add function description
354
355 Arguments:
356
357 SubsystemType - GC_TODO: add argument description
358
359 Returns:
360
361 GC_TODO: add return values
362
363 --*/
364 ;
365
366 #endif