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