]> git.proxmox.com Git - mirror_edk2.git/blame - SignedCapsulePkg/Universal/RecoveryModuleLoadPei/ParseConfigProfile.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SignedCapsulePkg / Universal / RecoveryModuleLoadPei / ParseConfigProfile.c
CommitLineData
e470ee6d
JY
1/** @file\r
2 Parse the INI configuration file and pass the information to the recovery driver\r
3 so that the driver can perform recovery accordingly.\r
4\r
91db774b 5 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
e470ee6d 6\r
fbf06957 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e470ee6d
JY
8\r
9**/\r
10\r
11#include "RecoveryModuleLoadPei.h"\r
12#include <Library/IniParsingLib.h>\r
13#include <Library/PrintLib.h>\r
14\r
b8786489 15#define MAX_LINE_LENGTH 512\r
e470ee6d
JY
16\r
17/**\r
18 Parse Config data file to get the updated data array.\r
19\r
20 @param[in] DataBuffer Config raw file buffer.\r
21 @param[in] BufferSize Size of raw buffer.\r
22 @param[in, out] ConfigHeader Pointer to the config header.\r
23 @param[in, out] RecoveryArray Pointer to the config of recovery data.\r
24\r
25 @retval EFI_NOT_FOUND No config data is found.\r
26 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.\r
27 @retval EFI_SUCCESS Parse the config file successfully.\r
28\r
29**/\r
30EFI_STATUS\r
31ParseRecoveryDataFile (\r
b8786489
MK
32 IN UINT8 *DataBuffer,\r
33 IN UINTN BufferSize,\r
34 IN OUT CONFIG_HEADER *ConfigHeader,\r
35 IN OUT RECOVERY_CONFIG_DATA **RecoveryArray\r
e470ee6d
JY
36 )\r
37{\r
b8786489
MK
38 EFI_STATUS Status;\r
39 CHAR8 *SectionName;\r
40 CHAR8 Entry[MAX_LINE_LENGTH];\r
41 UINTN Num;\r
42 UINTN Index;\r
43 EFI_GUID FileGuid;\r
44 VOID *Context;\r
e470ee6d
JY
45\r
46 //\r
47 // First process the data buffer and get all sections and entries\r
48 //\r
b8786489 49 Context = OpenIniFile (DataBuffer, BufferSize);\r
e470ee6d
JY
50 if (Context == NULL) {\r
51 return EFI_INVALID_PARAMETER;\r
52 }\r
53\r
54 //\r
55 // Now get NumOfUpdate\r
56 //\r
b8786489 57 Status = GetDecimalUintnFromDataFile (\r
e470ee6d
JY
58 Context,\r
59 "Head",\r
60 "NumOfRecovery",\r
61 &Num\r
62 );\r
b8786489
MK
63 if (EFI_ERROR (Status) || (Num == 0)) {\r
64 DEBUG ((DEBUG_ERROR, "NumOfRecovery not found\n"));\r
65 CloseIniFile (Context);\r
e470ee6d
JY
66 return EFI_NOT_FOUND;\r
67 }\r
68\r
69 ConfigHeader->NumOfRecovery = Num;\r
b8786489 70 *RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num));\r
e470ee6d 71 if (*RecoveryArray == NULL) {\r
b8786489 72 CloseIniFile (Context);\r
e470ee6d
JY
73 return EFI_OUT_OF_RESOURCES;\r
74 }\r
75\r
b8786489 76 for (Index = 0; Index < ConfigHeader->NumOfRecovery; Index++) {\r
e470ee6d
JY
77 //\r
78 // Get the section name of each update\r
79 //\r
80 AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Recovery");\r
91db774b
HW
81 AsciiValueToStringS (\r
82 Entry + AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
83 MAX_LINE_LENGTH - AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
84 0,\r
85 Index,\r
86 0\r
87 );\r
b8786489 88 Status = GetStringFromDataFile (\r
e470ee6d
JY
89 Context,\r
90 "Head",\r
91 Entry,\r
92 &SectionName\r
93 );\r
b8786489
MK
94 if (EFI_ERROR (Status) || (SectionName == NULL)) {\r
95 DEBUG ((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
96 CloseIniFile (Context);\r
e470ee6d
JY
97 return EFI_NOT_FOUND;\r
98 }\r
99\r
100 //\r
101 // The section name of this update has been found.\r
102 // Now looks for all the config data of this update\r
103 //\r
104\r
105 //\r
c38f0816 106 // FileGuid\r
e470ee6d 107 //\r
b8786489 108 Status = GetGuidFromDataFile (\r
e470ee6d
JY
109 Context,\r
110 SectionName,\r
111 "FileGuid",\r
112 &FileGuid\r
113 );\r
b8786489
MK
114 if (EFI_ERROR (Status)) {\r
115 CloseIniFile (Context);\r
116 DEBUG ((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
e470ee6d
JY
117 return EFI_NOT_FOUND;\r
118 }\r
119\r
b8786489 120 CopyGuid (&((*RecoveryArray)[Index].FileGuid), &FileGuid);\r
e470ee6d
JY
121\r
122 //\r
123 // Length\r
124 //\r
b8786489 125 Status = GetHexUintnFromDataFile (\r
e470ee6d
JY
126 Context,\r
127 SectionName,\r
128 "Length",\r
129 &Num\r
130 );\r
b8786489
MK
131 if (EFI_ERROR (Status)) {\r
132 CloseIniFile (Context);\r
133 DEBUG ((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
e470ee6d
JY
134 return EFI_NOT_FOUND;\r
135 }\r
b8786489 136\r
e470ee6d
JY
137 (*RecoveryArray)[Index].Length = Num;\r
138\r
139 //\r
140 // ImageOffset\r
141 //\r
b8786489 142 Status = GetHexUintnFromDataFile (\r
e470ee6d
JY
143 Context,\r
144 SectionName,\r
145 "ImageOffset",\r
146 &Num\r
147 );\r
b8786489
MK
148 if (EFI_ERROR (Status)) {\r
149 CloseIniFile (Context);\r
150 DEBUG ((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
e470ee6d
JY
151 return EFI_NOT_FOUND;\r
152 }\r
b8786489 153\r
e470ee6d
JY
154 (*RecoveryArray)[Index].ImageOffset = Num;\r
155 }\r
156\r
157 //\r
158 // Now all configuration data got. Free those temporary buffers\r
159 //\r
b8786489 160 CloseIniFile (Context);\r
e470ee6d
JY
161\r
162 return EFI_SUCCESS;\r
163}\r