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