]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/GenFvImage/GenFvImageExe.c
3 Copyright (c) 2004-2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 This contains all code necessary to build the GenFvImage.exe utility.
19 This utility relies heavily on the GenFvImage Lib. Definitions for both
20 can be found in the Tiano Firmware Volume Generation Utility
21 Specification, review draft.
26 // File included in build
28 #include "GenFvImageExe.h"
29 #include "CommonLib.h"
30 #include "EfiUtilityMsgs.h"
41 Displays the standard utility information to SDTOUT
53 printf ("%s v%d.%d -Tiano Firmware Volume Generation Utility.\n", UTILITY_NAME
, UTILITY_MAJOR_VERSION
, UTILITY_MINOR_VERSION
);
54 printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");
67 Displays the utility usage syntax to STDOUT
81 printf ("\nUsage: %s -I FvInfFileName\n", UTILITY_NAME
);
83 printf (" FvInfFileName is the name of the image description file.\n\n");
95 This utility uses GenFvImage.Lib to build a firmware volume image.
99 FvInfFileName The name of an FV image description file.
101 Arguments come in pair in any order.
106 EFI_SUCCESS No error conditions detected.
107 EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
108 EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
109 Most commonly this will be memory allocation
111 EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
112 EFI_ABORTED Error executing the GenFvImage lib.
117 CHAR8 InfFileName
[_MAX_PATH
];
123 CHAR8 FvFileNameBuffer
[_MAX_PATH
];
127 CHAR8 SymFileNameBuffer
[_MAX_PATH
];
130 UINTN SymImageSize
= 0;
131 CHAR8
*CurrentSymString
;
133 FvFileName
= FvFileNameBuffer
;
134 SymFileName
= SymFileNameBuffer
;
136 SetUtilityName (UTILITY_NAME
);
143 if ((strcmp(argv
[1], "-h") == 0) || (strcmp(argv
[1], "--help") == 0) ||
144 (strcmp(argv
[1], "-?") == 0) || (strcmp(argv
[1], "/?") == 0)) {
146 return GetUtilityStatus ();
149 if ((strcmp(argv
[1], "-V") == 0) || (strcmp(argv
[1], "--version") == 0)) {
151 return GetUtilityStatus ();
155 // Verify the correct number of arguments
157 if (argc
!= MAX_ARGS
) {
158 Error (NULL
, 0, 0, "invalid number of input parameters specified", NULL
);
160 return GetUtilityStatus ();
163 // Initialize variables
165 strcpy (InfFileName
, "");
168 // Parse the command line arguments
170 for (Index
= 1; Index
< MAX_ARGS
; Index
+= 2) {
172 // Make sure argument pair begin with - or /
174 if (argv
[Index
][0] != '-' && argv
[Index
][0] != '/') {
175 Error (NULL
, 0, 0, argv
[Index
], "argument pair must begin with \"-\" or \"/\"");
177 return GetUtilityStatus ();
180 // Make sure argument specifier is only one letter
182 if (argv
[Index
][2] != 0) {
183 Error (NULL
, 0, 0, argv
[Index
], "unrecognized argument");
185 return GetUtilityStatus ();
188 // Determine argument to read
190 switch (argv
[Index
][1]) {
194 if (strlen (InfFileName
) == 0) {
195 strcpy (InfFileName
, argv
[Index
+ 1]);
197 Error (NULL
, 0, 0, argv
[Index
+ 1], "FvInfFileName may only be specified once");
199 return GetUtilityStatus ();
204 Error (NULL
, 0, 0, argv
[Index
], "unrecognized argument");
206 return GetUtilityStatus ();
211 // Read the INF file image
213 Status
= GetFileImage (InfFileName
, &InfFileImage
, &InfFileSize
);
214 if (EFI_ERROR (Status
)) {
218 // Call the GenFvImage lib
220 Status
= GenerateFvImage (
232 // free InfFileImage memory
236 if (EFI_ERROR (Status
)) {
239 case EFI_INVALID_PARAMETER
:
240 Error (NULL
, 0, 0, "invalid parameter passed to GenFvImage Lib", NULL
);
241 return GetUtilityStatus ();
245 Error (NULL
, 0, 0, "error detected while creating the file image", NULL
);
246 return GetUtilityStatus ();
249 case EFI_OUT_OF_RESOURCES
:
250 Error (NULL
, 0, 0, "GenFvImage Lib could not allocate required resources", NULL
);
251 return GetUtilityStatus ();
254 case EFI_VOLUME_CORRUPTED
:
255 Error (NULL
, 0, 0, "no base address was specified, but the FV.INF included a PEI or BSF file", NULL
);
256 return GetUtilityStatus ();
260 Error (NULL
, 0, 0, "could not load FV image generation library", NULL
);
261 return GetUtilityStatus ();
265 Error (NULL
, 0, 0, "GenFvImage Lib returned unknown status", "status returned = 0x%X", Status
);
266 return GetUtilityStatus ();
273 FvFile
= fopen (FvFileName
, "wb");
274 if (FvFile
== NULL
) {
275 Error (NULL
, 0, 0, FvFileName
, "could not open output file");
278 return GetUtilityStatus ();
281 if (fwrite (FvImage
, 1, FvImageSize
, FvFile
) != FvImageSize
) {
282 Error (NULL
, 0, 0, FvFileName
, "failed to write to output file");
286 return GetUtilityStatus ();
295 if (strcmp (SymFileName
, "")) {
296 SymFile
= fopen (SymFileName
, "wt");
297 if (SymFile
== NULL
) {
298 Error (NULL
, 0, 0, SymFileName
, "could not open output symbol file");
300 return GetUtilityStatus ();
303 fprintf (SymFile
, "TEXTSYM format | V1.0\n");
305 CurrentSymString
= SymImage
;
306 while (((UINTN
) CurrentSymString
- (UINTN
) SymImage
) < SymImageSize
) {
307 fprintf (SymFile
, "%s", CurrentSymString
);
308 CurrentSymString
= (CHAR8
*) (((UINTN
) CurrentSymString
) + strlen (CurrentSymString
) + 1);
316 return GetUtilityStatus ();