]> git.proxmox.com Git - mirror_edk2.git/blame - SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c
SignedCapsulePkg/Universal: Fix various typos
[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 6\r
fbf06957 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
f6f91d38
JY
8\r
9**/\r
10\r
11#include "SystemFirmwareDxe.h"\r
12#include <Library/IniParsingLib.h>\r
13#include <Library/PrintLib.h>\r
14\r
15#define MAX_LINE_LENGTH 512\r
16\r
17/**\r
18 Parse Config data file to get the updated data array.\r
19\r
20 @param[in] DataBuffer Config raw file buffer.\r
21 @param[in] BufferSize Size of raw buffer.\r
22 @param[in, out] ConfigHeader Pointer to the config header.\r
23 @param[in, out] UpdateArray Pointer to the config of update data.\r
24\r
25 @retval EFI_NOT_FOUND No config data is found.\r
26 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.\r
27 @retval EFI_SUCCESS Parse the config file successfully.\r
28\r
29**/\r
30EFI_STATUS\r
31ParseUpdateDataFile (\r
32 IN UINT8 *DataBuffer,\r
33 IN UINTN BufferSize,\r
34 IN OUT CONFIG_HEADER *ConfigHeader,\r
35 IN OUT UPDATE_CONFIG_DATA **UpdateArray\r
36 )\r
37{\r
38 EFI_STATUS Status;\r
39 CHAR8 *SectionName;\r
40 CHAR8 Entry[MAX_LINE_LENGTH];\r
41 UINTN Num;\r
42 UINT64 Num64;\r
43 UINTN Index;\r
44 EFI_GUID FileGuid;\r
45 VOID *Context;\r
46\r
47 //\r
48 // First process the data buffer and get all sections and entries\r
49 //\r
50 Context = OpenIniFile(DataBuffer, BufferSize);\r
51 if (Context == NULL) {\r
52 return EFI_INVALID_PARAMETER;\r
53 }\r
54\r
55 //\r
56 // Now get NumOfUpdate\r
57 //\r
58 Status = GetDecimalUintnFromDataFile(\r
59 Context,\r
60 "Head",\r
61 "NumOfUpdate",\r
62 &Num\r
63 );\r
64 if (EFI_ERROR(Status) || (Num == 0)) {\r
65 DEBUG((DEBUG_ERROR, "NumOfUpdate not found\n"));\r
66 CloseIniFile(Context);\r
67 return EFI_NOT_FOUND;\r
68 }\r
69\r
70 ConfigHeader->NumOfUpdates = Num;\r
71 *UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num));\r
72 if (*UpdateArray == NULL) {\r
73 CloseIniFile(Context);\r
74 return EFI_OUT_OF_RESOURCES;\r
75 }\r
76\r
77 for (Index = 0 ; Index < ConfigHeader->NumOfUpdates ; Index++) {\r
78 //\r
79 // Get the section name of each update\r
80 //\r
81 AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Update");\r
91db774b
HW
82 AsciiValueToStringS (\r
83 Entry + AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
84 MAX_LINE_LENGTH - AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
85 0,\r
86 Index,\r
87 0\r
88 );\r
f6f91d38
JY
89 Status = GetStringFromDataFile(\r
90 Context,\r
91 "Head",\r
92 Entry,\r
93 &SectionName\r
94 );\r
95 if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
96 DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
97 CloseIniFile(Context);\r
98 return EFI_NOT_FOUND;\r
99 }\r
100\r
101 //\r
102 // The section name of this update has been found.\r
103 // Now looks for all the config data of this update\r
104 //\r
105 (*UpdateArray)[Index].Index = Index;\r
106\r
107 //\r
108 // FirmwareType\r
109 //\r
110 Status = GetDecimalUintnFromDataFile(\r
111 Context,\r
112 SectionName,\r
113 "FirmwareType",\r
114 &Num\r
115 );\r
116 if (EFI_ERROR(Status)) {\r
117 CloseIniFile(Context);\r
118 DEBUG((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));\r
119 return EFI_NOT_FOUND;\r
120 }\r
121 (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE) Num;\r
122\r
123 //\r
124 // AddressType\r
125 //\r
126 Status = GetDecimalUintnFromDataFile(\r
127 Context,\r
128 SectionName,\r
129 "AddressType",\r
130 &Num\r
131 );\r
132 if (EFI_ERROR(Status)) {\r
133 CloseIniFile(Context);\r
134 DEBUG((DEBUG_ERROR, "[%d] AddressType not found\n", Index));\r
135 return EFI_NOT_FOUND;\r
136 }\r
137 (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE) Num;\r
138\r
139 //\r
140 // BaseAddress\r
141 //\r
142 Status = GetHexUint64FromDataFile(\r
143 Context,\r
144 SectionName,\r
145 "BaseAddress",\r
146 &Num64\r
147 );\r
148 if (EFI_ERROR(Status)) {\r
149 CloseIniFile(Context);\r
150 DEBUG((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));\r
151 return EFI_NOT_FOUND;\r
152 }\r
153 (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num64;\r
154\r
155 //\r
c38f0816 156 // FileGuid\r
f6f91d38
JY
157 //\r
158 Status = GetGuidFromDataFile(\r
159 Context,\r
160 SectionName,\r
161 "FileGuid",\r
162 &FileGuid\r
163 );\r
164 if (EFI_ERROR(Status)) {\r
165 CloseIniFile(Context);\r
166 DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
167 return EFI_NOT_FOUND;\r
168 }\r
169\r
170 CopyGuid(&((*UpdateArray)[Index].FileGuid), &FileGuid);\r
171\r
172 //\r
173 // Length\r
174 //\r
175 Status = GetHexUintnFromDataFile(\r
176 Context,\r
177 SectionName,\r
178 "Length",\r
179 &Num\r
180 );\r
181 if (EFI_ERROR(Status)) {\r
182 CloseIniFile(Context);\r
183 DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
184 return EFI_NOT_FOUND;\r
185 }\r
186 (*UpdateArray)[Index].Length = (UINTN) Num;\r
187\r
188 //\r
189 // ImageOffset\r
190 //\r
191 Status = GetHexUintnFromDataFile(\r
192 Context,\r
193 SectionName,\r
194 "ImageOffset",\r
195 &Num\r
196 );\r
197 if (EFI_ERROR(Status)) {\r
198 CloseIniFile(Context);\r
199 DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
200 return EFI_NOT_FOUND;\r
201 }\r
202 (*UpdateArray)[Index].ImageOffset = (UINTN) Num;\r
203 }\r
204\r
205 //\r
206 // Now all configuration data got. Free those temporary buffers\r
207 //\r
208 CloseIniFile(Context);\r
209\r
210 return EFI_SUCCESS;\r
211}\r
212\r