genffsfile.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 2,403 行 · 第 1/5 页
C
2,403 行
/*++
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:
GenFfsFile.c
Abstract:
This file contains functions required to generate a Firmware File System
file.
--*/
#include "TianoCommon.h"
#include "EfiFirmwareFileSystem.h"
#include "EfiFirmwareVolumeHeader.h"
#include "EfiImageFormat.h"
#include "ParseInf.h"
#include "Compress.h"
#include "EfiCustomizedCompress.h"
#include "crc32.h"
#include "GenFfsFile.h"
#include <stdio.h>
#include <ctype.h> // for isalpha()
//
// include file for _spawnv
//
#include <process.h>
#include <stdlib.h>
#include <string.h>
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
#include "SimpleFileParsing.h"
#define UTILITY_NAME "GenFfsFile"
#define TOOLVERSION "0.32"
#define MAX_ARRAY_SIZE 100
static
INT32
GetNextLine (
OUT CHAR8 *Destination,
IN FILE *Package,
IN OUT UINT32 *LineNumber
);
static
void
CheckSlash (
IN OUT CHAR8 *String,
IN FILE *In,
IN OUT UINT32 *LineNumber
);
static
INT32
FindSectionInPackage (
IN CHAR8 *BuildDirectory,
IN FILE *OverridePackage,
IN OUT UINT32 *LineNumber
);
static
STATUS
ProcessCommandLineArgs (
int Argc,
char *Argv[]
);
static
void
PrintUsage (
void
);
//
// Keep globals in this structure
//
static struct {
UINT8 BuildDirectory[_MAX_PATH];
UINT8 PrimaryPackagePath[_MAX_PATH];
UINT8 OverridePackagePath[_MAX_PATH];
BOOLEAN Verbose;
} mGlobals;
static EFI_GUID mZeroGuid = { 0 };
static
void
StripQuotes (
IN OUT CHAR8 *String
)
/*++
Routine Description:
Removes quotes and/or whitespace from around a string
Arguments:
String - String to remove quotes from
Returns:
None
--*/
{
UINTN Index;
UINTN Index2;
UINTN StrLen;
Index2 = strspn (String, "\" \t\n");
StrLen = strlen (String);
for (Index = Index2; String[Index] != '\"', Index < StrLen; Index++) {
String[Index - Index2] = String[Index];
}
String[Index - Index2] = 0;
}
static
void
PrintUsage (
void
)
/*++
Routine Description:
Print Error / Help message.
Arguments:
void
Returns:
None
--*/
{
printf ("Usage:\n");
printf (UTILITY_NAME " -b \"build directory\" -p1 \"package1.inf\" -p2 \"package2.inf\" -v\n");
printf (" -b \"build directory\":\n ");
printf (" specifies the full path to the component build directory.\n");
printf (" -p1 \"P1_path\":\n");
printf (" specifies fully qualified file name to the primary package file.\n");
printf (" This file will normally exist in the same directory as the makefile\n");
printf (" for the component. Required.\n");
printf (" -p2 \"P2_path\":\n");
printf (" specifies fully qualified file name to the override package file.\n");
printf (" This file will normally exist in the build tip. Optional.\n");
}
static
INT32
TestComment (
IN CHAR8 *String,
IN FILE *In
)
/*++
Routine Description:
Tests input string to see if it is a comment, and if so goes to the next line in the file that is not a comment
Arguments:
String - String to test
In - Open file to move pointer within
Returns:
-1 - End of file reached
0 - Not a comment
1 - Comment bypassed
--*/
{
CHAR8 CharBuffer;
CharBuffer = 0;
if ((String[0] == '/') && (String[1] == '/')) {
while (CharBuffer != '\n') {
fscanf (In, "%c", &CharBuffer);
if (feof (In)) {
return -1;
}
}
} else {
return 0;
}
return 1;
}
static
void
BreakString (
IN CONST CHAR8 *Source,
OUT CHAR8 *Destination,
IN INTN Direction
)
/*++
Routine Description:
Takes an input string and returns either the part before the =, or the part after the =, depending on direction
Arguments:
Source - String to break
Destination - Buffer to place new string in
Direction - 0 to return all of source string before =
1 to return all of source string after =
Returns:
None
--*/
{
UINTN Index;
UINTN Index2;
Index = 0;
Index2 = 0;
if (strchr (Source, '=') == NULL) {
strcpy (Destination, Source);
return ;
}
if (Direction == 0) {
//
// return part of string before =
//
while (Source[Index] != '=') {
Destination[Index] = Source[Index++];
}
Destination[Index] = 0;
} else {
//
// return part of string after =
//
strcpy (Destination, strchr (Source, '=') + 1);
}
}
static
INT32
GetNextLine (
OUT CHAR8 *Destination,
IN FILE *Package,
IN OUT UINT32 *LineNumber
)
/*++
Routine Description:
Gets the next non-commented line from the file
Arguments:
Destination - Where to put string
Package - Package to get string from
LineNumber - The actual line number.
Returns:
-1 - End of file reached
0 - Success
--*/
{
CHAR8 String[_MAX_PATH];
fscanf (Package, "%s", &String);
if (feof (Package)) {
return -1;
}
while (TestComment (String, Package) == 1) {
fscanf (Package, "%s", &String);
if (feof (Package)) {
return -1;
}
}
strcpy (Destination, String);
return 0;
}
static
VOID
CheckSlash (
IN OUT CHAR8 *String,
IN FILE *In,
IN OUT UINT32 *LineNumber
)
/*++
Routine Description:
Checks to see if string is line continuation character, if so goes to next valid line
Arguments:
String - String to test
In - Open file to move pointer within
LineNumber - The line number.
Returns:
None
--*/
{
CHAR8 ByteBuffer;
ByteBuffer = 0;
switch (String[0]) {
case '\\':
while (String[0] == '\\') {
while (ByteBuffer != '\n') {
fscanf (In, "%c", &ByteBuffer);
}
(*LineNumber)++;
if (GetNextLine (String, In, LineNumber) == -1) {
return ;
}
}
break;
case '\n':
(*LineNumber)++;
while (String[0] == '\n') {
if (GetNextLine (String, In, LineNumber) == -1) {
return ;
}
}
break;
default:
break;
}
}
static
INT32
FindSectionInPackage (
IN CHAR8 *BuildDirectory,
IN FILE *OverridePackage,
IN OUT UINT32 *LineNumber
)
/*++
Routine Description:
Finds the matching section within the package
Arguments:
BuildDirectory - name of section to find
OverridePackage - Package file to search within
LineNumber - The line number.
Returns:
-1 - End of file reached
0 - Success
--*/
{
CHAR8 String[_MAX_PATH];
CHAR8 NewString[_MAX_PATH];
String[0] = 0;
while (strcmp (BuildDirectory, String) != 0) {
if (GetNextLine (NewString, OverridePackage, LineNumber) != 0) {
return -1;
}
if (NewString[0] == '[') {
if (NewString[strlen (NewString) - 1] != ']') {
//
// have to construct string.
//
strcpy (String, NewString + 1);
while (1) {
fscanf (OverridePackage, "%s", &NewString);
if (feof (OverridePackage)) {
return -1;
}
if (NewString[0] != ']') {
if (strlen (String) != 0) {
strcat (String, " ");
}
strcat (String, NewString);
if (String[strlen (String) - 1] == ']') {
String[strlen (String) - 1] = 0;
break;
}
} else {
break;
}
}
} else {
NewString[strlen (NewString) - 1] = 0;
strcpy (String, NewString + 1);
}
}
}
return 0;
}
static
EFI_STATUS
GenSimpleGuidSection (
IN OUT UINT8 *FileBuffer,
IN OUT UINT32 *BufferSize,
IN UINT32 DataSize,
IN EFI_GUID SignGuid,
IN UINT16 GuidedSectionAttributes
)
/*++
Routine Description:
add GUIDed section header for the data buffer.
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
SignGuid - Guid to be add.
GuidedSectionAttributes - The section attribute.
Returns:
EFI_SUCCESS - Successful
EFI_OUT_OF_RESOURCES - Not enough resource.
--*/
{
UINT32 TotalSize;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?