]> git.proxmox.com Git - mirror_edk2.git/blame - SignedCapsulePkg/Universal/RecoveryModuleLoadPei/ParseConfigProfile.c
Nt32Pkg: 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
5 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
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
88 AsciiValueToString(Entry + AsciiStrLen(Entry), 0, Index, 0);\r
89 Status = GetStringFromDataFile(\r
90 Context,\r
91 "Head",\r
92 Entry,\r
93 &SectionName\r
94 );\r
95 if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
96 DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
97 CloseIniFile(Context);\r
98 return EFI_NOT_FOUND;\r
99 }\r
100\r
101 //\r
102 // The section name of this update has been found.\r
103 // Now looks for all the config data of this update\r
104 //\r
105\r
106 //\r
107 // FileBuid\r
108 //\r
109 Status = GetGuidFromDataFile(\r
110 Context,\r
111 SectionName,\r
112 "FileGuid",\r
113 &FileGuid\r
114 );\r
115 if (EFI_ERROR(Status)) {\r
116 CloseIniFile(Context);\r
117 DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
118 return EFI_NOT_FOUND;\r
119 }\r
120\r
121 CopyGuid(&((*RecoveryArray)[Index].FileGuid), &FileGuid);\r
122\r
123 //\r
124 // Length\r
125 //\r
126 Status = GetHexUintnFromDataFile(\r
127 Context,\r
128 SectionName,\r
129 "Length",\r
130 &Num\r
131 );\r
132 if (EFI_ERROR(Status)) {\r
133 CloseIniFile(Context);\r
134 DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
135 return EFI_NOT_FOUND;\r
136 }\r
137 (*RecoveryArray)[Index].Length = Num;\r
138\r
139 //\r
140 // ImageOffset\r
141 //\r
142 Status = GetHexUintnFromDataFile(\r
143 Context,\r
144 SectionName,\r
145 "ImageOffset",\r
146 &Num\r
147 );\r
148 if (EFI_ERROR(Status)) {\r
149 CloseIniFile(Context);\r
150 DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
151 return EFI_NOT_FOUND;\r
152 }\r
153 (*RecoveryArray)[Index].ImageOffset = Num;\r
154 }\r
155\r
156 //\r
157 // Now all configuration data got. Free those temporary buffers\r
158 //\r
159 CloseIniFile(Context);\r
160\r
161 return EFI_SUCCESS;\r
162}\r
163\r