SignedCapsulePkg: 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
91db774b 5 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
f6f91d38
JY
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
91db774b
HW
89 AsciiValueToStringS (\r
90 Entry + AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
91 MAX_LINE_LENGTH - AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
92 0,\r
93 Index,\r
94 0\r
95 );\r
f6f91d38
JY
96 Status = GetStringFromDataFile(\r
97 Context,\r
98 "Head",\r
99 Entry,\r
100 &SectionName\r
101 );\r
102 if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
103 DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
104 CloseIniFile(Context);\r
105 return EFI_NOT_FOUND;\r
106 }\r
107\r
108 //\r
109 // The section name of this update has been found.\r
110 // Now looks for all the config data of this update\r
111 //\r
112 (*UpdateArray)[Index].Index = Index;\r
113\r
114 //\r
115 // FirmwareType\r
116 //\r
117 Status = GetDecimalUintnFromDataFile(\r
118 Context,\r
119 SectionName,\r
120 "FirmwareType",\r
121 &Num\r
122 );\r
123 if (EFI_ERROR(Status)) {\r
124 CloseIniFile(Context);\r
125 DEBUG((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));\r
126 return EFI_NOT_FOUND;\r
127 }\r
128 (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE) Num;\r
129\r
130 //\r
131 // AddressType\r
132 //\r
133 Status = GetDecimalUintnFromDataFile(\r
134 Context,\r
135 SectionName,\r
136 "AddressType",\r
137 &Num\r
138 );\r
139 if (EFI_ERROR(Status)) {\r
140 CloseIniFile(Context);\r
141 DEBUG((DEBUG_ERROR, "[%d] AddressType not found\n", Index));\r
142 return EFI_NOT_FOUND;\r
143 }\r
144 (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE) Num;\r
145\r
146 //\r
147 // BaseAddress\r
148 //\r
149 Status = GetHexUint64FromDataFile(\r
150 Context,\r
151 SectionName,\r
152 "BaseAddress",\r
153 &Num64\r
154 );\r
155 if (EFI_ERROR(Status)) {\r
156 CloseIniFile(Context);\r
157 DEBUG((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));\r
158 return EFI_NOT_FOUND;\r
159 }\r
160 (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num64;\r
161\r
162 //\r
163 // FileBuid\r
164 //\r
165 Status = GetGuidFromDataFile(\r
166 Context,\r
167 SectionName,\r
168 "FileGuid",\r
169 &FileGuid\r
170 );\r
171 if (EFI_ERROR(Status)) {\r
172 CloseIniFile(Context);\r
173 DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
174 return EFI_NOT_FOUND;\r
175 }\r
176\r
177 CopyGuid(&((*UpdateArray)[Index].FileGuid), &FileGuid);\r
178\r
179 //\r
180 // Length\r
181 //\r
182 Status = GetHexUintnFromDataFile(\r
183 Context,\r
184 SectionName,\r
185 "Length",\r
186 &Num\r
187 );\r
188 if (EFI_ERROR(Status)) {\r
189 CloseIniFile(Context);\r
190 DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
191 return EFI_NOT_FOUND;\r
192 }\r
193 (*UpdateArray)[Index].Length = (UINTN) Num;\r
194\r
195 //\r
196 // ImageOffset\r
197 //\r
198 Status = GetHexUintnFromDataFile(\r
199 Context,\r
200 SectionName,\r
201 "ImageOffset",\r
202 &Num\r
203 );\r
204 if (EFI_ERROR(Status)) {\r
205 CloseIniFile(Context);\r
206 DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
207 return EFI_NOT_FOUND;\r
208 }\r
209 (*UpdateArray)[Index].ImageOffset = (UINTN) Num;\r
210 }\r
211\r
212 //\r
213 // Now all configuration data got. Free those temporary buffers\r
214 //\r
215 CloseIniFile(Context);\r
216\r
217 return EFI_SUCCESS;\r
218}\r
219\r