TianoCore EDK2 master
Loading...
Searching...
No Matches
ParseConfigProfile.c
Go to the documentation of this file.
1
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 RECOVERY_CONFIG_DATA **RecoveryArray
36 )
37{
38 EFI_STATUS Status;
39 CHAR8 *SectionName;
40 CHAR8 Entry[MAX_LINE_LENGTH];
41 UINTN Num;
42 UINTN Index;
43 EFI_GUID FileGuid;
44 VOID *Context;
45
46 //
47 // First process the data buffer and get all sections and entries
48 //
49 Context = OpenIniFile (DataBuffer, BufferSize);
50 if (Context == NULL) {
51 return EFI_INVALID_PARAMETER;
52 }
53
54 //
55 // Now get NumOfUpdate
56 //
58 Context,
59 "Head",
60 "NumOfRecovery",
61 &Num
62 );
63 if (EFI_ERROR (Status) || (Num == 0)) {
64 DEBUG ((DEBUG_ERROR, "NumOfRecovery not found\n"));
65 CloseIniFile (Context);
66 return EFI_NOT_FOUND;
67 }
68
69 ConfigHeader->NumOfRecovery = Num;
70 *RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num));
71 if (*RecoveryArray == NULL) {
72 CloseIniFile (Context);
73 return EFI_OUT_OF_RESOURCES;
74 }
75
76 for (Index = 0; Index < ConfigHeader->NumOfRecovery; Index++) {
77 //
78 // Get the section name of each update
79 //
80 AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Recovery");
82 Entry + AsciiStrnLenS (Entry, MAX_LINE_LENGTH),
83 MAX_LINE_LENGTH - AsciiStrnLenS (Entry, MAX_LINE_LENGTH),
84 0,
85 Index,
86 0
87 );
88 Status = GetStringFromDataFile (
89 Context,
90 "Head",
91 Entry,
92 &SectionName
93 );
94 if (EFI_ERROR (Status) || (SectionName == NULL)) {
95 DEBUG ((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));
96 CloseIniFile (Context);
97 return EFI_NOT_FOUND;
98 }
99
100 //
101 // The section name of this update has been found.
102 // Now looks for all the config data of this update
103 //
104
105 //
106 // FileGuid
107 //
108 Status = GetGuidFromDataFile (
109 Context,
110 SectionName,
111 "FileGuid",
112 &FileGuid
113 );
114 if (EFI_ERROR (Status)) {
115 CloseIniFile (Context);
116 DEBUG ((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));
117 return EFI_NOT_FOUND;
118 }
119
120 CopyGuid (&((*RecoveryArray)[Index].FileGuid), &FileGuid);
121
122 //
123 // Length
124 //
125 Status = GetHexUintnFromDataFile (
126 Context,
127 SectionName,
128 "Length",
129 &Num
130 );
131 if (EFI_ERROR (Status)) {
132 CloseIniFile (Context);
133 DEBUG ((DEBUG_ERROR, "[%d] Length not found\n", Index));
134 return EFI_NOT_FOUND;
135 }
136
137 (*RecoveryArray)[Index].Length = Num;
138
139 //
140 // ImageOffset
141 //
142 Status = GetHexUintnFromDataFile (
143 Context,
144 SectionName,
145 "ImageOffset",
146 &Num
147 );
148 if (EFI_ERROR (Status)) {
149 CloseIniFile (Context);
150 DEBUG ((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));
151 return EFI_NOT_FOUND;
152 }
153
154 (*RecoveryArray)[Index].ImageOffset = Num;
155 }
156
157 //
158 // Now all configuration data got. Free those temporary buffers
159 //
160 CloseIniFile (Context);
161
162 return EFI_SUCCESS;
163}
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 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 ParseRecoveryDataFile(IN UINT8 *DataBuffer, IN UINTN BufferSize, IN OUT CONFIG_HEADER *ConfigHeader, IN OUT RECOVERY_CONFIG_DATA **RecoveryArray)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213