SignedCapsulePkg: Replace [Ascii|Unicode]ValueToString
[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
JY
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions\r
9 of the BSD License which accompanies this distribution. The\r
10 full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include "RecoveryModuleLoadPei.h"\r
19#include <Library/IniParsingLib.h>\r
20#include <Library/PrintLib.h>\r
21\r
22#define MAX_LINE_LENGTH 512\r
23\r
24/**\r
25 Parse Config data file to get the updated data array.\r
26\r
27 @param[in] DataBuffer Config raw file buffer.\r
28 @param[in] BufferSize Size of raw buffer.\r
29 @param[in, out] ConfigHeader Pointer to the config header.\r
30 @param[in, out] RecoveryArray Pointer to the config of recovery data.\r
31\r
32 @retval EFI_NOT_FOUND No config data is found.\r
33 @retval EFI_OUT_OF_RESOURCES No enough memory is allocated.\r
34 @retval EFI_SUCCESS Parse the config file successfully.\r
35\r
36**/\r
37EFI_STATUS\r
38ParseRecoveryDataFile (\r
39 IN UINT8 *DataBuffer,\r
40 IN UINTN BufferSize,\r
41 IN OUT CONFIG_HEADER *ConfigHeader,\r
42 IN OUT RECOVERY_CONFIG_DATA **RecoveryArray\r
43 )\r
44{\r
45 EFI_STATUS Status;\r
46 CHAR8 *SectionName;\r
47 CHAR8 Entry[MAX_LINE_LENGTH];\r
48 UINTN Num;\r
49 UINTN Index;\r
50 EFI_GUID FileGuid;\r
51 VOID *Context;\r
52\r
53 //\r
54 // First process the data buffer and get all sections and entries\r
55 //\r
56 Context = OpenIniFile(DataBuffer, BufferSize);\r
57 if (Context == NULL) {\r
58 return EFI_INVALID_PARAMETER;\r
59 }\r
60\r
61 //\r
62 // Now get NumOfUpdate\r
63 //\r
64 Status = GetDecimalUintnFromDataFile(\r
65 Context,\r
66 "Head",\r
67 "NumOfRecovery",\r
68 &Num\r
69 );\r
70 if (EFI_ERROR(Status) || (Num == 0)) {\r
71 DEBUG((DEBUG_ERROR, "NumOfRecovery not found\n"));\r
72 CloseIniFile(Context);\r
73 return EFI_NOT_FOUND;\r
74 }\r
75\r
76 ConfigHeader->NumOfRecovery = Num;\r
77 *RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num));\r
78 if (*RecoveryArray == NULL) {\r
79 CloseIniFile(Context);\r
80 return EFI_OUT_OF_RESOURCES;\r
81 }\r
82\r
83 for (Index = 0 ; Index < ConfigHeader->NumOfRecovery; Index++) {\r
84 //\r
85 // Get the section name of each update\r
86 //\r
87 AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Recovery");\r
91db774b
HW
88 AsciiValueToStringS (\r
89 Entry + AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
90 MAX_LINE_LENGTH - AsciiStrnLenS (Entry, MAX_LINE_LENGTH),\r
91 0,\r
92 Index,\r
93 0\r
94 );\r
e470ee6d
JY
95 Status = GetStringFromDataFile(\r
96 Context,\r
97 "Head",\r
98 Entry,\r
99 &SectionName\r
100 );\r
101 if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
102 DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
103 CloseIniFile(Context);\r
104 return EFI_NOT_FOUND;\r
105 }\r
106\r
107 //\r
108 // The section name of this update has been found.\r
109 // Now looks for all the config data of this update\r
110 //\r
111\r
112 //\r
113 // FileBuid\r
114 //\r
115 Status = GetGuidFromDataFile(\r
116 Context,\r
117 SectionName,\r
118 "FileGuid",\r
119 &FileGuid\r
120 );\r
121 if (EFI_ERROR(Status)) {\r
122 CloseIniFile(Context);\r
123 DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
124 return EFI_NOT_FOUND;\r
125 }\r
126\r
127 CopyGuid(&((*RecoveryArray)[Index].FileGuid), &FileGuid);\r
128\r
129 //\r
130 // Length\r
131 //\r
132 Status = GetHexUintnFromDataFile(\r
133 Context,\r
134 SectionName,\r
135 "Length",\r
136 &Num\r
137 );\r
138 if (EFI_ERROR(Status)) {\r
139 CloseIniFile(Context);\r
140 DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
141 return EFI_NOT_FOUND;\r
142 }\r
143 (*RecoveryArray)[Index].Length = Num;\r
144\r
145 //\r
146 // ImageOffset\r
147 //\r
148 Status = GetHexUintnFromDataFile(\r
149 Context,\r
150 SectionName,\r
151 "ImageOffset",\r
152 &Num\r
153 );\r
154 if (EFI_ERROR(Status)) {\r
155 CloseIniFile(Context);\r
156 DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
157 return EFI_NOT_FOUND;\r
158 }\r
159 (*RecoveryArray)[Index].ImageOffset = Num;\r
160 }\r
161\r
162 //\r
163 // Now all configuration data got. Free those temporary buffers\r
164 //\r
165 CloseIniFile(Context);\r
166\r
167 return EFI_SUCCESS;\r
168}\r
169\r