]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
3e99020d | 3 | Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r |
4b1e1121 | 4 | This program and the accompanying materials \r |
3eb9473e | 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 | |
32 | VOID\r | |
33 | PrintUtilityInfo (\r | |
34 | VOID\r | |
35 | )\r | |
36 | /*++\r | |
37 | \r | |
38 | Routine Description:\r | |
39 | \r | |
40 | Displays the standard utility information to SDTOUT\r | |
41 | \r | |
42 | Arguments:\r | |
43 | \r | |
44 | None\r | |
45 | \r | |
46 | Returns:\r | |
47 | \r | |
48 | None\r | |
49 | \r | |
50 | --*/\r | |
51 | {\r | |
3e99020d LG |
52 | int Index;\r |
53 | const char *Str[] = {\r | |
54 | UTILITY_NAME" "UTILITY_VERSION" - Intel Generate Firmware Volume Utility",\r | |
55 | " Copyright (C), 2004 - 2009 Intel Corporation",\r | |
56 | \r | |
57 | #if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )\r | |
58 | " Built from "UTILITY_BUILD", project of "UTILITY_VENDOR,\r | |
59 | #endif\r | |
60 | NULL\r | |
61 | };\r | |
62 | for (Index = 0; Str[Index] != NULL; Index++) {\r | |
63 | fprintf (stdout, "%s\n", Str[Index]);\r | |
64 | }\r | |
3eb9473e | 65 | }\r |
66 | \r | |
67 | VOID\r | |
68 | PrintUsage (\r | |
69 | VOID\r | |
70 | )\r | |
71 | /*++\r | |
72 | \r | |
73 | Routine Description:\r | |
74 | \r | |
75 | Displays the utility usage syntax to STDOUT\r | |
76 | \r | |
77 | Arguments:\r | |
78 | \r | |
79 | None\r | |
80 | \r | |
81 | Returns:\r | |
82 | \r | |
83 | None\r | |
84 | \r | |
85 | --*/\r | |
86 | {\r | |
3e99020d LG |
87 | int Index;\r |
88 | const char *Str[] = {\r | |
89 | "",\r | |
90 | "Usage:",\r | |
91 | " "UTILITY_NAME" [OPTION]",\r | |
92 | "Options:",\r | |
93 | " -I FvInfFileName The name of the image description file.",\r | |
94 | NULL\r | |
95 | };\r | |
96 | \r | |
97 | for (Index = 0; Str[Index] != NULL; Index++) {\r | |
98 | fprintf (stdout, "%s\n", Str[Index]);\r | |
99 | }\r | |
3eb9473e | 100 | }\r |
101 | \r | |
102 | EFI_STATUS\r | |
103 | main (\r | |
104 | IN INTN argc,\r | |
105 | IN CHAR8 **argv\r | |
106 | )\r | |
107 | /*++\r | |
108 | \r | |
109 | Routine Description:\r | |
110 | \r | |
111 | This utility uses GenFvImage.Lib to build a firmware volume image.\r | |
112 | \r | |
113 | Arguments:\r | |
114 | \r | |
115 | FvInfFileName The name of an FV image description file.\r | |
116 | \r | |
117 | Arguments come in pair in any order.\r | |
118 | -I FvInfFileName \r | |
119 | \r | |
120 | Returns:\r | |
121 | \r | |
122 | EFI_SUCCESS No error conditions detected.\r | |
123 | EFI_INVALID_PARAMETER One or more of the input parameters is invalid.\r | |
124 | EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable. \r | |
125 | Most commonly this will be memory allocation \r | |
126 | or file creation.\r | |
127 | EFI_LOAD_ERROR GenFvImage.lib could not be loaded.\r | |
128 | EFI_ABORTED Error executing the GenFvImage lib.\r | |
129 | \r | |
130 | --*/\r | |
131 | {\r | |
132 | EFI_STATUS Status;\r | |
133 | CHAR8 InfFileName[_MAX_PATH];\r | |
134 | CHAR8 *InfFileImage;\r | |
135 | UINTN InfFileSize;\r | |
136 | UINT8 *FvImage;\r | |
137 | UINTN FvImageSize;\r | |
138 | UINT8 Index;\r | |
139 | CHAR8 FvFileNameBuffer[_MAX_PATH];\r | |
140 | CHAR8 *FvFileName;\r | |
141 | FILE *FvFile;\r | |
142 | FILE *SymFile;\r | |
143 | CHAR8 SymFileNameBuffer[_MAX_PATH];\r | |
144 | CHAR8 *SymFileName;\r | |
145 | UINT8 *SymImage;\r | |
146 | UINTN SymImageSize;\r | |
147 | CHAR8 *CurrentSymString;\r | |
148 | \r | |
149 | FvFileName = FvFileNameBuffer;\r | |
150 | SymFileName = SymFileNameBuffer;\r | |
151 | \r | |
152 | SetUtilityName (UTILITY_NAME);\r | |
153 | //\r | |
154 | // Display utility information\r | |
155 | //\r | |
156 | PrintUtilityInfo ();\r | |
157 | \r | |
158 | //\r | |
159 | // Verify the correct number of arguments\r | |
160 | //\r | |
161 | if (argc != MAX_ARGS) {\r | |
162 | Error (NULL, 0, 0, "invalid number of input parameters specified", NULL);\r | |
163 | PrintUsage ();\r | |
164 | return GetUtilityStatus ();\r | |
165 | }\r | |
166 | //\r | |
167 | // Initialize variables\r | |
168 | //\r | |
169 | strcpy (InfFileName, "");\r | |
170 | \r | |
171 | //\r | |
172 | // Parse the command line arguments\r | |
173 | //\r | |
174 | for (Index = 1; Index < MAX_ARGS; Index += 2) {\r | |
175 | //\r | |
176 | // Make sure argument pair begin with - or /\r | |
177 | //\r | |
178 | if (argv[Index][0] != '-' && argv[Index][0] != '/') {\r | |
179 | Error (NULL, 0, 0, argv[Index], "argument pair must begin with \"-\" or \"/\"");\r | |
180 | PrintUsage ();\r | |
181 | return GetUtilityStatus ();\r | |
182 | }\r | |
183 | //\r | |
184 | // Make sure argument specifier is only one letter\r | |
185 | //\r | |
186 | if (argv[Index][2] != 0) {\r | |
187 | Error (NULL, 0, 0, argv[Index], "unrecognized argument");\r | |
188 | PrintUsage ();\r | |
189 | return GetUtilityStatus ();\r | |
190 | }\r | |
191 | //\r | |
192 | // Determine argument to read\r | |
193 | //\r | |
194 | switch (argv[Index][1]) {\r | |
195 | \r | |
196 | case 'I':\r | |
197 | case 'i':\r | |
198 | if (strlen (InfFileName) == 0) {\r | |
199 | strcpy (InfFileName, argv[Index + 1]);\r | |
200 | } else {\r | |
201 | Error (NULL, 0, 0, argv[Index + 1], "FvInfFileName may only be specified once");\r | |
202 | PrintUsage ();\r | |
203 | return GetUtilityStatus ();\r | |
204 | }\r | |
205 | break;\r | |
206 | \r | |
207 | default:\r | |
208 | Error (NULL, 0, 0, argv[Index], "unrecognized argument");\r | |
209 | PrintUsage ();\r | |
210 | return GetUtilityStatus ();\r | |
211 | break;\r | |
212 | }\r | |
213 | }\r | |
214 | //\r | |
215 | // Read the INF file image\r | |
216 | //\r | |
217 | Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);\r | |
218 | if (EFI_ERROR (Status)) {\r | |
219 | return STATUS_ERROR;\r | |
220 | }\r | |
221 | //\r | |
222 | // Call the GenFvImage lib\r | |
223 | //\r | |
224 | Status = GenerateFvImage (\r | |
225 | InfFileImage,\r | |
226 | InfFileSize,\r | |
227 | &FvImage,\r | |
228 | &FvImageSize,\r | |
229 | &FvFileName,\r | |
230 | &SymImage,\r | |
231 | &SymImageSize,\r | |
232 | &SymFileName\r | |
233 | );\r | |
234 | \r | |
235 | if (EFI_ERROR (Status)) {\r | |
236 | switch (Status) {\r | |
237 | \r | |
238 | case EFI_INVALID_PARAMETER:\r | |
239 | Error (NULL, 0, 0, "invalid parameter passed to GenFvImage Lib", NULL);\r | |
240 | return GetUtilityStatus ();\r | |
241 | break;\r | |
242 | \r | |
243 | case EFI_ABORTED:\r | |
244 | Error (NULL, 0, 0, "error detected while creating the file image", NULL);\r | |
245 | return GetUtilityStatus ();\r | |
246 | break;\r | |
247 | \r | |
248 | case EFI_OUT_OF_RESOURCES:\r | |
249 | Error (NULL, 0, 0, "GenFvImage Lib could not allocate required resources", NULL);\r | |
250 | return GetUtilityStatus ();\r | |
251 | break;\r | |
252 | \r | |
253 | case EFI_VOLUME_CORRUPTED:\r | |
254 | Error (NULL, 0, 0, "no base address was specified, but the FV.INF included a PEI or BSF file", NULL);\r | |
255 | return GetUtilityStatus ();\r | |
256 | break;\r | |
257 | \r | |
258 | case EFI_LOAD_ERROR:\r | |
259 | Error (NULL, 0, 0, "could not load FV image generation library", NULL);\r | |
260 | return GetUtilityStatus ();\r | |
261 | break;\r | |
262 | \r | |
263 | default:\r | |
264 | Error (NULL, 0, 0, "GenFvImage Lib returned unknown status", "status returned = 0x%X", Status);\r | |
265 | return GetUtilityStatus ();\r | |
266 | break;\r | |
267 | }\r | |
268 | }\r | |
269 | //\r | |
270 | // Write file\r | |
271 | //\r | |
272 | FvFile = fopen (FvFileName, "wb");\r | |
273 | if (FvFile == NULL) {\r | |
274 | Error (NULL, 0, 0, FvFileName, "could not open output file");\r | |
275 | free (FvImage);\r | |
276 | free (SymImage);\r | |
277 | return GetUtilityStatus ();\r | |
278 | }\r | |
279 | \r | |
280 | if (fwrite (FvImage, 1, FvImageSize, FvFile) != FvImageSize) {\r | |
281 | Error (NULL, 0, 0, FvFileName, "failed to write to output file");\r | |
282 | free (FvImage);\r | |
283 | free (SymImage);\r | |
284 | fclose (FvFile);\r | |
285 | return GetUtilityStatus ();\r | |
286 | }\r | |
287 | \r | |
288 | fclose (FvFile);\r | |
289 | free (FvImage);\r | |
290 | \r | |
291 | //\r | |
292 | // Write symbol file\r | |
293 | //\r | |
294 | if (strcmp (SymFileName, "")) {\r | |
295 | SymFile = fopen (SymFileName, "wt");\r | |
296 | if (SymFile == NULL) {\r | |
297 | Error (NULL, 0, 0, SymFileName, "could not open output symbol file");\r | |
298 | free (SymImage);\r | |
299 | return GetUtilityStatus ();\r | |
300 | }\r | |
301 | \r | |
302 | fprintf (SymFile, "TEXTSYM format | V1.0\n");\r | |
303 | \r | |
304 | CurrentSymString = SymImage;\r | |
305 | while (((UINTN) CurrentSymString - (UINTN) SymImage) < SymImageSize) {\r | |
306 | fprintf (SymFile, "%s", CurrentSymString);\r | |
307 | CurrentSymString = (CHAR8 *) (((UINTN) CurrentSymString) + strlen (CurrentSymString) + 1);\r | |
308 | }\r | |
309 | \r | |
310 | fclose (SymFile);\r | |
311 | }\r | |
312 | \r | |
313 | free (SymImage);\r | |
314 | \r | |
315 | return GetUtilityStatus ();\r | |
316 | }\r |