]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CodeTools/Source/GenFvImage/GenFvImageExe.c
3 Copyright (c) 2004, 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"
40 Displays the standard utility information to SDTOUT
53 "%s - Tiano Firmware Volume Generation Utility."" Version %i.%i\n\n",
55 UTILITY_MAJOR_VERSION
,
68 Displays the utility usage syntax to STDOUT
80 printf ("Usage: %s -I FvInfFileName\n", UTILITY_NAME
);
82 printf ("\tFvInfFileName is the name of the image description file.\n\n");
94 This utility uses GenFvImage.Lib to build a firmware volume image.
98 FvInfFileName The name of an FV image description file.
100 Arguments come in pair in any order.
105 EFI_SUCCESS No error conditions detected.
106 EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
107 EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
108 Most commonly this will be memory allocation
110 EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
111 EFI_ABORTED Error executing the GenFvImage lib.
116 CHAR8 InfFileName
[_MAX_PATH
];
122 CHAR8 FvFileNameBuffer
[_MAX_PATH
];
126 CHAR8 SymFileNameBuffer
[_MAX_PATH
];
130 CHAR8
*CurrentSymString
;
132 FvFileName
= FvFileNameBuffer
;
133 SymFileName
= SymFileNameBuffer
;
135 SetUtilityName (UTILITY_NAME
);
137 // Display utility information
142 // Verify the correct number of arguments
144 if (argc
!= MAX_ARGS
) {
145 Error (NULL
, 0, 0, "invalid number of input parameters specified", NULL
);
147 return GetUtilityStatus ();
150 // Initialize variables
152 strcpy (InfFileName
, "");
155 // Parse the command line arguments
157 for (Index
= 1; Index
< MAX_ARGS
; Index
+= 2) {
159 // Make sure argument pair begin with - or /
161 if (argv
[Index
][0] != '-' && argv
[Index
][0] != '/') {
162 Error (NULL
, 0, 0, argv
[Index
], "argument pair must begin with \"-\" or \"/\"");
164 return GetUtilityStatus ();
167 // Make sure argument specifier is only one letter
169 if (argv
[Index
][2] != 0) {
170 Error (NULL
, 0, 0, argv
[Index
], "unrecognized argument");
172 return GetUtilityStatus ();
175 // Determine argument to read
177 switch (argv
[Index
][1]) {
181 if (strlen (InfFileName
) == 0) {
182 strcpy (InfFileName
, argv
[Index
+ 1]);
184 Error (NULL
, 0, 0, argv
[Index
+ 1], "FvInfFileName may only be specified once");
186 return GetUtilityStatus ();
191 Error (NULL
, 0, 0, argv
[Index
], "unrecognized argument");
193 return GetUtilityStatus ();
198 // Read the INF file image
200 Status
= GetFileImage (InfFileName
, &InfFileImage
, &InfFileSize
);
201 if (EFI_ERROR (Status
)) {
205 // Call the GenFvImage lib
207 Status
= GenerateFvImage (
218 if (EFI_ERROR (Status
)) {
221 case EFI_INVALID_PARAMETER
:
222 Error (NULL
, 0, 0, "invalid parameter passed to GenFvImage Lib", NULL
);
223 return GetUtilityStatus ();
227 Error (NULL
, 0, 0, "error detected while creating the file image", NULL
);
228 return GetUtilityStatus ();
231 case EFI_OUT_OF_RESOURCES
:
232 Error (NULL
, 0, 0, "GenFvImage Lib could not allocate required resources", NULL
);
233 return GetUtilityStatus ();
236 case EFI_VOLUME_CORRUPTED
:
237 Error (NULL
, 0, 0, "no base address was specified, but the FV.INF included a PEI or BSF file", NULL
);
238 return GetUtilityStatus ();
242 Error (NULL
, 0, 0, "could not load FV image generation library", NULL
);
243 return GetUtilityStatus ();
247 Error (NULL
, 0, 0, "GenFvImage Lib returned unknown status", "status returned = 0x%X", Status
);
248 return GetUtilityStatus ();
255 FvFile
= fopen (FvFileName
, "wb");
256 if (FvFile
== NULL
) {
257 Error (NULL
, 0, 0, FvFileName
, "could not open output file");
260 return GetUtilityStatus ();
263 if (fwrite (FvImage
, 1, FvImageSize
, FvFile
) != FvImageSize
) {
264 Error (NULL
, 0, 0, FvFileName
, "failed to write to output file");
268 return GetUtilityStatus ();
277 if (strcmp (SymFileName
, "")) {
278 SymFile
= fopen (SymFileName
, "wt");
279 if (SymFile
== NULL
) {
280 Error (NULL
, 0, 0, SymFileName
, "could not open output symbol file");
282 return GetUtilityStatus ();
285 fprintf (SymFile
, "TEXTSYM format | V1.0\n");
287 CurrentSymString
= SymImage
;
288 while (((UINTN
) CurrentSymString
- (UINTN
) SymImage
) < SymImageSize
) {
289 fprintf (SymFile
, "%s", CurrentSymString
);
290 CurrentSymString
= (CHAR8
*) (((UINTN
) CurrentSymString
) + strlen (CurrentSymString
) + 1);
298 return GetUtilityStatus ();