TianoCore EDK2 master
Loading...
Searching...
No Matches
ParseConfigProfile.c
Go to the documentation of this file.
1
11#include "SystemFirmwareDxe.h"
13#include <Library/PrintLib.h>
14
15#define MAX_LINE_LENGTH 512
16
32 IN UINT8 *DataBuffer,
33 IN UINTN BufferSize,
34 IN OUT CONFIG_HEADER *ConfigHeader,
35 IN OUT UPDATE_CONFIG_DATA **UpdateArray
36 )
37{
38 EFI_STATUS Status;
39 CHAR8 *SectionName;
40 CHAR8 Entry[MAX_LINE_LENGTH];
41 UINTN Num;
42 UINT64 Num64;
43 UINTN Index;
44 EFI_GUID FileGuid;
45 VOID *Context;
46
47 //
48 // First process the data buffer and get all sections and entries
49 //
50 Context = OpenIniFile (DataBuffer, BufferSize);
51 if (Context == NULL) {
52 return EFI_INVALID_PARAMETER;
53 }
54
55 //
56 // Now get NumOfUpdate
57 //
59 Context,
60 "Head",
61 "NumOfUpdate",
62 &Num
63 );
64 if (EFI_ERROR (Status) || (Num == 0)) {
65 DEBUG ((DEBUG_ERROR, "NumOfUpdate not found\n"));
66 CloseIniFile (Context);
67 return EFI_NOT_FOUND;
68 }
69
70 ConfigHeader->NumOfUpdates = Num;
71 *UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num));
72 if (*UpdateArray == NULL) {
73 CloseIniFile (Context);
74 return EFI_OUT_OF_RESOURCES;
75 }
76
77 for (Index = 0; Index < ConfigHeader->NumOfUpdates; Index++) {
78 //
79 // Get the section name of each update
80 //
81 AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Update");
83 Entry + AsciiStrnLenS (Entry, MAX_LINE_LENGTH),
84 MAX_LINE_LENGTH - AsciiStrnLenS (Entry, MAX_LINE_LENGTH),
85 0,
86 Index,
87 0
88 );
89 Status = GetStringFromDataFile (
90 Context,
91 "Head",
92 Entry,
93 &SectionName
94 );
95 if (EFI_ERROR (Status) || (SectionName == NULL)) {
96 DEBUG ((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));
97 CloseIniFile (Context);
98 return EFI_NOT_FOUND;
99 }
100
101 //
102 // The section name of this update has been found.
103 // Now looks for all the config data of this update
104 //
105 (*UpdateArray)[Index].Index = Index;
106
107 //
108 // FirmwareType
109 //
111 Context,
112 SectionName,
113 "FirmwareType",
114 &Num
115 );
116 if (EFI_ERROR (Status)) {
117 CloseIniFile (Context);
118 DEBUG ((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));
119 return EFI_NOT_FOUND;
120 }
121
122 (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE)Num;
123
124 //
125 // AddressType
126 //
128 Context,
129 SectionName,
130 "AddressType",
131 &Num
132 );
133 if (EFI_ERROR (Status)) {
134 CloseIniFile (Context);
135 DEBUG ((DEBUG_ERROR, "[%d] AddressType not found\n", Index));
136 return EFI_NOT_FOUND;
137 }
138
139 (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE)Num;
140
141 //
142 // BaseAddress
143 //
144 Status = GetHexUint64FromDataFile (
145 Context,
146 SectionName,
147 "BaseAddress",
148 &Num64
149 );
150 if (EFI_ERROR (Status)) {
151 CloseIniFile (Context);
152 DEBUG ((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));
153 return EFI_NOT_FOUND;
154 }
155
156 (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS)Num64;
157
158 //
159 // FileGuid
160 //
161 Status = GetGuidFromDataFile (
162 Context,
163 SectionName,
164 "FileGuid",
165 &FileGuid
166 );
167 if (EFI_ERROR (Status)) {
168 CloseIniFile (Context);
169 DEBUG ((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));
170 return EFI_NOT_FOUND;
171 }
172
173 CopyGuid (&((*UpdateArray)[Index].FileGuid), &FileGuid);
174
175 //
176 // Length
177 //
178 Status = GetHexUintnFromDataFile (
179 Context,
180 SectionName,
181 "Length",
182 &Num
183 );
184 if (EFI_ERROR (Status)) {
185 CloseIniFile (Context);
186 DEBUG ((DEBUG_ERROR, "[%d] Length not found\n", Index));
187 return EFI_NOT_FOUND;
188 }
189
190 (*UpdateArray)[Index].Length = (UINTN)Num;
191
192 //
193 // ImageOffset
194 //
195 Status = GetHexUintnFromDataFile (
196 Context,
197 SectionName,
198 "ImageOffset",
199 &Num
200 );
201 if (EFI_ERROR (Status)) {
202 CloseIniFile (Context);
203 DEBUG ((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));
204 return EFI_NOT_FOUND;
205 }
206
207 (*UpdateArray)[Index].ImageOffset = (UINTN)Num;
208 }
209
210 //
211 // Now all configuration data got. Free those temporary buffers
212 //
213 CloseIniFile (Context);
214
215 return EFI_SUCCESS;
216}
UINT64 UINTN
UINTN EFIAPI AsciiStrnLenS(IN CONST CHAR8 *String, IN UINTN MaxSize)
Definition: SafeString.c:1696
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
Definition: SafeString.c:1797
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI CloseIniFile(IN VOID *Context)
EFI_STATUS EFIAPI GetStringFromDataFile(IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT CHAR8 **EntryValue)
EFI_STATUS EFIAPI GetGuidFromDataFile(IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT EFI_GUID *Guid)
EFI_STATUS EFIAPI GetHexUintnFromDataFile(IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT UINTN *Data)
VOID *EFIAPI OpenIniFile(IN UINT8 *DataBuffer, IN UINTN BufferSize)
EFI_STATUS EFIAPI GetHexUint64FromDataFile(IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT UINT64 *Data)
EFI_STATUS EFIAPI GetDecimalUintnFromDataFile(IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT UINTN *Data)
RETURN_STATUS EFIAPI AsciiValueToStringS(IN OUT CHAR8 *Buffer, IN UINTN BufferSize, IN UINTN Flags, IN INT64 Value, IN UINTN Width)
Definition: PrintLib.c:1055
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS ParseUpdateDataFile(IN UINT8 *DataBuffer, IN UINTN BufferSize, IN OUT CONFIG_HEADER *ConfigHeader, IN OUT UPDATE_CONFIG_DATA **UpdateArray)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213