]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*++\r |
2 | \r | |
db608e6b | 3 | Copyright (c) 2004-2007, Intel Corporation \r |
878ddf1f | 4 | All rights reserved. This program and the accompanying materials \r |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | GenFvImageExe.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | This contains all code necessary to build the GenFvImage.exe utility. \r | |
19 | This utility relies heavily on the GenFvImage Lib. Definitions for both\r | |
20 | can be found in the Tiano Firmware Volume Generation Utility \r | |
21 | Specification, review draft.\r | |
22 | \r | |
23 | --*/\r | |
24 | \r | |
25 | //\r | |
26 | // File included in build\r | |
27 | //\r | |
28 | #include "GenFvImageExe.h"\r | |
29 | #include "CommonLib.h"\r | |
30 | #include "EfiUtilityMsgs.h"\r | |
31 | \r | |
db608e6b | 32 | static\r |
33 | void \r | |
34 | Version(\r | |
35 | void\r | |
36 | )\r | |
878ddf1f | 37 | /*++\r |
38 | \r | |
39 | Routine Description:\r | |
40 | \r | |
41 | Displays the standard utility information to SDTOUT\r | |
42 | \r | |
43 | Arguments:\r | |
44 | \r | |
45 | None\r | |
46 | \r | |
47 | Returns:\r | |
48 | \r | |
49 | None\r | |
50 | \r | |
51 | --*/\r | |
52 | {\r | |
db608e6b | 53 | printf ("%s v%d.%d -Tiano Firmware Volume Generation Utility.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r |
54 | printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");\r | |
878ddf1f | 55 | }\r |
db608e6b | 56 | \r |
878ddf1f | 57 | \r |
db608e6b | 58 | static\r |
59 | void \r | |
60 | Usage(\r | |
61 | void\r | |
878ddf1f | 62 | )\r |
63 | /*++\r | |
64 | \r | |
65 | Routine Description:\r | |
66 | \r | |
67 | Displays the utility usage syntax to STDOUT\r | |
68 | \r | |
69 | Arguments:\r | |
70 | \r | |
71 | None\r | |
72 | \r | |
73 | Returns:\r | |
74 | \r | |
75 | None\r | |
76 | \r | |
77 | --*/\r | |
78 | {\r | |
db608e6b | 79 | Version();\r |
80 | \r | |
81 | printf ("\nUsage: %s -I FvInfFileName\n", UTILITY_NAME);\r | |
878ddf1f | 82 | printf (" Where:\n");\r |
db608e6b | 83 | printf (" FvInfFileName is the name of the image description file.\n\n");\r |
878ddf1f | 84 | }\r |
85 | \r | |
86 | int\r | |
87 | main (\r | |
88 | IN INTN argc,\r | |
89 | IN CHAR8 **argv\r | |
90 | )\r | |
91 | /*++\r | |
92 | \r | |
93 | Routine Description:\r | |
94 | \r | |
95 | This utility uses GenFvImage.Lib to build a firmware volume image.\r | |
96 | \r | |
97 | Arguments:\r | |
98 | \r | |
99 | FvInfFileName The name of an FV image description file.\r | |
100 | \r | |
101 | Arguments come in pair in any order.\r | |
102 | -I FvInfFileName \r | |
103 | \r | |
104 | Returns:\r | |
105 | \r | |
106 | EFI_SUCCESS No error conditions detected.\r | |
107 | EFI_INVALID_PARAMETER One or more of the input parameters is invalid.\r | |
108 | EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable. \r | |
109 | Most commonly this will be memory allocation \r | |
110 | or file creation.\r | |
111 | EFI_LOAD_ERROR GenFvImage.lib could not be loaded.\r | |
112 | EFI_ABORTED Error executing the GenFvImage lib.\r | |
113 | \r | |
114 | --*/\r | |
115 | {\r | |
116 | EFI_STATUS Status;\r | |
117 | CHAR8 InfFileName[_MAX_PATH];\r | |
118 | CHAR8 *InfFileImage;\r | |
119 | UINTN InfFileSize;\r | |
120 | UINT8 *FvImage;\r | |
121 | UINTN FvImageSize;\r | |
122 | UINT8 Index;\r | |
123 | CHAR8 FvFileNameBuffer[_MAX_PATH];\r | |
124 | CHAR8 *FvFileName;\r | |
125 | FILE *FvFile;\r | |
126 | FILE *SymFile;\r | |
127 | CHAR8 SymFileNameBuffer[_MAX_PATH];\r | |
128 | CHAR8 *SymFileName;\r | |
129 | UINT8 *SymImage;\r | |
1d940d05 | 130 | UINTN SymImageSize = 0;\r |
878ddf1f | 131 | CHAR8 *CurrentSymString;\r |
132 | \r | |
133 | FvFileName = FvFileNameBuffer;\r | |
134 | SymFileName = SymFileNameBuffer;\r | |
135 | \r | |
136 | SetUtilityName (UTILITY_NAME);\r | |
db608e6b | 137 | \r |
138 | if (argc == 1) {\r | |
139 | Usage ();\r | |
140 | return STATUS_ERROR;\r | |
141 | }\r | |
142 | \r | |
143 | if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0) ||\r | |
144 | (strcmp(argv[1], "-?") == 0) || (strcmp(argv[1], "/?") == 0)) {\r | |
145 | Usage();\r | |
146 | return GetUtilityStatus ();\r | |
147 | }\r | |
148 | \r | |
149 | if ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0)) {\r | |
150 | Version();\r | |
151 | return GetUtilityStatus ();\r | |
152 | }\r | |
153 | \r | |
878ddf1f | 154 | //\r |
155 | // Verify the correct number of arguments\r | |
156 | //\r | |
157 | if (argc != MAX_ARGS) {\r | |
158 | Error (NULL, 0, 0, "invalid number of input parameters specified", NULL);\r | |
db608e6b | 159 | Usage ();\r |
878ddf1f | 160 | return GetUtilityStatus ();\r |
161 | }\r | |
162 | //\r | |
163 | // Initialize variables\r | |
164 | //\r | |
165 | strcpy (InfFileName, "");\r | |
166 | \r | |
167 | //\r | |
168 | // Parse the command line arguments\r | |
169 | //\r | |
170 | for (Index = 1; Index < MAX_ARGS; Index += 2) {\r | |
171 | //\r | |
172 | // Make sure argument pair begin with - or /\r | |
173 | //\r | |
174 | if (argv[Index][0] != '-' && argv[Index][0] != '/') {\r | |
175 | Error (NULL, 0, 0, argv[Index], "argument pair must begin with \"-\" or \"/\"");\r | |
db608e6b | 176 | Usage ();\r |
878ddf1f | 177 | return GetUtilityStatus ();\r |
178 | }\r | |
179 | //\r | |
180 | // Make sure argument specifier is only one letter\r | |
181 | //\r | |
182 | if (argv[Index][2] != 0) {\r | |
183 | Error (NULL, 0, 0, argv[Index], "unrecognized argument");\r | |
db608e6b | 184 | Usage ();\r |
878ddf1f | 185 | return GetUtilityStatus ();\r |
186 | }\r | |
187 | //\r | |
188 | // Determine argument to read\r | |
189 | //\r | |
190 | switch (argv[Index][1]) {\r | |
191 | \r | |
192 | case 'I':\r | |
193 | case 'i':\r | |
194 | if (strlen (InfFileName) == 0) {\r | |
195 | strcpy (InfFileName, argv[Index + 1]);\r | |
196 | } else {\r | |
197 | Error (NULL, 0, 0, argv[Index + 1], "FvInfFileName may only be specified once");\r | |
db608e6b | 198 | Usage ();\r |
878ddf1f | 199 | return GetUtilityStatus ();\r |
200 | }\r | |
201 | break;\r | |
202 | \r | |
203 | default:\r | |
204 | Error (NULL, 0, 0, argv[Index], "unrecognized argument");\r | |
db608e6b | 205 | Usage ();\r |
878ddf1f | 206 | return GetUtilityStatus ();\r |
207 | break;\r | |
208 | }\r | |
209 | }\r | |
210 | //\r | |
211 | // Read the INF file image\r | |
212 | //\r | |
213 | Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);\r | |
214 | if (EFI_ERROR (Status)) {\r | |
215 | return STATUS_ERROR;\r | |
216 | }\r | |
217 | //\r | |
218 | // Call the GenFvImage lib\r | |
219 | //\r | |
220 | Status = GenerateFvImage (\r | |
221 | InfFileImage,\r | |
222 | InfFileSize,\r | |
223 | &FvImage,\r | |
224 | &FvImageSize,\r | |
225 | &FvFileName,\r | |
226 | &SymImage,\r | |
227 | &SymImageSize,\r | |
228 | &SymFileName\r | |
229 | );\r | |
230 | \r | |
4c50c885 LG |
231 | //\r |
232 | // free InfFileImage memory\r | |
233 | //\r | |
234 | free (InfFileImage);\r | |
235 | \r | |
878ddf1f | 236 | if (EFI_ERROR (Status)) {\r |
237 | switch (Status) {\r | |
238 | \r | |
239 | case EFI_INVALID_PARAMETER:\r | |
240 | Error (NULL, 0, 0, "invalid parameter passed to GenFvImage Lib", NULL);\r | |
241 | return GetUtilityStatus ();\r | |
242 | break;\r | |
243 | \r | |
244 | case EFI_ABORTED:\r | |
245 | Error (NULL, 0, 0, "error detected while creating the file image", NULL);\r | |
246 | return GetUtilityStatus ();\r | |
247 | break;\r | |
248 | \r | |
249 | case EFI_OUT_OF_RESOURCES:\r | |
250 | Error (NULL, 0, 0, "GenFvImage Lib could not allocate required resources", NULL);\r | |
251 | return GetUtilityStatus ();\r | |
252 | break;\r | |
253 | \r | |
254 | case EFI_VOLUME_CORRUPTED:\r | |
255 | Error (NULL, 0, 0, "no base address was specified, but the FV.INF included a PEI or BSF file", NULL);\r | |
256 | return GetUtilityStatus ();\r | |
257 | break;\r | |
258 | \r | |
259 | case EFI_LOAD_ERROR:\r | |
260 | Error (NULL, 0, 0, "could not load FV image generation library", NULL);\r | |
261 | return GetUtilityStatus ();\r | |
262 | break;\r | |
263 | \r | |
264 | default:\r | |
265 | Error (NULL, 0, 0, "GenFvImage Lib returned unknown status", "status returned = 0x%X", Status);\r | |
266 | return GetUtilityStatus ();\r | |
267 | break;\r | |
268 | }\r | |
269 | }\r | |
270 | //\r | |
271 | // Write file\r | |
272 | //\r | |
273 | FvFile = fopen (FvFileName, "wb");\r | |
274 | if (FvFile == NULL) {\r | |
275 | Error (NULL, 0, 0, FvFileName, "could not open output file");\r | |
276 | free (FvImage);\r | |
277 | free (SymImage);\r | |
278 | return GetUtilityStatus ();\r | |
279 | }\r | |
280 | \r | |
281 | if (fwrite (FvImage, 1, FvImageSize, FvFile) != FvImageSize) {\r | |
282 | Error (NULL, 0, 0, FvFileName, "failed to write to output file");\r | |
283 | free (FvImage);\r | |
284 | free (SymImage);\r | |
285 | fclose (FvFile);\r | |
286 | return GetUtilityStatus ();\r | |
287 | }\r | |
288 | \r | |
289 | fclose (FvFile);\r | |
290 | free (FvImage);\r | |
291 | \r | |
292 | //\r | |
293 | // Write symbol file\r | |
294 | //\r | |
295 | if (strcmp (SymFileName, "")) {\r | |
296 | SymFile = fopen (SymFileName, "wt");\r | |
297 | if (SymFile == NULL) {\r | |
298 | Error (NULL, 0, 0, SymFileName, "could not open output symbol file");\r | |
299 | free (SymImage);\r | |
300 | return GetUtilityStatus ();\r | |
301 | }\r | |
302 | \r | |
303 | fprintf (SymFile, "TEXTSYM format | V1.0\n");\r | |
304 | \r | |
305 | CurrentSymString = SymImage;\r | |
306 | while (((UINTN) CurrentSymString - (UINTN) SymImage) < SymImageSize) {\r | |
307 | fprintf (SymFile, "%s", CurrentSymString);\r | |
308 | CurrentSymString = (CHAR8 *) (((UINTN) CurrentSymString) + strlen (CurrentSymString) + 1);\r | |
309 | }\r | |
310 | \r | |
311 | fclose (SymFile);\r | |
312 | }\r | |
313 | \r | |
314 | free (SymImage);\r | |
315 | \r | |
316 | return GetUtilityStatus ();\r | |
317 | }\r |