]> git.proxmox.com Git - mirror_edk2.git/blame - SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
b8786489 15#define MAX_LINE_LENGTH 512\r
f6f91d38
JY
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
b8786489
MK
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
f6f91d38
JY
36 )\r
37{\r
b8786489
MK
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
f6f91d38
JY
46\r
47 //\r
48 // First process the data buffer and get all sections and entries\r
49 //\r
b8786489 50 Context = OpenIniFile (DataBuffer, BufferSize);\r
f6f91d38
JY
51 if (Context == NULL) {\r
52 return EFI_INVALID_PARAMETER;\r
53 }\r
54\r
55 //\r
56 // Now get NumOfUpdate\r
57 //\r
b8786489 58 Status = GetDecimalUintnFromDataFile (\r
f6f91d38
JY
59 Context,\r
60 "Head",\r
61 "NumOfUpdate",\r
62 &Num\r
63 );\r
b8786489
MK
64 if (EFI_ERROR (Status) || (Num == 0)) {\r
65 DEBUG ((DEBUG_ERROR, "NumOfUpdate not found\n"));\r
66 CloseIniFile (Context);\r
f6f91d38
JY
67 return EFI_NOT_FOUND;\r
68 }\r
69\r
70 ConfigHeader->NumOfUpdates = Num;\r
b8786489 71 *UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num));\r
f6f91d38 72 if (*UpdateArray == NULL) {\r
b8786489 73 CloseIniFile (Context);\r
f6f91d38
JY
74 return EFI_OUT_OF_RESOURCES;\r
75 }\r
76\r
b8786489 77 for (Index = 0; Index < ConfigHeader->NumOfUpdates; Index++) {\r
f6f91d38
JY
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
b8786489 89 Status = GetStringFromDataFile (\r
f6f91d38
JY
90 Context,\r
91 "Head",\r
92 Entry,\r
93 &SectionName\r
94 );\r
b8786489
MK
95 if (EFI_ERROR (Status) || (SectionName == NULL)) {\r
96 DEBUG ((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
97 CloseIniFile (Context);\r
f6f91d38
JY
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
b8786489 110 Status = GetDecimalUintnFromDataFile (\r
f6f91d38
JY
111 Context,\r
112 SectionName,\r
113 "FirmwareType",\r
114 &Num\r
115 );\r
b8786489
MK
116 if (EFI_ERROR (Status)) {\r
117 CloseIniFile (Context);\r
118 DEBUG ((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));\r
f6f91d38
JY
119 return EFI_NOT_FOUND;\r
120 }\r
b8786489
MK
121\r
122 (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE)Num;\r
f6f91d38
JY
123\r
124 //\r
125 // AddressType\r
126 //\r
b8786489 127 Status = GetDecimalUintnFromDataFile (\r
f6f91d38
JY
128 Context,\r
129 SectionName,\r
130 "AddressType",\r
131 &Num\r
132 );\r
b8786489
MK
133 if (EFI_ERROR (Status)) {\r
134 CloseIniFile (Context);\r
135 DEBUG ((DEBUG_ERROR, "[%d] AddressType not found\n", Index));\r
f6f91d38
JY
136 return EFI_NOT_FOUND;\r
137 }\r
b8786489
MK
138\r
139 (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE)Num;\r
f6f91d38
JY
140\r
141 //\r
142 // BaseAddress\r
143 //\r
b8786489 144 Status = GetHexUint64FromDataFile (\r
f6f91d38
JY
145 Context,\r
146 SectionName,\r
147 "BaseAddress",\r
148 &Num64\r
149 );\r
b8786489
MK
150 if (EFI_ERROR (Status)) {\r
151 CloseIniFile (Context);\r
152 DEBUG ((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));\r
f6f91d38
JY
153 return EFI_NOT_FOUND;\r
154 }\r
b8786489
MK
155\r
156 (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS)Num64;\r
f6f91d38
JY
157\r
158 //\r
c38f0816 159 // FileGuid\r
f6f91d38 160 //\r
b8786489 161 Status = GetGuidFromDataFile (\r
f6f91d38
JY
162 Context,\r
163 SectionName,\r
164 "FileGuid",\r
165 &FileGuid\r
166 );\r
b8786489
MK
167 if (EFI_ERROR (Status)) {\r
168 CloseIniFile (Context);\r
169 DEBUG ((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
f6f91d38
JY
170 return EFI_NOT_FOUND;\r
171 }\r
172\r
b8786489 173 CopyGuid (&((*UpdateArray)[Index].FileGuid), &FileGuid);\r
f6f91d38
JY
174\r
175 //\r
176 // Length\r
177 //\r
b8786489 178 Status = GetHexUintnFromDataFile (\r
f6f91d38
JY
179 Context,\r
180 SectionName,\r
181 "Length",\r
182 &Num\r
183 );\r
b8786489
MK
184 if (EFI_ERROR (Status)) {\r
185 CloseIniFile (Context);\r
186 DEBUG ((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
f6f91d38
JY
187 return EFI_NOT_FOUND;\r
188 }\r
b8786489
MK
189\r
190 (*UpdateArray)[Index].Length = (UINTN)Num;\r
f6f91d38
JY
191\r
192 //\r
193 // ImageOffset\r
194 //\r
b8786489 195 Status = GetHexUintnFromDataFile (\r
f6f91d38
JY
196 Context,\r
197 SectionName,\r
198 "ImageOffset",\r
199 &Num\r
200 );\r
b8786489
MK
201 if (EFI_ERROR (Status)) {\r
202 CloseIniFile (Context);\r
203 DEBUG ((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
f6f91d38
JY
204 return EFI_NOT_FOUND;\r
205 }\r
b8786489
MK
206\r
207 (*UpdateArray)[Index].ImageOffset = (UINTN)Num;\r
f6f91d38
JY
208 }\r
209\r
210 //\r
211 // Now all configuration data got. Free those temporary buffers\r
212 //\r
b8786489 213 CloseIniFile (Context);\r
f6f91d38
JY
214\r
215 return EFI_SUCCESS;\r
216}\r