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 - 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 "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");
89 Entry
+ AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
90 MAX_LINE_LENGTH
- AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
95 Status
= GetStringFromDataFile(
101 if (EFI_ERROR(Status
) || (SectionName
== NULL
)) {
102 DEBUG((DEBUG_ERROR
, "[%d] %a not found\n", Index
, Entry
));
103 CloseIniFile(Context
);
104 return EFI_NOT_FOUND
;
108 // The section name of this update has been found.
109 // Now looks for all the config data of this update
115 Status
= GetGuidFromDataFile(
121 if (EFI_ERROR(Status
)) {
122 CloseIniFile(Context
);
123 DEBUG((DEBUG_ERROR
, "[%d] FileGuid not found\n", Index
));
124 return EFI_NOT_FOUND
;
127 CopyGuid(&((*RecoveryArray
)[Index
].FileGuid
), &FileGuid
);
132 Status
= GetHexUintnFromDataFile(
138 if (EFI_ERROR(Status
)) {
139 CloseIniFile(Context
);
140 DEBUG((DEBUG_ERROR
, "[%d] Length not found\n", Index
));
141 return EFI_NOT_FOUND
;
143 (*RecoveryArray
)[Index
].Length
= Num
;
148 Status
= GetHexUintnFromDataFile(
154 if (EFI_ERROR(Status
)) {
155 CloseIniFile(Context
);
156 DEBUG((DEBUG_ERROR
, "[%d] ImageOffset not found\n", Index
));
157 return EFI_NOT_FOUND
;
159 (*RecoveryArray
)[Index
].ImageOffset
= Num
;
163 // Now all configuration data got. Free those temporary buffers
165 CloseIniFile(Context
);