3 Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 ParseGuidedSectionTools.c
18 Helper functions for parsing GuidedSectionTools.txt
26 #include "MemoryFile.h"
27 #include "CommonLib.h"
28 #include "EfiUtilityMsgs.h"
30 #include "ParseGuidedSectionTools.h"
31 #include "StringFuncs.h"
35 // Local types / structures
38 typedef struct _GUID_SEC_TOOL_ENTRY
{
42 struct _GUID_SEC_TOOL_ENTRY
*Next
;
43 } GUID_SEC_TOOL_ENTRY
;
46 // Functin Implementation
50 ParseGuidedSectionToolsFile (
57 This function parses the tools_def.txt file. It returns a
58 EFI_HANDLE object which can be used for the other library
59 functions and should be passed to FreeParsedGuidedSectionToolsHandle
60 to free resources when the tools_def.txt information is no
65 InputFile Path name of file to read
70 A non-NULL EFI_HANDLE otherwise
75 EFI_HANDLE MemoryFile
;
76 EFI_HANDLE ParsedGuidedSectionTools
;
78 Status
= GetMemoryFile (InputFile
, &MemoryFile
);
79 if (EFI_ERROR (Status
)) {
83 ParsedGuidedSectionTools
= ParseGuidedSectionToolsMemoryFile (MemoryFile
);
85 FreeMemoryFile (MemoryFile
);
87 return ParsedGuidedSectionTools
;
92 ParseGuidedSectionToolsMemoryFile (
93 IN EFI_HANDLE InputFile
99 This function parses the tools_def.txt file. It returns a
100 EFI_HANDLE object which can be used for the other library
101 functions and should be passed to FreeParsedGuidedSectionToolsHandle
102 to free resources when the tools_def.txt information is no
107 InputFile Memory file image.
112 InputBuffer otherwise
120 GUID_SEC_TOOL_ENTRY
*FirstGuidTool
;
121 GUID_SEC_TOOL_ENTRY
*LastGuidTool
;
122 GUID_SEC_TOOL_ENTRY
*NewGuidTool
;
124 FirstGuidTool
= NULL
;
128 NextLine
= ReadMemoryFileLine (InputFile
);
129 if (NextLine
== NULL
) {
133 Status
= StripInfDscStringInPlace (NextLine
);
134 if (EFI_ERROR (Status
)) {
138 if (NextLine
[0] == '\0') {
142 Tool
= SplitStringByWhitespace (NextLine
);
143 if ((Tool
!= NULL
) &&
146 Status
= StringToGuid (Tool
->Strings
[0], &Guid
);
147 if (!EFI_ERROR (Status
)) {
148 NewGuidTool
= malloc (sizeof (GUID_SEC_TOOL_ENTRY
));
149 if (NewGuidTool
!= NULL
) {
150 memcpy (&(NewGuidTool
->Guid
), &Guid
, sizeof (Guid
));
151 NewGuidTool
->Name
= CloneString(Tool
->Strings
[1]);
152 NewGuidTool
->Path
= CloneString(Tool
->Strings
[2]);
153 NewGuidTool
->Next
= NULL
;
155 if (FirstGuidTool
== NULL
) {
156 FirstGuidTool
= NewGuidTool
;
158 LastGuidTool
->Next
= NewGuidTool
;
160 LastGuidTool
= NewGuidTool
;
162 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
);