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