]>
Commit | Line | Data |
---|---|---|
30fdf114 | 1 | /** @file\r |
97fa0ee9 YL |
2 | This contains all code necessary to build the GenFvImage.exe utility. \r |
3 | This utility relies heavily on the GenFvImage Lib. Definitions for both\r | |
4 | can be found in the Tiano Firmware Volume Generation Utility \r | |
5 | Specification, review draft.\r | |
30fdf114 | 6 | \r |
1be2ed90 | 7 | Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r |
40d841f6 | 8 | This program and the accompanying materials \r |
30fdf114 LG |
9 | are licensed and made available under the terms and conditions of the BSD License \r |
10 | which accompanies this distribution. The full text of the license may be found at \r | |
11 | http://opensource.org/licenses/bsd-license.php \r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
15 | \r | |
30fdf114 LG |
16 | **/\r |
17 | \r | |
18 | //\r | |
19 | // File included in build\r | |
20 | //\r | |
21 | #include <stdio.h>\r | |
22 | #include <string.h>\r | |
23 | #include <stdlib.h>\r | |
24 | #include "GenFvInternalLib.h"\r | |
25 | \r | |
26 | //\r | |
27 | // Utility Name\r | |
28 | //\r | |
29 | #define UTILITY_NAME "GenFv"\r | |
30 | \r | |
31 | //\r | |
32 | // Utility version information\r | |
33 | //\r | |
34 | #define UTILITY_MAJOR_VERSION 0\r | |
35 | #define UTILITY_MINOR_VERSION 1\r | |
30fdf114 LG |
36 | \r |
37 | EFI_GUID mEfiFirmwareFileSystem2Guid = EFI_FIRMWARE_FILE_SYSTEM2_GUID;\r | |
e8a47801 | 38 | EFI_GUID mEfiFirmwareFileSystem3Guid = EFI_FIRMWARE_FILE_SYSTEM3_GUID;\r |
30fdf114 LG |
39 | \r |
40 | STATIC\r | |
41 | VOID \r | |
42 | Version (\r | |
43 | VOID\r | |
44 | )\r | |
45 | /*++\r | |
46 | \r | |
47 | Routine Description:\r | |
48 | \r | |
49 | Displays the standard utility information to SDTOUT\r | |
50 | \r | |
51 | Arguments:\r | |
52 | \r | |
53 | None\r | |
54 | \r | |
55 | Returns:\r | |
56 | \r | |
57 | None\r | |
58 | \r | |
59 | --*/\r | |
60 | {\r | |
b36d134f | 61 | fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r |
30fdf114 LG |
62 | }\r |
63 | \r | |
64 | STATIC\r | |
65 | VOID \r | |
66 | Usage (\r | |
67 | VOID\r | |
68 | )\r | |
69 | /*++\r | |
70 | \r | |
71 | Routine Description:\r | |
72 | \r | |
73 | Displays the utility usage syntax to STDOUT\r | |
74 | \r | |
75 | Arguments:\r | |
76 | \r | |
77 | None\r | |
78 | \r | |
79 | Returns:\r | |
80 | \r | |
81 | None\r | |
82 | \r | |
83 | --*/\r | |
84 | {\r | |
85 | //\r | |
86 | // Summary usage\r | |
87 | //\r | |
88 | fprintf (stdout, "\nUsage: %s [options]\n\n", UTILITY_NAME);\r | |
89 | \r | |
90 | //\r | |
91 | // Copyright declaration\r | |
92 | // \r | |
1be2ed90 | 93 | fprintf (stdout, "Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.\n\n");\r |
30fdf114 LG |
94 | \r |
95 | //\r | |
96 | // Details Option\r | |
97 | //\r | |
98 | fprintf (stdout, "Options:\n");\r | |
99 | fprintf (stdout, " -o FileName, --outputfile FileName\n\\r | |
100 | File is the FvImage or CapImage to be created.\n");\r | |
101 | fprintf (stdout, " -i FileName, --inputfile FileName\n\\r | |
102 | File is the input FV.inf or Cap.inf to specify\n\\r | |
103 | how to construct FvImage or CapImage.\n");\r | |
104 | fprintf (stdout, " -b BlockSize, --blocksize BlockSize\n\\r | |
105 | BlockSize is one HEX or DEC format value\n\\r | |
106 | BlockSize is required by Fv Image.\n");\r | |
107 | fprintf (stdout, " -n NumberBlock, --numberblock NumberBlock\n\\r | |
108 | NumberBlock is one HEX or DEC format value\n\\r | |
109 | NumberBlock is one optional parameter.\n");\r | |
110 | fprintf (stdout, " -f FfsFile, --ffsfile FfsFile\n\\r | |
111 | FfsFile is placed into Fv Image\n\\r | |
112 | multi files can input one by one\n");\r | |
113 | fprintf (stdout, " -s FileTakenSize, --filetakensize FileTakenSize\n\\r | |
114 | FileTakenSize specifies the size of the required\n\\r | |
115 | space that the input file is placed in Fvimage.\n\\r | |
116 | It is specified together with the input file.\n");\r | |
117 | fprintf (stdout, " -r Address, --baseaddr Address\n\\r | |
118 | Address is the rebase start address for drivers that\n\\r | |
119 | run in Flash. It supports DEC or HEX digital format.\n\\r | |
120 | If it is set to zero, no rebase action will be taken\n");\r | |
79b74a03 LG |
121 | fprintf (stdout, " -F ForceRebase, --force-rebase ForceRebase\n\\r |
122 | If value is TRUE, will always take rebase action\n\\r | |
123 | If value is FALSE, will always not take reabse action\n\\r | |
124 | If not specified, will take rebase action if rebase address greater than zero, \n\\r | |
125 | will not take rebase action if rebase address is zero.\n");\r | |
30fdf114 | 126 | fprintf (stdout, " -a AddressFile, --addrfile AddressFile\n\\r |
52302d4d LG |
127 | AddressFile is one file used to record the child\n\\r |
128 | FV base address when current FV base address is set.\n");\r | |
30fdf114 LG |
129 | fprintf (stdout, " -m logfile, --map logfile\n\\r |
130 | Logfile is the output fv map file name. if it is not\n\\r | |
131 | given, the FvName.map will be the default map file name\n"); \r | |
a709adfa | 132 | fprintf (stdout, " -g Guid, --guid Guid\n\\r |
30fdf114 LG |
133 | GuidValue is one specific capsule guid value\n\\r |
134 | or fv file system guid value.\n\\r | |
135 | Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");\r | |
a709adfa | 136 | fprintf (stdout, " --FvNameGuid Guid Guid is used to specify Fv Name.\n\\r |
30fdf114 LG |
137 | Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");\r |
138 | fprintf (stdout, " --capflag CapFlag Capsule Reset Flag can be PersistAcrossReset,\n\\r | |
fd171542 | 139 | or PopulateSystemTable or InitiateReset or not set\n");\r |
e8a47801 LG |
140 | fprintf (stdout, " --capoemflag CapOEMFlag\n\\r |
141 | Capsule OEM Flag is an integer between 0x0000 and 0xffff\n");\r | |
30fdf114 LG |
142 | fprintf (stdout, " --capheadsize HeadSize\n\\r |
143 | HeadSize is one HEX or DEC format value\n\\r | |
144 | HeadSize is required by Capsule Image.\n"); \r | |
145 | fprintf (stdout, " -c, --capsule Create Capsule Image.\n");\r | |
146 | fprintf (stdout, " -p, --dump Dump Capsule Image header.\n");\r | |
147 | fprintf (stdout, " -v, --verbose Turn on verbose output with informational messages.\n");\r | |
148 | fprintf (stdout, " -q, --quiet Disable all messages except key message and fatal error\n");\r | |
149 | fprintf (stdout, " -d, --debug level Enable debug messages, at input debug level.\n");\r | |
150 | fprintf (stdout, " --version Show program's version number and exit.\n");\r | |
151 | fprintf (stdout, " -h, --help Show this help message and exit.\n");\r | |
152 | }\r | |
153 | \r | |
154 | UINT32 mFvTotalSize;\r | |
155 | UINT32 mFvTakenSize;\r | |
156 | \r | |
157 | int\r | |
158 | main (\r | |
159 | IN int argc,\r | |
160 | IN char **argv\r | |
161 | )\r | |
162 | /*++\r | |
163 | \r | |
164 | Routine Description:\r | |
165 | \r | |
166 | This utility uses GenFvImage.Lib to build a firmware volume image.\r | |
167 | \r | |
168 | Arguments:\r | |
169 | \r | |
170 | FvInfFileName The name of an FV image description file or Capsule Image.\r | |
171 | \r | |
172 | Arguments come in pair in any order.\r | |
173 | -I FvInfFileName \r | |
174 | \r | |
175 | Returns:\r | |
176 | \r | |
177 | EFI_SUCCESS No error conditions detected.\r | |
178 | EFI_INVALID_PARAMETER One or more of the input parameters is invalid.\r | |
179 | EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable. \r | |
180 | Most commonly this will be memory allocation \r | |
181 | or file creation.\r | |
182 | EFI_LOAD_ERROR GenFvImage.lib could not be loaded.\r | |
183 | EFI_ABORTED Error executing the GenFvImage lib.\r | |
184 | \r | |
185 | --*/\r | |
186 | {\r | |
187 | EFI_STATUS Status;\r | |
188 | CHAR8 *InfFileName;\r | |
189 | CHAR8 *AddrFileName;\r | |
190 | CHAR8 *MapFileName;\r | |
191 | CHAR8 *InfFileImage;\r | |
192 | UINT32 InfFileSize;\r | |
193 | CHAR8 *OutFileName;\r | |
30fdf114 LG |
194 | BOOLEAN CapsuleFlag;\r |
195 | BOOLEAN DumpCapsule;\r | |
30fdf114 LG |
196 | FILE *FpFile;\r |
197 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
198 | UINT64 LogLevel, TempNumber;\r | |
199 | UINT32 Index;\r | |
200 | \r | |
201 | InfFileName = NULL;\r | |
202 | AddrFileName = NULL;\r | |
203 | InfFileImage = NULL;\r | |
204 | OutFileName = NULL;\r | |
205 | MapFileName = NULL;\r | |
206 | InfFileSize = 0;\r | |
207 | CapsuleFlag = FALSE;\r | |
208 | DumpCapsule = FALSE;\r | |
209 | FpFile = NULL;\r | |
210 | CapsuleHeader = NULL;\r | |
211 | LogLevel = 0;\r | |
212 | TempNumber = 0;\r | |
213 | Index = 0;\r | |
214 | mFvTotalSize = 0;\r | |
215 | mFvTakenSize = 0;\r | |
fd171542 | 216 | Status = EFI_SUCCESS;\r |
30fdf114 LG |
217 | \r |
218 | SetUtilityName (UTILITY_NAME);\r | |
219 | \r | |
220 | if (argc == 1) {\r | |
221 | Error (NULL, 0, 1001, "Missing options", "No input options specified.");\r | |
222 | Usage ();\r | |
223 | return STATUS_ERROR;\r | |
224 | }\r | |
225 | \r | |
226 | //\r | |
227 | // Init global data to Zero\r | |
228 | //\r | |
229 | memset (&mFvDataInfo, 0, sizeof (FV_INFO));\r | |
230 | memset (&mCapDataInfo, 0, sizeof (CAP_INFO)); \r | |
fd171542 | 231 | //\r |
232 | // Set the default FvGuid\r | |
233 | //\r | |
234 | memcpy (&mFvDataInfo.FvFileSystemGuid, &mEfiFirmwareFileSystem2Guid, sizeof (EFI_GUID));\r | |
79b74a03 | 235 | mFvDataInfo.ForceRebase = -1;\r |
30fdf114 LG |
236 | \r |
237 | //\r | |
238 | // Parse command line\r | |
239 | //\r | |
240 | argc --;\r | |
241 | argv ++;\r | |
242 | \r | |
243 | if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {\r | |
244 | Version ();\r | |
245 | Usage ();\r | |
246 | return STATUS_SUCCESS; \r | |
247 | }\r | |
248 | \r | |
249 | if (stricmp (argv[0], "--version") == 0) {\r | |
250 | Version ();\r | |
251 | return STATUS_SUCCESS; \r | |
252 | }\r | |
253 | \r | |
254 | while (argc > 0) {\r | |
255 | if ((stricmp (argv[0], "-i") == 0) || (stricmp (argv[0], "--inputfile") == 0)) {\r | |
256 | InfFileName = argv[1];\r | |
257 | if (InfFileName == NULL) {\r | |
258 | Error (NULL, 0, 1003, "Invalid option value", "Input file can't be null");\r | |
259 | return STATUS_ERROR;\r | |
260 | }\r | |
261 | argc -= 2;\r | |
262 | argv += 2;\r | |
263 | continue; \r | |
264 | }\r | |
265 | \r | |
266 | if ((stricmp (argv[0], "-a") == 0) || (stricmp (argv[0], "--addrfile") == 0)) {\r | |
267 | AddrFileName = argv[1];\r | |
268 | if (AddrFileName == NULL) {\r | |
269 | Error (NULL, 0, 1003, "Invalid option value", "Address file can't be null");\r | |
270 | return STATUS_ERROR;\r | |
271 | }\r | |
272 | argc -= 2;\r | |
273 | argv += 2;\r | |
274 | continue; \r | |
275 | }\r | |
276 | \r | |
277 | if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--outputfile") == 0)) {\r | |
278 | OutFileName = argv[1];\r | |
279 | if (OutFileName == NULL) {\r | |
280 | Error (NULL, 0, 1003, "Invalid option value", "Output file can't be null");\r | |
281 | return STATUS_ERROR;\r | |
282 | }\r | |
283 | argc -= 2;\r | |
284 | argv += 2;\r | |
285 | continue; \r | |
286 | }\r | |
287 | \r | |
288 | if ((stricmp (argv[0], "-r") == 0) || (stricmp (argv[0], "--baseaddr") == 0)) {\r | |
289 | Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r | |
290 | if (EFI_ERROR (Status)) {\r | |
291 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r | |
292 | return STATUS_ERROR; \r | |
293 | }\r | |
294 | mFvDataInfo.BaseAddress = TempNumber;\r | |
295 | mFvDataInfo.BaseAddressSet = TRUE;\r | |
296 | argc -= 2;\r | |
297 | argv += 2;\r | |
298 | continue; \r | |
299 | }\r | |
300 | \r | |
301 | if ((stricmp (argv[0], "-b") == 0) || (stricmp (argv[0], "--blocksize") == 0)) {\r | |
302 | Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r | |
303 | if (EFI_ERROR (Status)) {\r | |
304 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r | |
305 | return STATUS_ERROR; \r | |
306 | }\r | |
307 | if (TempNumber == 0) {\r | |
308 | Error (NULL, 0, 1003, "Invalid option value", "Fv block size can't be be set to zero");\r | |
309 | return STATUS_ERROR; \r | |
310 | }\r | |
311 | mFvDataInfo.FvBlocks[0].Length = (UINT32) TempNumber;\r | |
fd171542 | 312 | DebugMsg (NULL, 0, 9, "FV Block Size", "%s = 0x%llx", EFI_BLOCK_SIZE_STRING, (unsigned long long) TempNumber);\r |
30fdf114 LG |
313 | argc -= 2;\r |
314 | argv += 2;\r | |
315 | continue; \r | |
316 | }\r | |
317 | \r | |
318 | if ((stricmp (argv[0], "-n") == 0) || (stricmp (argv[0], "--numberblock") == 0)) {\r | |
319 | Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r | |
320 | if (EFI_ERROR (Status)) {\r | |
321 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r | |
322 | return STATUS_ERROR; \r | |
323 | }\r | |
324 | if (TempNumber == 0) {\r | |
325 | Error (NULL, 0, 1003, "Invalid option value", "Fv block number can't be set to zero");\r | |
326 | return STATUS_ERROR; \r | |
327 | }\r | |
328 | mFvDataInfo.FvBlocks[0].NumBlocks = (UINT32) TempNumber;\r | |
fd171542 | 329 | DebugMsg (NULL, 0, 9, "FV Number Block", "%s = 0x%llx", EFI_NUM_BLOCKS_STRING, (unsigned long long) TempNumber);\r |
30fdf114 LG |
330 | argc -= 2;\r |
331 | argv += 2;\r | |
332 | continue; \r | |
333 | }\r | |
334 | \r | |
79b74a03 | 335 | if ((strcmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--ffsfile") == 0)) {\r |
30fdf114 LG |
336 | if (argv[1] == NULL) {\r |
337 | Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile can't be null");\r | |
338 | return STATUS_ERROR;\r | |
339 | }\r | |
340 | strcpy (mFvDataInfo.FvFiles[Index], argv[1]);\r | |
fd171542 | 341 | DebugMsg (NULL, 0, 9, "FV component file", "the %uth name is %s", (unsigned) Index + 1, argv[1]);\r |
30fdf114 LG |
342 | argc -= 2;\r |
343 | argv += 2;\r | |
344 | \r | |
345 | if (argc > 0) {\r | |
346 | if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--filetakensize") == 0)) {\r | |
347 | if (argv[1] == NULL) {\r | |
348 | Error (NULL, 0, 1003, "Invalid option value", "Ffsfile Size can't be null");\r | |
349 | return STATUS_ERROR;\r | |
350 | }\r | |
351 | Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r | |
352 | if (EFI_ERROR (Status)) {\r | |
353 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r | |
354 | return STATUS_ERROR; \r | |
355 | }\r | |
fd171542 | 356 | mFvDataInfo.SizeofFvFiles[Index] = (UINT32) TempNumber;\r |
357 | DebugMsg (NULL, 0, 9, "FV component file size", "the %uth size is %s", (unsigned) Index + 1, argv[1]);\r | |
30fdf114 LG |
358 | argc -= 2;\r |
359 | argv += 2;\r | |
360 | }\r | |
361 | }\r | |
362 | Index ++;\r | |
363 | continue; \r | |
364 | }\r | |
365 | \r | |
366 | if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--filetakensize") == 0)) {\r | |
367 | Error (NULL, 0, 1003, "Invalid option", "It must be specified together with -f option to specify the file size.");\r | |
368 | return STATUS_ERROR; \r | |
369 | }\r | |
370 | \r | |
371 | if ((stricmp (argv[0], "-c") == 0) || (stricmp (argv[0], "--capsule") == 0)) {\r | |
372 | CapsuleFlag = TRUE;\r | |
373 | argc --;\r | |
374 | argv ++;\r | |
375 | continue; \r | |
376 | }\r | |
79b74a03 LG |
377 | \r |
378 | if ((strcmp (argv[0], "-F") == 0) || (stricmp (argv[0], "--force-rebase") == 0)) {\r | |
379 | if (argv[1] == NULL) {\r | |
380 | Error (NULL, 0, 1003, "Invalid option value", "Froce rebase flag can't be null");\r | |
381 | return STATUS_ERROR;\r | |
382 | }\r | |
383 | \r | |
384 | if (stricmp (argv[1], "TRUE") == 0) {\r | |
385 | mFvDataInfo.ForceRebase = 1;\r | |
386 | } else if (stricmp (argv[1], "FALSE") == 0) {\r | |
387 | mFvDataInfo.ForceRebase = 0;\r | |
388 | } else {\r | |
389 | Error (NULL, 0, 1003, "Invalid option value", "froce rebase flag value must be \"TRUE\" or \"FALSE\"");\r | |
390 | return STATUS_ERROR;\r | |
391 | }\r | |
392 | \r | |
393 | argc -= 2;\r | |
394 | argv += 2;\r | |
395 | continue; \r | |
396 | } \r | |
30fdf114 LG |
397 | \r |
398 | if (stricmp (argv[0], "--capheadsize") == 0) {\r | |
399 | //\r | |
400 | // Get Capsule Image Header Size\r | |
401 | //\r | |
402 | Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r | |
403 | if (EFI_ERROR (Status)) {\r | |
404 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r | |
405 | return STATUS_ERROR; \r | |
406 | }\r | |
407 | mCapDataInfo.HeaderSize = (UINT32) TempNumber;\r | |
fd171542 | 408 | DebugMsg (NULL, 0, 9, "Capsule Header size", "%s = 0x%llx", EFI_CAPSULE_HEADER_SIZE_STRING, (unsigned long long) TempNumber);\r |
30fdf114 LG |
409 | argc -= 2;\r |
410 | argv += 2;\r | |
411 | continue; \r | |
412 | }\r | |
413 | \r | |
414 | if (stricmp (argv[0], "--capflag") == 0) {\r | |
415 | //\r | |
416 | // Get Capsule Header\r | |
417 | //\r | |
418 | if (argv[1] == NULL) {\r | |
419 | Error (NULL, 0, 1003, "Option value is not set", "%s = %s", argv[0], argv[1]);\r | |
420 | return STATUS_ERROR;\r | |
421 | }\r | |
422 | if (strcmp (argv[1], "PopulateSystemTable") == 0) {\r | |
423 | mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE;\r | |
424 | } else if (strcmp (argv[1], "PersistAcrossReset") == 0) {\r | |
425 | mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET;\r | |
fd171542 | 426 | } else if (strcmp (argv[1], "InitiateReset") == 0) {\r |
427 | mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET;\r | |
30fdf114 LG |
428 | } else {\r |
429 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r | |
430 | return STATUS_ERROR;\r | |
431 | }\r | |
432 | DebugMsg (NULL, 0, 9, "Capsule Flag", argv[1]);\r | |
433 | argc -= 2;\r | |
434 | argv += 2;\r | |
435 | continue; \r | |
436 | }\r | |
437 | \r | |
e8a47801 LG |
438 | if (stricmp (argv[0], "--capoemflag") == 0) {\r |
439 | if (argv[1] == NULL) {\r | |
440 | Error (NULL, 0, 1003, "Invalid option value", "Capsule OEM flag can't be null");\r | |
441 | }\r | |
442 | Status = AsciiStringToUint64(argv[1], FALSE, &TempNumber);\r | |
443 | if (EFI_ERROR (Status) || TempNumber > 0xffff) {\r | |
444 | Error (NULL, 0, 1003, "Invalid option value", "Capsule OEM flag value must be integer value between 0x0000 and 0xffff");\r | |
445 | return STATUS_ERROR;\r | |
446 | }\r | |
447 | mCapDataInfo.Flags |= TempNumber;\r | |
448 | DebugMsg( NULL, 0, 9, "Capsule OEM Flags", argv[1]);\r | |
449 | argc -= 2;\r | |
450 | argv += 2;\r | |
451 | continue;\r | |
452 | }\r | |
453 | \r | |
30fdf114 LG |
454 | if (stricmp (argv[0], "--capguid") == 0) {\r |
455 | //\r | |
456 | // Get the Capsule Guid\r | |
457 | //\r | |
458 | Status = StringToGuid (argv[1], &mCapDataInfo.CapGuid);\r | |
459 | if (EFI_ERROR (Status)) {\r | |
460 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);\r | |
461 | return STATUS_ERROR;\r | |
462 | }\r | |
463 | DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);\r | |
464 | argc -= 2;\r | |
465 | argv += 2;\r | |
466 | continue; \r | |
467 | }\r | |
468 | \r | |
469 | if ((stricmp (argv[0], "-g") == 0) || (stricmp (argv[0], "--guid") == 0)) {\r | |
470 | //\r | |
471 | // Get the Capsule or Fv Guid\r | |
472 | //\r | |
473 | Status = StringToGuid (argv[1], &mCapDataInfo.CapGuid);\r | |
474 | if (EFI_ERROR (Status)) {\r | |
475 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_GUID_STRING, argv[1]);\r | |
476 | return STATUS_ERROR;\r | |
477 | }\r | |
478 | memcpy (&mFvDataInfo.FvFileSystemGuid, &mCapDataInfo.CapGuid, sizeof (EFI_GUID));\r | |
479 | mFvDataInfo.FvFileSystemGuidSet = TRUE;\r | |
480 | DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);\r | |
481 | DebugMsg (NULL, 0, 9, "FV Guid", "%s = %s", EFI_FV_FILESYSTEMGUID_STRING, argv[1]);\r | |
482 | argc -= 2;\r | |
483 | argv += 2;\r | |
484 | continue; \r | |
485 | }\r | |
486 | \r | |
487 | if (stricmp (argv[0], "--FvNameGuid") == 0) {\r | |
488 | //\r | |
489 | // Get Fv Name Guid\r | |
490 | //\r | |
491 | Status = StringToGuid (argv[1], &mFvDataInfo.FvNameGuid);\r | |
492 | if (EFI_ERROR (Status)) {\r | |
493 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_GUID_STRING, argv[1]);\r | |
494 | return STATUS_ERROR;\r | |
495 | }\r | |
496 | mFvDataInfo.FvNameGuidSet = TRUE;\r | |
497 | DebugMsg (NULL, 0, 9, "FV Name Guid", "%s = %s", EFI_FV_NAMEGUID_STRING, argv[1]);\r | |
498 | argc -= 2;\r | |
499 | argv += 2;\r | |
500 | continue; \r | |
501 | }\r | |
502 | \r | |
503 | if ((stricmp (argv[0], "-p") == 0) || (stricmp (argv[0], "--dump") == 0)) {\r | |
504 | DumpCapsule = TRUE;\r | |
505 | argc --;\r | |
506 | argv ++;\r | |
507 | continue; \r | |
508 | }\r | |
509 | \r | |
510 | if ((stricmp (argv[0], "-m") == 0) || (stricmp (argv[0], "--map") == 0)) {\r | |
511 | MapFileName = argv[1];\r | |
512 | if (MapFileName == NULL) {\r | |
513 | Error (NULL, 0, 1003, "Invalid option value", "Map file can't be null");\r | |
514 | return STATUS_ERROR;\r | |
515 | }\r | |
516 | argc -= 2;\r | |
517 | argv += 2;\r | |
518 | continue; \r | |
519 | }\r | |
520 | \r | |
521 | if ((stricmp (argv[0], "-v") == 0) || (stricmp (argv[0], "--verbose") == 0)) {\r | |
522 | SetPrintLevel (VERBOSE_LOG_LEVEL);\r | |
523 | VerboseMsg ("Verbose output Mode Set!");\r | |
524 | argc --;\r | |
525 | argv ++;\r | |
526 | continue;\r | |
527 | }\r | |
528 | \r | |
529 | if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {\r | |
530 | SetPrintLevel (KEY_LOG_LEVEL);\r | |
531 | KeyMsg ("Quiet output Mode Set!");\r | |
532 | argc --;\r | |
533 | argv ++;\r | |
534 | continue;\r | |
535 | }\r | |
536 | \r | |
537 | if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {\r | |
538 | Status = AsciiStringToUint64 (argv[1], FALSE, &LogLevel);\r | |
539 | if (EFI_ERROR (Status)) {\r | |
540 | Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r | |
541 | return STATUS_ERROR;\r | |
542 | }\r | |
543 | if (LogLevel > 9) {\r | |
fd171542 | 544 | Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, current input level is %d", (int) LogLevel);\r |
30fdf114 LG |
545 | return STATUS_ERROR;\r |
546 | }\r | |
547 | SetPrintLevel (LogLevel);\r | |
548 | DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[1]);\r | |
549 | argc -= 2;\r | |
550 | argv += 2;\r | |
551 | continue;\r | |
552 | }\r | |
553 | \r | |
554 | //\r | |
555 | // Don't recognize the parameter.\r | |
556 | //\r | |
557 | Error (NULL, 0, 1000, "Unknown option", "%s", argv[0]);\r | |
558 | return STATUS_ERROR;\r | |
559 | }\r | |
560 | \r | |
561 | VerboseMsg ("%s tool start.", UTILITY_NAME);\r | |
562 | \r | |
563 | //\r | |
564 | // check input parameter, InfFileName can be NULL\r | |
565 | //\r | |
566 | if (InfFileName == NULL && DumpCapsule) {\r | |
567 | Error (NULL, 0, 1001, "Missing option", "Input Capsule Image");\r | |
568 | return STATUS_ERROR;\r | |
569 | }\r | |
570 | VerboseMsg ("the input FvInf or CapInf file name is %s", InfFileName);\r | |
571 | \r | |
572 | if (!DumpCapsule && OutFileName == NULL) {\r | |
573 | Error (NULL, 0, 1001, "Missing option", "Output File");\r | |
574 | return STATUS_ERROR;\r | |
575 | }\r | |
576 | if (OutFileName != NULL) {\r | |
577 | VerboseMsg ("the output file name is %s", OutFileName);\r | |
578 | }\r | |
579 | \r | |
30fdf114 LG |
580 | //\r |
581 | // Read the INF file image\r | |
582 | //\r | |
583 | if (InfFileName != NULL) {\r | |
584 | Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);\r | |
585 | if (EFI_ERROR (Status)) {\r | |
586 | return STATUS_ERROR;\r | |
587 | }\r | |
588 | }\r | |
589 | \r | |
590 | if (DumpCapsule) {\r | |
591 | VerboseMsg ("Dump the capsule header information for the input capsule image %s", InfFileName);\r | |
592 | //\r | |
593 | // Dump Capsule Image Header Information\r | |
594 | //\r | |
595 | CapsuleHeader = (EFI_CAPSULE_HEADER *) InfFileImage;\r | |
596 | if (OutFileName == NULL) {\r | |
597 | FpFile = stdout;\r | |
598 | } else {\r | |
1be2ed90 | 599 | FpFile = fopen (LongFilePath (OutFileName), "w");\r |
30fdf114 LG |
600 | if (FpFile == NULL) {\r |
601 | Error (NULL, 0, 0001, "Error opening file", OutFileName);\r | |
602 | return STATUS_ERROR;\r | |
603 | }\r | |
604 | }\r | |
605 | fprintf (FpFile, "Capsule %s Image Header Information\n", InfFileName);\r | |
606 | fprintf (FpFile, " GUID %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", \r | |
fd171542 | 607 | (unsigned) CapsuleHeader->CapsuleGuid.Data1,\r |
608 | (unsigned) CapsuleHeader->CapsuleGuid.Data2,\r | |
609 | (unsigned) CapsuleHeader->CapsuleGuid.Data3,\r | |
610 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[0],\r | |
611 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[1],\r | |
612 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[2],\r | |
613 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[3],\r | |
614 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[4],\r | |
615 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[5],\r | |
616 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[6],\r | |
617 | (unsigned) CapsuleHeader->CapsuleGuid.Data4[7]);\r | |
618 | fprintf (FpFile, " Header size 0x%08X\n", (unsigned) CapsuleHeader->HeaderSize);\r | |
619 | fprintf (FpFile, " Flags 0x%08X\n", (unsigned) CapsuleHeader->Flags);\r | |
620 | fprintf (FpFile, " Capsule image size 0x%08X\n", (unsigned) CapsuleHeader->CapsuleImageSize);\r | |
30fdf114 LG |
621 | fclose (FpFile);\r |
622 | } else if (CapsuleFlag) {\r | |
623 | VerboseMsg ("Create capsule image");\r | |
624 | //\r | |
625 | // Call the GenerateCapImage to generate Capsule Image\r | |
626 | //\r | |
627 | for (Index = 0; mFvDataInfo.FvFiles[Index][0] != '\0'; Index ++) {\r | |
628 | strcpy (mCapDataInfo.CapFiles[Index], mFvDataInfo.FvFiles[Index]);\r | |
629 | }\r | |
630 | \r | |
631 | Status = GenerateCapImage (\r | |
632 | InfFileImage, \r | |
633 | InfFileSize,\r | |
634 | OutFileName\r | |
635 | );\r | |
636 | } else {\r | |
637 | VerboseMsg ("Create Fv image and its map file");\r | |
79b74a03 LG |
638 | //\r |
639 | // Will take rebase action at below situation:\r | |
640 | // 1. ForceRebase Flag specified to TRUE;\r | |
641 | // 2. ForceRebase Flag not specified, BaseAddress greater than zero.\r | |
642 | //\r | |
643 | if (((mFvDataInfo.BaseAddress > 0) && (mFvDataInfo.ForceRebase == -1)) || (mFvDataInfo.ForceRebase == 1)) {\r | |
fd171542 | 644 | VerboseMsg ("FvImage Rebase Address is 0x%llX", (unsigned long long) mFvDataInfo.BaseAddress);\r |
30fdf114 LG |
645 | }\r |
646 | //\r | |
647 | // Call the GenerateFvImage to generate Fv Image\r | |
648 | //\r | |
649 | Status = GenerateFvImage (\r | |
650 | InfFileImage,\r | |
651 | InfFileSize,\r | |
652 | OutFileName,\r | |
653 | MapFileName\r | |
654 | );\r | |
655 | }\r | |
656 | \r | |
657 | //\r | |
658 | // free InfFileImage memory\r | |
659 | //\r | |
660 | if (InfFileImage != NULL) {\r | |
661 | free (InfFileImage);\r | |
662 | }\r | |
663 | \r | |
664 | //\r | |
665 | // update boot driver address and runtime driver address in address file\r | |
666 | //\r | |
52302d4d | 667 | if (Status == EFI_SUCCESS && AddrFileName != NULL && mFvBaseAddressNumber > 0) {\r |
1be2ed90 | 668 | FpFile = fopen (LongFilePath (AddrFileName), "w");\r |
30fdf114 LG |
669 | if (FpFile == NULL) {\r |
670 | Error (NULL, 0, 0001, "Error opening file", AddrFileName);\r | |
671 | return STATUS_ERROR;\r | |
672 | }\r | |
52302d4d | 673 | fprintf (FpFile, FV_BASE_ADDRESS_STRING);\r |
30fdf114 | 674 | fprintf (FpFile, "\n");\r |
52302d4d | 675 | for (Index = 0; Index < mFvBaseAddressNumber; Index ++) {\r |
fd171542 | 676 | fprintf (\r |
677 | FpFile,\r | |
52302d4d LG |
678 | "0x%llx\n",\r |
679 | (unsigned long long)mFvBaseAddress[Index]\r | |
fd171542 | 680 | );\r |
30fdf114 | 681 | }\r |
52302d4d | 682 | fflush (FpFile);\r |
30fdf114 LG |
683 | fclose (FpFile);\r |
684 | }\r | |
685 | \r | |
686 | if (Status == EFI_SUCCESS) {\r | |
fd171542 | 687 | DebugMsg (NULL, 0, 9, "The Total Fv Size", "%s = 0x%x", EFI_FV_TOTAL_SIZE_STRING, (unsigned) mFvTotalSize);\r |
688 | DebugMsg (NULL, 0, 9, "The used Fv Size", "%s = 0x%x", EFI_FV_TAKEN_SIZE_STRING, (unsigned) mFvTakenSize);\r | |
689 | DebugMsg (NULL, 0, 9, "The space Fv size", "%s = 0x%x", EFI_FV_SPACE_SIZE_STRING, (unsigned) (mFvTotalSize - mFvTakenSize));\r | |
30fdf114 LG |
690 | }\r |
691 | \r | |
692 | VerboseMsg ("%s tool done with return code is 0x%x.", UTILITY_NAME, GetUtilityStatus ());\r | |
693 | \r | |
694 | return GetUtilityStatus ();\r | |
695 | }\r |