3 Copyright (c) 2007 - 2008, Intel Corporation
4 All rights reserved. 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
;
127 NextLine
= ReadMemoryFileLine (InputFile
);
128 if (NextLine
== NULL
) {
132 Status
= StripInfDscStringInPlace (NextLine
);
133 if (EFI_ERROR (Status
)) {
137 if (NextLine
[0] == '\0') {
141 Tool
= SplitStringByWhitespace (NextLine
);
142 if ((Tool
!= NULL
) &&
145 Status
= StringToGuid (Tool
->Strings
[0], &Guid
);
146 if (!EFI_ERROR (Status
)) {
147 NewGuidTool
= malloc (sizeof (GUID_SEC_TOOL_ENTRY
));
148 if (NewGuidTool
!= NULL
) {
149 memcpy (&(NewGuidTool
->Guid
), &Guid
, sizeof (Guid
));
150 NewGuidTool
->Name
= CloneString(Tool
->Strings
[1]);
151 NewGuidTool
->Path
= CloneString(Tool
->Strings
[2]);
152 NewGuidTool
->Next
= NULL
;
154 if (FirstGuidTool
== NULL
) {
155 FirstGuidTool
= NewGuidTool
;
157 LastGuidTool
->Next
= NewGuidTool
;
159 LastGuidTool
= NewGuidTool
;
161 FreeStringList (Tool
);
165 return FirstGuidTool
;
170 LookupGuidedSectionToolPath (
171 IN EFI_HANDLE ParsedGuidedSectionToolsHandle
,
172 IN EFI_GUID
*SectionGuid
178 This function looks up the appropriate tool to use for extracting
179 a GUID defined FV section.
183 ParsedGuidedSectionToolsHandle A parsed GUID section tools handle.
184 SectionGuid The GUID for the section.
188 NULL - if no tool is found or there is another error
189 Non-NULL - The tool to use to access the section contents. (The caller
190 must free the memory associated with this string.)
194 GUID_SEC_TOOL_ENTRY
*GuidTool
;
196 GuidTool
= (GUID_SEC_TOOL_ENTRY
*)ParsedGuidedSectionToolsHandle
;
197 if (GuidTool
== NULL
) {
201 for ( ; GuidTool
!= NULL
; GuidTool
= GuidTool
->Next
) {
202 if (CompareGuid (&(GuidTool
->Guid
), SectionGuid
) == 0) {
203 return CloneString (GuidTool
->Path
);