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