--- /dev/null
+/*++\r
+\r
+Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name: \r
+\r
+ GenBsfImage.h\r
+\r
+Abstract:\r
+\r
+ This file contains the relevant declarations required\r
+ to generate Boot Strap File\r
+\r
+--*/\r
+\r
+//\r
+// Module Coded to EFI 2.0 Coding Conventions\r
+//\r
+#ifndef _EFI_GEN_BSF_IMAGE_H\r
+#define _EFI_GEN_BSF_IMAGE_H\r
+\r
+//\r
+// External Files Referenced\r
+//\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <io.h>\r
+#include "assert.h"\r
+// #include "TianoCommon.h"\r
+#include "Common/FirmwareFileSystem.h"\r
+#include "Common/FirmwareVolumeHeader.h"\r
+#include "ParseInf.h"\r
+\r
+//\r
+// Internal Constants\r
+//\r
+#define EFI_IPF_VTF1_GUID \\r
+ { \\r
+ 0xfa371c9b, 0x5a86, 0x4198, 0xab, 0xc2, 0xed, 0x3f, 0xaa, 0xce, 0xb0, 0x8b \\r
+ };\r
+\r
+#define EFI_IPF_VTF2_GUID \\r
+ { \\r
+ 0x624a0d5a, 0x315f, 0x40b6, 0xa6, 0x33, 0xe5, 0xf7, 0xde, 0x58, 0x20, 0xa0 \\r
+ };\r
+\r
+#define EFI_IA32_BOOT_STRAP_GUID \\r
+ { \\r
+ 0xd4260a8d, 0x356, 0x4f45, 0x85, 0xe9, 0xad, 0x1d, 0x79, 0x22, 0x79, 0xf0 \\r
+ };\r
+\r
+#define CV_N_TYPE(a,b) (UINT8)(((UINT8)a << 7) + (UINT8)b) // Keeps the CV and Type in same byte field\r
+#define MAKE_VERSION(a,b) (UINT16)(((UINT16)a << 8) + (UINT16)b)\r
+\r
+#define FILE_NAME_SIZE 256\r
+#define COMPONENT_NAME_SIZE 128\r
+#define BSF_INPUT_FILE "BSF.INF"\r
+#define BSF_OUTPUT_FILE "Bsf.RAW"\r
+#define BSF_SYM_FILE "Bsf.SYM"\r
+#define FIT_SIGNATURE "_FIT_ "\r
+\r
+//\r
+// This is IA32 seccore\r
+//\r
+#define COMP_TYPE_SECCORE 0x0F\r
+\r
+//\r
+//Fit Type Definition\r
+//\r
+#define COMP_TYPE_FIT_HEADER 0x00\r
+#define COMP_TYPE_FIT_PAL_B 0x01\r
+\r
+//\r
+// This is generic PAL_A\r
+//\r
+#define COMP_TYPE_FIT_PAL_A 0x0F\r
+#define COMP_TYPE_FIT_PEICORE 0x10\r
+#define COMP_TYPE_FIT_AUTOSCAN 0x30\r
+#define COMP_TYPE_FIT_FV_BOOT 0x7E\r
+\r
+//\r
+//This is processor Specific PAL_A\r
+//\r
+#define COMP_TYPE_FIT_PAL_A_SPECIFIC 0x0E\r
+#define COMP_TYPE_FIT_UNUSED 0x7F\r
+\r
+#define FIT_TYPE_MASK 0x7F\r
+#define CHECKSUM_BIT_MASK 0x80\r
+\r
+//\r
+// IPF processor address is cached bit\r
+//\r
+#define IPF_CACHE_BIT 0x8000000000000000\r
+\r
+//\r
+// Size definition to calculate the location from top of address for\r
+// each component\r
+//\r
+#define SIZE_IA32_RESET_VECT 0x10 // 16 Bytes\r
+#define SIZE_SALE_ENTRY_POINT 0x08 // 8 Byte\r
+#define SIZE_FIT_TABLE_ADD 0x08 // 8 Byte\r
+#define SIZE_FIT_TABLE_PAL_A 0x10 \r
+#define SIZE_RESERVED 0x10\r
+\r
+\r
+#define SIZE_TO_OFFSET_PAL_A_END (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT + \\r
+ SIZE_FIT_TABLE_ADD + SIZE_FIT_TABLE_PAL_A + \\r
+ SIZE_RESERVED)\r
+#define SIZE_TO_PAL_A_FIT (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT + \\r
+ SIZE_FIT_TABLE_ADD + SIZE_FIT_TABLE_PAL_A)\r
+\r
+#define SIZE_OF_PAL_HEADER 0x40 //PAL has 64 byte header\r
+\r
+//\r
+// Utility Name\r
+//\r
+#define UTILITY_NAME "GenBsfImage"\r
+\r
+//\r
+// Utility version information\r
+//\r
+#define UTILITY_MAJOR_VERSION 0\r
+#define UTILITY_MINOR_VERSION 0\r
+#define UTILITY_DATE __DATE__\r
+\r
+//\r
+// The maximum number of arguments accepted from the command line.\r
+//\r
+#define ONE_BSF_ARGS 5\r
+#define TWO_BSF_ARGS 9\r
+\r
+//\r
+// The number of IA32 bsf arguments accepted from the command line.\r
+//\r
+#define IA32_ARGS 3\r
+\r
+#define IA32_SOFT_FIT "IA32BsfAddress.inf"\r
+\r
+//\r
+// Internal Data Structure\r
+//\r
+typedef enum _LOC_TYPE \r
+{\r
+ NONE, // In case there is - INF file\r
+ FIRST_VTF, // First VTF\r
+ SECOND_VTF, // Outside BSF\r
+} LOC_TYPE;\r
+\r
+typedef struct _PARSED_BSF_INFO {\r
+ CHAR8 CompName[COMPONENT_NAME_SIZE];\r
+ LOC_TYPE LocationType;\r
+ UINT8 CompType;\r
+ UINT8 MajorVer;\r
+ UINT8 MinorVer;\r
+ UINT8 CheckSumRequired;\r
+ BOOLEAN VersionPresent; // If it is TRUE, then, Version is in INF file\r
+ BOOLEAN PreferredSize;\r
+ BOOLEAN PreferredAddress;\r
+ CHAR8 CompBinName[FILE_NAME_SIZE];\r
+ CHAR8 CompSymName[FILE_NAME_SIZE];\r
+ UINTN CompSize;\r
+ UINT64 CompPreferredAddress;\r
+ UINT32 Align;\r
+\r
+ //\r
+ // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'\r
+ // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'\r
+ // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'\r
+ // Fixed - warning C4133: '=' : incompatible types - from 'struct _ParsedBsfInfo *' to 'struct _PARSED_BSF_INFO *'\r
+ //\r
+ struct _PARSED_BSF_INFO *NextBsfInfo;\r
+} PARSED_BSF_INFO;\r
+\r
+#pragma pack (1)\r
+typedef struct {\r
+ UINT64 CompAddress;\r
+ UINT32 CompSize;\r
+ UINT16 CompVersion;\r
+ UINT8 CvAndType;\r
+ UINT8 CheckSum;\r
+} FIT_TABLE;\r
+#pragma pack ()\r
+\r
+//\r
+// The function that displays general utility information\r
+//\r
+VOID\r
+PrintUtilityInfo (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Displays the standard utility information to SDTOUT\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// The function that displays the utility usage message.\r
+//\r
+VOID\r
+PrintUsage (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Displays the utility usage syntax to STDOUT\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Other Function Prototype Declarations\r
+//\r
+\r
+EFI_STATUS\r
+UpdateBsfBuffer(\r
+ IN UINT64 StartAddress,\r
+ IN UINT8 *Buffer,\r
+ IN UINT64 DataSize,\r
+ IN LOC_TYPE LocType\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Update the Firmware Volume Buffer with requested buffer data\r
+ \r
+Arguments:\r
+\r
+ StartAddress - StartAddress in buffer. This number will automatically\r
+ point to right address in buffer where data needed \r
+ to be updated.\r
+ Buffer - Buffer pointer from data will be copied to memory mapped buffer.\r
+ DataSize - Size of the data needed to be copied.\r
+ LocType - The type of the BSF\r
+\r
+Returns:\r
+ \r
+ EFI_ABORTED - The input parameter is error\r
+ EFI_SUCCESS - The function completed successfully\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+UpdateSymFile (\r
+ IN UINT64 BaseAddress,\r
+ IN CHAR8 *DestFileName,\r
+ IN CHAR8 *SourceFileName\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This function adds the SYM tokens in the source file to the destination file.\r
+ The SYM tokens are updated to reflect the base address.\r
+\r
+Arguments:\r
+\r
+ BaseAddress - The base address for the new SYM tokens.\r
+ DestFileName - The destination file.\r
+ SourceFileName - The source file.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - The function completed successfully.\r
+ EFI_INVALID_PARAMETER - One of the input parameters was invalid.\r
+ EFI_ABORTED - An error occurred.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+CalculateFitTableChecksum (\r
+ VOID\r
+ )\r
+/*++\r
+ \r
+Routine Description:\r
+\r
+ This function will perform byte checksum on the FIT table, if the the checksum required\r
+ field is set to CheckSum required. If the checksum is not required then checksum byte\r
+ will have value as 0;.\r
+ \r
+Arguments:\r
+\r
+ NONE\r
+ \r
+Returns:\r
+\r
+ Status - Value returned by call to CalculateChecksum8 ()\r
+ EFI_SUCCESS - The function completed successfully\r
+ \r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+GenerateBsfImage (\r
+ IN UINT64 StartAddress1,\r
+ IN UINT64 Size1,\r
+ IN UINT64 StartAddress2,\r
+ IN UINT64 Size2\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This is the main function which will be called from application.\r
+\r
+Arguments:\r
+\r
+ StartAddress1 - The start address of the first BSF \r
+ Size1 - The size of the first BSF\r
+ StartAddress2 - The start address of the second BSF \r
+ Size2 - The size of the second BSF\r
+\r
+Returns:\r
+ \r
+ EFI_OUT_OF_RESOURCES - Can not allocate memory\r
+ The return value can be any of the values \r
+ returned by the calls to following functions:\r
+ GetBsfRelatedInfoFromInfFile\r
+ ProcessAndCreateBsf\r
+ UpdateIA32ResetVector\r
+ UpdateFfsHeader\r
+ WriteBsfBinary\r
+ \r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PeimFixupInFitTable (\r
+ IN UINT64 StartAddress\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This function is an entry point to fixup SAL-E entry point.\r
+\r
+Arguments:\r
+\r
+ StartAddress - StartAddress for PEIM.....\r
+ \r
+Returns:\r
+ \r
+ EFI_SUCCESS - The function completed successfully\r
+ EFI_ABORTED - Error Opening File \r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+Generate32BsfImage (\r
+IN UINT64 BootFileStartAddress\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This is the main IA32 function which will be called from application.\r
+ (Now this tool is not used for IA32 platform, if it will be used in future,\r
+ the relative functions need to be updated, the updating can refer to IPF \r
+ functions)\r
+\r
+Arguments:\r
+\r
+ BootFileStartAddress - Top Address of Boot File\r
+\r
+Returns:\r
+ \r
+ The return value can be any of the values \r
+ returned by the calls to following functions:\r
+ Get32BsfRelatedInfoFromInfFile\r
+ CreateBsfBuffer\r
+ ProcessAndCreate32Bsf\r
+ Update32FfsHeader\r
+ WriteBsfBinary\r
+ \r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+GetTotal32BsfSize(\r
+ IN UINT32 *BsfSize \r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This function calculates total size for IA32 BSF which would be needed to create\r
+ the buffer. This will be done using Passed Info link list and looking for the\r
+ size of the components which belong to BSF. The addtional file header is accounted.\r
+\r
+Arguments:\r
+\r
+ BSFSize - Pointer to the size of IA32 BSF \r
+\r
+Returns:\r
+\r
+ EFI_ABORTED - Returned due to one of the following resons:\r
+ (a) Error Opening File\r
+ EFI_SUCCESS - The fuction completes successfully\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+ProcessAndCreate32Bsf (\r
+ IN UINT64 Size\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This function process the link list created during INF file parsing\r
+ and create component in IA32 BSF\r
+ \r
+Arguments:\r
+\r
+ Size - Size of the Firmware Volume of which, this BSF belongs to.\r
+\r
+Returns:\r
+ \r
+ EFI_UNSUPPORTED - Unknown component type\r
+ EFI_SUCCESS - The function completed successfully \r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+CreateAndUpdateSeccore (\r
+ IN PARSED_BSF_INFO *BsfInfo\r
+ )\r
+/*++\r
+ \r
+Routine Description:\r
+\r
+ This function reads the binary file for seccore and update them\r
+ in IA32 BSF Buffer\r
+ \r
+Arguments:\r
+\r
+ BsfInfo - Pointer to Parsed Info\r
+ \r
+Returns:\r
+\r
+ EFI_ABORTED - Due to one of the following reasons:\r
+ (a)Error Opening File\r
+ (b)The PAL_A Size is more than specified size status\r
+ One of the values mentioned below returned from \r
+ call to UpdateSymFile\r
+ EFI_SUCCESS - The function completed successfully.\r
+ EFI_INVALID_PARAMETER - One of the input parameters was invalid.\r
+ EFI_ABORTED - An error occurred.UpdateSymFile\r
+ \r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+CreateAndUpdate32Component (\r
+ IN PARSED_BSF_INFO *BsfInfo\r
+ )\r
+/*++\r
+ \r
+Routine Description:\r
+\r
+ This function reads the binary file for each components. Add it at aligned address.\r
+ \r
+Arguments:\r
+\r
+ BsfInfo - Pointer to Parsed Info\r
+ \r
+Returns:\r
+\r
+ EFI_SUCCESS - The function completed successful\r
+ EFI_ABORTED - Aborted due to one of the many reasons like:\r
+ (a) Component Size greater than the specified size.\r
+ (b) Error opening files.\r
+ EFI_INVALID_PARAMETER - Value returned from call to UpdateEntryPoint()\r
+ \r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+Update32FfsHeader(\r
+ IN UINT32 BsfSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Update the Firmware Volume Buffer with requested buffer data\r
+\r
+Arguments:\r
+\r
+ BsfSize - Size of the IA32 BSF\r
+\r
+Returns:\r
+ \r
+ EFI_SUCCESS - The function completed successfully\r
+ EFI_INVALID_PARAMETER - The Ffs File Header Pointer is NULL\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+Get32BsfRelatedInfoFromInfFile (\r
+ IN CHAR8 *FileName\r
+ )\r
+/*++\r
+ \r
+Routine Description:\r
+\r
+ This function reads the input file, parse it and create a list of tokens\r
+ which is parsed and used, to intialize the data related to IA32 BSF\r
+ \r
+Arguments:\r
+\r
+ FileName FileName which needed to be read to parse data\r
+\r
+Returns:\r
+ \r
+ EFI_ABORTED Error in opening file\r
+ EFI_INVALID_PARAMETER File doesn't contain any valid informations\r
+ EFI_OUT_OF_RESOURCES Malloc Failed\r
+ EFI_SUCCESS The function completed successfully \r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+Initialize32InFileInfo (\r
+ VOID \r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This function intializes the relevant global variable which is being\r
+ used to store the information retrieved from IA32 INF file.\r
+\r
+Arguments:\r
+\r
+ NONE\r
+\r
+Returns:\r
+\r
+ NONE\r
+\r
+--*/\r
+;\r
+\r
+VOID \r
+ParseAndUpdate32Components (\r
+ IN PARSED_BSF_INFO *BsfInfo\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This function intializes the relevant global variable which is being\r
+ used to store the information retrieved from INF file.\r
+ \r
+Arguments:\r
+\r
+ BsfInfo - A pointer to the BSF Info Structure\r
+ \r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+Write32SoftFit(\r
+ IN CHAR8 *FileName,\r
+ IN PARSED_BSF_INFO *BsfInfo\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Write IA32 Firmware Volume component address from memory to a file.\r
+ \r
+Arguments:\r
+\r
+ FileName Output File Name which needed to be created/\r
+ BsfInfo Parsed info link\r
+ \r
+Returns:\r
+\r
+ EFI_ABORTED - Returned due to one of the following resons:\r
+ (a) Error Opening File\r
+ (b) Failing to copy buffers\r
+ EFI_SUCCESS - The fuction completes successfully\r
+\r
+--*/\r
+;\r
+\r
+#endif\r