2 Helper functions for parsing GuidedSectionTools.txt
4 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "MemoryFile.h"
20 #include "CommonLib.h"
21 #include "EfiUtilityMsgs.h"
23 #include "ParseGuidedSectionTools.h"
24 #include "StringFuncs.h"
28 // Local types / structures
31 typedef struct _GUID_SEC_TOOL_ENTRY
{
35 struct _GUID_SEC_TOOL_ENTRY
*Next
;
36 } GUID_SEC_TOOL_ENTRY
;
39 // Functin Implementation
43 ParseGuidedSectionToolsFile (
50 This function parses the tools_def.txt file. It returns a
51 EFI_HANDLE object which can be used for the other library
52 functions and should be passed to FreeParsedGuidedSectionToolsHandle
53 to free resources when the tools_def.txt information is no
58 InputFile Path name of file to read
63 A non-NULL EFI_HANDLE otherwise
68 EFI_HANDLE MemoryFile
;
69 EFI_HANDLE ParsedGuidedSectionTools
;
71 Status
= GetMemoryFile (InputFile
, &MemoryFile
);
72 if (EFI_ERROR (Status
)) {
76 ParsedGuidedSectionTools
= ParseGuidedSectionToolsMemoryFile (MemoryFile
);
78 FreeMemoryFile (MemoryFile
);
80 return ParsedGuidedSectionTools
;
85 ParseGuidedSectionToolsMemoryFile (
86 IN EFI_HANDLE InputFile
92 This function parses the tools_def.txt file. It returns a
93 EFI_HANDLE object which can be used for the other library
94 functions and should be passed to FreeParsedGuidedSectionToolsHandle
95 to free resources when the tools_def.txt information is no
100 InputFile Memory file image.
105 InputBuffer otherwise
113 GUID_SEC_TOOL_ENTRY
*FirstGuidTool
;
114 GUID_SEC_TOOL_ENTRY
*LastGuidTool
;
115 GUID_SEC_TOOL_ENTRY
*NewGuidTool
;
117 FirstGuidTool
= NULL
;
121 NextLine
= ReadMemoryFileLine (InputFile
);
122 if (NextLine
== NULL
) {
126 Status
= StripInfDscStringInPlace (NextLine
);
127 if (EFI_ERROR (Status
)) {
132 if (NextLine
[0] == '\0') {
137 Tool
= SplitStringByWhitespace (NextLine
);
138 if ((Tool
!= NULL
) &&
141 Status
= StringToGuid (Tool
->Strings
[0], &Guid
);
142 if (!EFI_ERROR (Status
)) {
143 NewGuidTool
= malloc (sizeof (GUID_SEC_TOOL_ENTRY
));
144 if (NewGuidTool
!= NULL
) {
145 memcpy (&(NewGuidTool
->Guid
), &Guid
, sizeof (Guid
));
146 NewGuidTool
->Name
= CloneString(Tool
->Strings
[1]);
147 NewGuidTool
->Path
= CloneString(Tool
->Strings
[2]);
148 NewGuidTool
->Next
= NULL
;
150 if (FirstGuidTool
== NULL
) {
151 FirstGuidTool
= NewGuidTool
;
153 LastGuidTool
->Next
= NewGuidTool
;
155 LastGuidTool
= NewGuidTool
;
161 FreeStringList (Tool
);
166 return FirstGuidTool
;
171 LookupGuidedSectionToolPath (
172 IN EFI_HANDLE ParsedGuidedSectionToolsHandle
,
173 IN EFI_GUID
*SectionGuid
179 This function looks up the appropriate tool to use for extracting
180 a GUID defined FV section.
184 ParsedGuidedSectionToolsHandle A parsed GUID section tools handle.
185 SectionGuid The GUID for the section.
189 NULL - if no tool is found or there is another error
190 Non-NULL - The tool to use to access the section contents. (The caller
191 must free the memory associated with this string.)
195 GUID_SEC_TOOL_ENTRY
*GuidTool
;
197 GuidTool
= (GUID_SEC_TOOL_ENTRY
*)ParsedGuidedSectionToolsHandle
;
198 if (GuidTool
== NULL
) {
202 for ( ; GuidTool
!= NULL
; GuidTool
= GuidTool
->Next
) {
203 if (CompareGuid (&(GuidTool
->Guid
), SectionGuid
) == 0) {
204 return CloneString (GuidTool
->Path
);