2 Parse the INI configuration file and pass the information to the update driver
3 so that the driver can perform update accordingly.
5 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions
9 of the BSD License which accompanies this distribution. The
10 full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "SystemFirmwareDxe.h"
19 #include <Library/IniParsingLib.h>
20 #include <Library/PrintLib.h>
22 #define MAX_LINE_LENGTH 512
25 Parse Config data file to get the updated data array.
27 @param[in] DataBuffer Config raw file buffer.
28 @param[in] BufferSize Size of raw buffer.
29 @param[in, out] ConfigHeader Pointer to the config header.
30 @param[in, out] UpdateArray Pointer to the config of update data.
32 @retval EFI_NOT_FOUND No config data is found.
33 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
34 @retval EFI_SUCCESS Parse the config file successfully.
41 IN OUT CONFIG_HEADER
*ConfigHeader
,
42 IN OUT UPDATE_CONFIG_DATA
**UpdateArray
47 CHAR8 Entry
[MAX_LINE_LENGTH
];
55 // First process the data buffer and get all sections and entries
57 Context
= OpenIniFile(DataBuffer
, BufferSize
);
58 if (Context
== NULL
) {
59 return EFI_INVALID_PARAMETER
;
63 // Now get NumOfUpdate
65 Status
= GetDecimalUintnFromDataFile(
71 if (EFI_ERROR(Status
) || (Num
== 0)) {
72 DEBUG((DEBUG_ERROR
, "NumOfUpdate not found\n"));
73 CloseIniFile(Context
);
77 ConfigHeader
->NumOfUpdates
= Num
;
78 *UpdateArray
= AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA
) * Num
));
79 if (*UpdateArray
== NULL
) {
80 CloseIniFile(Context
);
81 return EFI_OUT_OF_RESOURCES
;
84 for (Index
= 0 ; Index
< ConfigHeader
->NumOfUpdates
; Index
++) {
86 // Get the section name of each update
88 AsciiStrCpyS (Entry
, MAX_LINE_LENGTH
, "Update");
89 AsciiValueToString(Entry
+ AsciiStrLen(Entry
), 0, Index
, 0);
90 Status
= GetStringFromDataFile(
96 if (EFI_ERROR(Status
) || (SectionName
== NULL
)) {
97 DEBUG((DEBUG_ERROR
, "[%d] %a not found\n", Index
, Entry
));
98 CloseIniFile(Context
);
103 // The section name of this update has been found.
104 // Now looks for all the config data of this update
106 (*UpdateArray
)[Index
].Index
= Index
;
111 Status
= GetDecimalUintnFromDataFile(
117 if (EFI_ERROR(Status
)) {
118 CloseIniFile(Context
);
119 DEBUG((DEBUG_ERROR
, "[%d] FirmwareType not found\n", Index
));
120 return EFI_NOT_FOUND
;
122 (*UpdateArray
)[Index
].FirmwareType
= (PLATFORM_FIRMWARE_TYPE
) Num
;
127 Status
= GetDecimalUintnFromDataFile(
133 if (EFI_ERROR(Status
)) {
134 CloseIniFile(Context
);
135 DEBUG((DEBUG_ERROR
, "[%d] AddressType not found\n", Index
));
136 return EFI_NOT_FOUND
;
138 (*UpdateArray
)[Index
].AddressType
= (FLASH_ADDRESS_TYPE
) Num
;
143 Status
= GetHexUint64FromDataFile(
149 if (EFI_ERROR(Status
)) {
150 CloseIniFile(Context
);
151 DEBUG((DEBUG_ERROR
, "[%d] BaseAddress not found\n", Index
));
152 return EFI_NOT_FOUND
;
154 (*UpdateArray
)[Index
].BaseAddress
= (EFI_PHYSICAL_ADDRESS
) Num64
;
159 Status
= GetGuidFromDataFile(
165 if (EFI_ERROR(Status
)) {
166 CloseIniFile(Context
);
167 DEBUG((DEBUG_ERROR
, "[%d] FileGuid not found\n", Index
));
168 return EFI_NOT_FOUND
;
171 CopyGuid(&((*UpdateArray
)[Index
].FileGuid
), &FileGuid
);
176 Status
= GetHexUintnFromDataFile(
182 if (EFI_ERROR(Status
)) {
183 CloseIniFile(Context
);
184 DEBUG((DEBUG_ERROR
, "[%d] Length not found\n", Index
));
185 return EFI_NOT_FOUND
;
187 (*UpdateArray
)[Index
].Length
= (UINTN
) Num
;
192 Status
= GetHexUintnFromDataFile(
198 if (EFI_ERROR(Status
)) {
199 CloseIniFile(Context
);
200 DEBUG((DEBUG_ERROR
, "[%d] ImageOffset not found\n", Index
));
201 return EFI_NOT_FOUND
;
203 (*UpdateArray
)[Index
].ImageOffset
= (UINTN
) Num
;
207 // Now all configuration data got. Free those temporary buffers
209 CloseIniFile(Context
);