• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Parse the INI configuration file and pass the information to the update driver
3   so that the driver can perform update 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 "SystemFirmwareDxe.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] UpdateArray     Pointer to the config of update 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
ParseUpdateDataFile(IN UINT8 * DataBuffer,IN UINTN BufferSize,IN OUT CONFIG_HEADER * ConfigHeader,IN OUT UPDATE_CONFIG_DATA ** UpdateArray)38 ParseUpdateDataFile (
39   IN      UINT8                         *DataBuffer,
40   IN      UINTN                         BufferSize,
41   IN OUT  CONFIG_HEADER                 *ConfigHeader,
42   IN OUT  UPDATE_CONFIG_DATA            **UpdateArray
43   )
44 {
45   EFI_STATUS                            Status;
46   CHAR8                                 *SectionName;
47   CHAR8                                 Entry[MAX_LINE_LENGTH];
48   UINTN                                 Num;
49   UINT64                                Num64;
50   UINTN                                 Index;
51   EFI_GUID                              FileGuid;
52   VOID                                  *Context;
53 
54   //
55   // First process the data buffer and get all sections and entries
56   //
57   Context = OpenIniFile(DataBuffer, BufferSize);
58   if (Context == NULL) {
59     return EFI_INVALID_PARAMETER;
60   }
61 
62   //
63   // Now get NumOfUpdate
64   //
65   Status = GetDecimalUintnFromDataFile(
66              Context,
67              "Head",
68              "NumOfUpdate",
69              &Num
70              );
71   if (EFI_ERROR(Status) || (Num == 0)) {
72     DEBUG((DEBUG_ERROR, "NumOfUpdate not found\n"));
73     CloseIniFile(Context);
74     return EFI_NOT_FOUND;
75   }
76 
77   ConfigHeader->NumOfUpdates = Num;
78   *UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num));
79   if (*UpdateArray == NULL) {
80     CloseIniFile(Context);
81     return EFI_OUT_OF_RESOURCES;
82   }
83 
84   for (Index = 0 ; Index < ConfigHeader->NumOfUpdates ; Index++) {
85     //
86     // Get the section name of each update
87     //
88     AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Update");
89     AsciiValueToString(Entry + AsciiStrLen(Entry), 0, Index, 0);
90     Status = GetStringFromDataFile(
91                Context,
92                "Head",
93                Entry,
94                &SectionName
95                );
96     if (EFI_ERROR(Status) || (SectionName == NULL)) {
97       DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));
98       CloseIniFile(Context);
99       return EFI_NOT_FOUND;
100     }
101 
102     //
103     // The section name of this update has been found.
104     // Now looks for all the config data of this update
105     //
106     (*UpdateArray)[Index].Index = Index;
107 
108     //
109     // FirmwareType
110     //
111     Status = GetDecimalUintnFromDataFile(
112                Context,
113                SectionName,
114                "FirmwareType",
115                &Num
116                );
117     if (EFI_ERROR(Status)) {
118       CloseIniFile(Context);
119       DEBUG((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));
120       return EFI_NOT_FOUND;
121     }
122     (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE) Num;
123 
124     //
125     // AddressType
126     //
127     Status = GetDecimalUintnFromDataFile(
128                Context,
129                SectionName,
130                "AddressType",
131                &Num
132                );
133     if (EFI_ERROR(Status)) {
134       CloseIniFile(Context);
135       DEBUG((DEBUG_ERROR, "[%d] AddressType not found\n", Index));
136       return EFI_NOT_FOUND;
137     }
138     (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE) Num;
139 
140     //
141     // BaseAddress
142     //
143     Status = GetHexUint64FromDataFile(
144                Context,
145                SectionName,
146                "BaseAddress",
147                &Num64
148                );
149     if (EFI_ERROR(Status)) {
150       CloseIniFile(Context);
151       DEBUG((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));
152       return EFI_NOT_FOUND;
153     }
154     (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num64;
155 
156     //
157     // FileBuid
158     //
159     Status = GetGuidFromDataFile(
160                Context,
161                SectionName,
162                "FileGuid",
163                &FileGuid
164                );
165     if (EFI_ERROR(Status)) {
166       CloseIniFile(Context);
167       DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));
168       return EFI_NOT_FOUND;
169     }
170 
171     CopyGuid(&((*UpdateArray)[Index].FileGuid), &FileGuid);
172 
173     //
174     // Length
175     //
176     Status = GetHexUintnFromDataFile(
177                Context,
178                SectionName,
179                "Length",
180                &Num
181                );
182     if (EFI_ERROR(Status)) {
183       CloseIniFile(Context);
184       DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));
185       return EFI_NOT_FOUND;
186     }
187     (*UpdateArray)[Index].Length = (UINTN) Num;
188 
189     //
190     // ImageOffset
191     //
192     Status = GetHexUintnFromDataFile(
193                Context,
194                SectionName,
195                "ImageOffset",
196                &Num
197                );
198     if (EFI_ERROR(Status)) {
199       CloseIniFile(Context);
200       DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));
201       return EFI_NOT_FOUND;
202     }
203     (*UpdateArray)[Index].ImageOffset = (UINTN) Num;
204   }
205 
206   //
207   // Now all configuration data got. Free those temporary buffers
208   //
209   CloseIniFile(Context);
210 
211   return EFI_SUCCESS;
212 }
213 
214