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