]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/Common/ParseGuidedSectionTools.c
Sync basetools' source and binary files with r1707 of the basetools project.
[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
fd171542 125 LastGuidTool = NULL;\r
30fdf114
LG
126\r
127 while (TRUE) {\r
128 NextLine = ReadMemoryFileLine (InputFile);\r
129 if (NextLine == NULL) {\r
130 break;\r
131 }\r
132 \r
133 Status = StripInfDscStringInPlace (NextLine);\r
134 if (EFI_ERROR (Status)) {\r
135 break;\r
136 }\r
137\r
138 if (NextLine[0] == '\0') {\r
139 continue;\r
140 }\r
141\r
142 Tool = SplitStringByWhitespace (NextLine);\r
143 if ((Tool != NULL) &&\r
144 (Tool->Count == 3)\r
145 ) {\r
146 Status = StringToGuid (Tool->Strings[0], &Guid);\r
147 if (!EFI_ERROR (Status)) {\r
148 NewGuidTool = malloc (sizeof (GUID_SEC_TOOL_ENTRY));\r
149 if (NewGuidTool != NULL) {\r
150 memcpy (&(NewGuidTool->Guid), &Guid, sizeof (Guid));\r
151 NewGuidTool->Name = CloneString(Tool->Strings[1]);\r
152 NewGuidTool->Path = CloneString(Tool->Strings[2]);\r
153 NewGuidTool->Next = NULL;\r
154 }\r
155 if (FirstGuidTool == NULL) {\r
156 FirstGuidTool = NewGuidTool;\r
157 } else {\r
158 LastGuidTool->Next = NewGuidTool;\r
159 }\r
160 LastGuidTool = NewGuidTool;\r
161 }\r
162 FreeStringList (Tool);\r
163 }\r
164 }\r
165\r
166 return FirstGuidTool;\r
167}\r
168\r
169\r
170CHAR8*\r
171LookupGuidedSectionToolPath (\r
172 IN EFI_HANDLE ParsedGuidedSectionToolsHandle,\r
173 IN EFI_GUID *SectionGuid\r
174 )\r
175/*++\r
176\r
177Routine Description:\r
178\r
179 This function looks up the appropriate tool to use for extracting\r
180 a GUID defined FV section.\r
181\r
182Arguments:\r
183\r
184 ParsedGuidedSectionToolsHandle A parsed GUID section tools handle.\r
185 SectionGuid The GUID for the section.\r
186\r
187Returns:\r
188\r
189 NULL - if no tool is found or there is another error\r
190 Non-NULL - The tool to use to access the section contents. (The caller\r
191 must free the memory associated with this string.)\r
192\r
193--*/\r
194{\r
195 GUID_SEC_TOOL_ENTRY *GuidTool;\r
196\r
197 GuidTool = (GUID_SEC_TOOL_ENTRY*)ParsedGuidedSectionToolsHandle;\r
198 if (GuidTool == NULL) {\r
199 return NULL;\r
200 }\r
201\r
202 for ( ; GuidTool != NULL; GuidTool = GuidTool->Next) {\r
203 if (CompareGuid (&(GuidTool->Guid), SectionGuid) == 0) {\r
204 return CloneString (GuidTool->Path);\r
205 }\r
206 }\r
207\r
208 return NULL;\r
209}\r
210\r
211\r