]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/Common/ParseGuidedSectionTools.c
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / C / Common / ParseGuidedSectionTools.c
CommitLineData
30fdf114
LG
1/** @file\r
2\r
3Copyright (c) 2007 - 2008, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 ParseGuidedSectionTools.c\r
15\r
16Abstract:\r
17\r
18 Helper functions for parsing GuidedSectionTools.txt\r
19\r
20**/\r
21\r
22#include <assert.h>\r
23#include <string.h>\r
24#include <ctype.h>\r
25#include <stdlib.h>\r
26#include "MemoryFile.h"\r
27#include "CommonLib.h"\r
28#include "EfiUtilityMsgs.h"\r
29#include "ParseInf.h"\r
30#include "ParseGuidedSectionTools.h"\r
31#include "StringFuncs.h"\r
32\r
33\r
34//\r
35// Local types / structures\r
36//\r
37\r
38typedef struct _GUID_SEC_TOOL_ENTRY {\r
39 EFI_GUID Guid;\r
40 CHAR8* Name;\r
41 CHAR8* Path;\r
42 struct _GUID_SEC_TOOL_ENTRY *Next;\r
43} GUID_SEC_TOOL_ENTRY;\r
44\r
45//\r
46// Functin Implementation\r
47//\r
48\r
49EFI_HANDLE\r
50ParseGuidedSectionToolsFile (\r
51 IN CHAR8 *InputFile\r
52 )\r
53/*++\r
54\r
55Routine Description:\r
56\r
57 This function parses the tools_def.txt file. It returns a\r
58 EFI_HANDLE object which can be used for the other library\r
59 functions and should be passed to FreeParsedGuidedSectionToolsHandle\r
60 to free resources when the tools_def.txt information is no\r
61 longer needed.\r
62\r
63Arguments:\r
64\r
65 InputFile Path name of file to read\r
66\r
67Returns:\r
68\r
69 NULL if error parsing\r
70 A non-NULL EFI_HANDLE otherwise\r
71\r
72--*/\r
73{\r
74 EFI_STATUS Status;\r
75 EFI_HANDLE MemoryFile;\r
76 EFI_HANDLE ParsedGuidedSectionTools;\r
77\r
78 Status = GetMemoryFile (InputFile, &MemoryFile);\r
79 if (EFI_ERROR (Status)) {\r
80 return NULL;\r
81 }\r
82\r
83 ParsedGuidedSectionTools = ParseGuidedSectionToolsMemoryFile (MemoryFile);\r
84\r
85 FreeMemoryFile (MemoryFile);\r
86 \r
87 return ParsedGuidedSectionTools;\r
88}\r
89\r
90\r
91EFI_HANDLE\r
92ParseGuidedSectionToolsMemoryFile (\r
93 IN EFI_HANDLE InputFile\r
94 )\r
95/*++\r
96\r
97Routine Description:\r
98\r
99 This function parses the tools_def.txt file. It returns a\r
100 EFI_HANDLE object which can be used for the other library\r
101 functions and should be passed to FreeParsedGuidedSectionToolsHandle\r
102 to free resources when the tools_def.txt information is no\r
103 longer needed.\r
104\r
105Arguments:\r
106\r
107 InputFile Memory file image.\r
108\r
109Returns:\r
110\r
111 NULL if error or EOF\r
112 InputBuffer otherwise\r
113\r
114--*/\r
115{\r
116 EFI_STATUS Status;\r
117 CHAR8 *NextLine;\r
118 STRING_LIST *Tool;\r
119 EFI_GUID Guid;\r
120 GUID_SEC_TOOL_ENTRY *FirstGuidTool;\r
121 GUID_SEC_TOOL_ENTRY *LastGuidTool;\r
122 GUID_SEC_TOOL_ENTRY *NewGuidTool;\r
123\r
124 FirstGuidTool = NULL;\r
125\r
126 while (TRUE) {\r
127 NextLine = ReadMemoryFileLine (InputFile);\r
128 if (NextLine == NULL) {\r
129 break;\r
130 }\r
131 \r
132 Status = StripInfDscStringInPlace (NextLine);\r
133 if (EFI_ERROR (Status)) {\r
134 break;\r
135 }\r
136\r
137 if (NextLine[0] == '\0') {\r
138 continue;\r
139 }\r
140\r
141 Tool = SplitStringByWhitespace (NextLine);\r
142 if ((Tool != NULL) &&\r
143 (Tool->Count == 3)\r
144 ) {\r
145 Status = StringToGuid (Tool->Strings[0], &Guid);\r
146 if (!EFI_ERROR (Status)) {\r
147 NewGuidTool = malloc (sizeof (GUID_SEC_TOOL_ENTRY));\r
148 if (NewGuidTool != NULL) {\r
149 memcpy (&(NewGuidTool->Guid), &Guid, sizeof (Guid));\r
150 NewGuidTool->Name = CloneString(Tool->Strings[1]);\r
151 NewGuidTool->Path = CloneString(Tool->Strings[2]);\r
152 NewGuidTool->Next = NULL;\r
153 }\r
154 if (FirstGuidTool == NULL) {\r
155 FirstGuidTool = NewGuidTool;\r
156 } else {\r
157 LastGuidTool->Next = NewGuidTool;\r
158 }\r
159 LastGuidTool = NewGuidTool;\r
160 }\r
161 FreeStringList (Tool);\r
162 }\r
163 }\r
164\r
165 return FirstGuidTool;\r
166}\r
167\r
168\r
169CHAR8*\r
170LookupGuidedSectionToolPath (\r
171 IN EFI_HANDLE ParsedGuidedSectionToolsHandle,\r
172 IN EFI_GUID *SectionGuid\r
173 )\r
174/*++\r
175\r
176Routine Description:\r
177\r
178 This function looks up the appropriate tool to use for extracting\r
179 a GUID defined FV section.\r
180\r
181Arguments:\r
182\r
183 ParsedGuidedSectionToolsHandle A parsed GUID section tools handle.\r
184 SectionGuid The GUID for the section.\r
185\r
186Returns:\r
187\r
188 NULL - if no tool is found or there is another error\r
189 Non-NULL - The tool to use to access the section contents. (The caller\r
190 must free the memory associated with this string.)\r
191\r
192--*/\r
193{\r
194 GUID_SEC_TOOL_ENTRY *GuidTool;\r
195\r
196 GuidTool = (GUID_SEC_TOOL_ENTRY*)ParsedGuidedSectionToolsHandle;\r
197 if (GuidTool == NULL) {\r
198 return NULL;\r
199 }\r
200\r
201 for ( ; GuidTool != NULL; GuidTool = GuidTool->Next) {\r
202 if (CompareGuid (&(GuidTool->Guid), SectionGuid) == 0) {\r
203 return CloneString (GuidTool->Path);\r
204 }\r
205 }\r
206\r
207 return NULL;\r
208}\r
209\r
210\r