]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/GenFvImage/GenFvImageExe.c
3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
4 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"
40 Displays the standard utility information to SDTOUT
54 UTILITY_NAME
" "UTILITY_VERSION
" - Intel Generate Firmware Volume Utility",
55 " Copyright (C), 2004 - 2009 Intel Corporation",
57 #if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )
58 " Built from "UTILITY_BUILD
", project of "UTILITY_VENDOR
,
62 for (Index
= 0; Str
[Index
] != NULL
; Index
++) {
63 fprintf (stdout
, "%s\n", Str
[Index
]);
75 Displays the utility usage syntax to STDOUT
91 " "UTILITY_NAME
" [OPTION]",
93 " -I FvInfFileName The name of the image description file.",
97 for (Index
= 0; Str
[Index
] != NULL
; Index
++) {
98 fprintf (stdout
, "%s\n", Str
[Index
]);
111 This utility uses GenFvImage.Lib to build a firmware volume image.
115 FvInfFileName The name of an FV image description file.
117 Arguments come in pair in any order.
122 EFI_SUCCESS No error conditions detected.
123 EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
124 EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
125 Most commonly this will be memory allocation
127 EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
128 EFI_ABORTED Error executing the GenFvImage lib.
133 CHAR8 InfFileName
[_MAX_PATH
];
139 CHAR8 FvFileNameBuffer
[_MAX_PATH
];
143 CHAR8 SymFileNameBuffer
[_MAX_PATH
];
147 CHAR8
*CurrentSymString
;
149 FvFileName
= FvFileNameBuffer
;
150 SymFileName
= SymFileNameBuffer
;
152 SetUtilityName (UTILITY_NAME
);
154 // Display utility information
159 // Verify the correct number of arguments
161 if (argc
!= MAX_ARGS
) {
162 Error (NULL
, 0, 0, "invalid number of input parameters specified", NULL
);
164 return GetUtilityStatus ();
167 // Initialize variables
169 strcpy (InfFileName
, "");
172 // Parse the command line arguments
174 for (Index
= 1; Index
< MAX_ARGS
; Index
+= 2) {
176 // Make sure argument pair begin with - or /
178 if (argv
[Index
][0] != '-' && argv
[Index
][0] != '/') {
179 Error (NULL
, 0, 0, argv
[Index
], "argument pair must begin with \"-\" or \"/\"");
181 return GetUtilityStatus ();
184 // Make sure argument specifier is only one letter
186 if (argv
[Index
][2] != 0) {
187 Error (NULL
, 0, 0, argv
[Index
], "unrecognized argument");
189 return GetUtilityStatus ();
192 // Determine argument to read
194 switch (argv
[Index
][1]) {
198 if (strlen (InfFileName
) == 0) {
199 strcpy (InfFileName
, argv
[Index
+ 1]);
201 Error (NULL
, 0, 0, argv
[Index
+ 1], "FvInfFileName may only be specified once");
203 return GetUtilityStatus ();
208 Error (NULL
, 0, 0, argv
[Index
], "unrecognized argument");
210 return GetUtilityStatus ();
215 // Read the INF file image
217 Status
= GetFileImage (InfFileName
, &InfFileImage
, &InfFileSize
);
218 if (EFI_ERROR (Status
)) {
222 // Call the GenFvImage lib
224 Status
= GenerateFvImage (
235 if (EFI_ERROR (Status
)) {
238 case EFI_INVALID_PARAMETER
:
239 Error (NULL
, 0, 0, "invalid parameter passed to GenFvImage Lib", NULL
);
240 return GetUtilityStatus ();
244 Error (NULL
, 0, 0, "error detected while creating the file image", NULL
);
245 return GetUtilityStatus ();
248 case EFI_OUT_OF_RESOURCES
:
249 Error (NULL
, 0, 0, "GenFvImage Lib could not allocate required resources", NULL
);
250 return GetUtilityStatus ();
253 case EFI_VOLUME_CORRUPTED
:
254 Error (NULL
, 0, 0, "no base address was specified, but the FV.INF included a PEI or BSF file", NULL
);
255 return GetUtilityStatus ();
259 Error (NULL
, 0, 0, "could not load FV image generation library", NULL
);
260 return GetUtilityStatus ();
264 Error (NULL
, 0, 0, "GenFvImage Lib returned unknown status", "status returned = 0x%X", Status
);
265 return GetUtilityStatus ();
272 FvFile
= fopen (FvFileName
, "wb");
273 if (FvFile
== NULL
) {
274 Error (NULL
, 0, 0, FvFileName
, "could not open output file");
277 return GetUtilityStatus ();
280 if (fwrite (FvImage
, 1, FvImageSize
, FvFile
) != FvImageSize
) {
281 Error (NULL
, 0, 0, FvFileName
, "failed to write to output file");
285 return GetUtilityStatus ();
294 if (strcmp (SymFileName
, "")) {
295 SymFile
= fopen (SymFileName
, "wt");
296 if (SymFile
== NULL
) {
297 Error (NULL
, 0, 0, SymFileName
, "could not open output symbol file");
299 return GetUtilityStatus ();
302 fprintf (SymFile
, "TEXTSYM format | V1.0\n");
304 CurrentSymString
= SymImage
;
305 while (((UINTN
) CurrentSymString
- (UINTN
) SymImage
) < SymImageSize
) {
306 fprintf (SymFile
, "%s", CurrentSymString
);
307 CurrentSymString
= (CHAR8
*) (((UINTN
) CurrentSymString
) + strlen (CurrentSymString
) + 1);
315 return GetUtilityStatus ();