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