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
;
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
;
139 (*UpdateArray
)[Index
].AddressType
= (FLASH_ADDRESS_TYPE
)Num
;
144 Status
= GetHexUint64FromDataFile (
150 if (EFI_ERROR (Status
)) {
151 CloseIniFile (Context
);
152 DEBUG ((DEBUG_ERROR
, "[%d] BaseAddress not found\n", Index
));
153 return EFI_NOT_FOUND
;
156 (*UpdateArray
)[Index
].BaseAddress
= (EFI_PHYSICAL_ADDRESS
)Num64
;
161 Status
= GetGuidFromDataFile (
167 if (EFI_ERROR (Status
)) {
168 CloseIniFile (Context
);
169 DEBUG ((DEBUG_ERROR
, "[%d] FileGuid not found\n", Index
));
170 return EFI_NOT_FOUND
;
173 CopyGuid (&((*UpdateArray
)[Index
].FileGuid
), &FileGuid
);
178 Status
= GetHexUintnFromDataFile (
184 if (EFI_ERROR (Status
)) {
185 CloseIniFile (Context
);
186 DEBUG ((DEBUG_ERROR
, "[%d] Length not found\n", Index
));
187 return EFI_NOT_FOUND
;
190 (*UpdateArray
)[Index
].Length
= (UINTN
)Num
;
195 Status
= GetHexUintnFromDataFile (
201 if (EFI_ERROR (Status
)) {
202 CloseIniFile (Context
);
203 DEBUG ((DEBUG_ERROR
, "[%d] ImageOffset not found\n", Index
));
204 return EFI_NOT_FOUND
;
207 (*UpdateArray
)[Index
].ImageOffset
= (UINTN
)Num
;
211 // Now all configuration data got. Free those temporary buffers
213 CloseIniFile (Context
);