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