]>
Commit | Line | Data |
---|---|---|
1 | /*++\r | |
2 | \r | |
3 | Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved\r | |
4 | This software and associated documentation (if any) is furnished\r | |
5 | under a license and may only be used or copied in accordance\r | |
6 | with the terms of the license. Except as permitted by such\r | |
7 | license, no part of this software or documentation may be\r | |
8 | reproduced, stored in a retrieval system, or transmitted in any\r | |
9 | form or by any means without the express written consent of\r | |
10 | Intel Corporation.\r | |
11 | \r | |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | GenFdImageExe.c\r | |
16 | \r | |
17 | Abstract:\r | |
18 | \r | |
19 | This contains all code necessary to build the GenFdImage.exe utility.\r | |
20 | This utility relies heavily on the GenFdImage Lib. Definitions for both \r | |
21 | can be found in the GenFdImage Utility Specification, review draft.\r | |
22 | \r | |
23 | --*/\r | |
24 | \r | |
25 | //\r | |
26 | // Coded to EFI 2.0 Coding Standards\r | |
27 | //\r | |
28 | //\r | |
29 | // Include files\r | |
30 | //\r | |
31 | #include "GenFdImage.h"\r | |
32 | #include "GenFdImageExe.h"\r | |
33 | \r | |
34 | VOID\r | |
35 | PrintUtilityInfo (\r | |
36 | VOID\r | |
37 | )\r | |
38 | /*++\r | |
39 | \r | |
40 | Routine Description:\r | |
41 | \r | |
42 | Displays the standard utility information to SDTOUT\r | |
43 | \r | |
44 | Arguments:\r | |
45 | \r | |
46 | None\r | |
47 | \r | |
48 | Returns:\r | |
49 | \r | |
50 | None\r | |
51 | \r | |
52 | --*/\r | |
53 | {\r | |
54 | printf (\r | |
55 | "%s, EFI 2.0 Firmware Device Image Generation Utility. ""Version %i.%i, %s.\n\n",\r | |
56 | UTILITY_NAME,\r | |
57 | UTILITY_MAJOR_VERSION,\r | |
58 | UTILITY_MINOR_VERSION,\r | |
59 | UTILITY_DATE\r | |
60 | );\r | |
61 | }\r | |
62 | \r | |
63 | VOID\r | |
64 | PrintUsage (\r | |
65 | VOID\r | |
66 | )\r | |
67 | /*++\r | |
68 | \r | |
69 | Routine Description:\r | |
70 | \r | |
71 | Displays the utility usage syntax to STDOUT\r | |
72 | \r | |
73 | Arguments:\r | |
74 | \r | |
75 | None\r | |
76 | \r | |
77 | Returns:\r | |
78 | \r | |
79 | None\r | |
80 | \r | |
81 | --*/\r | |
82 | {\r | |
83 | printf (\r | |
84 | "Usage: %s -B BaseAddress -S Size -F FillByte"" [-I FvInfFileName] -O OutputFileName \n",\r | |
85 | UTILITY_NAME\r | |
86 | );\r | |
87 | printf (" Where:\n");\r | |
88 | printf ("\tBaseAddress is the starting address of the FD Image\n\n");\r | |
89 | printf ("\tSize is the size of the FD Image.\n\n");\r | |
90 | printf ("\tFillByte is the desired value of free space in the Image\n\n");\r | |
91 | printf ("\tFvInfFileName is the name of an FV Image description file.\n\n");\r | |
92 | printf ("\tOutputFileName is the desired output file name.\n\n");\r | |
93 | }\r | |
94 | \r | |
95 | EFI_STATUS\r | |
96 | main (\r | |
97 | IN INTN argc,\r | |
98 | IN CHAR8 **argv\r | |
99 | )\r | |
100 | /*++\r | |
101 | \r | |
102 | Routine Description:\r | |
103 | \r | |
104 | This utility uses GenFdImage.lib to build a Firmware Device Image\r | |
105 | which will include several Firmware Volume Images.\r | |
106 | \r | |
107 | Arguments:\r | |
108 | \r | |
109 | Base Address Base Address of the firmware volume..\r | |
110 | Size Size of the Firmware Volume\r | |
111 | FillByte The byte value which would be needed to pad\r | |
112 | between various Firmware Volumes\r | |
113 | FvInfFile Fv inf file\r | |
114 | OutputFileName The name of output file which would be created\r | |
115 | \r | |
116 | Returns:\r | |
117 | \r | |
118 | EFI_SUCCESS No error conditions detected.\r | |
119 | EFI_INVALID_PARAMETER One or more of the input parameters is invalid.\r | |
120 | EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable. \r | |
121 | Most commonly this will be memory allocation or \r | |
122 | file creation.\r | |
123 | EFI_LOAD_ERROR GenFvImage.lib could not be loaded.\r | |
124 | EFI_ABORTED Error executing the GenFvImage lib.\r | |
125 | \r | |
126 | --*/\r | |
127 | // GC_TODO: argc - add argument and description to function comment\r | |
128 | // GC_TODO: argv - add argument and description to function comment\r | |
129 | {\r | |
130 | UINTN Index;\r | |
131 | UINTN FvFilesCount;\r | |
132 | \r | |
133 | UINT8 i;\r | |
134 | \r | |
135 | UINT64 StartAddress;\r | |
136 | UINT64 Size;\r | |
137 | UINT64 FillByteVal;\r | |
138 | \r | |
139 | CHAR8 **FvInfFileList;\r | |
140 | CHAR8 **OrgFvInfFileList;\r | |
141 | CHAR8 OutputFileName[_MAX_PATH];\r | |
142 | \r | |
143 | EFI_STATUS Status;\r | |
144 | \r | |
145 | INTN arg_counter;\r | |
146 | \r | |
147 | //\r | |
148 | // Echo for makefile debug\r | |
149 | //\r | |
150 | printf ("\n\n");\r | |
151 | for (arg_counter = 0; arg_counter < argc; arg_counter++) {\r | |
152 | printf ("%s ", argv[arg_counter]);\r | |
153 | }\r | |
154 | \r | |
155 | printf ("\n\n");\r | |
156 | \r | |
157 | //\r | |
158 | // Display utility information\r | |
159 | //\r | |
160 | PrintUtilityInfo ();\r | |
161 | \r | |
162 | //\r | |
163 | // Verify the correct number of arguments\r | |
164 | //\r | |
165 | if (argc < MIN_ARGS) {\r | |
166 | printf ("ERROR: missing 1 or more input arguments.\n\n");\r | |
167 | PrintUsage ();\r | |
168 | return EFI_INVALID_PARAMETER;\r | |
169 | }\r | |
170 | //\r | |
171 | // Initialize variables\r | |
172 | //\r | |
173 | StartAddress = 0;\r | |
174 | Size = 0;\r | |
175 | FillByteVal = 0;\r | |
176 | FvFilesCount = 0;\r | |
177 | \r | |
178 | for (i = 1; i < argc; i++) {\r | |
179 | if (stricmp (argv[i], "-I") == 0) {\r | |
180 | FvFilesCount++;\r | |
181 | }\r | |
182 | }\r | |
183 | \r | |
184 | FvInfFileList = malloc (sizeof (UINTN) * (FvFilesCount + 1));\r | |
185 | if (FvInfFileList == NULL) {\r | |
186 | printf ("ERROR: allocating memory for FvInfFileList in -main- function.\n");\r | |
187 | return EFI_OUT_OF_RESOURCES;\r | |
188 | }\r | |
189 | \r | |
190 | memset (FvInfFileList, 0, sizeof (UINTN) * (FvFilesCount + 1));\r | |
191 | \r | |
192 | OrgFvInfFileList = FvInfFileList;\r | |
193 | \r | |
194 | for (Index = 0; Index < FvFilesCount; Index++) {\r | |
195 | *FvInfFileList = malloc (_MAX_PATH);\r | |
196 | memset (*FvInfFileList, 0, _MAX_PATH);\r | |
197 | FvInfFileList++;\r | |
198 | }\r | |
199 | \r | |
200 | strcpy (OutputFileName, "");\r | |
201 | \r | |
202 | //\r | |
203 | // Parse the command line arguments\r | |
204 | //\r | |
205 | FvInfFileList = OrgFvInfFileList;\r | |
206 | \r | |
207 | for (i = 1; i < argc; i += 2) {\r | |
208 | //\r | |
209 | // Make sure argument pair begin with - or /\r | |
210 | //\r | |
211 | if (argv[i][0] != '-' && argv[i][0] != '/') {\r | |
212 | PrintUsage ();\r | |
213 | printf ("ERROR: Argument pair must begin with \"-\" or \"/\"\n");\r | |
214 | return EFI_INVALID_PARAMETER;\r | |
215 | }\r | |
216 | //\r | |
217 | // Make sure argument specifier is only one letter\r | |
218 | //\r | |
219 | if (argv[i][2] != 0) {\r | |
220 | PrintUsage ();\r | |
221 | printf ("ERROR: Unrecognized argument \"%s\".\n", argv[i]);\r | |
222 | return EFI_INVALID_PARAMETER;\r | |
223 | }\r | |
224 | //\r | |
225 | // Determine argument to read\r | |
226 | //\r | |
227 | switch (argv[i][1]) {\r | |
228 | \r | |
229 | case 'I':\r | |
230 | case 'i':\r | |
231 | if ((FvInfFileList != NULL) && (strlen (*FvInfFileList) == 0)) {\r | |
232 | strcpy (*FvInfFileList, argv[i + 1]);\r | |
233 | FvInfFileList++;\r | |
234 | } else {\r | |
235 | printf ("ERROR: FvInfFile Name is more than specifed.\n");\r | |
236 | return EFI_INVALID_PARAMETER;\r | |
237 | }\r | |
238 | break;\r | |
239 | \r | |
240 | case 'O':\r | |
241 | case 'o':\r | |
242 | if (strlen (OutputFileName) == 0) {\r | |
243 | strcpy (OutputFileName, argv[i + 1]);\r | |
244 | } else {\r | |
245 | PrintUsage ();\r | |
246 | printf ("ERROR: OutputFileName may only be specified once.\n");\r | |
247 | return EFI_INVALID_PARAMETER;\r | |
248 | }\r | |
249 | break;\r | |
250 | \r | |
251 | case 'B':\r | |
252 | case 'b':\r | |
253 | Status = AsciiStringToUint64 (argv[i + 1], FALSE, &StartAddress);\r | |
254 | if (Status != EFI_SUCCESS) {\r | |
255 | printf ("\nERROR: Bad FD Image start address specified");\r | |
256 | return EFI_INVALID_PARAMETER;\r | |
257 | }\r | |
258 | break;\r | |
259 | \r | |
260 | case 'S':\r | |
261 | case 's':\r | |
262 | Status = AsciiStringToUint64 (argv[i + 1], FALSE, &Size);\r | |
263 | if (Status != EFI_SUCCESS) {\r | |
264 | printf ("\nERROR: Bad FD Image size specified");\r | |
265 | return EFI_INVALID_PARAMETER;\r | |
266 | }\r | |
267 | break;\r | |
268 | \r | |
269 | case 'F':\r | |
270 | case 'f':\r | |
271 | Status = AsciiStringToUint64 (argv[i + 1], FALSE, &FillByteVal);\r | |
272 | if (Status != EFI_SUCCESS) {\r | |
273 | printf ("\nERROR: Not a recognized Fill Byte value");\r | |
274 | return EFI_INVALID_PARAMETER;\r | |
275 | }\r | |
276 | break;\r | |
277 | \r | |
278 | default:\r | |
279 | PrintUsage ();\r | |
280 | printf ("ERROR: Unrecognized argument \"%s\".\n", argv[i]);\r | |
281 | return EFI_INVALID_PARAMETER;\r | |
282 | break;\r | |
283 | }\r | |
284 | }\r | |
285 | //\r | |
286 | // Call the GenFdImage Lib\r | |
287 | //\r | |
288 | FvInfFileList = OrgFvInfFileList;\r | |
289 | \r | |
290 | Status = GenerateFdImage (\r | |
291 | StartAddress,\r | |
292 | Size,\r | |
293 | (UINT8) FillByteVal,\r | |
294 | OutputFileName,\r | |
295 | FvInfFileList\r | |
296 | );\r | |
297 | \r | |
298 | if (EFI_ERROR (Status)) {\r | |
299 | switch (Status) {\r | |
300 | \r | |
301 | case EFI_INVALID_PARAMETER:\r | |
302 | printf ("\nERROR: Invalid parameter passed to GenFdImage lib.\n");\r | |
303 | break;\r | |
304 | \r | |
305 | case EFI_ABORTED:\r | |
306 | printf ("\nERROR: Error detected while creating the file image.\n");\r | |
307 | break;\r | |
308 | \r | |
309 | case EFI_OUT_OF_RESOURCES:\r | |
310 | printf ("\nERROR: GenFdImage Lib could not allocate required resources.\n");\r | |
311 | break;\r | |
312 | \r | |
313 | case EFI_VOLUME_CORRUPTED:\r | |
314 | printf ("\nERROR: No base address was specified \n");\r | |
315 | break;\r | |
316 | \r | |
317 | case EFI_LOAD_ERROR:\r | |
318 | printf ("\nERROR: An error occurred loading one of the required support Lib.\n");\r | |
319 | break;\r | |
320 | \r | |
321 | default:\r | |
322 | printf ("\nERROR: GenFdImage lib returned unknown status %X.\n", Status);\r | |
323 | break;\r | |
324 | }\r | |
325 | \r | |
326 | return Status;\r | |
327 | }\r | |
328 | \r | |
329 | return EFI_SUCCESS;\r | |
330 | }\r |