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