]> git.proxmox.com Git - mirror_edk2.git/blob - SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c
7d414b07fbc4eb8635aff49828db96a59da55e6e
[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 (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE) Num;
122
123 //
124 // AddressType
125 //
126 Status = GetDecimalUintnFromDataFile(
127 Context,
128 SectionName,
129 "AddressType",
130 &Num
131 );
132 if (EFI_ERROR(Status)) {
133 CloseIniFile(Context);
134 DEBUG((DEBUG_ERROR, "[%d] AddressType not found\n", Index));
135 return EFI_NOT_FOUND;
136 }
137 (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE) Num;
138
139 //
140 // BaseAddress
141 //
142 Status = GetHexUint64FromDataFile(
143 Context,
144 SectionName,
145 "BaseAddress",
146 &Num64
147 );
148 if (EFI_ERROR(Status)) {
149 CloseIniFile(Context);
150 DEBUG((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));
151 return EFI_NOT_FOUND;
152 }
153 (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num64;
154
155 //
156 // FileBuid
157 //
158 Status = GetGuidFromDataFile(
159 Context,
160 SectionName,
161 "FileGuid",
162 &FileGuid
163 );
164 if (EFI_ERROR(Status)) {
165 CloseIniFile(Context);
166 DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));
167 return EFI_NOT_FOUND;
168 }
169
170 CopyGuid(&((*UpdateArray)[Index].FileGuid), &FileGuid);
171
172 //
173 // Length
174 //
175 Status = GetHexUintnFromDataFile(
176 Context,
177 SectionName,
178 "Length",
179 &Num
180 );
181 if (EFI_ERROR(Status)) {
182 CloseIniFile(Context);
183 DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));
184 return EFI_NOT_FOUND;
185 }
186 (*UpdateArray)[Index].Length = (UINTN) Num;
187
188 //
189 // ImageOffset
190 //
191 Status = GetHexUintnFromDataFile(
192 Context,
193 SectionName,
194 "ImageOffset",
195 &Num
196 );
197 if (EFI_ERROR(Status)) {
198 CloseIniFile(Context);
199 DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));
200 return EFI_NOT_FOUND;
201 }
202 (*UpdateArray)[Index].ImageOffset = (UINTN) Num;
203 }
204
205 //
206 // Now all configuration data got. Free those temporary buffers
207 //
208 CloseIniFile(Context);
209
210 return EFI_SUCCESS;
211 }
212