]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/GenFdImage/GenFdImageExe.c
3 Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
19 This contains all code necessary to build the GenFdImage.exe utility.
20 This utility relies heavily on the GenFdImage Lib. Definitions for both
21 can be found in the GenFdImage Utility Specification, review draft.
26 // Coded to EFI 2.0 Coding Standards
31 #include "GenFdImage.h"
32 #include "GenFdImageExe.h"
42 Displays the standard utility information to SDTOUT
55 "%s, EFI 2.0 Firmware Device Image Generation Utility. ""Version %i.%i, %s.\n\n",
57 UTILITY_MAJOR_VERSION
,
58 UTILITY_MINOR_VERSION
,
71 Displays the utility usage syntax to STDOUT
84 "Usage: %s -B BaseAddress -S Size -F FillByte"" [-I FvInfFileName] -O OutputFileName \n",
88 printf ("\tBaseAddress is the starting address of the FD Image\n\n");
89 printf ("\tSize is the size of the FD Image.\n\n");
90 printf ("\tFillByte is the desired value of free space in the Image\n\n");
91 printf ("\tFvInfFileName is the name of an FV Image description file.\n\n");
92 printf ("\tOutputFileName is the desired output file name.\n\n");
104 This utility uses GenFdImage.lib to build a Firmware Device Image
105 which will include several Firmware Volume Images.
109 Base Address Base Address of the firmware volume..
110 Size Size of the Firmware Volume
111 FillByte The byte value which would be needed to pad
112 between various Firmware Volumes
113 FvInfFile Fv inf file
114 OutputFileName The name of output file which would be created
118 EFI_SUCCESS No error conditions detected.
119 EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
120 EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
121 Most commonly this will be memory allocation or
123 EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
124 EFI_ABORTED Error executing the GenFvImage lib.
127 // GC_TODO: argc - add argument and description to function comment
128 // GC_TODO: argv - add argument and description to function comment
139 CHAR8
**FvInfFileList
;
140 CHAR8
**OrgFvInfFileList
;
141 CHAR8 OutputFileName
[_MAX_PATH
];
148 // Echo for makefile debug
151 for (arg_counter
= 0; arg_counter
< argc
; arg_counter
++) {
152 printf ("%s ", argv
[arg_counter
]);
158 // Display utility information
163 // Verify the correct number of arguments
165 if (argc
< MIN_ARGS
) {
166 printf ("ERROR: missing 1 or more input arguments.\n\n");
168 return EFI_INVALID_PARAMETER
;
171 // Initialize variables
178 for (i
= 1; i
< argc
; i
++) {
179 if (stricmp (argv
[i
], "-I") == 0) {
184 FvInfFileList
= malloc (sizeof (UINTN
) * (FvFilesCount
+ 1));
185 if (FvInfFileList
== NULL
) {
186 printf ("ERROR: allocating memory for FvInfFileList in -main- function.\n");
187 return EFI_OUT_OF_RESOURCES
;
190 memset (FvInfFileList
, 0, sizeof (UINTN
) * (FvFilesCount
+ 1));
192 OrgFvInfFileList
= FvInfFileList
;
194 for (Index
= 0; Index
< FvFilesCount
; Index
++) {
195 *FvInfFileList
= malloc (_MAX_PATH
);
196 memset (*FvInfFileList
, 0, _MAX_PATH
);
200 strcpy (OutputFileName
, "");
203 // Parse the command line arguments
205 FvInfFileList
= OrgFvInfFileList
;
207 for (i
= 1; i
< argc
; i
+= 2) {
209 // Make sure argument pair begin with - or /
211 if (argv
[i
][0] != '-' && argv
[i
][0] != '/') {
213 printf ("ERROR: Argument pair must begin with \"-\" or \"/\"\n");
214 return EFI_INVALID_PARAMETER
;
217 // Make sure argument specifier is only one letter
219 if (argv
[i
][2] != 0) {
221 printf ("ERROR: Unrecognized argument \"%s\".\n", argv
[i
]);
222 return EFI_INVALID_PARAMETER
;
225 // Determine argument to read
227 switch (argv
[i
][1]) {
231 if ((FvInfFileList
!= NULL
) && (strlen (*FvInfFileList
) == 0)) {
232 strcpy (*FvInfFileList
, argv
[i
+ 1]);
235 printf ("ERROR: FvInfFile Name is more than specifed.\n");
236 return EFI_INVALID_PARAMETER
;
242 if (strlen (OutputFileName
) == 0) {
243 strcpy (OutputFileName
, argv
[i
+ 1]);
246 printf ("ERROR: OutputFileName may only be specified once.\n");
247 return EFI_INVALID_PARAMETER
;
253 Status
= AsciiStringToUint64 (argv
[i
+ 1], FALSE
, &StartAddress
);
254 if (Status
!= EFI_SUCCESS
) {
255 printf ("\nERROR: Bad FD Image start address specified");
256 return EFI_INVALID_PARAMETER
;
262 Status
= AsciiStringToUint64 (argv
[i
+ 1], FALSE
, &Size
);
263 if (Status
!= EFI_SUCCESS
) {
264 printf ("\nERROR: Bad FD Image size specified");
265 return EFI_INVALID_PARAMETER
;
271 Status
= AsciiStringToUint64 (argv
[i
+ 1], FALSE
, &FillByteVal
);
272 if (Status
!= EFI_SUCCESS
) {
273 printf ("\nERROR: Not a recognized Fill Byte value");
274 return EFI_INVALID_PARAMETER
;
280 printf ("ERROR: Unrecognized argument \"%s\".\n", argv
[i
]);
281 return EFI_INVALID_PARAMETER
;
286 // Call the GenFdImage Lib
288 FvInfFileList
= OrgFvInfFileList
;
290 Status
= GenerateFdImage (
298 if (EFI_ERROR (Status
)) {
301 case EFI_INVALID_PARAMETER
:
302 printf ("\nERROR: Invalid parameter passed to GenFdImage lib.\n");
306 printf ("\nERROR: Error detected while creating the file image.\n");
309 case EFI_OUT_OF_RESOURCES
:
310 printf ("\nERROR: GenFdImage Lib could not allocate required resources.\n");
313 case EFI_VOLUME_CORRUPTED
:
314 printf ("\nERROR: No base address was specified \n");
318 printf ("\nERROR: An error occurred loading one of the required support Lib.\n");
322 printf ("\nERROR: GenFdImage lib returned unknown status %X.\n", Status
);