--- /dev/null
+/** @file\r
+ Parse the INI configuration file and pass the information to the recovery driver\r
+ so that the driver can perform recovery accordingly.\r
+\r
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions\r
+ of the BSD License which accompanies this distribution. The\r
+ full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "RecoveryModuleLoadPei.h"\r
+#include <Library/IniParsingLib.h>\r
+#include <Library/PrintLib.h>\r
+\r
+#define MAX_LINE_LENGTH 512\r
+\r
+/**\r
+ Parse Config data file to get the updated data array.\r
+\r
+ @param[in] DataBuffer Config raw file buffer.\r
+ @param[in] BufferSize Size of raw buffer.\r
+ @param[in, out] ConfigHeader Pointer to the config header.\r
+ @param[in, out] RecoveryArray Pointer to the config of recovery data.\r
+\r
+ @retval EFI_NOT_FOUND No config data is found.\r
+ @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.\r
+ @retval EFI_SUCCESS Parse the config file successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+ParseRecoveryDataFile (\r
+ IN UINT8 *DataBuffer,\r
+ IN UINTN BufferSize,\r
+ IN OUT CONFIG_HEADER *ConfigHeader,\r
+ IN OUT RECOVERY_CONFIG_DATA **RecoveryArray\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ CHAR8 *SectionName;\r
+ CHAR8 Entry[MAX_LINE_LENGTH];\r
+ UINTN Num;\r
+ UINTN Index;\r
+ EFI_GUID FileGuid;\r
+ VOID *Context;\r
+\r
+ //\r
+ // First process the data buffer and get all sections and entries\r
+ //\r
+ Context = OpenIniFile(DataBuffer, BufferSize);\r
+ if (Context == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Now get NumOfUpdate\r
+ //\r
+ Status = GetDecimalUintnFromDataFile(\r
+ Context,\r
+ "Head",\r
+ "NumOfRecovery",\r
+ &Num\r
+ );\r
+ if (EFI_ERROR(Status) || (Num == 0)) {\r
+ DEBUG((DEBUG_ERROR, "NumOfRecovery not found\n"));\r
+ CloseIniFile(Context);\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ ConfigHeader->NumOfRecovery = Num;\r
+ *RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num));\r
+ if (*RecoveryArray == NULL) {\r
+ CloseIniFile(Context);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ for (Index = 0 ; Index < ConfigHeader->NumOfRecovery; Index++) {\r
+ //\r
+ // Get the section name of each update\r
+ //\r
+ AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Recovery");\r
+ AsciiValueToString(Entry + AsciiStrLen(Entry), 0, Index, 0);\r
+ Status = GetStringFromDataFile(\r
+ Context,\r
+ "Head",\r
+ Entry,\r
+ &SectionName\r
+ );\r
+ if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
+ DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
+ CloseIniFile(Context);\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ //\r
+ // The section name of this update has been found.\r
+ // Now looks for all the config data of this update\r
+ //\r
+\r
+ //\r
+ // FileBuid\r
+ //\r
+ Status = GetGuidFromDataFile(\r
+ Context,\r
+ SectionName,\r
+ "FileGuid",\r
+ &FileGuid\r
+ );\r
+ if (EFI_ERROR(Status)) {\r
+ CloseIniFile(Context);\r
+ DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ CopyGuid(&((*RecoveryArray)[Index].FileGuid), &FileGuid);\r
+\r
+ //\r
+ // Length\r
+ //\r
+ Status = GetHexUintnFromDataFile(\r
+ Context,\r
+ SectionName,\r
+ "Length",\r
+ &Num\r
+ );\r
+ if (EFI_ERROR(Status)) {\r
+ CloseIniFile(Context);\r
+ DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ (*RecoveryArray)[Index].Length = Num;\r
+\r
+ //\r
+ // ImageOffset\r
+ //\r
+ Status = GetHexUintnFromDataFile(\r
+ Context,\r
+ SectionName,\r
+ "ImageOffset",\r
+ &Num\r
+ );\r
+ if (EFI_ERROR(Status)) {\r
+ CloseIniFile(Context);\r
+ DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ (*RecoveryArray)[Index].ImageOffset = Num;\r
+ }\r
+\r
+ //\r
+ // Now all configuration data got. Free those temporary buffers\r
+ //\r
+ CloseIniFile(Context);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r