2 Parse the INI configuration file and pass the information to the recovery driver
3 so that the driver can perform recovery 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 "RecoveryModuleLoadPei.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] RecoveryArray Pointer to the config of recovery 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.
38 ParseRecoveryDataFile (
41 IN OUT CONFIG_HEADER
*ConfigHeader
,
42 IN OUT RECOVERY_CONFIG_DATA
**RecoveryArray
47 CHAR8 Entry
[MAX_LINE_LENGTH
];
54 // First process the data buffer and get all sections and entries
56 Context
= OpenIniFile(DataBuffer
, BufferSize
);
57 if (Context
== NULL
) {
58 return EFI_INVALID_PARAMETER
;
62 // Now get NumOfUpdate
64 Status
= GetDecimalUintnFromDataFile(
70 if (EFI_ERROR(Status
) || (Num
== 0)) {
71 DEBUG((DEBUG_ERROR
, "NumOfRecovery not found\n"));
72 CloseIniFile(Context
);
76 ConfigHeader
->NumOfRecovery
= Num
;
77 *RecoveryArray
= AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA
) * Num
));
78 if (*RecoveryArray
== NULL
) {
79 CloseIniFile(Context
);
80 return EFI_OUT_OF_RESOURCES
;
83 for (Index
= 0 ; Index
< ConfigHeader
->NumOfRecovery
; Index
++) {
85 // Get the section name of each update
87 AsciiStrCpyS (Entry
, MAX_LINE_LENGTH
, "Recovery");
88 AsciiValueToString(Entry
+ AsciiStrLen(Entry
), 0, Index
, 0);
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
109 Status
= GetGuidFromDataFile(
115 if (EFI_ERROR(Status
)) {
116 CloseIniFile(Context
);
117 DEBUG((DEBUG_ERROR
, "[%d] FileGuid not found\n", Index
));
118 return EFI_NOT_FOUND
;
121 CopyGuid(&((*RecoveryArray
)[Index
].FileGuid
), &FileGuid
);
126 Status
= GetHexUintnFromDataFile(
132 if (EFI_ERROR(Status
)) {
133 CloseIniFile(Context
);
134 DEBUG((DEBUG_ERROR
, "[%d] Length not found\n", Index
));
135 return EFI_NOT_FOUND
;
137 (*RecoveryArray
)[Index
].Length
= Num
;
142 Status
= GetHexUintnFromDataFile(
148 if (EFI_ERROR(Status
)) {
149 CloseIniFile(Context
);
150 DEBUG((DEBUG_ERROR
, "[%d] ImageOffset not found\n", Index
));
151 return EFI_NOT_FOUND
;
153 (*RecoveryArray
)[Index
].ImageOffset
= Num
;
157 // Now all configuration data got. Free those temporary buffers
159 CloseIniFile(Context
);