2 Helper functions for parsing GuidedSectionTools.txt
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "MemoryFile.h"
14 #include "CommonLib.h"
15 #include "EfiUtilityMsgs.h"
17 #include "ParseGuidedSectionTools.h"
18 #include "StringFuncs.h"
22 // Local types / structures
25 typedef struct _GUID_SEC_TOOL_ENTRY
{
29 struct _GUID_SEC_TOOL_ENTRY
*Next
;
30 } GUID_SEC_TOOL_ENTRY
;
33 // Function Implementation
37 ParseGuidedSectionToolsFile (
44 This function parses the tools_def.txt file. It returns a
45 EFI_HANDLE object which can be used for the other library
46 functions and should be passed to FreeParsedGuidedSectionToolsHandle
47 to free resources when the tools_def.txt information is no
52 InputFile Path name of file to read
57 A non-NULL EFI_HANDLE otherwise
62 EFI_HANDLE MemoryFile
;
63 EFI_HANDLE ParsedGuidedSectionTools
;
65 Status
= GetMemoryFile (InputFile
, &MemoryFile
);
66 if (EFI_ERROR (Status
)) {
70 ParsedGuidedSectionTools
= ParseGuidedSectionToolsMemoryFile (MemoryFile
);
72 FreeMemoryFile (MemoryFile
);
74 return ParsedGuidedSectionTools
;
79 ParseGuidedSectionToolsMemoryFile (
80 IN EFI_HANDLE InputFile
86 This function parses the tools_def.txt file. It returns a
87 EFI_HANDLE object which can be used for the other library
88 functions and should be passed to FreeParsedGuidedSectionToolsHandle
89 to free resources when the tools_def.txt information is no
94 InputFile Memory file image.
107 GUID_SEC_TOOL_ENTRY
*FirstGuidTool
;
108 GUID_SEC_TOOL_ENTRY
*LastGuidTool
;
109 GUID_SEC_TOOL_ENTRY
*NewGuidTool
;
111 FirstGuidTool
= NULL
;
115 NextLine
= ReadMemoryFileLine (InputFile
);
116 if (NextLine
== NULL
) {
120 Status
= StripInfDscStringInPlace (NextLine
);
121 if (EFI_ERROR (Status
)) {
126 if (NextLine
[0] == '\0') {
131 Tool
= SplitStringByWhitespace (NextLine
);
132 if ((Tool
!= NULL
) &&
135 Status
= StringToGuid (Tool
->Strings
[0], &Guid
);
136 if (!EFI_ERROR (Status
)) {
137 NewGuidTool
= malloc (sizeof (GUID_SEC_TOOL_ENTRY
));
138 if (NewGuidTool
!= NULL
) {
139 memcpy (&(NewGuidTool
->Guid
), &Guid
, sizeof (Guid
));
140 NewGuidTool
->Name
= CloneString(Tool
->Strings
[1]);
141 NewGuidTool
->Path
= CloneString(Tool
->Strings
[2]);
142 NewGuidTool
->Next
= NULL
;
144 if (FirstGuidTool
== NULL
) {
145 FirstGuidTool
= NewGuidTool
;
147 LastGuidTool
->Next
= NewGuidTool
;
149 LastGuidTool
= NewGuidTool
;
155 FreeStringList (Tool
);
160 return FirstGuidTool
;
165 LookupGuidedSectionToolPath (
166 IN EFI_HANDLE ParsedGuidedSectionToolsHandle
,
167 IN EFI_GUID
*SectionGuid
173 This function looks up the appropriate tool to use for extracting
174 a GUID defined FV section.
178 ParsedGuidedSectionToolsHandle A parsed GUID section tools handle.
179 SectionGuid The GUID for the section.
183 NULL - if no tool is found or there is another error
184 Non-NULL - The tool to use to access the section contents. (The caller
185 must free the memory associated with this string.)
189 GUID_SEC_TOOL_ENTRY
*GuidTool
;
191 GuidTool
= (GUID_SEC_TOOL_ENTRY
*)ParsedGuidedSectionToolsHandle
;
192 if (GuidTool
== NULL
) {
196 for ( ; GuidTool
!= NULL
; GuidTool
= GuidTool
->Next
) {
197 if (CompareGuid (&(GuidTool
->Guid
), SectionGuid
) == 0) {
198 return CloneString (GuidTool
->Path
);