]>
Commit | Line | Data |
---|---|---|
30fdf114 | 1 | /** @file\r |
97fa0ee9 | 2 | Helper functions for parsing GuidedSectionTools.txt\r |
30fdf114 | 3 | \r |
2ff3293d | 4 | Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r |
40d841f6 | 5 | This program and the accompanying materials \r |
30fdf114 LG |
6 | are licensed and made available under the terms and conditions of the BSD License \r |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT 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 | |
31 | typedef 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 | |
42 | EFI_HANDLE\r | |
43 | ParseGuidedSectionToolsFile (\r | |
44 | IN CHAR8 *InputFile\r | |
45 | )\r | |
46 | /*++\r | |
47 | \r | |
48 | Routine 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 | |
56 | Arguments:\r | |
57 | \r | |
58 | InputFile Path name of file to read\r | |
59 | \r | |
60 | Returns:\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 | |
84 | EFI_HANDLE\r | |
85 | ParseGuidedSectionToolsMemoryFile (\r | |
86 | IN EFI_HANDLE InputFile\r | |
87 | )\r | |
88 | /*++\r | |
89 | \r | |
90 | Routine 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 | |
98 | Arguments:\r | |
99 | \r | |
100 | InputFile Memory file image.\r | |
101 | \r | |
102 | Returns:\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 | |
2ff3293d HW |
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 | |
30fdf114 | 154 | }\r |
30fdf114 LG |
155 | }\r |
156 | FreeStringList (Tool);\r | |
157 | }\r | |
158 | }\r | |
159 | \r | |
160 | return FirstGuidTool;\r | |
161 | }\r | |
162 | \r | |
163 | \r | |
164 | CHAR8*\r | |
165 | LookupGuidedSectionToolPath (\r | |
166 | IN EFI_HANDLE ParsedGuidedSectionToolsHandle,\r | |
167 | IN EFI_GUID *SectionGuid\r | |
168 | )\r | |
169 | /*++\r | |
170 | \r | |
171 | Routine Description:\r | |
172 | \r | |
173 | This function looks up the appropriate tool to use for extracting\r | |
174 | a GUID defined FV section.\r | |
175 | \r | |
176 | Arguments:\r | |
177 | \r | |
178 | ParsedGuidedSectionToolsHandle A parsed GUID section tools handle.\r | |
179 | SectionGuid The GUID for the section.\r | |
180 | \r | |
181 | Returns:\r | |
182 | \r | |
183 | NULL - if no tool is found or there is another error\r | |
184 | Non-NULL - The tool to use to access the section contents. (The caller\r | |
185 | must free the memory associated with this string.)\r | |
186 | \r | |
187 | --*/\r | |
188 | {\r | |
189 | GUID_SEC_TOOL_ENTRY *GuidTool;\r | |
190 | \r | |
191 | GuidTool = (GUID_SEC_TOOL_ENTRY*)ParsedGuidedSectionToolsHandle;\r | |
192 | if (GuidTool == NULL) {\r | |
193 | return NULL;\r | |
194 | }\r | |
195 | \r | |
196 | for ( ; GuidTool != NULL; GuidTool = GuidTool->Next) {\r | |
197 | if (CompareGuid (&(GuidTool->Guid), SectionGuid) == 0) {\r | |
198 | return CloneString (GuidTool->Path);\r | |
199 | }\r | |
200 | }\r | |
201 | \r | |
202 | return NULL;\r | |
203 | }\r | |
204 | \r | |
205 | \r |