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 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "RecoveryModuleLoadPei.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] RecoveryArray Pointer to the config of recovery 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.
31 ParseRecoveryDataFile (
34 IN OUT CONFIG_HEADER
*ConfigHeader
,
35 IN OUT RECOVERY_CONFIG_DATA
**RecoveryArray
40 CHAR8 Entry
[MAX_LINE_LENGTH
];
47 // First process the data buffer and get all sections and entries
49 Context
= OpenIniFile (DataBuffer
, BufferSize
);
50 if (Context
== NULL
) {
51 return EFI_INVALID_PARAMETER
;
55 // Now get NumOfUpdate
57 Status
= GetDecimalUintnFromDataFile (
63 if (EFI_ERROR (Status
) || (Num
== 0)) {
64 DEBUG ((DEBUG_ERROR
, "NumOfRecovery not found\n"));
65 CloseIniFile (Context
);
69 ConfigHeader
->NumOfRecovery
= Num
;
70 *RecoveryArray
= AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA
) * Num
));
71 if (*RecoveryArray
== NULL
) {
72 CloseIniFile (Context
);
73 return EFI_OUT_OF_RESOURCES
;
76 for (Index
= 0; Index
< ConfigHeader
->NumOfRecovery
; Index
++) {
78 // Get the section name of each update
80 AsciiStrCpyS (Entry
, MAX_LINE_LENGTH
, "Recovery");
82 Entry
+ AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
83 MAX_LINE_LENGTH
- AsciiStrnLenS (Entry
, MAX_LINE_LENGTH
),
88 Status
= GetStringFromDataFile (
94 if (EFI_ERROR (Status
) || (SectionName
== NULL
)) {
95 DEBUG ((DEBUG_ERROR
, "[%d] %a not found\n", Index
, Entry
));
96 CloseIniFile (Context
);
101 // The section name of this update has been found.
102 // Now looks for all the config data of this update
108 Status
= GetGuidFromDataFile (
114 if (EFI_ERROR (Status
)) {
115 CloseIniFile (Context
);
116 DEBUG ((DEBUG_ERROR
, "[%d] FileGuid not found\n", Index
));
117 return EFI_NOT_FOUND
;
120 CopyGuid (&((*RecoveryArray
)[Index
].FileGuid
), &FileGuid
);
125 Status
= GetHexUintnFromDataFile (
131 if (EFI_ERROR (Status
)) {
132 CloseIniFile (Context
);
133 DEBUG ((DEBUG_ERROR
, "[%d] Length not found\n", Index
));
134 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
;
154 (*RecoveryArray
)[Index
].ImageOffset
= Num
;
158 // Now all configuration data got. Free those temporary buffers
160 CloseIniFile (Context
);