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 - 2017, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "SystemFirmwareDxe.h"
12 #include <Library/IniParsingLib.h>
13 #include <Library/PrintLib.h>
15 #define MAX_LINE_LENGTH 512
18 Parse Config data file to get the updated data array.
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.
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.
34 IN OUT CONFIG_HEADER
*ConfigHeader
,
35 IN OUT UPDATE_CONFIG_DATA
**UpdateArray
40 CHAR8 Entry
[MAX_LINE_LENGTH
];
48 // First process the data buffer and get all sections and entries
50 Context
= OpenIniFile(DataBuffer
, BufferSize
);
51 if (Context
== NULL
) {
52 return EFI_INVALID_PARAMETER
;
56 // Now get NumOfUpdate
58 Status
= GetDecimalUintnFromDataFile(
64 if (EFI_ERROR(Status
) || (Num
== 0)) {
65 DEBUG((DEBUG_ERROR
, "NumOfUpdate not found\n"));
66 CloseIniFile(Context
);
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
;
77 for (Index
= 0 ; Index
< ConfigHeader
->NumOfUpdates
; Index
++) {
79 // Get the section name of each update
81 AsciiStrCpyS (Entry
, MAX_LINE_LENGTH
, "Update");
83 Entry
+ AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
84 MAX_LINE_LENGTH
- AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
89 Status
= GetStringFromDataFile(
95 if (EFI_ERROR(Status
) || (SectionName
== NULL
)) {
96 DEBUG((DEBUG_ERROR
, "[%d] %a not found\n", Index
, Entry
));
97 CloseIniFile(Context
);
102 // The section name of this update has been found.
103 // Now looks for all the config data of this update
105 (*UpdateArray
)[Index
].Index
= Index
;
110 Status
= GetDecimalUintnFromDataFile(
116 if (EFI_ERROR(Status
)) {
117 CloseIniFile(Context
);
118 DEBUG((DEBUG_ERROR
, "[%d] FirmwareType not found\n", Index
));
119 return EFI_NOT_FOUND
;
121 (*UpdateArray
)[Index
].FirmwareType
= (PLATFORM_FIRMWARE_TYPE
) Num
;
126 Status
= GetDecimalUintnFromDataFile(
132 if (EFI_ERROR(Status
)) {
133 CloseIniFile(Context
);
134 DEBUG((DEBUG_ERROR
, "[%d] AddressType not found\n", Index
));
135 return EFI_NOT_FOUND
;
137 (*UpdateArray
)[Index
].AddressType
= (FLASH_ADDRESS_TYPE
) Num
;
142 Status
= GetHexUint64FromDataFile(
148 if (EFI_ERROR(Status
)) {
149 CloseIniFile(Context
);
150 DEBUG((DEBUG_ERROR
, "[%d] BaseAddress not found\n", Index
));
151 return EFI_NOT_FOUND
;
153 (*UpdateArray
)[Index
].BaseAddress
= (EFI_PHYSICAL_ADDRESS
) Num64
;
158 Status
= GetGuidFromDataFile(
164 if (EFI_ERROR(Status
)) {
165 CloseIniFile(Context
);
166 DEBUG((DEBUG_ERROR
, "[%d] FileGuid not found\n", Index
));
167 return EFI_NOT_FOUND
;
170 CopyGuid(&((*UpdateArray
)[Index
].FileGuid
), &FileGuid
);
175 Status
= GetHexUintnFromDataFile(
181 if (EFI_ERROR(Status
)) {
182 CloseIniFile(Context
);
183 DEBUG((DEBUG_ERROR
, "[%d] Length not found\n", Index
));
184 return EFI_NOT_FOUND
;
186 (*UpdateArray
)[Index
].Length
= (UINTN
) Num
;
191 Status
= GetHexUintnFromDataFile(
197 if (EFI_ERROR(Status
)) {
198 CloseIniFile(Context
);
199 DEBUG((DEBUG_ERROR
, "[%d] ImageOffset not found\n", Index
));
200 return EFI_NOT_FOUND
;
202 (*UpdateArray
)[Index
].ImageOffset
= (UINTN
) Num
;
206 // Now all configuration data got. Free those temporary buffers
208 CloseIniFile(Context
);