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