Add in the 1st version of ECP.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2832 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
123
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/Common.h
Normal file
123
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/Common.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2004 - 2007, 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:
|
||||
|
||||
Common.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Common include file for the ProcessDsc utility.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _COMMON_H_
|
||||
#define _COMMON_H_
|
||||
|
||||
typedef char INT8;
|
||||
typedef unsigned int UINT32;
|
||||
|
||||
#include "EfiUtilityMsgs.h"
|
||||
|
||||
#define MAX_LINE_LEN 1024
|
||||
|
||||
#ifdef MAX_PATH
|
||||
#undef MAX_PATH
|
||||
#define MAX_PATH 1024
|
||||
#endif
|
||||
|
||||
//
|
||||
// Defines for how to expand symbols
|
||||
//
|
||||
#define EXPANDMODE_NO_UNDEFS 0x01
|
||||
#define EXPANDMODE_NO_DESTDIR 0x02
|
||||
#define EXPANDMODE_NO_SOURCEDIR 0x04
|
||||
#define EXPANDMODE_RECURSIVE 0x08
|
||||
|
||||
//
|
||||
// Defines for adding symbols
|
||||
//
|
||||
#define SYM_OVERWRITE 0x01 // overwrite existing assignments
|
||||
#define SYM_GLOBAL 0x02 // global symbol (persistent)
|
||||
#define SYM_LOCAL 0x04 // symbols at component level
|
||||
#define SYM_FILE 0x08 // symbols at file level
|
||||
#define SYM_FILEPATH 0x10 // symbol is a file path
|
||||
#define SYM_FILENAME 0x20 // symbol is a file name
|
||||
#define FV_DIR "FV_DIR" // symbol for base dir where FV files are
|
||||
#define DSC_FILENAME "DSC_FILENAME"
|
||||
|
||||
//
|
||||
// Smart file for better incremental build support.
|
||||
// Only re-create .pkg .inf or .apr files when it's content is changed.
|
||||
//
|
||||
//
|
||||
typedef struct _SMART_FILE {
|
||||
char *FileName;
|
||||
char *FileContent; // Previous file content
|
||||
int FileLength; // Previous file string length
|
||||
int FilePosition; // The offset from FileContent for next comparison
|
||||
FILE *FilePtr; // New file pointer if the file need to be re-created
|
||||
} SMART_FILE;
|
||||
|
||||
SMART_FILE *
|
||||
SmartOpen (
|
||||
char *FileName
|
||||
);
|
||||
|
||||
int
|
||||
SmartWrite (
|
||||
SMART_FILE *SmartFile,
|
||||
char *String
|
||||
);
|
||||
|
||||
void
|
||||
SmartClose (
|
||||
SMART_FILE *SmartFile
|
||||
);
|
||||
|
||||
INT8 *
|
||||
GetSymbolValue (
|
||||
INT8 *SymbolName
|
||||
);
|
||||
|
||||
int
|
||||
AddSymbol (
|
||||
INT8 *Name,
|
||||
INT8 *Value,
|
||||
int Mode
|
||||
);
|
||||
|
||||
int
|
||||
ExpandSymbols (
|
||||
INT8 *SourceLine,
|
||||
INT8 *DestLine,
|
||||
int LineLen,
|
||||
int ExpandMode
|
||||
);
|
||||
|
||||
void
|
||||
Message (
|
||||
UINT32 PrintMask,
|
||||
INT8 *Fmt,
|
||||
...
|
||||
);
|
||||
|
||||
int
|
||||
MakeFilePath (
|
||||
INT8 *FileName
|
||||
);
|
||||
|
||||
int
|
||||
IsAbsolutePath (
|
||||
INT8 *FileName
|
||||
);
|
||||
|
||||
#endif // ifndef _COMMON_H_
|
534
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/DscFile.c
Normal file
534
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/DscFile.c
Normal file
@@ -0,0 +1,534 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2004 - 2007, 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:
|
||||
|
||||
DscFile.c
|
||||
|
||||
Abstract:
|
||||
|
||||
This module is used to process description files at a high level. For the
|
||||
most part, it pre-parses the file to find and save off positions of all
|
||||
the sections ([section.subsection.subsection]) in a linked list, then
|
||||
provides services to find the sections by name, and read the lines from
|
||||
the section until you run into the next section.
|
||||
|
||||
NOTE: DSC file is synonomous with section file. A DSC file is simply a file
|
||||
containing bracketed section names [section.subsection.subsection...]
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdio.h> // for file ops
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h> // for malloc
|
||||
#include "Common.h"
|
||||
#include "DSCFile.h"
|
||||
|
||||
#define MAX_INCLUDE_NEST_LEVEL 20
|
||||
|
||||
static
|
||||
void
|
||||
DSCFileFree (
|
||||
DSC_FILE *DSC
|
||||
);
|
||||
|
||||
static
|
||||
STATUS
|
||||
DSCParseInclude (
|
||||
DSC_FILE *DSC,
|
||||
char *FileName,
|
||||
int NestLevel
|
||||
);
|
||||
|
||||
//
|
||||
// Constructor for a DSC file
|
||||
//
|
||||
int
|
||||
DSCFileInit (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
{
|
||||
memset ((char *) DSC, 0, sizeof (DSC_FILE));
|
||||
DSC->SavedPositionIndex = -1;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
//
|
||||
// Destructor for a DSC file
|
||||
//
|
||||
int
|
||||
DSCFileDestroy (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
{
|
||||
DSC->SavedPositionIndex = -1;
|
||||
DSCFileFree (DSC);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
//
|
||||
// Get the next line from a DSC file.
|
||||
//
|
||||
char *
|
||||
DSCFileGetLine (
|
||||
DSC_FILE *DSC,
|
||||
char *Line,
|
||||
int LineLen
|
||||
)
|
||||
{
|
||||
char *Cptr;
|
||||
|
||||
if (DSC->CurrentLine == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
//
|
||||
// Check for running into next section
|
||||
//
|
||||
if (DSC->CurrentLine->Line[0] == '[') {
|
||||
return NULL;
|
||||
}
|
||||
//
|
||||
// Allow special case where the line starts with backslash-bracket. If we
|
||||
// see this, then shift everything left one character.
|
||||
//
|
||||
if ((DSC->CurrentLine->Line[0] == '\\') && (DSC->CurrentLine->Line[1] == '[')) {
|
||||
Cptr = DSC->CurrentLine->Line + 1;
|
||||
} else {
|
||||
Cptr = DSC->CurrentLine->Line;
|
||||
}
|
||||
|
||||
strncpy (Line, Cptr, LineLen);
|
||||
ParserSetPosition (DSC->CurrentLine->FileName, DSC->CurrentLine->LineNum);
|
||||
DSC->CurrentLine = DSC->CurrentLine->Next;
|
||||
return Line;
|
||||
}
|
||||
|
||||
int
|
||||
DSCFileSetFile (
|
||||
DSC_FILE *DSC,
|
||||
char *FileName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Pre-scan a section file to find all the sections. Then we can speed up
|
||||
searching for the different sections.
|
||||
|
||||
Arguments:
|
||||
|
||||
DSC - pointer to a DSC structure (this pointer)
|
||||
FileName - name of the file to process
|
||||
|
||||
Returns:
|
||||
|
||||
STATUS_SUCCESS if everything went well.
|
||||
|
||||
--*/
|
||||
{
|
||||
STATUS Status;
|
||||
|
||||
//
|
||||
// Called to open a new sectioned file.
|
||||
//
|
||||
Status = DSCParseInclude (DSC, FileName, 1);
|
||||
return Status;
|
||||
}
|
||||
|
||||
static
|
||||
STATUS
|
||||
DSCParseInclude (
|
||||
DSC_FILE *DSC,
|
||||
char *FileName,
|
||||
int NestLevel
|
||||
)
|
||||
{
|
||||
SECTION *NewSect;
|
||||
SECTION_LINE *NewLine;
|
||||
DSC_FILE_NAME *NewDscFileName;
|
||||
char Line[MAX_LINE_LEN];
|
||||
char *Start;
|
||||
char *End;
|
||||
char SaveChar;
|
||||
char *TempCptr;
|
||||
char ShortHandSectionName[MAX_LINE_LEN];
|
||||
char ThisSectionName[MAX_LINE_LEN];
|
||||
SECTION *CurrSect;
|
||||
SECTION *TempSect;
|
||||
FILE *FilePtr;
|
||||
STATUS Status;
|
||||
UINT32 LineNum;
|
||||
|
||||
//
|
||||
// Make sure we haven't exceeded our maximum nesting level
|
||||
//
|
||||
if (NestLevel > MAX_INCLUDE_NEST_LEVEL) {
|
||||
Error (NULL, 0, 0, "application error", "maximum !include nesting level exceeded");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
//
|
||||
// Try to open the file
|
||||
//
|
||||
if ((FilePtr = fopen (FileName, "r")) == NULL) {
|
||||
//
|
||||
// This function is called to handle the DSC file from the command line too,
|
||||
// so differentiate whether this file is an include file or the main file
|
||||
// by examining the nest level.
|
||||
//
|
||||
if (NestLevel == 1) {
|
||||
Error (NULL, 0, 0, FileName, "could not open DSC file for reading");
|
||||
} else {
|
||||
Error (NULL, 0, 0, FileName, "could not open !include DSC file for reading");
|
||||
}
|
||||
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
//
|
||||
// We keep a linked list of files we parse for error reporting purposes.
|
||||
//
|
||||
NewDscFileName = malloc (sizeof (DSC_FILE_NAME));
|
||||
if (NewDscFileName == NULL) {
|
||||
Error (__FILE__, __LINE__, 0, "memory allocation failed", NULL);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
memset (NewDscFileName, 0, sizeof (DSC_FILE_NAME));
|
||||
NewDscFileName->FileName = (INT8 *) malloc (strlen (FileName) + 1);
|
||||
if (NewDscFileName->FileName == NULL) {
|
||||
Error (__FILE__, __LINE__, 0, "memory allocation failed", NULL);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
strcpy (NewDscFileName->FileName, FileName);
|
||||
if (DSC->FileName == NULL) {
|
||||
DSC->FileName = NewDscFileName;
|
||||
} else {
|
||||
DSC->LastFileName->Next = NewDscFileName;
|
||||
}
|
||||
|
||||
DSC->LastFileName = NewDscFileName;
|
||||
//
|
||||
// Read lines and process until done
|
||||
//
|
||||
Status = STATUS_SUCCESS;
|
||||
LineNum = 0;
|
||||
for (;;) {
|
||||
if (fgets (Line, sizeof (Line), FilePtr) == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
LineNum++;
|
||||
ParserSetPosition (FileName, LineNum);
|
||||
//
|
||||
// Add the line to our list if it's not a !include line
|
||||
//
|
||||
if ((strncmp (Line, "!include", 8) == 0) && (isspace (Line[8]))) {
|
||||
Start = Line + 9;
|
||||
while (*Start && (*Start != '"')) {
|
||||
Start++;
|
||||
}
|
||||
|
||||
if (*Start != '"') {
|
||||
Error (FileName, LineNum, 0, NULL, "invalid format for !include");
|
||||
Status = STATUS_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
Start++;
|
||||
for (End = Start; *End && (*End != '"'); End++)
|
||||
;
|
||||
if (*End != '"') {
|
||||
Error (FileName, LineNum, 0, NULL, "invalid format for !include");
|
||||
Status = STATUS_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
*End = 0;
|
||||
//
|
||||
// Expand symbols. Use 'ThisSectionName' as scratchpad
|
||||
//
|
||||
ExpandSymbols (Start, ThisSectionName, sizeof (ThisSectionName), EXPANDMODE_NO_UNDEFS);
|
||||
Status = DSCParseInclude (DSC, ThisSectionName, NestLevel + 1);
|
||||
if (Status != STATUS_SUCCESS) {
|
||||
Error (FileName, LineNum, 0, NULL, "failed to parse !include file");
|
||||
goto Done;
|
||||
}
|
||||
} else {
|
||||
NewLine = (SECTION_LINE *) malloc (sizeof (SECTION_LINE));
|
||||
if (NewLine == NULL) {
|
||||
Error (NULL, 0, 0, NULL, "failed to allocate memory");
|
||||
Status = STATUS_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
memset ((char *) NewLine, 0, sizeof (SECTION_LINE));
|
||||
NewLine->LineNum = LineNum;
|
||||
NewLine->FileName = NewDscFileName->FileName;
|
||||
NewLine->Line = (char *) malloc (strlen (Line) + 1);
|
||||
if (NewLine->Line == NULL) {
|
||||
Error (NULL, 0, 0, NULL, "failed to allocate memory");
|
||||
Status = STATUS_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
strcpy (NewLine->Line, Line);
|
||||
if (DSC->Lines == NULL) {
|
||||
DSC->Lines = NewLine;
|
||||
} else {
|
||||
DSC->LastLine->Next = NewLine;
|
||||
}
|
||||
|
||||
DSC->LastLine = NewLine;
|
||||
//
|
||||
// Parse the line for []. Ignore [] and [----] delimiters. The
|
||||
// line may have multiple definitions separated by commas, so
|
||||
// take each separately
|
||||
//
|
||||
Start = Line;
|
||||
if ((Line[0] == '[') && ((Line[1] != ']') && (Line[1] != '-'))) {
|
||||
//
|
||||
// Skip over open bracket and preceeding spaces
|
||||
//
|
||||
Start++;
|
||||
ShortHandSectionName[0] = 0;
|
||||
|
||||
while (*Start && (*Start != ']')) {
|
||||
while (isspace (*Start)) {
|
||||
Start++;
|
||||
}
|
||||
//
|
||||
// Hack off closing bracket or trailing spaces or comma separator.
|
||||
// Also allow things like [section.subsection1|subsection2], which
|
||||
// is shorthand for [section.subsection1,section.subsection2]
|
||||
//
|
||||
End = Start;
|
||||
while (*End && (*End != ']') && !isspace (*End) && (*End != ',') && (*End != '|')) {
|
||||
End++;
|
||||
}
|
||||
//
|
||||
// Save the character and null-terminate the string
|
||||
//
|
||||
SaveChar = *End;
|
||||
*End = 0;
|
||||
//
|
||||
// Now allocate space for a new section and add it to the linked list.
|
||||
// If the previous section ended with the shorthand indicator, then
|
||||
// the section name was saved off. Append this section name to it.
|
||||
//
|
||||
strcpy (ThisSectionName, ShortHandSectionName);
|
||||
if (*Start == '.') {
|
||||
strcat (ThisSectionName, Start + 1);
|
||||
} else {
|
||||
strcat (ThisSectionName, Start);
|
||||
}
|
||||
//
|
||||
// Allocate memory for the section. Then clear it out.
|
||||
//
|
||||
NewSect = (SECTION *) malloc (sizeof (SECTION));
|
||||
if (NewSect == NULL) {
|
||||
Error (NULL, 0, 0, NULL, "failed to allocation memory for sections");
|
||||
Status = STATUS_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
memset ((char *) NewSect, 0, sizeof (SECTION));
|
||||
NewSect->FirstLine = NewLine;
|
||||
NewSect->Name = (char *) malloc (strlen (ThisSectionName) + 1);
|
||||
if (NewSect->Name == NULL) {
|
||||
Error (NULL, 0, 0, NULL, "failed to allocation memory for sections");
|
||||
Status = STATUS_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
strcpy (NewSect->Name, ThisSectionName);
|
||||
if (DSC->Sections == NULL) {
|
||||
DSC->Sections = NewSect;
|
||||
} else {
|
||||
DSC->LastSection->Next = NewSect;
|
||||
}
|
||||
|
||||
DSC->LastSection = NewSect;
|
||||
*End = SaveChar;
|
||||
//
|
||||
// If the name ended in a shorthand indicator, then save the
|
||||
// section name and truncate it at the last dot.
|
||||
//
|
||||
if (SaveChar == '|') {
|
||||
strcpy (ShortHandSectionName, ThisSectionName);
|
||||
for (TempCptr = ShortHandSectionName + strlen (ShortHandSectionName) - 1;
|
||||
(TempCptr != ShortHandSectionName) && (*TempCptr != '.');
|
||||
TempCptr--
|
||||
)
|
||||
;
|
||||
//
|
||||
// If we didn't find a dot, then hopefully they have [name1|name2]
|
||||
// instead of [name1,name2].
|
||||
//
|
||||
if (TempCptr == ShortHandSectionName) {
|
||||
ShortHandSectionName[0] = 0;
|
||||
} else {
|
||||
//
|
||||
// Truncate after the dot
|
||||
//
|
||||
*(TempCptr + 1) = 0;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// Kill the shorthand string
|
||||
//
|
||||
ShortHandSectionName[0] = 0;
|
||||
}
|
||||
//
|
||||
// Skip to next section name or closing bracket
|
||||
//
|
||||
while (*End && ((*End == ',') || isspace (*End) || (*End == '|'))) {
|
||||
End++;
|
||||
}
|
||||
|
||||
Start = End;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// Look through all the sections to make sure we don't have any duplicates.
|
||||
// Allow [----] and [====] section separators
|
||||
//
|
||||
CurrSect = DSC->Sections;
|
||||
while (CurrSect != NULL) {
|
||||
TempSect = CurrSect->Next;
|
||||
while (TempSect != NULL) {
|
||||
if (isalpha (CurrSect->Name[0]) && (_stricmp (CurrSect->Name, TempSect->Name) == 0)) {
|
||||
Error (
|
||||
TempSect->FirstLine->FileName,
|
||||
TempSect->FirstLine->LineNum,
|
||||
0,
|
||||
TempSect->Name,
|
||||
"duplicate section found"
|
||||
);
|
||||
Error (
|
||||
CurrSect->FirstLine->FileName,
|
||||
CurrSect->FirstLine->LineNum,
|
||||
0,
|
||||
TempSect->Name,
|
||||
"first definition of duplicate section"
|
||||
);
|
||||
Status = STATUS_ERROR;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
TempSect = TempSect->Next;
|
||||
}
|
||||
|
||||
CurrSect = CurrSect->Next;
|
||||
}
|
||||
|
||||
Done:
|
||||
fclose (FilePtr);
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Free up memory allocated for DSC file handling.
|
||||
//
|
||||
static
|
||||
void
|
||||
DSCFileFree (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
{
|
||||
SECTION *NextSection;
|
||||
SECTION_LINE *NextLine;
|
||||
DSC_FILE_NAME *NextName;
|
||||
|
||||
while (DSC->Sections != NULL) {
|
||||
NextSection = DSC->Sections->Next;
|
||||
if (DSC->Sections->Name != NULL) {
|
||||
free (DSC->Sections->Name);
|
||||
}
|
||||
|
||||
free (DSC->Sections);
|
||||
DSC->Sections = NextSection;
|
||||
}
|
||||
|
||||
while (DSC->Lines != NULL) {
|
||||
NextLine = DSC->Lines->Next;
|
||||
free (DSC->Lines->Line);
|
||||
free (DSC->Lines);
|
||||
DSC->Lines = NextLine;
|
||||
}
|
||||
|
||||
while (DSC->FileName != NULL) {
|
||||
NextName = DSC->FileName->Next;
|
||||
free (DSC->FileName->FileName);
|
||||
free (DSC->FileName);
|
||||
DSC->FileName = NextName;
|
||||
}
|
||||
}
|
||||
|
||||
SECTION *
|
||||
DSCFileFindSection (
|
||||
DSC_FILE *DSC,
|
||||
char *Name
|
||||
)
|
||||
{
|
||||
SECTION *Sect;
|
||||
|
||||
//
|
||||
// Look through all the sections to find one with this name (case insensitive)
|
||||
//
|
||||
Sect = DSC->Sections;
|
||||
while (Sect != NULL) {
|
||||
if (_stricmp (Name, Sect->Name) == 0) {
|
||||
//
|
||||
// Position within file
|
||||
//
|
||||
DSC->CurrentLine = Sect->FirstLine->Next;
|
||||
return Sect;
|
||||
}
|
||||
|
||||
Sect = Sect->Next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
DSCFileSavePosition (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
{
|
||||
//
|
||||
// Advance to next slot
|
||||
//
|
||||
DSC->SavedPositionIndex++;
|
||||
if (DSC->SavedPositionIndex >= MAX_SAVES) {
|
||||
DSC->SavedPositionIndex--;
|
||||
Error (NULL, 0, 0, "APP ERROR", "max nesting of saved section file positions exceeded");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
DSC->SavedPosition[DSC->SavedPositionIndex] = DSC->CurrentLine;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
DSCFileRestorePosition (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
{
|
||||
if (DSC->SavedPositionIndex < 0) {
|
||||
Error (NULL, 0, 0, "APP ERROR", "underflow of saved positions in section file");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
DSC->CurrentLine = DSC->SavedPosition[DSC->SavedPositionIndex];
|
||||
DSC->SavedPositionIndex--;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
109
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/DscFile.h
Normal file
109
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/DscFile.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
|
||||
DscFile.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Defines and function prototypes for the ProcessDsc utility.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _DSC_FILE_H_
|
||||
#define _DSC_FILE_H_
|
||||
|
||||
typedef struct _SECTION_LINE {
|
||||
struct _SECTION_LINE *Next;
|
||||
char *Line;
|
||||
char *FileName;
|
||||
UINT32 LineNum;
|
||||
} SECTION_LINE;
|
||||
|
||||
//
|
||||
// Use this structure to keep track of parsed file names. Then
|
||||
// if we get a parse error we can figure out the file/line of
|
||||
// the error and print a useful message.
|
||||
//
|
||||
typedef struct _DSC_FILE_NAME {
|
||||
struct _DSC_FILE_NAME *Next;
|
||||
char *FileName;
|
||||
} DSC_FILE_NAME;
|
||||
|
||||
//
|
||||
// We create a list of section names when we pre-parse a description file.
|
||||
// Use this structure.
|
||||
//
|
||||
typedef struct _SECTION {
|
||||
struct _SECTION *Next;
|
||||
char *Name;
|
||||
SECTION_LINE *FirstLine;
|
||||
} SECTION;
|
||||
|
||||
#define MAX_SAVES 4
|
||||
|
||||
typedef struct {
|
||||
SECTION_LINE *SavedPosition[MAX_SAVES];
|
||||
int SavedPositionIndex;
|
||||
SECTION *Sections;
|
||||
SECTION_LINE *Lines;
|
||||
SECTION *LastSection;
|
||||
SECTION_LINE *LastLine;
|
||||
SECTION_LINE *CurrentLine;
|
||||
DSC_FILE_NAME *FileName;
|
||||
DSC_FILE_NAME *LastFileName;
|
||||
} DSC_FILE;
|
||||
|
||||
//
|
||||
// Function prototypes
|
||||
//
|
||||
int
|
||||
DSCFileSetFile (
|
||||
DSC_FILE *DSC,
|
||||
char *FileName
|
||||
)
|
||||
;
|
||||
SECTION *
|
||||
DSCFileFindSection (
|
||||
DSC_FILE *DSC,
|
||||
char *Name
|
||||
)
|
||||
;
|
||||
int
|
||||
DSCFileSavePosition (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
;
|
||||
int
|
||||
DSCFileRestorePosition (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
;
|
||||
char *
|
||||
DSCFileGetLine (
|
||||
DSC_FILE *DSC,
|
||||
char *Line,
|
||||
int LineLen
|
||||
)
|
||||
;
|
||||
int
|
||||
DSCFileInit (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
;
|
||||
int
|
||||
DSCFileDestroy (
|
||||
DSC_FILE *DSC
|
||||
)
|
||||
;
|
||||
|
||||
#endif // ifndef _DSC_FILE_H_
|
141
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/Exceptions.c
Normal file
141
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/Exceptions.c
Normal 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:
|
||||
|
||||
Exceptions.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Exception logging routines.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset()
|
||||
#include "Exceptions.h"
|
||||
|
||||
//
|
||||
// Max length of a saved exception message
|
||||
//
|
||||
#define MAX_EXCEPTION_MSG 200
|
||||
|
||||
//
|
||||
// We use this structure to track exceptions thrown. We nest deeper on
|
||||
// TryException() calls, and come back out on CatchException() calls.
|
||||
// We save off the first exception message for a given exception level,
|
||||
// but we save the count of how many were thrown.
|
||||
//
|
||||
typedef struct {
|
||||
int ExceptionCount;
|
||||
char ExceptionMsg[MAX_EXCEPTION_MSG];
|
||||
} EXCEPTION_LOG;
|
||||
|
||||
static EXCEPTION_LOG ExceptionLog[MAX_EXCEPTION_NESTING + 1];
|
||||
static int ExceptionLevel;
|
||||
|
||||
//
|
||||
// Initialize our data and structures for tracking exceptions.
|
||||
//
|
||||
int
|
||||
InitExceptions (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
ExceptionLevel = -1;
|
||||
memset ((char *) &ExceptionLog, 0, sizeof (ExceptionLog));
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
// This function replaces the _try() exception macro. It sets the
|
||||
// nesting level.
|
||||
//
|
||||
int
|
||||
TryException (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
//
|
||||
// Boost our exception level if we would not go out of range
|
||||
//
|
||||
ExceptionLevel++;
|
||||
if (ExceptionLevel >= MAX_EXCEPTION_NESTING) {
|
||||
fprintf (stderr, "ERROR: Max exception nesting level exceeded\n");
|
||||
ExceptionLevel--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
// This function replaces the _catch() exception macro. It's used to decrement
|
||||
// the nesting level and return any exeption error messages that were
|
||||
// thrown at the current nesting level.
|
||||
//
|
||||
char *
|
||||
CatchException (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
//
|
||||
// Return a pointer to exception message. NULL if no exceptions at this level
|
||||
//
|
||||
if (ExceptionLevel >= 0) {
|
||||
ExceptionLevel--;
|
||||
if (ExceptionLog[ExceptionLevel + 1].ExceptionMsg[0]) {
|
||||
return ExceptionLog[ExceptionLevel + 1].ExceptionMsg;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
fprintf (stderr, "ERROR: Invalid nesting level call to CatchException()\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
//
|
||||
// This function can be used to test for exceptions between the TryException()
|
||||
// and CatchException() calls in a given function.
|
||||
//
|
||||
int
|
||||
ExceptionThrown (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return ExceptionLog[ExceptionLevel].ExceptionCount;
|
||||
}
|
||||
//
|
||||
// This function replaces the _throw() exception macro. It saves off the
|
||||
// given error message at the current exeption level nesting.
|
||||
//
|
||||
int
|
||||
ThrowException (
|
||||
char *Msg
|
||||
)
|
||||
{
|
||||
if (ExceptionLevel < 0) {
|
||||
//
|
||||
// fprintf (stderr, "ERROR: Exception thrown out of scope");
|
||||
// Haven't yet enabled handling of exceptions, so just emit the message.
|
||||
//
|
||||
fprintf (stderr, Msg);
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
// Only log the first
|
||||
//
|
||||
if (ExceptionLog[ExceptionLevel].ExceptionMsg[0] == 0) {
|
||||
strncpy (ExceptionLog[ExceptionLevel].ExceptionMsg, Msg, MAX_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
ExceptionLog[ExceptionLevel].ExceptionCount++;
|
||||
return 0;
|
||||
}
|
@@ -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:
|
||||
|
||||
Exceptions.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Defines and function prototypes for the ProcessDsc utility.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _EXCEPTIONS_H_
|
||||
#define _EXCEPTIONS_H_
|
||||
|
||||
#define VOID void
|
||||
#define MAX_EXCEPTION_NESTING 4
|
||||
|
||||
//
|
||||
// Function prototypes
|
||||
//
|
||||
int
|
||||
InitExceptions (
|
||||
VOID
|
||||
)
|
||||
;
|
||||
int
|
||||
TryException (
|
||||
VOID
|
||||
)
|
||||
;
|
||||
char *
|
||||
CatchException (
|
||||
VOID
|
||||
)
|
||||
;
|
||||
int
|
||||
ExceptionThrown (
|
||||
VOID
|
||||
)
|
||||
;
|
||||
int
|
||||
ThrowException (
|
||||
char *EMsg
|
||||
)
|
||||
;
|
||||
|
||||
#endif // ifndef _EXCEPTIONS_H_
|
1566
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/FWVolume.c
Normal file
1566
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/FWVolume.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
|
||||
FWVolume.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Include file for the module that keeps track of files for the firmware
|
||||
volumes.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _FW_VOLUME_H_
|
||||
#define _FW_VOLUME_H_
|
||||
|
||||
//
|
||||
// class CFirmwareVolume
|
||||
// {
|
||||
// public:
|
||||
//
|
||||
void
|
||||
CFVConstructor (
|
||||
VOID
|
||||
)
|
||||
;
|
||||
void
|
||||
CFVDestructor (
|
||||
VOID
|
||||
)
|
||||
;
|
||||
|
||||
int
|
||||
CFVAddFVFile (
|
||||
char *Name,
|
||||
char *ComponentType,
|
||||
char *FVs,
|
||||
int ComponentsInstance,
|
||||
char *FFSExt,
|
||||
char *Processor,
|
||||
char *Apriori,
|
||||
char *BaseName,
|
||||
char *Guid
|
||||
)
|
||||
;
|
||||
|
||||
int
|
||||
CFVSetXRefFileName (
|
||||
char *FileName
|
||||
)
|
||||
;
|
||||
|
||||
int
|
||||
CFVWriteInfFiles (
|
||||
DSC_FILE *DSC,
|
||||
FILE *MakeFptr
|
||||
)
|
||||
;
|
||||
|
||||
int
|
||||
NonFFSFVWriteInfFiles (
|
||||
DSC_FILE *DSC,
|
||||
char *FileName
|
||||
)
|
||||
;
|
||||
|
||||
#endif // ifndef _FW_VOLUME_H_
|
102
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/Makefile
Normal file
102
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/Makefile
Normal file
@@ -0,0 +1,102 @@
|
||||
#/*++
|
||||
#
|
||||
# Copyright (c) 2004 - 2007, 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:
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# Abstract:
|
||||
#
|
||||
# makefile for building the ProcessDsc utility.
|
||||
#
|
||||
#--*/
|
||||
|
||||
#
|
||||
# Make sure environmental variable EDK_SOURCE is set
|
||||
#
|
||||
!IFNDEF EDK_SOURCE
|
||||
!ERROR EDK_SOURCE environmental variable not set
|
||||
!ENDIF
|
||||
|
||||
#
|
||||
# Do this if you want to compile from this directory
|
||||
#
|
||||
!IFNDEF TOOLCHAIN
|
||||
TOOLCHAIN = TOOLCHAIN_MSVC
|
||||
!ENDIF
|
||||
|
||||
!INCLUDE $(BUILD_DIR)\PlatformTools.env
|
||||
|
||||
#
|
||||
# Target specific information
|
||||
#
|
||||
|
||||
TARGET_NAME = ProcessDsc
|
||||
TARGET_SRC_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
|
||||
TARGET_EXE = $(EDK_TOOLS_OUTPUT)\ProcessDsc.exe
|
||||
|
||||
#
|
||||
# Build targets
|
||||
#
|
||||
|
||||
all: $(TARGET_EXE)
|
||||
|
||||
INC_DEPS = $(TARGET_SRC_DIR)\DSCFile.h $(INC_DEPS)
|
||||
INC_DEPS = $(TARGET_SRC_DIR)\FWVolume.h $(INC_DEPS)
|
||||
INC_DEPS = $(TARGET_SRC_DIR)\Exceptions.h $(INC_DEPS)
|
||||
INC_DEPS = $(TARGET_SRC_DIR)\Common.h $(INC_DEPS)
|
||||
|
||||
LIBS = $(LIBS) "$(EDK_TOOLS_OUTPUT)\Common.lib"
|
||||
|
||||
OBJECTS = $(EDK_TOOLS_OUTPUT)\DSCFile.obj \
|
||||
$(EDK_TOOLS_OUTPUT)\FWVolume.obj \
|
||||
$(EDK_TOOLS_OUTPUT)\ProcessDsc.obj \
|
||||
$(EDK_TOOLS_OUTPUT)\Exceptions.obj
|
||||
|
||||
#
|
||||
# Compile each source file
|
||||
#
|
||||
|
||||
$(EDK_TOOLS_OUTPUT)\DSCFile.obj : $(TARGET_SRC_DIR)\DSCFile.c $(INC_DEPS)
|
||||
$(CC) $(C_FLAGS) $(TARGET_SRC_DIR)\DSCFile.c /Fo$@
|
||||
|
||||
$(EDK_TOOLS_OUTPUT)\FWVolume.obj : $(TARGET_SRC_DIR)\FWVolume.c $(INC_DEPS)
|
||||
$(CC) $(C_FLAGS) $(TARGET_SRC_DIR)\FWVolume.c /Fo$@
|
||||
|
||||
$(EDK_TOOLS_OUTPUT)\ProcessDsc.obj : $(TARGET_SRC_DIR)\ProcessDsc.c $(INC_DEPS)
|
||||
$(CC) $(C_FLAGS) $(TARGET_SRC_DIR)\ProcessDsc.c /Fo$@
|
||||
|
||||
$(EDK_TOOLS_OUTPUT)\Exceptions.obj : $(TARGET_SRC_DIR)\Exceptions.c $(INC_DEPS)
|
||||
$(CC) $(C_FLAGS) $(TARGET_SRC_DIR)\Exceptions.c /Fo$@
|
||||
|
||||
#
|
||||
# Add Binary Build description for this tool.
|
||||
#
|
||||
|
||||
!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
|
||||
$(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
|
||||
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe $(TARGET_EXE) /Y
|
||||
if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
|
||||
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
|
||||
!ELSE
|
||||
$(TARGET_EXE) : $(OBJECTS) $(LIBS)
|
||||
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
|
||||
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
|
||||
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
|
||||
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
|
||||
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
|
||||
!ENDIF
|
||||
|
||||
clean:
|
||||
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL
|
||||
@if exist $(EDK_TOOLS_OUTPUT)\DscFile.* del $(EDK_TOOLS_OUTPUT)\DscFile.* > NUL
|
||||
@if exist $(EDK_TOOLS_OUTPUT)\Exceptions* del $(EDK_TOOLS_OUTPUT)\Exceptions.* > NUL
|
||||
@if exist $(EDK_TOOLS_OUTPUT)\FwVolume.* del $(EDK_TOOLS_OUTPUT)\FwVolume.* > NUL
|
4726
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/ProcessDsc.c
Normal file
4726
EdkCompatibilityPkg/Sample/Tools/Source/ProcessDsc/ProcessDsc.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user