]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/Common/ParseGuidedSectionTools.c
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / C / Common / ParseGuidedSectionTools.c
CommitLineData
30fdf114 1/** @file\r
97fa0ee9 2Helper functions for parsing GuidedSectionTools.txt\r
30fdf114 3\r
f7496d71
LG
4Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
30fdf114 12\r
30fdf114
LG
13**/\r
14\r
15#include <assert.h>\r
16#include <string.h>\r
17#include <ctype.h>\r
18#include <stdlib.h>\r
19#include "MemoryFile.h"\r
20#include "CommonLib.h"\r
21#include "EfiUtilityMsgs.h"\r
22#include "ParseInf.h"\r
23#include "ParseGuidedSectionTools.h"\r
24#include "StringFuncs.h"\r
25\r
26\r
27//\r
28// Local types / structures\r
29//\r
30\r
31typedef struct _GUID_SEC_TOOL_ENTRY {\r
32 EFI_GUID Guid;\r
33 CHAR8* Name;\r
34 CHAR8* Path;\r
35 struct _GUID_SEC_TOOL_ENTRY *Next;\r
36} GUID_SEC_TOOL_ENTRY;\r
37\r
38//\r
39// Functin Implementation\r
40//\r
41\r
42EFI_HANDLE\r
43ParseGuidedSectionToolsFile (\r
44 IN CHAR8 *InputFile\r
45 )\r
46/*++\r
47\r
48Routine Description:\r
49\r
50 This function parses the tools_def.txt file. It returns a\r
51 EFI_HANDLE object which can be used for the other library\r
52 functions and should be passed to FreeParsedGuidedSectionToolsHandle\r
53 to free resources when the tools_def.txt information is no\r
54 longer needed.\r
55\r
56Arguments:\r
57\r
58 InputFile Path name of file to read\r
59\r
60Returns:\r
61\r
62 NULL if error parsing\r
63 A non-NULL EFI_HANDLE otherwise\r
64\r
65--*/\r
66{\r
67 EFI_STATUS Status;\r
68 EFI_HANDLE MemoryFile;\r
69 EFI_HANDLE ParsedGuidedSectionTools;\r
70\r
71 Status = GetMemoryFile (InputFile, &MemoryFile);\r
72 if (EFI_ERROR (Status)) {\r
73 return NULL;\r
74 }\r
75\r
76 ParsedGuidedSectionTools = ParseGuidedSectionToolsMemoryFile (MemoryFile);\r
77\r
78 FreeMemoryFile (MemoryFile);\r
f7496d71 79\r
30fdf114
LG
80 return ParsedGuidedSectionTools;\r
81}\r
82\r
83\r
84EFI_HANDLE\r
85ParseGuidedSectionToolsMemoryFile (\r
86 IN EFI_HANDLE InputFile\r
87 )\r
88/*++\r
89\r
90Routine Description:\r
91\r
92 This function parses the tools_def.txt file. It returns a\r
93 EFI_HANDLE object which can be used for the other library\r
94 functions and should be passed to FreeParsedGuidedSectionToolsHandle\r
95 to free resources when the tools_def.txt information is no\r
96 longer needed.\r
97\r
98Arguments:\r
99\r
100 InputFile Memory file image.\r
101\r
102Returns:\r
103\r
104 NULL if error or EOF\r
105 InputBuffer otherwise\r
106\r
107--*/\r
108{\r
109 EFI_STATUS Status;\r
110 CHAR8 *NextLine;\r
111 STRING_LIST *Tool;\r
112 EFI_GUID Guid;\r
113 GUID_SEC_TOOL_ENTRY *FirstGuidTool;\r
114 GUID_SEC_TOOL_ENTRY *LastGuidTool;\r
115 GUID_SEC_TOOL_ENTRY *NewGuidTool;\r
116\r
117 FirstGuidTool = NULL;\r
fd171542 118 LastGuidTool = NULL;\r
30fdf114
LG
119\r
120 while (TRUE) {\r
121 NextLine = ReadMemoryFileLine (InputFile);\r
122 if (NextLine == NULL) {\r
123 break;\r
124 }\r
f7496d71 125\r
30fdf114
LG
126 Status = StripInfDscStringInPlace (NextLine);\r
127 if (EFI_ERROR (Status)) {\r
aee34651 128 free (NextLine);\r
30fdf114
LG
129 break;\r
130 }\r
131\r
132 if (NextLine[0] == '\0') {\r
aee34651 133 free (NextLine);\r
30fdf114
LG
134 continue;\r
135 }\r
136\r
137 Tool = SplitStringByWhitespace (NextLine);\r
138 if ((Tool != NULL) &&\r
139 (Tool->Count == 3)\r
140 ) {\r
141 Status = StringToGuid (Tool->Strings[0], &Guid);\r
142 if (!EFI_ERROR (Status)) {\r
143 NewGuidTool = malloc (sizeof (GUID_SEC_TOOL_ENTRY));\r
144 if (NewGuidTool != NULL) {\r
145 memcpy (&(NewGuidTool->Guid), &Guid, sizeof (Guid));\r
146 NewGuidTool->Name = CloneString(Tool->Strings[1]);\r
147 NewGuidTool->Path = CloneString(Tool->Strings[2]);\r
148 NewGuidTool->Next = NULL;\r
2ff3293d
HW
149\r
150 if (FirstGuidTool == NULL) {\r
151 FirstGuidTool = NewGuidTool;\r
152 } else {\r
153 LastGuidTool->Next = NewGuidTool;\r
154 }\r
155 LastGuidTool = NewGuidTool;\r
30fdf114 156 }\r
30fdf114 157 }\r
aee34651
HW
158 }\r
159\r
160 if (Tool != NULL) {\r
30fdf114
LG
161 FreeStringList (Tool);\r
162 }\r
aee34651 163 free (NextLine);\r
30fdf114
LG
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