1 /** @file
2 This file contains the relevant declarations required to generate Boot Strap File
3 
4 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 //
16 // Module Coded to EFI 2.0 Coding Conventions
17 //
18 #ifndef   __GEN_VTF_H__
19 #define   __GEN_VTF_H__
20 
21 //
22 // External Files Referenced
23 //
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #ifndef __GNUC__
28 #include <io.h>
29 #endif
30 #include "assert.h"
31 #include <Common/PiFirmwareFile.h>
32 #include "ParseInf.h"
33 
34 //
35 // Internal Constants
36 //
37 #define CV_N_TYPE(a,b)            (UINT8)(((UINT8)a << 7) + (UINT8)b)  // Keeps the CV and Type in same byte field
38 #define MAKE_VERSION(a,b)         (UINT16)(((UINT16)a << 8) + (UINT16)b)
39 
40 #define   FILE_NAME_SIZE          256
41 #define   COMPONENT_NAME_SIZE     128
42 #define   VTF_INPUT_FILE          "VTF.INF"
43 #define   VTF_OUTPUT_FILE1        "VTF1.RAW"
44 #define   VTF_OUTPUT_FILE2        "VTF2.RAW"
45 #define   VTF_SYM_FILE            "Vtf.SYM"
46 #define   FIT_SIGNATURE           "_FIT_   "
47 
48 //
49 //Fit Type Definition
50 //
51 #define   COMP_TYPE_FIT_HEADER          0x00
52 #define   COMP_TYPE_FIT_PAL_B           0x01
53 
54 //
55 // This is generic PAL_A
56 //
57 #define   COMP_TYPE_FIT_PAL_A           0x0F
58 #define   COMP_TYPE_FIT_PEICORE         0x10
59 #define   COMP_TYPE_FIT_AUTOSCAN        0x30
60 #define   COMP_TYPE_FIT_FV_BOOT         0x7E
61 
62 //
63 //This is processor Specific PAL_A
64 //
65 #define   COMP_TYPE_FIT_PAL_A_SPECIFIC  0x0E
66 #define   COMP_TYPE_FIT_UNUSED    0x7F
67 
68 #define   FIT_TYPE_MASK           0x7F
69 #define   CHECKSUM_BIT_MASK       0x80
70 
71 //
72 // IPF processor address is cached bit
73 //
74 #define IPF_CACHE_BIT 0x8000000000000000ULL
75 
76 //
77 // Size definition to calculate the location from top of address for
78 // each component
79 //
80 #define SIZE_IA32_RESET_VECT      0x10        // 16 Bytes
81 #define SIZE_SALE_ENTRY_POINT     0x08        // 8 Byte
82 #define SIZE_FIT_TABLE_ADD        0x08        // 8 Byte
83 #define SIZE_FIT_TABLE_PAL_A      0x10
84 #define SIZE_RESERVED             0x10
85 
86 
87 #define SIZE_TO_OFFSET_PAL_A_END  (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT + \
88                                   SIZE_FIT_TABLE_ADD + SIZE_FIT_TABLE_PAL_A + \
89                                   SIZE_RESERVED)
90 #define SIZE_TO_PAL_A_FIT         (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT + \
91                                   SIZE_FIT_TABLE_ADD + SIZE_FIT_TABLE_PAL_A)
92 
93 #define SIZE_OF_PAL_HEADER        0x40        //PAL has 64 byte header
94 
95 //
96 // Utility Name
97 //
98 #define UTILITY_NAME  "GenVtf"
99 
100 //
101 // Utility version information
102 //
103 #define UTILITY_MAJOR_VERSION   0
104 #define UTILITY_MINOR_VERSION   1
105 #define UTILITY_DATE            __DATE__
106 
107 //
108 // The maximum number of arguments accepted from the command line.
109 //
110 #define ONE_VTF_ARGS  10
111 #define TWO_VTF_ARGS  12
112 #define THREE_VTF_ARGS  16
113 
114 static BOOLEAN VerboseMode = FALSE;
115 
116 //
117 // Internal Data Structure
118 //
119 typedef enum _LOC_TYPE
120 {
121   NONE,                   // In case there is - INF file
122   FIRST_VTF,              // First VTF
123   SECOND_VTF,             // Outside VTF
124 } LOC_TYPE;
125 
126 typedef struct _PARSED_VTF_INFO {
127   CHAR8       CompName[COMPONENT_NAME_SIZE];
128   LOC_TYPE    LocationType;
129   UINT8       CompType;
130   UINT8       MajorVer;
131   UINT8       MinorVer;
132   UINT8       CheckSumRequired;
133   BOOLEAN     VersionPresent;                // If it is TRUE, then, Version is in INF file
134   BOOLEAN     PreferredSize;
135   BOOLEAN     PreferredAddress;
136   CHAR8       CompBinName[FILE_NAME_SIZE];
137   CHAR8       CompSymName[FILE_NAME_SIZE];
138   UINTN       CompSize;
139   UINT64      CompPreferredAddress;
140   UINT32      Align;
141 
142   //
143   //  Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedVtfInfo *' to 'struct _PARSED_VTF_INFO *'
144   //  Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedVtfInfo *' to 'struct _PARSED_VTF_INFO *'
145   //  Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedVtfInfo *' to 'struct _PARSED_VTF_INFO *'
146   //  Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedVtfInfo *' to 'struct _PARSED_VTF_INFO *'
147   //
148   struct      _PARSED_VTF_INFO   *NextVtfInfo;
149 } PARSED_VTF_INFO;
150 
151 #pragma pack (1)
152 typedef struct {
153   UINT64      CompAddress;
154   UINT32      CompSize;
155   UINT16      CompVersion;
156   UINT8       CvAndType;
157   UINT8       CheckSum;
158 } FIT_TABLE;
159 #pragma pack ()
160 
161 //
162 // Function Prototype Declarations
163 //
164 
165 EFI_STATUS
166 UpdateVtfBuffer(
167   IN  UINT64    StartAddress,
168   IN  UINT8     *Buffer,
169   IN  UINT64    DataSize,
170   IN  LOC_TYPE  LocType
171   )
172 /*++
173 
174 Routine Description:
175 
176   Update the Firmware Volume Buffer with requested buffer data
177 
178 Arguments:
179 
180   StartAddress   - StartAddress in buffer. This number will automatically
181                   point to right address in buffer where data needed
182                   to be updated.
183   Buffer         - Buffer pointer from data will be copied to memory mapped buffer.
184   DataSize       - Size of the data needed to be copied.
185   LocType        - The type of the VTF
186 
187 Returns:
188 
189   EFI_ABORTED  - The input parameter is error
190   EFI_SUCCESS  - The function completed successfully
191 
192 --*/
193 ;
194 
195 EFI_STATUS
196 UpdateSymFile (
197   IN UINT64 BaseAddress,
198   IN CHAR8  *DestFileName,
199   IN CHAR8  *SourceFileName,
200   IN UINT64 FileSize
201   )
202 /*++
203 
204 Routine Description:
205 
206   This function adds the SYM tokens in the source file to the destination file.
207   The SYM tokens are updated to reflect the base address.
208 
209 Arguments:
210 
211   BaseAddress    - The base address for the new SYM tokens.
212   DestFileName   - The destination file.
213   SourceFileName - The source file.
214   FileSize       - Size of bin file.
215 
216 Returns:
217 
218   EFI_SUCCESS             - The function completed successfully.
219   EFI_INVALID_PARAMETER   - One of the input parameters was invalid.
220   EFI_ABORTED             - An error occurred.
221 
222 --*/
223 ;
224 
225 EFI_STATUS
226 CalculateFitTableChecksum (
227   VOID
228   )
229 /*++
230 
231 Routine Description:
232 
233   This function will perform byte checksum on the FIT table, if the the checksum required
234   field is set to CheckSum required. If the checksum is not required then checksum byte
235   will have value as 0;.
236 
237 Arguments:
238 
239   NONE
240 
241 Returns:
242 
243   Status       - Value returned by call to CalculateChecksum8 ()
244   EFI_SUCCESS  - The function completed successfully
245 
246 --*/
247 ;
248 
249 EFI_STATUS
250 GenerateVtfImage (
251   IN  UINT64  StartAddress1,
252   IN  UINT64  Size1,
253   IN  UINT64  StartAddress2,
254   IN  UINT64  Size2,
255   IN  FILE    *fp
256   )
257 /*++
258 
259 Routine Description:
260 
261   This is the main function which will be called from application.
262 
263 Arguments:
264 
265   StartAddress1  - The start address of the first VTF
266   Size1          - The size of the first VTF
267   StartAddress2  - The start address of the second VTF
268   Size2          - The size of the second VTF
269 
270 Returns:
271 
272   EFI_OUT_OF_RESOURCES - Can not allocate memory
273   The return value can be any of the values
274   returned by the calls to following functions:
275       GetVtfRelatedInfoFromInfFile
276       ProcessAndCreateVtf
277       UpdateIA32ResetVector
278       UpdateFfsHeader
279       WriteVtfBinary
280 
281 --*/
282 ;
283 
284 EFI_STATUS
285 PeimFixupInFitTable (
286   IN  UINT64  StartAddress
287   )
288 /*++
289 
290 Routine Description:
291 
292   This function is an entry point to fixup SAL-E entry point.
293 
294 Arguments:
295 
296   StartAddress - StartAddress for PEIM.....
297 
298 Returns:
299 
300   EFI_SUCCESS   - The function completed successfully
301   EFI_ABORTED   - Error Opening File
302 
303 --*/
304 ;
305 
306 VOID
307 Usage (
308   VOID
309   )
310 /*++
311 
312 Routine Description:
313 
314   Displays the utility usage syntax to STDOUT
315 
316 Arguments:
317 
318   None
319 
320 Returns:
321 
322   None
323 
324 --*/
325 ;
326 #endif
327