Restructuring for better separation of Tool packages.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1674 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lhauch
2006-10-05 23:12:07 +00:00
parent 214b0d1914
commit feccee87a7
796 changed files with 32 additions and 32 deletions

View File

@ -0,0 +1,508 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CommonLib.c
Abstract:
Common Library Functions
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "CommonLib.h"
VOID
PeiZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
/*++
Routine Description:
Set Buffer to zero for Size bytes.
Arguments:
Buffer - Memory to set.
Size - Number of bytes to set
Returns:
None
--*/
{
INT8 *Ptr;
Ptr = Buffer;
while (Size--) {
*(Ptr++) = 0;
}
}
VOID
PeiCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
/*++
Routine Description:
Copy Length bytes from Source to Destination.
Arguments:
Destination - Target of copy
Source - Place to copy from
Length - Number of bytes to copy
Returns:
None
--*/
{
CHAR8 *Destination8;
CHAR8 *Source8;
Destination8 = Destination;
Source8 = Source;
while (Length--) {
*(Destination8++) = *(Source8++);
}
}
VOID
ZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
{
PeiZeroMem (Buffer, Size);
}
VOID
CopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
{
PeiCopyMem (Destination, Source, Length);
}
INTN
CompareGuid (
IN EFI_GUID *Guid1,
IN EFI_GUID *Guid2
)
/*++
Routine Description:
Compares to GUIDs
Arguments:
Guid1 - guid to compare
Guid2 - guid to compare
Returns:
= 0 if Guid1 == Guid2
!= 0 if Guid1 != Guid2
--*/
{
INT32 *g1;
INT32 *g2;
INT32 r;
//
// Compare 32 bits at a time
//
g1 = (INT32 *) Guid1;
g2 = (INT32 *) Guid2;
r = g1[0] - g2[0];
r |= g1[1] - g2[1];
r |= g1[2] - g2[2];
r |= g1[3] - g2[3];
return r;
}
EFI_STATUS
GetFileImage (
IN CHAR8 *InputFileName,
OUT CHAR8 **InputFileImage,
OUT UINT32 *BytesRead
)
/*++
Routine Description:
This function opens a file and reads it into a memory buffer. The function
will allocate the memory buffer and returns the size of the buffer.
Arguments:
InputFileName The name of the file to read.
InputFileImage A pointer to the memory buffer.
BytesRead The size of the memory buffer.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid.
EFI_ABORTED An error occurred.
EFI_OUT_OF_RESOURCES No resource to complete operations.
--*/
{
FILE *InputFile;
UINT32 FileSize;
//
// Verify input parameters.
//
if (InputFileName == NULL || strlen (InputFileName) == 0 || InputFileImage == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Open the file and copy contents into a memory buffer.
//
//
// Open the file
//
InputFile = fopen (InputFileName, "rb");
if (InputFile == NULL) {
printf ("ERROR: Could not open input file \"%s\".\n", InputFileName);
return EFI_ABORTED;
}
//
// Go to the end so that we can determine the file size
//
if (fseek (InputFile, 0, SEEK_END)) {
printf ("ERROR: System error reading input file \"%s\".\n", InputFileName);
fclose (InputFile);
return EFI_ABORTED;
}
//
// Get the file size
//
FileSize = ftell (InputFile);
if (FileSize == -1) {
printf ("ERROR: System error parsing input file \"%s\".\n", InputFileName);
fclose (InputFile);
return EFI_ABORTED;
}
//
// Allocate a buffer
//
*InputFileImage = malloc (FileSize);
if (*InputFileImage == NULL) {
fclose (InputFile);
return EFI_OUT_OF_RESOURCES;
}
//
// Reset to the beginning of the file
//
if (fseek (InputFile, 0, SEEK_SET)) {
printf ("ERROR: System error reading input file \"%s\".\n", InputFileName);
fclose (InputFile);
free (*InputFileImage);
*InputFileImage = NULL;
return EFI_ABORTED;
}
//
// Read all of the file contents.
//
*BytesRead = fread (*InputFileImage, sizeof (UINT8), FileSize, InputFile);
if (*BytesRead != sizeof (UINT8) * FileSize) {
printf ("ERROR: Reading file \"%s\"%i.\n", InputFileName);
fclose (InputFile);
free (*InputFileImage);
*InputFileImage = NULL;
return EFI_ABORTED;
}
//
// Close the file
//
fclose (InputFile);
return EFI_SUCCESS;
}
UINT8
CalculateChecksum8 (
IN UINT8 *Buffer,
IN UINTN Size
)
/*++
Routine Description:
This function calculates the value needed for a valid UINT8 checksum
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 8 bit checksum value needed.
--*/
{
return (UINT8) (0x100 - CalculateSum8 (Buffer, Size));
}
UINT8
CalculateSum8 (
IN UINT8 *Buffer,
IN UINTN Size
)
/*++
Routine Description::
This function calculates the UINT8 sum for the requested region.
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 8 bit checksum value needed.
--*/
{
UINTN Index;
UINT8 Sum;
Sum = 0;
//
// Perform the byte sum for buffer
//
for (Index = 0; Index < Size; Index++) {
Sum = (UINT8) (Sum + Buffer[Index]);
}
return Sum;
}
UINT16
CalculateChecksum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
/*++
Routine Description::
This function calculates the value needed for a valid UINT16 checksum
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 16 bit checksum value needed.
--*/
{
return (UINT16) (0x10000 - CalculateSum16 (Buffer, Size));
}
UINT16
CalculateSum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
/*++
Routine Description:
This function calculates the UINT16 sum for the requested region.
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 16 bit checksum
--*/
{
UINTN Index;
UINT16 Sum;
Sum = 0;
//
// Perform the word sum for buffer
//
for (Index = 0; Index < Size; Index++) {
Sum = (UINT16) (Sum + Buffer[Index]);
}
return (UINT16) Sum;
}
EFI_STATUS
PrintGuid (
IN EFI_GUID *Guid
)
/*++
Routine Description:
This function prints a GUID to STDOUT.
Arguments:
Guid Pointer to a GUID to print.
Returns:
EFI_SUCCESS The GUID was printed.
EFI_INVALID_PARAMETER The input was NULL.
--*/
{
if (Guid == NULL) {
printf ("ERROR: PrintGuid called with a NULL value.\n");
return EFI_INVALID_PARAMETER;
}
printf (
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]
);
return EFI_SUCCESS;
}
EFI_STATUS
PrintGuidToBuffer (
IN EFI_GUID *Guid,
IN OUT UINT8 *Buffer,
IN UINT32 BufferLen,
IN BOOLEAN Uppercase
)
/*++
Routine Description:
This function prints a GUID to a buffer
Arguments:
Guid - Pointer to a GUID to print.
Buffer - Pointer to a user-provided buffer to print to
BufferLen - Size of the Buffer
Uppercase - If use upper case.
Returns:
EFI_SUCCESS The GUID was printed.
EFI_INVALID_PARAMETER The input was NULL.
EFI_BUFFER_TOO_SMALL The input buffer was not big enough
--*/
{
if (Guid == NULL) {
printf ("ERROR: PrintGuidToBuffer() called with a NULL value\n");
return EFI_INVALID_PARAMETER;
}
if (BufferLen < PRINTED_GUID_BUFFER_SIZE) {
printf ("ERORR: PrintGuidToBuffer() called with invalid buffer size\n");
return EFI_BUFFER_TOO_SMALL;
}
if (Uppercase) {
sprintf (
Buffer,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]
);
} else {
sprintf (
Buffer,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]
);
}
return EFI_SUCCESS;
}
#ifdef __GNUC__
#ifndef __CYGWIN__
char *strlwr(char *s)
{
char *p = s;
for(;*s;s++) {
*s = tolower(*s);
}
return p;
}
#endif
#endif

View File

@ -0,0 +1,135 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CommonLib.h
Abstract:
Common library assistance routines.
--*/
#ifndef _EFI_COMMON_LIB_H
#define _EFI_COMMON_LIB_H
#include <Common/UefiBaseTypes.h>
#ifndef _MAX_PATH
#define _MAX_PATH 500
#endif
#define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination
//
// Function declarations
//
VOID
PeiZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
;
VOID
PeiCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
;
VOID
ZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
;
VOID
CopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
;
INTN
CompareGuid (
IN EFI_GUID *Guid1,
IN EFI_GUID *Guid2
)
;
EFI_STATUS
GetFileImage (
IN CHAR8 *InputFileName,
OUT CHAR8 **InputFileImage,
OUT UINT32 *BytesRead
)
;
UINT8
CalculateChecksum8 (
IN UINT8 *Buffer,
IN UINTN Size
)
;
UINT8
CalculateSum8 (
IN UINT8 *Buffer,
IN UINTN Size
)
;
UINT16
CalculateChecksum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
;
UINT16
CalculateSum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
;
EFI_STATUS
PrintGuid (
IN EFI_GUID *Guid
)
;
#define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination
EFI_STATUS
PrintGuidToBuffer (
IN EFI_GUID *Guid,
IN OUT UINT8 *Buffer,
IN UINT32 BufferLen,
IN BOOLEAN Uppercase
)
;
#define ASSERT(x) assert(x)
#ifdef __GNUC__
#define stricmp strcasecmp
#define strnicmp strncasecmp
#define strcmpi strcasecmp
#ifndef __CYGWIN__
char *strlwr(char *s);
#endif
#endif
#endif

View File

@ -0,0 +1,326 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
crc32.c
Abstract:
CalcuateCrc32 routine.
--*/
#include <stdlib.h>
#include "Crc32.h"
UINT32 mCrcTable[256] = {
0x00000000,
0x77073096,
0xEE0E612C,
0x990951BA,
0x076DC419,
0x706AF48F,
0xE963A535,
0x9E6495A3,
0x0EDB8832,
0x79DCB8A4,
0xE0D5E91E,
0x97D2D988,
0x09B64C2B,
0x7EB17CBD,
0xE7B82D07,
0x90BF1D91,
0x1DB71064,
0x6AB020F2,
0xF3B97148,
0x84BE41DE,
0x1ADAD47D,
0x6DDDE4EB,
0xF4D4B551,
0x83D385C7,
0x136C9856,
0x646BA8C0,
0xFD62F97A,
0x8A65C9EC,
0x14015C4F,
0x63066CD9,
0xFA0F3D63,
0x8D080DF5,
0x3B6E20C8,
0x4C69105E,
0xD56041E4,
0xA2677172,
0x3C03E4D1,
0x4B04D447,
0xD20D85FD,
0xA50AB56B,
0x35B5A8FA,
0x42B2986C,
0xDBBBC9D6,
0xACBCF940,
0x32D86CE3,
0x45DF5C75,
0xDCD60DCF,
0xABD13D59,
0x26D930AC,
0x51DE003A,
0xC8D75180,
0xBFD06116,
0x21B4F4B5,
0x56B3C423,
0xCFBA9599,
0xB8BDA50F,
0x2802B89E,
0x5F058808,
0xC60CD9B2,
0xB10BE924,
0x2F6F7C87,
0x58684C11,
0xC1611DAB,
0xB6662D3D,
0x76DC4190,
0x01DB7106,
0x98D220BC,
0xEFD5102A,
0x71B18589,
0x06B6B51F,
0x9FBFE4A5,
0xE8B8D433,
0x7807C9A2,
0x0F00F934,
0x9609A88E,
0xE10E9818,
0x7F6A0DBB,
0x086D3D2D,
0x91646C97,
0xE6635C01,
0x6B6B51F4,
0x1C6C6162,
0x856530D8,
0xF262004E,
0x6C0695ED,
0x1B01A57B,
0x8208F4C1,
0xF50FC457,
0x65B0D9C6,
0x12B7E950,
0x8BBEB8EA,
0xFCB9887C,
0x62DD1DDF,
0x15DA2D49,
0x8CD37CF3,
0xFBD44C65,
0x4DB26158,
0x3AB551CE,
0xA3BC0074,
0xD4BB30E2,
0x4ADFA541,
0x3DD895D7,
0xA4D1C46D,
0xD3D6F4FB,
0x4369E96A,
0x346ED9FC,
0xAD678846,
0xDA60B8D0,
0x44042D73,
0x33031DE5,
0xAA0A4C5F,
0xDD0D7CC9,
0x5005713C,
0x270241AA,
0xBE0B1010,
0xC90C2086,
0x5768B525,
0x206F85B3,
0xB966D409,
0xCE61E49F,
0x5EDEF90E,
0x29D9C998,
0xB0D09822,
0xC7D7A8B4,
0x59B33D17,
0x2EB40D81,
0xB7BD5C3B,
0xC0BA6CAD,
0xEDB88320,
0x9ABFB3B6,
0x03B6E20C,
0x74B1D29A,
0xEAD54739,
0x9DD277AF,
0x04DB2615,
0x73DC1683,
0xE3630B12,
0x94643B84,
0x0D6D6A3E,
0x7A6A5AA8,
0xE40ECF0B,
0x9309FF9D,
0x0A00AE27,
0x7D079EB1,
0xF00F9344,
0x8708A3D2,
0x1E01F268,
0x6906C2FE,
0xF762575D,
0x806567CB,
0x196C3671,
0x6E6B06E7,
0xFED41B76,
0x89D32BE0,
0x10DA7A5A,
0x67DD4ACC,
0xF9B9DF6F,
0x8EBEEFF9,
0x17B7BE43,
0x60B08ED5,
0xD6D6A3E8,
0xA1D1937E,
0x38D8C2C4,
0x4FDFF252,
0xD1BB67F1,
0xA6BC5767,
0x3FB506DD,
0x48B2364B,
0xD80D2BDA,
0xAF0A1B4C,
0x36034AF6,
0x41047A60,
0xDF60EFC3,
0xA867DF55,
0x316E8EEF,
0x4669BE79,
0xCB61B38C,
0xBC66831A,
0x256FD2A0,
0x5268E236,
0xCC0C7795,
0xBB0B4703,
0x220216B9,
0x5505262F,
0xC5BA3BBE,
0xB2BD0B28,
0x2BB45A92,
0x5CB36A04,
0xC2D7FFA7,
0xB5D0CF31,
0x2CD99E8B,
0x5BDEAE1D,
0x9B64C2B0,
0xEC63F226,
0x756AA39C,
0x026D930A,
0x9C0906A9,
0xEB0E363F,
0x72076785,
0x05005713,
0x95BF4A82,
0xE2B87A14,
0x7BB12BAE,
0x0CB61B38,
0x92D28E9B,
0xE5D5BE0D,
0x7CDCEFB7,
0x0BDBDF21,
0x86D3D2D4,
0xF1D4E242,
0x68DDB3F8,
0x1FDA836E,
0x81BE16CD,
0xF6B9265B,
0x6FB077E1,
0x18B74777,
0x88085AE6,
0xFF0F6A70,
0x66063BCA,
0x11010B5C,
0x8F659EFF,
0xF862AE69,
0x616BFFD3,
0x166CCF45,
0xA00AE278,
0xD70DD2EE,
0x4E048354,
0x3903B3C2,
0xA7672661,
0xD06016F7,
0x4969474D,
0x3E6E77DB,
0xAED16A4A,
0xD9D65ADC,
0x40DF0B66,
0x37D83BF0,
0xA9BCAE53,
0xDEBB9EC5,
0x47B2CF7F,
0x30B5FFE9,
0xBDBDF21C,
0xCABAC28A,
0x53B39330,
0x24B4A3A6,
0xBAD03605,
0xCDD70693,
0x54DE5729,
0x23D967BF,
0xB3667A2E,
0xC4614AB8,
0x5D681B02,
0x2A6F2B94,
0xB40BBE37,
0xC30C8EA1,
0x5A05DF1B,
0x2D02EF8D
};
EFI_STATUS
CalculateCrc32 (
IN UINT8 *Data,
IN UINTN DataSize,
IN OUT UINT32 *CrcOut
)
/*++
Routine Description:
The CalculateCrc32 routine.
Arguments:
Data - The buffer contaning the data to be processed
DataSize - The size of data to be processed
CrcOut - A pointer to the caller allocated UINT32 that on
contains the CRC32 checksum of Data
Returns:
EFI_SUCCESS - Calculation is successful.
EFI_INVALID_PARAMETER - Data / CrcOut = NULL, or DataSize = 0
--*/
{
UINT32 Crc;
UINTN Index;
UINT8 *Ptr;
if ((DataSize == 0) || (Data == NULL) || (CrcOut == NULL)) {
return EFI_INVALID_PARAMETER;
}
Crc = 0xffffffff;
for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {
Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];
}
*CrcOut = Crc ^ 0xffffffff;
return EFI_SUCCESS;
}

View File

@ -0,0 +1,54 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Crc32.h
Abstract:
Header file for CalcuateCrc32 routine
--*/
#ifndef _CRC32_H
#define _CRC32_H
#include <Common/UefiBaseTypes.h>
EFI_STATUS
CalculateCrc32 (
IN UINT8 *Data,
IN UINTN DataSize,
IN OUT UINT32 *CrcOut
)
/*++
Routine Description:
The CalculateCrc32 routine.
Arguments:
Data - The buffer contaning the data to be processed
DataSize - The size of data to be processed
CrcOut - A pointer to the caller allocated UINT32 that on
contains the CRC32 checksum of Data
Returns:
EFI_SUCCESS - Calculation is successful.
EFI_INVALID_PARAMETER - Data / CrcOut = NULL, or DataSize = 0
--*/
;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,69 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiCompress.h
Abstract:
Header file for compression routine
--*/
#ifndef _EFICOMPRESS_H
#define _EFICOMPRESS_H
#include <string.h>
#include <stdlib.h>
#include <Common/UefiBaseTypes.h>
EFI_STATUS
Compress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
)
;
/*++
Routine Description:
The compression routine.
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
DstBuffer - The buffer to store the compressed data
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case,
DstSize contains the size needed.
EFI_SUCCESS - Compression is successful.
--*/
typedef
EFI_STATUS
(*COMPRESS_FUNCTION) (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
);
#endif

View File

@ -0,0 +1,141 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiCustomizedCompress.h
Abstract:
Header file for Customized compression routine
--*/
#ifndef _EFICUSTOMIZEDCOMPRESS_H
#define _EFICUSTOMIZEDCOMPRESS_H
#include <Common/UefiBaseTypes.h>
EFI_STATUS
SetCustomizedCompressionType (
IN CHAR8 *Type
)
;
/*++
Routine Description:
The implementation of Customized SetCompressionType().
Arguments:
Type - The type if compression.
Returns:
EFI_SUCCESS - The type has been set.
EFI_UNSUPPORTED - This type is unsupported.
--*/
EFI_STATUS
CustomizedGetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
;
/*++
Routine Description:
The implementation of Customized GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
EFI_STATUS
CustomizedDecompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
;
/*++
Routine Description:
The implementation of Customized Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
EFI_STATUS
CustomizedCompress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
)
;
/*++
Routine Description:
The Customized compression routine.
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
DstBuffer - The buffer to store the compressed data
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case,
DstSize contains the size needed.
EFI_SUCCESS - Compression is successful.
--*/
#endif

View File

@ -0,0 +1,790 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiDecompress.c
Abstract:
Decompressor. Algorithm Ported from OPSD code (Decomp.asm)
--*/
#include "EfiDecompress.h"
//
// Decompression algorithm begins here
//
#define BITBUFSIZ 32
#define MAXMATCH 256
#define THRESHOLD 3
#define CODE_BIT 16
#define BAD_TABLE - 1
//
// C: Char&Len Set; P: Position Set; T: exTra Set
//
#define NC (0xff + MAXMATCH + 2 - THRESHOLD)
#define CBIT 9
#define PBIT 5
#define TBIT 5
#define MAXNP ((1U << PBIT) - 1)
#define NT (CODE_BIT + 3)
#if NT > MAXNP
#define NPT NT
#else
#define NPT MAXNP
#endif
typedef struct {
UINT8 *mSrcBase; // Starting address of compressed data
UINT8 *mDstBase; // Starting address of decompressed data
UINT32 mOutBuf;
UINT32 mInBuf;
UINT16 mBitCount;
UINT32 mBitBuf;
UINT32 mSubBitBuf;
UINT16 mBlockSize;
UINT32 mCompSize;
UINT32 mOrigSize;
UINT16 mBadTableFlag;
UINT16 mLeft[2 * NC - 1];
UINT16 mRight[2 * NC - 1];
UINT8 mCLen[NC];
UINT8 mPTLen[NPT];
UINT16 mCTable[4096];
UINT16 mPTTable[256];
} SCRATCH_DATA;
STATIC
VOID
FillBuf (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfBits
)
/*++
Routine Description:
Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
Arguments:
Sd - The global scratch data
NumOfBit - The number of bits to shift and read.
Returns: (VOID)
--*/
{
Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);
while (NumOfBits > Sd->mBitCount) {
Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));
if (Sd->mCompSize > 0) {
//
// Get 1 byte into SubBitBuf
//
Sd->mCompSize--;
Sd->mSubBitBuf = 0;
Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
Sd->mBitCount = 8;
} else {
//
// No more bits from the source, just pad zero bit.
//
Sd->mSubBitBuf = 0;
Sd->mBitCount = 8;
}
}
Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
}
STATIC
UINT32
GetBits (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfBits
)
/*++
Routine Description:
Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
NumOfBits of bits from source. Returns NumOfBits of bits that are
popped out.
Arguments:
Sd - The global scratch data.
NumOfBits - The number of bits to pop and read.
Returns:
The bits that are popped out.
--*/
{
UINT32 OutBits;
OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
FillBuf (Sd, NumOfBits);
return OutBits;
}
STATIC
UINT16
MakeTable (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfChar,
IN UINT8 *BitLen,
IN UINT16 TableBits,
OUT UINT16 *Table
)
/*++
Routine Description:
Creates Huffman Code mapping table according to code length array.
Arguments:
Sd - The global scratch data
NumOfChar - Number of symbols in the symbol set
BitLen - Code length array
TableBits - The width of the mapping table
Table - The table
Returns:
0 - OK.
BAD_TABLE - The table is corrupted.
--*/
{
UINT16 Count[17];
UINT16 Weight[17];
UINT16 Start[18];
UINT16 *Pointer;
UINT16 Index3;
UINT16 Index;
UINT16 Len;
UINT16 Char;
UINT16 JuBits;
UINT16 Avail;
UINT16 NextCode;
UINT16 Mask;
for (Index = 1; Index <= 16; Index++) {
Count[Index] = 0;
}
for (Index = 0; Index < NumOfChar; Index++) {
Count[BitLen[Index]]++;
}
Start[1] = 0;
for (Index = 1; Index <= 16; Index++) {
Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));
}
if (Start[17] != 0) {
/*(1U << 16)*/
return (UINT16) BAD_TABLE;
}
JuBits = (UINT16) (16 - TableBits);
for (Index = 1; Index <= TableBits; Index++) {
Start[Index] >>= JuBits;
Weight[Index] = (UINT16) (1U << (TableBits - Index));
}
while (Index <= 16) {
Weight[Index++] = (UINT16) (1U << (16 - Index));
}
Index = (UINT16) (Start[TableBits + 1] >> JuBits);
if (Index != 0) {
Index3 = (UINT16) (1U << TableBits);
while (Index != Index3) {
Table[Index++] = 0;
}
}
Avail = NumOfChar;
Mask = (UINT16) (1U << (15 - TableBits));
for (Char = 0; Char < NumOfChar; Char++) {
Len = BitLen[Char];
if (Len == 0) {
continue;
}
NextCode = (UINT16) (Start[Len] + Weight[Len]);
if (Len <= TableBits) {
for (Index = Start[Len]; Index < NextCode; Index++) {
Table[Index] = Char;
}
} else {
Index3 = Start[Len];
Pointer = &Table[Index3 >> JuBits];
Index = (UINT16) (Len - TableBits);
while (Index != 0) {
if (*Pointer == 0) {
Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
*Pointer = Avail++;
}
if (Index3 & Mask) {
Pointer = &Sd->mRight[*Pointer];
} else {
Pointer = &Sd->mLeft[*Pointer];
}
Index3 <<= 1;
Index--;
}
*Pointer = Char;
}
Start[Len] = NextCode;
}
//
// Succeeds
//
return 0;
}
STATIC
UINT32
DecodeP (
IN SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decodes a position value.
Arguments:
Sd - the global scratch data
Returns:
The position value decoded.
--*/
{
UINT16 Val;
UINT32 Mask;
UINT32 Pos;
Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
if (Val >= MAXNP) {
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Sd->mBitBuf & Mask) {
Val = Sd->mRight[Val];
} else {
Val = Sd->mLeft[Val];
}
Mask >>= 1;
} while (Val >= MAXNP);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mPTLen[Val]);
Pos = Val;
if (Val > 1) {
Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
}
return Pos;
}
STATIC
UINT16
ReadPTLen (
IN SCRATCH_DATA *Sd,
IN UINT16 nn,
IN UINT16 nbit,
IN UINT16 Special
)
/*++
Routine Description:
Reads code lengths for the Extra Set or the Position Set
Arguments:
Sd - The global scratch data
nn - Number of symbols
nbit - Number of bits needed to represent nn
Special - The special symbol that needs to be taken care of
Returns:
0 - OK.
BAD_TABLE - Table is corrupted.
--*/
{
UINT16 Number;
UINT16 CharC;
UINT16 Index;
UINT32 Mask;
Number = (UINT16) GetBits (Sd, nbit);
if (Number == 0) {
CharC = (UINT16) GetBits (Sd, nbit);
for (Index = 0; Index < 256; Index++) {
Sd->mPTTable[Index] = CharC;
}
for (Index = 0; Index < nn; Index++) {
Sd->mPTLen[Index] = 0;
}
return 0;
}
Index = 0;
while (Index < Number) {
CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
if (CharC == 7) {
Mask = 1U << (BITBUFSIZ - 1 - 3);
while (Mask & Sd->mBitBuf) {
Mask >>= 1;
CharC += 1;
}
}
FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
Sd->mPTLen[Index++] = (UINT8) CharC;
if (Index == Special) {
CharC = (UINT16) GetBits (Sd, 2);
CharC--;
while ((INT16) (CharC) >= 0) {
Sd->mPTLen[Index++] = 0;
CharC--;
}
}
}
while (Index < nn) {
Sd->mPTLen[Index++] = 0;
}
return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
}
STATIC
VOID
ReadCLen (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Reads code lengths for Char&Len Set.
Arguments:
Sd - the global scratch data
Returns: (VOID)
--*/
{
UINT16 Number;
UINT16 CharC;
UINT16 Index;
UINT32 Mask;
Number = (UINT16) GetBits (Sd, CBIT);
if (Number == 0) {
CharC = (UINT16) GetBits (Sd, CBIT);
for (Index = 0; Index < NC; Index++) {
Sd->mCLen[Index] = 0;
}
for (Index = 0; Index < 4096; Index++) {
Sd->mCTable[Index] = CharC;
}
return ;
}
Index = 0;
while (Index < Number) {
CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
if (CharC >= NT) {
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Mask & Sd->mBitBuf) {
CharC = Sd->mRight[CharC];
} else {
CharC = Sd->mLeft[CharC];
}
Mask >>= 1;
} while (CharC >= NT);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mPTLen[CharC]);
if (CharC <= 2) {
if (CharC == 0) {
CharC = 1;
} else if (CharC == 1) {
CharC = (UINT16) (GetBits (Sd, 4) + 3);
} else if (CharC == 2) {
CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
}
CharC--;
while ((INT16) (CharC) >= 0) {
Sd->mCLen[Index++] = 0;
CharC--;
}
} else {
Sd->mCLen[Index++] = (UINT8) (CharC - 2);
}
}
while (Index < NC) {
Sd->mCLen[Index++] = 0;
}
MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
return ;
}
STATIC
UINT16
DecodeC (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decode a character/length value.
Arguments:
Sd - The global scratch data.
Returns:
The value decoded.
--*/
{
UINT16 Index2;
UINT32 Mask;
if (Sd->mBlockSize == 0) {
//
// Starting a new block
//
Sd->mBlockSize = (UINT16) GetBits (Sd, 16);
Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
if (Sd->mBadTableFlag != 0) {
return 0;
}
ReadCLen (Sd);
Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, PBIT, (UINT16) (-1));
if (Sd->mBadTableFlag != 0) {
return 0;
}
}
Sd->mBlockSize--;
Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
if (Index2 >= NC) {
Mask = 1U << (BITBUFSIZ - 1 - 12);
do {
if (Sd->mBitBuf & Mask) {
Index2 = Sd->mRight[Index2];
} else {
Index2 = Sd->mLeft[Index2];
}
Mask >>= 1;
} while (Index2 >= NC);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mCLen[Index2]);
return Index2;
}
STATIC
VOID
Decode (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decode the source data and put the resulting data into the destination buffer.
Arguments:
Sd - The global scratch data
Returns: (VOID)
--*/
{
UINT16 BytesRemain;
UINT32 DataIdx;
UINT16 CharC;
BytesRemain = (UINT16) (-1);
DataIdx = 0;
for (;;) {
CharC = DecodeC (Sd);
if (Sd->mBadTableFlag != 0) {
return ;
}
if (CharC < 256) {
//
// Process an Original character
//
Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
if (Sd->mOutBuf >= Sd->mOrigSize) {
return ;
}
} else {
//
// Process a Pointer
//
CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));
BytesRemain = CharC;
DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;
BytesRemain--;
while ((INT16) (BytesRemain) >= 0) {
Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
if (Sd->mOutBuf >= Sd->mOrigSize) {
return ;
}
BytesRemain--;
}
}
}
return ;
}
EFI_STATUS
GetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
UINT8 *Src;
*ScratchSize = sizeof (SCRATCH_DATA);
Src = Source;
if (SrcSize < 8) {
return EFI_INVALID_PARAMETER;
}
*DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
return EFI_SUCCESS;
}
EFI_STATUS
Decompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
UINT32 Index;
UINT32 CompSize;
UINT32 OrigSize;
EFI_STATUS Status;
SCRATCH_DATA *Sd;
UINT8 *Src;
UINT8 *Dst;
Status = EFI_SUCCESS;
Src = Source;
Dst = Destination;
if (ScratchSize < sizeof (SCRATCH_DATA)) {
return EFI_INVALID_PARAMETER;
}
Sd = (SCRATCH_DATA *) Scratch;
if (SrcSize < 8) {
return EFI_INVALID_PARAMETER;
}
CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
if (SrcSize < CompSize + 8) {
return EFI_INVALID_PARAMETER;
}
if (DstSize != OrigSize) {
return EFI_INVALID_PARAMETER;
}
Src = Src + 8;
for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {
((UINT8 *) Sd)[Index] = 0;
}
Sd->mSrcBase = Src;
Sd->mDstBase = Dst;
Sd->mCompSize = CompSize;
Sd->mOrigSize = OrigSize;
//
// Fill the first BITBUFSIZ bits
//
FillBuf (Sd, BITBUFSIZ);
//
// Decompress it
//
Decode (Sd);
if (Sd->mBadTableFlag != 0) {
//
// Something wrong with the source
//
Status = EFI_INVALID_PARAMETER;
}
return Status;
}

View File

@ -0,0 +1,106 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiDecompress.h
Abstract:
Header file for compression routine
--*/
#ifndef _EFI_DECOMPRESS_H
#define _EFI_DECOMPRESS_H
#include <Common/UefiBaseTypes.h>
EFI_STATUS
GetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
);
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
EFI_STATUS
Decompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
;
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
typedef
EFI_STATUS
(*GETINFO_FUNCTION) (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
);
typedef
EFI_STATUS
(*DECOMPRESS_FUNCTION) (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
);
#endif

View File

@ -0,0 +1,755 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiUtilityMsgs.c
Abstract:
EFI tools utility functions to display warning, error, and informational
messages.
--*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include "EfiUtilityMsgs.h"
#define MAX_LINE_LEN 200
//
// Declare module globals for keeping track of the the utility's
// name and other settings.
//
static STATUS mStatus = STATUS_SUCCESS;
static CHAR8 mUtilityName[50] = { 0 };
static UINT32 mDebugMsgMask = 0;
static CHAR8 *mSourceFileName = NULL;
static UINT32 mSourceFileLineNum = 0;
static UINT32 mErrorCount = 0;
static UINT32 mWarningCount = 0;
static UINT32 mMaxErrors = 0;
static UINT32 mMaxWarnings = 0;
static UINT32 mMaxWarningsPlusErrors = 0;
static INT8 mPrintLimitsSet = 0;
static
void
PrintMessage (
CHAR8 *Type,
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
va_list List
);
static
void
PrintLimitExceeded (
VOID
);
void
Error (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Prints an error message.
Arguments:
All arguments are optional, though the printed message may be useless if
at least something valid is not specified.
FileName - name of the file or application. If not specified, then the
utilty name (as set by the utility calling SetUtilityName()
earlier) is used. Otherwise "Unknown utility" is used.
LineNumber - the line number of error, typically used by parsers. If the
utility is not a parser, then 0 should be specified. Otherwise
the FileName and LineNumber info can be used to cause
MS Visual Studio to jump to the error.
MessageCode - an application-specific error code that can be referenced in
other documentation.
Text - the text in question, typically used by parsers.
MsgFmt - the format string for the error message. Can contain formatting
controls for use with the varargs.
Returns:
None.
Notes:
We print the following (similar to the Warn() and Debug()
W
Typical error/warning message format:
bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : function does not take 2 parameters
BUGBUG -- these three utility functions are almost identical, and
should be modified to share code.
Visual Studio does not find error messages with:
" error :"
" error 1:"
" error c1:"
" error 1000:"
" error c100:"
It does find:
" error c1000:"
--*/
{
va_list List;
//
// If limits have been set, then check that we have not exceeded them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our error count
//
if (mMaxErrors != 0) {
if (mErrorCount > mMaxErrors) {
PrintLimitExceeded ();
return ;
}
}
}
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserError (
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser error, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
MessageCode - application-specific error code
Text - text to print in the error message
MsgFmt - format string to print at the end of the error message
Returns:
NA
--*/
{
va_list List;
//
// If limits have been set, then check them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our error count
//
if (mMaxErrors != 0) {
if (mErrorCount > mMaxErrors) {
PrintLimitExceeded ();
return ;
}
}
}
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserWarning (
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser warning, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
ErrorCode - application-specific error code
OffendingText - text to print in the warning message
MsgFmt - format string to print at the end of the warning message
Returns:
NA
--*/
{
va_list List;
//
// If limits have been set, then check them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our warning count
//
if (mMaxWarnings != 0) {
if (mWarningCount > mMaxWarnings) {
PrintLimitExceeded ();
return ;
}
}
}
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", mSourceFileName, mSourceFileLineNum, ErrorCode, OffendingText, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
Warning (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - the text in question (parsers)
MsgFmt - the format string for the warning message. Can contain formatting
controls for use with varargs.
Returns:
None.
--*/
{
va_list List;
//
// If limits have been set, then check them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our warning count
//
if (mMaxWarnings != 0) {
if (mWarningCount > mMaxWarnings) {
PrintLimitExceeded ();
return ;
}
}
}
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
DebugMsg (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MsgMask,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - typically the name of the utility printing the debug message, but
can be the name of a file being parsed.
LineNumber - the line number in FileName (parsers)
MsgMask - an application-specific bitmask that, in combination with mDebugMsgMask,
determines if the debug message gets printed.
Text - the text in question (parsers)
MsgFmt - the format string for the debug message. Can contain formatting
controls for use with varargs.
Returns:
None.
--*/
{
va_list List;
//
// If the debug mask is not applicable, then do nothing.
//
if ((MsgMask != 0) && ((mDebugMsgMask & MsgMask) == 0)) {
return ;
}
va_start (List, MsgFmt);
PrintMessage ("debug", FileName, LineNumber, 0, Text, MsgFmt, List);
va_end (List);
}
static
void
PrintMessage (
CHAR8 *Type,
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
va_list List
)
/*++
Routine Description:
Worker routine for all the utility printing services. Prints the message in
a format that Visual Studio will find when scanning build outputs for
errors or warnings.
Arguments:
Type - "warning" or "error" string to insert into the message to be
printed. The first character of this string (converted to uppercase)
is used to preceed the MessageCode value in the output string.
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - part of the message to print
MsgFmt - the format string for the message. Can contain formatting
controls for use with varargs.
List - the variable list.
Returns:
None.
Notes:
If FileName == NULL then this utility will use the string passed into SetUtilityName().
LineNumber is only used if the caller is a parser, in which case FileName refers to the
file being parsed.
Text and MsgFmt are both optional, though it would be of little use calling this function with
them both NULL.
Output will typically be of the form:
<FileName>(<LineNumber>) : <Type> <Type[0]><MessageCode>: <Text> : <MsgFmt>
Parser (LineNumber != 0)
VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function does not take 2 parameters
Generic utility (LineNumber == 0)
UtilityName : error E1234 : Text string : MsgFmt string and args
--*/
{
CHAR8 Line[MAX_LINE_LEN];
CHAR8 Line2[MAX_LINE_LEN];
CHAR8 *Cptr;
//
// If given a filename, then add it (and the line number) to the string.
// If there's no filename, then use the program name if provided.
//
if (FileName != NULL) {
Cptr = FileName;
} else if (mUtilityName[0] != 0) {
Cptr = mUtilityName;
} else {
Cptr = "Unknown utility";
}
strcpy (Line, Cptr);
if (LineNumber != 0) {
sprintf (Line2, "(%d)", LineNumber);
strcat (Line, Line2);
}
//
// Have to print an error code or Visual Studio won't find the
// message for you. It has to be decimal digits too.
//
sprintf (Line2, " : %s %c%04d", Type, toupper (Type[0]), MessageCode);
strcat (Line, Line2);
fprintf (stdout, "%s", Line);
//
// If offending text was provided, then print it
//
if (Text != NULL) {
fprintf (stdout, ": %s ", Text);
}
//
// Print formatted message if provided
//
if (MsgFmt != NULL) {
vsprintf (Line2, MsgFmt, List);
fprintf (stdout, ": %s", Line2);
}
fprintf (stdout, "\n");
}
void
ParserSetPosition (
CHAR8 *SourceFileName,
UINT32 LineNum
)
/*++
Routine Description:
Set the position in a file being parsed. This can be used to
print error messages deeper down in a parser.
Arguments:
SourceFileName - name of the source file being parsed
LineNum - line number of the source file being parsed
Returns:
NA
--*/
{
mSourceFileName = SourceFileName;
mSourceFileLineNum = LineNum;
}
void
SetUtilityName (
CHAR8 *UtilityName
)
/*++
Routine Description:
All printed error/warning/debug messages follow the same format, and
typically will print a filename or utility name followed by the error
text. However if a filename is not passed to the print routines, then
they'll print the utility name if you call this function early in your
app to set the utility name.
Arguments:
UtilityName - name of the utility, which will be printed with all
error/warning/debug messags.
Returns:
NA
--*/
{
//
// Save the name of the utility in our local variable. Make sure its
// length does not exceed our buffer.
//
if (UtilityName != NULL) {
if (strlen (UtilityName) >= sizeof (mUtilityName)) {
Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");
strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);
mUtilityName[sizeof (mUtilityName) - 1] = 0;
return ;
} else {
strcpy (mUtilityName, UtilityName);
}
} else {
Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");
}
}
STATUS
GetUtilityStatus (
VOID
)
/*++
Routine Description:
When you call Error() or Warning(), this module keeps track of it and
sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility
exits, it can call this function to get the status and use it as a return
value.
Arguments:
None.
Returns:
Worst-case status reported, as defined by which print function was called.
--*/
{
return mStatus;
}
void
SetDebugMsgMask (
UINT32 DebugMask
)
/*++
Routine Description:
Set the debug printing mask. This is used by the DebugMsg() function
to determine when/if a debug message should be printed.
Arguments:
DebugMask - bitmask, specific to the calling application
Returns:
NA
--*/
{
mDebugMsgMask = DebugMask;
}
void
SetPrintLimits (
UINT32 MaxErrors,
UINT32 MaxWarnings,
UINT32 MaxWarningsPlusErrors
)
/*++
Routine Description:
Set the limits of how many errors, warnings, and errors+warnings
we will print.
Arguments:
MaxErrors - maximum number of error messages to print
MaxWarnings - maximum number of warning messages to print
MaxWarningsPlusErrors
- maximum number of errors+warnings to print
Returns:
NA
--*/
{
mMaxErrors = MaxErrors;
mMaxWarnings = MaxWarnings;
mMaxWarningsPlusErrors = MaxWarningsPlusErrors;
mPrintLimitsSet = 1;
}
static
void
PrintLimitExceeded (
VOID
)
{
static INT8 mPrintLimitExceeded = 0;
//
// If we've already printed the message, do nothing. Otherwise
// temporarily increase our print limits so we can pass one
// more message through.
//
if (mPrintLimitExceeded == 0) {
mPrintLimitExceeded++;
mMaxErrors++;
mMaxWarnings++;
mMaxWarningsPlusErrors++;
Error (NULL, 0, 0, "error/warning print limit exceeded", NULL);
mMaxErrors--;
mMaxWarnings--;
mMaxWarningsPlusErrors--;
}
}
#if 0
void
TestUtilityMessages (
VOID
)
{
char *ArgStr = "ArgString";
int ArgInt;
ArgInt = 0x12345678;
//
// Test without setting utility name
//
fprintf (stdout, "* Testing without setting utility name\n");
fprintf (stdout, "** Test debug message not printed\n");
DebugMsg (NULL, 0, 0x00000001, NULL, NULL);
fprintf (stdout, "** Test warning with two strings and two args\n");
Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
fprintf (stdout, "** Test error with two strings and two args\n");
Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
fprintf (stdout, "** Test parser warning with nothing\n");
ParserWarning (0, NULL, NULL);
fprintf (stdout, "** Test parser error with nothing\n");
ParserError (0, NULL, NULL);
//
// Test with utility name set now
//
fprintf (stdout, "** Testingin with utility name set\n");
SetUtilityName ("MyUtilityName");
//
// Test debug prints
//
SetDebugMsgMask (2);
fprintf (stdout, "** Test debug message with one string\n");
DebugMsg (NULL, 0, 0x00000002, "Text1", NULL);
fprintf (stdout, "** Test debug message with one string\n");
DebugMsg (NULL, 0, 0x00000002, NULL, "Text2");
fprintf (stdout, "** Test debug message with two strings\n");
DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2");
fprintf (stdout, "** Test debug message with two strings and two args\n");
DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
//
// Test warning prints
//
fprintf (stdout, "** Test warning with no strings\n");
Warning (NULL, 0, 1234, NULL, NULL);
fprintf (stdout, "** Test warning with one string\n");
Warning (NULL, 0, 1234, "Text1", NULL);
fprintf (stdout, "** Test warning with one string\n");
Warning (NULL, 0, 1234, NULL, "Text2");
fprintf (stdout, "** Test warning with two strings and two args\n");
Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
//
// Test error prints
//
fprintf (stdout, "** Test error with no strings\n");
Error (NULL, 0, 1234, NULL, NULL);
fprintf (stdout, "** Test error with one string\n");
Error (NULL, 0, 1234, "Text1", NULL);
fprintf (stdout, "** Test error with one string\n");
Error (NULL, 0, 1234, NULL, "Text2");
fprintf (stdout, "** Test error with two strings and two args\n");
Error (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
//
// Test parser prints
//
fprintf (stdout, "** Test parser errors\n");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, NULL, NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, "Text1", NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, NULL, "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, "Text1", "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
fprintf (stdout, "** Test parser warnings\n");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, NULL, NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, "Text1", NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, NULL, "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, "Text1", "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
}
#endif

View File

@ -0,0 +1,137 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiUtilityMsgs.h
Abstract:
Defines and prototypes for common EFI utility error and debug messages.
--*/
#ifndef _EFI_UTILITY_MSGS_H_
#define _EFI_UTILITY_MSGS_H_
#include <Common/UefiBaseTypes.h>
//
// Status codes returned by EFI utility programs and functions
//
#define STATUS_SUCCESS 0
#define STATUS_WARNING 1
#define STATUS_ERROR 2
#define VOID void
typedef int STATUS;
#ifdef __cplusplus
extern "C" {
#endif
//
// When we call Error() or Warning(), the module keeps track of the worst
// case reported. GetUtilityStatus() will get the worst-case results, which
// can be used as the return value from the app.
//
STATUS
GetUtilityStatus (
void
);
//
// If someone prints an error message and didn't specify a source file name,
// then we print the utility name instead. However they must tell us the
// utility name early on via this function.
//
void
SetUtilityName (
CHAR8 *ProgramName
)
;
void
Error (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
Warning (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
DebugMsg (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MsgLevel,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
SetDebugMsgMask (
UINT32 MsgMask
)
;
void
ParserSetPosition (
CHAR8 *SourceFileName,
UINT32 LineNum
)
;
void
ParserError (
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
ParserWarning (
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
SetPrintLimits (
UINT32 NumErrors,
UINT32 NumWarnings,
UINT32 NumWarningsPlusErrors
)
;
#ifdef __cplusplus
}
#endif
#endif // #ifndef _EFI_UTILITY_MSGS_H_

View File

@ -0,0 +1,780 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FvLib.c
Abstract:
These functions assist in parsing and manipulating a Firmware Volume.
--*/
//
// Include files
//
#include "FvLib.h"
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
//
// Module global variables
//
EFI_FIRMWARE_VOLUME_HEADER *mFvHeader = NULL;
UINT32 mFvLength = 0;
//
// External function implementations
//
EFI_STATUS
InitializeFvLib (
IN VOID *Fv,
IN UINT32 FvLength
)
/*++
Routine Description:
This initializes the FV lib with a pointer to the FV and length. It does not
verify the FV in any way.
Arguments:
Fv Buffer containing the FV.
FvLength Length of the FV
Returns:
EFI_SUCCESS Function Completed successfully.
EFI_INVALID_PARAMETER A required parameter was NULL.
--*/
{
//
// Verify input arguments
//
if (Fv == NULL) {
return EFI_INVALID_PARAMETER;
}
mFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Fv;
mFvLength = FvLength;
return EFI_SUCCESS;
}
EFI_STATUS
GetFvHeader (
OUT EFI_FIRMWARE_VOLUME_HEADER **FvHeader,
OUT UINT32 *FvLength
)
/*++
Routine Description:
This function returns a pointer to the current FV and the size.
Arguments:
FvHeader Pointer to the FV buffer.
FvLength Length of the FV
Returns:
EFI_SUCCESS Function Completed successfully.
EFI_INVALID_PARAMETER A required parameter was NULL.
EFI_ABORTED The library needs to be initialized.
--*/
{
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input arguments
//
if (FvHeader == NULL) {
return EFI_INVALID_PARAMETER;
}
*FvHeader = mFvHeader;
return EFI_SUCCESS;
}
EFI_STATUS
GetNextFile (
IN EFI_FFS_FILE_HEADER *CurrentFile,
OUT EFI_FFS_FILE_HEADER **NextFile
)
/*++
Routine Description:
This function returns the next file. If the current file is NULL, it returns
the first file in the FV. If the function returns EFI_SUCCESS and the file
pointer is NULL, then there are no more files in the FV.
Arguments:
CurrentFile Pointer to the current file, must be within the current FV.
NextFile Pointer to the next file in the FV.
Returns:
EFI_SUCCESS Function completed successfully.
EFI_INVALID_PARAMETER A required parameter was NULL or is out of range.
EFI_ABORTED The library needs to be initialized.
--*/
{
EFI_STATUS Status;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input arguments
//
if (NextFile == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Get first file
//
if (CurrentFile == NULL) {
CurrentFile = (EFI_FFS_FILE_HEADER *) ((UINTN) mFvHeader + mFvHeader->HeaderLength);
//
// Verify file is valid
//
Status = VerifyFfsFile (CurrentFile);
if (EFI_ERROR (Status)) {
//
// no files in this FV
//
*NextFile = NULL;
return EFI_SUCCESS;
} else {
//
// Verify file is in this FV.
//
if ((UINTN) CurrentFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FFS_FILE_HEADER)) {
*NextFile = NULL;
return EFI_SUCCESS;
}
*NextFile = CurrentFile;
return EFI_SUCCESS;
}
}
//
// Verify current file is in range
//
if (((UINTN) CurrentFile < (UINTN) mFvHeader + sizeof (EFI_FIRMWARE_VOLUME_HEADER)) ||
((UINTN) CurrentFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER))
) {
return EFI_INVALID_PARAMETER;
}
//
// Get next file, compensate for 8 byte alignment if necessary.
//
*NextFile = (EFI_FFS_FILE_HEADER *) (((UINTN) CurrentFile + GetLength (CurrentFile->Size) + 0x07) & (-1 << 3));
//
// Verify file is in this FV.
//
if ((UINTN) *NextFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FFS_FILE_HEADER)) {
*NextFile = NULL;
return EFI_SUCCESS;
}
//
// Verify file is valid
//
Status = VerifyFfsFile (*NextFile);
if (EFI_ERROR (Status)) {
//
// no more files in this FV
//
*NextFile = NULL;
return EFI_SUCCESS;
}
return EFI_SUCCESS;
}
EFI_STATUS
GetFileByName (
IN EFI_GUID *FileName,
OUT EFI_FFS_FILE_HEADER **File
)
/*++
Routine Description:
Find a file by name. The function will return NULL if the file is not found.
Arguments:
FileName The GUID file name of the file to search for.
File Return pointer. In the case of an error, contents are undefined.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_ABORTED An error was encountered.
EFI_INVALID_PARAMETER One of the parameters was NULL.
--*/
{
EFI_FFS_FILE_HEADER *CurrentFile;
EFI_STATUS Status;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input parameters
//
if (FileName == NULL || File == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Get the first file
//
Status = GetNextFile (NULL, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing the FV", NULL);
return EFI_ABORTED;
}
//
// Loop as long as we have a valid file
//
while (CurrentFile) {
if (!CompareGuid (&CurrentFile->Name, FileName)) {
*File = CurrentFile;
return EFI_SUCCESS;
}
Status = GetNextFile (CurrentFile, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing the FV", NULL);
return EFI_ABORTED;
}
}
//
// File not found in this FV.
//
*File = NULL;
return EFI_SUCCESS;
}
EFI_STATUS
GetFileByType (
IN EFI_FV_FILETYPE FileType,
IN UINTN Instance,
OUT EFI_FFS_FILE_HEADER **File
)
/*++
Routine Description:
Find a file by type and instance. An instance of 1 is the first instance.
The function will return NULL if a matching file cannot be found.
File type EFI_FV_FILETYPE_ALL means any file type is valid.
Arguments:
FileType Type of file to search for.
Instance Instace of the file type to return.
File Return pointer. In the case of an error, contents are undefined.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_ABORTED An error was encountered.
EFI_INVALID_PARAMETER One of the parameters was NULL.
--*/
{
EFI_FFS_FILE_HEADER *CurrentFile;
EFI_STATUS Status;
UINTN FileCount;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input parameters
//
if (File == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Initialize the number of matching files found.
//
FileCount = 0;
//
// Get the first file
//
Status = GetNextFile (NULL, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing FV", NULL);
return EFI_ABORTED;
}
//
// Loop as long as we have a valid file
//
while (CurrentFile) {
if (FileType == EFI_FV_FILETYPE_ALL || CurrentFile->Type == FileType) {
FileCount++;
}
if (FileCount == Instance) {
*File = CurrentFile;
return EFI_SUCCESS;
}
Status = GetNextFile (CurrentFile, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing the FV", NULL);
return EFI_ABORTED;
}
}
*File = NULL;
return EFI_SUCCESS;
}
EFI_STATUS
GetSectionByType (
IN EFI_FFS_FILE_HEADER *File,
IN EFI_SECTION_TYPE SectionType,
IN UINTN Instance,
OUT EFI_FILE_SECTION_POINTER *Section
)
/*++
Routine Description:
Find a section in a file by type and instance. An instance of 1 is the first
instance. The function will return NULL if a matching section cannot be found.
The function will not handle encapsulating sections.
Arguments:
File The file to search.
SectionType Type of file to search for.
Instance Instace of the section to return.
Section Return pointer. In the case of an error, contents are undefined.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_ABORTED An error was encountered.
EFI_INVALID_PARAMETER One of the parameters was NULL.
EFI_NOT_FOUND No found.
--*/
{
EFI_FILE_SECTION_POINTER CurrentSection;
EFI_STATUS Status;
UINTN SectionCount;
//
// Verify input parameters
//
if (File == NULL || Instance == 0) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FFS header
//
Status = VerifyFfsFile (File);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "invalid FFS file", NULL);
return EFI_ABORTED;
}
//
// Initialize the number of matching sections found.
//
SectionCount = 0;
//
// Get the first section
//
CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) File + sizeof (EFI_FFS_FILE_HEADER));
//
// Loop as long as we have a valid file
//
while ((UINTN) CurrentSection.CommonHeader < (UINTN) File + GetLength (File->Size)) {
if (CurrentSection.CommonHeader->Type == SectionType) {
SectionCount++;
}
if (SectionCount == Instance) {
*Section = CurrentSection;
return EFI_SUCCESS;
}
//
// Find next section (including compensating for alignment issues.
//
CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetLength (CurrentSection.CommonHeader->Size) + 0x03) & (-1 << 2));
}
//
// Section not found
//
(*Section).Code16Section = NULL;
return EFI_NOT_FOUND;
}
//
// will not parse compressed sections
//
EFI_STATUS
VerifyFv (
IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
)
/*++
Routine Description:
Verify the current pointer points to a valid FV header.
Arguments:
FvHeader Pointer to an alleged FV file.
Returns:
EFI_SUCCESS The FV header is valid.
EFI_VOLUME_CORRUPTED The FV header is not valid.
EFI_INVALID_PARAMETER A required parameter was NULL.
EFI_ABORTED Operation aborted.
--*/
{
UINT16 Checksum;
//
// Verify input parameters
//
if (FvHeader == NULL) {
return EFI_INVALID_PARAMETER;
}
if (FvHeader->Signature != EFI_FVH_SIGNATURE) {
Error (NULL, 0, 0, "invalid FV header signature", NULL);
return EFI_VOLUME_CORRUPTED;
}
//
// Verify header checksum
//
Checksum = CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));
if (Checksum != 0) {
Error (NULL, 0, 0, "invalid FV header checksum", NULL);
return EFI_ABORTED;
}
return EFI_SUCCESS;
}
EFI_STATUS
VerifyFfsFile (
IN EFI_FFS_FILE_HEADER *FfsHeader
)
/*++
Routine Description:
Verify the current pointer points to a FFS file header.
Arguments:
FfsHeader Pointer to an alleged FFS file.
Returns:
EFI_SUCCESS The Ffs header is valid.
EFI_NOT_FOUND This "file" is the beginning of free space.
EFI_VOLUME_CORRUPTED The Ffs header is not valid.
EFI_ABORTED The erase polarity is not known.
--*/
{
BOOLEAN ErasePolarity;
EFI_STATUS Status;
EFI_FFS_FILE_HEADER BlankHeader;
UINT8 Checksum;
UINT32 FileLength;
UINT32 OccupiedFileLength;
EFI_FFS_FILE_TAIL *Tail;
UINT8 SavedChecksum;
UINT8 SavedState;
UINT8 FileGuidString[80];
UINT32 TailSize;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Get the erase polarity.
//
Status = GetErasePolarity (&ErasePolarity);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Check if we have free space
//
if (ErasePolarity) {
memset (&BlankHeader, -1, sizeof (EFI_FFS_FILE_HEADER));
} else {
memset (&BlankHeader, 0, sizeof (EFI_FFS_FILE_HEADER));
}
if (memcmp (&BlankHeader, FfsHeader, sizeof (EFI_FFS_FILE_HEADER)) == 0) {
return EFI_NOT_FOUND;
}
//
// Convert the GUID to a string so we can at least report which file
// if we find an error.
//
PrintGuidToBuffer (&FfsHeader->Name, FileGuidString, sizeof (FileGuidString), TRUE);
if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {
TailSize = sizeof (EFI_FFS_FILE_TAIL);
} else {
TailSize = 0;
}
//
// Verify file header checksum
//
SavedState = FfsHeader->State;
FfsHeader->State = 0;
SavedChecksum = FfsHeader->IntegrityCheck.Checksum.File;
FfsHeader->IntegrityCheck.Checksum.File = 0;
Checksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
FfsHeader->State = SavedState;
FfsHeader->IntegrityCheck.Checksum.File = SavedChecksum;
if (Checksum != 0) {
Error (NULL, 0, 0, FileGuidString, "invalid FFS file header checksum");
return EFI_ABORTED;
}
//
// Verify file checksum
//
if (FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) {
//
// Verify file data checksum
//
FileLength = GetLength (FfsHeader->Size);
OccupiedFileLength = (FileLength + 0x07) & (-1 << 3);
Checksum = CalculateSum8 ((UINT8 *) FfsHeader, FileLength - TailSize);
Checksum = (UINT8) (Checksum - FfsHeader->State);
if (Checksum != 0) {
Error (NULL, 0, 0, FileGuidString, "invalid FFS file checksum");
return EFI_ABORTED;
}
} else {
//
// File does not have a checksum
// Verify contents are 0x5A as spec'd
//
if (FfsHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM) {
Error (NULL, 0, 0, FileGuidString, "invalid fixed FFS file header checksum");
return EFI_ABORTED;
}
}
//
// Check if the tail is present and verify it if it is.
//
if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {
//
// Verify tail is complement of integrity check field in the header.
//
Tail = (EFI_FFS_FILE_TAIL *) ((UINTN) FfsHeader + GetLength (FfsHeader->Size) - sizeof (EFI_FFS_FILE_TAIL));
if (FfsHeader->IntegrityCheck.TailReference != (EFI_FFS_FILE_TAIL)~(*Tail)) {
Error (NULL, 0, 0, FileGuidString, "invalid FFS file tail");
return EFI_ABORTED;
}
}
return EFI_SUCCESS;
}
UINT32
GetLength (
UINT8 *ThreeByteLength
)
/*++
Routine Description:
Converts a three byte length value into a UINT32.
Arguments:
ThreeByteLength Pointer to the first of the 3 byte length.
Returns:
UINT32 Size of the section
--*/
{
UINT32 Length;
if (ThreeByteLength == NULL) {
return 0;
}
Length = *((UINT32 *) ThreeByteLength);
Length = Length & 0x00FFFFFF;
return Length;
}
EFI_STATUS
GetErasePolarity (
OUT BOOLEAN *ErasePolarity
)
/*++
Routine Description:
This function returns with the FV erase polarity. If the erase polarity
for a bit is 1, the function return TRUE.
Arguments:
ErasePolarity A pointer to the erase polarity.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid.
EFI_ABORTED Operation aborted.
--*/
{
EFI_STATUS Status;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Verify input parameters.
//
if (ErasePolarity == NULL) {
return EFI_INVALID_PARAMETER;
}
if (mFvHeader->Attributes & EFI_FVB_ERASE_POLARITY) {
*ErasePolarity = TRUE;
} else {
*ErasePolarity = FALSE;
}
return EFI_SUCCESS;
}
UINT8
GetFileState (
IN BOOLEAN ErasePolarity,
IN EFI_FFS_FILE_HEADER *FfsHeader
)
/*++
Routine Description:
This function returns a the highest state bit in the FFS that is set.
It in no way validate the FFS file.
Arguments:
ErasePolarity The erase polarity for the file state bits.
FfsHeader Pointer to a FFS file.
Returns:
UINT8 The hightest set state of the file.
--*/
{
UINT8 FileState;
UINT8 HighestBit;
FileState = FfsHeader->State;
if (ErasePolarity) {
FileState = (UINT8)~FileState;
}
HighestBit = 0x80;
while (HighestBit != 0 && (HighestBit & FileState) == 0) {
HighestBit >>= 1;
}
return HighestBit;
}

View File

@ -0,0 +1,181 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FvLib.h
Abstract:
These functions assist in parsing and manipulating a Firmware Volume.
--*/
#ifndef _EFI_FV_LIB_H
#define _EFI_FV_LIB_H
//
// Include files
//
#include <string.h>
#include <Common/UefiBaseTypes.h>
#include <Common/EfiImage.h>
#include <Common/FirmwareVolumeImageFormat.h>
#include <Common/FirmwareFileSystem.h>
#include <Common/FirmwareVolumeHeader.h>
#include <Common/MultiPhase.h>
EFI_STATUS
InitializeFvLib (
IN VOID *Fv,
IN UINT32 FvLength
)
;
EFI_STATUS
GetFvHeader (
OUT EFI_FIRMWARE_VOLUME_HEADER **FvHeader,
OUT UINT32 *FvLength
)
;
EFI_STATUS
GetNextFile (
IN EFI_FFS_FILE_HEADER *CurrentFile,
OUT EFI_FFS_FILE_HEADER **NextFile
)
;
EFI_STATUS
GetFileByName (
IN EFI_GUID *FileName,
OUT EFI_FFS_FILE_HEADER **File
)
;
EFI_STATUS
GetFileByType (
IN EFI_FV_FILETYPE FileType,
IN UINTN Instance,
OUT EFI_FFS_FILE_HEADER **File
)
;
EFI_STATUS
GetSectionByType (
IN EFI_FFS_FILE_HEADER *File,
IN EFI_SECTION_TYPE SectionType,
IN UINTN Instance,
OUT EFI_FILE_SECTION_POINTER *Section
)
;
//
// will not parse compressed sections
//
EFI_STATUS
VerifyFv (
IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
)
;
EFI_STATUS
VerifyFfsFile (
IN EFI_FFS_FILE_HEADER *FfsHeader
)
;
/*++
Routine Description:
Verify the current pointer points to a FFS file header.
Arguments:
FfsHeader Pointer to an alleged FFS file.
Returns:
EFI_SUCCESS The Ffs header is valid.
EFI_NOT_FOUND This "file" is the beginning of free space.
EFI_VOLUME_CORRUPTED The Ffs header is not valid.
--*/
UINT32
GetLength (
UINT8 *ThreeByteLength
)
;
/*++
Routine Description:
Converts a three byte length value into a UINT32.
Arguments:
ThreeByteLength Pointer to the first of the 3 byte length.
Returns:
UINT32 Size of the section
--*/
EFI_STATUS
GetErasePolarity (
OUT BOOLEAN *ErasePolarity
)
;
/*++
Routine Description:
This function returns with the FV erase polarity. If the erase polarity
for a bit is 1, the function return TRUE.
Arguments:
ErasePolarity A pointer to the erase polarity.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid.
--*/
UINT8
GetFileState (
IN BOOLEAN ErasePolarity,
IN EFI_FFS_FILE_HEADER *FfsHeader
)
;
/*++
Routine Description:
This function returns a the highest state bit in the FFS that is set.
It in no way validate the FFS file.
Arguments:
ErasePolarity The erase polarity for the file state bits.
FfsHeader Pointer to a FFS file.
Returns:
UINT8 The hightest set state of the file.
--*/
#endif

View File

@ -0,0 +1,516 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
MyAlloc.c
Abstract:
File for memory allocation tracking functions.
--*/
#include "MyAlloc.h"
#if USE_MYALLOC
//
// Get back to original alloc/free calls.
//
#undef malloc
#undef calloc
#undef realloc
#undef free
//
// Start of allocation list.
//
static MY_ALLOC_STRUCT *MyAllocData = NULL;
//
//
//
static UINT32 MyAllocHeadMagik = MYALLOC_HEAD_MAGIK;
static UINT32 MyAllocTailMagik = MYALLOC_TAIL_MAGIK;
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID
MyCheck (
BOOLEAN Final,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// Check for corruptions in the allocated memory chain. If a corruption
// is detection program operation stops w/ an exit(1) call.
//
// Parameters:
//
// Final := When FALSE, MyCheck() returns if the allocated memory chain
// has not been corrupted. When TRUE, MyCheck() returns if there
// are no un-freed allocations. If there are un-freed allocations,
// they are displayed and exit(1) is called.
//
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
//
// Check parameters.
//
if (File == NULL || Line == 0) {
printf (
"\nMyCheck(Final=%u, File=%xh, Line=%u)"
"Invalid parameter(s).\n",
Final,
File,
Line
);
exit (1);
}
if (strlen (File) == 0) {
printf (
"\nMyCheck(Final=%u, File=%s, Line=%u)"
"Invalid parameter.\n",
Final,
File,
Line
);
exit (1);
}
//
// Check structure contents.
//
for (Tmp = MyAllocData; Tmp != NULL; Tmp = Tmp->Next) {
if (memcmp(Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik) ||
memcmp(&Tmp->Buffer[Tmp->Size + sizeof(UINT32)], &MyAllocTailMagik, sizeof MyAllocTailMagik)) {
break;
}
}
//
// If Tmp is not NULL, the structure is corrupt.
//
if (Tmp != NULL) {
printf (
"\nMyCheck(Final=%u, File=%s, Line=%u)""\nStructure corrupted!"
"\nFile=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
Final,
File,
Line,
Tmp->File,
Tmp->Line,
Tmp->Size,
*(UINT32 *) (Tmp->Buffer),
*(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
);
exit (1);
}
//
// If Final is TRUE, display the state of the structure chain.
//
if (Final) {
if (MyAllocData != NULL) {
printf (
"\nMyCheck(Final=%u, File=%s, Line=%u)"
"\nSome allocated items have not been freed.\n",
Final,
File,
Line
);
for (Tmp = MyAllocData; Tmp != NULL; Tmp = Tmp->Next) {
printf (
"File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
Tmp->File,
Tmp->Line,
Tmp->Size,
*(UINT32 *) (Tmp->Buffer),
*(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
);
}
}
}
}
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID *
MyAlloc (
UINTN Size,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// Allocate a new link in the allocation chain along with enough storage
// for the File[] string, requested Size and alignment overhead. If
// memory cannot be allocated or the allocation chain has been corrupted,
// exit(1) will be called.
//
// Parameters:
//
// Size := Number of bytes (UINT8) requested by the called.
// Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to the caller's buffer.
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
UINTN Len;
//
// Check for invalid parameters.
//
if (Size == 0 || File == NULL || Line == 0) {
printf (
"\nMyAlloc(Size=%u, File=%xh, Line=%u)"
"\nInvalid parameter(s).\n",
Size,
File,
Line
);
exit (1);
}
Len = strlen (File);
if (Len == 0) {
printf (
"\nMyAlloc(Size=%u, File=%s, Line=%u)"
"\nInvalid parameter.\n",
Size,
File,
Line
);
exit (1);
}
//
// Check the allocation list for corruption.
//
MyCheck (0, __FILE__, __LINE__);
//
// Allocate a new entry.
//
Tmp = calloc (
1,
sizeof (MY_ALLOC_STRUCT) + Len + 1 + sizeof (UINT64) + Size + (sizeof MyAllocHeadMagik) + (sizeof MyAllocTailMagik)
);
if (Tmp == NULL) {
printf (
"\nMyAlloc(Size=%u, File=%s, Line=%u)"
"\nOut of memory.\n",
Size,
File,
Line
);
exit (1);
}
//
// Fill in the new entry.
//
Tmp->File = ((UINT8 *) Tmp) + sizeof (MY_ALLOC_STRUCT);
strcpy (Tmp->File, File);
Tmp->Line = Line;
Tmp->Size = Size;
Tmp->Buffer = (UINT8 *) (((UINTN) Tmp + Len + 9) &~7);
memcpy (Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik);
memcpy (
&Tmp->Buffer[Size + sizeof (UINT32)],
&MyAllocTailMagik,
sizeof MyAllocTailMagik
);
Tmp->Next = MyAllocData;
Tmp->Cksum = (UINTN) Tmp + (UINTN) (Tmp->Next) + Tmp->Line + Tmp->Size + (UINTN) (Tmp->File) + (UINTN) (Tmp->Buffer);
MyAllocData = Tmp;
return Tmp->Buffer + sizeof (UINT32);
}
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID *
MyRealloc (
VOID *Ptr,
UINTN Size,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization
// for shrinking or expanding buffers. An invalid parameter will cause
// MyRealloc() to fail with a call to exit(1).
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be re-allocated.
//
// Size := Size of new buffer. Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to new caller's buffer.
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
VOID *Buffer;
//
// Check for invalid parameter(s).
//
if (Size == 0 || File == NULL || Line == 0) {
printf (
"\nMyRealloc(Ptr=%xh, Size=%u, File=%xh, Line=%u)"
"\nInvalid parameter(s).\n",
Ptr,
Size,
File,
Line
);
exit (1);
}
if (strlen (File) == 0) {
printf (
"\nMyRealloc(Ptr=%xh, Size=%u, File=%s, Line=%u)"
"\nInvalid parameter.\n",
Ptr,
Size,
File,
Line
);
exit (1);
}
//
// Find existing buffer in allocation list.
//
if (Ptr == NULL) {
Tmp = NULL;
} else if (&MyAllocData->Buffer[sizeof (UINT32)] == Ptr) {
Tmp = MyAllocData;
} else {
for (Tmp = MyAllocData;; Tmp = Tmp->Next) {
if (Tmp->Next == NULL) {
printf (
"\nMyRealloc(Ptr=%xh, Size=%u, File=%s, Line=%u)"
"\nCould not find buffer.\n",
Ptr,
Size,
File,
Line
);
exit (1);
}
Tmp = Tmp->Next;
}
}
//
// Allocate new buffer, copy old data, free old buffer.
//
Buffer = MyAlloc (Size, File, Line);
if (Buffer != NULL && Tmp != NULL) {
memcpy (
Buffer,
&Tmp->Buffer[sizeof (UINT32)],
((Size <= Tmp->Size) ? Size : Tmp->Size)
);
MyFree (Ptr, __FILE__, __LINE__);
}
return Buffer;
}
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID
MyFree (
VOID *Ptr,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// Release a previously allocated buffer. Invalid parameters will cause
// MyFree() to fail with an exit(1) call.
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be freed.
// A NULL pointer will be ignored.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
MY_ALLOC_STRUCT *Tmp2;
//
// Check for invalid parameter(s).
//
if (File == NULL || Line == 0) {
printf (
"\nMyFree(Ptr=%xh, File=%xh, Line=%u)"
"\nInvalid parameter(s).\n",
Ptr,
File,
Line
);
exit (1);
}
if (strlen (File) == 0) {
printf (
"\nMyFree(Ptr=%xh, File=%s, Line=%u)"
"\nInvalid parameter.\n",
Ptr,
File,
Line
);
exit (1);
}
//
// Freeing NULL is always valid.
//
if (Ptr == NULL) {
return ;
}
//
// Fail if nothing is allocated.
//
if (MyAllocData == NULL) {
printf (
"\nMyFree(Ptr=%xh, File=%s, Line=%u)"
"\nCalled before memory allocated.\n",
Ptr,
File,
Line
);
exit (1);
}
//
// Check for corrupted allocation list.
//
MyCheck (0, __FILE__, __LINE__);
//
// Need special check for first item in list.
//
if (&MyAllocData->Buffer[sizeof (UINT32)] == Ptr) {
//
// Unlink first item in list.
//
Tmp = MyAllocData;
MyAllocData = MyAllocData->Next;
} else {
//
// Walk list looking for matching item.
//
for (Tmp = MyAllocData;; Tmp = Tmp->Next) {
//
// Fail if end of list is reached.
//
if (Tmp->Next == NULL) {
printf (
"\nMyFree(Ptr=%xh, File=%s, Line=%u)\n"
"\nNot found.\n",
Ptr,
File,
Line
);
exit (1);
}
//
// Leave loop when match is found.
//
if (&Tmp->Next->Buffer[sizeof (UINT32)] == Ptr) {
break;
}
}
//
// Unlink item from list.
//
Tmp2 = Tmp->Next;
Tmp->Next = Tmp->Next->Next;
Tmp = Tmp2;
}
//
// Release item.
//
free (Tmp);
}
#endif /* USE_MYALLOC */
/* eof - MyAlloc.c */

View File

@ -0,0 +1,222 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
MyAlloc.h
Abstract:
Header file for memory allocation tracking functions.
--*/
#ifndef _MYALLOC_H_
#define _MYALLOC_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Common/BaseTypes.h>
//
// Default operation is to use the memory allocation tracking functions.
// To over-ride add "#define USE_MYALLOC 0" to your program header and/or
// source files as needed. Or, just do not include this header file in
// your project.
//
#ifndef USE_MYALLOC
#define USE_MYALLOC 1
#endif
#if USE_MYALLOC
//
// Replace C library allocation routines with MyAlloc routines.
//
#define malloc(size) MyAlloc ((size), __FILE__, __LINE__)
#define calloc(count, size) MyAlloc ((count) * (size), __FILE__, __LINE__)
#define realloc(ptr, size) MyRealloc ((ptr), (size), __FILE__, __LINE__)
#define free(ptr) MyFree ((ptr), __FILE__, __LINE__)
#define alloc_check(final) MyCheck ((final), __FILE__, __LINE__)
//
// Structure for checking/tracking memory allocations.
//
typedef struct MyAllocStruct {
UINTN Cksum;
struct MyAllocStruct *Next;
UINTN Line;
UINTN Size;
UINT8 *File;
UINT8 *Buffer;
} MY_ALLOC_STRUCT;
//
// Cksum := (UINTN)This + (UINTN)Next + Line + Size + (UINTN)File +
// (UINTN)Buffer;
//
// Next := Pointer to next allocation structure in the list.
//
// Line := __LINE__
//
// Size := Size of allocation request.
//
// File := Pointer to __FILE__ string stored immediately following
// MY_ALLOC_STRUCT in memory.
//
// Buffer := Pointer to UINT32 aligned storage immediately following
// the NULL terminated __FILE__ string. This is UINT32
// aligned because the underflow signature is 32-bits and
// this will place the first caller address on a 64-bit
// boundary.
//
//
// Signatures used to check for buffer overflow/underflow conditions.
//
#define MYALLOC_HEAD_MAGIK 0xBADFACED
#define MYALLOC_TAIL_MAGIK 0xDEADBEEF
VOID
MyCheck (
BOOLEAN Final,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// Check for corruptions in the allocated memory chain. If a corruption
// is detection program operation stops w/ an exit(1) call.
//
// Parameters:
//
// Final := When FALSE, MyCheck() returns if the allocated memory chain
// has not been corrupted. When TRUE, MyCheck() returns if there
// are no un-freed allocations. If there are un-freed allocations,
// they are displayed and exit(1) is called.
//
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
VOID *
MyAlloc (
UINTN Size,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// Allocate a new link in the allocation chain along with enough storage
// for the File[] string, requested Size and alignment overhead. If
// memory cannot be allocated or the allocation chain has been corrupted,
// exit(1) will be called.
//
// Parameters:
//
// Size := Number of bytes (UINT8) requested by the called.
// Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to the caller's buffer.
//
// --*/
//
VOID *
MyRealloc (
VOID *Ptr,
UINTN Size,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization
// for shrinking or expanding buffers. An invalid parameter will cause
// MyRealloc() to fail with a call to exit(1).
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be re-allocated.
// Ptr cannot be NULL.
//
// Size := Size of new buffer. Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to new caller's buffer.
//
// --*/
//
VOID
MyFree (
VOID *Ptr,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// Release a previously allocated buffer. Invalid parameters will cause
// MyFree() to fail with an exit(1) call.
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be freed.
// A NULL pointer will be ignored.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
#else /* USE_MYALLOC */
//
// Nothing to do when USE_MYALLOC is zero.
//
#define alloc_check(final)
#endif /* USE_MYALLOC */
#endif /* _MYALLOC_H_ */
/* eof - MyAlloc.h */

View File

@ -0,0 +1,630 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ParseInf.c
Abstract:
This contains some useful functions for parsing INF files.
--*/
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "ParseInf.h"
#ifndef _MAX_PATH
#define _MAX_PATH 500
#endif
CHAR8 *
ReadLine (
IN MEMORY_FILE *InputFile,
IN OUT CHAR8 *InputBuffer,
IN UINTN MaxLength
)
/*++
Routine Description:
This function reads a line, stripping any comments.
The function reads a string from the input stream argument and stores it in
the input string. ReadLine reads characters from the current file position
to and including the first newline character, to the end of the stream, or
until the number of characters read is equal to MaxLength - 1, whichever
comes first. The newline character, if read, is replaced with a \0.
Arguments:
InputFile Memory file image.
InputBuffer Buffer to read into, must be _MAX_PATH size.
MaxLength The maximum size of the input buffer.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
{
CHAR8 *CharPtr;
CHAR8 *EndOfLine;
UINTN CharsToCopy;
//
// Verify input parameters are not null
//
assert (InputBuffer);
assert (InputFile->FileImage);
assert (InputFile->Eof);
assert (InputFile->CurrentFilePointer);
//
// Check for end of file condition
//
if (InputFile->CurrentFilePointer >= InputFile->Eof) {
return NULL;
}
//
// Find the next newline char
//
EndOfLine = strchr (InputFile->CurrentFilePointer, '\n');
//
// Determine the number of characters to copy.
//
if (EndOfLine == 0) {
//
// If no newline found, copy to the end of the file.
//
CharsToCopy = InputFile->Eof - InputFile->CurrentFilePointer;
} else if (EndOfLine >= InputFile->Eof) {
//
// If the newline found was beyond the end of file, copy to the eof.
//
CharsToCopy = InputFile->Eof - InputFile->CurrentFilePointer;
} else {
//
// Newline found in the file.
//
CharsToCopy = EndOfLine - InputFile->CurrentFilePointer;
}
//
// If the end of line is too big for the current buffer, set it to the max
// size of the buffer (leaving room for the \0.
//
if (CharsToCopy > MaxLength - 1) {
CharsToCopy = MaxLength - 1;
}
//
// Copy the line.
//
memcpy (InputBuffer, InputFile->CurrentFilePointer, CharsToCopy);
//
// Add the null termination over the 0x0D
//
InputBuffer[CharsToCopy - 1] = '\0';
//
// Increment the current file pointer (include the 0x0A)
//
InputFile->CurrentFilePointer += CharsToCopy + 1;
//
// Strip any comments
//
CharPtr = strstr (InputBuffer, "//");
if (CharPtr != 0) {
CharPtr[0] = 0;
}
//
// Return the string
//
return InputBuffer;
}
BOOLEAN
FindSection (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section
)
/*++
Routine Description:
This function parses a file from the beginning to find a section.
The section string may be anywhere within a line.
Arguments:
InputFile Memory file image.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
{
CHAR8 InputBuffer[_MAX_PATH];
CHAR8 *CurrentToken;
//
// Verify input is not NULL
//
assert (InputFile->FileImage);
assert (InputFile->Eof);
assert (InputFile->CurrentFilePointer);
assert (Section);
//
// Rewind to beginning of file
//
InputFile->CurrentFilePointer = InputFile->FileImage;
//
// Read lines until the section is found
//
while (InputFile->CurrentFilePointer < InputFile->Eof) {
//
// Read a line
//
ReadLine (InputFile, InputBuffer, _MAX_PATH);
//
// Check if the section is found
//
CurrentToken = strstr (InputBuffer, Section);
if (CurrentToken != NULL) {
return TRUE;
}
}
return FALSE;
}
EFI_STATUS
FindToken (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section,
IN CHAR8 *Token,
IN UINTN Instance,
OUT CHAR8 *Value
)
/*++
Routine Description:
Finds a token value given the section and token to search for.
Arguments:
InputFile Memory file image.
Section The section to search for, a string within [].
Token The token to search for, e.g. EFI_PEIM_RECOVERY, followed by an = in the INF file.
Instance The instance of the token to search for. Zero is the first instance.
Value The string that holds the value following the =. Must be _MAX_PATH in size.
Returns:
EFI_SUCCESS Value found.
EFI_ABORTED Format error detected in INF file.
EFI_INVALID_PARAMETER Input argument was null.
EFI_LOAD_ERROR Error reading from the file.
EFI_NOT_FOUND Section/Token/Value not found.
--*/
{
CHAR8 InputBuffer[_MAX_PATH];
CHAR8 *CurrentToken;
BOOLEAN ParseError;
BOOLEAN ReadError;
UINTN Occurrance;
//
// Check input parameters
//
if (InputFile->FileImage == NULL ||
InputFile->Eof == NULL ||
InputFile->CurrentFilePointer == NULL ||
Section == NULL ||
strlen (Section) == 0 ||
Token == NULL ||
strlen (Token) == 0 ||
Value == NULL
) {
return EFI_INVALID_PARAMETER;
}
//
// Initialize error codes
//
ParseError = FALSE;
ReadError = FALSE;
//
// Initialize our instance counter for the search token
//
Occurrance = 0;
if (FindSection (InputFile, Section)) {
//
// Found the desired section, find and read the desired token
//
do {
//
// Read a line from the file
//
if (ReadLine (InputFile, InputBuffer, _MAX_PATH) == NULL) {
//
// Error reading from input file
//
ReadError = TRUE;
break;
}
//
// Get the first non-whitespace string
//
CurrentToken = strtok (InputBuffer, " \t\n");
if (CurrentToken == NULL) {
//
// Whitespace line found (or comment) so continue
//
CurrentToken = InputBuffer;
continue;
}
//
// Make sure we have not reached the end of the current section
//
if (CurrentToken[0] == '[') {
break;
}
//
// Compare the current token with the desired token
//
if (strcmp (CurrentToken, Token) == 0) {
//
// Found it
//
//
// Check if it is the correct instance
//
if (Instance == Occurrance) {
//
// Copy the contents following the =
//
CurrentToken = strtok (NULL, "= \t\n");
if (CurrentToken == NULL) {
//
// Nothing found, parsing error
//
ParseError = TRUE;
} else {
//
// Copy the current token to the output value
//
strcpy (Value, CurrentToken);
return EFI_SUCCESS;
}
} else {
//
// Increment the occurrance found
//
Occurrance++;
}
}
} while (
!ParseError &&
!ReadError &&
InputFile->CurrentFilePointer < InputFile->Eof &&
CurrentToken[0] != '[' &&
Occurrance <= Instance
);
}
//
// Distinguish between read errors and INF file format errors.
//
if (ReadError) {
return EFI_LOAD_ERROR;
}
if (ParseError) {
return EFI_ABORTED;
}
return EFI_NOT_FOUND;
}
EFI_STATUS
StringToGuid (
IN CHAR8 *AsciiGuidBuffer,
OUT EFI_GUID *GuidBuffer
)
/*++
Routine Description:
Converts a string to an EFI_GUID. The string must be in the
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.
Arguments:
AsciiGuidBuffer - pointer to ascii string
GuidBuffer - pointer to destination Guid
Returns:
EFI_ABORTED Could not convert the string
EFI_SUCCESS The string was successfully converted
EFI_INVALID_PARAMETER Input parameter is invalid.
--*/
{
INT32 Index;
UINTN Data1;
UINTN Data2;
UINTN Data3;
UINTN Data4[8];
if (AsciiGuidBuffer == NULL || GuidBuffer == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Scan the guid string into the buffer
//
Index = sscanf (
AsciiGuidBuffer,
"%08x-%04x-%04x-%02x%02x-%02hx%02hx%02hx%02hx%02hx%02hx",
&Data1,
&Data2,
&Data3,
&Data4[0],
&Data4[1],
&Data4[2],
&Data4[3],
&Data4[4],
&Data4[5],
&Data4[6],
&Data4[7]
);
//
// Verify the correct number of items were scanned.
//
if (Index != 11) {
printf ("ERROR: Malformed GUID \"%s\".\n\n", AsciiGuidBuffer);
return EFI_ABORTED;
}
//
// Copy the data into our GUID.
//
GuidBuffer->Data1 = (UINT32) Data1;
GuidBuffer->Data2 = (UINT16) Data2;
GuidBuffer->Data3 = (UINT16) Data3;
GuidBuffer->Data4[0] = (UINT8) Data4[0];
GuidBuffer->Data4[1] = (UINT8) Data4[1];
GuidBuffer->Data4[2] = (UINT8) Data4[2];
GuidBuffer->Data4[3] = (UINT8) Data4[3];
GuidBuffer->Data4[4] = (UINT8) Data4[4];
GuidBuffer->Data4[5] = (UINT8) Data4[5];
GuidBuffer->Data4[6] = (UINT8) Data4[6];
GuidBuffer->Data4[7] = (UINT8) Data4[7];
return EFI_SUCCESS;
}
EFI_STATUS
AsciiStringToUint64 (
IN CONST CHAR8 *AsciiString,
IN BOOLEAN IsHex,
OUT UINT64 *ReturnValue
)
/*++
Routine Description:
Converts a null terminated ascii string that represents a number into a
UINT64 value. A hex number may be preceeded by a 0x, but may not be
succeeded by an h. A number without 0x or 0X is considered to be base 10
unless the IsHex input is true.
Arguments:
AsciiString The string to convert.
IsHex Force the string to be treated as a hex number.
ReturnValue The return value.
Returns:
EFI_SUCCESS Number successfully converted.
EFI_ABORTED Invalid character encountered.
--*/
{
UINT8 Index;
UINT64 HexNumber;
CHAR8 CurrentChar;
//
// Initialize the result
//
HexNumber = 0;
//
// Add each character to the result
//
if (IsHex || (AsciiString[0] == '0' && (AsciiString[1] == 'x' || AsciiString[1] == 'X'))) {
//
// Verify string is a hex number
//
for (Index = 2; Index < strlen (AsciiString); Index++) {
if (isxdigit (AsciiString[Index]) == 0) {
return EFI_ABORTED;
}
}
//
// Convert the hex string.
//
for (Index = 2; AsciiString[Index] != '\0'; Index++) {
CurrentChar = AsciiString[Index];
HexNumber *= 16;
if (CurrentChar >= '0' && CurrentChar <= '9') {
HexNumber += CurrentChar - '0';
} else if (CurrentChar >= 'a' && CurrentChar <= 'f') {
HexNumber += CurrentChar - 'a' + 10;
} else if (CurrentChar >= 'A' && CurrentChar <= 'F') {
HexNumber += CurrentChar - 'A' + 10;
} else {
//
// Unrecognized character
//
return EFI_ABORTED;
}
}
*ReturnValue = HexNumber;
} else {
//
// Verify string is a number
//
for (Index = 0; Index < strlen (AsciiString); Index++) {
if (isdigit (AsciiString[Index]) == 0) {
return EFI_ABORTED;
}
}
*ReturnValue = atol (AsciiString);
}
return EFI_SUCCESS;
};
CHAR8 *
ReadLineInStream (
IN FILE *InputFile,
IN OUT CHAR8 *InputBuffer
)
/*++
Routine Description:
This function reads a line, stripping any comments.
// BUGBUG: This is obsolete once genmake goes away...
Arguments:
InputFile Stream pointer.
InputBuffer Buffer to read into, must be _MAX_PATH size.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
{
CHAR8 *CharPtr;
//
// Verify input parameters are not null
//
assert (InputFile);
assert (InputBuffer);
//
// Read a line
//
if (fgets (InputBuffer, _MAX_PATH, InputFile) == NULL) {
return NULL;
}
//
// Strip any comments
//
CharPtr = strstr (InputBuffer, "//");
if (CharPtr != 0) {
CharPtr[0] = 0;
}
CharPtr = strstr (InputBuffer, "#");
if (CharPtr != 0) {
CharPtr[0] = 0;
}
//
// Return the string
//
return InputBuffer;
}
BOOLEAN
FindSectionInStream (
IN FILE *InputFile,
IN CHAR8 *Section
)
/*++
Routine Description:
This function parses a stream file from the beginning to find a section.
The section string may be anywhere within a line.
// BUGBUG: This is obsolete once genmake goes away...
Arguments:
InputFile Stream pointer.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
{
CHAR8 InputBuffer[_MAX_PATH];
CHAR8 *CurrentToken;
//
// Verify input is not NULL
//
assert (InputFile);
assert (Section);
//
// Rewind to beginning of file
//
if (fseek (InputFile, 0, SEEK_SET) != 0) {
return FALSE;
}
//
// Read lines until the section is found
//
while (feof (InputFile) == 0) {
//
// Read a line
//
ReadLineInStream (InputFile, InputBuffer);
//
// Check if the section is found
//
CurrentToken = strstr (InputBuffer, Section);
if (CurrentToken != NULL) {
return TRUE;
}
}
return FALSE;
}

View File

@ -0,0 +1,234 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ParseInf.h
Abstract:
Header file for helper functions useful for parsing INF files.
--*/
#ifndef _EFI_PARSE_INF_H
#define _EFI_PARSE_INF_H
#include <stdio.h>
#include <stdlib.h>
#include <Common/UefiBaseTypes.h>
//
// Common data structures
//
typedef struct {
CHAR8 *FileImage;
CHAR8 *Eof;
CHAR8 *CurrentFilePointer;
} MEMORY_FILE;
//
// Functions declarations
//
CHAR8 *
ReadLine (
IN MEMORY_FILE *InputFile,
IN OUT CHAR8 *InputBuffer,
IN UINTN MaxLength
)
;
/*++
Routine Description:
This function reads a line, stripping any comments.
The function reads a string from the input stream argument and stores it in
the input string. ReadLine reads characters from the current file position
to and including the first newline character, to the end of the stream, or
until the number of characters read is equal to MaxLength - 1, whichever
comes first. The newline character, if read, is replaced with a \0.
Arguments:
InputFile Memory file image.
InputBuffer Buffer to read into, must be _MAX_PATH size.
MaxLength The maximum size of the input buffer.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
BOOLEAN
FindSection (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section
)
;
/*++
Routine Description:
This function parses a file from the beginning to find a section.
The section string may be anywhere within a line.
Arguments:
InputFile Memory file image.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
EFI_STATUS
FindToken (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section,
IN CHAR8 *Token,
IN UINTN Instance,
OUT CHAR8 *Value
)
;
/*++
Routine Description:
Finds a token value given the section and token to search for.
Arguments:
InputFile Memory file image.
Section The section to search for, a string within [].
Token The token to search for, e.g. EFI_PEIM_RECOVERY, followed by an = in the INF file.
Instance The instance of the token to search for. Zero is the first instance.
Value The string that holds the value following the =. Must be _MAX_PATH in size.
Returns:
EFI_SUCCESS Value found.
EFI_ABORTED Format error detected in INF file.
EFI_INVALID_PARAMETER Input argument was null.
EFI_LOAD_ERROR Error reading from the file.
EFI_NOT_FOUND Section/Token/Value not found.
--*/
EFI_STATUS
StringToGuid (
IN CHAR8 *AsciiGuidBuffer,
OUT EFI_GUID *GuidBuffer
)
;
/*++
Routine Description:
Converts a string to an EFI_GUID. The string must be in the
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.
Arguments:
GuidBuffer - pointer to destination Guid
AsciiGuidBuffer - pointer to ascii string
Returns:
EFI_ABORTED Could not convert the string
EFI_SUCCESS The string was successfully converted
--*/
EFI_STATUS
AsciiStringToUint64 (
IN CONST CHAR8 *AsciiString,
IN BOOLEAN IsHex,
OUT UINT64 *ReturnValue
)
;
/*++
Routine Description:
Converts a null terminated ascii string that represents a number into a
UINT64 value. A hex number may be preceeded by a 0x, but may not be
succeeded by an h. A number without 0x or 0X is considered to be base 10
unless the IsHex input is true.
Arguments:
AsciiString The string to convert.
IsHex Force the string to be treated as a hex number.
ReturnValue The return value.
Returns:
EFI_SUCCESS Number successfully converted.
EFI_ABORTED Invalid character encountered.
--*/
CHAR8 *
ReadLineInStream (
IN FILE *InputFile,
IN OUT CHAR8 *InputBuffer
)
;
/*++
Routine Description:
This function reads a line, stripping any comments.
Arguments:
InputFile Stream pointer.
InputBuffer Buffer to read into, must be _MAX_PATH size.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
BOOLEAN
FindSectionInStream (
IN FILE *InputFile,
IN CHAR8 *Section
)
;
/*++
Routine Description:
This function parses a stream file from the beginning to find a section.
The section string may be anywhere within a line.
Arguments:
InputFile Stream pointer.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SimpleFileParsing.h
Abstract:
Function prototypes and defines for the simple file parsing routines.
--*/
#ifndef _SIMPLE_FILE_PARSING_H_
#define _SIMPLE_FILE_PARSING_H_
#include <Common/UefiBaseTypes.h>
#define T_CHAR char
STATUS
SFPInit (
VOID
)
;
STATUS
SFPOpenFile (
char *FileName
)
;
BOOLEAN
SFPIsKeyword (
T_CHAR *Str
)
;
BOOLEAN
SFPIsToken (
T_CHAR *Str
)
;
BOOLEAN
SFPGetNextToken (
T_CHAR *Str,
unsigned int Len
)
;
BOOLEAN
SFPGetGuidToken (
T_CHAR *Str,
UINT32 Len
)
;
#define PARSE_GUID_STYLE_5_FIELDS 0
BOOLEAN
SFPGetGuid (
int GuidStyle,
EFI_GUID *Value
)
;
BOOLEAN
SFPSkipToToken (
T_CHAR *Str
)
;
BOOLEAN
SFPGetNumber (
unsigned int *Value
)
;
BOOLEAN
SFPGetQuotedString (
T_CHAR *Str,
int Length
)
;
BOOLEAN
SFPIsEOF (
VOID
)
;
STATUS
SFPCloseFile (
VOID
)
;
unsigned
int
SFPGetLineNumber (
VOID
)
;
T_CHAR *
SFPGetFileName (
VOID
)
;
#endif // #ifndef _SIMPLE_FILE_PARSING_H_

View File

@ -0,0 +1,73 @@
/*--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
WinNtInclude.h
Abstract:
Include file for the WinNt Library
--*/
#ifndef __WIN_NT_INCLUDE_H__
#define __WIN_NT_INCLUDE_H__
//
// Win32 include files do not compile clean with /W4, so we use the warning
// pragma to suppress the warnings for Win32 only. This way our code can stil
// compile at /W4 (highest warning level) with /WX (warnings cause build
// errors).
//
#pragma warning(disable : 4115)
#pragma warning(disable : 4201)
#pragma warning(disable : 4214)
#pragma warning(disable : 4028)
#pragma warning(disable : 4133)
#define GUID _WINNT_DUP_GUID_____
#define _LIST_ENTRY _WINNT_DUP_LIST_ENTRY_FORWARD
#define LIST_ENTRY _WINNT_DUP_LIST_ENTRY
#define InterlockedIncrement _WINNT_DUP_InterlockedIncrement
#define InterlockedDecrement _WINNT_DUP_InterlockedDecrement
#define InterlockedCompareExchange64 _WINNT_DUP_InterlockedCompareExchange64
#undef UNALIGNED
#undef CONST
#undef VOID
#ifndef __GNUC__
#include "windows.h"
#endif
#undef GUID
#undef _LIST_ENTRY
#undef LIST_ENTRY
#undef InterlockedIncrement
#undef InterlockedDecrement
#undef InterlockedCompareExchange64
#undef InterlockedCompareExchangePointer
#define VOID void
//
// Prevent collisions with Windows API name macros that deal with Unicode/Not issues
//
#undef LoadImage
#undef CreateEvent
//
// Set the warnings back on as the EFI code must be /W4.
//
#pragma warning(default : 4115)
#pragma warning(default : 4201)
#pragma warning(default : 4214)
#endif

View File

@ -0,0 +1,67 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="CommonTools.lib" basedir=".">
<!--
EDK Common Tools Library
Copyright (c) 2006, Intel Corporation
-->
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="tmp" value="tmp"/>
<property name="LibName" value="CommonTool"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/Common/tmp"/>
<target name="CommonTools.lib" depends="init, ToolsLibrary">
<echo message="The EDK Tool Library: ${LibName} build has completed."/>
</target>
<target name="init">
<echo message="Building the EDK Tool Library: ${LibName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="ToolsLibrary" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${LIB_DIR}/CommonTools"
outtype="static"
debug="true"
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<compilerarg value="-fPIC" if="x86_64_linux"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<fileset dir="${basedir}/Common"
includes="*.c" />
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only from ${BUILD_DIR}"/>
<delete dir="${BUILD_DIR}"/>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Library: ${LibName}${ext_static}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${LIB_DIR}/${LibName}${ext_static}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,105 @@
/** @file
Compression DLL used by PCD Tools
Copyright (c) 2006, Intel Corporation All rights reserved.
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#if defined(__GNUC__)
typedef long long __int64;/*For cygwin build*/
#endif
#include "CompressDll.h"
#include "EfiCompress.h"
extern
EFI_STATUS
Compress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
);
JNIEXPORT jbyteArray JNICALL Java_org_tianocore_framework_tasks_Compress_CallCompress
(JNIEnv *env, jobject obj, jbyteArray SourceBuffer, jint SourceSize, jstring path)
{
char* DestBuffer;
int DestSize;
int Result;
char *InputBuffer;
jbyteArray OutputBuffer;
jbyte *TempByte;
DestSize = 0;
DestBuffer = NULL;
TempByte = (*env)->GetByteArrayElements(env, SourceBuffer, 0);
InputBuffer = (char*) TempByte;
//
// First call compress function and get need buffer size
//
Result = Compress (
(char*) InputBuffer,
SourceSize,
DestBuffer,
&DestSize
);
if (Result = EFI_BUFFER_TOO_SMALL) {
DestBuffer = malloc (DestSize);
}
//
// Second call compress and get the DestBuffer value
//
Result = Compress(
(char*) InputBuffer,
SourceSize,
DestBuffer,
&DestSize
);
//
// new a MV array to store the return compressed buffer
//
OutputBuffer = (*env)->NewByteArray(env, DestSize);
(*env)->SetByteArrayRegion(env, OutputBuffer,0, DestSize, (jbyte*) DestBuffer);
//
// Free Ouputbuffer.
//
free (DestBuffer);
if (Result != 0) {
return NULL;
} else {
return OutputBuffer;
}
}
#ifdef _MSC_VER
BOOLEAN
__stdcall
DllMainCRTStartup(
unsigned int hDllHandle,
unsigned int nReason,
void* Reserved
)
{
return TRUE;
}
#else
#ifdef __GNUC__
#endif
#endif

View File

@ -0,0 +1,22 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_tianocore_frameworktasks_Compress */
#ifndef _Included_org_tianocore_framework_tasks_Compress
#define _Included_org_tianocore_framework_tasks_Compress
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_tianocore_frameworktasks_Compress
* Method: CallCompress
* Signature: ([BILjava/lang/String;)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_tianocore_framework_tasks_Compress_CallCompress
(JNIEnv *, jobject, jbyteArray, jint, jstring);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK CompressDll Tool Library
Copyright (c) 2006, Intel Corporation
-->
<property name="WORKSPACE" value="${env.WORKSPACE}"/>
<property name="LibName" value="CompressDll"/>
<property name="FileSet" value="CompressDll.c CompressDll.h"/>
<property name="LibFileSet" value="CompressDll.c DepexParser.h"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${WORKSPACE}/Tools/Source/TianoTools/${LibName}/tmp"/>
<target name="GenTool" depends="init,Lib" >
<echo message="The EDK Tool Library: ${LibName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool Library: ${LibName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Lib" depends="init">
<cc name="${ToolChain}"
objdir="${BUILD_DIR}"
outtype="shared"
debug="true"
optimize="speed"
outfile="${BIN_DIR}/${LibName}"
outputfileproperty="result"
>
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${LibName}" includes="${LibFileSet}" defaultexcludes="TRUE" excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<includepath path="${env.JAVA_HOME}/include"/>
<includepath path="${env.JAVA_HOME}/include/linux" if="gcc"/>
<includepath path="${env.JAVA_HOME}/include/win32" if="cygwin"/>
<includepath path="${env.JAVA_HOME}/include/win32" if="msft"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
<syslibset libs="kernel32" if="msft"/>
<linkerarg value="-mno-cygwin" if="cygwin"/>
<linkerarg value="--add-stdcall-alias" if="cygwin"/>
</cc>
<copy file="${result}" tofile="${BIN_DIR}/CompressDll.dll"/>
<chmod file="${BIN_DIR}/CompressDll.dll" perm="ugo+x"/>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${LibName}${ext_shared}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${LibName}.*"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,247 @@
/*++
Copyright (c) 1999-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CreateMtFile.c
Abstract:
Simple utility to create a pad file containing fixed data.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Common/UefiBaseTypes.h>
#define PROGRAM_NAME "CreateMtFile"
typedef struct {
INT8 *OutFileName;
INT8 ByteValue;
UINT32 FileSize;
} OPTIONS;
static
EFI_STATUS
ProcessArgs (
IN INT32 Argc,
IN INT8 *Argv[],
IN OUT OPTIONS *Options
);
static
void
Usage (
VOID
);
int
main (
IN INT32 Argc,
IN INT8 *Argv[]
)
/*++
Routine Description:
Main entry point for this utility.
Arguments:
Standard C entry point args Argc and Argv
Returns:
EFI_SUCCESS if good to go
--*/
// GC_TODO: ] - add argument and description to function comment
// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
{
FILE *OutFptr;
OPTIONS Options;
//
// Process the command-line arguments.
//
if (ProcessArgs (Argc, Argv, &Options) != EFI_SUCCESS) {
return EFI_INVALID_PARAMETER;
}
//
// Open the output file
//
if ((OutFptr = fopen (Options.OutFileName, "wb")) == NULL) {
fprintf (
stdout,
PROGRAM_NAME " ERROR: Could not open output file '%s' for writing\n",
Options.OutFileName
);
return EFI_DEVICE_ERROR;
}
//
// Write the pad bytes. Do it the slow way (one at a time) for now.
//
while (Options.FileSize > 0) {
if (fwrite (&Options.ByteValue, 1, 1, OutFptr) != 1) {
fclose (OutFptr);
fprintf (stdout, PROGRAM_NAME " ERROR: Failed to write to output file\n");
return EFI_DEVICE_ERROR;
}
Options.FileSize--;
}
//
// Close the file
//
fclose (OutFptr);
return EFI_SUCCESS;
}
static
EFI_STATUS
ProcessArgs (
IN INT32 Argc,
IN INT8 *Argv[],
IN OUT OPTIONS *Options
)
/*++
Routine Description:
Process the command line arguments.
Arguments:
Argc - argument count as passed in to the entry point function
Argv - array of arguments as passed in to the entry point function
Options - stucture of where to put the values of the parsed arguments
Returns:
EFI_SUCCESS if everything looks good
EFI_INVALID_PARAMETER otherwise
--*/
// GC_TODO: ] - add argument and description to function comment
{
UINT32 Multiplier;
//
// Clear the options
//
memset ((char *) Options, 0, sizeof (OPTIONS));
//
// Skip program name
//
Argv++;
Argc--;
if (Argc < 2) {
Usage ();
return EFI_INVALID_PARAMETER;
}
//
// If first arg is dash-option, then print usage.
//
if (Argv[0][0] == '-') {
Usage ();
return EFI_INVALID_PARAMETER;
}
//
// First arg is file name
//
Options->OutFileName = Argv[0];
Argc--;
Argv++;
//
// Second arg is file size. Allow 0x1000, 0x100K, 1024, 1K
//
Multiplier = 1;
if ((Argv[0][strlen (Argv[0]) - 1] == 'k') || (Argv[0][strlen (Argv[0]) - 1] == 'K')) {
Multiplier = 1024;
}
//
// Look for 0x prefix on file size
//
if ((Argv[0][0] == '0') && ((Argv[0][1] == 'x') || (Argv[0][1] == 'X'))) {
if (sscanf (Argv[0], "%x", &Options->FileSize) != 1) {
fprintf (stdout, PROGRAM_NAME " ERROR: Invalid file size '%s'\n", Argv[0]);
Usage ();
return EFI_INVALID_PARAMETER;
}
//
// Otherwise must be a decimal number
//
} else {
if (sscanf (Argv[0], "%d", &Options->FileSize) != 1) {
fprintf (stdout, PROGRAM_NAME " ERROR: Invalid file size '%s'\n", Argv[0]);
Usage ();
return EFI_INVALID_PARAMETER;
}
}
Options->FileSize *= Multiplier;
//
// Assume byte value of 0xff
//
Options->ByteValue = (INT8) (UINT8) 0xFF;
return EFI_SUCCESS;
}
//
// Print utility usage info
//
static
void
Usage (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
{
UINT32 Index;
static const INT8 *Text[] = {
" ",
"Usage: "PROGRAM_NAME " OutFileName FileSize",
" where:",
" OutFileName is the name of the output file to generate",
" FileSize is the size of the file to create",
" Examples:",
" "PROGRAM_NAME " OutFile.bin 32K",
" "PROGRAM_NAME " OutFile.bin 0x1000",
" ",
NULL
};
for (Index = 0; Text[Index] != NULL; Index++) {
fprintf (stdout, "%s\n", Text[Index]);
}
}

View File

@ -0,0 +1,70 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK CreateMtFile Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="CreateMtFile"/>
<property name="FileSet" value="*.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
optimize="speed"
debug="true">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/Ia32"/>
<includepath path="${PACKAGE_DIR}/Common"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,146 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CustomizedCompress.c
Abstract:
Header file for Customized compression routine
--*/
#include <Common/UefiBaseTypes.h>
EFI_STATUS
SetCustomizedCompressionType (
IN CHAR8 *Type
)
/*++
Routine Description:
The implementation of Customized SetCompressionType().
Arguments:
Type - The type if compression.
Returns:
EFI_SUCCESS - The type has been set.
EFI_UNSUPPORTED - This type is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
CustomizedGetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The implementation of Customized GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
EFI_UNSUPPORTED - The operation is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
CustomizedDecompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
/*++
Routine Description:
The implementation of Customized Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
EFI_UNSUPPORTED - The operation is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
CustomizedCompress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
)
/*++
Routine Description:
The Customized compression routine.
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
DstBuffer - The buffer to store the compressed data
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case,
DstSize contains the size needed.
EFI_SUCCESS - Compression is successful.
EFI_UNSUPPORTED - The operation is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}

View File

@ -0,0 +1,75 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenLib" basedir="." name="CustomizedCompressLibrary">
<!--
EDK Customized Compress Library
Copyright (c) 2006, Intel Corporation
-->
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LibName" value="CustomizedCompress"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/CustomizedCompress/tmp"/>
<target name="GenLib" depends="init, CustomizedCompress">
<echo message="The EDK Tool Library ${LibName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool Library: ${LibName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="CustomizedCompress" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${LIB_DIR}/${LibName}"
outtype="static"
debug="true"
optimize="speed">
<fileset dir="${basedir}/CustomizedCompress"
includes="*.c"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/Ia32"/>
</cc>
<if>
<istrue value="msft"/>
<then>
<exec dir="${BUILD_DIR}" executable="lib" failonerror="false">
<arg line="/NOLOGO *.lib /OUT:${LIB_DIR}/CustomizedCompress${ext_static}"/>
</exec>
</then>
</if>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Library: ${LibName}${ext_static}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${LIB_DIR}/${LibName}${ext_static}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,165 @@
/*++
Copyright (c) 1999-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiCompressMain.c
Abstract:
The main function for the compression utility.
--*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <Common/UefiBaseTypes.h>
#include "EfiCompress.h"
int
main (
INT32 argc,
CHAR8 *argv[]
)
/*++
Routine Description:
Compresses the input files
Arguments:
argc - number of arguments passed into the command line.
argv[] - files to compress and files to output compressed data to.
Returns:
int: 0 for successful execution of the function.
--*/
{
EFI_STATUS Status;
FILE *infile;
FILE *outfile;
UINT32 SrcSize;
UINT32 DstSize;
UINT8 *SrcBuffer;
UINT8 *DstBuffer;
UINT8 Buffer[8];
//
// Added for makefile debug - KCE
//
INT32 arg_counter;
printf ("\n\n");
for (arg_counter = 0; arg_counter < argc; arg_counter++) {
printf ("%s ", argv[arg_counter]);
}
printf ("\n\n");
SrcBuffer = DstBuffer = NULL;
infile = outfile = NULL;
if (argc != 3) {
printf ("Usage: EFICOMPRESS <infile> <outfile>\n");
goto Done;
}
if ((outfile = fopen (argv[2], "wb")) == NULL) {
printf ("Can't open output file\n");
goto Done;
}
if ((infile = fopen (argv[1], "rb")) == NULL) {
printf ("Can't open input file\n");
goto Done;
}
//
// Get the size of source file
//
SrcSize = 0;
while (fread (Buffer, 1, 1, infile)) {
SrcSize++;
}
//
// Read in the source data
//
if ((SrcBuffer = malloc (SrcSize)) == NULL) {
printf ("Can't allocate memory\n");
goto Done;
}
rewind (infile);
if (fread (SrcBuffer, 1, SrcSize, infile) != SrcSize) {
printf ("Can't read from source\n");
goto Done;
}
//
// Get destination data size and do the compression
//
DstSize = 0;
Status = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);
if (Status == EFI_BUFFER_TOO_SMALL) {
if ((DstBuffer = malloc (DstSize)) == NULL) {
printf ("Can't allocate memory\n");
goto Done;
}
Status = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);
}
if (EFI_ERROR (Status)) {
printf ("Compress Error\n");
goto Done;
}
printf ("\nOrig Size = %ld\n", SrcSize);
printf ("Comp Size = %ld\n", DstSize);
if (DstBuffer == NULL) {
printf ("No destination to write to.\n");
goto Done;
}
//
// Write out the result
//
if (fwrite (DstBuffer, 1, DstSize, outfile) != DstSize) {
printf ("Can't write to destination file\n");
}
Done:
if (SrcBuffer) {
free (SrcBuffer);
}
if (DstBuffer) {
free (DstBuffer);
}
if (infile) {
fclose (infile);
}
if (outfile) {
fclose (outfile);
}
return 0;
}

View File

@ -0,0 +1,70 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK EfiCompress Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="EfiCompress"/>
<property name="FileSet" value="*.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
optimize="speed"
debug="true">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK EfiRom Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="EfiRom"/>
<property name="FileSet" value="*.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
optimize="speed"
debug="true">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,281 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FlashDefFile.h
Abstract:
Header file for flash management utility in the Intel Platform
Innovation Framework for EFI build environment.
--*/
#ifndef _FLASH_DEF_FILE_H_
#define _FLASH_DEF_FILE_H_
#ifdef __cplusplus
extern "C"
{
#endif
void
FDFConstructor (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
;
void
FDFDestructor (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFParseFile (
char *FileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFCreateCIncludeFile (
char *FlashDeviceName,
char *FileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FlashDeviceName - GC_TODO: add argument description
FileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFCreateCFlashMapDataFile (
char *FlashDeviceName,
char *FileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FlashDeviceName - GC_TODO: add argument description
FileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFCreateAsmIncludeFile (
char *FlashDeviceName,
char *FileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FlashDeviceName - GC_TODO: add argument description
FileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFParseFile (
char *FileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFCreateImage (
char *FlashDeviceName,
char *ImageName,
char *FileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FlashDeviceName - GC_TODO: add argument description
ImageName - GC_TODO: add argument description
FileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFCreateDscFile (
char *FlashDeviceName,
char *FileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FlashDeviceName - GC_TODO: add argument description
FileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDFCreateSymbols (
char *FlashDeviceName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FlashDeviceName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
FDDiscover (
char *FDFileName,
unsigned int BaseAddr
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FDFileName - GC_TODO: add argument description
BaseAddr - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
#ifdef __cplusplus
}
#endif
#endif // #ifndef _FLASH_DEF_FILE_H_

View File

@ -0,0 +1,769 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FlashMap.c
Abstract:
Utility for flash management in the Intel Platform Innovation Framework
for EFI build environment.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <Common/UefiBaseTypes.h>
#include "EfiUtilityMsgs.h"
#include "Microcode.h"
#include "FlashDefFile.h"
#include "Symbols.h"
#define UTILITY_NAME "FlashMap"
typedef struct _STRING_LIST {
struct _STRING_LIST *Next;
char *Str;
} STRING_LIST;
//
// Keep our globals in one of these structures
//
static struct {
char *CIncludeFileName;
char *FlashDevice;
char *FlashDeviceImage;
char *MCIFileName;
char *MCOFileName;
char *ImageOutFileName;
char *DscFileName;
char *AsmIncludeFileName;
char *FlashDefinitionFileName;
char *StringReplaceInFileName;
char *StringReplaceOutFileName;
char *DiscoverFDImageName;
char MicrocodePadByteValue;
unsigned int MicrocodeAlignment;
STRING_LIST *MCIFileNames;
STRING_LIST *LastMCIFileNames;
unsigned int BaseAddress;
} mGlobals;
#define DEFAULT_MC_PAD_BYTE_VALUE 0xFF
#define DEFAULT_MC_ALIGNMENT 16
static
STATUS
ProcessCommandLine (
int argc,
char *argv[]
);
static
STATUS
MergeMicrocodeFiles (
char *OutFileName,
STRING_LIST *FileNames,
unsigned int Alignment,
char PadByteValue
);
static
void
Usage (
VOID
);
char*
NormalizePath (
char* OldPathName
);
int
main (
int argc,
char *argv[]
)
/*++
Routine Description:
Parse the command line arguments and then call worker functions to do the work
Arguments:
argc - number of elements in argv
argv - array of command-line arguments
Returns:
STATUS_SUCCESS - no problems encountered while processing
STATUS_WARNING - warnings, but no errors, were encountered while processing
STATUS_ERROR - errors were encountered while processing
--*/
{
STATUS Status;
SetUtilityName (UTILITY_NAME);
Status = ProcessCommandLine (argc, argv);
if (Status != STATUS_SUCCESS) {
return Status;
}
//
// Check for discovery of an FD (command line option)
//
if (mGlobals.DiscoverFDImageName != NULL) {
Status = FDDiscover (mGlobals.DiscoverFDImageName, mGlobals.BaseAddress);
goto Done;
}
//
// If they're doing microcode file parsing, then do that
//
if (mGlobals.MCIFileName != NULL) {
MicrocodeConstructor ();
MicrocodeParseFile (mGlobals.MCIFileName, mGlobals.MCOFileName);
MicrocodeDestructor ();
}
//
// If they're doing microcode file merging, then do that now
//
if (mGlobals.MCIFileNames != NULL) {
MergeMicrocodeFiles (
mGlobals.MCOFileName,
mGlobals.MCIFileNames,
mGlobals.MicrocodeAlignment,
mGlobals.MicrocodePadByteValue
);
}
//
// If using a flash definition file, then process that and return
//
if (mGlobals.FlashDefinitionFileName != NULL) {
FDFConstructor ();
SymbolsConstructor ();
Status = FDFParseFile (mGlobals.FlashDefinitionFileName);
if (GetUtilityStatus () != STATUS_ERROR) {
//
// If they want us to do a string-replace on a file, then add the symbol definitions to
// the symbol table, and then do the string replace.
//
if (mGlobals.StringReplaceInFileName != NULL) {
Status = FDFCreateSymbols (mGlobals.FlashDevice);
Status = SymbolsFileStringsReplace (mGlobals.StringReplaceInFileName, mGlobals.StringReplaceOutFileName);
}
//
// If they want us to create a .h defines file or .c flashmap data file, then do so now
//
if (mGlobals.CIncludeFileName != NULL) {
Status = FDFCreateCIncludeFile (mGlobals.FlashDevice, mGlobals.CIncludeFileName);
}
if (mGlobals.AsmIncludeFileName != NULL) {
Status = FDFCreateAsmIncludeFile (mGlobals.FlashDevice, mGlobals.AsmIncludeFileName);
}
//
// If they want us to create an image, do that now
//
if (mGlobals.ImageOutFileName != NULL) {
Status = FDFCreateImage (mGlobals.FlashDevice, mGlobals.FlashDeviceImage, mGlobals.ImageOutFileName);
}
//
// If they want to create an output DSC file, do that now
//
if (mGlobals.DscFileName != NULL) {
Status = FDFCreateDscFile (mGlobals.FlashDevice, mGlobals.DscFileName);
}
}
SymbolsDestructor ();
FDFDestructor ();
}
Done:
//
// Free up memory
//
while (mGlobals.MCIFileNames != NULL) {
mGlobals.LastMCIFileNames = mGlobals.MCIFileNames->Next;
_free (mGlobals.MCIFileNames);
mGlobals.MCIFileNames = mGlobals.LastMCIFileNames;
}
return GetUtilityStatus ();
}
static
STATUS
MergeMicrocodeFiles (
char *OutFileName,
STRING_LIST *FileNames,
unsigned int Alignment,
char PadByteValue
)
/*++
Routine Description:
Merge binary microcode files into a single file, taking into consideration
the alignment and pad value.
Arguments:
OutFileName - name of the output file to create
FileNames - linked list of input microcode files to merge
Alignment - alignment for each microcode file in the output image
PadByteValue - value to use when padding to meet alignment requirements
Returns:
STATUS_SUCCESS - merge completed successfully or with acceptable warnings
STATUS_ERROR - merge failed, output file not created
--*/
{
long FileSize;
long TotalFileSize;
FILE *InFptr;
FILE *OutFptr;
char *Buffer;
STATUS Status;
//
// Open the output file
//
if ((OutFptr = fopen (OutFileName, "wb")) == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
return STATUS_ERROR;
}
//
// Walk the list of files
//
Status = STATUS_ERROR;
Buffer = NULL;
InFptr = NULL;
TotalFileSize = 0;
while (FileNames != NULL) {
//
// Open the file, determine the size, then read it in and write
// it back out.
//
if ((InFptr = fopen (NormalizePath(FileNames->Str), "rb")) == NULL) {
Error (NULL, 0, 0, NormalizePath(FileNames->Str), "failed to open input file for reading");
goto Done;
}
fseek (InFptr, 0, SEEK_END);
FileSize = ftell (InFptr);
fseek (InFptr, 0, SEEK_SET);
if (FileSize != 0) {
Buffer = (char *) _malloc (FileSize);
if (Buffer == NULL) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
goto Done;
}
if (fread (Buffer, FileSize, 1, InFptr) != 1) {
Error (NULL, 0, 0, FileNames->Str, "failed to read file contents");
goto Done;
}
//
// Align
//
if (Alignment != 0) {
while ((TotalFileSize % Alignment) != 0) {
if (fwrite (&PadByteValue, 1, 1, OutFptr) != 1) {
Error (NULL, 0, 0, OutFileName, "failed to write pad bytes to output file");
goto Done;
}
TotalFileSize++;
}
}
TotalFileSize += FileSize;
if (fwrite (Buffer, FileSize, 1, OutFptr) != 1) {
Error (NULL, 0, 0, OutFileName, "failed to write to output file");
goto Done;
}
_free (Buffer);
Buffer = NULL;
} else {
Warning (NULL, 0, 0, FileNames->Str, "0-size file encountered");
}
fclose (InFptr);
InFptr = NULL;
FileNames = FileNames->Next;
}
Status = STATUS_SUCCESS;
Done:
fclose (OutFptr);
if (InFptr != NULL) {
fclose (InFptr);
}
if (Buffer != NULL) {
_free (Buffer);
}
if (Status == STATUS_ERROR) {
remove (OutFileName);
}
return Status;
}
static
STATUS
ProcessCommandLine (
int argc,
char *argv[]
)
/*++
Routine Description:
Process the command line arguments
Arguments:
argc - Standard C entry point arguments
argv[] - Standard C entry point arguments
Returns:
STATUS_SUCCESS - no problems encountered while processing
STATUS_WARNING - warnings, but no errors, were encountered while processing
STATUS_ERROR - errors were encountered while processing
--*/
{
int ThingsToDo;
unsigned int Temp;
STRING_LIST *Str;
//
// Skip program name arg, process others
//
argc--;
argv++;
if (argc == 0) {
Usage ();
return STATUS_ERROR;
}
//
// Clear out our globals, then start walking the arguments
//
memset ((void *) &mGlobals, 0, sizeof (mGlobals));
mGlobals.MicrocodePadByteValue = DEFAULT_MC_PAD_BYTE_VALUE;
mGlobals.MicrocodeAlignment = DEFAULT_MC_ALIGNMENT;
ThingsToDo = 0;
while (argc > 0) {
if (strcmp (argv[0], "-?") == 0) {
Usage ();
return STATUS_ERROR;
} else if (strcmp (argv[0], "-hfile") == 0) {
//
// -hfile FileName
//
// Used to specify an output C #include file to create that contains
// #define statements for all the flashmap region offsets and sizes.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires an output file name");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.CIncludeFileName = argv[0];
ThingsToDo++;
} else if (strcmp (argv[0], "-flashdevice") == 0) {
//
// -flashdevice FLASH_DEVICE_NAME
//
// Used to select which flash device definition to operate on.
// Check for additional argument
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires a flash device name to use");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.FlashDevice = argv[0];
} else if (strcmp (argv[0], "-mco") == 0) {
//
// -mco OutFileName
//
// Used to specify a microcode output binary file to create.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, (INT8 *) argv[0], (INT8 *) "option requires an output microcode file name to create");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.MCOFileName = argv[0];
ThingsToDo++;
} else if (strcmp (argv[0], "-asmincfile") == 0) {
//
// -asmincfile FileName
//
// Used to specify the name of the output assembly include file that contains
// equates for the flash region addresses and sizes.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires an output ASM include file name to create");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.AsmIncludeFileName = argv[0];
ThingsToDo++;
} else if (strcmp (argv[0], "-mci") == 0) {
//
// -mci FileName
//
// Used to specify an input microcode text file to parse.
// Check for additional argument
//
if (argc < 2) {
Error (NULL, 0, 0, (INT8 *) argv[0], (INT8 *) "option requires an input microcode text file name to parse");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.MCIFileName = argv[0];
} else if (strcmp (argv[0], "-flashdeviceimage") == 0) {
//
// -flashdeviceimage FlashDeviceImage
//
// Used to specify which flash device image definition from the input flash definition file
// to create.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires the name of a flash definition image to use");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.FlashDeviceImage = argv[0];
} else if (strcmp (argv[0], "-imageout") == 0) {
//
// -imageout FileName
//
// Used to specify the name of the output FD image file to create.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires an output image filename to create");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.ImageOutFileName = argv[0];
ThingsToDo++;
} else if (strcmp (argv[0], "-dsc") == 0) {
//
// -dsc FileName
//
// Used to specify the name of the output DSC file to create.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires an output DSC filename to create");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.DscFileName = argv[0];
ThingsToDo++;
} else if (strcmp (argv[0], "-fdf") == 0) {
//
// -fdf FileName
//
// Used to specify the name of the input flash definition file.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires an input flash definition file name");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.FlashDefinitionFileName = argv[0];
} else if (strcmp (argv[0], "-discover") == 0) {
//
// -discover FDFileName
//
// Debug functionality used to scan an existing FD image, trying to find
// firmware volumes at 64K boundaries.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires an input FD image file name");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.DiscoverFDImageName = argv[0];
ThingsToDo++;
} else if (strcmp (argv[0], "-baseaddr") == 0) {
//
// -baseaddr Addr
//
// Used to specify a base address when doing a discover of an FD image.
// Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires a base address");
return STATUS_ERROR;
}
argc--;
argv++;
if (tolower (argv[0][1]) == 'x') {
sscanf (argv[0] + 2, "%x", &mGlobals.BaseAddress);
} else {
sscanf (argv[0], "%d", &mGlobals.BaseAddress);
}
} else if (strcmp (argv[0], "-padvalue") == 0) {
//
// -padvalue Value
//
// Used to specify the value to pad with when aligning data while
// creating an FD image. Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires a byte value");
return STATUS_ERROR;
}
argc--;
argv++;
if (tolower (argv[0][1]) == 'x') {
sscanf (argv[0] + 2, "%x", &Temp);
mGlobals.MicrocodePadByteValue = (char) Temp;
} else {
sscanf (argv[0], "%d", &Temp);
mGlobals.MicrocodePadByteValue = (char) Temp;
}
} else if (strcmp (argv[0], "-align") == 0) {
//
// -align Alignment
//
// Used to specify how each data file is aligned in the region
// when creating an FD image. Check for additional argument.
//
if (argc < 2) {
Error (NULL, 0, 0, argv[0], "option requires an alignment");
return STATUS_ERROR;
}
argc--;
argv++;
if (tolower (argv[0][1]) == 'x') {
sscanf (argv[0] + 2, "%x", &mGlobals.MicrocodeAlignment);
} else {
sscanf (argv[0], "%d", &mGlobals.MicrocodeAlignment);
}
} else if (strcmp (argv[0], "-mcmerge") == 0) {
//
// -mcmerge FileName(s)
//
// Used to concatenate multiple microde binary files. Can specify
// multiple file names with the one -mcmerge flag. Check for additional argument.
//
if ((argc < 2) || (argv[1][0] == '-')) {
Error (NULL, 0, 0, argv[0], "option requires one or more input file names");
return STATUS_ERROR;
}
//
// Take input files until another option or end of list
//
ThingsToDo++;
while ((argc > 1) && (argv[1][0] != '-')) {
Str = (STRING_LIST *) _malloc (sizeof (STRING_LIST));
if (Str == NULL) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
return STATUS_ERROR;
}
memset (Str, 0, sizeof (STRING_LIST));
Str->Str = argv[1];
if (mGlobals.MCIFileNames == NULL) {
mGlobals.MCIFileNames = Str;
} else {
mGlobals.LastMCIFileNames->Next = Str;
}
mGlobals.LastMCIFileNames = Str;
argc--;
argv++;
}
} else if (strcmp (argv[0], "-strsub") == 0) {
//
// -strsub SrcFile DestFile
//
// Used to perform string substitutions on a file, writing the result to a new
// file. Check for two additional arguments.
//
if (argc < 3) {
Error (NULL, 0, 0, argv[0], "option requires input and output file names for string substitution");
return STATUS_ERROR;
}
argc--;
argv++;
mGlobals.StringReplaceInFileName = argv[0];
argc--;
argv++;
mGlobals.StringReplaceOutFileName = argv[0];
ThingsToDo++;
} else {
Error (NULL, 0, 0, argv[0], "invalid option");
return STATUS_ERROR;
}
argc--;
argv++;
}
//
// If no outputs requested, then report an error
//
if (ThingsToDo == 0) {
Error (NULL, 0, 0, "nothing to do", NULL);
return STATUS_ERROR;
}
//
// If they want an asm file, #include file, or C file to be created, then they have to specify a
// flash device name and flash definition file name.
//
if ((mGlobals.CIncludeFileName != NULL) &&
((mGlobals.FlashDevice == NULL) || (mGlobals.FlashDefinitionFileName == NULL))) {
Error (NULL, 0, 0, "must specify -flashdevice and -fdf with -hfile", NULL);
return STATUS_ERROR;
}
if ((mGlobals.AsmIncludeFileName != NULL) &&
((mGlobals.FlashDevice == NULL) || (mGlobals.FlashDefinitionFileName == NULL))) {
Error (NULL, 0, 0, "must specify -flashdevice and -fdf with -asmincfile", NULL);
return STATUS_ERROR;
}
//
// If they want a dsc file to be created, then they have to specify a
// flash device name and a flash definition file name
//
if (mGlobals.DscFileName != NULL) {
if (mGlobals.FlashDevice == NULL) {
Error (NULL, 0, 0, "must specify -flashdevice with -dsc", NULL);
return STATUS_ERROR;
}
if (mGlobals.FlashDefinitionFileName == NULL) {
Error (NULL, 0, 0, "must specify -fdf with -dsc", NULL);
return STATUS_ERROR;
}
}
//
// If they specified an output microcode file name, then they have to specify an input
// file name, and vice versa.
//
if ((mGlobals.MCIFileName != NULL) && (mGlobals.MCOFileName == NULL)) {
Error (NULL, 0, 0, "must specify output microcode file name", NULL);
return STATUS_ERROR;
}
if ((mGlobals.MCOFileName != NULL) && (mGlobals.MCIFileName == NULL) && (mGlobals.MCIFileNames == NULL)) {
Error (NULL, 0, 0, "must specify input microcode file name", NULL);
return STATUS_ERROR;
}
//
// If doing merge, then have to specify output file name
//
if ((mGlobals.MCIFileNames != NULL) && (mGlobals.MCOFileName == NULL)) {
Error (NULL, 0, 0, "must specify output microcode file name", NULL);
return STATUS_ERROR;
}
//
// If they want an output image to be created, then they have to specify
// the flash device and the flash device image to use.
//
if (mGlobals.ImageOutFileName != NULL) {
if (mGlobals.FlashDevice == NULL) {
Error (NULL, 0, 0, "must specify -flashdevice with -imageout", NULL);
return STATUS_ERROR;
}
if (mGlobals.FlashDeviceImage == NULL) {
Error (NULL, 0, 0, "must specify -flashdeviceimage with -imageout", NULL);
return STATUS_ERROR;
}
if (mGlobals.FlashDefinitionFileName == NULL) {
Error (NULL, 0, 0, "must specify -c or -fdf with -imageout", NULL);
return STATUS_ERROR;
}
}
return STATUS_SUCCESS;
}
static
void
Usage (
VOID
)
/*++
Routine Description:
Print utility command line help
Arguments:
None
Returns:
NA
--*/
{
int i;
char *Msg[] = {
"Usage: FlashTool -fdf FlashDefFile -flashdevice FlashDevice",
" -flashdeviceimage FlashDeviceImage -mci MCIFile -mco MCOFile",
" -discover FDImage -dsc DscFile -asmincfile AsmIncFile",
" -imageOut ImageOutFile -hfile HFile -strsub InStrFile OutStrFile",
" -baseaddr BaseAddr -align Alignment -padvalue PadValue",
" -mcmerge MCIFile(s)",
" where",
" FlashDefFile - input Flash Definition File",
" FlashDevice - flash device to use (from flash definition file)",
" FlashDeviceImage - flash device image to use (from flash definition file)",
" MCIFile - input microcode file to parse",
" MCOFile - output binary microcode image to create from MCIFile",
" HFile - output #include file to create",
" FDImage - name of input FDImage file to scan",
" ImageOutFile - output image file to create",
" DscFile - output DSC file to create",
" AsmIncFile - output ASM include file to create",
" InStrFile - input file to replace symbol names, writing result to OutStrFile",
" BaseAddr - base address of FDImage (used with -discover)",
" Alignment - alignment to use when merging microcode binaries",
" PadValue - byte value to use as pad value when aligning microcode binaries",
" MCIFile(s) - one or more microcode binary files to merge/concatenate",
"",
NULL
};
for (i = 0; Msg[i] != NULL; i++) {
fprintf (stdout, "%s\n", Msg[i]);
}
}
char*
NormalizePath (
char* OldPathName
)
{
char* Visitor;
if (OldPathName == NULL) {
return NULL;
}
Visitor = OldPathName;
while (*Visitor != '\0') {
if (*Visitor == '\\') {
*Visitor = '/';
}
Visitor++;
}
return OldPathName;
}

View File

@ -0,0 +1,304 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Microcode.c
Abstract:
Utility for working with microcode patch files in the Intel
Platform Innovation Framework for EFI build environment.
--*/
#include <stdio.h>
#include <string.h> // for memset()
#include <ctype.h>
#include <stdlib.h> // for malloc()
#include "EfiUtilityMsgs.h"
#include "Microcode.h"
#define MAX_LINE_LEN 256
//
// Structure definition for a microcode header
//
typedef struct {
unsigned int HeaderVersion;
unsigned int PatchId;
unsigned int Date;
unsigned int CpuId;
unsigned int Checksum;
unsigned int LoaderVersion;
unsigned int PlatformId;
unsigned int DataSize; // if 0, then TotalSize = 2048, and TotalSize field is invalid
unsigned int TotalSize; // number of bytes
unsigned int Reserved[3];
} MICROCODE_IMAGE_HEADER;
static
STATUS
MicrocodeReadData (
FILE *InFptr,
unsigned int *Data
);
void
MicrocodeConstructor (
void
)
/*++
Routine Description:
Constructor of module Microcode
Arguments:
None
Returns:
None
--*/
{
}
void
MicrocodeDestructor (
void
)
/*++
Routine Description:
Destructor of module Microcode
Arguments:
None
Returns:
None
--*/
{
}
static
STATUS
MicrocodeReadData (
FILE *InFptr,
unsigned int *Data
)
/*++
Routine Description:
Read a 32-bit microcode data value from a text file and convert to raw binary form.
Arguments:
InFptr - file pointer to input text file
Data - pointer to where to return the data parsed
Returns:
STATUS_SUCCESS - no errors or warnings, Data contains valid information
STATUS_ERROR - errors were encountered
--*/
{
char Line[MAX_LINE_LEN];
char *cptr;
Line[MAX_LINE_LEN - 1] = 0;
*Data = 0;
if (fgets (Line, MAX_LINE_LEN, InFptr) == NULL) {
return STATUS_ERROR;
}
//
// If it was a binary file, then it may have overwritten our null terminator
//
if (Line[MAX_LINE_LEN - 1] != 0) {
return STATUS_ERROR;
}
//
// Look for
// dd 000000001h ; comment
// dd XXXXXXXX
// DD XXXXXXXXX
// DD XXXXXXXXX
//
for (cptr = Line; *cptr && isspace(*cptr); cptr++) {
}
if ((tolower(cptr[0]) == 'd') && (tolower(cptr[1]) == 'd') && isspace (cptr[2])) {
//
// Skip blanks and look for a hex digit
//
cptr += 3;
for (; *cptr && isspace(*cptr); cptr++) {
}
if (isxdigit (*cptr)) {
if (sscanf (cptr, "%X", Data) != 1) {
return STATUS_ERROR;
}
}
return STATUS_SUCCESS;
}
return STATUS_ERROR;
}
STATUS
MicrocodeParseFile (
char *InFileName,
char *OutFileName
)
/*++
Routine Description:
Parse a microcode text file, and write the binary results to an output file.
Arguments:
InFileName - input text file to parse
OutFileName - output file to write raw binary data from parsed input file
Returns:
STATUS_SUCCESS - no errors or warnings
STATUS_ERROR - errors were encountered
--*/
{
FILE *InFptr;
FILE *OutFptr;
STATUS Status;
MICROCODE_IMAGE_HEADER *Header;
unsigned int Size;
unsigned int Size2;
unsigned int Data;
unsigned int Checksum;
char *Buffer;
char *Ptr;
unsigned int TotalSize;
Status = STATUS_ERROR;
InFptr = NULL;
OutFptr = NULL;
Buffer = NULL;
//
// Open the input text file
//
if ((InFptr = fopen (InFileName, "r")) == NULL) {
Error (NULL, 0, 0, InFileName, "failed to open input microcode file for reading");
return STATUS_ERROR;
}
//
// Make two passes on the input file. The first pass is to determine how
// much data is in the file so we can allocate a working buffer. Then
// we'll allocate a buffer and re-read the file into the buffer for processing.
//
Size = 0;
do {
Status = MicrocodeReadData (InFptr, &Data);
if (Status == STATUS_SUCCESS) {
Size += sizeof (Data);
}
} while (Status == STATUS_SUCCESS);
//
// Error if no data.
//
if (Size == 0) {
Error (NULL, 0, 0, InFileName, "no parse-able data found in file");
goto Done;
}
if (Size < sizeof (MICROCODE_IMAGE_HEADER)) {
Error (NULL, 0, 0, InFileName, "amount of parse-able data is insufficient to contain a microcode header");
goto Done;
}
//
// Allocate a buffer for the data
//
Buffer = (char *) _malloc (Size);
if (Buffer == NULL) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
goto Done;
}
//
// Re-read the file, storing the data into our buffer
//
fseek (InFptr, 0, SEEK_SET);
Ptr = Buffer;
do {
Status = MicrocodeReadData (InFptr, &Data);
if (Status == STATUS_SUCCESS) {
*(unsigned int *) Ptr = Data;
Ptr += sizeof (Data);
}
} while (Status == STATUS_SUCCESS);
//
// Can't do much checking on the header because, per the spec, the
// DataSize field may be 0, which means DataSize = 2000 and TotalSize = 2K,
// and the TotalSize field is invalid (actually missing). Thus we can't
// even verify the Reserved fields are 0.
//
Header = (MICROCODE_IMAGE_HEADER *) Buffer;
if (Header->DataSize == 0) {
TotalSize = 2048;
} else {
TotalSize = Header->TotalSize;
}
if (TotalSize != Size) {
Error (NULL, 0, 0, InFileName, "file contents do not contain expected TotalSize 0x%04X", TotalSize);
goto Done;
}
//
// Checksum the contents
//
Ptr = Buffer;
Checksum = 0;
Size2 = 0;
while (Size2 < Size) {
Checksum += *(unsigned int *) Ptr;
Ptr += 4;
Size2 += 4;
}
if (Checksum != 0) {
Error (NULL, 0, 0, InFileName, "checksum failed on file contents");
goto Done;
}
//
// Open the output file and write the buffer contents
//
if ((OutFptr = fopen (OutFileName, "wb")) == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output microcode file for writing");
goto Done;
}
if (fwrite (Buffer, Size, 1, OutFptr) != 1) {
Error (NULL, 0, 0, OutFileName, "failed to write microcode data to output file");
goto Done;
}
Status = STATUS_SUCCESS;
Done:
if (Buffer != NULL) {
free (Buffer);
}
if (InFptr != NULL) {
fclose (InFptr);
}
if (OutFptr != NULL) {
fclose (OutFptr);
if (Status == STATUS_ERROR) {
remove (OutFileName);
}
}
return Status;
}

View File

@ -0,0 +1,87 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Microcode.h
Abstract:
Header file for flash management utility in the Intel Platform
Innovation Framework for EFI build environment.
--*/
#ifndef _MICROCODE_H_
#define _MICROCODE_H_
void
MicrocodeConstructor (
void
);
/*++
Routine Description:
Constructor of module Microcode
Arguments:
None
Returns:
None
--*/
void
MicrocodeDestructor (
void
);
/*++
Routine Description:
Destructor of module Microcode
Arguments:
None
Returns:
None
--*/
STATUS
MicrocodeParseFile (
char *InFileName,
char *OutFileName
);
/*++
Routine Description:
Parse a microcode text file, and write the binary results to an output file.
Arguments:
InFileName - input text file to parse
OutFileName - output file to write raw binary data from parsed input file
Returns:
STATUS_SUCCESS - no errors or warnings
STATUS_ERROR - errors were encountered
--*/
#endif // #ifndef _MICROCODE_H_

View File

@ -0,0 +1,648 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Symbol.c
Abstract:
Class-like implementation for a symbol table.
--*/
// GC_TODO: fix comment to set correct module name: Symbols.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//
// for isspace()
//
#include <ctype.h>
#include <Common/UefiBaseTypes.h>
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
#include "Symbols.h"
#define MAX_LINE_LEN 512
//
// Linked list to keep track of all symbols
//
typedef struct _SYMBOL {
struct _SYMBOL *Next;
int Type;
char *Name;
char *Value;
} SYMBOL;
static
SYMBOL *
FreeSymbols (
SYMBOL *Syms
);
static
int
ExpandMacros (
char *SourceLine,
char *DestLine,
int LineLen
);
static SYMBOL *mSymbolTable = NULL;
void
SymbolsConstructor (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
{
SymbolsDestructor ();
}
void
SymbolsDestructor (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
{
mSymbolTable = FreeSymbols (mSymbolTable);
}
char *
GetSymbolValue (
char *SymbolName
)
/*++
Routine Description:
Look up a symbol in our symbol table.
Arguments:
SymbolName
Returns:
Pointer to the value of the symbol if found
NULL if the symbol is not found
--*/
// GC_TODO: SymbolName - add argument and description to function comment
{
SYMBOL *Symbol;
//
// Walk the symbol table
//
Symbol = mSymbolTable;
while (Symbol) {
if (stricmp (SymbolName, Symbol->Name) == 0) {
return Symbol->Value;
}
Symbol = Symbol->Next;
}
return NULL;
}
int
SymbolAdd (
char *Name,
char *Value,
int Mode
)
/*++
Routine Description:
Add a symbol name/value to the symbol table
Arguments:
Name - name of symbol to add
Value - value of symbol to add
Mode - currrently unused
Returns:
Length of symbol added.
Notes:
If Value == NULL, then this routine will assume that the Name field
looks something like "MySymName = MySymValue", and will try to parse
it that way and add the symbol name/pair from the string.
--*/
{
SYMBOL *Symbol;
SYMBOL *NewSymbol;
int Len;
char *Start;
char *Cptr;
char CSave;
char *SaveCptr;
Len = 0;
SaveCptr = NULL;
CSave = 0;
//
// If value pointer is null, then they passed us a line something like:
// varname = value, or simply var =
//
if (Value == NULL) {
Start = Name;
while (*Name && isspace (*Name)) {
Name++;
}
if (Name == NULL) {
return -1;
}
//
// Find the end of the name. Either space or a '='.
//
for (Value = Name; *Value && !isspace (*Value) && (*Value != '='); Value++)
;
if (Value == NULL) {
return -1;
}
//
// Look for the '='
//
Cptr = Value;
while (*Value && (*Value != '=')) {
Value++;
}
if (Value == NULL) {
return -1;
}
//
// Now truncate the name
//
*Cptr = 0;
//
// Skip over the = and then any spaces
//
Value++;
while (*Value && isspace (*Value)) {
Value++;
}
//
// Find end of string, checking for quoted string
//
if (*Value == '\"') {
Value++;
for (Cptr = Value; *Cptr && *Cptr != '\"'; Cptr++)
;
} else {
for (Cptr = Value; *Cptr && !isspace (*Cptr); Cptr++)
;
}
//
// Null terminate the value string
//
CSave = *Cptr;
SaveCptr = Cptr;
*Cptr = 0;
Len = (int) (Cptr - Start);
}
//
// We now have a symbol name and a value. Look for an existing variable
// and overwrite it.
//
Symbol = mSymbolTable;
while (Symbol) {
//
// Check for symbol name match
//
if (stricmp (Name, Symbol->Name) == 0) {
_free (Symbol->Value);
Symbol->Value = (char *) _malloc (strlen (Value) + 1);
if (Symbol->Value == NULL) {
Error (NULL, 0, 0, NULL, "failed to allocate memory");
return -1;
}
strcpy (Symbol->Value, Value);
//
// If value == "NULL", then make it a 0-length string
//
if (stricmp (Symbol->Value, "NULL") == 0) {
Symbol->Value[0] = 0;
}
return Len;
}
Symbol = Symbol->Next;
}
//
// Does not exist, create a new one
//
NewSymbol = (SYMBOL *) _malloc (sizeof (SYMBOL));
if (NewSymbol == NULL) {
Error (NULL, 0, 0, NULL, "memory allocation failure");
return -1;
}
memset ((char *) NewSymbol, 0, sizeof (SYMBOL));
NewSymbol->Name = (char *) _malloc (strlen (Name) + 1);
if (NewSymbol->Name == NULL) {
Error (NULL, 0, 0, NULL, "memory allocation failure");
_free (NewSymbol);
return -1;
}
NewSymbol->Value = (char *) _malloc (strlen (Value) + 1);
if (NewSymbol->Value == NULL) {
Error (NULL, 0, 0, NULL, "memory allocation failure");
_free (NewSymbol->Name);
_free (NewSymbol);
return -1;
}
strcpy (NewSymbol->Name, Name);
strcpy (NewSymbol->Value, Value);
//
// Remove trailing spaces
//
Cptr = NewSymbol->Value + strlen (NewSymbol->Value) - 1;
while (Cptr > NewSymbol->Value) {
if (isspace (*Cptr)) {
*Cptr = 0;
Cptr--;
} else {
break;
}
}
//
// Add it to the head of the list.
//
NewSymbol->Next = mSymbolTable;
mSymbolTable = NewSymbol;
//
// If value == "NULL", then make it a 0-length string
//
if (stricmp (NewSymbol->Value, "NULL") == 0) {
NewSymbol->Value[0] = 0;
}
//
// Restore the terminator we inserted if they passed in var=value
//
if (SaveCptr != NULL) {
*SaveCptr = CSave;
}
_free (NewSymbol->Value);
_free (NewSymbol->Name);
_free (NewSymbol);
return Len;
}
static
STATUS
RemoveSymbol (
char *Name,
char SymbolType
)
/*++
Routine Description:
Remove a symbol name/value from the symbol table
Arguments:
Name - name of symbol to remove
SymbolType - type of symbol to remove
Returns:
STATUS_SUCCESS - matching symbol found and removed
STATUS_ERROR - matching symbol not found in symbol table
--*/
{
SYMBOL *Symbol;
SYMBOL *PrevSymbol;
PrevSymbol = NULL;
Symbol = mSymbolTable;
//
// Walk the linked list of symbols in the symbol table looking
// for a match of both symbol name and type.
//
while (Symbol) {
if ((stricmp (Name, Symbol->Name) == 0) && (Symbol->Type & SymbolType)) {
//
// If the symbol has a value associated with it, free the memory
// allocated for the value.
// Then free the memory allocated for the symbols string name.
//
if (Symbol->Value) {
_free (Symbol->Value);
}
_free (Symbol->Name);
//
// Link the previous symbol to the next symbol to effectively
// remove this symbol from the linked list.
//
if (PrevSymbol) {
PrevSymbol->Next = Symbol->Next;
} else {
mSymbolTable = Symbol->Next;
}
_free (Symbol);
return STATUS_SUCCESS;
}
PrevSymbol = Symbol;
Symbol = Symbol->Next;
}
return STATUS_WARNING;
}
static
SYMBOL *
FreeSymbols (
SYMBOL *Syms
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
Syms - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
SYMBOL *Next;
while (Syms) {
if (Syms->Name != NULL) {
_free (Syms->Name);
}
if (Syms->Value != NULL) {
_free (Syms->Value);
}
Next = Syms->Next;
_free (Syms);
Syms = Next;
}
return Syms;
}
static
int
ExpandMacros (
char *SourceLine,
char *DestLine,
int LineLen
)
/*++
Routine Description:
Given a line of text, replace all variables of format $(NAME) with values
from our symbol table.
Arguments:
SourceLine - input line of text to do symbol replacements on
DestLine - on output, SourceLine with symbols replaced
LineLen - length of DestLine, so we don't exceed its allocated length
Returns:
STATUS_SUCCESS - no problems encountered
STATUS_WARNING - missing closing parenthesis on a symbol reference in SourceLine
STATUS_ERROR - memory allocation failure
--*/
{
static int NestDepth = 0;
char *FromPtr;
char *ToPtr;
char *SaveStart;
char *Cptr;
char *value;
int Expanded;
int ExpandedCount;
INT8 *LocalDestLine;
STATUS Status;
int LocalLineLen;
NestDepth++;
Status = STATUS_SUCCESS;
LocalDestLine = (char *) _malloc (LineLen);
if (LocalDestLine == NULL) {
Error (__FILE__, __LINE__, 0, "memory allocation failed", NULL);
return STATUS_ERROR;
}
FromPtr = SourceLine;
ToPtr = LocalDestLine;
//
// Walk the entire line, replacing $(MACRO_NAME).
//
LocalLineLen = LineLen;
ExpandedCount = 0;
while (*FromPtr && (LocalLineLen > 0)) {
if ((*FromPtr == '$') && (*(FromPtr + 1) == '(')) {
//
// Save the start in case it's undefined, in which case we copy it as-is.
//
SaveStart = FromPtr;
Expanded = 0;
//
// Macro expansion time. Find the end (no spaces allowed)
//
FromPtr += 2;
for (Cptr = FromPtr; *Cptr && (*Cptr != ')'); Cptr++)
;
if (*Cptr) {
//
// Truncate the string at the closing parenthesis for ease-of-use.
// Then copy the string directly to the destination line in case we don't find
// a definition for it.
//
*Cptr = 0;
strcpy (ToPtr, SaveStart);
if ((value = GetSymbolValue (FromPtr)) != NULL) {
strcpy (ToPtr, value);
LocalLineLen -= strlen (value);
ToPtr += strlen (value);
Expanded = 1;
ExpandedCount++;
}
if (!Expanded) {
//
// Restore closing parenthesis, and advance to next character
//
*Cptr = ')';
FromPtr = SaveStart + 1;
ToPtr++;
} else {
FromPtr = Cptr + 1;
}
} else {
Error (NULL, 0, 0, SourceLine, "missing closing parenthesis on macro");
strcpy (ToPtr, FromPtr);
Status = STATUS_WARNING;
goto Done;
}
} else {
*ToPtr = *FromPtr;
FromPtr++;
ToPtr++;
LocalLineLen--;
}
}
if (*FromPtr == 0) {
*ToPtr = 0;
}
//
// If we expanded at least one string successfully, then make a recursive call to try again.
//
if ((ExpandedCount != 0) && (Status == STATUS_SUCCESS) && (NestDepth < 10)) {
Status = ExpandMacros (LocalDestLine, DestLine, LineLen);
_free (LocalDestLine);
NestDepth = 0;
return Status;
}
Done:
if (Status != STATUS_ERROR) {
strcpy (DestLine, LocalDestLine);
}
NestDepth = 0;
_free (LocalDestLine);
return Status;
}
STATUS
SymbolsFileStringsReplace (
char *InFileName,
char *OutFileName
)
/*++
Routine Description:
Given input and output file names, read in the input file, replace variable
references of format $(NAME) with appropriate values from our symbol table,
and write the result out to the output file.
Arguments:
InFileName - name of input text file to replace variable references
OutFileName - name of output text file to write results to
Returns:
STATUS_SUCCESS - no problems encountered
STATUS_ERROR - failed to open input or output file
--*/
{
STATUS Status;
FILE *InFptr;
FILE *OutFptr;
char Line[MAX_LINE_LEN];
char OutLine[MAX_LINE_LEN];
Status = STATUS_ERROR;
//
// Open input and output files
//
InFptr = NULL;
OutFptr = NULL;
if ((InFptr = fopen (InFileName, "r")) == NULL) {
Error (NULL, 0, 0, InFileName, "failed to open input file for reading");
goto Done;
}
if ((OutFptr = fopen (OutFileName, "w")) == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
goto Done;
}
//
// Read lines from input file until done
//
while (fgets (Line, sizeof (Line), InFptr) != NULL) {
ExpandMacros (Line, OutLine, sizeof (OutLine));
fprintf (OutFptr, OutLine);
}
Status = STATUS_SUCCESS;
Done:
if (InFptr != NULL) {
fclose (InFptr);
}
if (OutFptr != NULL) {
fclose (OutFptr);
}
return Status;
}

View File

@ -0,0 +1,124 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Symbols.h
Abstract:
Defines and prototypes for a class-like symbol table service.
--*/
#ifndef _SYMBOLS_H_
#define _SYMBOLS_H_
#ifdef __cplusplus
extern "C"
{
#endif
int
SymbolAdd (
char *Name,
char *Value,
int Mode
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
Name - GC_TODO: add argument description
Value - GC_TODO: add argument description
Mode - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
STATUS
SymbolsFileStringsReplace (
char *InFileName,
char *OutFileName
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
InFileName - GC_TODO: add argument description
OutFileName - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
void
SymbolsConstructor (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
;
void
SymbolsDestructor (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
;
#ifdef __cplusplus
}
#endif
#endif // #ifndef _SYMBOLS_H_

View File

@ -0,0 +1,76 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK FlashMap Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="FlashMap"/>
<property name="FileSet" value="*.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
optimize="speed"
debug="true">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<defineset>
<define name="_malloc" value="malloc"/>
<define name="_free" value="free"/>
</defineset>
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,71 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK FwImage Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="FwImage"/>
<property name="FileSet" value="fwimage.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,510 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
fwimage.c
Abstract:
Converts a pe32+ image to an FW image type
--*/
#include "WinNtInclude.h"
#ifndef __GNUC__
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <Common/UefiBaseTypes.h>
#include <Common/EfiImage.h>
#include "CommonLib.h"
#include "EfiUtilityMsgs.c"
#define UTILITY_NAME "FwImage"
#ifdef __GNUC__
typedef unsigned long ULONG;
typedef unsigned char UCHAR;
typedef unsigned char *PUCHAR;
typedef unsigned short USHORT;
#endif
VOID
Usage (
VOID
)
{
printf ("Usage: " UTILITY_NAME " {-t time-date} [BASE|SEC|PEI_CORE|PEIM|DXE_CORE|DXE_DRIVER|DXE_RUNTIME_DRIVER|DXE_SAL_DRIVER|DXE_SMM_DRIVER|TOOL|UEFI_DRIVER|UEFI_APPLICATION|USER_DEFINED] peimage [outimage]");
}
static
STATUS
FCopyFile (
FILE *in,
FILE *out
)
{
ULONG filesize;
ULONG offset;
ULONG length;
UCHAR Buffer[8 * 1024];
fseek (in, 0, SEEK_END);
filesize = ftell (in);
fseek (in, 0, SEEK_SET);
fseek (out, 0, SEEK_SET);
offset = 0;
while (offset < filesize) {
length = sizeof (Buffer);
if (filesize - offset < length) {
length = filesize - offset;
}
fread (Buffer, length, 1, in);
fwrite (Buffer, length, 1, out);
offset += length;
}
if ((ULONG) ftell (out) != filesize) {
Error (NULL, 0, 0, "write error", NULL);
return STATUS_ERROR;
}
return STATUS_SUCCESS;
}
static
STATUS
FReadFile (
FILE *in,
VOID **Buffer,
UINTN *Length
)
{
fseek (in, 0, SEEK_END);
*Length = ftell (in);
*Buffer = malloc (*Length);
fseek (in, 0, SEEK_SET);
fread (*Buffer, *Length, 1, in);
return STATUS_SUCCESS;
}
static
STATUS
FWriteFile (
FILE *out,
VOID *Buffer,
UINTN Length
)
{
fseek (out, 0, SEEK_SET);
fwrite (Buffer, Length, 1, out);
if ((ULONG) ftell (out) != Length) {
Error (NULL, 0, 0, "write error", NULL);
return STATUS_ERROR;
}
free (Buffer);
return STATUS_SUCCESS;
}
int
main (
int argc,
char *argv[]
)
/*++
Routine Description:
Main function.
Arguments:
argc - Number of command line parameters.
argv - Array of pointers to command line parameter strings.
Returns:
STATUS_SUCCESS - Utility exits successfully.
STATUS_ERROR - Some error occurred during execution.
--*/
{
ULONG Type;
PUCHAR Ext;
PUCHAR p;
PUCHAR pe;
PUCHAR OutImageName;
UCHAR outname[500];
FILE *fpIn;
FILE *fpOut;
VOID *ZeroBuffer;
EFI_IMAGE_DOS_HEADER *DosHdr;
EFI_IMAGE_NT_HEADERS *PeHdr;
EFI_IMAGE_OPTIONAL_HEADER32 *Optional32;
EFI_IMAGE_OPTIONAL_HEADER64 *Optional64;
time_t TimeStamp;
struct tm TimeStruct;
EFI_IMAGE_DOS_HEADER BackupDosHdr;
ULONG Index;
ULONG Index1;
ULONG Index2;
ULONG Index3;
BOOLEAN TimeStampPresent;
UINTN AllignedRelocSize;
UINTN Delta;
EFI_IMAGE_SECTION_HEADER *SectionHeader;
UINT8 *FileBuffer;
UINTN FileLength;
RUNTIME_FUNCTION *RuntimeFunction;
UNWIND_INFO *UnwindInfo;
SetUtilityName (UTILITY_NAME);
//
// Assign to fix compile warning
//
OutImageName = NULL;
Type = 0;
Ext = 0;
TimeStamp = 0;
TimeStampPresent = FALSE;
//
// Look for -t time-date option first. If the time is "0", then
// skip it.
//
if ((argc > 2) && !strcmp (argv[1], "-t")) {
TimeStampPresent = TRUE;
if (strcmp (argv[2], "0") != 0) {
//
// Convert the string to a value
//
memset ((char *) &TimeStruct, 0, sizeof (TimeStruct));
if (sscanf(
argv[2], "%d/%d/%d,%d:%d:%d",
&TimeStruct.tm_mon, /* months since January - [0,11] */
&TimeStruct.tm_mday, /* day of the month - [1,31] */
&TimeStruct.tm_year, /* years since 1900 */
&TimeStruct.tm_hour, /* hours since midnight - [0,23] */
&TimeStruct.tm_min, /* minutes after the hour - [0,59] */
&TimeStruct.tm_sec /* seconds after the minute - [0,59] */
) != 6) {
Error (NULL, 0, 0, argv[2], "failed to convert to mm/dd/yyyy,hh:mm:ss format");
return STATUS_ERROR;
}
//
// Now fixup some of the fields
//
TimeStruct.tm_mon--;
TimeStruct.tm_year -= 1900;
//
// Sanity-check values?
// Convert
//
TimeStamp = mktime (&TimeStruct);
if (TimeStamp == (time_t) - 1) {
Error (NULL, 0, 0, argv[2], "failed to convert time");
return STATUS_ERROR;
}
}
//
// Skip over the args
//
argc -= 2;
argv += 2;
}
//
// Check for enough args
//
if (argc < 3) {
Usage ();
return STATUS_ERROR;
}
if (argc == 4) {
OutImageName = argv[3];
}
//
// Get new image type
//
p = argv[1];
if (*p == '/' || *p == '\\') {
p += 1;
}
if (stricmp (p, "app") == 0 || stricmp (p, "UEFI_APPLICATION") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION;
Ext = ".efi";
} else if (stricmp (p, "bsdrv") == 0 || stricmp (p, "DXE_DRIVER") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
Ext = ".efi";
} else if (stricmp (p, "rtdrv") == 0 || stricmp (p, "DXE_RUNTIME_DRIVER") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER;
Ext = ".efi";
} else if (stricmp (p, "rtdrv") == 0 || stricmp (p, "DXE_SAL_DRIVER") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER;
Ext = ".efi";
} else if (stricmp (p, "SEC") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
Ext = ".sec";
} else if (stricmp (p, "peim") == 0 ||
stricmp (p, "BASE") == 0 ||
stricmp (p, "PEI_CORE") == 0 ||
stricmp (p, "PEIM") == 0 ||
stricmp (p, "DXE_SMM_DRIVER") == 0 ||
stricmp (p, "TOOL") == 0 ||
stricmp (p, "UEFI_APPLICATION") == 0 ||
stricmp (p, "USER_DEFINED") == 0 ||
stricmp (p, "UEFI_DRIVER") == 0 ||
stricmp (p, "DXE_CORE") == 0
) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
Ext = ".pei";
} else {
printf ("%s", p);
Usage ();
return STATUS_ERROR;
}
//
// open source file
//
fpIn = fopen (argv[2], "rb");
if (!fpIn) {
Error (NULL, 0, 0, argv[2], "failed to open input file for reading");
return STATUS_ERROR;
}
FReadFile (fpIn, (VOID **)&FileBuffer, &FileLength);
//
// Read the dos & pe hdrs of the image
//
DosHdr = (EFI_IMAGE_DOS_HEADER *)FileBuffer;
if (DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Error (NULL, 0, 0, argv[2], "DOS header signature not found in source image");
fclose (fpIn);
return STATUS_ERROR;
}
PeHdr = (EFI_IMAGE_NT_HEADERS *)(FileBuffer + DosHdr->e_lfanew);
if (PeHdr->Signature != EFI_IMAGE_NT_SIGNATURE) {
Error (NULL, 0, 0, argv[2], "PE header signature not found in source image");
fclose (fpIn);
return STATUS_ERROR;
}
//
// open output file
//
strcpy (outname, argv[2]);
pe = NULL;
for (p = outname; *p; p++) {
if (*p == '.') {
pe = p;
}
}
if (!pe) {
pe = p;
}
strcpy (pe, Ext);
if (!OutImageName) {
OutImageName = outname;
}
fpOut = fopen (OutImageName, "w+b");
if (!fpOut) {
Error (NULL, 0, 0, OutImageName, "could not open output file for writing");
fclose (fpIn);
return STATUS_ERROR;
}
//
// Zero all unused fields of the DOS header
//
memcpy (&BackupDosHdr, DosHdr, sizeof (EFI_IMAGE_DOS_HEADER));
memset (DosHdr, 0, sizeof (EFI_IMAGE_DOS_HEADER));
DosHdr->e_magic = BackupDosHdr.e_magic;
DosHdr->e_lfanew = BackupDosHdr.e_lfanew;
for (Index = sizeof (EFI_IMAGE_DOS_HEADER); Index < (ULONG) DosHdr->e_lfanew; Index++) {
FileBuffer[Index] = DosHdr->e_cp;
}
//
// Path the PE header
//
PeHdr->OptionalHeader.Subsystem = (USHORT) Type;
if (TimeStampPresent) {
PeHdr->FileHeader.TimeDateStamp = (UINT32) TimeStamp;
}
if (PeHdr->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
Optional32 = (EFI_IMAGE_OPTIONAL_HEADER32 *)&PeHdr->OptionalHeader;
Optional32->MajorLinkerVersion = 0;
Optional32->MinorLinkerVersion = 0;
Optional32->MajorOperatingSystemVersion = 0;
Optional32->MinorOperatingSystemVersion = 0;
Optional32->MajorImageVersion = 0;
Optional32->MinorImageVersion = 0;
Optional32->MajorSubsystemVersion = 0;
Optional32->MinorSubsystemVersion = 0;
Optional32->Win32VersionValue = 0;
Optional32->CheckSum = 0;
Optional32->SizeOfStackReserve = 0;
Optional32->SizeOfStackCommit = 0;
Optional32->SizeOfHeapReserve = 0;
Optional32->SizeOfHeapCommit = 0;
//
// Strip zero padding at the end of the .reloc section
//
if (Optional32->NumberOfRvaAndSizes >= 6) {
if (Optional32->DataDirectory[5].Size != 0) {
SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);
for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {
//
// Look for the Section Header that starts as the same virtual address as the Base Relocation Data Directory
//
if (SectionHeader->VirtualAddress == Optional32->DataDirectory[5].VirtualAddress) {
SectionHeader->Misc.VirtualSize = Optional32->DataDirectory[5].Size;
AllignedRelocSize = (Optional32->DataDirectory[5].Size + Optional32->FileAlignment - 1) & (~(Optional32->FileAlignment - 1));
//
// Check to see if there is zero padding at the end of the base relocations
//
if (AllignedRelocSize < SectionHeader->SizeOfRawData) {
//
// Check to see if the base relocations are at the end of the file
//
if (SectionHeader->PointerToRawData + SectionHeader->SizeOfRawData == Optional32->SizeOfImage) {
//
// All the required conditions are met to strip the zero padding of the end of the base relocations section
//
Optional32->SizeOfImage -= (SectionHeader->SizeOfRawData - AllignedRelocSize);
Optional32->SizeOfInitializedData -= (SectionHeader->SizeOfRawData - AllignedRelocSize);
SectionHeader->SizeOfRawData = AllignedRelocSize;
FileLength = Optional32->SizeOfImage;
}
}
}
}
}
}
}
if (PeHdr->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
Optional64 = (EFI_IMAGE_OPTIONAL_HEADER64 *)&PeHdr->OptionalHeader;
Optional64->MajorLinkerVersion = 0;
Optional64->MinorLinkerVersion = 0;
Optional64->MajorOperatingSystemVersion = 0;
Optional64->MinorOperatingSystemVersion = 0;
Optional64->MajorImageVersion = 0;
Optional64->MinorImageVersion = 0;
Optional64->MajorSubsystemVersion = 0;
Optional64->MinorSubsystemVersion = 0;
Optional64->Win32VersionValue = 0;
Optional64->CheckSum = 0;
Optional64->SizeOfStackReserve = 0;
Optional64->SizeOfStackCommit = 0;
Optional64->SizeOfHeapReserve = 0;
Optional64->SizeOfHeapCommit = 0;
//
// Zero the .pdata section if the machine type is X64 and the Debug Directory is empty
//
if (PeHdr->FileHeader.Machine == 0x8664) { // X64
if (Optional64->NumberOfRvaAndSizes >= 4) {
if (Optional64->NumberOfRvaAndSizes < 7 || (Optional64->NumberOfRvaAndSizes >= 7 && Optional64->DataDirectory[6].Size == 0)) {
SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);
for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {
if (SectionHeader->VirtualAddress == Optional64->DataDirectory[3].VirtualAddress) {
RuntimeFunction = (RUNTIME_FUNCTION *)(FileBuffer + SectionHeader->PointerToRawData);
for (Index1 = 0; Index1 < Optional64->DataDirectory[3].Size / sizeof (RUNTIME_FUNCTION); Index1++, RuntimeFunction++) {
SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);
for (Index2 = 0; Index2 < PeHdr->FileHeader.NumberOfSections; Index2++, SectionHeader++) {
if (RuntimeFunction->UnwindInfoAddress > SectionHeader->VirtualAddress && RuntimeFunction->UnwindInfoAddress < (SectionHeader->VirtualAddress + SectionHeader->SizeOfRawData)) {
UnwindInfo = (UNWIND_INFO *)(FileBuffer + SectionHeader->PointerToRawData + (RuntimeFunction->UnwindInfoAddress - SectionHeader->VirtualAddress));
if (UnwindInfo->Version == 1) {
memset (UnwindInfo + 1, 0, UnwindInfo->CountOfUnwindCodes * sizeof (UINT16));
memset (UnwindInfo, 0, sizeof (UNWIND_INFO));
}
}
}
memset (RuntimeFunction, 0, sizeof (RUNTIME_FUNCTION));
}
}
}
Optional64->DataDirectory[3].Size = 0;
Optional64->DataDirectory[3].VirtualAddress = 0;
}
}
}
//
// Strip zero padding at the end of the .reloc section
//
if (Optional64->NumberOfRvaAndSizes >= 6) {
if (Optional64->DataDirectory[5].Size != 0) {
SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);
for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {
//
// Look for the Section Header that starts as the same virtual address as the Base Relocation Data Directory
//
if (SectionHeader->VirtualAddress == Optional64->DataDirectory[5].VirtualAddress) {
SectionHeader->Misc.VirtualSize = Optional64->DataDirectory[5].Size;
AllignedRelocSize = (Optional64->DataDirectory[5].Size + Optional64->FileAlignment - 1) & (~(Optional64->FileAlignment - 1));
//
// Check to see if there is zero padding at the end of the base relocations
//
if (AllignedRelocSize < SectionHeader->SizeOfRawData) {
//
// Check to see if the base relocations are at the end of the file
//
if (SectionHeader->PointerToRawData + SectionHeader->SizeOfRawData == Optional64->SizeOfImage) {
//
// All the required conditions are met to strip the zero padding of the end of the base relocations section
//
Optional64->SizeOfImage -= (SectionHeader->SizeOfRawData - AllignedRelocSize);
Optional64->SizeOfInitializedData -= (SectionHeader->SizeOfRawData - AllignedRelocSize);
SectionHeader->SizeOfRawData = AllignedRelocSize;
FileLength = Optional64->SizeOfImage;
}
}
}
}
}
}
}
FWriteFile (fpOut, FileBuffer, FileLength);
//
// Done
//
fclose (fpIn);
fclose (fpOut);
//
// printf ("Created %s\n", OutImageName);
//
return STATUS_SUCCESS;
}

View File

@ -0,0 +1,544 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenAcpiTable.c
Abstract:
A utility that extracts the .DATA section from a PE/COFF image.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Common/UefiBaseTypes.h>
#include <Common/EfiImage.h> // for PE32 structure definitions
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
//
// Version of this utility
//
#define UTILITY_NAME "GenAcpiTable"
#define UTILITY_VERSION "v0.11"
//
// Define the max length of a filename
//
#define MAX_PATH 256
#define DEFAULT_OUTPUT_EXTENSION ".acpi"
//
// Use this to track our command-line options and globals
//
struct {
INT8 OutFileName[MAX_PATH];
INT8 InFileName[MAX_PATH];
} mOptions;
//
// Use these to convert from machine type value to a named type
//
typedef struct {
UINT16 Value;
INT8 *Name;
} STRING_LOOKUP;
static STRING_LOOKUP mMachineTypes[] = {
EFI_IMAGE_MACHINE_IA32,
"IA32",
EFI_IMAGE_MACHINE_IA64,
"IA64",
EFI_IMAGE_MACHINE_EBC,
"EBC",
0,
NULL
};
static STRING_LOOKUP mSubsystemTypes[] = {
EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION,
"EFI application",
EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER,
"EFI boot service driver",
EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER,
"EFI runtime driver",
0,
NULL
};
//
// Function prototypes
//
static
void
Usage (
VOID
);
static
STATUS
ParseCommandLine (
int Argc,
char *Argv[]
);
static
STATUS
CheckPE32File (
INT8 *FileName,
FILE *Fptr,
UINT16 *MachineType,
UINT16 *SubSystem
);
static
STATUS
ProcessFile (
INT8 *InFileName,
INT8 *OutFileName
);
static
void
DumpImage (
INT8 *FileName
);
main (
int Argc,
char *Argv[]
)
/*++
Routine Description:
Arguments:
Argc - standard C main() argument count
Argv - standard C main() argument list
Returns:
0 success
non-zero otherwise
--*/
// GC_TODO: ] - add argument and description to function comment
{
UINT32 Status;
SetUtilityName (UTILITY_NAME);
//
// Parse the command line arguments
//
if (ParseCommandLine (Argc, Argv)) {
return STATUS_ERROR;
}
//
// Make sure we don't have the same filename for input and output files
//
if (stricmp (mOptions.OutFileName, mOptions.InFileName) == 0) {
Error (NULL, 0, 0, mOptions.OutFileName, "input and output file names must be different");
goto Finish;
}
//
// Process the file
//
ProcessFile (mOptions.InFileName, mOptions.OutFileName);
Finish:
Status = GetUtilityStatus ();
return Status;
}
static
STATUS
ProcessFile (
INT8 *InFileName,
INT8 *OutFileName
)
/*++
Routine Description:
Process a PE32 EFI file.
Arguments:
InFileName - Name of the PE32 EFI file to process.
OutFileName - Name of the output file for the processed data.
Returns:
0 - successful
--*/
{
STATUS Status;
UINTN Index;
FILE *InFptr;
FILE *OutFptr;
UINT16 MachineType;
UINT16 SubSystem;
UINT32 PESigOffset;
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader32;
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader64;
EFI_IMAGE_SECTION_HEADER SectionHeader;
UINT8 *Buffer;
long SaveFilePosition;
InFptr = NULL;
OutFptr = NULL;
Buffer = NULL;
Status = STATUS_ERROR;
//
// Try to open the input file
//
if ((InFptr = fopen (InFileName, "rb")) == NULL) {
Error (NULL, 0, 0, InFileName, "failed to open input file for reading");
return STATUS_ERROR;
}
//
// Double-check the file to make sure it's what we expect it to be
//
if (CheckPE32File (InFileName, InFptr, &MachineType, &SubSystem) != STATUS_SUCCESS) {
goto Finish;
}
//
// Per the PE/COFF specification, at offset 0x3C in the file is a 32-bit
// offset (from the start of the file) to the PE signature, which always
// follows the MSDOS stub. The PE signature is immediately followed by the
// COFF file header.
//
//
if (fseek (InFptr, 0x3C, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to PE signature in file", NULL);
goto Finish;
}
if (fread (&PESigOffset, sizeof (PESigOffset), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read PE signature offset from file");
goto Finish;
}
if (fseek (InFptr, PESigOffset + 4, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to PE signature");
goto Finish;
}
//
// We should now be at the COFF file header. Read it in and verify it's
// of an image type we support.
//
if (fread (&FileHeader, sizeof (EFI_IMAGE_FILE_HEADER), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read file header from image");
goto Finish;
}
if ((FileHeader.Machine != EFI_IMAGE_MACHINE_IA32) && (FileHeader.Machine != EFI_IMAGE_MACHINE_IA64) && (FileHeader.Machine != EFI_IMAGE_MACHINE_X64)) {
Error (NULL, 0, 0, InFileName, "image is of an unsupported machine type 0x%X", (UINT32) FileHeader.Machine);
goto Finish;
}
//
// Read in the optional header. Assume PE32, and if not, then re-read as PE32+
//
SaveFilePosition = ftell (InFptr);
if (fread (&OptionalHeader32, sizeof (EFI_IMAGE_OPTIONAL_HEADER32), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read optional header from input file");
goto Finish;
}
if (OptionalHeader32.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
if (fseek (InFptr, SaveFilePosition, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to .data section");
goto Finish;
}
if (fread (&OptionalHeader64, sizeof (EFI_IMAGE_OPTIONAL_HEADER64), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read optional header from input file");
goto Finish;
}
}
//
// Search for the ".data" section
//
for (Index = 0; Index < FileHeader.NumberOfSections; Index++) {
if (fread (&SectionHeader, sizeof (EFI_IMAGE_SECTION_HEADER), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read optional header from input file");
goto Finish;
}
if (strcmp (SectionHeader.Name, ".data") == 0) {
if (fseek (InFptr, SectionHeader.PointerToRawData, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to .data section");
goto Finish;
}
Buffer = (UINT8 *) malloc (SectionHeader.Misc.VirtualSize);
if (Buffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Finish;
}
if (fread (Buffer, SectionHeader.Misc.VirtualSize, 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to .data section");
goto Finish;
}
//
// Now open our output file
//
if ((OutFptr = fopen (OutFileName, "wb")) == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
goto Finish;
}
if (fwrite (Buffer, SectionHeader.Misc.VirtualSize, 1, OutFptr) != 1) {
Error (NULL, 0, 0, OutFileName, "failed to write .data section");
goto Finish;
}
Status = STATUS_SUCCESS;
goto Finish;
}
}
Status = STATUS_ERROR;
Finish:
if (InFptr != NULL) {
fclose (InFptr);
}
//
// Close the output file. If there was an error, delete the output file so
// that a subsequent build will rebuild it.
//
if (OutFptr != NULL) {
fclose (OutFptr);
if (GetUtilityStatus () == STATUS_ERROR) {
remove (OutFileName);
}
}
//
// Free up our buffer
//
if (Buffer != NULL) {
free (Buffer);
}
return Status;
}
static
STATUS
CheckPE32File (
INT8 *FileName,
FILE *Fptr,
UINT16 *MachineType,
UINT16 *SubSystem
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FileName - GC_TODO: add argument description
Fptr - GC_TODO: add argument description
MachineType - GC_TODO: add argument description
SubSystem - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
/*++
Routine Description:
Given a file pointer to a supposed PE32 image file, verify that it is indeed a
PE32 image file, and then return the machine type in the supplied pointer.
Arguments:
Fptr File pointer to the already-opened PE32 file
MachineType Location to stuff the machine type of the PE32 file. This is needed
because the image may be Itanium-based, IA32, or EBC.
Returns:
0 success
non-zero otherwise
--*/
EFI_IMAGE_DOS_HEADER DosHeader;
EFI_IMAGE_FILE_HEADER FileHdr;
EFI_IMAGE_OPTIONAL_HEADER OptionalHdr;
UINT32 PESig;
STATUS Status;
Status = STATUS_ERROR;
//
// Position to the start of the file
//
fseek (Fptr, 0, SEEK_SET);
//
// Read the DOS header
//
if (fread (&DosHeader, sizeof (DosHeader), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read the DOS stub from the input file");
goto Finish;
}
//
// Check the magic number (0x5A4D)
//
if (DosHeader.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Error (NULL, 0, 0, FileName, "input file does not appear to be a PE32 image (magic number)");
goto Finish;
}
//
// Position into the file and check the PE signature
//
fseek (Fptr, (long) DosHeader.e_lfanew, SEEK_SET);
if (fread (&PESig, sizeof (PESig), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read PE signature bytes");
goto Finish;
}
//
// Check the PE signature in the header "PE\0\0"
//
if (PESig != EFI_IMAGE_NT_SIGNATURE) {
Error (NULL, 0, 0, FileName, "file does not appear to be a PE32 image (signature)");
goto Finish;
}
//
// Read the file header
//
if (fread (&FileHdr, sizeof (FileHdr), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read PE file header from input file");
goto Finish;
}
//
// Read the optional header so we can get the subsystem
//
if (fread (&OptionalHdr, sizeof (OptionalHdr), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read COFF optional header from input file");
goto Finish;
}
*SubSystem = OptionalHdr.Subsystem;
//
// Good to go
//
Status = STATUS_SUCCESS;
Finish:
fseek (Fptr, 0, SEEK_SET);
return Status;
}
static
int
ParseCommandLine (
int Argc,
char *Argv[]
)
/*++
Routine Description:
Given the Argc/Argv program arguments, and a pointer to an options structure,
parse the command-line options and check their validity.
Arguments:
Argc - standard C main() argument count
Argv - standard C main() argument list
Returns:
STATUS_SUCCESS success
non-zero otherwise
--*/
// GC_TODO: ] - add argument and description to function comment
{
//
// Clear out the options
//
memset ((char *) &mOptions, 0, sizeof (mOptions));
//
// Skip over the program name
//
Argc--;
Argv++;
if (Argc != 2) {
Usage ();
return STATUS_ERROR;
}
strcpy (mOptions.InFileName, Argv[0]);
//
// Next argument
//
Argv++;
Argc--;
strcpy (mOptions.OutFileName, Argv[0]);
return STATUS_SUCCESS;
}
static
void
Usage (
VOID
)
/*++
Routine Description:
Print usage information for this utility.
Arguments:
None.
Returns:
Nothing.
--*/
{
int Index;
static const char *Msg[] = {
UTILITY_NAME " version "UTILITY_VERSION " - Generate ACPI Table image utility",
" Generate an ACPI Table image from an EFI PE32 image",
" Usage: "UTILITY_NAME " InFileName OutFileName",
" where:",
" InFileName - name of the input PE32 file",
" OutFileName - to write output to OutFileName rather than InFileName"DEFAULT_OUTPUT_EXTENSION,
"",
NULL
};
for (Index = 0; Msg[Index] != NULL; Index++) {
fprintf (stdout, "%s\n", Msg[Index]);
}
}

View File

@ -0,0 +1,71 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenAcpiTable Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenAcpiTable"/>
<property name="FileSet" value="*.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
optimize="speed"
debug="true">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/Ia32"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,286 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenCRC32Section.c
Abstract:
This file contains functions required to generate a Firmware File System
file. The code is compliant with the Tiano C Coding standards.
--*/
#include "GenCRC32Section.h"
#define TOOLVERSION "0.2"
#define UTILITY_NAME "GenCrc32Section"
EFI_GUID gEfiCrc32SectionGuid = EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID;
EFI_STATUS
SignSectionWithCrc32 (
IN OUT UINT8 *FileBuffer,
IN OUT UINT32 *BufferSize,
IN UINT32 DataSize
)
/*++
Routine Description:
Signs the section with CRC32 and add GUIDed section header for the
signed data. data stays in same location (overwrites source data).
Arguments:
FileBuffer - Buffer containing data to sign
BufferSize - On input, the size of FileBuffer. On output, the size of
actual section data (including added section header).
DataSize - Length of data to Sign
Key - Key to use when signing. Currently only CRC32 is supported.
Returns:
EFI_SUCCESS - Successful
EFI_OUT_OF_RESOURCES - Not enough resource to complete the operation.
--*/
{
UINT32 Crc32Checksum;
EFI_STATUS Status;
UINT32 TotalSize;
CRC32_SECTION_HEADER Crc32Header;
UINT8 *SwapBuffer;
Crc32Checksum = 0;
SwapBuffer = NULL;
if (DataSize == 0) {
*BufferSize = 0;
return EFI_SUCCESS;
}
Status = CalculateCrc32 (FileBuffer, DataSize, &Crc32Checksum);
if (EFI_ERROR (Status)) {
return Status;
}
TotalSize = DataSize + CRC32_SECTION_HEADER_SIZE;
Crc32Header.GuidSectionHeader.CommonHeader.Type = EFI_SECTION_GUID_DEFINED;
Crc32Header.GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalSize & 0xff);
Crc32Header.GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalSize & 0xff00) >> 8);
Crc32Header.GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalSize & 0xff0000) >> 16);
memcpy (&(Crc32Header.GuidSectionHeader.SectionDefinitionGuid), &gEfiCrc32SectionGuid, sizeof (EFI_GUID));
Crc32Header.GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID;
Crc32Header.GuidSectionHeader.DataOffset = CRC32_SECTION_HEADER_SIZE;
Crc32Header.CRC32Checksum = Crc32Checksum;
SwapBuffer = (UINT8 *) malloc (DataSize);
if (SwapBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
memcpy (SwapBuffer, FileBuffer, DataSize);
memcpy (FileBuffer, &Crc32Header, CRC32_SECTION_HEADER_SIZE);
memcpy (FileBuffer + CRC32_SECTION_HEADER_SIZE, SwapBuffer, DataSize);
//
// Make sure section ends on a DWORD boundary
//
while ((TotalSize & 0x03) != 0) {
FileBuffer[TotalSize] = 0;
TotalSize++;
}
*BufferSize = TotalSize;
if (SwapBuffer != NULL) {
free (SwapBuffer);
}
return EFI_SUCCESS;
}
VOID
PrintUsage (
VOID
)
{
printf ("Usage:\n");
printf (UTILITY_NAME " -i \"inputfile1\" \"inputfile2\" -o \"outputfile\" \n");
printf (" -i \"inputfile\":\n ");
printf (" specifies the input files that would be signed to CRC32 Guided section.\n");
printf (" -o \"outputfile\":\n");
printf (" specifies the output file that is a CRC32 Guided section.\n");
}
INT32
ReadFilesContentsIntoBuffer (
IN CHAR8 *argv[],
IN INT32 Start,
IN OUT UINT8 **FileBuffer,
IN OUT UINT32 *BufferSize,
OUT UINT32 *ContentSize,
IN INT32 MaximumArguments
)
{
INT32 Index;
CHAR8 *FileName;
FILE *InputFile;
UINT8 Temp;
UINT32 Size;
FileName = NULL;
InputFile = NULL;
Size = 0;
Index = 0;
//
// read all input files into one file buffer
//
while (argv[Start + Index][0] != '-') {
FileName = argv[Start + Index];
InputFile = fopen (FileName, "rb");
if (InputFile == NULL) {
Error (NULL, 0, 0, FileName, "failed to open input binary file");
return -1;
}
fread (&Temp, sizeof (UINT8), 1, InputFile);
while (!feof (InputFile)) {
(*FileBuffer)[Size++] = Temp;
fread (&Temp, sizeof (UINT8), 1, InputFile);
}
fclose (InputFile);
InputFile = NULL;
//
// Make sure section ends on a DWORD boundary
//
while ((Size & 0x03) != 0) {
(*FileBuffer)[Size] = 0;
Size++;
}
Index++;
if (Index == MaximumArguments) {
break;
}
}
*ContentSize = Size;
return Index;
}
int
main (
INT32 argc,
CHAR8 *argv[]
)
{
FILE *OutputFile;
UINT8 *FileBuffer;
UINT32 BufferSize;
EFI_STATUS Status;
UINT32 ContentSize;
CHAR8 *OutputFileName;
INT32 ReturnValue;
INT32 Index;
OutputFile = NULL;
FileBuffer = NULL;
ContentSize = 0;
OutputFileName = NULL;
SetUtilityName (UTILITY_NAME);
if (argc == 1) {
PrintUsage ();
return -1;
}
BufferSize = 1024 * 1024 * 16;
FileBuffer = (UINT8 *) malloc (BufferSize * sizeof (UINT8));
if (FileBuffer == NULL) {
Error (NULL, 0, 0, "memory allocation failed", NULL);
return -1;
}
ZeroMem (FileBuffer, BufferSize);
for (Index = 0; Index < argc; Index++) {
if (strcmpi (argv[Index], "-i") == 0) {
ReturnValue = ReadFilesContentsIntoBuffer (
argv,
(Index + 1),
&FileBuffer,
&BufferSize,
&ContentSize,
(argc - (Index + 1))
);
if (ReturnValue == -1) {
Error (NULL, 0, 0, "failed to read file contents", NULL);
return -1;
}
Index += ReturnValue;
}
if (strcmpi (argv[Index], "-o") == 0) {
OutputFileName = argv[Index + 1];
}
}
OutputFile = fopen (OutputFileName, "wb");
if (OutputFile == NULL) {
Error (NULL, 0, 0, OutputFileName, "failed to open output binary file");
free (FileBuffer);
return -1;
}
/*
//
// make sure section ends on a DWORD boundary ??
//
while ( (Size & 0x03) != 0 ) {
FileBuffer[Size] = 0;
Size ++;
}
*/
Status = SignSectionWithCrc32 (FileBuffer, &BufferSize, ContentSize);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "failed to sign section", NULL);
free (FileBuffer);
fclose (OutputFile);
return -1;
}
ContentSize = fwrite (FileBuffer, sizeof (UINT8), BufferSize, OutputFile);
if (ContentSize != BufferSize) {
Error (NULL, 0, 0, "failed to write output buffer", NULL);
ReturnValue = -1;
} else {
ReturnValue = 0;
}
free (FileBuffer);
fclose (OutputFile);
return ReturnValue;
}

View File

@ -0,0 +1,63 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenCRC32Section.h
Abstract:
Header file for GenFfsFile. Mainly defines the header of section
header for CRC32 GUID defined sections. Share with GenSection.c
--*/
//
// External Files Referenced
//
/* Standard Headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
/* MDE Headers */
#include <Common/UefiBaseTypes.h>
#include <Common/EfiImage.h>
#include <Common/FirmwareVolumeImageFormat.h>
#include <Common/FirmwareFileSystem.h>
#include <Common/FirmwareVolumeHeader.h>
#include <Protocol/GuidedSectionExtraction.h>
/* Tool Headers */
#include "CommonLib.h"
#include "Crc32.h"
#include "EfiCompress.h"
#include "EfiUtilityMsgs.h"
#include "ParseInf.h"
//
// Module Coded to Tiano Coding Conventions
//
#ifndef _EFI_GEN_CRC32_SECTION_H
#define _EFI_GEN_CRC32_SECTION_H
typedef struct {
EFI_GUID_DEFINED_SECTION GuidSectionHeader;
UINT32 CRC32Checksum;
} CRC32_SECTION_HEADER;
#define EFI_SECTION_CRC32_GUID_DEFINED 0
#define CRC32_SECTION_HEADER_SIZE (sizeof (CRC32_SECTION_HEADER))
#endif

View File

@ -0,0 +1,69 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenCRC32Section Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenCRC32Section"/>
<property name="FileSet" value="GenCRC32Section.c GenCRC32Section.h"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,50 @@
/*++
Copyright (c) 2004-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CreateGuid.c
Abstract:
Library routine to create a GUID
--*/
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
void
CreateGuid (
GUID *Guid
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
Guid - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
CoCreateGuid (Guid);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,72 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenCapsuleHdr Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenCapsuleHdr"/>
<property name="FileSet" value="GenCapsuleHdr.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
optimize="speed"
debug="true">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
<syslibset dir="${env.CYGWIN_HOME}/lib/mingw" libs="msvcr71" if="cygwin"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,903 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DepexParser.c
Abstract:
Validate Dependency Expression syntax
recursive descent Algorithm
The original BNF grammar(taken from "Pre EFI Initialization Core Interface Specification
draft review 0.9") is thus:
<depex> ::= BEFORE <guid> END
| AFTER <guid> END
| SOR <bool> END
| <bool> END
<bool> ::= <bool> AND <term>
| <bool> OR <term>
| <term>
<term> ::= NOT <factor>
| <factor>
<factor> ::= <bool>
| TRUE
| FALSE
| GUID
<guid> ::= '{' <hex32> ',' <hex16> ',' <hex16> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> '}'
<hex32> ::= <hexprefix> <hexvalue>
<hex16> ::= <hexprefix> <hexvalue>
<hex8> ::= <hexprefix> <hexvalue>
<hexprefix>::= '0' 'x'
| '0' 'X'
<hexvalue> ::= <hexdigit> <hexvalue>
| <hexdigit>
<hexdigit> ::= [0-9]
| [a-f]
| [A-F]
After cleaning left recursive and parentheses supported, the BNF grammar used in this module is thus:
<depex> ::= BEFORE <guid>
| AFTER <guid>
| SOR <bool>
| <bool>
<bool> ::= <term><rightbool>
<rightbool>::= AND <term><rightbool>
| OR <term><rightbool>
| ''
<term> ::= NOT <factor>
| <factor>
<factor> ::= '('<bool>')'<rightfactor>
| NOT <factor> <rightbool> <rightfactor>
| TRUE <rightfactor>
| FALSE <rightfactor>
| END <rightfactor>
| <guid> <rightfactor>
<rightfactor> ::=AND <term><rightbool> <rightfactor>
| OR <term><rightbool> <rightfactor>
| ''
<guid> ::= '{' <hex32> ',' <hex16> ',' <hex16> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> '}'
<hex32> ::= <hexprefix> <hexvalue>
<hex16> ::= <hexprefix> <hexvalue>
<hex8> ::= <hexprefix> <hexvalue>
<hexprefix>::= '0' 'x'
| '0' 'X'
<hexvalue> ::= <hexdigit> <hexvalue>
| <hexdigit>
<hexdigit> ::= [0-9]
| [a-f]
| [A-F]
Note: 1. There's no precedence in operators except parentheses;
2. For hex32, less and equal than 8 bits is valid, more than 8 bits is invalid.
Same constraint for hex16 is 4, hex8 is 2. All hex should contains at least 1 bit.
3. "<factor> ::= '('<bool>')'<rightfactor>" is added to support parentheses;
4. "<factor> ::= GUID" is changed to "<factor> ::= <guid>";
5. "DEPENDENCY_END" is the terminal of the expression. But it has been filtered by caller.
During parsing, "DEPENDENCY_END" will be treated as illegal factor;
This code should build in any environment that supports a standard C-library w/ string
operations and File I/O services.
As an example of usage, consider the following:
The input string could be something like:
NOT ({ 0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72,
0x3b } AND { 0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69,
0x72, 0x3b }) OR { 0x03c4e603, 0xac28, 0x11d3, 0x9a, 0x2d, 0x00, 0x90, 0x27,
0x3f, 0xc1, 0x4d } AND
It's invalid for an extra "AND" in the end.
Complies with Tiano C Coding Standards Document, version 0.33, 16 Aug 2001.
--*/
#include "DepexParser.h"
BOOLEAN
ParseBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
BOOLEAN
ParseTerm (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
BOOLEAN
ParseRightBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
BOOLEAN
ParseFactor (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
VOID
LeftTrim (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Left trim the space, '\n' and '\r' character in string.
The space at the end does not need trim.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
None
--*/
{
while
(
((*Pindex) < (Pbegin + length)) &&
((strncmp (*Pindex, " ", 1) == 0) || (strncmp (*Pindex, "\n", 1) == 0) || (strncmp (*Pindex, "\r", 1) == 0))
) {
(*Pindex)++;
}
}
BOOLEAN
ParseHexdigit (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex bit in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex bit, return TRUE, otherwise FALSE
--*/
{
//
// <hexdigit> ::= [0-9] | [a-f] | [A-F]
//
if (((**Pindex) >= '0' && (**Pindex) <= '9') ||
((**Pindex) >= 'a' && (**Pindex) <= 'f') ||
((**Pindex) >= 'A' && (**Pindex) <= 'F')
) {
(*Pindex)++;
return TRUE;
} else {
return FALSE;
}
}
BOOLEAN
ParseHex32 (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex32 in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of point to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex32, return TRUE, otherwise FALSE
--*/
{
INT32 Index;
INT8 *Pin;
Index = 0;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if ((strncmp (*Pindex, "0x", 2) != 0) && (strncmp (*Pindex, "0X", 2) != 0)) {
return FALSE;
}
(*Pindex) += 2;
while (ParseHexdigit (Pbegin, length, Pindex)) {
Index++;
}
if (Index > 0 && Index <= 8) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseHex16 (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex16 in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex16, return TRUE, otherwise FALSE
--*/
{
int Index;
INT8 *Pin;
Index = 0;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if ((strncmp (*Pindex, "0x", 2) != 0) && (strncmp (*Pindex, "0X", 2) != 0)) {
return FALSE;
}
(*Pindex) += 2;
while (ParseHexdigit (Pbegin, length, Pindex)) {
Index++;
}
if (Index > 0 && Index <= 4) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseHex8 (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex8 in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex8, return TRUE, otherwise FALSE
--*/
{
int Index;
INT8 *Pin;
Index = 0;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if ((strncmp (*Pindex, "0x", 2) != 0) && (strncmp (*Pindex, "0X", 2) != 0)) {
return FALSE;
}
(*Pindex) += 2;
while (ParseHexdigit (Pbegin, length, Pindex)) {
Index++;
}
if (Index > 0 && Index <= 2) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseGuid (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse guid in dependency expression.
There can be any number of spaces between '{' and hexword, ',' and hexword,
hexword and ',', hexword and '}'. The hexword include hex32, hex16 and hex8.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid guid, return TRUE, otherwise FALSE
--*/
{
INT32 Index;
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "{", 1) != 0) {
return FALSE;
}
(*Pindex)++;
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex32 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, ",", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
for (Index = 0; Index < 2; Index++) {
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex16 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, ",", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "{", 1) != 0) {
return FALSE;
}
(*Pindex)++;
for (Index = 0; Index < 7; Index++) {
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex8 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, ",", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
}
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex8 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "}", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "}", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
return TRUE;
}
BOOLEAN
ParseRightFactor (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse rightfactor in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid rightfactor expression, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <rightfactor> ::=AND <term> <rightbool> <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_AND, strlen (OPERATOR_AND)) == 0) {
*Pindex += strlen (OPERATOR_AND);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightfactor> ::=OR <term> <rightbool> <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_OR, strlen (OPERATOR_OR)) == 0) {
*Pindex += strlen (OPERATOR_OR);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightfactor> ::= ''
//
*Pindex = Pin;
return TRUE;
}
BOOLEAN
ParseRightBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse rightbool in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid rightbool expression, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <rightbool>::= AND <term><rightbool>
//
if (strncmp (*Pindex, OPERATOR_AND, strlen (OPERATOR_AND)) == 0) {
*Pindex += strlen (OPERATOR_AND);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightbool>::= OR <term><rightbool>
//
if (strncmp (*Pindex, OPERATOR_OR, strlen (OPERATOR_OR)) == 0) {
*Pindex += strlen (OPERATOR_OR);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightbool>::= ''
//
*Pindex = Pin;
return TRUE;
}
BOOLEAN
ParseFactor (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse factor in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid factor, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <factor> ::= '('<bool>')'<rightfactor>
//
if (strncmp (*Pindex, OPERATOR_LEFT_PARENTHESIS, strlen (OPERATOR_LEFT_PARENTHESIS)) == 0) {
*Pindex += strlen (OPERATOR_LEFT_PARENTHESIS);
LeftTrim (Pbegin, length, Pindex);
if (!ParseBool (Pbegin, length, Pindex)) {
*Pindex = Pin;
} else {
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, OPERATOR_RIGHT_PARENTHESIS, strlen (OPERATOR_RIGHT_PARENTHESIS)) == 0) {
*Pindex += strlen (OPERATOR_RIGHT_PARENTHESIS);
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
}
}
}
//
// <factor> ::= NOT <factor> <rightbool> <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_NOT, strlen (OPERATOR_NOT)) == 0) {
*Pindex += strlen (OPERATOR_NOT);
LeftTrim (Pbegin, length, Pindex);
if (ParseFactor (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <factor> ::= TRUE <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_TRUE, strlen (OPERATOR_TRUE)) == 0) {
*Pindex += strlen (OPERATOR_TRUE);
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
}
//
// <factor> ::= FALSE <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_FALSE, strlen (OPERATOR_FALSE)) == 0) {
*Pindex += strlen (OPERATOR_FALSE);
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
}
//
// <factor> ::= <guid> <rightfactor>
//
if (ParseGuid (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseTerm (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse term in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid term, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <term> ::= NOT <factor>
//
if (strncmp (*Pindex, OPERATOR_NOT, strlen (OPERATOR_NOT)) == 0) {
*Pindex += strlen (OPERATOR_NOT);
LeftTrim (Pbegin, length, Pindex);
if (!ParseFactor (Pbegin, length, Pindex)) {
*Pindex = Pin;
} else {
return TRUE;
}
}
//
// <term> ::=<factor>
//
if (ParseFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid bool expression, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (!ParseRightBool (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
} else {
return TRUE;
}
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseDepex (
IN INT8 *Pbegin,
IN UINT32 length
)
/*++
Routine Description:
Parse whole dependency expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Returns:
BOOLEAN If string is a valid dependency expression, return TRUE, otherwise FALSE
--*/
{
BOOLEAN Result;
INT8 **Pindex;
INT8 *temp;
Result = FALSE;
temp = Pbegin;
Pindex = &temp;
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, OPERATOR_BEFORE, strlen (OPERATOR_BEFORE)) == 0) {
(*Pindex) += strlen (OPERATOR_BEFORE);
Result = ParseGuid (Pbegin, length, Pindex);
} else if (strncmp (*Pindex, OPERATOR_AFTER, strlen (OPERATOR_AFTER)) == 0) {
(*Pindex) += strlen (OPERATOR_AFTER);
Result = ParseGuid (Pbegin, length, Pindex);
} else if (strncmp (*Pindex, OPERATOR_SOR, strlen (OPERATOR_SOR)) == 0) {
(*Pindex) += strlen (OPERATOR_SOR);
Result = ParseBool (Pbegin, length, Pindex);
} else {
Result = ParseBool (Pbegin, length, Pindex);
}
LeftTrim (Pbegin, length, Pindex);
return (BOOLEAN) (Result && (*Pindex) >= (Pbegin + length));
}

View File

@ -0,0 +1,26 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenDepex.h
Abstract:
This file contains the relevant declarations required
to generate a binary Dependency File
Complies with Tiano C Coding Standards Document, version 0.31, 12 Dec 2000.
--*/
// TODO: fix comment to set correct module name: DepexParser.h
#ifndef _EFI_DEPEX_PARSER_H_
#define _EFI_DEPEX_PARSER_H_
#include "GenDepex.h"
#endif

View File

@ -0,0 +1,919 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenDepex.c
Abstract:
Generate Dependency Expression ("GenDepex")
Infix to Postfix Algorithm
This code has been scrubbed to be free of having any EFI core tree dependencies.
It should build in any environment that supports a standard C-library w/ string
operations and File I/O services.
As an example of usage, consider the following:
The input user file could be something like "Sample.DXS" whose contents are
#include "Tiano.h"
DEPENDENCY_START
NOT (DISK_IO_PROTOCOL AND SIMPLE_FILE_SYSTEM_PROTOCOL)
OR EFI_PXE_BASE_CODE_PROTOCOL
DEPENDENCY_END
This file is then washed through the C-preprocessor, viz.,
cl /EP Sample.DXS > Sample.TMP1
This yields the following file "Sample.TMP1" whose contents are
DEPENDENCY_START
NOT ({ 0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72,
0x3b } AND { 0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69,
0x72, 0x3b }) OR { 0x03c4e603, 0xac28, 0x11d3, 0x9a, 0x2d, 0x00, 0x90, 0x27,
0x3f, 0xc1, 0x4d }
DEPENDENCY_END
This file, in turn, will be fed into the utility, viz.,
GenDepex Sample.TMP1 Sample.TMP2
With a file that is 55 bytes long:
55 bytes for the grammar binary
PUSH opcode - 1 byte
GUID Instance - 16 bytes
PUSH opcode - 1 byte
GUID Instance - 16 bytes
AND opcode - 1 byte
NOT opcode - 1 byte
PUSH opcode - 1 byte
GUID Instance - 16 bytes
OR opcode - 1 byte
END opcode - 1 byte
The file "Sample.TMP2" could be fed via a Section-builder utility
(GenSection) that would be used for the creation of a dependency
section file (.DPX) which in turn would be used by a generate FFS
utility (GenFfsFile) to produce a DXE driver/core (.DXE) or
a DXE application (.APP) file.
Complies with Tiano C Coding Standards Document, version 0.31, 12 Dec 2000.
--*/
#include "GenDepex.h"
#define TOOL_NAME "GenDepex"
extern
ParseDepex (
IN INT8 *Pbegin,
IN UINT32 length
);
VOID
PrintGenDepexUtilityInfo (
VOID
)
/*++
Routine Description:
Displays the standard utility information to SDTOUT.
Arguments:
None
Returns:
None
--*/
{
printf (
"%s, Tiano Dependency Expression Generation Utility. Version %d.%d.\n",
UTILITY_NAME,
UTILITY_MAJOR_VERSION,
UTILITY_MINOR_VERSION
);
printf ("Copyright (C) 1996-2002 Intel Corporation. All rights reserved.\n\n");
}
VOID
PrintGenDepexUsageInfo (
VOID
)
/*++
Routine Description:
Displays the utility usage syntax to STDOUT.
Arguments:
None
Returns:
None
--*/
{
printf (
"Usage: %s -I <INFILE> -O <OUTFILE> [-P <Optional Boundary for padding up>] \n",
UTILITY_NAME
);
printf (" Where:\n");
printf (" <INFILE> is the input pre-processed dependency text files name.\n");
printf (" <OUTFILE> is the output binary dependency files name.\n");
printf (" <Optional Boundary for padding up> is the padding integer value.\n");
printf (" This is the boundary to align the output file size to.\n");
}
DEPENDENCY_OPCODE
PopOpCode (
IN OUT VOID **Stack
)
/*++
Routine Description:
Pop an element from the Opcode stack.
Arguments:
Stack Current top of the OpCode stack location
Returns:
DEPENDENCY_OPCODE OpCode at the top of the OpCode stack.
Stack New top of the OpCode stack location
--*/
{
DEPENDENCY_OPCODE *OpCodePtr;
OpCodePtr = *Stack;
OpCodePtr--;
*Stack = OpCodePtr;
return *OpCodePtr;
}
VOID
PushOpCode (
IN OUT VOID **Stack,
IN DEPENDENCY_OPCODE OpCode
)
/*++
Routine Description:
Push an element onto the Opcode Stack
Arguments:
Stack Current top of the OpCode stack location
OpCode OpCode to push onto the stack
Returns:
Stack New top of the OpCode stack location
--*/
{
DEPENDENCY_OPCODE *OpCodePtr;
OpCodePtr = *Stack;
*OpCodePtr = OpCode;
OpCodePtr++;
*Stack = OpCodePtr;
}
EFI_STATUS
GenerateDependencyExpression (
IN FILE *InFile,
IN OUT FILE *OutFile,
IN INT8 Padding OPTIONAL
)
/*++
Routine Description:
This takes the pre-compiled dependency text file and
converts it into a binary dependency file.
The BNF for the dependency expression is as follows
(from the DXE 1.0 Draft specification).
The inputted BNF grammar is thus:
<depex> ::= sor <dep> |
before GUID <dep> |
after GUID <dep> |
<bool>
<dep> ::= <bool> |
<bool> ::= <bool> and <term> |
<bool> or <term> |
<term>
<term> ::= not <factor> |
<factor>
<factor> ::= ( <bool> ) |
<term> <term> |
GUID |
<boolval>
<boolval> ::= true |
false
The outputed binary grammer is thus:
<depex> ::= sor <dep> |
before <depinst> <dep> |
after <depinst> <dep> |
<bool>
<dep> ::= <bool> |
<bool> ::= <bool> and <term> |
<bool> or <term> | <term>
<term> ::= not <factor> |
<factor>
<factor> ::= ( <bool> ) |
<term> <term> |
<boolval> |
<depinst> |
<termval>
<boolval> ::= true |
false
<depinst> ::= push GUID
<termval> ::= end
BugBug: A correct grammer is parsed correctly. A file that violates the
grammer may parse when it should generate an error. There is some
error checking and it covers most of the case when it's an include
of definition issue. An ill formed expresion may not be detected.
Arguments:
InFile - Input pre-compiled text file of the dependency expression.
This needs to be in ASCII.
The file pointer can not be NULL.
OutFile - Binary dependency file.
The file pointer can not be NULL.
Padding - OPTIONAL integer value to pad the output file to.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the parameters in the text file was invalid.
EFI_OUT_OF_RESOURCES Unable to allocate memory.
EFI_ABORTED An misc error occurred.
--*/
{
INT8 *Ptrx;
INT8 *Pend;
INT8 *EvaluationStack;
INT8 *StackPtr;
INT8 *Buffer;
INT8 Line[LINESIZE];
UINTN Index;
UINTN OutFileSize;
UINTN FileSize;
UINTN Results;
BOOLEAN NotDone;
BOOLEAN Before_Flag;
BOOLEAN After_Flag;
BOOLEAN Dep_Flag;
BOOLEAN SOR_Flag;
EFI_GUID Guid;
UINTN ArgCountParsed;
DEPENDENCY_OPCODE Opcode;
Before_Flag = FALSE;
After_Flag = FALSE;
Dep_Flag = FALSE;
SOR_Flag = FALSE;
memset (Line, 0, LINESIZE);
OutFileSize = 0;
EvaluationStack = (INT8 *) malloc (EVAL_STACK_SIZE);
if (EvaluationStack != NULL) {
StackPtr = EvaluationStack;
} else {
printf ("Unable to allocate memory to EvaluationStack - Out of resources\n");
return EFI_OUT_OF_RESOURCES;
}
Results = (UINTN) fseek (InFile, 0, SEEK_END);
if (Results != 0) {
printf ("FSEEK failed - Aborted\n");
return EFI_ABORTED;
}
FileSize = ftell (InFile);
if (FileSize == -1L) {
printf ("FTELL failed - Aborted\n");
return EFI_ABORTED;
}
Buffer = (INT8 *) malloc (FileSize + BUFFER_SIZE);
if (Buffer == NULL) {
printf ("Unable to allocate memory to Buffer - Out of resources\n");
free (EvaluationStack);
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
return EFI_OUT_OF_RESOURCES;
}
Results = (UINTN) fseek (InFile, 0, SEEK_SET);
if (Results != 0) {
printf ("FSEEK failed - Aborted\n");
return EFI_ABORTED;
}
memset (Buffer, 0, FileSize + BUFFER_SIZE);
fread (Buffer, FileSize, 1, InFile);
Ptrx = Buffer;
Pend = Ptrx + FileSize - strlen (DEPENDENCY_END);
Index = FileSize;
NotDone = TRUE;
while ((Index--) && NotDone) {
if (strncmp (Pend, DEPENDENCY_END, strlen (DEPENDENCY_END)) == 0) {
NotDone = FALSE;
} else {
Pend--;
}
}
if (NotDone) {
printf ("Couldn't find end string %s\n", DEPENDENCY_END);
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_INVALID_PARAMETER;
}
Index = FileSize;
NotDone = TRUE;
while ((Index--) && NotDone) {
if (strncmp (Ptrx, DEPENDENCY_START, strlen (DEPENDENCY_START)) == 0) {
Ptrx += sizeof (DEPENDENCY_START);
NotDone = FALSE;
//
// BUGBUG -- should Index be decremented by sizeof(DEPENDENCY_START)?
//
} else {
Ptrx++;
}
}
if (NotDone) {
printf ("Couldn't find start string %s\n", DEPENDENCY_START);
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_INVALID_PARAMETER;
}
//
// validate the syntax of expression
//
if (!ParseDepex (Ptrx, Pend - Ptrx - 1)) {
printf ("The syntax of expression is wrong\n");
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_INVALID_PARAMETER;
}
NotDone = TRUE;
while ((Index--) && NotDone) {
if (*Ptrx == ' ') {
Ptrx++;
} else if (*Ptrx == '\n' || *Ptrx == '\r') {
Ptrx++;
} else if (strncmp (Ptrx, OPERATOR_SOR, strlen (OPERATOR_SOR)) == 0) {
//
// Checks for some invalid dependencies
//
if (Before_Flag) {
printf ("A BEFORE operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (After_Flag) {
printf ("An AFTER operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (SOR_Flag) {
printf ("Another SOR operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (Dep_Flag) {
printf ("The Schedule On Request - SOR operator must be the first operator following DEPENDENCY_START\n");
return EFI_INVALID_PARAMETER;
} else {
//
// BUGBUG - This was not in the spec but is in the CORE code
// An OPERATOR_SOR has to be first - following the DEPENDENCY_START
//
fputc (EFI_DEP_SOR, OutFile);
OutFileSize++;
Ptrx += sizeof (OPERATOR_SOR);
SOR_Flag = TRUE;
}
} else if (strncmp (Ptrx, OPERATOR_BEFORE, strlen (OPERATOR_BEFORE)) == 0) {
//
// Checks for some invalid dependencies
//
if (Before_Flag) {
printf ("Another BEFORE operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (After_Flag) {
printf ("An AFTER operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (SOR_Flag) {
printf ("A SOR operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (Dep_Flag) {
printf ("The BEFORE operator must be the first operator following DEPENDENCY_START\n");
return EFI_INVALID_PARAMETER;
} else {
fputc (EFI_DEP_BEFORE, OutFile);
OutFileSize++;
Ptrx += sizeof (OPERATOR_BEFORE);
Before_Flag = TRUE;
}
} else if (strncmp (Ptrx, OPERATOR_AFTER, strlen (OPERATOR_AFTER)) == 0) {
//
// Checks for some invalid dependencies
//
if (Before_Flag) {
printf ("A BEFORE operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (After_Flag) {
printf ("Another AFTER operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (SOR_Flag) {
printf ("A SOR operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (Dep_Flag) {
printf ("The AFTER operator must be the first operator following DEPENDENCY_START\n");
return EFI_INVALID_PARAMETER;
} else {
fputc (EFI_DEP_AFTER, OutFile);
OutFileSize++;
Ptrx += sizeof (OPERATOR_AFTER);
Dep_Flag = TRUE;
After_Flag = TRUE;
}
} else if (strncmp (Ptrx, OPERATOR_AND, strlen (OPERATOR_AND)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
break;
}
}
PushOpCode ((VOID **) &StackPtr, EFI_DEP_AND);
Ptrx += sizeof (OPERATOR_AND);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_OR, strlen (OPERATOR_OR)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
break;
}
}
PushOpCode ((VOID **) &StackPtr, EFI_DEP_OR);
Ptrx += sizeof (OPERATOR_OR);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_NOT, strlen (OPERATOR_NOT)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
break;
}
}
PushOpCode ((VOID **) &StackPtr, EFI_DEP_NOT);
Ptrx += sizeof (OPERATOR_NOT);
Dep_Flag = TRUE;
} else if (*Ptrx == '\t') {
printf ("File contains tabs. This violates the coding standard\n");
return EFI_INVALID_PARAMETER;
} else if (*Ptrx == '\n') {
//
// Skip the newline character in the file
//
Ptrx++;
} else if (strncmp (Ptrx, OPERATOR_LEFT_PARENTHESIS, strlen (OPERATOR_LEFT_PARENTHESIS)) == 0) {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
Ptrx += strlen (OPERATOR_LEFT_PARENTHESIS);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_RIGHT_PARENTHESIS, strlen (OPERATOR_RIGHT_PARENTHESIS)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
break;
}
}
Ptrx += strlen (OPERATOR_RIGHT_PARENTHESIS);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_TRUE, strlen (OPERATOR_TRUE)) == 0) {
fputc (EFI_DEP_TRUE, OutFile);
OutFileSize++;
//
// OutFileSize += sizeof (EFI_DEP_TRUE);
//
Dep_Flag = TRUE;
Ptrx += strlen (OPERATOR_TRUE);
} else if (strncmp (Ptrx, OPERATOR_FALSE, strlen (OPERATOR_FALSE)) == 0) {
fputc (EFI_DEP_FALSE, OutFile);
OutFileSize++;
//
// OutFileSize += sizeof (EFI_DEP_FALSE);
//
Dep_Flag = TRUE;
Ptrx += strlen (OPERATOR_FALSE);
} else if (*Ptrx == '{') {
Ptrx++;
if (*Ptrx == ' ') {
Ptrx++;
}
{
int byte_index;
// This is an array of UINT32s. sscanf will trash memory
// if you try to read into a UINT8 with a %x formatter.
UINT32 Guid_Data4[8];
ArgCountParsed = sscanf (
Ptrx,
"%x, %x, %x, { %x, %x, %x, %x, %x, %x, %x, %x }",
&Guid.Data1,
&Guid.Data2,
&Guid.Data3,
&Guid_Data4[0],
&Guid_Data4[1],
&Guid_Data4[2],
&Guid_Data4[3],
&Guid_Data4[4],
&Guid_Data4[5],
&Guid_Data4[6],
&Guid_Data4[7]
);
// Now we can copy the 32 bit ints into the GUID.
for (byte_index=0; byte_index<8; byte_index++) {
Guid.Data4[byte_index] = (UINT8) Guid_Data4[byte_index];
}
}
if (ArgCountParsed != 11) {
printf ("We have found an illegal GUID\n");
printf ("Fix your depex\n");
exit (-1);
}
while (*Ptrx != '}') {
Ptrx++;
}
Ptrx++;
while (*Ptrx != '}') {
Ptrx++;
}
//
// Absorb the closing }
//
Ptrx++;
//
// Don't provide a PUSH Opcode for the Before and After case
//
if ((!Before_Flag) && (!After_Flag)) {
fputc (EFI_DEP_PUSH, OutFile);
OutFileSize++;
}
fwrite (&Guid, sizeof (EFI_GUID), 1, OutFile);
OutFileSize += sizeof (EFI_GUID);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, DEPENDENCY_END, strlen (DEPENDENCY_END)) == 0) {
NotDone = FALSE;
} else {
//
// Not a valid construct. Null terminate somewhere out there and
// print an error message.
//
*(Ptrx + 20) = 0;
printf (TOOL_NAME " ERROR: Unrecognized input at: \"%s\"...\n", Ptrx);
return EFI_INVALID_PARAMETER;
}
}
//
// DRAIN();
//
while (StackPtr != EvaluationStack) {
fputc (PopOpCode ((VOID **) &StackPtr), OutFile);
OutFileSize++;
}
if (OutFileSize == 0) {
printf ("Grammer contains no operators or constants\n");
return EFI_INVALID_PARAMETER;
}
fputc (EFI_DEP_END, OutFile);
OutFileSize++;
//
// Checks for invalid padding values
//
if (Padding < 0) {
printf ("The inputted padding value was %d\n", Padding);
printf ("The optional padding value can not be less than ZERO\n");
return EFI_INVALID_PARAMETER;
} else if (Padding > 0) {
while ((OutFileSize % Padding) != 0) {
fputc (' ', OutFile);
OutFileSize++;
}
}
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_SUCCESS;
} // End GenerateDependencyExpression function
int
main (
IN UINTN argc,
IN CHAR8 *argv[]
)
/*++
Routine Description:
Parse user entries. Print some rudimentary help
Arguments:
argc The count of input arguments
argv The input arguments string array
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid or one of the parameters in the text file was invalid.
EFI_OUT_OF_RESOURCES Unable to allocate memory.
EFI_ABORTED Unable to open/create a file or a misc error.
--*/
// TODO: ] - add argument and description to function comment
{
FILE *OutFile;
FILE *InFile;
UINT8 Padding;
UINTN Index;
BOOLEAN Input_Flag;
BOOLEAN Output_Flag;
BOOLEAN Pad_Flag;
InFile = NULL;
OutFile = NULL;
Padding = 0;
Input_Flag = FALSE;
Output_Flag = FALSE;
Pad_Flag = FALSE;
if (argc < 5) {
printf ("Not enough arguments\n");
PrintGenDepexUsageInfo ();
return EFI_INVALID_PARAMETER;
}
for (Index = 1; Index < argc - 1; Index++) {
if ((strcmp (argv[Index], "-I") == 0) || (strcmp (argv[Index], "-i") == 0)) {
if (!Input_Flag) {
InFile = fopen (argv[Index + 1], "rb");
Input_Flag = TRUE;
} else {
printf ("GenDepex only allows one INPUT (-I) argument\n");
return EFI_INVALID_PARAMETER;
}
} else if ((strcmp (argv[Index], "-O") == 0) || (strcmp (argv[Index], "-o") == 0)) {
if (!Output_Flag) {
OutFile = fopen (argv[Index + 1], "wb");
Output_Flag = TRUE;
} else {
printf ("GenDepex only allows one OUTPUT (-O) argument\n");
return EFI_INVALID_PARAMETER;
}
} else if ((strcmp (argv[Index], "-P") == 0) || (strcmp (argv[Index], "-p") == 0)) {
if (!Pad_Flag) {
Padding = (UINT8) atoi (argv[Index + 1]);
Pad_Flag = TRUE;
} else {
printf ("GenDepex only allows one PADDING (-P) argument\n");
return EFI_INVALID_PARAMETER;
}
}
}
PrintGenDepexUtilityInfo ();
if (InFile == NULL) {
printf ("Can not open <INFILE> for reading.\n");
PrintGenDepexUsageInfo ();
return EFI_ABORTED;
}
if (OutFile == NULL) {
printf ("Can not open <OUTFILE> for writting.\n");
PrintGenDepexUsageInfo ();
return EFI_ABORTED;
}
return GenerateDependencyExpression (InFile, OutFile, Padding);
}

View File

@ -0,0 +1,71 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenDepex.h
Abstract:
This file contains the relevant declarations required
to generate a binary Dependency File
Complies with Tiano C Coding Standards Document, version 0.31, 12 Dec 2000.
--*/
#ifndef _EFI_GEN_DEPEX_H
#define _EFI_GEN_DEPEX_H
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#ifndef __GNUC__
#include <malloc.h>
#endif
#include <Common/UefiBaseTypes.h>
#include <Common/Dependency.h>
#define DEPENDENCY_START "DEPENDENCY_START"
#define OPERATOR_BEFORE "BEFORE"
#define OPERATOR_AFTER "AFTER"
#define OPERATOR_AND "AND"
#define OPERATOR_OR "OR"
#define OPERATOR_NOT "NOT"
#define OPERATOR_TRUE "TRUE"
#define OPERATOR_FALSE "FALSE"
#define OPERATOR_SOR "SOR"
#define OPERATOR_END "END"
#define OPERATOR_LEFT_PARENTHESIS "("
#define OPERATOR_RIGHT_PARENTHESIS ")"
#define DEPENDENCY_END "DEPENDENCY_END"
#define DXE_DEP_LEFT_PARENTHESIS 0x0a
#define DXE_DEP_RIGHT_PARENTHESIS 0x0b
#define LINESIZE 320
#define SIZE_A_SYMBOL 60
#define DEPENDENCY_OPCODE UINT8
#define EVAL_STACK_SIZE 0x1024
#define BUFFER_SIZE 0x100
//
// Utility Name
//
#define UTILITY_NAME "GenDepex"
//
// Utility version information
//
#define UTILITY_MAJOR_VERSION 0
#define UTILITY_MINOR_VERSION 5
#endif

View File

@ -0,0 +1,68 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenDepex Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenDepex"/>
<property name="FileSet" value="DepexParser.c GenDepex.c GenDepex.h"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}" />
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/Ia32"/>
<includepath path="${PACKAGE_DIR}/Common"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFfsFile.h
Abstract:
Header file for GenFfsFile.
--*/
//
// Module Coded to Tiano Coding Conventions
//
#ifndef _EFI_GEN_FFSFILE_H
#define _EFI_GEN_FFSFILE_H
//
// External Files Referenced
//
#include <Common/UefiBaseTypes.h>
#include <Common/FirmwareVolumeImageFormat.h>
#include "MyAlloc.h"
#endif

View File

@ -0,0 +1,969 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SimpleFileParsing.c
Abstract:
Generic but simple file parsing routines.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <Common/UefiBaseTypes.h>
#include "EfiUtilityMsgs.h"
#include "SimpleFileParsing.h"
#define MAX_PATH 255
#define MAX_NEST_DEPTH 20 // just in case we get in an endless loop.
#define MAX_STRING_IDENTIFIER_NAME 100 // number of wchars
#define MAX_LINE_LEN 400
#define T_CHAR_SPACE ' '
#define T_CHAR_NULL 0
#define T_CHAR_CR '\r'
#define T_CHAR_TAB '\t'
#define T_CHAR_LF '\n'
#define T_CHAR_SLASH '/'
#define T_CHAR_BACKSLASH '\\'
#define T_CHAR_DOUBLE_QUOTE '"'
#define T_CHAR_LC_X 'x'
#define T_CHAR_0 '0'
//
// We keep a linked list of these for the source files we process
//
typedef struct _SOURCE_FILE {
FILE *Fptr;
T_CHAR *FileBuffer;
T_CHAR *FileBufferPtr;
UINT32 FileSize;
INT8 FileName[MAX_PATH];
UINT32 LineNum;
BOOLEAN EndOfFile;
BOOLEAN SkipToHash;
struct _SOURCE_FILE *Previous;
struct _SOURCE_FILE *Next;
T_CHAR ControlCharacter;
} SOURCE_FILE;
//
// Here's all our module globals.
//
static struct {
SOURCE_FILE SourceFile;
BOOLEAN Verbose;
} mGlobals;
static
UINT32
t_strcmp (
T_CHAR *Buffer,
T_CHAR *Str
);
static
UINT32
t_strncmp (
T_CHAR *Str1,
T_CHAR *Str2,
UINT32 Len
);
static
UINT32
t_strlen (
T_CHAR *Str
);
static
void
RewindFile (
SOURCE_FILE *SourceFile
);
static
BOOLEAN
SkipTo (
SOURCE_FILE *SourceFile,
T_CHAR TChar,
BOOLEAN StopAfterNewline
);
static
BOOLEAN
IsWhiteSpace (
SOURCE_FILE *SourceFile
);
static
UINT32
SkipWhiteSpace (
SOURCE_FILE *SourceFile
);
static
BOOLEAN
EndOfFile (
SOURCE_FILE *SourceFile
);
static
void
PreprocessFile (
SOURCE_FILE *SourceFile
);
//
// static
// T_CHAR *
// GetQuotedString (
// SOURCE_FILE *SourceFile,
// BOOLEAN Optional
// );
//
static
T_CHAR *
t_strcpy (
T_CHAR *Dest,
T_CHAR *Src
);
static
STATUS
ProcessIncludeFile (
SOURCE_FILE *SourceFile,
SOURCE_FILE *ParentSourceFile
);
static
STATUS
ParseFile (
SOURCE_FILE *SourceFile
);
static
FILE *
FindFile (
IN INT8 *FileName,
OUT INT8 *FoundFileName,
IN UINT32 FoundFileNameLen
);
static
STATUS
ProcessFile (
SOURCE_FILE *SourceFile
);
STATUS
SFPInit (
VOID
)
{
memset ((void *) &mGlobals, 0, sizeof (mGlobals));
return STATUS_SUCCESS;
}
UINT32
SFPGetLineNumber (
VOID
)
{
return mGlobals.SourceFile.LineNum;
}
/*++
Routine Description:
Return the line number of the file we're parsing. Used
for error reporting purposes.
Arguments:
None.
Returns:
The line number, or 0 if no file is being processed
--*/
T_CHAR *
SFPGetFileName (
VOID
)
/*++
Routine Description:
Return the name of the file we're parsing. Used
for error reporting purposes.
Arguments:
None.
Returns:
A pointer to the file name. Null if no file is being
processed.
--*/
{
if (mGlobals.SourceFile.FileName[0]) {
return mGlobals.SourceFile.FileName;
}
return NULL;
}
STATUS
SFPOpenFile (
IN INT8 *FileName
)
/*++
Routine Description:
Open a file for parsing.
Arguments:
FileName - name of the file to parse
Returns:
--*/
{
STATUS Status;
t_strcpy (mGlobals.SourceFile.FileName, FileName);
Status = ProcessIncludeFile (&mGlobals.SourceFile, NULL);
return Status;
}
BOOLEAN
SFPIsToken (
T_CHAR *Str
)
/*++
Routine Description:
Check to see if the specified token is found at
the current position in the input file.
Arguments:
Str - the token to look for
Returns:
TRUE - the token is next
FALSE - the token is not next
Notes:
We do a simple string comparison on this function. It is
the responsibility of the caller to ensure that the token
is not a subset of some other token.
The file pointer is advanced past the token in the input file.
--*/
{
UINT32 Len;
SkipWhiteSpace (&mGlobals.SourceFile);
if ((Len = t_strcmp (mGlobals.SourceFile.FileBufferPtr, Str)) > 0) {
mGlobals.SourceFile.FileBufferPtr += Len;
return TRUE;
}
return FALSE;
}
BOOLEAN
SFPGetNextToken (
T_CHAR *Str,
UINT32 Len
)
{
UINT32 Index;
SkipWhiteSpace (&mGlobals.SourceFile);
Index = 0;
while (!EndOfFile (&mGlobals.SourceFile) && (Index < Len)) {
if (IsWhiteSpace (&mGlobals.SourceFile)) {
if (Index > 0) {
Str[Index] = 0;
return TRUE;
}
return FALSE;
} else {
Str[Index] = mGlobals.SourceFile.FileBufferPtr[0];
mGlobals.SourceFile.FileBufferPtr++;
Index++;
}
}
return FALSE;
}
BOOLEAN
SFPSkipToToken (
T_CHAR *Str
)
{
UINT32 Len;
T_CHAR *SavePos;
Len = t_strlen (Str);
SavePos = mGlobals.SourceFile.FileBufferPtr;
SkipWhiteSpace (&mGlobals.SourceFile);
while (!EndOfFile (&mGlobals.SourceFile)) {
if (t_strncmp (Str, mGlobals.SourceFile.FileBufferPtr, Len) == 0) {
mGlobals.SourceFile.FileBufferPtr += Len;
return TRUE;
}
mGlobals.SourceFile.FileBufferPtr++;
SkipWhiteSpace (&mGlobals.SourceFile);
}
mGlobals.SourceFile.FileBufferPtr = SavePos;
return FALSE;
}
BOOLEAN
SFPGetNumber (
UINT32 *Value
)
/*++
Routine Description:
Check the token at the current file position for a numeric value.
May be either decimal or hex.
Arguments:
Value - pointer where to store the value
Returns:
FALSE - current token is not a number
TRUE - current token is a number
--*/
{
//
// UINT32 Len;
//
SkipWhiteSpace (&mGlobals.SourceFile);
if (EndOfFile (&mGlobals.SourceFile)) {
return FALSE;
}
if (isdigit (mGlobals.SourceFile.FileBufferPtr[0])) {
//
// Check for hex value
//
if ((mGlobals.SourceFile.FileBufferPtr[0] == T_CHAR_0) && (mGlobals.SourceFile.FileBufferPtr[1] == T_CHAR_LC_X)) {
if (!isxdigit (mGlobals.SourceFile.FileBufferPtr[2])) {
return FALSE;
}
mGlobals.SourceFile.FileBufferPtr += 2;
sscanf (mGlobals.SourceFile.FileBufferPtr, "%x", Value);
while (isxdigit (mGlobals.SourceFile.FileBufferPtr[0])) {
mGlobals.SourceFile.FileBufferPtr++;
}
return TRUE;
} else {
*Value = atoi (mGlobals.SourceFile.FileBufferPtr);
while (isdigit (mGlobals.SourceFile.FileBufferPtr[0])) {
mGlobals.SourceFile.FileBufferPtr++;
}
return TRUE;
}
} else {
return FALSE;
}
}
STATUS
SFPCloseFile (
VOID
)
/*++
Routine Description:
Close the file being parsed.
Arguments:
None.
Returns:
STATUS_SUCCESS - the file was closed
STATUS_ERROR - no file is currently open
--*/
{
if (mGlobals.SourceFile.FileBuffer != NULL) {
free (mGlobals.SourceFile.FileBuffer);
memset (&mGlobals.SourceFile, 0, sizeof (mGlobals.SourceFile));
return STATUS_SUCCESS;
}
return STATUS_ERROR;
}
static
STATUS
ProcessIncludeFile (
SOURCE_FILE *SourceFile,
SOURCE_FILE *ParentSourceFile
)
/*++
Routine Description:
Given a source file, open the file and parse it
Arguments:
SourceFile - name of file to parse
ParentSourceFile - for error reporting purposes, the file that #included SourceFile.
Returns:
Standard status.
--*/
{
static UINT32 NestDepth = 0;
INT8 FoundFileName[MAX_PATH];
STATUS Status;
Status = STATUS_SUCCESS;
NestDepth++;
//
// Print the file being processed. Indent so you can tell the include nesting
// depth.
//
if (mGlobals.Verbose) {
fprintf (stdout, "%*cProcessing file '%s'\n", NestDepth * 2, ' ', SourceFile->FileName);
}
//
// Make sure we didn't exceed our maximum nesting depth
//
if (NestDepth > MAX_NEST_DEPTH) {
Error (NULL, 0, 0, SourceFile->FileName, "max nesting depth (%d) exceeded", NestDepth);
Status = STATUS_ERROR;
goto Finish;
}
//
// Try to open the file locally, and if that fails try along our include paths.
//
strcpy (FoundFileName, SourceFile->FileName);
if ((SourceFile->Fptr = fopen (FoundFileName, "r")) == NULL) {
//
// Try to find it among the paths if it has a parent (that is, it is included
// by someone else).
//
Error (NULL, 0, 0, SourceFile->FileName, "file not found");
return STATUS_ERROR;
}
//
// Process the file found
//
ProcessFile (SourceFile);
Finish:
//
// Close open files and return status
//
if (SourceFile->Fptr != NULL) {
fclose (SourceFile->Fptr);
SourceFile->Fptr = NULL;
}
return Status;
}
static
STATUS
ProcessFile (
SOURCE_FILE *SourceFile
)
{
//
// Get the file size, and then read the entire thing into memory.
// Allocate space for a terminator character.
//
fseek (SourceFile->Fptr, 0, SEEK_END);
SourceFile->FileSize = ftell (SourceFile->Fptr);
fseek (SourceFile->Fptr, 0, SEEK_SET);
SourceFile->FileBuffer = (T_CHAR *) malloc (SourceFile->FileSize + sizeof (T_CHAR));
if (SourceFile->FileBuffer == NULL) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
return STATUS_ERROR;
}
fread ((VOID *) SourceFile->FileBuffer, SourceFile->FileSize, 1, SourceFile->Fptr);
SourceFile->FileBuffer[(SourceFile->FileSize / sizeof (T_CHAR))] = T_CHAR_NULL;
//
// Pre-process the file to replace comments with spaces
//
PreprocessFile (SourceFile);
SourceFile->LineNum = 1;
return STATUS_SUCCESS;
}
static
void
PreprocessFile (
SOURCE_FILE *SourceFile
)
/*++
Routine Description:
Preprocess a file to replace all carriage returns with NULLs so
we can print lines from the file to the screen.
Arguments:
SourceFile - structure that we use to keep track of an input file.
Returns:
Nothing.
--*/
{
BOOLEAN InComment;
RewindFile (SourceFile);
InComment = FALSE;
while (!EndOfFile (SourceFile)) {
//
// If a line-feed, then no longer in a comment
//
if (SourceFile->FileBufferPtr[0] == T_CHAR_LF) {
SourceFile->FileBufferPtr++;
SourceFile->LineNum++;
InComment = 0;
} else if (SourceFile->FileBufferPtr[0] == T_CHAR_CR) {
//
// Replace all carriage returns with a NULL so we can print stuff
//
SourceFile->FileBufferPtr[0] = 0;
SourceFile->FileBufferPtr++;
} else if (InComment) {
SourceFile->FileBufferPtr[0] = T_CHAR_SPACE;
SourceFile->FileBufferPtr++;
} else if ((SourceFile->FileBufferPtr[0] == T_CHAR_SLASH) && (SourceFile->FileBufferPtr[1] == T_CHAR_SLASH)) {
SourceFile->FileBufferPtr += 2;
InComment = TRUE;
} else {
SourceFile->FileBufferPtr++;
}
}
//
// Could check for end-of-file and still in a comment, but
// should not be necessary. So just restore the file pointers.
//
RewindFile (SourceFile);
}
#if 0
static
T_CHAR *
GetQuotedString (
SOURCE_FILE *SourceFile,
BOOLEAN Optional
)
{
T_CHAR *String;
T_CHAR *Start;
T_CHAR *Ptr;
UINT32 Len;
BOOLEAN PreviousBackslash;
if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {
if (!Optional) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "expected quoted string", "%S", SourceFile->FileBufferPtr);
}
return NULL;
}
Len = 0;
SourceFile->FileBufferPtr++;
Start = Ptr = SourceFile->FileBufferPtr;
PreviousBackslash = FALSE;
while (!EndOfFile (SourceFile)) {
if ((SourceFile->FileBufferPtr[0] == T_CHAR_DOUBLE_QUOTE) && (!PreviousBackslash)) {
break;
} else if (SourceFile->FileBufferPtr[0] == T_CHAR_CR) {
Warning (SourceFile->FileName, SourceFile->LineNum, 0, "carriage return found in quoted string", "%S", Start);
PreviousBackslash = FALSE;
} else if (SourceFile->FileBufferPtr[0] == T_CHAR_BACKSLASH) {
PreviousBackslash = TRUE;
} else {
PreviousBackslash = FALSE;
}
SourceFile->FileBufferPtr++;
Len++;
}
if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {
Warning (SourceFile->FileName, SourceFile->LineNum, 0, "missing closing quote on string", "%S", Start);
} else {
SourceFile->FileBufferPtr++;
}
//
// Now allocate memory for the string and save it off
//
String = (T_CHAR *) malloc ((Len + 1) * sizeof (T_CHAR));
if (String == NULL) {
Error (NULL, 0, 0, "memory allocation failed", NULL);
return NULL;
}
//
// Copy the string from the file buffer to the local copy.
// We do no reformatting of it whatsoever at this point.
//
Ptr = String;
while (Len > 0) {
*Ptr = *Start;
Start++;
Ptr++;
Len--;
}
*Ptr = 0;
return String;
}
#endif
static
BOOLEAN
EndOfFile (
SOURCE_FILE *SourceFile
)
{
//
// The file buffer pointer will typically get updated before the End-of-file flag in the
// source file structure, so check it first.
//
if (SourceFile->FileBufferPtr >= SourceFile->FileBuffer + SourceFile->FileSize / sizeof (T_CHAR)) {
SourceFile->EndOfFile = TRUE;
return TRUE;
}
if (SourceFile->EndOfFile) {
return TRUE;
}
return FALSE;
}
#if 0
static
void
ProcessTokenInclude (
SOURCE_FILE *SourceFile
)
{
INT8 IncludeFileName[MAX_PATH];
INT8 *To;
UINT32 Len;
BOOLEAN ReportedError;
SOURCE_FILE IncludedSourceFile;
ReportedError = FALSE;
if (SkipWhiteSpace (SourceFile) == 0) {
Warning (SourceFile->FileName, SourceFile->LineNum, 0, "expected whitespace following #include keyword", NULL);
}
//
// Should be quoted file name
//
if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "expected quoted include file name", NULL);
goto FailDone;
}
SourceFile->FileBufferPtr++;
//
// Copy the filename as ascii to our local string
//
To = IncludeFileName;
Len = 0;
while (!EndOfFile (SourceFile)) {
if ((SourceFile->FileBufferPtr[0] == T_CHAR_CR) || (SourceFile->FileBufferPtr[0] == T_CHAR_LF)) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "end-of-line found in quoted include file name", NULL);
goto FailDone;
}
if (SourceFile->FileBufferPtr[0] == T_CHAR_DOUBLE_QUOTE) {
SourceFile->FileBufferPtr++;
break;
}
//
// If too long, then report the error once and process until the closing quote
//
Len++;
if (!ReportedError && (Len >= sizeof (IncludeFileName))) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "length of include file name exceeds limit", NULL);
ReportedError = TRUE;
}
if (!ReportedError) {
//
// *To = UNICODE_TO_ASCII(SourceFile->FileBufferPtr[0]);
//
*To = (T_CHAR) SourceFile->FileBufferPtr[0];
To++;
}
SourceFile->FileBufferPtr++;
}
if (!ReportedError) {
*To = 0;
memset ((char *) &IncludedSourceFile, 0, sizeof (SOURCE_FILE));
strcpy (IncludedSourceFile.FileName, IncludeFileName);
//
// IncludedSourceFile.ControlCharacter = DEFAULT_CONTROL_CHARACTER;
//
ProcessIncludeFile (&IncludedSourceFile, SourceFile);
//
// printf ("including file '%s'\n", IncludeFileName);
//
}
return ;
FailDone:
//
// Error recovery -- skip to next #
//
SourceFile->SkipToHash = TRUE;
}
#endif
static
BOOLEAN
IsWhiteSpace (
SOURCE_FILE *SourceFile
)
{
switch (*SourceFile->FileBufferPtr) {
case T_CHAR_NULL:
case T_CHAR_CR:
case T_CHAR_SPACE:
case T_CHAR_TAB:
case T_CHAR_LF:
return TRUE;
default:
return FALSE;
}
}
UINT32
SkipWhiteSpace (
SOURCE_FILE *SourceFile
)
{
UINT32 Count;
Count = 0;
while (!EndOfFile (SourceFile)) {
Count++;
switch (*SourceFile->FileBufferPtr) {
case T_CHAR_NULL:
case T_CHAR_CR:
case T_CHAR_SPACE:
case T_CHAR_TAB:
SourceFile->FileBufferPtr++;
break;
case T_CHAR_LF:
SourceFile->FileBufferPtr++;
SourceFile->LineNum++;
if (mGlobals.Verbose) {
printf ("%d: %S\n", SourceFile->LineNum, SourceFile->FileBufferPtr);
}
break;
default:
return Count - 1;
}
}
//
// Some tokens require trailing whitespace. If we're at the end of the
// file, then we count that as well.
//
if ((Count == 0) && (EndOfFile (SourceFile))) {
Count++;
}
return Count;
}
static
UINT32
t_strcmp (
T_CHAR *Buffer,
T_CHAR *Str
)
{
UINT32 Len;
Len = 0;
while (*Str == *Buffer) {
Buffer++;
Str++;
Len++;
}
if (*Str) {
return 0;
}
return Len;
}
static
UINT32
t_strlen (
T_CHAR *Str
)
{
UINT32 Len;
Len = 0;
while (*Str) {
Len++;
Str++;
}
return Len;
}
static
UINT32
t_strncmp (
T_CHAR *Str1,
T_CHAR *Str2,
UINT32 Len
)
{
while (Len > 0) {
if (*Str1 != *Str2) {
return Len;
}
Len--;
Str1++;
Str2++;
}
return 0;
}
static
T_CHAR *
t_strcpy (
T_CHAR *Dest,
T_CHAR *Src
)
{
T_CHAR *SaveDest;
SaveDest = Dest;
while (*Src) {
*Dest = *Src;
Dest++;
Src++;
}
*Dest = 0;
return SaveDest;
}
#if 0
static
BOOLEAN
IsValidIdentifierChar (
INT8 Char,
BOOLEAN FirstChar
)
{
//
// If it's the first character of an identifier, then
// it must be one of [A-Za-z_].
//
if (FirstChar) {
if (isalpha (Char) || (Char == '_')) {
return TRUE;
}
} else {
//
// If it's not the first character, then it can
// be one of [A-Za-z_0-9]
//
if (isalnum (Char) || (Char == '_')) {
return TRUE;
}
}
return FALSE;
}
#endif
static
void
RewindFile (
SOURCE_FILE *SourceFile
)
{
SourceFile->LineNum = 1;
SourceFile->FileBufferPtr = SourceFile->FileBuffer;
SourceFile->EndOfFile = 0;
}
#if 0
static
BOOLEAN
SkipTo (
SOURCE_FILE *SourceFile,
T_CHAR TChar,
BOOLEAN StopAfterNewline
)
{
while (!EndOfFile (SourceFile)) {
//
// Check for the character of interest
//
if (SourceFile->FileBufferPtr[0] == TChar) {
return TRUE;
} else {
if (SourceFile->FileBufferPtr[0] == T_CHAR_LF) {
SourceFile->LineNum++;
if (StopAfterNewline) {
SourceFile->FileBufferPtr++;
if (SourceFile->FileBufferPtr[0] == 0) {
SourceFile->FileBufferPtr++;
}
return FALSE;
}
}
SourceFile->FileBufferPtr++;
}
}
return FALSE;
}
#endif

View File

@ -0,0 +1,71 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenFfsFile Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenFfsFile"/>
<property name="FileSet" value="GenFfsFile.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,57 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.c
Abstract:
EBC Specific relocation fixups
Revision History
--*/
RETURN_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an IA-32 specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
EFI_UNSUPPORTED - Unsupported now
--*/
{
return RETURN_UNSUPPORTED;
}

View File

@ -0,0 +1,299 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageExe.c
Abstract:
This contains all code necessary to build the GenFvImage.exe utility.
This utility relies heavily on the GenFvImage Lib. Definitions for both
can be found in the Tiano Firmware Volume Generation Utility
Specification, review draft.
--*/
//
// File included in build
//
#include "GenFvImageExe.h"
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
VOID
PrintUtilityInfo (
VOID
)
/*++
Routine Description:
Displays the standard utility information to SDTOUT
Arguments:
None
Returns:
None
--*/
{
printf (
"%s - Tiano Firmware Volume Generation Utility."" Version %i.%i\n\n",
UTILITY_NAME,
UTILITY_MAJOR_VERSION,
UTILITY_MINOR_VERSION
);
}
VOID
PrintUsage (
VOID
)
/*++
Routine Description:
Displays the utility usage syntax to STDOUT
Arguments:
None
Returns:
None
--*/
{
printf ("Usage: %s -I FvInfFileName\n", UTILITY_NAME);
printf (" Where:\n");
printf ("\tFvInfFileName is the name of the image description file.\n\n");
}
int
main (
IN INTN argc,
IN CHAR8 **argv
)
/*++
Routine Description:
This utility uses GenFvImage.Lib to build a firmware volume image.
Arguments:
FvInfFileName The name of an FV image description file.
Arguments come in pair in any order.
-I FvInfFileName
Returns:
EFI_SUCCESS No error conditions detected.
EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
Most commonly this will be memory allocation
or file creation.
EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
EFI_ABORTED Error executing the GenFvImage lib.
--*/
{
EFI_STATUS Status;
CHAR8 InfFileName[_MAX_PATH];
CHAR8 *InfFileImage;
UINTN InfFileSize;
UINT8 *FvImage;
UINTN FvImageSize;
UINT8 Index;
CHAR8 FvFileNameBuffer[_MAX_PATH];
CHAR8 *FvFileName;
FILE *FvFile;
FILE *SymFile;
CHAR8 SymFileNameBuffer[_MAX_PATH];
CHAR8 *SymFileName;
UINT8 *SymImage;
UINTN SymImageSize;
CHAR8 *CurrentSymString;
FvFileName = FvFileNameBuffer;
SymFileName = SymFileNameBuffer;
SetUtilityName (UTILITY_NAME);
//
// Display utility information
//
PrintUtilityInfo ();
//
// Verify the correct number of arguments
//
if (argc != MAX_ARGS) {
Error (NULL, 0, 0, "invalid number of input parameters specified", NULL);
PrintUsage ();
return GetUtilityStatus ();
}
//
// Initialize variables
//
strcpy (InfFileName, "");
//
// Parse the command line arguments
//
for (Index = 1; Index < MAX_ARGS; Index += 2) {
//
// Make sure argument pair begin with - or /
//
if (argv[Index][0] != '-' && argv[Index][0] != '/') {
Error (NULL, 0, 0, argv[Index], "argument pair must begin with \"-\" or \"/\"");
PrintUsage ();
return GetUtilityStatus ();
}
//
// Make sure argument specifier is only one letter
//
if (argv[Index][2] != 0) {
Error (NULL, 0, 0, argv[Index], "unrecognized argument");
PrintUsage ();
return GetUtilityStatus ();
}
//
// Determine argument to read
//
switch (argv[Index][1]) {
case 'I':
case 'i':
if (strlen (InfFileName) == 0) {
strcpy (InfFileName, argv[Index + 1]);
} else {
Error (NULL, 0, 0, argv[Index + 1], "FvInfFileName may only be specified once");
PrintUsage ();
return GetUtilityStatus ();
}
break;
default:
Error (NULL, 0, 0, argv[Index], "unrecognized argument");
PrintUsage ();
return GetUtilityStatus ();
break;
}
}
//
// Read the INF file image
//
Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);
if (EFI_ERROR (Status)) {
return STATUS_ERROR;
}
//
// Call the GenFvImage lib
//
Status = GenerateFvImage (
InfFileImage,
InfFileSize,
&FvImage,
&FvImageSize,
&FvFileName,
&SymImage,
&SymImageSize,
&SymFileName
);
if (EFI_ERROR (Status)) {
switch (Status) {
case EFI_INVALID_PARAMETER:
Error (NULL, 0, 0, "invalid parameter passed to GenFvImage Lib", NULL);
return GetUtilityStatus ();
break;
case EFI_ABORTED:
Error (NULL, 0, 0, "error detected while creating the file image", NULL);
return GetUtilityStatus ();
break;
case EFI_OUT_OF_RESOURCES:
Error (NULL, 0, 0, "GenFvImage Lib could not allocate required resources", NULL);
return GetUtilityStatus ();
break;
case EFI_VOLUME_CORRUPTED:
Error (NULL, 0, 0, "no base address was specified, but the FV.INF included a PEI or BSF file", NULL);
return GetUtilityStatus ();
break;
case EFI_LOAD_ERROR:
Error (NULL, 0, 0, "could not load FV image generation library", NULL);
return GetUtilityStatus ();
break;
default:
Error (NULL, 0, 0, "GenFvImage Lib returned unknown status", "status returned = 0x%X", Status);
return GetUtilityStatus ();
break;
}
}
//
// Write file
//
FvFile = fopen (FvFileName, "wb");
if (FvFile == NULL) {
Error (NULL, 0, 0, FvFileName, "could not open output file");
free (FvImage);
free (SymImage);
return GetUtilityStatus ();
}
if (fwrite (FvImage, 1, FvImageSize, FvFile) != FvImageSize) {
Error (NULL, 0, 0, FvFileName, "failed to write to output file");
free (FvImage);
free (SymImage);
fclose (FvFile);
return GetUtilityStatus ();
}
fclose (FvFile);
free (FvImage);
//
// Write symbol file
//
if (strcmp (SymFileName, "")) {
SymFile = fopen (SymFileName, "wt");
if (SymFile == NULL) {
Error (NULL, 0, 0, SymFileName, "could not open output symbol file");
free (SymImage);
return GetUtilityStatus ();
}
fprintf (SymFile, "TEXTSYM format | V1.0\n");
CurrentSymString = SymImage;
while (((UINTN) CurrentSymString - (UINTN) SymImage) < SymImageSize) {
fprintf (SymFile, "%s", CurrentSymString);
CurrentSymString = (CHAR8 *) (((UINTN) CurrentSymString) + strlen (CurrentSymString) + 1);
}
fclose (SymFile);
}
free (SymImage);
return GetUtilityStatus ();
}

View File

@ -0,0 +1,98 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageExe.h
Abstract:
Definitions for the PeimFixup exe utility.
--*/
//
// Coded to Tiano Coding Standards
//
#ifndef _EFI_GEN_FV_IMAGE_EXE_H
#define _EFI_GEN_FV_IMAGE_EXE_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "GenFvImageLib.h"
//
// Utility Name
//
#define UTILITY_NAME "GenFvImage"
//
// Utility version information
//
#define UTILITY_MAJOR_VERSION 0
#define UTILITY_MINOR_VERSION 1
#define UTILITY_DATE __DATE__
//
// The maximum number of arguments accepted from the command line.
//
#define MAX_ARGS 3
//
// The function that displays general utility information
//
VOID
PrintUtilityInfo (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
//
// The function that displays the utility usage message.
//
VOID
PrintUsage (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,142 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageLib.h
Abstract:
This file contains describes the public interfaces to the GenFvImage Library.
The basic purpose of the library is to create Firmware Volume images.
--*/
#ifndef _EFI_GEN_FV_IMAGE_LIB_H
#define _EFI_GEN_FV_IMAGE_LIB_H
//
// Include files
//
#include <Common/UefiBaseTypes.h>
#include <Common/MultiPhase.h>
#include "ParseInf.h"
//
// Following definition is used for FIT in IPF
//
#define COMP_TYPE_FIT_PEICORE 0x10
#define COMP_TYPE_FIT_UNUSED 0x7F
#define FIT_TYPE_MASK 0x7F
#define CHECKSUM_BIT_MASK 0x80
#pragma pack(1)
typedef struct {
UINT64 CompAddress;
UINT32 CompSize;
UINT16 CompVersion;
UINT8 CvAndType;
UINT8 CheckSum;
} FIT_TABLE;
#pragma pack()
//
// Exported function prototypes
//
EFI_STATUS
GenerateFvImage (
IN CHAR8 *InfFileImage,
IN UINTN InfFileSize,
OUT UINT8 **FvImage,
OUT UINTN *FvImageSize,
OUT CHAR8 **FvFileName,
OUT UINT8 **SymImage,
OUT UINTN *SymImageSize,
OUT CHAR8 **SymFileName
)
;
/*++
Routine Description:
This is the main function which will be called from application.
Arguments:
InfFileImage Buffer containing the INF file contents.
InfFileSize Size of the contents of the InfFileImage buffer.
FvImage Pointer to the FV image created.
FvImageSize Size of the FV image created and pointed to by FvImage.
FvFileName Requested name for the FV file.
SymImage Pointer to the Sym image created.
SymImageSize Size of the Sym image created and pointed to by SymImage.
SymFileName Requested name for the Sym file.
Returns:
EFI_SUCCESS Function completed successfully.
EFI_OUT_OF_RESOURCES Could not allocate required resources.
EFI_ABORTED Error encountered.
EFI_INVALID_PARAMETER A required parameter was NULL.
--*/
EFI_STATUS
UpdatePeiCoreEntryInFit (
IN FIT_TABLE *FitTablePtr,
IN UINT64 PeiCorePhysicalAddress
)
;
/*++
Routine Description:
This function is used to update the Pei Core address in FIT, this can be used by Sec core to pass control from
Sec to Pei Core
Arguments:
FitTablePtr - The pointer of FIT_TABLE.
PeiCorePhysicalAddress - The address of Pei Core entry.
Returns:
EFI_SUCCESS - The PEI_CORE FIT entry was updated successfully.
EFI_NOT_FOUND - Not found the PEI_CORE FIT entry.
--*/
VOID
UpdateFitCheckSum (
IN FIT_TABLE *FitTablePtr
)
;
/*++
Routine Description:
This function is used to update the checksum for FIT.
Arguments:
FitTablePtr - The pointer of FIT_TABLE.
Returns:
None.
--*/
#endif

View File

@ -0,0 +1,172 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageLibInternal.h
Abstract:
This file contains describes the private declarations for the GenFvImage Library.
The basic purpose of the library is to create Firmware Volume images.
--*/
#ifndef _EFI_GEN_FV_IMAGE_LIB_INTERNAL_H
#define _EFI_GEN_FV_IMAGE_LIB_INTERNAL_H
//
// Include files
//
#include <stdlib.h>
#include <Common/FirmwareVolumeHeader.h>
#include "CommonLib.h"
#include "GenFvImageLib.h"
//
// Private data declarations
//
//
// The maximum number of block map entries supported by the library
//
#define MAX_NUMBER_OF_FV_BLOCKS 100
//
// The maximum number of files in the FV supported by the library
//
#define MAX_NUMBER_OF_FILES_IN_FV 1000
#define MAX_NUMBER_OF_COMPONENTS_IN_FV 10
//
// INF file strings
//
#define OPTIONS_SECTION_STRING "[options]"
#define ATTRIBUTES_SECTION_STRING "[attributes]"
#define FILES_SECTION_STRING "[files]"
#define COMPONENT_SECTION_STRING "[components]"
#define EFI_FV_BASE_ADDRESS_STRING "EFI_BASE_ADDRESS"
#define EFI_FV_FILE_NAME_STRING "EFI_FILE_NAME"
#define EFI_SYM_FILE_NAME_STRING "EFI_SYM_FILE_NAME"
#define EFI_NUM_BLOCKS_STRING "EFI_NUM_BLOCKS"
#define EFI_BLOCK_SIZE_STRING "EFI_BLOCK_SIZE"
#define EFI_FV_GUID_STRING "EFI_FV_GUID"
#define EFI_FVB_READ_DISABLED_CAP_STRING "EFI_READ_DISABLED_CAP"
#define EFI_FVB_READ_ENABLED_CAP_STRING "EFI_READ_ENABLED_CAP"
#define EFI_FVB_READ_STATUS_STRING "EFI_READ_STATUS"
#define EFI_FVB_WRITE_DISABLED_CAP_STRING "EFI_WRITE_DISABLED_CAP"
#define EFI_FVB_WRITE_ENABLED_CAP_STRING "EFI_WRITE_ENABLED_CAP"
#define EFI_FVB_WRITE_STATUS_STRING "EFI_WRITE_STATUS"
#define EFI_FVB_LOCK_CAP_STRING "EFI_LOCK_CAP"
#define EFI_FVB_LOCK_STATUS_STRING "EFI_LOCK_STATUS"
#define EFI_FVB_STICKY_WRITE_STRING "EFI_STICKY_WRITE"
#define EFI_FVB_MEMORY_MAPPED_STRING "EFI_MEMORY_MAPPED"
#define EFI_FVB_ERASE_POLARITY_STRING "EFI_ERASE_POLARITY"
#define EFI_FVB_ALIGNMENT_CAP_STRING "EFI_ALIGNMENT_CAP"
#define EFI_FVB_ALIGNMENT_2_STRING "EFI_ALIGNMENT_2"
#define EFI_FVB_ALIGNMENT_4_STRING "EFI_ALIGNMENT_4"
#define EFI_FVB_ALIGNMENT_8_STRING "EFI_ALIGNMENT_8"
#define EFI_FVB_ALIGNMENT_16_STRING "EFI_ALIGNMENT_16"
#define EFI_FVB_ALIGNMENT_32_STRING "EFI_ALIGNMENT_32"
#define EFI_FVB_ALIGNMENT_64_STRING "EFI_ALIGNMENT_64"
#define EFI_FVB_ALIGNMENT_128_STRING "EFI_ALIGNMENT_128"
#define EFI_FVB_ALIGNMENT_256_STRING "EFI_ALIGNMENT_256"
#define EFI_FVB_ALIGNMENT_512_STRING "EFI_ALIGNMENT_512"
#define EFI_FVB_ALIGNMENT_1K_STRING "EFI_ALIGNMENT_1K"
#define EFI_FVB_ALIGNMENT_2K_STRING "EFI_ALIGNMENT_2K"
#define EFI_FVB_ALIGNMENT_4K_STRING "EFI_ALIGNMENT_4K"
#define EFI_FVB_ALIGNMENT_8K_STRING "EFI_ALIGNMENT_8K"
#define EFI_FVB_ALIGNMENT_16K_STRING "EFI_ALIGNMENT_16K"
#define EFI_FVB_ALIGNMENT_32K_STRING "EFI_ALIGNMENT_32K"
#define EFI_FVB_ALIGNMENT_64K_STRING "EFI_ALIGNMENT_64K"
//
// Component sections
//
#define EFI_NV_VARIABLE_STRING "EFI_NV_VARIABLE"
#define EFI_NV_EVENT_LOG_STRING "EFI_NV_EVENT_LOG"
#define EFI_NV_FTW_WORKING_STRING "EFI_NV_FTW_WORKING"
#define EFI_NV_FTW_SPARE_STRING "EFI_NV_FTW_SPARE"
#define EFI_FILE_NAME_STRING "EFI_FILE_NAME"
#define ONE_STRING "1"
#define ZERO_STRING "0"
#define TRUE_STRING "TRUE"
#define FALSE_STRING "FALSE"
#define NULL_STRING "NULL"
//
// Defines to calculate the offset for PEI CORE entry points
//
#define IA32_PEI_CORE_ENTRY_OFFSET 0x20
//
// Defines to calculate the FIT table
//
#define IPF_FIT_ADDRESS_OFFSET 0x20
//
// Defines to calculate the offset for SALE_ENTRY
//
#define IPF_SALE_ENTRY_ADDRESS_OFFSET 0x18
//
// Symbol file definitions, current max size if 512K
//
#define SYMBOL_FILE_SIZE 0x80000
#define FV_IMAGES_TOP_ADDRESS 0x100000000ULL
//
// Private data types
//
//
// Component information
//
typedef struct {
UINTN Size;
CHAR8 ComponentName[_MAX_PATH];
} COMPONENT_INFO;
//
// FV information holder
//
typedef struct {
EFI_PHYSICAL_ADDRESS BaseAddress;
EFI_GUID FvGuid;
UINTN Size;
CHAR8 FvName[_MAX_PATH];
CHAR8 SymName[_MAX_PATH];
EFI_FV_BLOCK_MAP_ENTRY FvBlocks[MAX_NUMBER_OF_FV_BLOCKS];
EFI_FVB_ATTRIBUTES FvAttributes;
CHAR8 FvFiles[MAX_NUMBER_OF_FILES_IN_FV][_MAX_PATH];
COMPONENT_INFO FvComponents[MAX_NUMBER_OF_COMPONENTS_IN_FV];
} FV_INFO;
//
// Private function prototypes
//
EFI_STATUS
ParseFvInf (
IN MEMORY_FILE *InfFile,
IN FV_INFO *FvInfo
)
;
#endif

View File

@ -0,0 +1,124 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenFvImage Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenFvImage"/>
<property name="FileSet" value="GenFvImageLib.c GenFvImageExe.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<istrue value="${OSX}"/>
<then>
<property name="syslibdirs" value=""/>
<property name="syslibs" value=""/>
</then>
</if>
<if>
<istrue value="${cygwin}"/>
<then>
<property name="syslibdirs" value="${env.CYGWIN_HOME}/lib/e2fsprogs"/>
<property name="syslibs" value="uuid"/>
</then>
</if>
<if>
<istrue value="${msft}"/>
<then>
<property name="syslibdirs" value=""/>
<property name="syslibs" value="uuid"/>
</then>
</if>
<if>
<istrue value="${linux}"/>
<then>
<if>
<istrue value="${x86_64_linux}"/>
<then>
<property name="syslibdirs" value="/lib64"/>
</then>
<else>
<property name="syslibdirs" value="/usr/lib"/>
</else>
</if>
<property name="syslibs" value="uuid"/>
</then>
</if>
<echo message="syslibdirs set to: ${syslibdirs}"/>
</target>
<target name="Tool" depends="init, GenFvImage"/>
<target name="GenFvImage" >
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<defineset>
<define name="BUILDING_TOOLS"/>
<define name="TOOL_BUILD_IA32_TARGET"/>
</defineset>
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"/>
<includepath path="${PACKAGE_DIR}/${ToolName}"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
<linkerarg value="/nodefaultlib:libc.lib" if="msft"/>
<syslibset dir="${syslibdirs}" libs="${syslibs}" if="cyglinux"/>
<syslibset libs="RpcRT4" if="msft"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}_Ia32${ext_exe}"/>
<fileset file="${BIN_DIR}/${ToolName}_X64${ext_exe}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
<fileset file="${BIN_DIR}/${ToolName}_Ipf${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,938 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenSection.c
Abstract:
Creates output file that is a properly formed section per the FV spec.
--*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Common/UefiBaseTypes.h>
#include <Common/FirmwareVolumeImageFormat.h>
#include <Protocol/GuidedSectionExtraction.h>
#include "CommonLib.h"
#include "EfiCompress.h"
#include "EfiCustomizedCompress.h"
#include "Crc32.h"
#include "EfiUtilityMsgs.h"
#include "GenSection.h"
#define UTILITY_NAME "GenSection"
#define PARAMETER_NOT_SPECIFIED "Parameter not specified"
#define MAXIMUM_INPUT_FILE_NUM 10
char *SectionTypeName[] = {
NULL, // 0x00 - reserved
"EFI_SECTION_COMPRESSION", // 0x01
"EFI_SECTION_GUID_DEFINED", // 0x02
NULL, // 0x03 - reserved
NULL, // 0x04 - reserved
NULL, // 0x05 - reserved
NULL, // 0x06 - reserved
NULL, // 0x07 - reserved
NULL, // 0x08 - reserved
NULL, // 0x09 - reserved
NULL, // 0x0A - reserved
NULL, // 0x0B - reserved
NULL, // 0x0C - reserved
NULL, // 0x0D - reserved
NULL, // 0x0E - reserved
NULL, // 0x0F - reserved
"EFI_SECTION_PE32", // 0x10
"EFI_SECTION_PIC", // 0x11
"EFI_SECTION_TE", // 0x12
"EFI_SECTION_DXE_DEPEX", // 0x13
"EFI_SECTION_VERSION", // 0x14
"EFI_SECTION_USER_INTERFACE", // 0x15
"EFI_SECTION_COMPATIBILITY16", // 0x16
"EFI_SECTION_FIRMWARE_VOLUME_IMAGE", // 0x17
"EFI_SECTION_FREEFORM_SUBTYPE_GUID", // 0x18
"EFI_SECTION_RAW", // 0x19
NULL, // 0x1A
"EFI_SECTION_PEI_DEPEX" // 0x1B
};
char *CompressionTypeName[] = { "NONE", "STANDARD" };
char *GUIDedSectionTypeName[] = { "CRC32" };
EFI_GUID gEfiCrc32SectionGuid = EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID;
static
VOID
PrintUsageMessage (
VOID
)
{
UINTN SectionType;
UINTN DisplayCount;
printf ("Usage: "UTILITY_NAME " -i InputFile -o OutputFile -s SectionType [SectionType params]\n\n");
printf (" Where SectionType is one of the following section types:\n\n");
DisplayCount = 0;
for (SectionType = 0; SectionType <= EFI_SECTION_LAST_SECTION_TYPE; SectionType++) {
if (SectionTypeName[SectionType] != NULL) {
printf (" %s\n", SectionTypeName[SectionType]);
}
}
printf ("\n and SectionType dependent parameters are as follows:\n\n");
printf (
" %s: -t < %s | %s >\n",
SectionTypeName[EFI_SECTION_COMPRESSION],
CompressionTypeName[EFI_NOT_COMPRESSED],
CompressionTypeName[EFI_STANDARD_COMPRESSION]
);
printf (
" %s: -t < %s >\n"" // Currently only CRC32 is supported\n\n",
SectionTypeName[EFI_SECTION_GUID_DEFINED],
GUIDedSectionTypeName[EFI_SECTION_CRC32_GUID_DEFINED]
);
printf (
" %s: -v VersionNumber\n"" [-a \"Version string\"]\n\n",
SectionTypeName[EFI_SECTION_VERSION]
);
printf (
" %s: -a \"Human readable name\"\n\n",
SectionTypeName[EFI_SECTION_USER_INTERFACE]
);
}
VOID
Ascii2UnicodeWriteString (
char *String,
FILE *OutFile,
BOOLEAN WriteLangCode
)
{
UINTN Index;
UINT8 AsciiNull;
//
// BUGBUG need to get correct language code...
//
char *EnglishLangCode = "eng";
AsciiNull = 0;
//
// first write the language code (english only)
//
if (WriteLangCode) {
fwrite (EnglishLangCode, 1, 4, OutFile);
}
//
// Next, write out the string... Convert ASCII to Unicode in the process.
//
Index = 0;
do {
fwrite (&String[Index], 1, 1, OutFile);
fwrite (&AsciiNull, 1, 1, OutFile);
} while (String[Index++] != 0);
}
STATUS
GenSectionCommonLeafSection (
char **InputFileName,
int InputFileNum,
UINTN SectionType,
FILE *OutFile
)
/*++
Routine Description:
Generate a leaf section of type other than EFI_SECTION_VERSION
and EFI_SECTION_USER_INTERFACE. Input file must be well formed.
The function won't validate the input file's contents. For
common leaf sections, the input file may be a binary file.
The utility will add section header to the file.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be 1 for leaf section.
SectionType - A valid section type string
OutFile - Output file handle
Returns:
STATUS_ERROR - can't continue
STATUS_SUCCESS - successful return
--*/
{
UINT64 InputFileLength;
FILE *InFile;
UINT8 *Buffer;
INTN TotalLength;
EFI_COMMON_SECTION_HEADER CommonSect;
STATUS Status;
if (InputFileNum > 1) {
Error (NULL, 0, 0, "invalid parameter", "more than one input file specified");
return STATUS_ERROR;
} else if (InputFileNum < 1) {
Error (NULL, 0, 0, "no input file specified", NULL);
return STATUS_ERROR;
}
//
// Open the input file
//
InFile = fopen (InputFileName[0], "rb");
if (InFile == NULL) {
Error (NULL, 0, 0, InputFileName[0], "failed to open input file");
return STATUS_ERROR;
}
Status = STATUS_ERROR;
Buffer = NULL;
//
// Seek to the end of the input file so we can determine its size
//
fseek (InFile, 0, SEEK_END);
fgetpos (InFile, &InputFileLength);
fseek (InFile, 0, SEEK_SET);
//
// Fill in the fields in the local section header structure
//
CommonSect.Type = (EFI_SECTION_TYPE) SectionType;
TotalLength = sizeof (CommonSect) + (INTN) InputFileLength;
//
// Size must fit in 3 bytes
//
if (TotalLength >= 0x1000000) {
Error (NULL, 0, 0, InputFileName[0], "file size (0x%X) exceeds section size limit", TotalLength);
goto Done;
}
//
// Now copy the size into the section header and write out the section header
//
memcpy (&CommonSect.Size, &TotalLength, 3);
fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);
//
// Allocate a buffer to read in the contents of the input file. Then
// read it in as one block and write it to the output file.
//
if (InputFileLength != 0) {
Buffer = (UINT8 *) malloc ((size_t) InputFileLength);
if (Buffer == NULL) {
Error (__FILE__, __LINE__, 0, "memory allocation failure", NULL);
goto Done;
}
if (fread (Buffer, (size_t) InputFileLength, 1, InFile) != 1) {
Error (NULL, 0, 0, InputFileName[0], "failed to read contents of file");
goto Done;
}
if (fwrite (Buffer, (size_t) InputFileLength, 1, OutFile) != 1) {
Error (NULL, 0, 0, "failed to write to output file", NULL);
goto Done;
}
}
Status = STATUS_SUCCESS;
Done:
fclose (InFile);
if (Buffer != NULL) {
free (Buffer);
}
return Status;
}
EFI_STATUS
GetSectionContents (
char **InputFileName,
int InputFileNum,
UINT8 *FileBuffer,
UINTN *BufferLength
)
/*++
Routine Description:
Get the contents of all section files specified in InputFileName
into FileBuffer.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be at least 1.
FileBuffer - Output buffer to contain data
BufferLength - Actual length of the data
Returns:
EFI_SUCCESS on successful return
EFI_INVALID_PARAMETER if InputFileNum is less than 1
EFI_ABORTED if unable to open input file.
--*/
{
UINTN Size;
UINTN FileSize;
INTN Index;
FILE *InFile;
if (InputFileNum < 1) {
Error (NULL, 0, 0, "must specify at least one input file", NULL);
return EFI_INVALID_PARAMETER;
}
Size = 0;
//
// Go through our array of file names and copy their contents
// to the output buffer.
//
for (Index = 0; Index < InputFileNum; Index++) {
InFile = fopen (InputFileName[Index], "rb");
if (InFile == NULL) {
Error (NULL, 0, 0, InputFileName[Index], "failed to open input file");
return EFI_ABORTED;
}
fseek (InFile, 0, SEEK_END);
FileSize = ftell (InFile);
fseek (InFile, 0, SEEK_SET);
//
// Now read the contents of the file into the buffer
//
if (FileSize > 0) {
if (fread (FileBuffer + Size, (size_t) FileSize, 1, InFile) != 1) {
Error (NULL, 0, 0, InputFileName[Index], "failed to read contents of input file");
fclose (InFile);
return EFI_ABORTED;
}
}
fclose (InFile);
Size += (UINTN) FileSize;
//
// make sure section ends on a DWORD boundary
//
while ((Size & 0x03) != 0) {
FileBuffer[Size] = 0;
Size++;
}
}
*BufferLength = Size;
return EFI_SUCCESS;
}
EFI_STATUS
GenSectionCompressionSection (
char **InputFileName,
int InputFileNum,
UINTN SectionType,
UINTN SectionSubType,
FILE *OutFile
)
/*++
Routine Description:
Generate an encapsulating section of type EFI_SECTION_COMPRESSION
Input file must be already sectioned. The function won't validate
the input files' contents. Caller should hand in files already
with section header.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be at least 1.
SectionType - Section type to generate. Should be
EFI_SECTION_COMPRESSION
SectionSubType - Specify the compression algorithm requested.
OutFile - Output file handle
Returns:
EFI_SUCCESS on successful return
EFI_INVALID_PARAMETER if InputFileNum is less than 1
EFI_ABORTED if unable to open input file.
EFI_OUT_OF_RESOURCES No resource to complete the operation.
--*/
{
UINTN TotalLength;
UINTN InputLength;
UINTN CompressedLength;
UINT8 *FileBuffer;
UINT8 *OutputBuffer;
EFI_STATUS Status;
EFI_COMPRESSION_SECTION CompressionSect;
COMPRESS_FUNCTION CompressFunction;
if (SectionType != EFI_SECTION_COMPRESSION) {
Error (NULL, 0, 0, "parameter must be EFI_SECTION_COMPRESSION", NULL);
return EFI_INVALID_PARAMETER;
}
InputLength = 0;
FileBuffer = NULL;
OutputBuffer = NULL;
CompressedLength = 0;
FileBuffer = (UINT8 *) malloc ((1024 * 1024 * 4) * sizeof (UINT8));
if (FileBuffer == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
//
// read all input file contents into a buffer
//
Status = GetSectionContents (
InputFileName,
InputFileNum,
FileBuffer,
&InputLength
);
if (EFI_ERROR (Status)) {
free (FileBuffer);
return Status;
}
CompressFunction = NULL;
//
// Now data is in FileBuffer, compress the data
//
switch (SectionSubType) {
case EFI_NOT_COMPRESSED:
CompressedLength = InputLength;
break;
case EFI_STANDARD_COMPRESSION:
CompressFunction = (COMPRESS_FUNCTION) Compress;
break;
case EFI_CUSTOMIZED_COMPRESSION:
CompressFunction = (COMPRESS_FUNCTION) CustomizedCompress;
break;
default:
Error (NULL, 0, 0, "unknown compression type", NULL);
free (FileBuffer);
return EFI_ABORTED;
}
if (CompressFunction != NULL) {
Status = CompressFunction (FileBuffer, InputLength, OutputBuffer, &CompressedLength);
if (Status == EFI_BUFFER_TOO_SMALL) {
OutputBuffer = malloc (CompressedLength);
if (!OutputBuffer) {
free (FileBuffer);
return EFI_OUT_OF_RESOURCES;
}
Status = CompressFunction (FileBuffer, InputLength, OutputBuffer, &CompressedLength);
}
free (FileBuffer);
FileBuffer = OutputBuffer;
if (EFI_ERROR (Status)) {
if (FileBuffer != NULL) {
free (FileBuffer);
}
return Status;
}
}
TotalLength = CompressedLength + sizeof (EFI_COMPRESSION_SECTION);
//
// Add the section header for the compressed data
//
CompressionSect.CommonHeader.Type = (EFI_SECTION_TYPE) SectionType;
CompressionSect.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);
CompressionSect.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);
CompressionSect.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);
CompressionSect.CompressionType = (UINT8) SectionSubType;
CompressionSect.UncompressedLength = InputLength;
fwrite (&CompressionSect, sizeof (CompressionSect), 1, OutFile);
fwrite (FileBuffer, CompressedLength, 1, OutFile);
free (FileBuffer);
return EFI_SUCCESS;
}
EFI_STATUS
GenSectionGuidDefinedSection (
char **InputFileName,
int InputFileNum,
UINTN SectionType,
UINTN SectionSubType,
FILE *OutFile
)
/*++
Routine Description:
Generate an encapsulating section of type EFI_SECTION_GUID_DEFINED
Input file must be already sectioned. The function won't validate
the input files' contents. Caller should hand in files already
with section header.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be at least 1.
SectionType - Section type to generate. Should be
EFI_SECTION_GUID_DEFINED
SectionSubType - Specify the authentication algorithm requested.
OutFile - Output file handle
Returns:
EFI_SUCCESS on successful return
EFI_INVALID_PARAMETER if InputFileNum is less than 1
EFI_ABORTED if unable to open input file.
EFI_OUT_OF_RESOURCES No resource to complete the operation.
--*/
{
INTN TotalLength;
INTN InputLength;
UINT8 *FileBuffer;
UINT32 Crc32Checksum;
EFI_STATUS Status;
CRC32_SECTION_HEADER Crc32GuidSect;
if (SectionType != EFI_SECTION_GUID_DEFINED) {
Error (NULL, 0, 0, "parameter must be EFI_SECTION_GUID_DEFINED", NULL);
return EFI_INVALID_PARAMETER;
}
InputLength = 0;
FileBuffer = NULL;
FileBuffer = (UINT8 *) malloc ((1024 * 1024 * 4) * sizeof (UINT8));
if (FileBuffer == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
//
// read all input file contents into a buffer
//
Status = GetSectionContents (
InputFileName,
InputFileNum,
FileBuffer,
&InputLength
);
if (EFI_ERROR (Status)) {
free (FileBuffer);
return Status;
}
//
// Now data is in FileBuffer, compress the data
//
switch (SectionSubType) {
case EFI_SECTION_CRC32_GUID_DEFINED:
Crc32Checksum = 0;
CalculateCrc32 (FileBuffer, InputLength, &Crc32Checksum);
if (EFI_ERROR (Status)) {
free (FileBuffer);
return Status;
}
TotalLength = InputLength + CRC32_SECTION_HEADER_SIZE;
Crc32GuidSect.GuidSectionHeader.CommonHeader.Type = (EFI_SECTION_TYPE) SectionType;
Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);
Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);
Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);
memcpy (&(Crc32GuidSect.GuidSectionHeader.SectionDefinitionGuid), &gEfiCrc32SectionGuid, sizeof (EFI_GUID));
Crc32GuidSect.GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID;
Crc32GuidSect.GuidSectionHeader.DataOffset = CRC32_SECTION_HEADER_SIZE;
Crc32GuidSect.CRC32Checksum = Crc32Checksum;
break;
default:
Error (NULL, 0, 0, "invalid parameter", "unknown GUID defined type");
free (FileBuffer);
return EFI_ABORTED;
}
fwrite (&Crc32GuidSect, sizeof (Crc32GuidSect), 1, OutFile);
fwrite (FileBuffer, InputLength, 1, OutFile);
free (FileBuffer);
return EFI_SUCCESS;
}
int
main (
int argc,
char *argv[]
)
/*++
Routine Description:
Main
Arguments:
command line parameters
Returns:
EFI_SUCCESS Section header successfully generated and section concatenated.
EFI_ABORTED Could not generate the section
EFI_OUT_OF_RESOURCES No resource to complete the operation.
--*/
{
INTN Index;
INTN VersionNumber;
UINTN SectionType;
UINTN SectionSubType;
BOOLEAN InputFileRequired;
BOOLEAN SubTypeRequired;
FILE *InFile;
FILE *OutFile;
INTN InputFileNum;
char **InputFileName;
char *OutputFileName;
char AuxString[500] = { 0 };
char *ParamSectionType;
char *ParamSectionSubType;
char *ParamLength;
char *ParamVersion;
char *ParamDigitalSignature;
EFI_STATUS Status;
EFI_COMMON_SECTION_HEADER CommonSect;
InputFileName = NULL;
OutputFileName = PARAMETER_NOT_SPECIFIED;
ParamSectionType = PARAMETER_NOT_SPECIFIED;
ParamSectionSubType = PARAMETER_NOT_SPECIFIED;
ParamLength = PARAMETER_NOT_SPECIFIED;
ParamVersion = PARAMETER_NOT_SPECIFIED;
ParamDigitalSignature = PARAMETER_NOT_SPECIFIED;
Status = EFI_SUCCESS;
VersionNumber = 0;
SectionType = 0;
SectionSubType = 0;
InputFileRequired = TRUE;
SubTypeRequired = FALSE;
InFile = NULL;
OutFile = NULL;
InputFileNum = 0;
Status = EFI_SUCCESS;
SetUtilityName (UTILITY_NAME);
if (argc == 1) {
PrintUsageMessage ();
return STATUS_ERROR;
}
//
// Parse command line
//
Index = 1;
while (Index < argc) {
if (strcmpi (argv[Index], "-i") == 0) {
//
// Input File found
//
Index++;
InputFileName = (char **) malloc (MAXIMUM_INPUT_FILE_NUM * sizeof (char *));
if (InputFileName == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
memset (InputFileName, 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (char *)));
InputFileName[InputFileNum] = argv[Index];
InputFileNum++;
Index++;
//
// Parse subsequent parameters until another switch is encountered
//
while ((Index < argc) && (argv[Index][0] != '-')) {
if ((InputFileNum % MAXIMUM_INPUT_FILE_NUM) == 0) {
//
// InputFileName buffer too small, need to realloc
//
InputFileName = (char **) realloc (
InputFileName,
(InputFileNum + MAXIMUM_INPUT_FILE_NUM) * sizeof (char *)
);
if (InputFileName == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
memset (&(InputFileName[InputFileNum]), 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (char *)));
}
InputFileName[InputFileNum] = argv[Index];
InputFileNum++;
Index++;
}
}
if (strcmpi (argv[Index], "-o") == 0) {
//
// Output file found
//
Index++;
OutputFileName = argv[Index];
} else if (strcmpi (argv[Index], "-s") == 0) {
//
// Section Type found
//
Index++;
ParamSectionType = argv[Index];
} else if (strcmpi (argv[Index], "-t") == 0) {
//
// Compression or Authentication type
//
Index++;
ParamSectionSubType = argv[Index];
} else if (strcmpi (argv[Index], "-l") == 0) {
//
// Length
//
Index++;
ParamLength = argv[Index];
} else if (strcmpi (argv[Index], "-v") == 0) {
//
// VersionNumber
//
Index++;
ParamVersion = argv[Index];
} else if (strcmpi (argv[Index], "-a") == 0) {
//
// Aux string
//
Index++;
//
// Note, the MSVC C-Start parses out and consolidates quoted strings from the command
// line. Quote characters are stripped. If this tool is ported to other environments
// this will need to be taken into account
//
strncpy (AuxString, argv[Index], 499);
} else if (strcmpi (argv[Index], "-d") == 0) {
//
// Digital signature for EFI_TEST_AUTHENTICAION (must be 0 or 1)
//
Index++;
ParamDigitalSignature = argv[Index];
} else if (strcmpi (argv[Index], "-?") == 0) {
PrintUsageMessage ();
return STATUS_ERROR;
} else {
Error (NULL, 0, 0, argv[Index], "unknown option");
return GetUtilityStatus ();
}
Index++;
}
//
// At this point, all command line parameters are verified as not being totally
// bogus. Next verify the command line parameters are complete and make
// sense...
//
if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_COMPRESSION]) == 0) {
SectionType = EFI_SECTION_COMPRESSION;
SubTypeRequired = TRUE;
if (stricmp (ParamSectionSubType, CompressionTypeName[EFI_NOT_COMPRESSED]) == 0) {
SectionSubType = EFI_NOT_COMPRESSED;
} else if (stricmp (ParamSectionSubType, CompressionTypeName[EFI_STANDARD_COMPRESSION]) == 0) {
SectionSubType = EFI_STANDARD_COMPRESSION;
} else {
Error (NULL, 0, 0, ParamSectionSubType, "unknown compression type");
PrintUsageMessage ();
return GetUtilityStatus ();
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_GUID_DEFINED]) == 0) {
SectionType = EFI_SECTION_GUID_DEFINED;
SubTypeRequired = TRUE;
if (stricmp (ParamSectionSubType, GUIDedSectionTypeName[EFI_SECTION_CRC32_GUID_DEFINED]) == 0) {
SectionSubType = EFI_SECTION_CRC32_GUID_DEFINED;
} else {
Error (NULL, 0, 0, ParamSectionSubType, "unknown GUID defined section type", ParamSectionSubType);
PrintUsageMessage ();
return GetUtilityStatus ();
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_PE32]) == 0) {
SectionType = EFI_SECTION_PE32;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_PIC]) == 0) {
SectionType = EFI_SECTION_PIC;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_TE]) == 0) {
SectionType = EFI_SECTION_TE;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_DXE_DEPEX]) == 0) {
SectionType = EFI_SECTION_DXE_DEPEX;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_VERSION]) == 0) {
SectionType = EFI_SECTION_VERSION;
InputFileRequired = FALSE;
Index = sscanf (ParamVersion, "%d", &VersionNumber);
if (Index != 1 || VersionNumber < 0 || VersionNumber > 65565) {
Error (NULL, 0, 0, ParamVersion, "illegal version number");
PrintUsageMessage ();
return GetUtilityStatus ();
}
if (strcmp (AuxString, PARAMETER_NOT_SPECIFIED) == 0) {
AuxString[0] = 0;
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_USER_INTERFACE]) == 0) {
SectionType = EFI_SECTION_USER_INTERFACE;
InputFileRequired = FALSE;
if (strcmp (AuxString, PARAMETER_NOT_SPECIFIED) == 0) {
Error (NULL, 0, 0, "user interface string not specified", NULL);
PrintUsageMessage ();
return GetUtilityStatus ();
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_COMPATIBILITY16]) == 0) {
SectionType = EFI_SECTION_COMPATIBILITY16;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_FIRMWARE_VOLUME_IMAGE]) == 0) {
SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_FREEFORM_SUBTYPE_GUID]) == 0) {
SectionType = EFI_SECTION_FREEFORM_SUBTYPE_GUID;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_RAW]) == 0) {
SectionType = EFI_SECTION_RAW;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_PEI_DEPEX]) == 0) {
SectionType = EFI_SECTION_PEI_DEPEX;
} else {
Error (NULL, 0, 0, ParamSectionType, "unknown section type");
PrintUsageMessage ();
return GetUtilityStatus ();
}
//
// Open output file
//
OutFile = fopen (OutputFileName, "wb");
if (OutFile == NULL) {
Error (NULL, 0, 0, OutputFileName, "failed to open output file for writing");
if (InFile != NULL) {
fclose (InFile);
}
return GetUtilityStatus ();
}
//
// At this point, we've fully validated the command line, and opened appropriate
// files, so let's go and do what we've been asked to do...
//
//
// Within this switch, build and write out the section header including any
// section type specific pieces. If there's an input file, it's tacked on later
//
switch (SectionType) {
case EFI_SECTION_COMPRESSION:
Status = GenSectionCompressionSection (
InputFileName,
InputFileNum,
SectionType,
SectionSubType,
OutFile
);
break;
case EFI_SECTION_GUID_DEFINED:
Status = GenSectionGuidDefinedSection (
InputFileName,
InputFileNum,
SectionType,
SectionSubType,
OutFile
);
break;
case EFI_SECTION_VERSION:
CommonSect.Type = (EFI_SECTION_TYPE) SectionType;
Index = sizeof (CommonSect);
//
// 2 characters for the build number
//
Index += 2;
//
// Aux string is ascii.. unicode is 2X + 2 bytes for terminating unicode null.
//
Index += (strlen (AuxString) * 2) + 2;
memcpy (&CommonSect.Size, &Index, 3);
fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);
fwrite (&VersionNumber, 2, 1, OutFile);
Ascii2UnicodeWriteString (AuxString, OutFile, FALSE);
break;
case EFI_SECTION_USER_INTERFACE:
CommonSect.Type = (EFI_SECTION_TYPE) SectionType;
Index = sizeof (CommonSect);
//
// Aux string is ascii.. unicode is 2X + 2 bytes for terminating unicode null.
//
Index += (strlen (AuxString) * 2) + 2;
memcpy (&CommonSect.Size, &Index, 3);
fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);
Ascii2UnicodeWriteString (AuxString, OutFile, FALSE);
break;
default:
//
// All other section types are caught by default (they're all the same)
//
Status = GenSectionCommonLeafSection (
InputFileName,
InputFileNum,
SectionType,
OutFile
);
break;
}
if (InputFileName != NULL) {
free (InputFileName);
}
fclose (OutFile);
//
// If we had errors, then delete the output file
//
if (GetUtilityStatus () == STATUS_ERROR) {
remove (OutputFileName);
}
return GetUtilityStatus ();
}

View File

@ -0,0 +1,42 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenSection.h
Abstract:
Header file for GenSection.
--*/
//
// Module Coded to Tiano Coding Conventions
//
#ifndef _EFI_GEN_SECTION_H
#define _EFI_GEN_SECTION_H
//
// External Files Referenced
//
#include <Common/UefiBaseTypes.h>
#include <Common/FirmwareVolumeImageFormat.h>
typedef struct {
EFI_GUID_DEFINED_SECTION GuidSectionHeader;
UINT32 CRC32Checksum;
} CRC32_SECTION_HEADER;
#define EFI_SECTION_CRC32_GUID_DEFINED 0
#define CRC32_SECTION_HEADER_SIZE (sizeof (CRC32_SECTION_HEADER))
#endif

View File

@ -0,0 +1,71 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenSection Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenSection"/>
<property name="FileSet" value="GenSection.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,916 @@
/*++
Copyright (c) 1999-2006 Intel Corporation. All rights reserved
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenTEImage.c
Abstract:
Utility program to shrink a PE32 image down by replacing
the DOS, PE, and optional headers with a minimal header.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Common/UefiBaseTypes.h>
#include <Common/EfiImage.h> // for PE32 structure definitions
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
//
// Version of this utility
//
#define UTILITY_NAME "GenTEImage"
#define UTILITY_VERSION "v0.11"
//
// Define the max length of a filename
//
#define MAX_PATH 256
#define DEFAULT_OUTPUT_EXTENSION ".te"
//
// Use this to track our command-line options and globals
//
struct {
INT8 OutFileName[MAX_PATH];
INT8 InFileName[MAX_PATH];
INT8 Verbose;
INT8 Dump;
} mOptions;
//
// Use these to convert from machine type value to a named type
//
typedef struct {
UINT16 Value;
INT8 *Name;
} STRING_LOOKUP;
static STRING_LOOKUP mMachineTypes[] = {
EFI_IMAGE_MACHINE_IA32,
"IA32",
EFI_IMAGE_MACHINE_IA64,
"IA64",
EFI_IMAGE_MACHINE_EBC,
"EBC",
0,
NULL
};
static STRING_LOOKUP mSubsystemTypes[] = {
EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION,
"EFI application",
EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER,
"EFI boot service driver",
EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER,
"EFI runtime driver",
0,
NULL
};
//
// Function prototypes
//
static
void
Usage (
VOID
);
static
STATUS
ParseCommandLine (
int Argc,
char *Argv[]
);
static
STATUS
CheckPE32File (
INT8 *FileName,
FILE *Fptr,
UINT16 *MachineType,
UINT16 *SubSystem
);
static
STATUS
ProcessFile (
INT8 *InFileName,
INT8 *OutFileName
);
static
void
DumpImage (
INT8 *FileName
);
static
INT8 *
GetMachineTypeStr (
UINT16 MachineType
);
static
INT8 *
GetSubsystemTypeStr (
UINT16 SubsystemType
);
main (
int Argc,
char *Argv[]
)
/*++
Routine Description:
Arguments:
Argc - standard C main() argument count
Argv - standard C main() argument list
Returns:
0 success
non-zero otherwise
--*/
// GC_TODO: ] - add argument and description to function comment
{
INT8 *Ext;
UINT32 Status;
SetUtilityName (UTILITY_NAME);
//
// Parse the command line arguments
//
if (ParseCommandLine (Argc, Argv)) {
return STATUS_ERROR;
}
//
// If dumping an image, then do that and quit
//
if (mOptions.Dump) {
DumpImage (mOptions.InFileName);
goto Finish;
}
//
// Determine the output filename. Either what they specified on
// the command line, or the first input filename with a different extension.
//
if (!mOptions.OutFileName[0]) {
strcpy (mOptions.OutFileName, mOptions.InFileName);
//
// Find the last . on the line and replace the filename extension with
// the default
//
for (Ext = mOptions.OutFileName + strlen (mOptions.OutFileName) - 1;
(Ext >= mOptions.OutFileName) && (*Ext != '.') && (*Ext != '\\');
Ext--
)
;
//
// If dot here, then insert extension here, otherwise append
//
if (*Ext != '.') {
Ext = mOptions.OutFileName + strlen (mOptions.OutFileName);
}
strcpy (Ext, DEFAULT_OUTPUT_EXTENSION);
}
//
// Make sure we don't have the same filename for input and output files
//
if (stricmp (mOptions.OutFileName, mOptions.InFileName) == 0) {
Error (NULL, 0, 0, mOptions.OutFileName, "input and output file names must be different");
goto Finish;
}
//
// Process the file
//
ProcessFile (mOptions.InFileName, mOptions.OutFileName);
Finish:
Status = GetUtilityStatus ();
return Status;
}
static
STATUS
ProcessFile (
INT8 *InFileName,
INT8 *OutFileName
)
/*++
Routine Description:
Process a PE32 EFI file.
Arguments:
InFileName - the file name pointer to the input file
OutFileName - the file name pointer to the output file
Returns:
STATUS_SUCCESS - the process has been finished successfully
STATUS_ERROR - error occured during the processing
--*/
{
STATUS Status;
FILE *InFptr;
FILE *OutFptr;
UINT16 MachineType;
UINT16 SubSystem;
EFI_TE_IMAGE_HEADER TEImageHeader;
UINT32 PESigOffset;
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader32;
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader64;
UINT32 BytesStripped;
UINT32 FileSize;
UINT8 *Buffer;
long SaveFilePosition;
InFptr = NULL;
OutFptr = NULL;
Buffer = NULL;
Status = STATUS_ERROR;
//
// Try to open the input file
//
if ((InFptr = fopen (InFileName, "rb")) == NULL) {
Error (NULL, 0, 0, InFileName, "failed to open input file for reading");
return STATUS_ERROR;
}
//
// Double-check the file to make sure it's what we expect it to be
//
if (CheckPE32File (InFileName, InFptr, &MachineType, &SubSystem) != STATUS_SUCCESS) {
goto Finish;
}
//
// Initialize our new header
//
memset (&TEImageHeader, 0, sizeof (EFI_TE_IMAGE_HEADER));
//
// Seek to the end to get the file size
//
fseek (InFptr, 0, SEEK_END);
FileSize = ftell (InFptr);
fseek (InFptr, 0, SEEK_SET);
//
// Per the PE/COFF specification, at offset 0x3C in the file is a 32-bit
// offset (from the start of the file) to the PE signature, which always
// follows the MSDOS stub. The PE signature is immediately followed by the
// COFF file header.
//
//
if (fseek (InFptr, 0x3C, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to PE signature in file", NULL);
goto Finish;
}
if (fread (&PESigOffset, sizeof (PESigOffset), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read PE signature offset from file");
goto Finish;
}
if (fseek (InFptr, PESigOffset + 4, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to PE signature");
goto Finish;
}
//
// We should now be at the COFF file header. Read it in and verify it's
// of an image type we support.
//
if (fread (&FileHeader, sizeof (EFI_IMAGE_FILE_HEADER), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read file header from image");
goto Finish;
}
if ((FileHeader.Machine != EFI_IMAGE_MACHINE_IA32) && (FileHeader.Machine != EFI_IMAGE_MACHINE_IA64)) {
Error (NULL, 0, 0, InFileName, "image is of an unsupported machine type 0x%X", (UINT32) FileHeader.Machine);
goto Finish;
}
//
// Calculate the total number of bytes we're going to strip off. The '4' is for the
// PE signature PE\0\0. Then sanity check the size.
//
BytesStripped = PESigOffset + 4 + sizeof (EFI_IMAGE_FILE_HEADER) + FileHeader.SizeOfOptionalHeader;
if (BytesStripped >= FileSize) {
Error (NULL, 0, 0, InFileName, "attempt to strip more bytes than the total file size");
goto Finish;
}
if (BytesStripped &~0xFFFF) {
Error (NULL, 0, 0, InFileName, "attempt to strip more than 64K bytes", NULL);
goto Finish;
}
TEImageHeader.StrippedSize = (UINT16) BytesStripped;
//
// Read in the optional header. Assume PE32, and if not, then re-read as PE32+
//
SaveFilePosition = ftell (InFptr);
if (fread (&OptionalHeader32, sizeof (EFI_IMAGE_OPTIONAL_HEADER32), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read optional header from input file");
goto Finish;
}
if (OptionalHeader32.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Fill in our new header with required data directory entries
//
TEImageHeader.AddressOfEntryPoint = OptionalHeader32.AddressOfEntryPoint;
//
// - BytesStripped + sizeof (EFI_TE_IMAGE_HEADER);
//
// We're going to pack the subsystem into 1 byte. Make sure it fits
//
if (OptionalHeader32.Subsystem &~0xFF) {
Error (
NULL,
0,
0,
InFileName,
NULL,
"image subsystem 0x%X cannot be packed into 1 byte",
(UINT32) OptionalHeader32.Subsystem
);
goto Finish;
}
TEImageHeader.Subsystem = (UINT8) OptionalHeader32.Subsystem;
TEImageHeader.BaseOfCode = OptionalHeader32.BaseOfCode;
TEImageHeader.ImageBase = (UINT64) (OptionalHeader32.ImageBase + TEImageHeader.StrippedSize - sizeof (EFI_TE_IMAGE_HEADER));
if (OptionalHeader32.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
}
if (OptionalHeader32.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
}
} else if (OptionalHeader32.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
//
// Rewind and re-read the optional header
//
fseek (InFptr, SaveFilePosition, SEEK_SET);
if (fread (&OptionalHeader64, sizeof (EFI_IMAGE_OPTIONAL_HEADER64), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to re-read optional header from input file");
goto Finish;
}
TEImageHeader.AddressOfEntryPoint = OptionalHeader64.AddressOfEntryPoint;
//
// - BytesStripped + sizeof (EFI_TE_IMAGE_HEADER);
//
// We're going to pack the subsystem into 1 byte. Make sure it fits
//
if (OptionalHeader64.Subsystem &~0xFF) {
Error (
NULL,
0,
0,
InFileName,
NULL,
"image subsystem 0x%X cannot be packed into 1 byte",
(UINT32) OptionalHeader64.Subsystem
);
goto Finish;
}
TEImageHeader.Subsystem = (UINT8) OptionalHeader64.Subsystem;
TEImageHeader.BaseOfCode = OptionalHeader32.BaseOfCode;
TEImageHeader.ImageBase = (UINT64) (OptionalHeader64.ImageBase + TEImageHeader.StrippedSize - sizeof (EFI_TE_IMAGE_HEADER));
if (OptionalHeader64.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
}
if (OptionalHeader64.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
}
} else {
Error (
NULL,
0,
0,
InFileName,
"unsupported magic number 0x%X found in optional header",
(UINT32) OptionalHeader32.Magic
);
goto Finish;
}
//
// Fill in the remainder of our new image header
//
TEImageHeader.Signature = EFI_TE_IMAGE_HEADER_SIGNATURE;
TEImageHeader.Machine = FileHeader.Machine;
//
// We're going to pack the number of sections into a single byte. Make sure it fits.
//
if (FileHeader.NumberOfSections &~0xFF) {
Error (
NULL,
0,
0,
InFileName,
NULL,
"image's number of sections 0x%X cannot be packed into 1 byte",
(UINT32) FileHeader.NumberOfSections
);
goto Finish;
}
TEImageHeader.NumberOfSections = (UINT8) FileHeader.NumberOfSections;
//
// Now open our output file
//
if ((OutFptr = fopen (OutFileName, "wb")) == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
goto Finish;
}
//
// Write the TE header
//
if (fwrite (&TEImageHeader, sizeof (EFI_TE_IMAGE_HEADER), 1, OutFptr) != 1) {
Error (NULL, 0, 0, "failed to write image header to output file", NULL);
goto Finish;
}
//
// Position into the input file, read the part we're not stripping, and
// write it out.
//
fseek (InFptr, BytesStripped, SEEK_SET);
Buffer = (UINT8 *) malloc (FileSize - BytesStripped);
if (Buffer == NULL) {
Error (NULL, 0, 0, "application error", "failed to allocate memory");
goto Finish;
}
if (fread (Buffer, FileSize - BytesStripped, 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read remaining contents of input file");
goto Finish;
}
if (fwrite (Buffer, FileSize - BytesStripped, 1, OutFptr) != 1) {
Error (NULL, 0, 0, OutFileName, "failed to write all bytes to output file");
goto Finish;
}
Status = STATUS_SUCCESS;
Finish:
if (InFptr != NULL) {
fclose (InFptr);
}
//
// Close the output file. If there was an error, delete the output file so
// that a subsequent build will rebuild it.
//
if (OutFptr != NULL) {
fclose (OutFptr);
if (GetUtilityStatus () == STATUS_ERROR) {
remove (OutFileName);
}
}
//
// Free up our buffer
//
if (Buffer != NULL) {
free (Buffer);
}
return Status;
}
static
STATUS
CheckPE32File (
INT8 *FileName,
FILE *Fptr,
UINT16 *MachineType,
UINT16 *SubSystem
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FileName - GC_TODO: add argument description
Fptr - GC_TODO: add argument description
MachineType - GC_TODO: add argument description
SubSystem - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
/*++
Routine Description:
Given a file pointer to a supposed PE32 image file, verify that it is indeed a
PE32 image file, and then return the machine type in the supplied pointer.
Arguments:
Fptr File pointer to the already-opened PE32 file
MachineType Location to stuff the machine type of the PE32 file. This is needed
because the image may be Itanium-based, IA32, or EBC.
Returns:
0 success
non-zero otherwise
--*/
EFI_IMAGE_DOS_HEADER DosHeader;
EFI_IMAGE_FILE_HEADER FileHdr;
EFI_IMAGE_OPTIONAL_HEADER OptionalHdr;
UINT32 PESig;
STATUS Status;
Status = STATUS_ERROR;
//
// Position to the start of the file
//
fseek (Fptr, 0, SEEK_SET);
//
// Read the DOS header
//
if (fread (&DosHeader, sizeof (DosHeader), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read the DOS stub from the input file");
goto Finish;
}
//
// Check the magic number (0x5A4D)
//
if (DosHeader.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Error (NULL, 0, 0, FileName, "input file does not appear to be a PE32 image (magic number)");
goto Finish;
}
//
// Position into the file and check the PE signature
//
fseek (Fptr, (long) DosHeader.e_lfanew, SEEK_SET);
if (fread (&PESig, sizeof (PESig), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read PE signature bytes");
goto Finish;
}
//
// Check the PE signature in the header "PE\0\0"
//
if (PESig != EFI_IMAGE_NT_SIGNATURE) {
Error (NULL, 0, 0, FileName, "file does not appear to be a PE32 image (signature)");
goto Finish;
}
//
// Read the file header
//
if (fread (&FileHdr, sizeof (FileHdr), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read PE file header from input file");
goto Finish;
}
//
// Read the optional header so we can get the subsystem
//
if (fread (&OptionalHdr, sizeof (OptionalHdr), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read COFF optional header from input file");
goto Finish;
}
*SubSystem = OptionalHdr.Subsystem;
if (mOptions.Verbose) {
fprintf (stdout, " Got subsystem = 0x%X from image\n", (int) *SubSystem);
}
//
// Good to go
//
Status = STATUS_SUCCESS;
Finish:
fseek (Fptr, 0, SEEK_SET);
return Status;
}
static
int
ParseCommandLine (
int Argc,
char *Argv[]
)
/*++
Routine Description:
Given the Argc/Argv program arguments, and a pointer to an options structure,
parse the command-line options and check their validity.
Arguments:
Argc - standard C main() argument count
Argv - standard C main() argument list
Returns:
STATUS_SUCCESS success
non-zero otherwise
--*/
// GC_TODO: ] - add argument and description to function comment
{
//
// Clear out the options
//
memset ((char *) &mOptions, 0, sizeof (mOptions));
//
// Skip over the program name
//
Argc--;
Argv++;
//
// If no arguments, assume they want usage info
//
if (Argc == 0) {
Usage ();
return STATUS_ERROR;
}
//
// Process until no more arguments
//
while ((Argc > 0) && (Argv[0][0] == '-')) {
if (stricmp (Argv[0], "-o") == 0) {
//
// Output filename specified with -o
// Make sure there's another parameter
//
if (Argc > 1) {
strcpy (mOptions.OutFileName, Argv[1]);
} else {
Error (NULL, 0, 0, Argv[0], "missing output file name with option");
Usage ();
return STATUS_ERROR;
}
Argv++;
Argc--;
} else if ((stricmp (Argv[0], "-h") == 0) || (strcmp (Argv[0], "-?") == 0)) {
//
// Help option
//
Usage ();
return STATUS_ERROR;
} else if (stricmp (Argv[0], "-v") == 0) {
//
// -v for verbose
//
mOptions.Verbose = 1;
} else if (stricmp (Argv[0], "-dump") == 0) {
//
// -dump for dumping an image
//
mOptions.Dump = 1;
} else {
Error (NULL, 0, 0, Argv[0], "unrecognized option");
Usage ();
return STATUS_ERROR;
}
//
// Next argument
//
Argv++;
Argc--;
}
//
// Better be one more arg for input file name
//
if (Argc == 0) {
Error (NULL, 0, 0, "input file name required", NULL);
Usage ();
return STATUS_ERROR;
}
if (Argc != 1) {
Error (NULL, 0, 0, Argv[1], "extra arguments on command line");
return STATUS_ERROR;
}
strcpy (mOptions.InFileName, Argv[0]);
return STATUS_SUCCESS;
}
static
void
Usage (
VOID
)
/*++
Routine Description:
Print usage information for this utility.
Arguments:
None.
Returns:
Nothing.
--*/
{
int Index;
static const char *Msg[] = {
UTILITY_NAME " version "UTILITY_VERSION " - TE image utility",
" Generate a TE image from an EFI PE32 image",
" Usage: "UTILITY_NAME " {-v} {-dump} {-h|-?} {-o OutFileName} InFileName",
" [-e|-b] [FileName(s)]",
" where:",
" -v - for verbose output",
" -dump - to dump the input file to a text file",
" -h -? - for this help information",
" -o OutFileName - to write output to OutFileName rather than InFileName"DEFAULT_OUTPUT_EXTENSION,
" InFileName - name of the input PE32 file",
"",
NULL
};
for (Index = 0; Msg[Index] != NULL; Index++) {
fprintf (stdout, "%s\n", Msg[Index]);
}
}
static
VOID
DumpImage (
INT8 *FileName
)
/*++
Routine Description:
Dump a specified image information
Arguments:
FileName - File name pointer to the image to dump
Returns:
Nothing.
--*/
{
FILE *InFptr;
EFI_TE_IMAGE_HEADER TEImageHeader;
INT8 *NamePtr;
//
// Open the input file
//
InFptr = NULL;
if ((InFptr = fopen (FileName, "rb")) == NULL) {
Error (NULL, 0, 0, FileName, "failed to open input file for reading");
return ;
}
if (fread (&TEImageHeader, sizeof (EFI_TE_IMAGE_HEADER), 1, InFptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read image header from input file");
goto Finish;
}
if (TEImageHeader.Signature != EFI_TE_IMAGE_HEADER_SIGNATURE) {
Error (NULL, 0, 0, FileName, "Image does not appear to be a TE image (bad signature)");
goto Finish;
}
//
// Dump the header
//
fprintf (stdout, "Header (%d bytes):\n", sizeof (EFI_TE_IMAGE_HEADER));
fprintf (stdout, " Signature: 0x%04X (TE)\n", (UINT32) TEImageHeader.Signature);
NamePtr = GetMachineTypeStr (TEImageHeader.Machine);
fprintf (stdout, " Machine: 0x%04X (%s)\n", (UINT32) TEImageHeader.Machine, NamePtr);
NamePtr = GetSubsystemTypeStr (TEImageHeader.Subsystem);
fprintf (stdout, " Subsystem: 0x%02X (%s)\n", (UINT32) TEImageHeader.Subsystem, NamePtr);
fprintf (stdout, " Number of sections 0x%02X\n", (UINT32) TEImageHeader.NumberOfSections);
fprintf (stdout, " Stripped size: 0x%04X\n", (UINT32) TEImageHeader.StrippedSize);
fprintf (stdout, " Entry point: 0x%08X\n", TEImageHeader.AddressOfEntryPoint);
fprintf (stdout, " Base of code: 0x%08X\n", TEImageHeader.BaseOfCode);
fprintf (stdout, " Data directories:\n");
fprintf (
stdout,
" %8X [%8X] RVA [size] of Base Relocation Directory\n",
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress,
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size
);
fprintf (
stdout,
" %8X [%8X] RVA [size] of Debug Directory\n",
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress,
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].Size
);
Finish:
if (InFptr != NULL) {
fclose (InFptr);
}
}
static
INT8 *
GetMachineTypeStr (
UINT16 MachineType
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
MachineType - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
int Index;
for (Index = 0; mMachineTypes[Index].Name != NULL; Index++) {
if (mMachineTypes[Index].Value == MachineType) {
return mMachineTypes[Index].Name;
}
}
return "unknown";
}
static
INT8 *
GetSubsystemTypeStr (
UINT16 SubsystemType
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
SubsystemType - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
int Index;
for (Index = 0; mSubsystemTypes[Index].Name != NULL; Index++) {
if (mSubsystemTypes[Index].Value == SubsystemType) {
return mSubsystemTypes[Index].Name;
}
}
return "unknown";
}

View File

@ -0,0 +1,72 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenTEImage Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenTEImage"/>
<property name="FileSet" value="*.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="init">
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/${HostArch}"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,57 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CommonUtils.h
Abstract:
Common utility defines and structure definitions.
--*/
#ifndef _COMMON_UTILS_H_
#define _COMMON_UTILS_H_
//
// Basic types
//
typedef unsigned char UINT8;
typedef char INT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef UINT8 BOOLEAN;
typedef UINT32 STATUS;
#define TRUE 1
#define FALSE 0
#define STATUS_SUCCESS 0
#define STATUS_WARNING 1
#define STATUS_ERROR 2
//
// Linked list of strings
//
typedef struct _STRING_LIST {
struct _STRING_LIST *Next;
char *Str;
} STRING_LIST;
int
CreateGuidList (
INT8 *OutFileName
)
;
#endif // #ifndef _COMMON_UTILS_H_

View File

@ -0,0 +1,285 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FileSearch.c
Abstract:
Module used to support file searches on the system.
--*/
#include <stdio.h>
#include "CommonUtils.h"
#include "FileSearch.h"
#include "UtilsMsgs.h"
//
// Internal file search flag for sanity checks
//
#define FILE_SEARCH_STARTED 0x8000
#define FILE_SEARCH_INITED 0x4000
static
BOOLEAN
FileSearchMeetsCriteria (
FILE_SEARCH_DATA *FSData
);
/*****************************************************************************/
STATUS
FileSearchInit (
FILE_SEARCH_DATA *FSData
)
{
memset ((char *) FSData, 0, sizeof (FILE_SEARCH_DATA));
FSData->Handle = INVALID_HANDLE_VALUE;
FSData->FileSearchFlags = FILE_SEARCH_INITED;
FSData->FileName[0] = 0;
return STATUS_SUCCESS;
}
STATUS
FileSearchStart (
FILE_SEARCH_DATA *FSData,
char *FileMask,
UINT32 SearchFlags
)
{
BOOLEAN Done;
//
// Save their flags, and set a flag to indicate that they called this
// start function so we can perform extended checking in the other
// routines we have in this module.
//
FSData->FileSearchFlags |= (SearchFlags | FILE_SEARCH_STARTED);
FSData->FileName[0] = 0;
//
// Begin the search
//
FSData->Handle = FindFirstFile (FileMask, &(FSData->FindData));
if (FSData->Handle == INVALID_HANDLE_VALUE) {
return STATUS_ERROR;
}
//
// Keep looping through until we find a file meeting the caller's
// criteria per the search flags
//
Done = FALSE;
while (!Done) {
//
// If we're done (we found a match) copy the file name found and return
//
Done = FileSearchMeetsCriteria (FSData);
if (Done) {
return STATUS_SUCCESS;
}
//
// Go on to next file
//
if (!FindNextFile (FSData->Handle, &(FSData->FindData))) {
return STATUS_NOT_FOUND;
}
}
//
// Not reached
//
return STATUS_NOT_FOUND;
}
//
// Find the next file meeting their criteria and return it.
//
STATUS
FileSearchFindNext (
FILE_SEARCH_DATA *FSData
)
{
BOOLEAN Done;
Done = FALSE;
while (!Done) {
if (!FindNextFile (FSData->Handle, &(FSData->FindData))) {
return STATUS_NOT_FOUND;
}
//
// See if it matches their criteria
//
Done = FileSearchMeetsCriteria (FSData);
if (Done) {
return STATUS_SUCCESS;
}
}
//
// Not reached
//
return STATUS_NOT_FOUND;
}
//
// Perform any cleanup necessary to close down a search
//
STATUS
FileSearchDestroy (
FILE_SEARCH_DATA *FSData
)
{
if (FSData->Handle != INVALID_HANDLE_VALUE) {
FindClose (FSData->Handle);
FSData->Handle = INVALID_HANDLE_VALUE;
}
FSData->FileName[0] = 0;
FSData->FileSearchFlags = 0;
return STATUS_SUCCESS;
}
static
BOOLEAN
FileSearchMeetsCriteria (
FILE_SEARCH_DATA *FSData
)
{
BOOLEAN Status;
STRING_LIST *StrList;
UINT32 ExtLen;
UINT32 FileNameLen;
Status = FALSE;
//
// First clear the flag indicating this is neither a file or a
// directory.
//
FSData->FileFlags &= ~(FILE_SEARCH_DIR | FILE_SEARCH_FILE);
//
// We found a file. See if it matches the user's search criteria. First
// check for this being a directory, and they want directories, and
// it's not "." and it's not ".."
//
if ((FSData->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
(FSData->FileSearchFlags & FILE_SEARCH_DIR) &&
(strcmp (FSData->FindData.cFileName, ".")) &&
(strcmp (FSData->FindData.cFileName, ".."))
) {
//
// Assume we'll make it past this check
//
Status = TRUE;
//
// If they have a list of exclude directories, then check for those
//
StrList = FSData->ExcludeDirs;
while (StrList != NULL) {
if (stricmp (FSData->FindData.cFileName, StrList->Str) == 0) {
Status = FALSE;
break;
}
StrList = StrList->Next;
}
//
// If we didn't fail due to excluded directories, then set the dir flag
//
if (Status) {
FSData->FileFlags |= FILE_SEARCH_DIR;
}
//
// Else check for a file, and they want files....
//
} else if (((FSData->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) &&
(FSData->FileSearchFlags & FILE_SEARCH_FILE)
) {
//
// See if it's in our list of excluded files
//
Status = TRUE;
StrList = FSData->ExcludeFiles;
while (StrList != NULL) {
if (stricmp (FSData->FindData.cFileName, StrList->Str) == 0) {
Status = FALSE;
break;
}
StrList = StrList->Next;
}
if (Status) {
//
// See if it's in our list of excluded file extensions
//
FileNameLen = strlen (FSData->FindData.cFileName);
StrList = FSData->ExcludeExtensions;
while (StrList != NULL) {
ExtLen = strlen (StrList->Str);
if (stricmp (
FSData->FindData.cFileName + FileNameLen - ExtLen,
StrList->Str
) == 0) {
Status = FALSE;
break;
}
StrList = StrList->Next;
}
}
if (Status) {
FSData->FileFlags |= FILE_SEARCH_FILE;
}
}
//
// If it's a match, copy the filename into another field of the structure
// for portability.
//
if (Status) {
strcpy (FSData->FileName, FSData->FindData.cFileName);
}
return Status;
}
//
// Exclude a list of subdirectories.
//
STATUS
FileSearchExcludeDirs (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
{
FSData->ExcludeDirs = StrList;
return STATUS_SUCCESS;
}
STATUS
FileSearchExcludeFiles (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
{
FSData->ExcludeFiles = StrList;
return STATUS_SUCCESS;
}
STATUS
FileSearchExcludeExtensions (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
{
FSData->ExcludeExtensions = StrList;
return STATUS_SUCCESS;
}

View File

@ -0,0 +1,108 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FileSearch.h
Abstract:
Header file to support file searching.
--*/
#ifndef _FILE_SEARCH_H_
#define _FILE_SEARCH_H_
//
// Since the file searching routines are OS dependent, put the
// necessary include paths in this header file so that the non-OS-dependent
// files don't need to include these windows-specific header files.
//
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <direct.h>
#include <windows.h>
//
// Return codes of some of the file search routines
//
#define STATUS_NOT_FOUND 0x1000
//
// Flags for what to search for. Also used in the FileFlags return field.
//
#define FILE_SEARCH_DIR 0x0001
#define FILE_SEARCH_FILE 0x0002
//
// Here's our class definition
//
typedef struct {
HANDLE Handle;
WIN32_FIND_DATA FindData;
UINT32 FileSearchFlags; // DIRS, FILES, etc
UINT32 FileFlags;
INT8 FileName[MAX_PATH]; // for portability
STRING_LIST *ExcludeDirs;
STRING_LIST *ExcludeFiles;
STRING_LIST *ExcludeExtensions;
} FILE_SEARCH_DATA;
//
// Here's our member functions
//
STATUS
FileSearchInit (
FILE_SEARCH_DATA *FSData
)
;
STATUS
FileSearchDestroy (
FILE_SEARCH_DATA *FSData
)
;
STATUS
FileSearchStart (
FILE_SEARCH_DATA *FSData,
char *FileMask,
UINT32 SearchFlags
)
;
STATUS
FileSearchFindNext (
FILE_SEARCH_DATA *FSData
)
;
STATUS
FileSearchExcludeDirs (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
;
STATUS
FileSearchExcludeExtensions (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
;
STATUS
FileSearchExcludeFiles (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,186 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GuidList.c
Abstract:
Utility to create a GUID-to-name listing file that can
be used by other utilities. Basic operation is to take the
table of name+GUIDs that we have compiled into this utility,
and create a text file that can be parsed by other utilities
to do replacement of "name" with "GUID".
Notes:
To add a new GUID to this database:
1. Add a "#include EFI_GUID_DEFINITION(name)" statement below
2. Modify the mGuidList[] array below to add the new GUID name
The only issue that may come up is that, if the source GUID file
is not in the standard GUID directory, then this utility won't
compile because the #include fails. In this case you'd need
to define a new macro (if it's in a standard place) or modify
this utility's makefile to add the path to your new .h file.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <Common/UefiBaseTypes.h>
#include <Guid/Apriori.h>
#include <Guid/AcpiTableStorage.h>
#include "EfiUtilityMsgs.h"
#define GUID_XREF(varname, guid) { \
#varname, #guid, guid \
}
#define NULL_GUID \
{ \
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 \
}
typedef struct {
INT8 *VariableName;
INT8 *DefineName;
EFI_GUID Guid;
} GUID_LIST;
//
// This is our table of all GUIDs we want to print out to create
// a GUID-to-name cross reference.
// Use the #defined name from the GUID definition's source .h file.
//
static GUID_LIST mGuidList[] = {
GUID_XREF(gAprioriGuid, EFI_APRIORI_GUID),
GUID_XREF(gEfiAcpiTableStorageGuid, EFI_ACPI_TABLE_STORAGE_GUID),
// FIXME The next line was removed in the port to R9.
// GUID_XREF(gEfiDefaultBmpLogoGuid, EFI_DEFAULT_BMP_LOGO_GUID),
GUID_XREF(gEfiAcpiTableStorageGuid, EFI_ACPI_TABLE_STORAGE_GUID),
//
// Terminator
//
{
NULL,
NULL,
NULL_GUID
}
};
void
PrintGuidText (
FILE *OutFptr,
INT8 *VariableName,
INT8 *DefineName,
EFI_GUID *Guid
);
int
CreateGuidList (
INT8 *OutFileName
)
/*++
Routine Description:
Print our GUID/name list to the specified output file.
Arguments:
OutFileName - name of the output file to write our results to.
Returns:
0 if successful
nonzero otherwise
--*/
{
FILE *OutFptr;
int Index;
//
// Open output file for writing. If the name is NULL, then write to stdout
//
if (OutFileName != NULL) {
OutFptr = fopen (OutFileName, "w");
if (OutFptr == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
return STATUS_ERROR;
}
} else {
OutFptr = stdout;
}
for (Index = 0; mGuidList[Index].VariableName != NULL; Index++) {
PrintGuidText (OutFptr, mGuidList[Index].VariableName, mGuidList[Index].DefineName, &mGuidList[Index].Guid);
}
//
// Close the output file if they specified one.
//
if (OutFileName != NULL) {
fclose (OutFptr);
}
return STATUS_SUCCESS;
}
void
PrintGuidText (
FILE *OutFptr,
INT8 *VariableName,
INT8 *DefineName,
EFI_GUID *Guid
)
/*++
Routine Description:
Print a GUID/name combo in INF-style format
guid-guid-guid-guid DEFINE_NAME gName
Arguments:
OutFptr - file pointer to which to write the output
VariableName - the GUID variable's name
DefineName - the name used in the #define
Guid - pointer to the GUID value
Returns:
NA
--*/
{
if (OutFptr == NULL) {
OutFptr = stdout;
}
fprintf (
OutFptr,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X %s %s\n",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7],
DefineName,
VariableName
);
}

View File

@ -0,0 +1,490 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
UtilsMsgs.c
Abstract:
EFI tools utility functions to display warning, error, and informational
messages.
--*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <Common/UefiBaseTypes.h>
#include "EfiUtilityMsgs.h"
#define MAX_LINE_LEN 200
//
// Declare module globals for keeping track of the the utility's
// name and other settings.
//
static STATUS mStatus = STATUS_SUCCESS;
static INT8 mUtilityName[50] = { 0 };
static INT8 *mSourceFileName = NULL;
static UINT32 mSourceFileLineNum = 0;
static UINT32 mErrorCount = 0;
static UINT32 mWarningCount = 0;
static UINT32 mDebugMsgMask = 0;
static
void
PrintMessage (
INT8 *Type,
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
va_list List
);
void
Error (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Prints an error message.
Arguments:
All arguments are optional, though the printed message may be useless if
at least something valid is not specified.
FileName - name of the file or application. If not specified, then the
utilty name (as set by the utility calling SetUtilityName()
earlier) is used. Otherwise "Unknown utility" is used.
LineNumber - the line number of error, typically used by parsers. If the
utility is not a parser, then 0 should be specified. Otherwise
the FileName and LineNumber info can be used to cause
MS Visual Studio to jump to the error.
MessageCode - an application-specific error code that can be referenced in
other documentation.
Text - the text in question, typically used by parsers.
MsgFmt - the format string for the error message. Can contain formatting
controls for use with the varargs.
Returns:
None.
Notes:
We print the following (similar to the Warn() and Debug()
W
Typical error/warning message format:
bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : function does not take 2 parameters
BUGBUG -- these three utility functions are almost identical, and
should be modified to share code.
Visual Studio does not find error messages with:
" error :"
" error 1:"
" error c1:"
" error 1000:"
" error c100:"
It does find:
" error c1000:"
--*/
{
va_list List;
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserError (
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser error, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
MessageCode - application-specific error code
Text - text to print in the error message
MsgFmt - format string to print at the end of the error message
...
Returns:
NA
--*/
{
va_list List;
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserWarning (
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser warning, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
ErrorCode - application-specific error code
OffendingText - text to print in the warning message
MsgFmt - format string to print at the end of the warning message
...
Returns:
NA
--*/
{
va_list List;
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", mSourceFileName, mSourceFileLineNum, ErrorCode, OffendingText, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
Warning (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - the text in question (parsers)
MsgFmt - the format string for the warning message. Can contain formatting
controls for use with varargs.
...
Returns:
None.
--*/
{
va_list List;
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
DebugMsg (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MsgMask,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - typically the name of the utility printing the debug message, but
can be the name of a file being parsed.
LineNumber - the line number in FileName (parsers)
MsgMask - an application-specific bitmask that, in combination with mDebugMsgMask,
determines if the debug message gets printed.
Text - the text in question (parsers)
MsgFmt - the format string for the debug message. Can contain formatting
controls for use with varargs.
...
Returns:
None.
--*/
{
va_list List;
//
// If the debug mask is not applicable, then do nothing.
//
if ((MsgMask != 0) && ((mDebugMsgMask & MsgMask) == 0)) {
return ;
}
va_start (List, MsgFmt);
PrintMessage ("debug", FileName, LineNumber, 0, Text, MsgFmt, List);
va_end (List);
}
static
void
PrintMessage (
INT8 *Type,
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
va_list List
)
/*++
Routine Description:
Worker routine for all the utility printing services. Prints the message in
a format that Visual Studio will find when scanning build outputs for
errors or warnings.
Arguments:
Type - "warning" or "error" string to insert into the message to be
printed. The first character of this string (converted to uppercase)
is used to preceed the MessageCode value in the output string.
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - part of the message to print
MsgFmt - the format string for the message. Can contain formatting
controls for use with varargs.
List - Variable function parameter list.
Returns:
None.
Notes:
If FileName == NULL then this utility will use the string passed into SetUtilityName().
LineNumber is only used if the caller is a parser, in which case FileName refers to the
file being parsed.
Text and MsgFmt are both optional, though it would be of little use calling this function with
them both NULL.
Output will typically be of the form:
<FileName>(<LineNumber>) : <Type> <Type[0]><MessageCode>: <Text> : <MsgFmt>
Parser (LineNumber != 0)
VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function does not take 2 parameters
Generic utility (LineNumber == 0)
UtilityName : error E1234 : Text string : MsgFmt string and args
--*/
{
INT8 Line[MAX_LINE_LEN];
INT8 Line2[MAX_LINE_LEN];
INT8 *Cptr;
//
// If given a filename, then add it (and the line number) to the string.
// If there's no filename, then use the program name if provided.
//
if (FileName != NULL) {
Cptr = FileName;
} else if (mUtilityName[0] != 0) {
Cptr = mUtilityName;
} else {
Cptr = "Unknown utility";
}
strcpy (Line, Cptr);
if (LineNumber != 0) {
sprintf (Line2, "(%d)", LineNumber);
strcat (Line, Line2);
}
//
// Have to print an error code or Visual Studio won't find the
// message for you. It has to be decimal digits too.
//
sprintf (Line2, " : %s %c%04d", Type, toupper (Type[0]), MessageCode);
strcat (Line, Line2);
fprintf (stdout, "%s", Line);
//
// If offending text was provided, then print it
//
if (Text != NULL) {
fprintf (stdout, ": %s ", Text);
}
//
// Print formatted message if provided
//
if (MsgFmt != NULL) {
vsprintf (Line2, MsgFmt, List);
fprintf (stdout, ": %s", Line2);
}
fprintf (stdout, "\n");
}
void
ParserSetPosition (
INT8 *SourceFileName,
UINT32 LineNum
)
/*++
Routine Description:
Set the position in a file being parsed. This can be used to
print error messages deeper down in a parser.
Arguments:
SourceFileName - name of the source file being parsed
LineNum - line number of the source file being parsed
Returns:
NA
--*/
{
mSourceFileName = SourceFileName;
mSourceFileLineNum = LineNum;
}
void
SetUtilityName (
INT8 *UtilityName
)
/*++
Routine Description:
All printed error/warning/debug messages follow the same format, and
typically will print a filename or utility name followed by the error
text. However if a filename is not passed to the print routines, then
they'll print the utility name if you call this function early in your
app to set the utility name.
Arguments:
UtilityName - name of the utility, which will be printed with all
error/warning/debug messags.
Returns:
NA
--*/
{
//
// Save the name of the utility in our local variable. Make sure its
// length does not exceed our buffer.
//
if (UtilityName != NULL) {
if (strlen (UtilityName) >= sizeof (mUtilityName)) {
Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");
strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);
mUtilityName[sizeof (mUtilityName) - 1] = 0;
return ;
} else {
strcpy (mUtilityName, UtilityName);
}
} else {
Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");
}
}
STATUS
GetUtilityStatus (
VOID
)
/*++
Routine Description:
When you call Error() or Warning(), this module keeps track of it and
sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility
exits, it can call this function to get the status and use it as a return
value.
Arguments:
None.
Returns:
Worst-case status reported, as defined by which print function was called.
--*/
{
return mStatus;
}

View File

@ -0,0 +1,106 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
UtilsMsgs.h
Abstract:
Prototypes for the EFI tools utility functions.
--*/
#ifndef _UTILS_MESSAGES_H_
#define _UTILS_MESSAGES_H_
STATUS
GetUtilityStatus (
VOID
)
;
//
// If someone prints an error message and didn't specify a source file name,
// then we print the utility name instead. However they must tell us the
// utility name early on via this function.
//
VOID
SetUtilityName (
INT8 *ProgramName
)
;
void
Error (
INT8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
Warning (
INT8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
DebugMsg (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MsgLevel,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
SetDebugMsgMask (
UINT32 MsgMask
)
;
void
ParserSetPosition (
INT8 *SourceFileName,
UINT32 LineNum
)
;
void
ParserError (
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
ParserWarning (
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
#endif

View File

@ -0,0 +1,84 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GuidChk Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GuidChk"/>
<property name="FileSet" value="*.c *.h"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<if>
<isfalse value="${gcc}"/>
<then>
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</then>
</if>
</target>
<target name="init">
<if>
<istrue value="${gcc}"/>
<then>
<echo message="The EDK Tool: ${ToolName} is not built for GCC!"/>
</then>
<else>
<echo message="Building the EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
</else>
</if>
</target>
<target name="Tool" depends="init" unless="gcc">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
debug="true"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/Include"/>
<includepath path="${PACKAGE_DIR}/Include/Ia32"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<libset dir="${LIB_DIR}" libs="CommonTools"/>
</cc>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset dir="${BUILD_DIR}"/>
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@ -0,0 +1,212 @@
/** @file
Processor or Compiler specific defines for all supported processors.
This file is stand alone self consistent set of definitions.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: BaseTypes.h
**/
#ifndef __BASE_TYPES_H__
#define __BASE_TYPES_H__
//
// Include processor specific binding
//
#include <ProcessorBind.h>
#include <stdarg.h>
#define MEMORY_FENCE() MemoryFence ()
#define BREAKPOINT() CpuBreakpoint ()
#define DEADLOOP() CpuDeadLoop ()
typedef struct {
UINT32 Data1;
UINT16 Data2;
UINT16 Data3;
UINT8 Data4[8];
} GUID;
//
// Modifiers to absract standard types to aid in debug of problems
//
#define CONST const
#define STATIC static
#define VOID void
//
// Modifiers for Data Types used to self document code.
// This concept is borrowed for UEFI specification.
//
#ifndef IN
//
// Some other envirnments use this construct, so #ifndef to prevent
// mulitple definition.
//
#define IN
#define OUT
#define OPTIONAL
#endif
//
// Constants. They may exist in other build structures, so #ifndef them.
//
#ifndef TRUE
//
// BugBug: UEFI specification claims 1 and 0. We are concerned about the
// complier portability so we did it this way.
//
#define TRUE ((BOOLEAN)(1==1))
#endif
#ifndef FALSE
#define FALSE ((BOOLEAN)(0==1))
#endif
#ifndef NULL
#define NULL ((VOID *) 0)
#endif
//
// Support for variable length argument lists using the ANSI standard.
//
// Since we are using the ANSI standard we used the standard nameing and
// did not folow the coding convention
//
// VA_LIST - typedef for argument list.
// VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use.
// VA_END (VA_LIST Marker) - Clear Marker
// VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argumnet from
// the ... list. You must know the size and pass it in this macro.
//
// example:
//
// UINTN
// ExampleVarArg (
// IN UINTN NumberOfArgs,
// ...
// )
// {
// VA_LIST Marker;
// UINTN Index;
// UINTN Result;
//
// //
// // Initialize the Marker
// //
// VA_START (Marker, NumberOfArgs);
// for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) {
// //
// // The ... list is a series of UINTN values, so average them up.
// //
// Result += VA_ARG (Marker, UINTN);
// }
//
// VA_END (Marker);
// return Result
// }
//
#define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1))
//
// Also support coding convention rules for var arg macros
//
#ifndef VA_START
// typedef CHAR8 *VA_LIST;
// #define VA_START(ap, v) (ap = (VA_LIST) & (v) + _INT_SIZE_OF (v))
// #define VA_ARG(ap, t) (*(t *) ((ap += _INT_SIZE_OF (t)) - _INT_SIZE_OF (t)))
// #define VA_END(ap) (ap = (VA_LIST) 0)
// Use the native arguments for tools.
#define VA_START va_start
#define VA_ARG va_arg
#define VA_END va_end
#define VA_LIST va_list
#endif
///
/// CONTAINING_RECORD - returns a pointer to the structure
/// from one of it's elements.
///
#define _CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
///
/// ALIGN_POINTER - aligns a pointer to the lowest boundry
///
#define ALIGN_POINTER(p, s) ((VOID *) ((p) + (((s) - ((UINTN) (p))) & ((s) - 1))))
///
/// ALIGN_VARIABLE - aligns a variable up to the next natural boundry for int size of a processor
///
#define ALIGN_VARIABLE(Value, Adjustment) \
Adjustment = 0U; \
if ((UINTN) (Value) % sizeof (UINTN)) { \
(Adjustment) = (UINTN)(sizeof (UINTN) - ((UINTN) (Value) % sizeof (UINTN))); \
} \
(Value) = (UINTN)((UINTN) (Value) + (UINTN) (Adjustment))
//
// EFI Error Codes common to all execution phases
//
typedef INTN RETURN_STATUS;
///
/// Set the upper bit to indicate EFI Error.
///
#define ENCODE_ERROR(a) (MAX_BIT | (a))
#define ENCODE_WARNING(a) (a)
#define RETURN_ERROR(a) ((a) < 0)
#define RETURN_SUCCESS 0
#define RETURN_LOAD_ERROR ENCODE_ERROR (1)
#define RETURN_INVALID_PARAMETER ENCODE_ERROR (2)
#define RETURN_UNSUPPORTED ENCODE_ERROR (3)
#define RETURN_BAD_BUFFER_SIZE ENCODE_ERROR (4)
#define RETURN_BUFFER_TOO_SMALL ENCODE_ERROR (5)
#define RETURN_NOT_READY ENCODE_ERROR (6)
#define RETURN_DEVICE_ERROR ENCODE_ERROR (7)
#define RETURN_WRITE_PROTECTED ENCODE_ERROR (8)
#define RETURN_OUT_OF_RESOURCES ENCODE_ERROR (9)
#define RETURN_VOLUME_CORRUPTED ENCODE_ERROR (10)
#define RETURN_VOLUME_FULL ENCODE_ERROR (11)
#define RETURN_NO_MEDIA ENCODE_ERROR (12)
#define RETURN_MEDIA_CHANGED ENCODE_ERROR (13)
#define RETURN_NOT_FOUND ENCODE_ERROR (14)
#define RETURN_ACCESS_DENIED ENCODE_ERROR (15)
#define RETURN_NO_RESPONSE ENCODE_ERROR (16)
#define RETURN_NO_MAPPING ENCODE_ERROR (17)
#define RETURN_TIMEOUT ENCODE_ERROR (18)
#define RETURN_NOT_STARTED ENCODE_ERROR (19)
#define RETURN_ALREADY_STARTED ENCODE_ERROR (20)
#define RETURN_ABORTED ENCODE_ERROR (21)
#define RETURN_ICMP_ERROR ENCODE_ERROR (22)
#define RETURN_TFTP_ERROR ENCODE_ERROR (23)
#define RETURN_PROTOCOL_ERROR ENCODE_ERROR (24)
#define RETURN_INCOMPATIBLE_VERSION ENCODE_ERROR (25)
#define RETURN_SECURITY_VIOLATION ENCODE_ERROR (26)
#define RETURN_CRC_ERROR ENCODE_ERROR (27)
#define RETURN_END_OF_MEDIA ENCODE_ERROR (28)
#define RETURN_END_OF_FILE ENCODE_ERROR (31)
#define RETURN_WARN_UNKNOWN_GLYPH ENCODE_WARNING (1)
#define RETURN_WARN_DELETE_FAILURE ENCODE_WARNING (2)
#define RETURN_WARN_WRITE_FAILURE ENCODE_WARNING (3)
#define RETURN_WARN_BUFFER_TOO_SMALL ENCODE_WARNING (4)
typedef UINT64 PHYSICAL_ADDRESS;
#endif

View File

@ -0,0 +1,67 @@
/** @file
Defines for the EFI Capsule functionality.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: Capsule.h
@par Revision Reference:
These definitions are from Capsule Spec Version 0.9.
**/
#ifndef _EFI_CAPSULE_H_
#define _EFI_CAPSULE_H_
//
// Bits in the flags field of the capsule header
//
#define EFI_CAPSULE_HEADER_FLAG_SETUP 0x00000001 // supports setup changes
#define CAPSULE_BLOCK_DESCRIPTOR_SIGNATURE EFI_SIGNATURE_32 ('C', 'B', 'D', 'S')
//
// An array of these describe the blocks that make up a capsule for
// a capsule update.
//
typedef struct {
UINT64 Length; // length of the data block
EFI_PHYSICAL_ADDRESS Data; // physical address of the data block
UINT32 Signature; // CBDS
UINT32 CheckSum; // to sum this structure to 0
} EFI_CAPSULE_BLOCK_DESCRIPTOR;
typedef struct {
EFI_GUID OemGuid;
UINT32 HeaderSize;
//
// UINT8 OemHdrData[];
//
} EFI_CAPSULE_OEM_HEADER;
typedef struct {
EFI_GUID CapsuleGuid;
UINT32 HeaderSize;
UINT32 Flags;
UINT32 CapsuleImageSize;
UINT32 SequenceNumber;
EFI_GUID InstanceId;
UINT32 OffsetToSplitInformation;
UINT32 OffsetToCapsuleBody;
UINT32 OffsetToOemDefinedHeader;
UINT32 OffsetToAuthorInformation;
UINT32 OffsetToRevisionInformation;
UINT32 OffsetToShortDescription;
UINT32 OffsetToLongDescription;
UINT32 OffsetToApplicableDevices;
} EFI_CAPSULE_HEADER;
#endif // #ifndef _EFI_CAPSULE_H_

View File

@ -0,0 +1,50 @@
/** @file
This module contains data specific to dependency expressions
and local function prototypes.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: Dependency.h
**/
#ifndef __DEPENDENCY_H__
#define __DEPENDENCY_H__
/// EFI_DEP_BEFORE - If present, this must be the first and only opcode
#define EFI_DEP_BEFORE 0x00
/// EFI_DEP_AFTER - If present, this must be the first and only opcode
#define EFI_DEP_AFTER 0x01
#define EFI_DEP_PUSH 0x02
#define EFI_DEP_AND 0x03
#define EFI_DEP_OR 0x04
#define EFI_DEP_NOT 0x05
#define EFI_DEP_TRUE 0x06
#define EFI_DEP_FALSE 0x07
#define EFI_DEP_END 0x08
/// EFI_DEP_SOR - If present, this must be the first opcode
#define EFI_DEP_SOR 0x09
///
/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependecy expression
/// to save time. A EFI_DEP_PUSH is evauated one an
/// replaced with EFI_DEP_REPLACE_TRUE
///
#define EFI_DEP_REPLACE_TRUE 0xff
///
/// Define the initial size of the dependency expression evaluation stack
///
#define DEPEX_STACK_SIZE_INCREMENT 0x1000
#endif

View File

@ -0,0 +1,716 @@
/** @file
EFI image format for PE32+. Please note some data structures are different
for IA-32 and Itanium-based images, look for UINTN and the #ifdef EFI_IA64
@bug Fix text - doc as defined in MSFT EFI specification.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: EfiImage.h
**/
#ifndef __EFI_IMAGE_H__
#define __EFI_IMAGE_H__
//
// PE32+ Subsystem type for EFI images
//
#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
//
// BugBug: Need to get a real answer for this problem. This is not in the
// PE specification.
//
// A SAL runtime driver does not get fixed up when a transition to
// virtual mode is made. In all other cases it should be treated
// like a EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER image
//
#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
//
// PE32+ Machine type for EFI images
//
#define IMAGE_FILE_MACHINE_I386 0x014c
#define IMAGE_FILE_MACHINE_IA64 0x0200
#define IMAGE_FILE_MACHINE_EBC 0x0EBC
#define IMAGE_FILE_MACHINE_X64 0x8664
//
// Support old names for backward compatible
//
#define EFI_IMAGE_MACHINE_IA32 IMAGE_FILE_MACHINE_I386
#define EFI_IMAGE_MACHINE_IA64 IMAGE_FILE_MACHINE_IA64
#define EFI_IMAGE_MACHINE_IPF IMAGE_FILE_MACHINE_IA64
#define EFI_IMAGE_MACHINE_EBC IMAGE_FILE_MACHINE_EBC
#define EFI_IMAGE_MACHINE_X64 IMAGE_FILE_MACHINE_X64
#define EFI_IMAGE_DOS_SIGNATURE 0x5A4D // MZ
#define EFI_IMAGE_OS2_SIGNATURE 0x454E // NE
#define EFI_IMAGE_OS2_SIGNATURE_LE 0x454C // LE
#define EFI_IMAGE_NT_SIGNATURE 0x00004550 // PE00
#define EFI_IMAGE_EDOS_SIGNATURE 0x44454550 // PEED
///
/// PE images can start with an optional DOS header, so if an image is run
/// under DOS it can print an error message.
///
typedef struct {
UINT16 e_magic; // Magic number
UINT16 e_cblp; // Bytes on last page of file
UINT16 e_cp; // Pages in file
UINT16 e_crlc; // Relocations
UINT16 e_cparhdr; // Size of header in paragraphs
UINT16 e_minalloc; // Minimum extra paragraphs needed
UINT16 e_maxalloc; // Maximum extra paragraphs needed
UINT16 e_ss; // Initial (relative) SS value
UINT16 e_sp; // Initial SP value
UINT16 e_csum; // Checksum
UINT16 e_ip; // Initial IP value
UINT16 e_cs; // Initial (relative) CS value
UINT16 e_lfarlc; // File address of relocation table
UINT16 e_ovno; // Overlay number
UINT16 e_res[4]; // Reserved words
UINT16 e_oemid; // OEM identifier (for e_oeminfo)
UINT16 e_oeminfo; // OEM information; e_oemid specific
UINT16 e_res2[10]; // Reserved words
UINT32 e_lfanew; // File address of new exe header
} EFI_IMAGE_DOS_HEADER;
///
/// File header format.
///
typedef struct {
UINT16 Machine;
UINT16 NumberOfSections;
UINT32 TimeDateStamp;
UINT32 PointerToSymbolTable;
UINT32 NumberOfSymbols;
UINT16 SizeOfOptionalHeader;
UINT16 Characteristics;
} EFI_IMAGE_FILE_HEADER;
#define EFI_IMAGE_SIZEOF_FILE_HEADER 20
#define EFI_IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
#define EFI_IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
#define EFI_IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
#define EFI_IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
#define EFI_IMAGE_FILE_SYSTEM 0x1000 // System File.
#define EFI_IMAGE_FILE_DLL 0x2000 // File is a DLL.
#define EFI_IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
#define EFI_IMAGE_FILE_MACHINE_UNKNOWN 0
#define EFI_IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
#define EFI_IMAGE_FILE_MACHINE_R3000 0x162 // MIPS* little-endian, 0540 big-endian
#define EFI_IMAGE_FILE_MACHINE_R4000 0x166 // MIPS* little-endian
#define EFI_IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP*
#define EFI_IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM* PowerPC Little-Endian
#define EFI_IMAGE_FILE_MACHINE_TAHOE 0x7cc // Intel EM machine
//
// * Other names and brands may be claimed as the property of others.
//
///
/// Directory format.
///
typedef struct {
UINT32 VirtualAddress;
UINT32 Size;
} EFI_IMAGE_DATA_DIRECTORY;
#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
typedef struct {
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
UINT32 BaseOfData;
UINT32 BaseOfBss;
UINT32 GprMask;
UINT32 CprMask[4];
UINT32 GpValue;
} EFI_IMAGE_ROM_OPTIONAL_HEADER;
#define EFI_IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
#define EFI_IMAGE_SIZEOF_ROM_OPTIONAL_HEADER sizeof (EFI_IMAGE_ROM_OPTIONAL_HEADER)
typedef struct {
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
} EFI_IMAGE_ROM_HEADERS;
///
/// @attention
/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64
/// are for use ONLY by tools. All proper EFI code MUST use
/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!
///
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
typedef struct {
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
UINT32 BaseOfData;
//
// NT additional fields.
//
UINT32 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT32 SizeOfStackReserve;
UINT32 SizeOfStackCommit;
UINT32 SizeOfHeapReserve;
UINT32 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
} EFI_IMAGE_OPTIONAL_HEADER32;
///
/// @attention
/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64
/// are for use ONLY by tools. All proper EFI code MUST use
/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!
///
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
typedef struct {
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
//
// NT additional fields.
//
UINT64 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT64 SizeOfStackReserve;
UINT64 SizeOfStackCommit;
UINT64 SizeOfHeapReserve;
UINT64 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
} EFI_IMAGE_OPTIONAL_HEADER64;
///
/// @attention
/// EFI_IMAGE_NT_HEADERS32 and EFI_IMAGE_HEADERS64 are for use ONLY
/// by tools. All proper EFI code MUST use EFI_IMAGE_NT_HEADERS ONLY!!!
///
typedef struct {
UINT32 Signature;
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;
} EFI_IMAGE_NT_HEADERS32;
#define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)
typedef struct {
UINT32 Signature;
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;
} EFI_IMAGE_NT_HEADERS64;
#define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)
//
// Processor specific definition of EFI_IMAGE_OPTIONAL_HEADER so the
// type name EFI_IMAGE_OPTIONAL_HEADER is appropriate to the build. Same for
// EFI_IMAGE_NT_HEADERS. These definitions MUST be used by ALL EFI code.
//
#if defined (MDE_CPU_IA32)
typedef EFI_IMAGE_OPTIONAL_HEADER32 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS32 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
(((Machine) == EFI_IMAGE_MACHINE_IA32) || ((Machine) == EFI_IMAGE_MACHINE_EBC))
#elif defined (MDE_CPU_IPF)
typedef EFI_IMAGE_OPTIONAL_HEADER64 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS64 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
(((Machine) == EFI_IMAGE_MACHINE_IPF) || ((Machine) == EFI_IMAGE_MACHINE_EBC))
#elif defined (MDE_CPU_X64)
typedef EFI_IMAGE_OPTIONAL_HEADER64 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS64 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
(((Machine) == EFI_IMAGE_MACHINE_X64) || ((Machine) == EFI_IMAGE_MACHINE_EBC))
#elif defined (MDE_CPU_EBC)
//
// This is just to make sure you can cross compile with the EBC compiiler.
// It does not make sense to have a PE loader coded in EBC. You need to
// understand the basic
//
typedef EFI_IMAGE_OPTIONAL_HEADER64 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS64 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) ((Machine) == EFI_IMAGE_MACHINE_EBC)
#else
#error Unknown Processor Type
#endif
#define EFI_IMAGE_FIRST_SECTION(ntheader) \
( \
(EFI_IMAGE_SECTION_HEADER *) \
( \
(UINT32) ntheader + \
FIELD_OFFSET (EFI_IMAGE_NT_HEADERS, OptionalHeader) + \
((EFI_IMAGE_NT_HEADERS *) (ntheader))->FileHeader.SizeOfOptionalHeader \
) \
)
//
// Subsystem Values
//
#define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0
#define EFI_IMAGE_SUBSYSTEM_NATIVE 1
#define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
#define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3.
#define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5
#define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7
//
// Directory Entries
//
#define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
#define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
#define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
#define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
#define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
#define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
#define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
#define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
#define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
//
// Section header format.
//
#define EFI_IMAGE_SIZEOF_SHORT_NAME 8
typedef struct {
UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];
union {
UINT32 PhysicalAddress;
UINT32 VirtualSize;
} Misc;
UINT32 VirtualAddress;
UINT32 SizeOfRawData;
UINT32 PointerToRawData;
UINT32 PointerToRelocations;
UINT32 PointerToLinenumbers;
UINT16 NumberOfRelocations;
UINT16 NumberOfLinenumbers;
UINT32 Characteristics;
} EFI_IMAGE_SECTION_HEADER;
#define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
#define EFI_IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
#define EFI_IMAGE_SCN_CNT_CODE 0x00000020
#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
#define EFI_IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
#define EFI_IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
#define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
#define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000
#define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000
#define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000
#define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000
#define EFI_IMAGE_SCN_ALIGN_8BYTES 0x00400000
#define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000
#define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000
#define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000
#define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000
#define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000
#define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000
#define EFI_IMAGE_SCN_MEM_SHARED 0x10000000
#define EFI_IMAGE_SCN_MEM_EXECUTE 0x20000000
#define EFI_IMAGE_SCN_MEM_READ 0x40000000
#define EFI_IMAGE_SCN_MEM_WRITE 0x80000000
///
/// Symbol format.
///
#define EFI_IMAGE_SIZEOF_SYMBOL 18
//
// Section values.
//
// Symbols have a section number of the section in which they are
// defined. Otherwise, section numbers have the following meanings:
//
#define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 // Symbol is undefined or is common.
#define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 // Symbol is an absolute value.
#define EFI_IMAGE_SYM_DEBUG (UINT16) -2 // Symbol is a special debug item.
//
// Type (fundamental) values.
//
#define EFI_IMAGE_SYM_TYPE_NULL 0 // no type.
#define EFI_IMAGE_SYM_TYPE_VOID 1 //
#define EFI_IMAGE_SYM_TYPE_CHAR 2 // type character.
#define EFI_IMAGE_SYM_TYPE_SHORT 3 // type short integer.
#define EFI_IMAGE_SYM_TYPE_INT 4
#define EFI_IMAGE_SYM_TYPE_LONG 5
#define EFI_IMAGE_SYM_TYPE_FLOAT 6
#define EFI_IMAGE_SYM_TYPE_DOUBLE 7
#define EFI_IMAGE_SYM_TYPE_STRUCT 8
#define EFI_IMAGE_SYM_TYPE_UNION 9
#define EFI_IMAGE_SYM_TYPE_ENUM 10 // enumeration.
#define EFI_IMAGE_SYM_TYPE_MOE 11 // member of enumeration.
#define EFI_IMAGE_SYM_TYPE_BYTE 12
#define EFI_IMAGE_SYM_TYPE_WORD 13
#define EFI_IMAGE_SYM_TYPE_UINT 14
#define EFI_IMAGE_SYM_TYPE_DWORD 15
//
// Type (derived) values.
//
#define EFI_IMAGE_SYM_DTYPE_NULL 0 // no derived type.
#define EFI_IMAGE_SYM_DTYPE_POINTER 1
#define EFI_IMAGE_SYM_DTYPE_FUNCTION 2
#define EFI_IMAGE_SYM_DTYPE_ARRAY 3
//
// Storage classes.
//
#define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION (UINT8) -1
#define EFI_IMAGE_SYM_CLASS_NULL 0
#define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1
#define EFI_IMAGE_SYM_CLASS_EXTERNAL 2
#define EFI_IMAGE_SYM_CLASS_STATIC 3
#define EFI_IMAGE_SYM_CLASS_REGISTER 4
#define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5
#define EFI_IMAGE_SYM_CLASS_LABEL 6
#define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
#define EFI_IMAGE_SYM_CLASS_ARGUMENT 9
#define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10
#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
#define EFI_IMAGE_SYM_CLASS_UNION_TAG 12
#define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13
#define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
#define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15
#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
#define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17
#define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18
#define EFI_IMAGE_SYM_CLASS_BLOCK 100
#define EFI_IMAGE_SYM_CLASS_FUNCTION 101
#define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102
#define EFI_IMAGE_SYM_CLASS_FILE 103
#define EFI_IMAGE_SYM_CLASS_SECTION 104
#define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
//
// type packing constants
//
#define EFI_IMAGE_N_BTMASK 017
#define EFI_IMAGE_N_TMASK 060
#define EFI_IMAGE_N_TMASK1 0300
#define EFI_IMAGE_N_TMASK2 0360
#define EFI_IMAGE_N_BTSHFT 4
#define EFI_IMAGE_N_TSHIFT 2
//
// Communal selection types.
//
#define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1
#define EFI_IMAGE_COMDAT_SELECT_ANY 2
#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
#define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
#define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
#define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
///
/// Relocation format.
///
typedef struct {
UINT32 VirtualAddress;
UINT32 SymbolTableIndex;
UINT16 Type;
} EFI_IMAGE_RELOCATION;
#define EFI_IMAGE_SIZEOF_RELOCATION 10
//
// I386 relocation types.
//
#define EFI_IMAGE_REL_I386_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
#define EFI_IMAGE_REL_I386_DIR16 01 // Direct 16-bit reference to the symbols virtual address
#define EFI_IMAGE_REL_I386_REL16 02 // PC-relative 16-bit reference to the symbols virtual address
#define EFI_IMAGE_REL_I386_DIR32 06 // Direct 32-bit reference to the symbols virtual address
#define EFI_IMAGE_REL_I386_DIR32NB 07 // Direct 32-bit reference to the symbols virtual address, base not included
#define EFI_IMAGE_REL_I386_SEG12 011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
#define EFI_IMAGE_REL_I386_SECTION 012
#define EFI_IMAGE_REL_I386_SECREL 013
#define EFI_IMAGE_REL_I386_REL32 024 // PC-relative 32-bit reference to the symbols virtual address
///
/// Based relocation format.
///
typedef struct {
UINT32 VirtualAddress;
UINT32 SizeOfBlock;
} EFI_IMAGE_BASE_RELOCATION;
#define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8
//
// Based relocation types.
//
#define EFI_IMAGE_REL_BASED_ABSOLUTE 0
#define EFI_IMAGE_REL_BASED_HIGH 1
#define EFI_IMAGE_REL_BASED_LOW 2
#define EFI_IMAGE_REL_BASED_HIGHLOW 3
#define EFI_IMAGE_REL_BASED_HIGHADJ 4
#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
#define EFI_IMAGE_REL_BASED_IA64_IMM64 9
#define EFI_IMAGE_REL_BASED_DIR64 10
///
/// Line number format.
///
typedef struct {
union {
UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
UINT32 VirtualAddress; // Virtual address of line number.
} Type;
UINT16 Linenumber; // Line number.
} EFI_IMAGE_LINENUMBER;
#define EFI_IMAGE_SIZEOF_LINENUMBER 6
//
// Archive format.
//
#define EFI_IMAGE_ARCHIVE_START_SIZE 8
#define EFI_IMAGE_ARCHIVE_START "!<arch>\n"
#define EFI_IMAGE_ARCHIVE_END "`\n"
#define EFI_IMAGE_ARCHIVE_PAD "\n"
#define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ "
#define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
typedef struct {
UINT8 Name[16]; // File member name - `/' terminated.
UINT8 Date[12]; // File member date - decimal.
UINT8 UserID[6]; // File member user id - decimal.
UINT8 GroupID[6]; // File member group id - decimal.
UINT8 Mode[8]; // File member mode - octal.
UINT8 Size[10]; // File member size - decimal.
UINT8 EndHeader[2]; // String to end header.
} EFI_IMAGE_ARCHIVE_MEMBER_HEADER;
#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
//
// DLL support.
//
///
/// DLL Export Format
///
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Name;
UINT32 Base;
UINT32 NumberOfFunctions;
UINT32 NumberOfNames;
UINT32 AddressOfFunctions;
UINT32 AddressOfNames;
UINT32 AddressOfNameOrdinals;
} EFI_IMAGE_EXPORT_DIRECTORY;
///
/// DLL support.
/// Import Format
///
typedef struct {
UINT16 Hint;
UINT8 Name[1];
} EFI_IMAGE_IMPORT_BY_NAME;
typedef struct {
union {
UINT32 Function;
UINT32 Ordinal;
EFI_IMAGE_IMPORT_BY_NAME *AddressOfData;
} u1;
} EFI_IMAGE_THUNK_DATA;
#define EFI_IMAGE_ORDINAL_FLAG 0x80000000
#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)
#define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT32 ForwarderChain;
UINT32 Name;
EFI_IMAGE_THUNK_DATA *FirstThunk;
} EFI_IMAGE_IMPORT_DESCRIPTOR;
///
/// Debug Format
///
#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Type;
UINT32 SizeOfData;
UINT32 RVA;
UINT32 FileOffset;
} EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;
#define CODEVIEW_SIGNATURE_NB10 0x3031424E // "NB10"
typedef struct {
UINT32 Signature; // "NB10"
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
//
// Filename of .PDB goes here
//
} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;
#define CODEVIEW_SIGNATURE_RSDS 0x53445352 // "RSDS"
typedef struct {
UINT32 Signature; // "RSDS"
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
UINT32 Unknown4;
UINT32 Unknown5;
//
// Filename of .PDB goes here
//
} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
//
// .pdata entries for X64
//
typedef struct {
UINT32 FunctionStartAddress;
UINT32 FunctionEndAddress;
UINT32 UnwindInfoAddress;
} RUNTIME_FUNCTION;
typedef struct {
UINT8 Version:3;
UINT8 Flags:5;
UINT8 SizeOfProlog;
UINT8 CountOfUnwindCodes;
UINT8 FrameRegister:4;
UINT8 FrameRegisterOffset:4;
} UNWIND_INFO;
///
/// Header format for TE images
///
typedef struct {
UINT16 Signature; // signature for TE format = "VZ"
UINT16 Machine; // from the original file header
UINT8 NumberOfSections; // from the original file header
UINT8 Subsystem; // from original optional header
UINT16 StrippedSize; // how many bytes we removed from the header
UINT32 AddressOfEntryPoint; // offset to entry point -- from original optional header
UINT32 BaseOfCode; // from original image -- required for ITP debug
UINT64 ImageBase; // from original file header
EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // only base relocation and debug directory
} EFI_TE_IMAGE_HEADER;
#define EFI_TE_IMAGE_HEADER_SIGNATURE 0x5A56 // "VZ"
//
// Data directory indexes in our TE image header
//
#define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
#define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
#endif

View File

@ -0,0 +1,98 @@
/** @file
This file defines the data structures that comprise the FFS file system.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: FirmwareFileSystem.h
@par Revision Reference:
These definitions are from Firmware File System Spec 0.9.
**/
#ifndef __EFI_FFS_FILE_SYSTEM_H__
#define __EFI_FFS_FILE_SYSTEM_H__
///
/// FFS specific file types
///
#define EFI_FV_FILETYPE_FFS_PAD 0xF0
//
// FFS File Attributes
//
#define FFS_ATTRIB_TAIL_PRESENT 0x01
#define FFS_ATTRIB_RECOVERY 0x02
#define FFS_ATTRIB_HEADER_EXTENSION 0x04
#define FFS_ATTRIB_DATA_ALIGNMENT 0x38
#define FFS_ATTRIB_CHECKSUM 0x40
///
/// FFS_FIXED_CHECKSUM is the default checksum value used when the
/// FFS_ATTRIB_CHECKSUM attribute bit is clear
/// note this is NOT an architecturally defined value, but is in this file for
/// implementation convenience
///
#define FFS_FIXED_CHECKSUM 0x5A
//
// File state definitions
//
#define EFI_FILE_HEADER_CONSTRUCTION 0x01
#define EFI_FILE_HEADER_VALID 0x02
#define EFI_FILE_DATA_VALID 0x04
#define EFI_FILE_MARKED_FOR_UPDATE 0x08
#define EFI_FILE_DELETED 0x10
#define EFI_FILE_HEADER_INVALID 0x20
#define EFI_FILE_ALL_STATE_BITS (EFI_FILE_HEADER_CONSTRUCTION | \
EFI_FILE_HEADER_VALID | \
EFI_FILE_DATA_VALID | \
EFI_FILE_MARKED_FOR_UPDATE | \
EFI_FILE_DELETED | \
EFI_FILE_HEADER_INVALID \
)
#define EFI_TEST_FFS_ATTRIBUTES_BIT(FvbAttributes, TestAttributes, Bit) \
( \
(BOOLEAN) ( \
(FvbAttributes & EFI_FVB_ERASE_POLARITY) ? (((~TestAttributes) & Bit) == Bit) : ((TestAttributes & Bit) == Bit) \
) \
)
typedef UINT16 EFI_FFS_FILE_TAIL;
///
/// FFS file integrity check structure
///
typedef union {
struct {
UINT8 Header;
UINT8 File;
} Checksum;
UINT16 TailReference;
} EFI_FFS_INTEGRITY_CHECK;
//
// FFS file header definition
//
typedef UINT8 EFI_FFS_FILE_ATTRIBUTES;
typedef UINT8 EFI_FFS_FILE_STATE;
typedef struct {
EFI_GUID Name;
EFI_FFS_INTEGRITY_CHECK IntegrityCheck;
EFI_FV_FILETYPE Type;
EFI_FFS_FILE_ATTRIBUTES Attributes;
UINT8 Size[3];
EFI_FFS_FILE_STATE State;
} EFI_FFS_FILE_HEADER;
#endif

View File

@ -0,0 +1,109 @@
/** @file
Defines data structure that is the volume header found at the beginning of
all firmware volumes that are either memory mapped, or have an
associated FirmwareVolumeBlock protocol.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: FirmwareVolumeHeader.h
@par Revision Reference:
These definitions are from Firmware Volume Block Spec 0.9.
**/
#ifndef __EFI_FIRMWARE_VOLUME_HEADER_H__
#define __EFI_FIRMWARE_VOLUME_HEADER_H__
//
// Firmware Volume Block Attributes definition
//
typedef UINT32 EFI_FVB_ATTRIBUTES;
//
// Firmware Volume Block Attributes bit definitions
//
#define EFI_FVB_READ_DISABLED_CAP 0x00000001
#define EFI_FVB_READ_ENABLED_CAP 0x00000002
#define EFI_FVB_READ_STATUS 0x00000004
#define EFI_FVB_WRITE_DISABLED_CAP 0x00000008
#define EFI_FVB_WRITE_ENABLED_CAP 0x00000010
#define EFI_FVB_WRITE_STATUS 0x00000020
#define EFI_FVB_LOCK_CAP 0x00000040
#define EFI_FVB_LOCK_STATUS 0x00000080
#define EFI_FVB_STICKY_WRITE 0x00000200
#define EFI_FVB_MEMORY_MAPPED 0x00000400
#define EFI_FVB_ERASE_POLARITY 0x00000800
#define EFI_FVB_ALIGNMENT_CAP 0x00008000
#define EFI_FVB_ALIGNMENT_2 0x00010000
#define EFI_FVB_ALIGNMENT_4 0x00020000
#define EFI_FVB_ALIGNMENT_8 0x00040000
#define EFI_FVB_ALIGNMENT_16 0x00080000
#define EFI_FVB_ALIGNMENT_32 0x00100000
#define EFI_FVB_ALIGNMENT_64 0x00200000
#define EFI_FVB_ALIGNMENT_128 0x00400000
#define EFI_FVB_ALIGNMENT_256 0x00800000
#define EFI_FVB_ALIGNMENT_512 0x01000000
#define EFI_FVB_ALIGNMENT_1K 0x02000000
#define EFI_FVB_ALIGNMENT_2K 0x04000000
#define EFI_FVB_ALIGNMENT_4K 0x08000000
#define EFI_FVB_ALIGNMENT_8K 0x10000000
#define EFI_FVB_ALIGNMENT_16K 0x20000000
#define EFI_FVB_ALIGNMENT_32K 0x40000000
#define EFI_FVB_ALIGNMENT_64K 0x80000000
#define EFI_FVB_CAPABILITIES (EFI_FVB_READ_DISABLED_CAP | \
EFI_FVB_READ_ENABLED_CAP | \
EFI_FVB_WRITE_DISABLED_CAP | \
EFI_FVB_WRITE_ENABLED_CAP | \
EFI_FVB_LOCK_CAP \
)
#define EFI_FVB_STATUS (EFI_FVB_READ_STATUS | EFI_FVB_WRITE_STATUS | EFI_FVB_LOCK_STATUS)
///
/// Firmware Volume Header Revision definition
///
#define EFI_FVH_REVISION 0x01
///
/// Firmware Volume Header Signature definition
///
#define EFI_FVH_SIGNATURE EFI_SIGNATURE_32 ('_', 'F', 'V', 'H')
///
/// Firmware Volume Header Block Map Entry definition
///
typedef struct {
UINT32 NumBlocks;
UINT32 BlockLength;
} EFI_FV_BLOCK_MAP_ENTRY;
///
/// Firmware Volume Header definition
///
typedef struct {
UINT8 ZeroVector[16];
EFI_GUID FileSystemGuid;
UINT64 FvLength;
UINT32 Signature;
EFI_FVB_ATTRIBUTES Attributes;
UINT16 HeaderLength;
UINT16 Checksum;
UINT8 Reserved[3];
UINT8 Revision;
EFI_FV_BLOCK_MAP_ENTRY FvBlockMap[1];
} EFI_FIRMWARE_VOLUME_HEADER;
#endif

View File

@ -0,0 +1,277 @@
/** @file
This file defines the data structures that are architecturally defined for file
images loaded via the FirmwareVolume protocol. The Firmware Volume specification
is the basis for these definitions.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: FimrwareVolumeImageFormat.h
@par Revision Reference:
These definitions are from Firmware Volume Spec 0.9.
**/
#ifndef __FIRMWARE_VOLUME_IMAGE_FORMAT_H__
#define __FIRMWARE_VOLUME_IMAGE_FORMAT_H__
//
// pack all data structures since this is actually a binary format and we cannot
// allow internal padding in the data structures because of some compilerism..
//
#pragma pack(1)
//
// ////////////////////////////////////////////////////////////////////////////
//
// Architectural file types
//
typedef UINT8 EFI_FV_FILETYPE;
#define EFI_FV_FILETYPE_ALL 0x00
#define EFI_FV_FILETYPE_RAW 0x01
#define EFI_FV_FILETYPE_FREEFORM 0x02
#define EFI_FV_FILETYPE_SECURITY_CORE 0x03
#define EFI_FV_FILETYPE_PEI_CORE 0x04
#define EFI_FV_FILETYPE_DXE_CORE 0x05
#define EFI_FV_FILETYPE_PEIM 0x06
#define EFI_FV_FILETYPE_DRIVER 0x07
#define EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER 0x08
#define EFI_FV_FILETYPE_APPLICATION 0x09
//
// File type 0x0A is reserved and should not be used
//
#define EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE 0x0B
//
// ////////////////////////////////////////////////////////////////////////////
//
// Section types
//
typedef UINT8 EFI_SECTION_TYPE;
//
// ************************************************************
// The section type EFI_SECTION_ALL is a psuedo type. It is
// used as a wildcard when retrieving sections. The section
// type EFI_SECTION_ALL matches all section types.
// ************************************************************
//
#define EFI_SECTION_ALL 0x00
//
// ************************************************************
// Encapsulation section Type values
// ************************************************************
//
#define EFI_SECTION_COMPRESSION 0x01
#define EFI_SECTION_GUID_DEFINED 0x02
//
// ************************************************************
// Leaf section Type values
// ************************************************************
//
#define EFI_SECTION_FIRST_LEAF_SECTION_TYPE 0x10
#define EFI_SECTION_PE32 0x10
#define EFI_SECTION_PIC 0x11
#define EFI_SECTION_TE 0x12
#define EFI_SECTION_DXE_DEPEX 0x13
#define EFI_SECTION_VERSION 0x14
#define EFI_SECTION_USER_INTERFACE 0x15
#define EFI_SECTION_COMPATIBILITY16 0x16
#define EFI_SECTION_FIRMWARE_VOLUME_IMAGE 0x17
#define EFI_SECTION_FREEFORM_SUBTYPE_GUID 0x18
#define EFI_SECTION_RAW 0x19
#define EFI_SECTION_PEI_DEPEX 0x1B
#define EFI_SECTION_LAST_LEAF_SECTION_TYPE 0x1B
#define EFI_SECTION_LAST_SECTION_TYPE 0x1B
//
// ////////////////////////////////////////////////////////////////////////////
//
// Common section header
//
typedef struct {
UINT8 Size[3];
UINT8 Type;
} EFI_COMMON_SECTION_HEADER;
#define SECTION_SIZE(SectionHeaderPtr) \
((UINT32) (*((UINT32 *) ((EFI_COMMON_SECTION_HEADER *) SectionHeaderPtr)->Size) & 0x00ffffff))
//
// ////////////////////////////////////////////////////////////////////////////
//
// Compression section
//
//
// CompressionType values
//
#define EFI_NOT_COMPRESSED 0x00
#define EFI_STANDARD_COMPRESSION 0x01
#define EFI_CUSTOMIZED_COMPRESSION 0x02
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
UINT32 UncompressedLength;
UINT8 CompressionType;
} EFI_COMPRESSION_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// GUID defined section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
EFI_GUID SectionDefinitionGuid;
UINT16 DataOffset;
UINT16 Attributes;
} EFI_GUID_DEFINED_SECTION;
//
// Bit values for Attributes
//
#define EFI_GUIDED_SECTION_PROCESSING_REQUIRED 0x01
#define EFI_GUIDED_SECTION_AUTH_STATUS_VALID 0x02
//
// Bit values for AuthenticationStatus
//
#define EFI_AGGREGATE_AUTH_STATUS_PLATFORM_OVERRIDE 0x000001
#define EFI_AGGREGATE_AUTH_STATUS_IMAGE_SIGNED 0x000002
#define EFI_AGGREGATE_AUTH_STATUS_NOT_TESTED 0x000004
#define EFI_AGGREGATE_AUTH_STATUS_TEST_FAILED 0x000008
#define EFI_AGGREGATE_AUTH_STATUS_ALL 0x00000f
#define EFI_LOCAL_AUTH_STATUS_PLATFORM_OVERRIDE 0x010000
#define EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED 0x020000
#define EFI_LOCAL_AUTH_STATUS_NOT_TESTED 0x040000
#define EFI_LOCAL_AUTH_STATUS_TEST_FAILED 0x080000
#define EFI_LOCAL_AUTH_STATUS_ALL 0x0f0000
//
// ////////////////////////////////////////////////////////////////////////////
//
// PE32+ section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
} EFI_PE32_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// PIC section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
} EFI_PIC_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// PEIM header section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
} EFI_PEIM_HEADER_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// DEPEX section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
} EFI_DEPEX_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// Version section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
UINT16 BuildNumber;
INT16 VersionString[1];
} EFI_VERSION_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// User interface section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
INT16 FileNameString[1];
} EFI_USER_INTERFACE_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// Code16 section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
} EFI_CODE16_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// Firmware Volume Image section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
} EFI_FIRMWARE_VOLUME_IMAGE_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// Freeform subtype GUID section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
EFI_GUID SubTypeGuid;
} EFI_FREEFORM_SUBTYPE_GUID_SECTION;
//
// ////////////////////////////////////////////////////////////////////////////
//
// Raw section
//
typedef struct {
EFI_COMMON_SECTION_HEADER CommonHeader;
} EFI_RAW_SECTION;
//
// undo the pragma from the beginning...
//
#pragma pack()
typedef union {
EFI_COMMON_SECTION_HEADER *CommonHeader;
EFI_COMPRESSION_SECTION *CompressionSection;
EFI_GUID_DEFINED_SECTION *GuidDefinedSection;
EFI_PE32_SECTION *Pe32Section;
EFI_PIC_SECTION *PicSection;
EFI_PEIM_HEADER_SECTION *PeimHeaderSection;
EFI_DEPEX_SECTION *DependencySection;
EFI_VERSION_SECTION *VersionSection;
EFI_USER_INTERFACE_SECTION *UISection;
EFI_CODE16_SECTION *Code16Section;
EFI_FIRMWARE_VOLUME_IMAGE_SECTION *FVImageSection;
EFI_FREEFORM_SUBTYPE_GUID_SECTION *FreeformSubtypeSection;
EFI_RAW_SECTION *RawSection;
} EFI_FILE_SECTION_POINTER;
#endif

View File

@ -0,0 +1,422 @@
/** @file
This file defines the encoding for the VFR (Visual Form Representation) language.
IFR is primarily consumed by the EFI presentation engine, and produced by EFI
internal application and drivers as well as all add-in card option-ROM drivers
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: InternalFormRepresentation.h
@par Revision Reference:
These definitions are from Human Interface Infrastructure Spec Version 0.92.
**/
#ifndef __EFI_INTERNAL_FORM_REPRESENTATION_H__
#define __EFI_INTERNAL_FORM_REPRESENTATION_H__
//
// The following types are currently defined:
//
typedef UINT32 RELOFST;
typedef CHAR16 *EFI_STRING;
//
// IFR Op codes
//
#define EFI_IFR_FORM_OP 0x01
#define EFI_IFR_SUBTITLE_OP 0x02
#define EFI_IFR_TEXT_OP 0x03
#define EFI_IFR_GRAPHIC_OP 0x04
#define EFI_IFR_ONE_OF_OP 0x05
#define EFI_IFR_CHECKBOX_OP 0x06
#define EFI_IFR_NUMERIC_OP 0x07
#define EFI_IFR_PASSWORD_OP 0x08
#define EFI_IFR_ONE_OF_OPTION_OP 0x09 // ONEOF OPTION field
#define EFI_IFR_SUPPRESS_IF_OP 0x0A
#define EFI_IFR_END_FORM_OP 0x0B
#define EFI_IFR_HIDDEN_OP 0x0C
#define EFI_IFR_END_FORM_SET_OP 0x0D
#define EFI_IFR_FORM_SET_OP 0x0E
#define EFI_IFR_REF_OP 0x0F
#define EFI_IFR_END_ONE_OF_OP 0x10
#define EFI_IFR_END_OP EFI_IFR_END_ONE_OF_OP
#define EFI_IFR_INCONSISTENT_IF_OP 0x11
#define EFI_IFR_EQ_ID_VAL_OP 0x12
#define EFI_IFR_EQ_ID_ID_OP 0x13
#define EFI_IFR_EQ_ID_LIST_OP 0x14
#define EFI_IFR_AND_OP 0x15
#define EFI_IFR_OR_OP 0x16
#define EFI_IFR_NOT_OP 0x17
#define EFI_IFR_END_IF_OP 0x18 // for endif of inconsistentif, suppressif, grayoutif
#define EFI_IFR_GRAYOUT_IF_OP 0x19
#define EFI_IFR_DATE_OP 0x1A
#define EFI_IFR_TIME_OP 0x1B
#define EFI_IFR_STRING_OP 0x1C
#define EFI_IFR_LABEL_OP 0x1D
#define EFI_IFR_SAVE_DEFAULTS_OP 0x1E
#define EFI_IFR_RESTORE_DEFAULTS_OP 0x1F
#define EFI_IFR_BANNER_OP 0x20
#define EFI_IFR_INVENTORY_OP 0x21
#define EFI_IFR_EQ_VAR_VAL_OP 0x22
#define EFI_IFR_ORDERED_LIST_OP 0x23
#define EFI_IFR_VARSTORE_OP 0x24
#define EFI_IFR_VARSTORE_SELECT_OP 0x25
#define EFI_IFR_VARSTORE_SELECT_PAIR_OP 0x26
#define EFI_IFR_TRUE_OP 0x27
#define EFI_IFR_FALSE_OP 0x28
#define EFI_IFR_GT_OP 0x29
#define EFI_IFR_GE_OP 0x2A
#define EFI_IFR_OEM_DEFINED_OP 0x2B
#define EFI_IFR_LAST_OPCODE EFI_IFR_OEM_DEFINED_OP
#define EFI_IFR_OEM_OP 0xFE
#define EFI_IFR_NV_ACCESS_COMMAND 0xFF
//
// Define values for the flags fields in some VFR opcodes. These are
// bitmasks.
//
#define EFI_IFR_FLAG_DEFAULT 0x01
#define EFI_IFR_FLAG_MANUFACTURING 0x02
#define EFI_IFR_FLAG_INTERACTIVE 0x04
#define EFI_IFR_FLAG_NV_ACCESS 0x08
#define EFI_IFR_FLAG_RESET_REQUIRED 0x10
#define EFI_IFR_FLAG_LATE_CHECK 0x20
#define EFI_NON_DEVICE_CLASS 0x00 // Useful when you do not want something in the Device Manager
#define EFI_DISK_DEVICE_CLASS 0x01
#define EFI_VIDEO_DEVICE_CLASS 0x02
#define EFI_NETWORK_DEVICE_CLASS 0x04
#define EFI_INPUT_DEVICE_CLASS 0x08
#define EFI_ON_BOARD_DEVICE_CLASS 0x10
#define EFI_OTHER_DEVICE_CLASS 0x20
#define EFI_SETUP_APPLICATION_SUBCLASS 0x00
#define EFI_GENERAL_APPLICATION_SUBCLASS 0x01
#define EFI_FRONT_PAGE_SUBCLASS 0x02
#define EFI_SINGLE_USE_SUBCLASS 0x03 // Used to display a single entity and then exit
//
// Used to flag dynamically created op-codes. This is meaningful to the IFR Library set
// and the browser since we need to distinguish between compiled NV map data and created data.
// We do not allow new entries to be created in the NV map dynamically however we still need
// to display this information correctly. To dynamically create op-codes and assume that their
// data will be saved, ensure that the NV starting location they refer to is pre-defined in the
// NV map.
//
#define EFI_IFR_FLAG_CREATED 128
#pragma pack(1)
//
// IFR Structure definitions
//
typedef struct {
UINT8 OpCode;
UINT8 Length;
} EFI_IFR_OP_HEADER;
typedef struct {
EFI_IFR_OP_HEADER Header;
EFI_GUID Guid;
STRING_REF FormSetTitle;
STRING_REF Help;
EFI_PHYSICAL_ADDRESS CallbackHandle;
UINT16 Class;
UINT16 SubClass;
UINT16 NvDataSize; // set once, size of the NV data as defined in the script
} EFI_IFR_FORM_SET;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 FormId;
STRING_REF FormTitle;
} EFI_IFR_FORM;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 LabelId;
} EFI_IFR_LABEL;
typedef struct {
EFI_IFR_OP_HEADER Header;
STRING_REF SubTitle;
} EFI_IFR_SUBTITLE;
typedef struct {
EFI_IFR_OP_HEADER Header;
STRING_REF Help;
STRING_REF Text;
STRING_REF TextTwo;
UINT8 Flags; // This is included solely for purposes of interactive/dynamic support.
UINT16 Key; // Value to be passed to caller to identify this particular op-code
} EFI_IFR_TEXT;
//
// goto
//
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 FormId;
STRING_REF Prompt;
STRING_REF Help; // The string Token for the context-help
UINT8 Flags; // This is included solely for purposes of interactive/dynamic support.
UINT16 Key; // Value to be passed to caller to identify this particular op-code
} EFI_IFR_REF;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_FORM;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_FORM_SET;
//
// Also notice that the IFR_ONE_OF and IFR_CHECK_BOX are identical in structure......code assumes this to be true, if this ever
// changes we need to revisit the InitializeTagStructures code
//
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // The ID designating what the question is about...sucked in from a #define, likely in the form of a variable name
UINT8 Width; // The Size of the Data being saved
STRING_REF Prompt; // The String Token for the Prompt
STRING_REF Help; // The string Token for the context-help
} EFI_IFR_ONE_OF;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // The offset in NV for storage of the data
UINT8 MaxEntries; // The maximum number of options in the ordered list (=size of NVStore)
STRING_REF Prompt; // The string token for the prompt
STRING_REF Help; // The string token for the context-help
} EFI_IFR_ORDERED_LIST;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // The ID designating what the question is about...sucked in from a #define, likely in the form of a variable name
UINT8 Width; // The Size of the Data being saved
STRING_REF Prompt; // The String Token for the Prompt
STRING_REF Help; // The string Token for the context-help
UINT8 Flags; // For now, if non-zero, means that it is the default option, - further definition likely
UINT16 Key; // Value to be passed to caller to identify this particular op-code
} EFI_IFR_CHECKBOX, EFI_IFR_CHECK_BOX;
typedef struct {
EFI_IFR_OP_HEADER Header;
STRING_REF Option; // The string token describing the option
UINT16 Value; // The value associated with this option that is stored in the NVRAM if chosen
UINT8 Flags; // For now, if non-zero, means that it is the default option, - further definition likely above
UINT16 Key; // Value to be passed to caller to identify this particular op-code
} EFI_IFR_ONE_OF_OPTION;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // The ID designating what the question is about...sucked in from a #define, likely in the form of a variable name
UINT8 Width; // The Size of the Data being saved
STRING_REF Prompt; // The String Token for the Prompt
STRING_REF Help; // The string Token for the context-help
UINT8 Flags; // This is included solely for purposes of interactive/dynamic support.
UINT16 Key; // Value to be passed to caller to identify this particular op-code
UINT16 Minimum;
UINT16 Maximum;
UINT16 Step; // If step is 0, then manual input is specified, otherwise, left/right arrow selection is called for
UINT16 Default;
} EFI_IFR_NUMERIC;
//
// There is an interesting twist with regards to Time and Date. This is one of the few items which can accept input from
// a user, however may or may not need to use storage in the NVRAM space. The decided method for determining if NVRAM space
// will be used (only for a TimeOp or DateOp) is: If .QuestionId == 0 && .Width == 0 (normally an impossibility) then use system
// resources to store the data away and not NV resources. In other words, the setup engine will call gRT->SetTime, and gRT->SetDate
// for the saving of data, and the values displayed will be from the gRT->GetXXXX series of calls.
//
typedef struct {
EFI_IFR_NUMERIC Hour;
EFI_IFR_NUMERIC Minute;
EFI_IFR_NUMERIC Second;
} EFI_IFR_TIME;
typedef struct {
EFI_IFR_NUMERIC Year;
EFI_IFR_NUMERIC Month;
EFI_IFR_NUMERIC Day;
} EFI_IFR_DATE;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // The ID designating what the question is about...sucked in from a #define, likely in the form of a variable name
UINT8 Width; // The Size of the Data being saved -- BUGBUG -- remove someday
STRING_REF Prompt; // The String Token for the Prompt
STRING_REF Help; // The string Token for the context-help
UINT8 Flags; // This is included solely for purposes of interactive/dynamic support.
UINT16 Key; // Value to be passed to caller to identify this particular op-code
UINT8 MinSize; // Minimum allowable sized password
UINT8 MaxSize; // Maximum allowable sized password
UINT16 Encoding;
} EFI_IFR_PASSWORD;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // The ID designating what the question is about...sucked in from a #define, likely in the form of a variable name
UINT8 Width; // The Size of the Data being saved -- BUGBUG -- remove someday
STRING_REF Prompt; // The String Token for the Prompt
STRING_REF Help; // The string Token for the context-help
UINT8 Flags; // This is included solely for purposes of interactive/dynamic support.
UINT16 Key; // Value to be passed to caller to identify this particular op-code
UINT8 MinSize; // Minimum allowable sized password
UINT8 MaxSize; // Maximum allowable sized password
} EFI_IFR_STRING;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_ONE_OF;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 Value;
UINT16 Key;
} EFI_IFR_HIDDEN;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT8 Flags;
} EFI_IFR_SUPPRESS;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT8 Flags;
} EFI_IFR_GRAY_OUT;
typedef struct {
EFI_IFR_OP_HEADER Header;
STRING_REF Popup;
UINT8 Flags;
} EFI_IFR_INCONSISTENT;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // offset into variable storage
UINT8 Width; // size of variable storage
UINT16 Value; // value to compare against
} EFI_IFR_EQ_ID_VAL;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; // offset into variable storage
UINT8 Width; // size of variable storage
UINT16 ListLength;
UINT16 ValueList[1];
} EFI_IFR_EQ_ID_LIST;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 QuestionId1; // offset into variable storage for first value to compare
UINT8 Width; // size of variable storage (must be same for both)
UINT16 QuestionId2; // offset into variable storage for second value to compare
} EFI_IFR_EQ_ID_ID;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 VariableId; // offset into variable storage
UINT16 Value; // value to compare against
} EFI_IFR_EQ_VAR_VAL;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_AND;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_OR;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_NOT;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_EXPR, EFI_IFR_END_IF;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 FormId;
STRING_REF Prompt;
STRING_REF Help;
UINT8 Flags;
UINT16 Key;
} EFI_IFR_SAVE_DEFAULTS;
typedef struct {
EFI_IFR_OP_HEADER Header;
STRING_REF Help;
STRING_REF Text;
STRING_REF TextTwo; // optional text
} EFI_IFR_INVENTORY;
typedef struct {
EFI_IFR_OP_HEADER Header;
EFI_GUID Guid; // GUID for the variable
UINT16 VarId; // variable store ID, as referenced elsewhere in the form
UINT16 Size; // size of the variable storage
} EFI_IFR_VARSTORE;
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 VarId; // variable store ID, as referenced elsewhere in the form
} EFI_IFR_VARSTORE_SELECT;
//
// Used for the ideqid VFR statement where two variable stores may be referenced in the
// same VFR statement.
// A browser should treat this as an EFI_IFR_VARSTORE_SELECT statement and assume that all following
// IFR opcodes use the VarId as defined here.
//
typedef struct {
EFI_IFR_OP_HEADER Header;
UINT16 VarId; // variable store ID, as referenced elsewhere in the form
UINT16 SecondaryVarId; // variable store ID, as referenced elsewhere in the form
} EFI_IFR_VARSTORE_SELECT_PAIR;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_TRUE;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_FALSE;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_GT;
typedef struct {
EFI_IFR_OP_HEADER Header;
} EFI_IFR_GE;
//
// Save defaults and restore defaults have same structure
//
#define EFI_IFR_RESTORE_DEFAULTS EFI_IFR_SAVE_DEFAULTS
typedef struct {
EFI_IFR_OP_HEADER Header;
STRING_REF Title; // The string token for the banner title
UINT16 LineNumber; // 1-based line number
UINT8 Alignment; // left, center, or right-aligned
} EFI_IFR_BANNER;
#define EFI_IFR_BANNER_ALIGN_LEFT 0
#define EFI_IFR_BANNER_ALIGN_CENTER 1
#define EFI_IFR_BANNER_ALIGN_RIGHT 2
#define EFI_IFR_BANNER_TIMEOUT 0xFF
#pragma pack()
#endif

View File

@ -0,0 +1,84 @@
/** @file
This includes some definitions that will be used in both PEI and DXE phases.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: MultiPhase.h
**/
#ifndef __MULTI_PHASE_H__
#define __MULTI_PHASE_H__
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Needed EFI defines for PEI
//
typedef UINT64 EFI_PHYSICAL_ADDRESS;
typedef enum {
EfiReservedMemoryType,
EfiLoaderCode,
EfiLoaderData,
EfiBootServicesCode,
EfiBootServicesData,
EfiRuntimeServicesCode,
EfiRuntimeServicesData,
EfiConventionalMemory,
EfiUnusableMemory,
EfiACPIReclaimMemory,
EfiACPIMemoryNVS,
EfiMemoryMappedIO,
EfiMemoryMappedIOPortSpace,
EfiPalCode,
EfiMaxMemoryType
} EFI_MEMORY_TYPE;
typedef UINT32 EFI_STATUS_CODE_TYPE;
typedef UINT32 EFI_STATUS_CODE_VALUE;
typedef struct {
UINT16 HeaderSize;
UINT16 Size;
EFI_GUID Type;
} EFI_STATUS_CODE_DATA;
typedef struct {
UINT64 Signature;
UINT32 Revision;
UINT32 HeaderSize;
UINT32 CRC32;
UINT32 Reserved;
} EFI_TABLE_HEADER;
#define EFI_PAGE_SIZE 4096
typedef VOID *EFI_HANDLE;
typedef UINT16 EFI_HII_HANDLE;
typedef UINT16 STRING_REF;
typedef struct {
INT16 Value;
INT16 Exponent;
} EFI_EXP_BASE10_DATA;
//
// Define macros to build data structure signatures from characters.
//
#define EFI_SIGNATURE_16(A, B) ((A) | (B << 8))
#define EFI_SIGNATURE_32(A, B, C, D) (EFI_SIGNATURE_16 (A, B) | (EFI_SIGNATURE_16 (C, D) << 16))
#define EFI_SIGNATURE_64(A, B, C, D, E, F, G, H) \
(EFI_SIGNATURE_32 (A, B, C, D) | ((UINT64) (EFI_SIGNATURE_32 (E, F, G, H)) << 32))
#include <Protocol/DevicePath.h>
#endif

View File

@ -0,0 +1,85 @@
/** @file
This file makes the BaseTypes.h backward compatible with the ones used in the
past for EFI and Tiano development. It's mostly just prepending an EFI_ on the
definitions.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: UefiBaseTypes.h
**/
#ifndef __UEFI_BASE_TYPES_H__
#define __UEFI_BASE_TYPES_H__
#include <Common/BaseTypes.h>
typedef UINT64 EFI_LBA;
#define EFIERR(_a) ENCODE_ERROR(_a)
#define EFI_MAX_BIT MAX_BIT
#define EFI_MAX_ADDRESS MAX_ADDRESS
#define EFI_BREAKPOINT() CpuBreakpoint ()
#define EFI_DEADLOOP() CpuDeadLoop ()
#define EFI_ERROR(A) RETURN_ERROR(A)
typedef GUID EFI_GUID;
typedef RETURN_STATUS EFI_STATUS;
#define EFI_SUCCESS RETURN_SUCCESS
#define EFI_LOAD_ERROR RETURN_LOAD_ERROR
#define EFI_INVALID_PARAMETER RETURN_INVALID_PARAMETER
#define EFI_UNSUPPORTED RETURN_UNSUPPORTED
#define EFI_BAD_BUFFER_SIZE RETURN_BAD_BUFFER_SIZE
#define EFI_BUFFER_TOO_SMALL RETURN_BUFFER_TOO_SMALL
#define EFI_NOT_READY RETURN_NOT_READY
#define EFI_DEVICE_ERROR RETURN_DEVICE_ERROR
#define EFI_WRITE_PROTECTED RETURN_WRITE_PROTECTED
#define EFI_OUT_OF_RESOURCES RETURN_OUT_OF_RESOURCES
#define EFI_VOLUME_CORRUPTED RETURN_VOLUME_CORRUPTED
#define EFI_VOLUME_FULL RETURN_VOLUME_FULL
#define EFI_NO_MEDIA RETURN_NO_MEDIA
#define EFI_MEDIA_CHANGED RETURN_MEDIA_CHANGED
#define EFI_NOT_FOUND RETURN_NOT_FOUND
#define EFI_ACCESS_DENIED RETURN_ACCESS_DENIED
#define EFI_NO_RESPONSE RETURN_NO_RESPONSE
#define EFI_NO_MAPPING RETURN_NO_MAPPING
#define EFI_TIMEOUT RETURN_TIMEOUT
#define EFI_NOT_STARTED RETURN_NOT_STARTED
#define EFI_ALREADY_STARTED RETURN_ALREADY_STARTED
#define EFI_ABORTED RETURN_ABORTED
#define EFI_ICMP_ERROR RETURN_ICMP_ERROR
#define EFI_TFTP_ERROR RETURN_TFTP_ERROR
#define EFI_PROTOCOL_ERROR RETURN_PROTOCOL_ERROR
#define EFI_INCOMPATIBLE_VERSION RETURN_INCOMPATIBLE_VERSION
#define EFI_SECURITY_VIOLATION RETURN_SECURITY_VIOLATION
#define EFI_CRC_ERROR RETURN_CRC_ERROR
#define EFI_END_OF_MEDIA RETURN_END_OF_MEDIA
#define EFI_END_OF_FILE RETURN_END_OF_FILE
#define EFI_WARN_UNKNOWN_GLYPH RETURN_WARN_UNKNOWN_GLYPH
#define EFI_WARN_DELETE_FAILURE RETURN_WARN_DELETE_FAILURE
#define EFI_WARN_WRITE_FAILURE RETURN_WARN_WRITE_FAILURE
#define EFI_WARN_BUFFER_TOO_SMALL RETURN_WARN_BUFFER_TOO_SMALL
//
// The EFI memory allocation functions work in units of EFI_PAGEs that are
// 4K. This should in no way be confused with the page size of the processor.
// An EFI_PAGE is just the quanta of memory in EFI.
//
#define EFI_PAGE_MASK 0xFFF
#define EFI_PAGE_SHIFT 12
#define EFI_SIZE_TO_PAGES(a) (((a) >> EFI_PAGE_SHIFT) + (((a) & EFI_PAGE_MASK) ? 1 : 0))
#define EFI_PAGES_TO_SIZE(a) ( (a) << EFI_PAGE_SHIFT)
#endif

View File

@ -0,0 +1,78 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiVariable.h
Abstract:
Header file for EFI Variable Services
--*/
#ifndef _EFI_VARIABLE_H_
#define _EFI_VARIABLE_H_
#define VARIABLE_STORE_SIGNATURE EFI_SIGNATURE_32 ('$', 'V', 'S', 'S')
#define MAX_VARIABLE_SIZE 1024
#define VARIABLE_DATA 0x55AA
//
// Variable Store Header flags
//
#define VARIABLE_STORE_FORMATTED 0x5a
#define VARIABLE_STORE_HEALTHY 0xfe
//
// Variable Store Status
//
typedef enum {
EfiRaw,
EfiValid,
EfiInvalid,
EfiUnknown
} VARIABLE_STORE_STATUS;
//
// Variable State flags
//
#define VAR_IN_DELETED_TRANSITION 0xfe // Variable is in obsolete transistion
#define VAR_DELETED 0xfd // Variable is obsolete
#define VAR_ADDED 0x7f // Variable has been completely added
#define IS_VARIABLE_STATE(_c, _Mask) (BOOLEAN) (((~_c) & (~_Mask)) != 0)
#pragma pack(1)
typedef struct {
UINT32 Signature;
UINT32 Size;
UINT8 Format;
UINT8 State;
UINT16 Reserved;
UINT32 Reserved1;
} VARIABLE_STORE_HEADER;
typedef struct {
UINT16 StartId;
UINT8 State;
UINT8 Reserved;
UINT32 Attributes;
UINTN NameSize;
UINTN DataSize;
EFI_GUID VendorGuid;
} VARIABLE_HEADER;
#pragma pack()
#endif // _EFI_VARIABLE_H_

View File

@ -0,0 +1,47 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiWorkingBlockHeader.h
Abstract:
Defines data structure that is the headers found at the runtime
updatable firmware volumes, such as the FileSystemGuid of the
working block, the header structure of the variable block, FTW
working block, or event log block.
--*/
#ifndef _EFI_WORKING_BLOCK_HEADER_H_
#define _EFI_WORKING_BLOCK_HEADER_H_
//
// EFI Fault tolerant working block header
// The header is immediately followed by the write queue.
//
typedef struct {
EFI_GUID Signature;
UINT32 Crc;
UINT32 WorkingBlockValid : 1;
UINT32 WorkingBlockInvalid : 1;
#define WORKING_BLOCK_VALID 0x1
#define WORKING_BLOCK_INVALID 0x2
UINT32 Reserved : 6;
UINT8 Reserved3[3];
UINTN WriteQueueSize;
//
// UINT8 WriteQueue[WriteQueueSize];
//
} EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER;
#endif

View File

@ -0,0 +1,30 @@
/** @file
The ACPI table storage file is fully FFS compliant.
The file is a number of sections of type EFI_SECTION_RAW.
This GUID is used to identify the file as an ACPI table storage file.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: AcpiTableStorage.h
@par Revision Reference:
GUID defined in ACPI Table Storage Spec Version 0.9.
**/
#ifndef _ACPI_TABLE_STORAGE_H_
#define _ACPI_TABLE_STORAGE_H_
#define EFI_ACPI_TABLE_STORAGE_GUID \
{ 0x7e374e25, 0x8e01, 0x4fee, {0x87, 0xf2, 0x39, 0xc, 0x23, 0xc6, 0x6, 0xcd } }
extern EFI_GUID gEfiAcpiTableStorageGuid;
#endif

View File

@ -0,0 +1,32 @@
/** @file
GUID used as an FV filename for A Priori file. The A Priori file contains a
list of FV filenames that the DXE dispatcher will schedule reguardless of
the dependency grammer.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: Apriori.h
@par Revision Reference:
GUID defined in DXE CIS spec version 0.91B
**/
#ifndef __APRIORI_GUID_H__
#define __APRIORI_GUID_H__
#define EFI_APRIORI_GUID \
{ \
0xfc510ee7, 0xffdc, 0x11d4, {0xbd, 0x41, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
}
extern EFI_GUID gAprioriGuid;
#endif

View File

@ -0,0 +1,43 @@
/** @file
GUIDs used for EFI Capsule
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: Capsule.h
@par Revision Reference:
GUIDs defined in Capsule Spec Version 0.9
**/
#ifndef __CAPSULE_GUID_H__
#define __CAPSULE_GUID_H__
//
// This is the GUID of the capsule header of the image on disk.
//
#define EFI_CAPSULE_GUID \
{ \
0x3B6686BD, 0x0D76, 0x4030, {0xB7, 0x0E, 0xB5, 0x51, 0x9E, 0x2F, 0xC5, 0xA0 } \
}
//
// This is the GUID of the configuration results file created by the capsule
// application.
//
#define EFI_CONFIG_FILE_NAME_GUID \
{ \
0x98B8D59B, 0xE8BA, 0x48EE, {0x98, 0xDD, 0xC2, 0x95, 0x39, 0x2F, 0x1E, 0xDB } \
}
extern EFI_GUID gEfiCapsuleGuid;
extern EFI_GUID gEfiConfigFileNameGuid;
#endif

View File

@ -0,0 +1,40 @@
/** @file
Guid used to define the Firmware File System. See the Framework Firmware
File System Specification for more details.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: FirmwareFileSystem.h
@par Revision Reference:
Guids defined in Firmware File System Spec 0.9
**/
#ifndef __FIRMWARE_FILE_SYSTEM_GUID_H__
#define __FIRMWARE_FILE_SYSTEM_GUID_H__
//
// GUIDs defined by the FFS specification.
//
#define EFI_FIRMWARE_FILE_SYSTEM_GUID \
{ \
0x7A9354D9, 0x0468, 0x444a, {0x81, 0xCE, 0x0B, 0xF6, 0x17, 0xD8, 0x90, 0xDF } \
}
#define EFI_FFS_VOLUME_TOP_FILE_GUID \
{ \
0x1BA0062E, 0xC779, 0x4582, {0x85, 0x66, 0x33, 0x6A, 0xE8, 0xF7, 0x8F, 0x9 } \
}
extern EFI_GUID gEfiFirmwareFileSystemGuid;
extern EFI_GUID gEfiFirmwareVolumeTopFileGuid;
#endif

View File

@ -0,0 +1,167 @@
/** @file
Processor or Compiler specific defines and types for x64.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: ProcessorBind.h
**/
#ifndef __PROCESSOR_BIND_H__
#define __PROCESSOR_BIND_H__
//
// Define the processor type so other code can make processor based choices
//
#define MDE_CPU_IA32
//
// Make sure we are useing the correct packing rules per EFI specification
//
#ifndef __GNUC__
#pragma pack()
#endif
#if _MSC_EXTENSIONS
//
// Disable warning that make it impossible to compile at /W4
// This only works for Microsoft* tools
//
//
// Disabling bitfield type checking warnings.
//
#pragma warning ( disable : 4214 )
//
// Disabling the unreferenced formal parameter warnings.
//
#pragma warning ( disable : 4100 )
//
// Disable slightly different base types warning as CHAR8 * can not be set
// to a constant string.
//
#pragma warning ( disable : 4057 )
//
// ASSERT(FALSE) or while (TRUE) are legal constructes so supress this warning
//
#pragma warning ( disable : 4127 )
#endif
#if !defined(__GNUC__) && (__STDC_VERSION__ < 199901L)
//
// No ANSI C 2000 stdint.h integer width declarations, so define equivalents
//
#if _MSC_EXTENSIONS
//
// use Microsoft* C complier dependent interger width types
//
typedef unsigned __int64 UINT64;
typedef __int64 INT64;
typedef unsigned __int32 UINT32;
typedef __int32 INT32;
typedef unsigned short UINT16;
typedef unsigned short CHAR16;
typedef short INT16;
typedef unsigned char BOOLEAN;
typedef unsigned char UINT8;
typedef char CHAR8;
typedef char INT8;
#else
//
// Assume standard IA-32 alignment.
// BugBug: Need to check portability of long long
//
typedef unsigned long long UINT64;
typedef long long INT64;
typedef unsigned int UINT32;
typedef int INT32;
typedef unsigned short UINT16;
typedef unsigned short CHAR16;
typedef short INT16;
typedef unsigned char BOOLEAN;
typedef unsigned char UINT8;
typedef char CHAR8;
typedef char INT8;
#endif
#define UINT8_MAX 0xff
#else
//
// Use ANSI C 2000 stdint.h integer width declarations
//
#include "stdint.h"
typedef uint8_t BOOLEAN;
typedef int8_t INT8;
typedef uint8_t UINT8;
typedef int16_t INT16;
typedef uint16_t UINT16;
typedef int32_t INT32;
typedef uint32_t UINT32;
typedef int64_t INT64;
typedef uint64_t UINT64;
typedef char CHAR8;
typedef uint16_t CHAR16;
#endif
typedef UINT32 UINTN;
typedef INT32 INTN;
//
// Processor specific defines
//
#define MAX_BIT 0x80000000
#define MAX_2_BITS 0xC0000000
//
// Maximum legal IA-32 address
//
#define MAX_ADDRESS 0xFFFFFFFF
//
// Modifier to ensure that all protocol member functions and EFI intrinsics
// use the correct C calling convention. All protocol member functions and
// EFI intrinsics are required to modify thier member functions with EFIAPI.
//
#if _MSC_EXTENSIONS
//
// Microsoft* compiler requires _EFIAPI useage, __cdecl is Microsoft* specific C.
//
#define EFIAPI __cdecl
#endif
#if __GNUC__
#define EFIAPI __attribute__((cdecl))
#endif
//
// The Microsoft* C compiler can removed references to unreferenced data items
// if the /OPT:REF linker option is used. We defined a macro as this is a
// a non standard extension
//
#if _MSC_EXTENSIONS
#define GLOBAL_REMOVE_IF_UNREFERENCED __declspec(selectany)
#else
#define GLOBAL_REMOVE_IF_UNREFERENCED
#endif
#endif

View File

@ -0,0 +1,481 @@
/** @file
Support for PCI 2.2 standard.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: pci22.h
**/
#ifndef _PCI22_H
#define _PCI22_H
#define PCI_MAX_SEGMENT 0
#define PCI_MAX_BUS 255
#define PCI_MAX_DEVICE 31
#define PCI_MAX_FUNC 7
//
// Command
//
#define PCI_VGA_PALETTE_SNOOP_DISABLED 0x20
#pragma pack(push, 1)
typedef struct {
UINT16 VendorId;
UINT16 DeviceId;
UINT16 Command;
UINT16 Status;
UINT8 RevisionID;
UINT8 ClassCode[3];
UINT8 CacheLineSize;
UINT8 LatencyTimer;
UINT8 HeaderType;
UINT8 BIST;
} PCI_DEVICE_INDEPENDENT_REGION;
typedef struct {
UINT32 Bar[6];
UINT32 CISPtr;
UINT16 SubsystemVendorID;
UINT16 SubsystemID;
UINT32 ExpansionRomBar;
UINT8 CapabilityPtr;
UINT8 Reserved1[3];
UINT32 Reserved2;
UINT8 InterruptLine;
UINT8 InterruptPin;
UINT8 MinGnt;
UINT8 MaxLat;
} PCI_DEVICE_HEADER_TYPE_REGION;
typedef struct {
PCI_DEVICE_INDEPENDENT_REGION Hdr;
PCI_DEVICE_HEADER_TYPE_REGION Device;
} PCI_TYPE00;
typedef struct {
UINT32 Bar[2];
UINT8 PrimaryBus;
UINT8 SecondaryBus;
UINT8 SubordinateBus;
UINT8 SecondaryLatencyTimer;
UINT8 IoBase;
UINT8 IoLimit;
UINT16 SecondaryStatus;
UINT16 MemoryBase;
UINT16 MemoryLimit;
UINT16 PrefetchableMemoryBase;
UINT16 PrefetchableMemoryLimit;
UINT32 PrefetchableBaseUpper32;
UINT32 PrefetchableLimitUpper32;
UINT16 IoBaseUpper16;
UINT16 IoLimitUpper16;
UINT8 CapabilityPtr;
UINT8 Reserved[3];
UINT32 ExpansionRomBAR;
UINT8 InterruptLine;
UINT8 InterruptPin;
UINT16 BridgeControl;
} PCI_BRIDGE_CONTROL_REGISTER;
typedef struct {
PCI_DEVICE_INDEPENDENT_REGION Hdr;
PCI_BRIDGE_CONTROL_REGISTER Bridge;
} PCI_TYPE01;
typedef union {
PCI_TYPE00 Device;
PCI_TYPE01 Bridge;
} PCI_TYPE_GENERIC;
typedef struct {
UINT32 CardBusSocketReg; // Cardus Socket/ExCA Base
// Address Register
//
UINT16 Reserved;
UINT16 SecondaryStatus; // Secondary Status
UINT8 PciBusNumber; // PCI Bus Number
UINT8 CardBusBusNumber; // CardBus Bus Number
UINT8 SubordinateBusNumber; // Subordinate Bus Number
UINT8 CardBusLatencyTimer; // CardBus Latency Timer
UINT32 MemoryBase0; // Memory Base Register 0
UINT32 MemoryLimit0; // Memory Limit Register 0
UINT32 MemoryBase1;
UINT32 MemoryLimit1;
UINT32 IoBase0;
UINT32 IoLimit0; // I/O Base Register 0
UINT32 IoBase1; // I/O Limit Register 0
UINT32 IoLimit1;
UINT8 InterruptLine; // Interrupt Line
UINT8 InterruptPin; // Interrupt Pin
UINT16 BridgeControl; // Bridge Control
} PCI_CARDBUS_CONTROL_REGISTER;
//
// Definitions of PCI class bytes and manipulation macros.
//
#define PCI_CLASS_OLD 0x00
#define PCI_CLASS_OLD_OTHER 0x00
#define PCI_CLASS_OLD_VGA 0x01
#define PCI_CLASS_MASS_STORAGE 0x01
#define PCI_CLASS_MASS_STORAGE_SCSI 0x00
#define PCI_CLASS_MASS_STORAGE_IDE 0x01 // obsolete
#define PCI_CLASS_IDE 0x01
#define PCI_CLASS_MASS_STORAGE_FLOPPY 0x02
#define PCI_CLASS_MASS_STORAGE_IPI 0x03
#define PCI_CLASS_MASS_STORAGE_RAID 0x04
#define PCI_CLASS_MASS_STORAGE_OTHER 0x80
#define PCI_CLASS_NETWORK 0x02
#define PCI_CLASS_NETWORK_ETHERNET 0x00
#define PCI_CLASS_ETHERNET 0x00 // obsolete
#define PCI_CLASS_NETWORK_TOKENRING 0x01
#define PCI_CLASS_NETWORK_FDDI 0x02
#define PCI_CLASS_NETWORK_ATM 0x03
#define PCI_CLASS_NETWORK_ISDN 0x04
#define PCI_CLASS_NETWORK_OTHER 0x80
#define PCI_CLASS_DISPLAY 0x03
#define PCI_CLASS_DISPLAY_CTRL 0x03 // obsolete
#define PCI_CLASS_DISPLAY_VGA 0x00
#define PCI_CLASS_VGA 0x00 // obsolete
#define PCI_CLASS_DISPLAY_XGA 0x01
#define PCI_CLASS_DISPLAY_3D 0x02
#define PCI_CLASS_DISPLAY_OTHER 0x80
#define PCI_CLASS_DISPLAY_GFX 0x80
#define PCI_CLASS_GFX 0x80 // obsolete
#define PCI_CLASS_BRIDGE 0x06
#define PCI_CLASS_BRIDGE_HOST 0x00
#define PCI_CLASS_BRIDGE_ISA 0x01
#define PCI_CLASS_ISA 0x01 // obsolete
#define PCI_CLASS_BRIDGE_EISA 0x02
#define PCI_CLASS_BRIDGE_MCA 0x03
#define PCI_CLASS_BRIDGE_P2P 0x04
#define PCI_CLASS_BRIDGE_PCMCIA 0x05
#define PCI_CLASS_BRIDGE_NUBUS 0x06
#define PCI_CLASS_BRIDGE_CARDBUS 0x07
#define PCI_CLASS_BRIDGE_RACEWAY 0x08
#define PCI_CLASS_BRIDGE_ISA_PDECODE 0x80
#define PCI_CLASS_ISA_POSITIVE_DECODE 0x80 // obsolete
#define PCI_CLASS_SERIAL 0x0C
#define PCI_CLASS_SERIAL_FIREWIRE 0x00
#define PCI_CLASS_SERIAL_ACCESS_BUS 0x01
#define PCI_CLASS_SERIAL_SSA 0x02
#define PCI_CLASS_SERIAL_USB 0x03
#define PCI_CLASS_SERIAL_FIBRECHANNEL 0x04
#define PCI_CLASS_SERIAL_SMB 0x05
#define IS_CLASS1(_p, c) ((_p)->Hdr.ClassCode[2] == (c))
#define IS_CLASS2(_p, c, s) (IS_CLASS1 (_p, c) && ((_p)->Hdr.ClassCode[1] == (s)))
#define IS_CLASS3(_p, c, s, p) (IS_CLASS2 (_p, c, s) && ((_p)->Hdr.ClassCode[0] == (p)))
#define IS_PCI_DISPLAY(_p) IS_CLASS1 (_p, PCI_CLASS_DISPLAY)
#define IS_PCI_VGA(_p) IS_CLASS3 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_VGA, 0)
#define IS_PCI_8514(_p) IS_CLASS3 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_VGA, 1)
#define IS_PCI_GFX(_p) IS_CLASS3 (_p, PCI_CLASS_DISPLAY, PCI_CLASS_DISPLAY_GFX, 0)
#define IS_PCI_OLD(_p) IS_CLASS1 (_p, PCI_CLASS_OLD)
#define IS_PCI_OLD_VGA(_p) IS_CLASS2 (_p, PCI_CLASS_OLD, PCI_CLASS_OLD_VGA)
#define IS_PCI_IDE(_p) IS_CLASS2 (_p, PCI_CLASS_MASS_STORAGE, PCI_CLASS_MASS_STORAGE_IDE)
#define IS_PCI_SCSI(_p) IS_CLASS3 (_p, PCI_CLASS_MASS_STORAGE, PCI_CLASS_MASS_STORAGE_SCSI, 0)
#define IS_PCI_RAID(_p) IS_CLASS3 (_p, PCI_CLASS_MASS_STORAGE, PCI_CLASS_MASS_STORAGE_RAID, 0)
#define IS_PCI_LPC(_p) IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_ISA, 0)
#define IS_PCI_P2P(_p) IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_P2P, 0)
#define IS_PCI_P2P_SUB(_p) IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_P2P, 1)
#define IS_PCI_USB(_p) IS_CLASS2 (_p, PCI_CLASS_SERIAL, PCI_CLASS_SERIAL_USB)
#define HEADER_TYPE_DEVICE 0x00
#define HEADER_TYPE_PCI_TO_PCI_BRIDGE 0x01
#define HEADER_TYPE_CARDBUS_BRIDGE 0x02
#define HEADER_TYPE_MULTI_FUNCTION 0x80
#define HEADER_LAYOUT_CODE 0x7f
#define IS_PCI_BRIDGE(_p) (((_p)->Hdr.HeaderType & HEADER_LAYOUT_CODE) == (HEADER_TYPE_PCI_TO_PCI_BRIDGE))
#define IS_CARDBUS_BRIDGE(_p) (((_p)->Hdr.HeaderType & HEADER_LAYOUT_CODE) == (HEADER_TYPE_CARDBUS_BRIDGE))
#define IS_PCI_MULTI_FUNC(_p) ((_p)->Hdr.HeaderType & HEADER_TYPE_MULTI_FUNCTION)
#define PCI_DEVICE_ROMBAR 0x30
#define PCI_BRIDGE_ROMBAR 0x38
#define PCI_MAX_BAR 6
#define PCI_MAX_CONFIG_OFFSET 0x100
//
// bugbug: this is supported in PCI spec v2.3
//
#define PCI_EXP_MAX_CONFIG_OFFSET 0x1000
#define PCI_VENDOR_ID_OFFSET 0x00
#define PCI_DEVICE_ID_OFFSET 0x02
#define PCI_COMMAND_OFFSET 0x04
#define PCI_PRIMARY_STATUS_OFFSET 0x06
#define PCI_REVISION_ID_OFFSET 0x08
#define PCI_CLASSCODE_OFFSET 0x09
#define PCI_CACHELINE_SIZE_OFFSET 0x0C
#define PCI_LATENCY_TIMER_OFFSET 0x0D
#define PCI_HEADER_TYPE_OFFSET 0x0E
#define PCI_BIST_OFFSET 0x0F
#define PCI_BRIDGE_CONTROL_REGISTER_OFFSET 0x3E
#define PCI_BRIDGE_STATUS_REGISTER_OFFSET 0x1E
#define PCI_BRIDGE_PRIMARY_BUS_REGISTER_OFFSET 0x18
#define PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET 0x19
#define PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET 0x1a
typedef struct {
UINT8 Register;
UINT8 Function;
UINT8 Device;
UINT8 Bus;
UINT8 Reserved[4];
} DEFIO_PCI_ADDR;
typedef union {
struct {
UINT32 Reg : 8;
UINT32 Func : 3;
UINT32 Dev : 5;
UINT32 Bus : 8;
UINT32 Reserved : 7;
UINT32 Enable : 1;
} Bits;
UINT32 Uint32;
} PCI_CONFIG_ACCESS_CF8;
#pragma pack()
#define EFI_ROOT_BRIDGE_LIST 'eprb'
#define PCI_EXPANSION_ROM_HEADER_SIGNATURE 0xaa55
#define EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE 0x0EF1
#define PCI_DATA_STRUCTURE_SIGNATURE EFI_SIGNATURE_32 ('P', 'C', 'I', 'R')
#define PCI_CODE_TYPE_PCAT_IMAGE 0x00
#define PCI_CODE_TYPE_EFI_IMAGE 0x03
#define EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED 0x0001
#define EFI_PCI_COMMAND_IO_SPACE 0x0001
#define EFI_PCI_COMMAND_MEMORY_SPACE 0x0002
#define EFI_PCI_COMMAND_BUS_MASTER 0x0004
#define EFI_PCI_COMMAND_SPECIAL_CYCLE 0x0008
#define EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE 0x0010
#define EFI_PCI_COMMAND_VGA_PALETTE_SNOOP 0x0020
#define EFI_PCI_COMMAND_PARITY_ERROR_RESPOND 0x0040
#define EFI_PCI_COMMAND_STEPPING_CONTROL 0x0080
#define EFI_PCI_COMMAND_SERR 0x0100
#define EFI_PCI_COMMAND_FAST_BACK_TO_BACK 0x0200
#define EFI_PCI_BRIDGE_CONTROL_PARITY_ERROR_RESPONSE 0x0001
#define EFI_PCI_BRIDGE_CONTROL_SERR 0x0002
#define EFI_PCI_BRIDGE_CONTROL_ISA 0x0004
#define EFI_PCI_BRIDGE_CONTROL_VGA 0x0008
#define EFI_PCI_BRIDGE_CONTROL_VGA_16 0x0010
#define EFI_PCI_BRIDGE_CONTROL_MASTER_ABORT 0x0020
#define EFI_PCI_BRIDGE_CONTROL_RESET_SECONDARY_BUS 0x0040
#define EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK 0x0080
#define EFI_PCI_BRIDGE_CONTROL_PRIMARY_DISCARD_TIMER 0x0100
#define EFI_PCI_BRIDGE_CONTROL_SECONDARY_DISCARD_TIMER 0x0200
#define EFI_PCI_BRIDGE_CONTROL_TIMER_STATUS 0x0400
#define EFI_PCI_BRIDGE_CONTROL_DISCARD_TIMER_SERR 0x0800
//
// Following are the PCI-CARDBUS bridge control bit
//
#define EFI_PCI_BRIDGE_CONTROL_IREQINT_ENABLE 0x0080
#define EFI_PCI_BRIDGE_CONTROL_RANGE0_MEMORY_TYPE 0x0100
#define EFI_PCI_BRIDGE_CONTROL_RANGE1_MEMORY_TYPE 0x0200
#define EFI_PCI_BRIDGE_CONTROL_WRITE_POSTING_ENABLE 0x0400
//
// Following are the PCI status control bit
//
#define EFI_PCI_STATUS_CAPABILITY 0x0010
#define EFI_PCI_STATUS_66MZ_CAPABLE 0x0020
#define EFI_PCI_FAST_BACK_TO_BACK_CAPABLE 0x0080
#define EFI_PCI_MASTER_DATA_PARITY_ERROR 0x0100
#define EFI_PCI_CAPABILITY_PTR 0x34
#define EFI_PCI_CARDBUS_BRIDGE_CAPABILITY_PTR 0x14
#pragma pack(1)
typedef struct {
UINT16 Signature; // 0xaa55
UINT8 Reserved[0x16];
UINT16 PcirOffset;
} PCI_EXPANSION_ROM_HEADER;
typedef struct {
UINT16 Signature; // 0xaa55
UINT16 InitializationSize;
UINT32 EfiSignature; // 0x0EF1
UINT16 EfiSubsystem;
UINT16 EfiMachineType;
UINT16 CompressionType;
UINT8 Reserved[8];
UINT16 EfiImageHeaderOffset;
UINT16 PcirOffset;
} EFI_PCI_EXPANSION_ROM_HEADER;
typedef struct {
UINT16 Signature; // 0xaa55
UINT8 Size512;
UINT8 Reserved[15];
UINT16 PcirOffset;
} EFI_LEGACY_EXPANSION_ROM_HEADER;
typedef union {
UINT8 *Raw;
PCI_EXPANSION_ROM_HEADER *Generic;
EFI_PCI_EXPANSION_ROM_HEADER *Efi;
EFI_LEGACY_EXPANSION_ROM_HEADER *PcAt;
} EFI_PCI_ROM_HEADER;
typedef struct {
UINT32 Signature; // "PCIR"
UINT16 VendorId;
UINT16 DeviceId;
UINT16 Reserved0;
UINT16 Length;
UINT8 Revision;
UINT8 ClassCode[3];
UINT16 ImageLength;
UINT16 CodeRevision;
UINT8 CodeType;
UINT8 Indicator;
UINT16 Reserved1;
} PCI_DATA_STRUCTURE;
//
// PCI Capability List IDs and records
//
#define EFI_PCI_CAPABILITY_ID_PMI 0x01
#define EFI_PCI_CAPABILITY_ID_AGP 0x02
#define EFI_PCI_CAPABILITY_ID_VPD 0x03
#define EFI_PCI_CAPABILITY_ID_SLOTID 0x04
#define EFI_PCI_CAPABILITY_ID_MSI 0x05
#define EFI_PCI_CAPABILITY_ID_HOTPLUG 0x06
#define EFI_PCI_CAPABILITY_ID_PCIX 0x07
//
// bugbug: this ID is defined in PCI spec v2.3
//
#define EFI_PCI_CAPABILITY_ID_PCIEXP 0x10
typedef struct {
UINT8 CapabilityID;
UINT8 NextItemPtr;
} EFI_PCI_CAPABILITY_HDR;
//
// Capability EFI_PCI_CAPABILITY_ID_PMI
//
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT16 PMC;
UINT16 PMCSR;
UINT8 BridgeExtention;
UINT8 Data;
} EFI_PCI_CAPABILITY_PMI;
//
// Capability EFI_PCI_CAPABILITY_ID_AGP
//
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT8 Rev;
UINT8 Reserved;
UINT32 Status;
UINT32 Command;
} EFI_PCI_CAPABILITY_AGP;
//
// Capability EFI_PCI_CAPABILITY_ID_VPD
//
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT16 AddrReg;
UINT32 DataReg;
} EFI_PCI_CAPABILITY_VPD;
//
// Capability EFI_PCI_CAPABILITY_ID_SLOTID
//
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT8 ExpnsSlotReg;
UINT8 ChassisNo;
} EFI_PCI_CAPABILITY_SLOTID;
//
// Capability EFI_PCI_CAPABILITY_ID_MSI
//
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT16 MsgCtrlReg;
UINT32 MsgAddrReg;
UINT16 MsgDataReg;
} EFI_PCI_CAPABILITY_MSI32;
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT16 MsgCtrlReg;
UINT32 MsgAddrRegLsdw;
UINT32 MsgAddrRegMsdw;
UINT16 MsgDataReg;
} EFI_PCI_CAPABILITY_MSI64;
//
// Capability EFI_PCI_CAPABILITY_ID_HOTPLUG
//
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
//
// not finished - fields need to go here
//
} EFI_PCI_CAPABILITY_HOTPLUG;
//
// Capability EFI_PCI_CAPABILITY_ID_PCIX
//
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT16 CommandReg;
UINT32 StatusReg;
} EFI_PCI_CAPABILITY_PCIX;
typedef struct {
EFI_PCI_CAPABILITY_HDR Hdr;
UINT16 SecStatusReg;
UINT32 StatusReg;
UINT32 SplitTransCtrlRegUp;
UINT32 SplitTransCtrlRegDn;
} EFI_PCI_CAPABILITY_PCIX_BRDG;
#define DEVICE_ID_NOCARE 0xFFFF
#define PCI_ACPI_UNUSED 0
#define PCI_BAR_NOCHANGE 0
#define PCI_BAR_OLD_ALIGN 0xFFFFFFFFFFFFFFFFULL
#define PCI_BAR_EVEN_ALIGN 0xFFFFFFFFFFFFFFFEULL
#define PCI_BAR_SQUAD_ALIGN 0xFFFFFFFFFFFFFFFDULL
#define PCI_BAR_DQUAD_ALIGN 0xFFFFFFFFFFFFFFFCULL
#define PCI_BAR_IDX0 0x00
#define PCI_BAR_IDX1 0x01
#define PCI_BAR_IDX2 0x02
#define PCI_BAR_IDX3 0x03
#define PCI_BAR_IDX4 0x04
#define PCI_BAR_IDX5 0x05
#define PCI_BAR_ALL 0xFF
#pragma pack(pop)
#endif

View File

@ -0,0 +1,131 @@
/** @file
Memory Only PE COFF loader
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: PeCoffLib.h
**/
#ifndef __BASE_PE_COFF_LIB_H__
#define __BASE_PE_COFF_LIB_H__
//
// Return status codes from the PE/COFF Loader services
// BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes
//
#define IMAGE_ERROR_SUCCESS 0
#define IMAGE_ERROR_IMAGE_READ 1
#define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2
#define IMAGE_ERROR_INVALID_MACHINE_TYPE 3
#define IMAGE_ERROR_INVALID_SUBSYSTEM 4
#define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5
#define IMAGE_ERROR_INVALID_IMAGE_SIZE 6
#define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7
#define IMAGE_ERROR_SECTION_NOT_LOADED 8
#define IMAGE_ERROR_FAILED_RELOCATION 9
#define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10
//
// PE/COFF Loader Read Function passed in by caller
//
typedef
RETURN_STATUS
(EFIAPI *PE_COFF_LOADER_READ_FILE) (
IN VOID *FileHandle,
IN UINTN FileOffset,
IN OUT UINTN *ReadSize,
OUT VOID *Buffer
);
//
// Context structure used while PE/COFF image is being loaded and relocated
//
typedef struct {
PHYSICAL_ADDRESS ImageAddress;
UINT64 ImageSize;
PHYSICAL_ADDRESS DestinationAddress;
PHYSICAL_ADDRESS EntryPoint;
PE_COFF_LOADER_READ_FILE ImageRead;
VOID *Handle;
VOID *FixupData;
UINT32 SectionAlignment;
UINT32 PeCoffHeaderOffset;
UINT32 DebugDirectoryEntryRva;
VOID *CodeView;
CHAR8 *PdbPointer;
UINTN SizeOfHeaders;
UINT32 ImageCodeMemoryType;
UINT32 ImageDataMemoryType;
UINT32 ImageError;
UINTN FixupDataSize;
UINT16 Machine;
UINT16 ImageType;
BOOLEAN RelocationsStripped;
BOOLEAN IsTeImage;
} PE_COFF_LOADER_IMAGE_CONTEXT;
/**
Retrieves information on a PE/COFF image
@param ImageContext The context of the image being loaded
@retval EFI_SUCCESS The information on the PE/COFF image was collected.
@retval EFI_INVALID_PARAMETER ImageContext is NULL.
@retval EFI_UNSUPPORTED The PE/COFF image is not supported.
@retval Otherwise The error status from reading the PE/COFF image using the
ImageContext->ImageRead() function
**/
RETURN_STATUS
EFIAPI
PeCoffLoaderGetImageInfo (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
;
/**
Relocates a PE/COFF image in memory
@param ImageContext Contains information on the loaded image to relocate
@retval EFI_SUCCESS if the PE/COFF image was relocated
@retval EFI_LOAD_ERROR if the image is not a valid PE/COFF image
@retval EFI_UNSUPPORTED not support
**/
RETURN_STATUS
EFIAPI
PeCoffLoaderRelocateImage (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
;
/**
Loads a PE/COFF image into memory
@param ImageContext Contains information on image to load into memory
@retval EFI_SUCCESS if the PE/COFF image was loaded
@retval EFI_BUFFER_TOO_SMALL if the caller did not provide a large enough buffer
@retval EFI_LOAD_ERROR if the image is a runtime driver with no relocations
@retval EFI_INVALID_PARAMETER if the image address is invalid
**/
RETURN_STATUS
EFIAPI
PeCoffLoaderLoadImage (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
;
#endif

View File

@ -0,0 +1,406 @@
/** @file
Library that provides print services
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: PrintLib.h
**/
#ifndef __PRINT_LIB_H__
#define __PRINT_LIB_H__
//
// Print primitives
//
#define LEFT_JUSTIFY 0x01
#define COMMA_TYPE 0x08
#define PREFIX_ZERO 0x20
/**
Produces a Null-terminated Unicode string in an output buffer based on
a Null-terminated Unicode format string and a VA_LIST argument list
Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
and BufferSize.
The Unicode string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list specified by Marker based on the
contents of the format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
Unicode string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@param Marker VA_LIST marker for the variable argument list.
@return return Length of the produced output buffer.
**/
UINTN
EFIAPI
UnicodeVSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
IN VA_LIST Marker
);
/**
Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
Unicode format string and variable argument list.
Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
and BufferSize.
The Unicode string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list based on the contents of the format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
Unicode string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@return Length of the produced output buffer.
**/
UINTN
EFIAPI
UnicodeSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
...
);
/**
Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
ASCII format string and a VA_LIST argument list
Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
and BufferSize.
The Unicode string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list specified by Marker based on the
contents of the format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
Unicode string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@param Marker VA_LIST marker for the variable argument list.
@return Length of the produced output buffer.
**/
UINTN
EFIAPI
UnicodeVSPrintAsciiFormat (
OUT CHAR16 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
IN VA_LIST Marker
);
/**
Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
ASCII format string and variable argument list.
Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
and BufferSize.
The Unicode string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list based on the contents of the
format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
Unicode string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@return Length of the produced output buffer.
**/
UINTN
EFIAPI
UnicodeSPrintAsciiFormat (
OUT CHAR16 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
...
);
/**
Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
ASCII format string and a VA_LIST argument list.
Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
and BufferSize.
The ASCII string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list specified by Marker based on
the contents of the format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
ASCII string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@param Marker VA_LIST marker for the variable argument list.
@return Length of the produced output buffer.
**/
UINTN
EFIAPI
AsciiVSPrint (
OUT CHAR8 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
IN VA_LIST Marker
);
/**
Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
ASCII format string and variable argument list.
Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
and BufferSize.
The ASCII string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list based on the contents of the
format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
ASCII string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@return Length of the produced output buffer.
**/
UINTN
EFIAPI
AsciiSPrint (
OUT CHAR8 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
...
);
/**
Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
ASCII format string and a VA_LIST argument list.
Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
and BufferSize.
The ASCII string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list specified by Marker based on
the contents of the format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
ASCII string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@param Marker VA_LIST marker for the variable argument list.
@return Length of the produced output buffer.
**/
UINTN
EFIAPI
AsciiVSPrintUnicodeFormat (
OUT CHAR8 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
IN VA_LIST Marker
);
/**
Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
ASCII format string and variable argument list.
Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
and BufferSize.
The ASCII string is produced by parsing the format string specified by FormatString.
Arguments are pulled from the variable argument list based on the contents of the
format string.
The length of the produced output buffer is returned.
If BufferSize is 0, then no output buffer is produced and 0 is returned.
If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().
If BufferSize is not 0 and FormatString is NULL, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().
@param StartOfBuffer APointer to the output buffer for the produced Null-terminated
ASCII string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString Null-terminated Unicode format string.
@return Length of the produced output buffer.
**/
UINTN
EFIAPI
AsciiSPrintUnicodeFormat (
OUT CHAR8 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
...
);
/**
Converts a decimal value to a Null-terminated Unicode string.
Converts the decimal number specified by Value to a Null-terminated Unicode
string specified by Buffer containing at most Width characters.
If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
The total number of characters placed in Buffer is returned.
If the conversion contains more than Width characters, then only the first
Width characters are returned, and the total number of characters
required to perform the conversion is returned.
Additional conversion parameters are specified in Flags.
The Flags bit LEFT_JUSTIFY is always ignored.
All conversions are left justified in Buffer.
If Width is 0, PREFIX_ZERO is ignored in Flags.
If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
are inserted every 3rd digit starting from the right.
If Value is < 0, then the fist character in Buffer is a '-'.
If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
then Buffer is padded with '0' characters so the combination of the optional '-'
sign character, '0' characters, digit characters for Value, and the Null-terminator
add up to Width characters.
If Buffer is NULL, then ASSERT().
If unsupported bits are set in Flags, then ASSERT().
If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
@param Buffer Pointer to the output buffer for the produced Null-terminated
Unicode string.
@param Flags The bitmask of flags that specify left justification, zero pad, and commas.
@param Value The 64-bit signed value to convert to a string.
@param Width The maximum number of Unicode characters to place in Buffer.
@return Total number of characters required to perform the conversion.
**/
UINTN
EFIAPI
UnicodeValueToString (
IN OUT CHAR16 *Buffer,
IN UINTN Flags,
IN INT64 Value,
IN UINTN Width
);
/**
Converts a decimal value to a Null-terminated ASCII string.
Converts the decimal number specified by Value to a Null-terminated ASCII string
specified by Buffer containing at most Width characters.
If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
The total number of characters placed in Buffer is returned.
If the conversion contains more than Width characters, then only the first Width
characters are returned, and the total number of characters required to perform
the conversion is returned.
Additional conversion parameters are specified in Flags.
The Flags bit LEFT_JUSTIFY is always ignored.
All conversions are left justified in Buffer.
If Width is 0, PREFIX_ZERO is ignored in Flags.
If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
are inserted every 3rd digit starting from the right.
If Value is < 0, then the fist character in Buffer is a '-'.
If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then Buffer
is padded with '0' characters so the combination of the optional '-'
sign character, '0' characters, digit characters for Value, and the
Null-terminator add up to Width characters.
If Buffer is NULL, then ASSERT().
If unsupported bits are set in Flags, then ASSERT().
If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
@param Buffer Pointer to the output buffer for the produced Null-terminated
ASCII string.
@param Flags The bitmask of flags that specify left justification, zero pad, and commas.
@param Value The 64-bit signed value to convert to a string.
@param Width The maximum number of ASCII characters to place in Buffer.
@return Total number of characters required to perform the conversion.
**/
UINTN
EFIAPI
AsciiValueToString (
IN OUT CHAR8 *Buffer,
IN UINTN Flags,
IN INT64 Value,
IN UINTN Width
);
#endif

View File

@ -0,0 +1,94 @@
/** @file
The device path protocol as defined in EFI 1.0.
The device path represents a programatic path to a device. It's the view
from a software point of view. It also must persist from boot to boot, so
it can not contain things like PCI bus numbers that change from boot to boot.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: DevicePath.h
**/
#ifndef __EFI_DEVICE_PATH_PROTOCOL_H__
#define __EFI_DEVICE_PATH_PROTOCOL_H__
//
// Device Path protocol
//
#define EFI_DEVICE_PATH_PROTOCOL_GUID \
{ \
0x9576e91, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
}
#pragma pack(1)
typedef struct {
UINT8 Type;
UINT8 SubType;
UINT8 Length[2];
} EFI_DEVICE_PATH_PROTOCOL;
#pragma pack()
#define EFI_DP_TYPE_MASK 0x7F
#define EFI_DP_TYPE_UNPACKED 0x80
#define END_DEVICE_PATH_TYPE 0x7f
#define EFI_END_ENTIRE_DEVICE_PATH 0xff
#define EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff
#define EFI_END_INSTANCE_DEVICE_PATH 0x01
#define END_ENTIRE_DEVICE_PATH_SUBTYPE EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE
#define END_INSTANCE_DEVICE_PATH_SUBTYPE EFI_END_INSTANCE_DEVICE_PATH
#define EFI_END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))
#define END_DEVICE_PATH_LENGTH EFI_END_DEVICE_PATH_LENGTH
#define DP_IS_END_TYPE(a)
#define DP_IS_END_SUBTYPE(a) (((a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)
#define DevicePathSubType(a) ((a)->SubType)
#define IsDevicePathUnpacked(a) ((a)->Type & EFI_DP_TYPE_UNPACKED)
#define EfiDevicePathNodeLength(a) (((a)->Length[0]) | ((a)->Length[1] << 8))
#define DevicePathNodeLength(a) (EfiDevicePathNodeLength(a))
#define EfiNextDevicePathNode(a) ((EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) (a)) + EfiDevicePathNodeLength (a)))
#define NextDevicePathNode(a) (EfiNextDevicePathNode(a))
#define EfiDevicePathType(a) (((a)->Type) & EFI_DP_TYPE_MASK)
#define DevicePathType(a) (EfiDevicePathType(a))
#define EfiIsDevicePathEndType(a) (EfiDevicePathType (a) == END_DEVICE_PATH_TYPE)
#define IsDevicePathEndType(a) (EfiIsDevicePathEndType(a))
#define EfiIsDevicePathEndSubType(a) ((a)->SubType == EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)
#define IsDevicePathEndSubType(a) (EfiIsDevicePathEndSubType(a))
#define EfiIsDevicePathEndInstanceSubType(a) ((a)->SubType == EFI_END_INSTANCE_DEVICE_PATH)
#define EfiIsDevicePathEnd(a) (EfiIsDevicePathEndType (a) && EfiIsDevicePathEndSubType (a))
#define IsDevicePathEnd(a) (EfiIsDevicePathEnd(a))
#define EfiIsDevicePathEndInstance(a) (EfiIsDevicePathEndType (a) && EfiIsDevicePathEndInstanceSubType (a))
#define SetDevicePathNodeLength(a,l) { \
(a)->Length[0] = (UINT8) (l); \
(a)->Length[1] = (UINT8) ((l) >> 8); \
}
#define SetDevicePathEndNode(a) { \
(a)->Type = END_DEVICE_PATH_TYPE; \
(a)->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; \
(a)->Length[0] = sizeof(EFI_DEVICE_PATH_PROTOCOL); \
(a)->Length[1] = 0; \
}
extern EFI_GUID gEfiDevicePathProtocolGuid;
#endif

Some files were not shown because too many files have changed in this diff Show More