Fix for linux builds
[mirror_edk2.git] / Tools / CCode / Source / GenBsfImage / GenBsfImage.h
1 /*++
2
3 Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
10 Intel Corporation.
11
12
13 Module Name:
14
15 GenBsfImage.h
16
17 Abstract:
18
19 This file contains the relevant declarations required
20 to generate Boot Strap File
21
22 --*/
23
24 //
25 // Module Coded to EFI 2.0 Coding Conventions
26 //
27 #ifndef _EFI_GEN_BSF_IMAGE_H
28 #define _EFI_GEN_BSF_IMAGE_H
29
30 //
31 // External Files Referenced
32 //
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include "assert.h"
37 // #include "TianoCommon.h"
38 #include "Common/FirmwareFileSystem.h"
39 #include "Common/FirmwareVolumeHeader.h"
40 #include "ParseInf.h"
41
42 //
43 // Internal Constants
44 //
45 #define EFI_IPF_VTF1_GUID \
46 { \
47 0xfa371c9b, 0x5a86, 0x4198, 0xab, 0xc2, 0xed, 0x3f, 0xaa, 0xce, 0xb0, 0x8b \
48 };
49
50 #define EFI_IPF_VTF2_GUID \
51 { \
52 0x624a0d5a, 0x315f, 0x40b6, 0xa6, 0x33, 0xe5, 0xf7, 0xde, 0x58, 0x20, 0xa0 \
53 };
54
55 #define EFI_IA32_BOOT_STRAP_GUID \
56 { \
57 0xd4260a8d, 0x356, 0x4f45, 0x85, 0xe9, 0xad, 0x1d, 0x79, 0x22, 0x79, 0xf0 \
58 };
59
60 #define CV_N_TYPE(a,b) (UINT8)(((UINT8)a << 7) + (UINT8)b) // Keeps the CV and Type in same byte field
61 #define MAKE_VERSION(a,b) (UINT16)(((UINT16)a << 8) + (UINT16)b)
62
63 #define FILE_NAME_SIZE 256
64 #define COMPONENT_NAME_SIZE 128
65 #define BSF_INPUT_FILE "BSF.INF"
66 #define BSF_OUTPUT_FILE "Bsf.RAW"
67 #define BSF_SYM_FILE "Bsf.SYM"
68 #define FIT_SIGNATURE "_FIT_ "
69
70 //
71 // This is IA32 seccore
72 //
73 #define COMP_TYPE_SECCORE 0x0F
74
75 //
76 //Fit Type Definition
77 //
78 #define COMP_TYPE_FIT_HEADER 0x00
79 #define COMP_TYPE_FIT_PAL_B 0x01
80
81 //
82 // This is generic PAL_A
83 //
84 #define COMP_TYPE_FIT_PAL_A 0x0F
85 #define COMP_TYPE_FIT_PEICORE 0x10
86 #define COMP_TYPE_FIT_AUTOSCAN 0x30
87 #define COMP_TYPE_FIT_FV_BOOT 0x7E
88
89 //
90 //This is processor Specific PAL_A
91 //
92 #define COMP_TYPE_FIT_PAL_A_SPECIFIC 0x0E
93 #define COMP_TYPE_FIT_UNUSED 0x7F
94
95 #define FIT_TYPE_MASK 0x7F
96 #define CHECKSUM_BIT_MASK 0x80
97
98 //
99 // IPF processor address is cached bit
100 //
101 #define IPF_CACHE_BIT 0x8000000000000000
102
103 //
104 // Size definition to calculate the location from top of address for
105 // each component
106 //
107 #define SIZE_IA32_RESET_VECT 0x10 // 16 Bytes
108 #define SIZE_SALE_ENTRY_POINT 0x08 // 8 Byte
109 #define SIZE_FIT_TABLE_ADD 0x08 // 8 Byte
110 #define SIZE_FIT_TABLE_PAL_A 0x10
111 #define SIZE_RESERVED 0x10
112
113
114 #define SIZE_TO_OFFSET_PAL_A_END (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT + \
115 SIZE_FIT_TABLE_ADD + SIZE_FIT_TABLE_PAL_A + \
116 SIZE_RESERVED)
117 #define SIZE_TO_PAL_A_FIT (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT + \
118 SIZE_FIT_TABLE_ADD + SIZE_FIT_TABLE_PAL_A)
119
120 #define SIZE_OF_PAL_HEADER 0x40 //PAL has 64 byte header
121
122 //
123 // Utility Name
124 //
125 #define UTILITY_NAME "GenBsfImage"
126
127 //
128 // Utility version information
129 //
130 #define UTILITY_MAJOR_VERSION 0
131 #define UTILITY_MINOR_VERSION 0
132 #define UTILITY_DATE __DATE__
133
134 //
135 // The maximum number of arguments accepted from the command line.
136 //
137 #define ONE_BSF_ARGS 5
138 #define TWO_BSF_ARGS 9
139
140 //
141 // The number of IA32 bsf arguments accepted from the command line.
142 //
143 #define IA32_ARGS 3
144
145 #define IA32_SOFT_FIT "IA32BsfAddress.inf"
146
147 //
148 // Internal Data Structure
149 //
150 typedef enum _LOC_TYPE
151 {
152 NONE, // In case there is - INF file
153 FIRST_VTF, // First VTF
154 SECOND_VTF, // Outside BSF
155 } LOC_TYPE;
156
157 typedef struct _PARSED_BSF_INFO {
158 CHAR8 CompName[COMPONENT_NAME_SIZE];
159 LOC_TYPE LocationType;
160 UINT8 CompType;
161 UINT8 MajorVer;
162 UINT8 MinorVer;
163 UINT8 CheckSumRequired;
164 BOOLEAN VersionPresent; // If it is TRUE, then, Version is in INF file
165 BOOLEAN PreferredSize;
166 BOOLEAN PreferredAddress;
167 CHAR8 CompBinName[FILE_NAME_SIZE];
168 CHAR8 CompSymName[FILE_NAME_SIZE];
169 UINTN CompSize;
170 UINT64 CompPreferredAddress;
171 UINT32 Align;
172
173 //
174 // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'
175 // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'
176 // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'
177 // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'
178 //
179 struct _PARSED_BSF_INFO *NextBsfInfo;
180 } PARSED_BSF_INFO;
181
182 #pragma pack (1)
183 typedef struct {
184 UINT64 CompAddress;
185 UINT32 CompSize;
186 UINT16 CompVersion;
187 UINT8 CvAndType;
188 UINT8 CheckSum;
189 } FIT_TABLE;
190 #pragma pack ()
191
192 //
193 // The function that displays general utility information
194 //
195 VOID
196 PrintUtilityInfo (
197 VOID
198 )
199 /*++
200
201 Routine Description:
202
203 Displays the standard utility information to SDTOUT
204
205 Arguments:
206
207 None
208
209 Returns:
210
211 None
212
213 --*/
214 ;
215
216 //
217 // The function that displays the utility usage message.
218 //
219 VOID
220 PrintUsage (
221 VOID
222 )
223 /*++
224
225 Routine Description:
226
227 Displays the utility usage syntax to STDOUT
228
229 Arguments:
230
231 None
232
233 Returns:
234
235 None
236
237 --*/
238 ;
239
240 //
241 // Other Function Prototype Declarations
242 //
243
244 EFI_STATUS
245 UpdateBsfBuffer(
246 IN UINT64 StartAddress,
247 IN UINT8 *Buffer,
248 IN UINT64 DataSize,
249 IN LOC_TYPE LocType
250 )
251 /*++
252
253 Routine Description:
254
255 Update the Firmware Volume Buffer with requested buffer data
256
257 Arguments:
258
259 StartAddress - StartAddress in buffer. This number will automatically
260 point to right address in buffer where data needed
261 to be updated.
262 Buffer - Buffer pointer from data will be copied to memory mapped buffer.
263 DataSize - Size of the data needed to be copied.
264 LocType - The type of the BSF
265
266 Returns:
267
268 EFI_ABORTED - The input parameter is error
269 EFI_SUCCESS - The function completed successfully
270
271 --*/
272 ;
273
274 EFI_STATUS
275 UpdateSymFile (
276 IN UINT64 BaseAddress,
277 IN CHAR8 *DestFileName,
278 IN CHAR8 *SourceFileName
279 )
280 /*++
281
282 Routine Description:
283
284 This function adds the SYM tokens in the source file to the destination file.
285 The SYM tokens are updated to reflect the base address.
286
287 Arguments:
288
289 BaseAddress - The base address for the new SYM tokens.
290 DestFileName - The destination file.
291 SourceFileName - The source file.
292
293 Returns:
294
295 EFI_SUCCESS - The function completed successfully.
296 EFI_INVALID_PARAMETER - One of the input parameters was invalid.
297 EFI_ABORTED - An error occurred.
298
299 --*/
300 ;
301
302 EFI_STATUS
303 CalculateFitTableChecksum (
304 VOID
305 )
306 /*++
307
308 Routine Description:
309
310 This function will perform byte checksum on the FIT table, if the the checksum required
311 field is set to CheckSum required. If the checksum is not required then checksum byte
312 will have value as 0;.
313
314 Arguments:
315
316 NONE
317
318 Returns:
319
320 Status - Value returned by call to CalculateChecksum8 ()
321 EFI_SUCCESS - The function completed successfully
322
323 --*/
324 ;
325
326 EFI_STATUS
327 GenerateBsfImage (
328 IN UINT64 StartAddress1,
329 IN UINT64 Size1,
330 IN UINT64 StartAddress2,
331 IN UINT64 Size2
332 )
333 /*++
334
335 Routine Description:
336
337 This is the main function which will be called from application.
338
339 Arguments:
340
341 StartAddress1 - The start address of the first BSF
342 Size1 - The size of the first BSF
343 StartAddress2 - The start address of the second BSF
344 Size2 - The size of the second BSF
345
346 Returns:
347
348 EFI_OUT_OF_RESOURCES - Can not allocate memory
349 The return value can be any of the values
350 returned by the calls to following functions:
351 GetBsfRelatedInfoFromInfFile
352 ProcessAndCreateBsf
353 UpdateIA32ResetVector
354 UpdateFfsHeader
355 WriteBsfBinary
356
357 --*/
358 ;
359
360 EFI_STATUS
361 PeimFixupInFitTable (
362 IN UINT64 StartAddress
363 )
364 /*++
365
366 Routine Description:
367
368 This function is an entry point to fixup SAL-E entry point.
369
370 Arguments:
371
372 StartAddress - StartAddress for PEIM.....
373
374 Returns:
375
376 EFI_SUCCESS - The function completed successfully
377 EFI_ABORTED - Error Opening File
378
379 --*/
380 ;
381
382 EFI_STATUS
383 Generate32BsfImage (
384 IN UINT64 BootFileStartAddress
385 )
386 /*++
387
388 Routine Description:
389
390 This is the main IA32 function which will be called from application.
391 (Now this tool is not used for IA32 platform, if it will be used in future,
392 the relative functions need to be updated, the updating can refer to IPF
393 functions)
394
395 Arguments:
396
397 BootFileStartAddress - Top Address of Boot File
398
399 Returns:
400
401 The return value can be any of the values
402 returned by the calls to following functions:
403 Get32BsfRelatedInfoFromInfFile
404 CreateBsfBuffer
405 ProcessAndCreate32Bsf
406 Update32FfsHeader
407 WriteBsfBinary
408
409 --*/
410 ;
411
412 EFI_STATUS
413 GetTotal32BsfSize(
414 IN UINT32 *BsfSize
415 )
416 /*++
417
418 Routine Description:
419
420 This function calculates total size for IA32 BSF which would be needed to create
421 the buffer. This will be done using Passed Info link list and looking for the
422 size of the components which belong to BSF. The addtional file header is accounted.
423
424 Arguments:
425
426 BSFSize - Pointer to the size of IA32 BSF
427
428 Returns:
429
430 EFI_ABORTED - Returned due to one of the following resons:
431 (a) Error Opening File
432 EFI_SUCCESS - The fuction completes successfully
433
434 --*/
435 ;
436
437 EFI_STATUS
438 ProcessAndCreate32Bsf (
439 IN UINT64 Size
440 )
441 /*++
442
443 Routine Description:
444
445 This function process the link list created during INF file parsing
446 and create component in IA32 BSF
447
448 Arguments:
449
450 Size - Size of the Firmware Volume of which, this BSF belongs to.
451
452 Returns:
453
454 EFI_UNSUPPORTED - Unknown component type
455 EFI_SUCCESS - The function completed successfully
456
457 --*/
458 ;
459
460 EFI_STATUS
461 CreateAndUpdateSeccore (
462 IN PARSED_BSF_INFO *BsfInfo
463 )
464 /*++
465
466 Routine Description:
467
468 This function reads the binary file for seccore and update them
469 in IA32 BSF Buffer
470
471 Arguments:
472
473 BsfInfo - Pointer to Parsed Info
474
475 Returns:
476
477 EFI_ABORTED - Due to one of the following reasons:
478 (a)Error Opening File
479 (b)The PAL_A Size is more than specified size status
480 One of the values mentioned below returned from
481 call to UpdateSymFile
482 EFI_SUCCESS - The function completed successfully.
483 EFI_INVALID_PARAMETER - One of the input parameters was invalid.
484 EFI_ABORTED - An error occurred.UpdateSymFile
485
486 --*/
487 ;
488
489 EFI_STATUS
490 CreateAndUpdate32Component (
491 IN PARSED_BSF_INFO *BsfInfo
492 )
493 /*++
494
495 Routine Description:
496
497 This function reads the binary file for each components. Add it at aligned address.
498
499 Arguments:
500
501 BsfInfo - Pointer to Parsed Info
502
503 Returns:
504
505 EFI_SUCCESS - The function completed successful
506 EFI_ABORTED - Aborted due to one of the many reasons like:
507 (a) Component Size greater than the specified size.
508 (b) Error opening files.
509 EFI_INVALID_PARAMETER - Value returned from call to UpdateEntryPoint()
510
511 --*/
512 ;
513
514 EFI_STATUS
515 Update32FfsHeader(
516 IN UINT32 BsfSize
517 )
518 /*++
519
520 Routine Description:
521
522 Update the Firmware Volume Buffer with requested buffer data
523
524 Arguments:
525
526 BsfSize - Size of the IA32 BSF
527
528 Returns:
529
530 EFI_SUCCESS - The function completed successfully
531 EFI_INVALID_PARAMETER - The Ffs File Header Pointer is NULL
532
533 --*/
534 ;
535
536 EFI_STATUS
537 Get32BsfRelatedInfoFromInfFile (
538 IN CHAR8 *FileName
539 )
540 /*++
541
542 Routine Description:
543
544 This function reads the input file, parse it and create a list of tokens
545 which is parsed and used, to intialize the data related to IA32 BSF
546
547 Arguments:
548
549 FileName FileName which needed to be read to parse data
550
551 Returns:
552
553 EFI_ABORTED Error in opening file
554 EFI_INVALID_PARAMETER File doesn't contain any valid informations
555 EFI_OUT_OF_RESOURCES Malloc Failed
556 EFI_SUCCESS The function completed successfully
557
558 --*/
559 ;
560
561 VOID
562 Initialize32InFileInfo (
563 VOID
564 )
565 /*++
566
567 Routine Description:
568
569 This function intializes the relevant global variable which is being
570 used to store the information retrieved from IA32 INF file.
571
572 Arguments:
573
574 NONE
575
576 Returns:
577
578 NONE
579
580 --*/
581 ;
582
583 VOID
584 ParseAndUpdate32Components (
585 IN PARSED_BSF_INFO *BsfInfo
586 )
587 /*++
588
589 Routine Description:
590
591 This function intializes the relevant global variable which is being
592 used to store the information retrieved from INF file.
593
594 Arguments:
595
596 BsfInfo - A pointer to the BSF Info Structure
597
598
599 Returns:
600
601 None
602
603 --*/
604 ;
605
606 EFI_STATUS
607 Write32SoftFit(
608 IN CHAR8 *FileName,
609 IN PARSED_BSF_INFO *BsfInfo
610 )
611 /*++
612
613 Routine Description:
614
615 Write IA32 Firmware Volume component address from memory to a file.
616
617 Arguments:
618
619 FileName Output File Name which needed to be created/
620 BsfInfo Parsed info link
621
622 Returns:
623
624 EFI_ABORTED - Returned due to one of the following resons:
625 (a) Error Opening File
626 (b) Failing to copy buffers
627 EFI_SUCCESS - The fuction completes successfully
628
629 --*/
630 ;
631
632 #endif