ArmPkg: only attempt buildin MmCommunicationDxe for AArch64
[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
15#define MAX_LINE_LENGTH 512\r
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
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
36 )\r
37{\r
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
45\r
46 //\r
47 // First process the data buffer and get all sections and entries\r
48 //\r
49 Context = OpenIniFile(DataBuffer, BufferSize);\r
50 if (Context == NULL) {\r
51 return EFI_INVALID_PARAMETER;\r
52 }\r
53\r
54 //\r
55 // Now get NumOfUpdate\r
56 //\r
57 Status = GetDecimalUintnFromDataFile(\r
58 Context,\r
59 "Head",\r
60 "NumOfRecovery",\r
61 &Num\r
62 );\r
63 if (EFI_ERROR(Status) || (Num == 0)) {\r
64 DEBUG((DEBUG_ERROR, "NumOfRecovery not found\n"));\r
65 CloseIniFile(Context);\r
66 return EFI_NOT_FOUND;\r
67 }\r
68\r
69 ConfigHeader->NumOfRecovery = Num;\r
70 *RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num));\r
71 if (*RecoveryArray == NULL) {\r
72 CloseIniFile(Context);\r
73 return EFI_OUT_OF_RESOURCES;\r
74 }\r
75\r
76 for (Index = 0 ; Index < ConfigHeader->NumOfRecovery; Index++) {\r
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
e470ee6d
JY
88 Status = GetStringFromDataFile(\r
89 Context,\r
90 "Head",\r
91 Entry,\r
92 &SectionName\r
93 );\r
94 if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
95 DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
96 CloseIniFile(Context);\r
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
JY
107 //\r
108 Status = GetGuidFromDataFile(\r
109 Context,\r
110 SectionName,\r
111 "FileGuid",\r
112 &FileGuid\r
113 );\r
114 if (EFI_ERROR(Status)) {\r
115 CloseIniFile(Context);\r
116 DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
117 return EFI_NOT_FOUND;\r
118 }\r
119\r
120 CopyGuid(&((*RecoveryArray)[Index].FileGuid), &FileGuid);\r
121\r
122 //\r
123 // Length\r
124 //\r
125 Status = GetHexUintnFromDataFile(\r
126 Context,\r
127 SectionName,\r
128 "Length",\r
129 &Num\r
130 );\r
131 if (EFI_ERROR(Status)) {\r
132 CloseIniFile(Context);\r
133 DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
134 return EFI_NOT_FOUND;\r
135 }\r
136 (*RecoveryArray)[Index].Length = Num;\r
137\r
138 //\r
139 // ImageOffset\r
140 //\r
141 Status = GetHexUintnFromDataFile(\r
142 Context,\r
143 SectionName,\r
144 "ImageOffset",\r
145 &Num\r
146 );\r
147 if (EFI_ERROR(Status)) {\r
148 CloseIniFile(Context);\r
149 DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
150 return EFI_NOT_FOUND;\r
151 }\r
152 (*RecoveryArray)[Index].ImageOffset = Num;\r
153 }\r
154\r
155 //\r
156 // Now all configuration data got. Free those temporary buffers\r
157 //\r
158 CloseIniFile(Context);\r
159\r
160 return EFI_SUCCESS;\r
161}\r
162\r