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 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");
90 Entry
+ AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
91 MAX_LINE_LENGTH
- AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
96 Status
= GetStringFromDataFile(
102 if (EFI_ERROR(Status
) || (SectionName
== NULL
)) {
103 DEBUG((DEBUG_ERROR
, "[%d] %a not found\n", Index
, Entry
));
104 CloseIniFile(Context
);
105 return EFI_NOT_FOUND
;
109 // The section name of this update has been found.
110 // Now looks for all the config data of this update
112 (*UpdateArray
)[Index
].Index
= Index
;
117 Status
= GetDecimalUintnFromDataFile(
123 if (EFI_ERROR(Status
)) {
124 CloseIniFile(Context
);
125 DEBUG((DEBUG_ERROR
, "[%d] FirmwareType not found\n", Index
));
126 return EFI_NOT_FOUND
;
128 (*UpdateArray
)[Index
].FirmwareType
= (PLATFORM_FIRMWARE_TYPE
) Num
;
133 Status
= GetDecimalUintnFromDataFile(
139 if (EFI_ERROR(Status
)) {
140 CloseIniFile(Context
);
141 DEBUG((DEBUG_ERROR
, "[%d] AddressType not found\n", Index
));
142 return EFI_NOT_FOUND
;
144 (*UpdateArray
)[Index
].AddressType
= (FLASH_ADDRESS_TYPE
) Num
;
149 Status
= GetHexUint64FromDataFile(
155 if (EFI_ERROR(Status
)) {
156 CloseIniFile(Context
);
157 DEBUG((DEBUG_ERROR
, "[%d] BaseAddress not found\n", Index
));
158 return EFI_NOT_FOUND
;
160 (*UpdateArray
)[Index
].BaseAddress
= (EFI_PHYSICAL_ADDRESS
) Num64
;
165 Status
= GetGuidFromDataFile(
171 if (EFI_ERROR(Status
)) {
172 CloseIniFile(Context
);
173 DEBUG((DEBUG_ERROR
, "[%d] FileGuid not found\n", Index
));
174 return EFI_NOT_FOUND
;
177 CopyGuid(&((*UpdateArray
)[Index
].FileGuid
), &FileGuid
);
182 Status
= GetHexUintnFromDataFile(
188 if (EFI_ERROR(Status
)) {
189 CloseIniFile(Context
);
190 DEBUG((DEBUG_ERROR
, "[%d] Length not found\n", Index
));
191 return EFI_NOT_FOUND
;
193 (*UpdateArray
)[Index
].Length
= (UINTN
) Num
;
198 Status
= GetHexUintnFromDataFile(
204 if (EFI_ERROR(Status
)) {
205 CloseIniFile(Context
);
206 DEBUG((DEBUG_ERROR
, "[%d] ImageOffset not found\n", Index
));
207 return EFI_NOT_FOUND
;
209 (*UpdateArray
)[Index
].ImageOffset
= (UINTN
) Num
;
213 // Now all configuration data got. Free those temporary buffers
215 CloseIniFile(Context
);