]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/GenFdImage/GenFdImageExe.c
Clean up some data type mismatches.
[mirror_edk2.git] / Tools / Source / TianoTools / GenFdImage / GenFdImageExe.c
1 /*++
2
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
10 Intel Corporation.
11
12
13 Module Name:
14
15 GenFdImageExe.c
16
17 Abstract:
18
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.
22
23 --*/
24
25 //
26 // Coded to EFI 2.0 Coding Standards
27 //
28 //
29 // Include files
30 //
31 #include "GenFdImage.h"
32 #include "GenFdImageExe.h"
33
34 VOID
35 PrintUtilityInfo (
36 VOID
37 )
38 /*++
39
40 Routine Description:
41
42 Displays the standard utility information to SDTOUT
43
44 Arguments:
45
46 None
47
48 Returns:
49
50 None
51
52 --*/
53 {
54 printf (
55 "%s, EFI 2.0 Firmware Device Image Generation Utility. ""Version %i.%i, %s.\n\n",
56 UTILITY_NAME,
57 UTILITY_MAJOR_VERSION,
58 UTILITY_MINOR_VERSION,
59 UTILITY_DATE
60 );
61 }
62
63 VOID
64 PrintUsage (
65 VOID
66 )
67 /*++
68
69 Routine Description:
70
71 Displays the utility usage syntax to STDOUT
72
73 Arguments:
74
75 None
76
77 Returns:
78
79 None
80
81 --*/
82 {
83 printf (
84 "Usage: %s -B BaseAddress -S Size -F FillByte"" [-I FvInfFileName] -O OutputFileName \n",
85 UTILITY_NAME
86 );
87 printf (" Where:\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");
93 }
94
95 EFI_STATUS
96 main (
97 IN INTN argc,
98 IN CHAR8 **argv
99 )
100 /*++
101
102 Routine Description:
103
104 This utility uses GenFdImage.lib to build a Firmware Device Image
105 which will include several Firmware Volume Images.
106
107 Arguments:
108
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
115
116 Returns:
117
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
122 file creation.
123 EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
124 EFI_ABORTED Error executing the GenFvImage lib.
125
126 --*/
127 // GC_TODO: argc - add argument and description to function comment
128 // GC_TODO: argv - add argument and description to function comment
129 {
130 UINTN Index;
131 UINTN FvFilesCount;
132
133 UINT8 i;
134
135 UINT64 StartAddress;
136 UINT64 Size;
137 UINT64 FillByteVal;
138
139 CHAR8 **FvInfFileList;
140 CHAR8 **OrgFvInfFileList;
141 CHAR8 OutputFileName[_MAX_PATH];
142
143 EFI_STATUS Status;
144
145 INTN arg_counter;
146
147 //
148 // Echo for makefile debug
149 //
150 printf ("\n\n");
151 for (arg_counter = 0; arg_counter < argc; arg_counter++) {
152 printf ("%s ", argv[arg_counter]);
153 }
154
155 printf ("\n\n");
156
157 //
158 // Display utility information
159 //
160 PrintUtilityInfo ();
161
162 //
163 // Verify the correct number of arguments
164 //
165 if (argc < MIN_ARGS) {
166 printf ("ERROR: missing 1 or more input arguments.\n\n");
167 PrintUsage ();
168 return EFI_INVALID_PARAMETER;
169 }
170 //
171 // Initialize variables
172 //
173 StartAddress = 0;
174 Size = 0;
175 FillByteVal = 0;
176 FvFilesCount = 0;
177
178 for (i = 1; i < argc; i++) {
179 if (stricmp (argv[i], "-I") == 0) {
180 FvFilesCount++;
181 }
182 }
183
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;
188 }
189
190 memset (FvInfFileList, 0, sizeof (UINTN) * (FvFilesCount + 1));
191
192 OrgFvInfFileList = FvInfFileList;
193
194 for (Index = 0; Index < FvFilesCount; Index++) {
195 *FvInfFileList = malloc (_MAX_PATH);
196 memset (*FvInfFileList, 0, _MAX_PATH);
197 FvInfFileList++;
198 }
199
200 strcpy (OutputFileName, "");
201
202 //
203 // Parse the command line arguments
204 //
205 FvInfFileList = OrgFvInfFileList;
206
207 for (i = 1; i < argc; i += 2) {
208 //
209 // Make sure argument pair begin with - or /
210 //
211 if (argv[i][0] != '-' && argv[i][0] != '/') {
212 PrintUsage ();
213 printf ("ERROR: Argument pair must begin with \"-\" or \"/\"\n");
214 return EFI_INVALID_PARAMETER;
215 }
216 //
217 // Make sure argument specifier is only one letter
218 //
219 if (argv[i][2] != 0) {
220 PrintUsage ();
221 printf ("ERROR: Unrecognized argument \"%s\".\n", argv[i]);
222 return EFI_INVALID_PARAMETER;
223 }
224 //
225 // Determine argument to read
226 //
227 switch (argv[i][1]) {
228
229 case 'I':
230 case 'i':
231 if ((FvInfFileList != NULL) && (strlen (*FvInfFileList) == 0)) {
232 strcpy (*FvInfFileList, argv[i + 1]);
233 FvInfFileList++;
234 } else {
235 printf ("ERROR: FvInfFile Name is more than specifed.\n");
236 return EFI_INVALID_PARAMETER;
237 }
238 break;
239
240 case 'O':
241 case 'o':
242 if (strlen (OutputFileName) == 0) {
243 strcpy (OutputFileName, argv[i + 1]);
244 } else {
245 PrintUsage ();
246 printf ("ERROR: OutputFileName may only be specified once.\n");
247 return EFI_INVALID_PARAMETER;
248 }
249 break;
250
251 case 'B':
252 case 'b':
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;
257 }
258 break;
259
260 case 'S':
261 case 's':
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;
266 }
267 break;
268
269 case 'F':
270 case 'f':
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;
275 }
276 break;
277
278 default:
279 PrintUsage ();
280 printf ("ERROR: Unrecognized argument \"%s\".\n", argv[i]);
281 return EFI_INVALID_PARAMETER;
282 break;
283 }
284 }
285 //
286 // Call the GenFdImage Lib
287 //
288 FvInfFileList = OrgFvInfFileList;
289
290 Status = GenerateFdImage (
291 StartAddress,
292 Size,
293 (UINT8) FillByteVal,
294 OutputFileName,
295 FvInfFileList
296 );
297
298 if (EFI_ERROR (Status)) {
299 switch (Status) {
300
301 case EFI_INVALID_PARAMETER:
302 printf ("\nERROR: Invalid parameter passed to GenFdImage lib.\n");
303 break;
304
305 case EFI_ABORTED:
306 printf ("\nERROR: Error detected while creating the file image.\n");
307 break;
308
309 case EFI_OUT_OF_RESOURCES:
310 printf ("\nERROR: GenFdImage Lib could not allocate required resources.\n");
311 break;
312
313 case EFI_VOLUME_CORRUPTED:
314 printf ("\nERROR: No base address was specified \n");
315 break;
316
317 case EFI_LOAD_ERROR:
318 printf ("\nERROR: An error occurred loading one of the required support Lib.\n");
319 break;
320
321 default:
322 printf ("\nERROR: GenFdImage lib returned unknown status %X.\n", Status);
323 break;
324 }
325
326 return Status;
327 }
328
329 return EFI_SUCCESS;
330 }