]> git.proxmox.com Git - mirror_edk2.git/blame - SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c
Nt32Pkg: Replace [Ascii|Unicode]ValueToString
[mirror_edk2.git] / SignedCapsulePkg / Universal / SystemFirmwareUpdate / ParseConfigProfile.c
CommitLineData
f6f91d38
JY
1/** @file\r
2 Parse the INI configuration file and pass the information to the update driver\r
3 so that the driver can perform update accordingly.\r
4\r
5 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions\r
9 of the BSD License which accompanies this distribution. The\r
10 full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include "SystemFirmwareDxe.h"\r
19#include <Library/IniParsingLib.h>\r
20#include <Library/PrintLib.h>\r
21\r
22#define MAX_LINE_LENGTH 512\r
23\r
24/**\r
25 Parse Config data file to get the updated data array.\r
26\r
27 @param[in] DataBuffer Config raw file buffer.\r
28 @param[in] BufferSize Size of raw buffer.\r
29 @param[in, out] ConfigHeader Pointer to the config header.\r
30 @param[in, out] UpdateArray Pointer to the config of update data.\r
31\r
32 @retval EFI_NOT_FOUND No config data is found.\r
33 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.\r
34 @retval EFI_SUCCESS Parse the config file successfully.\r
35\r
36**/\r
37EFI_STATUS\r
38ParseUpdateDataFile (\r
39 IN UINT8 *DataBuffer,\r
40 IN UINTN BufferSize,\r
41 IN OUT CONFIG_HEADER *ConfigHeader,\r
42 IN OUT UPDATE_CONFIG_DATA **UpdateArray\r
43 )\r
44{\r
45 EFI_STATUS Status;\r
46 CHAR8 *SectionName;\r
47 CHAR8 Entry[MAX_LINE_LENGTH];\r
48 UINTN Num;\r
49 UINT64 Num64;\r
50 UINTN Index;\r
51 EFI_GUID FileGuid;\r
52 VOID *Context;\r
53\r
54 //\r
55 // First process the data buffer and get all sections and entries\r
56 //\r
57 Context = OpenIniFile(DataBuffer, BufferSize);\r
58 if (Context == NULL) {\r
59 return EFI_INVALID_PARAMETER;\r
60 }\r
61\r
62 //\r
63 // Now get NumOfUpdate\r
64 //\r
65 Status = GetDecimalUintnFromDataFile(\r
66 Context,\r
67 "Head",\r
68 "NumOfUpdate",\r
69 &Num\r
70 );\r
71 if (EFI_ERROR(Status) || (Num == 0)) {\r
72 DEBUG((DEBUG_ERROR, "NumOfUpdate not found\n"));\r
73 CloseIniFile(Context);\r
74 return EFI_NOT_FOUND;\r
75 }\r
76\r
77 ConfigHeader->NumOfUpdates = Num;\r
78 *UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num));\r
79 if (*UpdateArray == NULL) {\r
80 CloseIniFile(Context);\r
81 return EFI_OUT_OF_RESOURCES;\r
82 }\r
83\r
84 for (Index = 0 ; Index < ConfigHeader->NumOfUpdates ; Index++) {\r
85 //\r
86 // Get the section name of each update\r
87 //\r
88 AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Update");\r
89 AsciiValueToString(Entry + AsciiStrLen(Entry), 0, Index, 0);\r
90 Status = GetStringFromDataFile(\r
91 Context,\r
92 "Head",\r
93 Entry,\r
94 &SectionName\r
95 );\r
96 if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
97 DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
98 CloseIniFile(Context);\r
99 return EFI_NOT_FOUND;\r
100 }\r
101\r
102 //\r
103 // The section name of this update has been found.\r
104 // Now looks for all the config data of this update\r
105 //\r
106 (*UpdateArray)[Index].Index = Index;\r
107\r
108 //\r
109 // FirmwareType\r
110 //\r
111 Status = GetDecimalUintnFromDataFile(\r
112 Context,\r
113 SectionName,\r
114 "FirmwareType",\r
115 &Num\r
116 );\r
117 if (EFI_ERROR(Status)) {\r
118 CloseIniFile(Context);\r
119 DEBUG((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));\r
120 return EFI_NOT_FOUND;\r
121 }\r
122 (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE) Num;\r
123\r
124 //\r
125 // AddressType\r
126 //\r
127 Status = GetDecimalUintnFromDataFile(\r
128 Context,\r
129 SectionName,\r
130 "AddressType",\r
131 &Num\r
132 );\r
133 if (EFI_ERROR(Status)) {\r
134 CloseIniFile(Context);\r
135 DEBUG((DEBUG_ERROR, "[%d] AddressType not found\n", Index));\r
136 return EFI_NOT_FOUND;\r
137 }\r
138 (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE) Num;\r
139\r
140 //\r
141 // BaseAddress\r
142 //\r
143 Status = GetHexUint64FromDataFile(\r
144 Context,\r
145 SectionName,\r
146 "BaseAddress",\r
147 &Num64\r
148 );\r
149 if (EFI_ERROR(Status)) {\r
150 CloseIniFile(Context);\r
151 DEBUG((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));\r
152 return EFI_NOT_FOUND;\r
153 }\r
154 (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num64;\r
155\r
156 //\r
157 // FileBuid\r
158 //\r
159 Status = GetGuidFromDataFile(\r
160 Context,\r
161 SectionName,\r
162 "FileGuid",\r
163 &FileGuid\r
164 );\r
165 if (EFI_ERROR(Status)) {\r
166 CloseIniFile(Context);\r
167 DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
168 return EFI_NOT_FOUND;\r
169 }\r
170\r
171 CopyGuid(&((*UpdateArray)[Index].FileGuid), &FileGuid);\r
172\r
173 //\r
174 // Length\r
175 //\r
176 Status = GetHexUintnFromDataFile(\r
177 Context,\r
178 SectionName,\r
179 "Length",\r
180 &Num\r
181 );\r
182 if (EFI_ERROR(Status)) {\r
183 CloseIniFile(Context);\r
184 DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
185 return EFI_NOT_FOUND;\r
186 }\r
187 (*UpdateArray)[Index].Length = (UINTN) Num;\r
188\r
189 //\r
190 // ImageOffset\r
191 //\r
192 Status = GetHexUintnFromDataFile(\r
193 Context,\r
194 SectionName,\r
195 "ImageOffset",\r
196 &Num\r
197 );\r
198 if (EFI_ERROR(Status)) {\r
199 CloseIniFile(Context);\r
200 DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
201 return EFI_NOT_FOUND;\r
202 }\r
203 (*UpdateArray)[Index].ImageOffset = (UINTN) Num;\r
204 }\r
205\r
206 //\r
207 // Now all configuration data got. Free those temporary buffers\r
208 //\r
209 CloseIniFile(Context);\r
210\r
211 return EFI_SUCCESS;\r
212}\r
213\r