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