diff options
author | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-06-21 21:09:12 +0000 |
---|---|---|
committer | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-06-21 21:09:12 +0000 |
commit | ecbc84213ca7f54b98863572c40af6a91cd569bc (patch) | |
tree | ff4ac71f48733a174de364264e7c220d0ce6d15d | |
parent | cc7f0a911113bfd03121a0807283161351887eb7 (diff) | |
download | edk2-ecbc84213ca7f54b98863572c40af6a91cd569bc.zip edk2-ecbc84213ca7f54b98863572c40af6a91cd569bc.tar.gz edk2-ecbc84213ca7f54b98863572c40af6a91cd569bc.tar.bz2 |
Not needed
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@588 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r-- | Tools/Source/TianoTools/GenFdImage/GenFdImage.h | 87 | ||||
-rw-r--r-- | Tools/Source/TianoTools/GenFdImage/GenFdImageDll.c | 864 | ||||
-rw-r--r-- | Tools/Source/TianoTools/GenFdImage/GenFdImageExe.c | 330 | ||||
-rw-r--r-- | Tools/Source/TianoTools/GenFdImage/GenFdImageExe.h | 91 | ||||
-rw-r--r-- | Tools/Source/TianoTools/GenFdImage/GenFdImageLib.c | 848 |
5 files changed, 0 insertions, 2220 deletions
diff --git a/Tools/Source/TianoTools/GenFdImage/GenFdImage.h b/Tools/Source/TianoTools/GenFdImage/GenFdImage.h deleted file mode 100644 index a2c1afb..0000000 --- a/Tools/Source/TianoTools/GenFdImage/GenFdImage.h +++ /dev/null @@ -1,87 +0,0 @@ -/*++
-
-Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
-This software and associated documentation (if any) is furnished
-under a license and may only be used or copied in accordance
-with the terms of the license. Except as permitted by such
-license, no part of this software or documentation may be
-reproduced, stored in a retrieval system, or transmitted in any
-form or by any means without the express written consent of
-Intel Corporation.
-
-
-Module Name:
-
- GenFdImage.h
-
-Abstract:
-
- This file contains the relevant declarations required
- to generate the Firmware Device
-
---*/
-
-//
-// Coded to EFI 2.0 Coding Standard
-//
-#ifndef _EFI_GEN_FD_IMAGE_H
-#define _EFI_GEN_FD_IMAGE_H
-
-//
-// Included Header files
-//
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "ParseInf.h"
-
-//
-// Defines
-//
-#define FILE_NAME_SIZE 256
-
-//
-// Type Definition
-//
-typedef struct {
- UINT64 FdSize;
- UINT64 FdBaseAddress;
- UINT8 PadValue;
- CHAR8 OutFileName[FILE_NAME_SIZE];
-} FDINFO;
-
-//
-// Exported Function Prototype
-//
-EFI_STATUS
-GenerateFdImage (
- IN UINT64 BaseAddress,
- IN UINT64 Size,
- IN UINT8 PadByte,
- IN CHAR8 *OutFile,
- IN CHAR8 **FileList
- )
-/*++
-
-Routine Description:
-
- GC_TODO: Add function description
-
-Arguments:
-
- BaseAddress - GC_TODO: add argument description
- Size - GC_TODO: add argument description
- PadByte - GC_TODO: add argument description
- OutFile - GC_TODO: add argument description
- FileList - GC_TODO: add argument description
-
-Returns:
-
- GC_TODO: add return values
-
---*/
-;
-
-#endif
diff --git a/Tools/Source/TianoTools/GenFdImage/GenFdImageDll.c b/Tools/Source/TianoTools/GenFdImage/GenFdImageDll.c deleted file mode 100644 index 057c108..0000000 --- a/Tools/Source/TianoTools/GenFdImage/GenFdImageDll.c +++ /dev/null @@ -1,864 +0,0 @@ -/*++
-Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
-This software and associated documentation (if any) is furnished
-under a license and may only be used or copied in accordance
-with the terms of the license. Except as permitted by such
-license, no part of this software or documentation may be
-reproduced, stored in a retrieval system, or transmitted in any
-form or by any means without the express written consent of
-Intel Corporation.
-
-
- Module Name:
- GenFdImageDll.C
-
- Abstarct:
- This file contains the relevant functions required to complete
- the API to generate Firmware Device
---*/
-
-// GC_TODO: fix comment to add: Abstract:
-//
-// This tells the compiler to export the DLL functions
-//
-#define GEN_FD_IMAGE_EXPORTS
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <Common/UefiBaseTypes.h>
-
-#include "GenFdImage.h"
-#include "ParseInf.h"
-
-//
-// Global declaration
-//
-UINTN ValidLineNum = 0;
-
-UINTN NumFvFiles = 0;
-static UINT64 LastAddress = 0;
-
-CHAR8 **TokenStr;
-CHAR8 **OrgStrTokPtr;
-
-FDINFO *FdInfo;
-FDINFO *OrgFdInfoPtr;
-
-FVINFO **FvInfo;
-FVINFO **OrgFvInfoPtr;
-
-//
-// Global function declarations
-//
-EFI_STATUS
-BuildFirmwareDeviceBinaryFromFwVolumes (
- IN UINT64 FvBaseAddress,
- IN CHAR8 *FvFileName,
- IN CHAR8 *FdFileName
- );
-
-INTN
-CompareItems (
- IN const VOID *Arg1,
- IN const VOID *Arg2
- )
-/*++
-Description:
-
- This function is used by qsort to sort the Fv list based on FvBaseAddress
-
-Input:
- Arg1
- Arg2
-
-Return:
-
- None
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: Arg1 - add argument and description to function comment
-// GC_TODO: Arg2 - add argument and description to function comment
-{
- if ((*(FVINFO **) Arg1)->FvBaseAddress > (*(FVINFO **) Arg2)->FvBaseAddress) {
- return 1;
- } else if ((*(FVINFO **) Arg1)->FvBaseAddress < (*(FVINFO **) Arg2)->FvBaseAddress) {
- return -1;
- } else {
- return 0;
- }
-}
-
-VOID
-BuildTokenList (
- IN CHAR8 *Token
- )
-/*++
-Description:
-
- This function builds the token list in an array which will be parsed later
-
-Input:
- Token String,
-
-Return:
-
- None
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: Token - add argument and description to function comment
-{
-
- strcpy (*TokenStr, Token);
- TokenStr++;
-}
-
-VOID
-TrimLine (
- IN CHAR8 *Line
- )
-/*++
-Description:
-
- This function cleans up the line by removing all whitespace and
- comments
-
-Input:
-
- Line String,
-
-Return:
- None
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: Line - add argument and description to function comment
-{
- CHAR8 TmpLine[FILE_NAME_SIZE];
- CHAR8 c;
- CHAR8 *Ptr0;
- UINTN i;
- UINTN j;
-
- //
- // Change '#' to '//' for Comment style
- //
- // if((Ptr0=strchr(Line, '#')) != NULL) {
- //
- if ((Ptr0 = strstr (Line, "//")) != NULL) {
- Line[Ptr0 - Line] = 0;
- }
-
- i = j = 0;
-
- while ((c = Line[i]) != 0) {
- if ((c != ' ') && (c != '\t') && (c != '\n')) {
- TmpLine[j++] = c;
- }
-
- i++;
- }
-
- TmpLine[j] = 0;
- strcpy (Line, TmpLine);
-}
-
-VOID
-ValidLineCount (
- IN FILE *Fp
- )
-/*++
-
-Description:
-
- This function calculated number of valid lines in a input file.
-
-Input:
-
- Fp Pointer to a file handle which has been opened.
-
-Return:
-
- None
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: Fp - add argument and description to function comment
-{
- CHAR8 Buff[FILE_NAME_SIZE];
-
- while (fgets (Buff, sizeof (Buff), Fp)) {
- TrimLine (Buff);
- if (Buff[0] == 0) {
- continue;
- }
-
- ValidLineNum++;
- }
-}
-
-VOID
-ParseInputFile (
- IN FILE *Fp
- )
-/*++
-
-Description:
-
- This function parses the input file and tokenize the string
-
-Input:
-
- Fp Pointer to a file handle which has been opened.
-
-Return:
-
- None
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: Fp - add argument and description to function comment
-{
- CHAR8 *Token;
- CHAR8 Buff[FILE_NAME_SIZE];
- CHAR8 OrgLine[FILE_NAME_SIZE];
- CHAR8 Str[FILE_NAME_SIZE];
- CHAR8 Delimit[] = "=";
-
- while (fgets (Buff, sizeof (Buff), Fp) != NULL) {
- strcpy (OrgLine, Buff);
- TrimLine (Buff);
-
- if (Buff[0] == 0) {
- continue;
- }
-
- Token = strtok (Buff, Delimit);
-
- while (Token != NULL) {
- strcpy (Str, Token);
- BuildTokenList (Str);
- Token = strtok (NULL, Delimit);
- }
- }
-}
-
-EFI_STATUS
-InitializeComps (
- VOID
- )
-/*++
-
-Description:
-
- This function intializes the relevant global variable which is being
- used to store the information retrieved from INF file.
-
-Input:
-
- None
-
-Return:
-
- EFI_STATUS
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- UINTN Index;
-
- FdInfo = malloc (sizeof (FDINFO));
-
- if (FdInfo == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- OrgFdInfoPtr = FdInfo;
-
- FvInfo = malloc (sizeof (int) * NumFvFiles);
-
- if (FvInfo == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- OrgFvInfoPtr = FvInfo;
-
- for (Index = 0; Index < NumFvFiles; Index++) {
- *FvInfo = malloc (sizeof (FVINFO));
-
- if (*FvInfo == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- memset (*FvInfo, 0, sizeof (FVINFO));
- FvInfo++;
- }
-
- FvInfo = OrgFvInfoPtr;
-
- return EFI_SUCCESS;
-}
-
-VOID
-InitializeInFileInfo (
- VOID
- )
-/*++
-
-Description:
-
- This function intializes the relevant global variable which is being
- used to store the information retrieved from INF file.
-
-Input:
-
- NONE
-
-Return:
-
- NONE
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-{
- UINTN OptionFlag;
- UINT64 StringValue;
-
- OptionFlag = 0;
- TokenStr = OrgStrTokPtr;
-
- while (*TokenStr != NULL) {
- if (stricmp (*TokenStr, "[options]") == 0) {
- OptionFlag = 1;
- }
-
- if (OptionFlag) {
- if (stricmp (*TokenStr, "EFI_FV_BASE_ADDRESS") == 0) {
- *TokenStr++;
- if (AsciiStringToUint64 (*TokenStr, FALSE, &StringValue) != EFI_SUCCESS) {
- printf ("\nERROR: Cannot determine the FV base address.");
- return ;
- }
- (*FvInfo)->FvBaseAddress = StringValue;
- } else if (stricmp (*TokenStr, "EFI_FV_FILE_NAME") == 0) {
- *TokenStr++;
- strcpy ((*FvInfo)->FvFile, *TokenStr);
- }
- }
-
- TokenStr++;
- }
-}
-
-EFI_STATUS
-GetFvRelatedInfoFromInfFile (
- IN CHAR8 *FileName
- )
-/*++
-
-Description:
-
- This function reads the input file, parse it and create a list of tokens
- which is parsed and used, to intialize the data related to Firmware Volume.
-
-Input:
-
- FileName FileName which needed to be read to parse data
-
-Return:
-
- EFI_STATUS
-
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: FileName - add argument and description to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- FILE *Fp;
- UINTN Index;
-
- Fp = fopen (FileName, "r");
-
- if (Fp == NULL) {
- printf ("Error in opening %s file\n", FileName);
- return EFI_ABORTED;
- }
-
- ValidLineCount (Fp);
-
- if (ValidLineNum == 0) {
- printf ("\nFile doesn't contain any valid informations");
- return EFI_ABORTED;
- }
-
- TokenStr = (CHAR8 **) malloc (sizeof (UINTN) * (2 * ValidLineNum));
- memset (TokenStr, 0, sizeof (UINTN) * (2 * ValidLineNum));
- OrgStrTokPtr = TokenStr;
-
- for (Index = 0; Index < (2 * ValidLineNum); Index++) {
- *TokenStr = (CHAR8 *) malloc (sizeof (CHAR8) * FILE_NAME_SIZE);
- memset (*TokenStr, 0, FILE_NAME_SIZE);
- TokenStr++;
- }
-
- *TokenStr = NULL;
- TokenStr = OrgStrTokPtr;
- fseek (Fp, 0L, SEEK_SET);
-
- ParseInputFile (Fp);
- InitializeInFileInfo ();
-
- if (Fp) {
- fclose (Fp);
- }
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-WriteFwBinary (
- IN CHAR8 *FileName,
- IN UINT64 StartAddress,
- IN UINT64 Size,
- IN UINT8 *Buffer
- )
-/*++
-
-Description:
-
- This function reads the input file, parse it and create a list of tokens
- which is parsed and used, to intialize the data related to Firmware Volume.
-
-Input:
-
- FileName FileName which needed to be read to parse data
- StartAddress This will set the file position.
- Size Size in bytes needed to be written
- Buffer Buffer needed to e written
-
-Return:
-
- EFI_STATUS
-
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: FileName - add argument and description to function comment
-// GC_TODO: StartAddress - add argument and description to function comment
-// GC_TODO: Size - add argument and description to function comment
-// GC_TODO: Buffer - add argument and description to function comment
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- FILE *Fp;
- UINTN NumByte;
-
- Fp = fopen (FileName, "a+b");
-
- if (Fp == NULL) {
- printf ("\nERROR:Error in opening file %s ", FileName);
- return EFI_INVALID_PARAMETER;
- }
-
- fseek (Fp, (UINTN) StartAddress, SEEK_SET);
- NumByte = fwrite ((VOID *) Buffer, sizeof (UINT8), (UINTN) Size, Fp);
-
- //
- // Check to ensure that buffer has been copied successfully
- //
- if (NumByte != Size) {
- printf ("\nERROR: Error in copying the buffer into file");
- return EFI_ABORTED;
- }
-
- if (Fp) {
- fclose (Fp);
- }
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-BuildFirmwareDeviceBinaryFromFwVolumes (
- IN UINT64 FvBaseAddress,
- IN CHAR8 *FvFileName,
- IN CHAR8 *FdFileName
- )
-/*++
-
-Description:
-
- This function reads the input file, parse it and create a list of tokens
- which is parsed and used, to intialize the data related to Firmware Volume.
-
-Input:
-
- FvBaseAddress Base Address. This info is retrieved from INF file
- FvFileName InputFileName
- FdFileName Output File Name
-
-Return:
-
- EFI_STATUS
-
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: FvBaseAddress - add argument and description to function comment
-// GC_TODO: FvFileName - add argument and description to function comment
-// GC_TODO: FdFileName - add argument and description to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- FILE *Fp;
- UINT64 FileSize;
- UINT64 NumByteRead;
- UINT64 PadByteSize;
- UINTN Index;
- UINT64 BaseAddress;
- UINT8 *Buffer;
- EFI_STATUS Status;
- static UINT64 StartAddress = 0;
-
- Fp = fopen (FvFileName, "r+b");
-
- if (Fp == NULL) {
- printf ("\nERROR:Error in opening file %s", FvFileName);
- return EFI_ABORTED;
- }
-
- BaseAddress = FdInfo->FdBaseAddress;
-
- //
- // Check if Base Address of Firmware Volume falls below the Base Address
- // Firmware Device, if yes, then abort this process.
- //
- if (FvBaseAddress < BaseAddress) {
- printf ("\nERROR: Firmware Volume Base Address falls below Firmware Device Address.\n");
- return EFI_ABORTED;
- }
- //
- // Check if there are any hole between two Firmware Volumes. If any hole
- // exists, fill the hole with PadByte data.
- //
- if (FvBaseAddress > LastAddress) {
- PadByteSize = (FvBaseAddress - LastAddress);
- Buffer = malloc ((UINTN) PadByteSize);
-
- for (Index = 0; Index < PadByteSize; Index++) {
- *Buffer = FdInfo->PadValue;
- Buffer++;
- }
-
- Buffer -= PadByteSize;
- Status = WriteFwBinary (FdFileName, StartAddress, (UINT64) PadByteSize, Buffer);
-
- if (Buffer) {
- free (Buffer);
- }
-
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Error in writing the binary image to file");
- return Status;
- }
-
- StartAddress += PadByteSize;
- LastAddress += PadByteSize;
- }
- //
- // Proceed with next Firmware Volume updates
- //
- FileSize = _filelength (fileno (Fp));
-
- if ((FvBaseAddress + FileSize) > (FdInfo->FdBaseAddress + FdInfo->FdSize)) {
- printf (
- "\nERROR:Unable to update Firmware Device. File %s is larger than \
- available space.",
- FvFileName
- );
- if (Fp) {
- fclose (Fp);
- }
-
- return EFI_ABORTED;
- }
-
- Buffer = malloc ((UINTN) FileSize);
-
- if (Buffer == NULL) {
- printf ("Error in allocating buffer to read specific file\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- NumByteRead = fread ((VOID *) Buffer, sizeof (UINT8), (UINTN) FileSize, Fp);
-
- Status = WriteFwBinary (FdFileName, StartAddress, FileSize, Buffer);
-
- if (Buffer) {
- free ((VOID *) Buffer);
- }
-
- if (Fp) {
- fclose (Fp);
- }
-
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Error in writing the binary image to file");
- return Status;
- }
-
- StartAddress += NumByteRead;
- LastAddress += FileSize;
-
- return EFI_SUCCESS;
-}
-
-VOID
-CleanUpMemory (
- VOID
- )
-/*++
-
-Description:
-
- This function cleans up any allocated buffer
-
-Input:
-
- NONE
-
-Return:
-
- NONE
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-{
- UINTN Index;
-
- if (FdInfo) {
- free (FdInfo);
- }
-
- FvInfo = OrgFvInfoPtr;
-
- if (FvInfo) {
- for (Index = 0; Index < NumFvFiles; Index++) {
- if (*FvInfo) {
- free (*FvInfo);
- }
-
- FvInfo++;
- }
-
- FvInfo = OrgFvInfoPtr;
- free (FvInfo);
- }
-}
-
-GEN_FD_IMAGE_API
-EFI_STATUS
-GenerateFdImage (
- IN UINT64 BaseAddress,
- IN UINT64 Size,
- IN UINT8 PadByte,
- IN CHAR8 *OutFile,
- IN CHAR8 **FileList
- )
-/*++
-
-Description:
-
- This function reads the input file, parse it and create a list of tokens
- which is parsed and used, to intialize the data related to Firmware Volume.
-
-Input:
-
- BaseAddress Base Address for this Firmware Device
- Size, Total Size of the Firmware Device
- PadByte Pad byte data
- OutFile Output File Name
- FileList File List pointer to INF file names.
-
-Return:
-
- EFI_STATUS
-
---*/
-// GC_TODO: function comment is missing 'Routine Description:'
-// GC_TODO: function comment is missing 'Arguments:'
-// GC_TODO: function comment is missing 'Returns:'
-// GC_TODO: BaseAddress - add argument and description to function comment
-// GC_TODO: Size - add argument and description to function comment
-// GC_TODO: PadByte - add argument and description to function comment
-// GC_TODO: OutFile - add argument and description to function comment
-// GC_TODO: FileList - add argument and description to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- EFI_STATUS Status;
- UINTN Index;
- UINTN PadSize;
- UINTN FileSize;
- CHAR8 **InFile;
- FILE *Fp;
- UINT8 *Buffer;
- UINTN NumByte;
-
- //
- // Ensure, if there are any previous Firmware Device exists,
- // If yes, make it to 0 bytes
- //
- if ((Fp = fopen (OutFile, "w")) != NULL) {
- fclose (Fp);
- }
-
- InFile = FileList;
-
- while (*InFile != NULL) {
- NumFvFiles++;
- InFile++;
- }
-
- InitializeComps ();
-
- //
- // Restore the orginal pointers
- //
- FvInfo = OrgFvInfoPtr;
- InFile = FileList;
-
- while (*InFile != NULL) {
- strcpy ((*FvInfo)->FvInfoFile, *InFile);
- Status = GetFvRelatedInfoFromInfFile (*InFile);
-
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Error occurred in processsing INF file");
- CleanUpMemory ();
- return Status;
- }
-
- InFile++;
- FvInfo++;
- }
-
- FdInfo->FdSize = Size;
- FdInfo->FdBaseAddress = BaseAddress;
- FdInfo->PadValue = PadByte;
- FvInfo = OrgFvInfoPtr;
- strcpy (FdInfo->OutFileName, OutFile);
-
- for (Index = 0; Index < NumFvFiles; Index++) {
- Status = GenerateFvImage ((*FvInfo)->FvInfoFile);
-
- if (Status != EFI_SUCCESS) {
- CleanUpMemory ();
- return Status;
- }
-
- FvInfo++;
- }
-
- FvInfo = OrgFvInfoPtr;
-
- //
- // Sort the Firmware Volume informations. Firmware Volume with lower
- // base addresses will be processed first and hiher base address one
- // will be processed later.
- //
- qsort ((VOID *) FvInfo, NumFvFiles, sizeof (FVINFO *), CompareItems);
-
- LastAddress = (*FvInfo)->FvBaseAddress;
-
- for (Index = 0; Index < NumFvFiles; Index++) {
- Status = BuildFirmwareDeviceBinaryFromFwVolumes (
- (*FvInfo)->FvBaseAddress,
- (*FvInfo)->FvFile,
- FdInfo->OutFileName
- );
- if (Status != EFI_SUCCESS) {
- CleanUpMemory ();
- return Status;
- }
-
- FvInfo++;
- }
- //
- // Check if any space left after copying data from all Firmware Volumes
- // If yes, then fill those location with PadValue.
- //
- if ((FdInfo->FdBaseAddress + Size) > LastAddress) {
-
- PadSize = (UINTN) ((FdInfo->FdBaseAddress + FdInfo->FdSize) - LastAddress);
- Buffer = malloc (PadSize);
-
- if (Buffer == NULL) {
- CleanUpMemory ();
- return EFI_OUT_OF_RESOURCES;
- }
-
- for (Index = 0; Index < PadSize; Index++) {
- *Buffer = FdInfo->PadValue;
- Buffer++;
- }
-
- Buffer -= PadSize;
-
- Fp = fopen (OutFile, "a+b");
-
- if (Fp == NULL) {
- printf ("\nERROR:Opening file %s", OutFile);
- CleanUpMemory ();
- return EFI_ABORTED;
- }
-
- FileSize = _filelength (fileno (Fp));
- fseek (Fp, FileSize, SEEK_SET);
- NumByte = fwrite (Buffer, sizeof (UINT8), PadSize, Fp);
-
- if (Buffer) {
- free (Buffer);
- }
-
- fclose (Fp);
-
- if (NumByte != (sizeof (UINT8) * PadSize)) {
- printf ("\nERROR: Copying data from buffer to File %s ", OutFile);
- CleanUpMemory ();
- return EFI_ABORTED;
- }
- }
- //
- // Clean up all the memory which has been allocated so far.
- //
- CleanUpMemory ();
- return EFI_SUCCESS;
-}
diff --git a/Tools/Source/TianoTools/GenFdImage/GenFdImageExe.c b/Tools/Source/TianoTools/GenFdImage/GenFdImageExe.c deleted file mode 100644 index 9c56d06..0000000 --- a/Tools/Source/TianoTools/GenFdImage/GenFdImageExe.c +++ /dev/null @@ -1,330 +0,0 @@ -/*++
-
-Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
-This software and associated documentation (if any) is furnished
-under a license and may only be used or copied in accordance
-with the terms of the license. Except as permitted by such
-license, no part of this software or documentation may be
-reproduced, stored in a retrieval system, or transmitted in any
-form or by any means without the express written consent of
-Intel Corporation.
-
-
-Module Name:
-
- GenFdImageExe.c
-
-Abstract:
-
- This contains all code necessary to build the GenFdImage.exe utility.
- This utility relies heavily on the GenFdImage Lib. Definitions for both
- can be found in the GenFdImage Utility Specification, review draft.
-
---*/
-
-//
-// Coded to EFI 2.0 Coding Standards
-//
-//
-// Include files
-//
-#include "GenFdImage.h"
-#include "GenFdImageExe.h"
-
-VOID
-PrintUtilityInfo (
- VOID
- )
-/*++
-
-Routine Description:
-
- Displays the standard utility information to SDTOUT
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- printf (
- "%s, EFI 2.0 Firmware Device Image Generation Utility. ""Version %i.%i, %s.\n\n",
- UTILITY_NAME,
- UTILITY_MAJOR_VERSION,
- UTILITY_MINOR_VERSION,
- UTILITY_DATE
- );
-}
-
-VOID
-PrintUsage (
- VOID
- )
-/*++
-
-Routine Description:
-
- Displays the utility usage syntax to STDOUT
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- printf (
- "Usage: %s -B BaseAddress -S Size -F FillByte"" [-I FvInfFileName] -O OutputFileName \n",
- UTILITY_NAME
- );
- printf (" Where:\n");
- printf ("\tBaseAddress is the starting address of the FD Image\n\n");
- printf ("\tSize is the size of the FD Image.\n\n");
- printf ("\tFillByte is the desired value of free space in the Image\n\n");
- printf ("\tFvInfFileName is the name of an FV Image description file.\n\n");
- printf ("\tOutputFileName is the desired output file name.\n\n");
-}
-
-EFI_STATUS
-main (
- IN INTN argc,
- IN CHAR8 **argv
- )
-/*++
-
-Routine Description:
-
- This utility uses GenFdImage.lib to build a Firmware Device Image
- which will include several Firmware Volume Images.
-
-Arguments:
-
- Base Address Base Address of the firmware volume..
- Size Size of the Firmware Volume
- FillByte The byte value which would be needed to pad
- between various Firmware Volumes
- FvInfFile Fv inf file
- OutputFileName The name of output file which would be created
-
-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.
-
---*/
-// GC_TODO: argc - add argument and description to function comment
-// GC_TODO: argv - add argument and description to function comment
-{
- UINTN Index;
- UINTN FvFilesCount;
-
- UINT8 i;
-
- UINT64 StartAddress;
- UINT64 Size;
- UINT64 FillByteVal;
-
- CHAR8 **FvInfFileList;
- CHAR8 **OrgFvInfFileList;
- CHAR8 OutputFileName[_MAX_PATH];
-
- EFI_STATUS Status;
-
- INTN arg_counter;
-
- //
- // Echo for makefile debug
- //
- printf ("\n\n");
- for (arg_counter = 0; arg_counter < argc; arg_counter++) {
- printf ("%s ", argv[arg_counter]);
- }
-
- printf ("\n\n");
-
- //
- // Display utility information
- //
- PrintUtilityInfo ();
-
- //
- // Verify the correct number of arguments
- //
- if (argc < MIN_ARGS) {
- printf ("ERROR: missing 1 or more input arguments.\n\n");
- PrintUsage ();
- return EFI_INVALID_PARAMETER;
- }
- //
- // Initialize variables
- //
- StartAddress = 0;
- Size = 0;
- FillByteVal = 0;
- FvFilesCount = 0;
-
- for (i = 1; i < argc; i++) {
- if (stricmp (argv[i], "-I") == 0) {
- FvFilesCount++;
- }
- }
-
- FvInfFileList = malloc (sizeof (UINTN) * (FvFilesCount + 1));
- if (FvInfFileList == NULL) {
- printf ("ERROR: allocating memory for FvInfFileList in -main- function.\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- memset (FvInfFileList, 0, sizeof (UINTN) * (FvFilesCount + 1));
-
- OrgFvInfFileList = FvInfFileList;
-
- for (Index = 0; Index < FvFilesCount; Index++) {
- *FvInfFileList = malloc (_MAX_PATH);
- memset (*FvInfFileList, 0, _MAX_PATH);
- FvInfFileList++;
- }
-
- strcpy (OutputFileName, "");
-
- //
- // Parse the command line arguments
- //
- FvInfFileList = OrgFvInfFileList;
-
- for (i = 1; i < argc; i += 2) {
- //
- // Make sure argument pair begin with - or /
- //
- if (argv[i][0] != '-' && argv[i][0] != '/') {
- PrintUsage ();
- printf ("ERROR: Argument pair must begin with \"-\" or \"/\"\n");
- return EFI_INVALID_PARAMETER;
- }
- //
- // Make sure argument specifier is only one letter
- //
- if (argv[i][2] != 0) {
- PrintUsage ();
- printf ("ERROR: Unrecognized argument \"%s\".\n", argv[i]);
- return EFI_INVALID_PARAMETER;
- }
- //
- // Determine argument to read
- //
- switch (argv[i][1]) {
-
- case 'I':
- case 'i':
- if ((FvInfFileList != NULL) && (strlen (*FvInfFileList) == 0)) {
- strcpy (*FvInfFileList, argv[i + 1]);
- FvInfFileList++;
- } else {
- printf ("ERROR: FvInfFile Name is more than specifed.\n");
- return EFI_INVALID_PARAMETER;
- }
- break;
-
- case 'O':
- case 'o':
- if (strlen (OutputFileName) == 0) {
- strcpy (OutputFileName, argv[i + 1]);
- } else {
- PrintUsage ();
- printf ("ERROR: OutputFileName may only be specified once.\n");
- return EFI_INVALID_PARAMETER;
- }
- break;
-
- case 'B':
- case 'b':
- Status = AsciiStringToUint64 (argv[i + 1], FALSE, &StartAddress);
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Bad FD Image start address specified");
- return EFI_INVALID_PARAMETER;
- }
- break;
-
- case 'S':
- case 's':
- Status = AsciiStringToUint64 (argv[i + 1], FALSE, &Size);
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Bad FD Image size specified");
- return EFI_INVALID_PARAMETER;
- }
- break;
-
- case 'F':
- case 'f':
- Status = AsciiStringToUint64 (argv[i + 1], FALSE, &FillByteVal);
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Not a recognized Fill Byte value");
- return EFI_INVALID_PARAMETER;
- }
- break;
-
- default:
- PrintUsage ();
- printf ("ERROR: Unrecognized argument \"%s\".\n", argv[i]);
- return EFI_INVALID_PARAMETER;
- break;
- }
- }
- //
- // Call the GenFdImage Lib
- //
- FvInfFileList = OrgFvInfFileList;
-
- Status = GenerateFdImage (
- StartAddress,
- Size,
- (UINT8) FillByteVal,
- OutputFileName,
- FvInfFileList
- );
-
- if (EFI_ERROR (Status)) {
- switch (Status) {
-
- case EFI_INVALID_PARAMETER:
- printf ("\nERROR: Invalid parameter passed to GenFdImage lib.\n");
- break;
-
- case EFI_ABORTED:
- printf ("\nERROR: Error detected while creating the file image.\n");
- break;
-
- case EFI_OUT_OF_RESOURCES:
- printf ("\nERROR: GenFdImage Lib could not allocate required resources.\n");
- break;
-
- case EFI_VOLUME_CORRUPTED:
- printf ("\nERROR: No base address was specified \n");
- break;
-
- case EFI_LOAD_ERROR:
- printf ("\nERROR: An error occurred loading one of the required support Lib.\n");
- break;
-
- default:
- printf ("\nERROR: GenFdImage lib returned unknown status %X.\n", Status);
- break;
- }
-
- return Status;
- }
-
- return EFI_SUCCESS;
-}
diff --git a/Tools/Source/TianoTools/GenFdImage/GenFdImageExe.h b/Tools/Source/TianoTools/GenFdImage/GenFdImageExe.h deleted file mode 100644 index e07cb23..0000000 --- a/Tools/Source/TianoTools/GenFdImage/GenFdImageExe.h +++ /dev/null @@ -1,91 +0,0 @@ -/*++
-
-Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
-This software and associated documentation (if any) is furnished
-under a license and may only be used or copied in accordance
-with the terms of the license. Except as permitted by such
-license, no part of this software or documentation may be
-reproduced, stored in a retrieval system, or transmitted in any
-form or by any means without the express written consent of
-Intel Corporation.
-
-
-Module Name:
-
- GenFdImageExe.h
-
-Abstract:
-
- Definitions for the Boot Strap File Image generation utility.
-
---*/
-
-#ifndef _EFI_GEN_FD_IMAGE_EXE_H
-#define _EFI_GEN_FD_IMAGE_EXE_H
-
-//
-// Utility Name
-//
-#define UTILITY_NAME "GenFdImage"
-
-//
-// Utility version information
-//
-#define UTILITY_MAJOR_VERSION 0
-#define UTILITY_MINOR_VERSION 0
-#define UTILITY_DATE __DATE__
-
-//
-// The maximum number of arguments accepted from the command line.
-//
-#define MIN_ARGS 10
-
-//
-// The function that displays general utility information
-//
-VOID
-PrintUtilityInfo (
- VOID
- )
-/*++
-
-Routine Description:
-
- GC_TODO: Add function description
-
-Arguments:
-
- None
-
-Returns:
-
- GC_TODO: add return values
-
---*/
-;
-
-//
-// The function that displays the utility usage message.
-//
-VOID
-PrintUsage (
- VOID
- )
-/*++
-
-Routine Description:
-
- GC_TODO: Add function description
-
-Arguments:
-
- None
-
-Returns:
-
- GC_TODO: add return values
-
---*/
-;
-
-#endif
diff --git a/Tools/Source/TianoTools/GenFdImage/GenFdImageLib.c b/Tools/Source/TianoTools/GenFdImage/GenFdImageLib.c deleted file mode 100644 index 39698d9..0000000 --- a/Tools/Source/TianoTools/GenFdImage/GenFdImageLib.c +++ /dev/null @@ -1,848 +0,0 @@ -/*++
-
-Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
-This software and associated documentation (if any) is furnished
-under a license and may only be used or copied in accordance
-with the terms of the license. Except as permitted by such
-license, no part of this software or documentation may be
-reproduced, stored in a retrieval system, or transmitted in any
-form or by any means without the express written consent of
-Intel Corporation.
-
-
-Module Name:
-
- GenFdImageLib.C
-
-Abstract:
-
- This file contains the functions required to generate
- the Firmware Device
-
---*/
-
-//
-// Coded to EFI 2.0 Coding Standards
-//
-//
-// Include file in build
-//
-#include "GenFdImage.h"
-
-//
-// Global declarations
-//
-UINTN ValidLineNum = 0;
-UINTN NumFvFiles = 0;
-
-static UINT64 LastAddress = 0;
-
-CHAR8 **TokenStr;
-CHAR8 **OrgStrTokPtr;
-
-FDINFO *FdInfo;
-FDINFO *OrgFdInfoPtr;
-
-FVINFO **FvInfo;
-FVINFO **OrgFvInfoPtr;
-
-//
-// Internal Functions
-//
-INTN
-CompareItems (
- IN const VOID *Arg1,
- IN const VOID *Arg2
- )
-/*++
-
-Routine Description:
-
- This function is used by qsort to sort the Fv list based on FvBaseAddress
-
-Arguments:
-
- Arg1
- Arg2
-
-Returns:
-
- None
-
---*/
-// GC_TODO: Arg1 - add argument and description to function comment
-// GC_TODO: Arg2 - add argument and description to function comment
-{
- if ((*(FVINFO **) Arg1)->FvBaseAddress > (*(FVINFO **) Arg2)->FvBaseAddress) {
- return 1;
- } else if ((*(FVINFO **) Arg1)->FvBaseAddress < (*(FVINFO **) Arg2)->FvBaseAddress) {
- return -1;
- } else {
- return 0;
- }
-}
-
-VOID
-BuildTokenList (
- IN CHAR8 *Token
- )
-/*++
-
-Routine Description:
-
- This function builds the token list in an array which will be parsed later
-
-Arguments:
-
- Token String,
-
-Returns:
-
- None
-
---*/
-{
- strcpy (*TokenStr, Token);
- TokenStr++;
-}
-
-VOID
-TrimLine (
- IN CHAR8 *Line
- )
-/*++
-
-Routine Description:
-
- This function cleans up the line by removing all whitespace and
- comments.
-
-Arguments:
-
- Line String,
-
-Returns:
-
- None
-
---*/
-{
- CHAR8 TmpLine[FILE_NAME_SIZE];
- CHAR8 c;
- CHAR8 *Ptr0;
-
- UINTN i;
- UINTN j;
-
- //
- // Change '#' to '//' for Comment style
- //
- // if((Ptr0=strchr(Line, '#')) != NULL) {
- //
- if ((Ptr0 = strstr (Line, "//")) != NULL) {
- Line[Ptr0 - Line] = 0;
- }
-
- i = 0;
- j = 0;
- while ((c = Line[i]) != 0) {
- if ((c != ' ') && (c != '\t') && (c != '\n')) {
- TmpLine[j++] = c;
- }
-
- i++;
- }
-
- TmpLine[j] = 0;
- strcpy (Line, TmpLine);
-}
-
-VOID
-ValidLineCount (
- IN FILE *Fp
- )
-/*++
-
-Routine Description:
-
- This function calculates number of valid lines in a input file.
-
-Arguments:
-
- Fp Pointer to a file handle which has been opened.
-
-Returns:
-
- None
-
---*/
-{
- CHAR8 Buff[FILE_NAME_SIZE];
-
- while (fgets (Buff, sizeof (Buff), Fp)) {
- TrimLine (Buff);
- if (Buff[0] == 0) {
- continue;
- }
-
- ValidLineNum++;
- }
-}
-
-VOID
-ParseInputFile (
- IN FILE *Fp
- )
-/*++
-
-Routine Description:
-
- This function parses the input file and tokenizes the string
-
-Arguments:
-
- Fp Pointer to a file handle which has been opened.
-
-Returns:
-
- None
-
---*/
-{
- CHAR8 *Token;
- CHAR8 Buff[FILE_NAME_SIZE];
- CHAR8 OrgLine[FILE_NAME_SIZE];
- CHAR8 Str[FILE_NAME_SIZE];
- CHAR8 Delimit[] = "=";
-
- while (fgets (Buff, sizeof (Buff), Fp) != NULL) {
- strcpy (OrgLine, Buff);
- TrimLine (Buff);
-
- if (Buff[0] == 0) {
- continue;
- }
-
- Token = strtok (Buff, Delimit);
-
- while (Token != NULL) {
- strcpy (Str, Token);
- BuildTokenList (Str);
- Token = strtok (NULL, Delimit);
- }
- }
-}
-
-EFI_STATUS
-InitializeComps (
- VOID
- )
-/*++
-
-Routine Description:
-
- This function intializes the relevant global variable
- used to store the information retrieved from the INF file.
-
-Arguments:
-
- None
-
-Returns:
-
- EFI_STATUS
-
---*/
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- UINTN Index;
-
- FdInfo = malloc (sizeof (FDINFO));
-
- if (FdInfo == NULL) {
- printf ("ERROR: allocating memory (struct FDINFO) in"" function InitializeComps.\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- OrgFdInfoPtr = FdInfo;
-
- FvInfo = malloc (sizeof (INTN) * NumFvFiles);
-
- if (FvInfo == NULL) {
- printf ("ERROR: allocating memory (INTN * NumFvFiles) in"" function InitializeComps.\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- OrgFvInfoPtr = FvInfo;
-
- for (Index = 0; Index < NumFvFiles; Index++) {
- *FvInfo = malloc (sizeof (FVINFO));
-
- if (*FvInfo == NULL) {
- printf ("ERROR: allocating memory (FVINFO) in"" function InitializeComps.\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- memset (*FvInfo, 0, sizeof (FVINFO));
- FvInfo++;
- }
-
- FvInfo = OrgFvInfoPtr;
-
- return EFI_SUCCESS;
-}
-
-VOID
-InitializeInFileInfo (
- VOID
- )
-/*++
-
-Routine Description:
-
- This function intializes the relevant global variable
- used to store the information retrieved from the INF file.
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- UINTN OptionFlag;
-
- UINT64 StringValue;
-
- OptionFlag = 0;
- TokenStr = OrgStrTokPtr;
-
- while (*TokenStr != NULL) {
- if (stricmp (*TokenStr, "[options]") == 0) {
- OptionFlag = 1;
- }
-
- if (OptionFlag) {
- if (stricmp (*TokenStr, "EFI_FV_BASE_ADDRESS") == 0) {
- *TokenStr++;
- if (AsciiStringToUint64 (
- *TokenStr,
- FALSE,
- &StringValue
- ) != EFI_SUCCESS) {
- printf ("\nERROR: Cannot determine the FV base address.");
- return ;
- }
- (*FvInfo)->FvBaseAddress = StringValue;
- } else if (stricmp (*TokenStr, "EFI_FV_FILE_NAME") == 0) {
- *TokenStr++;
- strcpy ((*FvInfo)->FvFile, *TokenStr);
- }
- }
-
- TokenStr++;
- }
-}
-
-EFI_STATUS
-GetFvRelatedInfoFromInfFile (
- IN CHAR8 *FileName
- )
-/*++
-
-Routine Description:
-
- This function reads the input file, parses it and create a list of tokens
- which are parsed and used, to intialize the data related to the Firmware
- Volume.
-
-Arguments:
-
- FileName FileName which needed to be read to parse data
-
-Returns:
-
- EFI_STATUS
-
---*/
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- FILE *Fp;
-
- UINTN Index;
-
- Fp = fopen (FileName, "r");
-
- if (Fp == NULL) {
- printf ("Error in opening %s file\n", FileName);
- return EFI_ABORTED;
- }
-
- ValidLineCount (Fp);
-
- if (ValidLineNum == 0) {
- printf ("\nFile doesn't contain any valid informations");
- return EFI_ABORTED;
- }
-
- TokenStr = (CHAR8 **) malloc (sizeof (UINTN) * (2 * ValidLineNum));
- memset (TokenStr, 0, sizeof (UINTN) * (2 * ValidLineNum));
- OrgStrTokPtr = TokenStr;
-
- for (Index = 0; Index < (2 * ValidLineNum); Index++) {
- *TokenStr = (CHAR8 *) malloc (sizeof (CHAR8) * FILE_NAME_SIZE);
- memset (*TokenStr, 0, FILE_NAME_SIZE);
- TokenStr++;
- }
-
- *TokenStr = NULL;
- TokenStr = OrgStrTokPtr;
- fseek (Fp, 0L, SEEK_SET);
-
- ParseInputFile (Fp);
- InitializeInFileInfo ();
-
- if (Fp) {
- fclose (Fp);
- }
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-WriteFwBinary (
- IN CHAR8 *FileName,
- IN UINT64 StartAddress,
- IN UINT64 Size,
- IN UINT8 *Buffer
- )
-/*++
-
-Routine Description:
-
- This function reads the input file, parses it and creates a list of tokens
- which are parsed and used to intialize the data related to the Firmware
- Volume.
-
-Arguments:
-
- FileName FileName which needed to be read to parse data
- StartAddress This will set the file position.
- Size Size in bytes needed to be written
- Buffer Buffer needed to e written
-
-Returns:
-
- EFI_STATUS
-
---*/
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- FILE *Fp;
-
- UINTN NumByte;
-
- Fp = fopen (FileName, "a+b");
-
- if (Fp == NULL) {
- printf ("\nERROR:Error in opening file %s ", FileName);
- return EFI_INVALID_PARAMETER;
- }
-
- fseek (Fp, (UINTN) StartAddress, SEEK_SET);
- NumByte = fwrite ((VOID *) Buffer, sizeof (UINT8), (UINTN) Size, Fp);
-
- //
- // Check to ensure that buffer has been copied successfully
- //
- if (NumByte != Size) {
- printf ("\nERROR: Error in copying the buffer into file");
- return EFI_ABORTED;
- }
-
- if (Fp) {
- fclose (Fp);
- }
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-BuildFirmwareDeviceBinaryFromFwVolumes (
- IN UINT64 FvBaseAddress,
- IN CHAR8 *FvFileName,
- IN CHAR8 *FdFileName
- )
-/*++
-
-Routine Description:
-
- This function reads the input file, parses it and creates a list of tokens
- which are parsed and used to intialize the data related to the Firmware
- Volume.
-
-Arguments:
-
- FvBaseAddress Base Address. This info is retrieved from INF file
- FvFileName InputFileName
- FdFileName Output File Name
-
-Returns:
-
- EFI_STATUS
-
---*/
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- FILE *Fp;
-
- UINT64 FileSize;
- UINT64 NumByteRead;
- UINT64 PadByteSize;
- UINT64 BaseAddress;
-
- UINTN Index;
-
- UINT8 *Buffer;
-
- EFI_STATUS Status;
-
- static UINT64 StartAddress = 0;
-
- Fp = fopen (FvFileName, "r+b");
-
- if (Fp == NULL) {
- printf ("\nERROR:Error in opening file %s", FvFileName);
- return EFI_ABORTED;
- }
-
- BaseAddress = FdInfo->FdBaseAddress;
-
- //
- // Check if Base Address of Firmware Volume falls below the Base Address
- // Firmware Device, if yes, then abort this process.
- //
- if (FvBaseAddress < BaseAddress) {
- printf ("\nERROR: Firmware Volume Base Address falls below Firmware ""Device Address.\n");
- return EFI_ABORTED;
- }
- //
- // Check if there are any holes between two Firmware Volumes. If any holes
- // exist, fill the hole with PadByted data.
- //
- if (FvBaseAddress > LastAddress) {
- PadByteSize = (FvBaseAddress - LastAddress);
- Buffer = malloc ((UINTN) PadByteSize);
- if (Buffer == NULL) {
- printf ("ERROR: allocating (Buffer) memory in"" function BuildFirmwareDeviceBinaryFromFwVolumes.\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- for (Index = 0; Index < PadByteSize; Index++) {
- *Buffer = FdInfo->PadValue;
- Buffer++;
- }
-
- Buffer -= PadByteSize;
- Status = WriteFwBinary (
- FdFileName,
- StartAddress,
- (UINT64) PadByteSize,
- Buffer
- );
-
- if (Buffer) {
- free (Buffer);
- }
-
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Error in writing the binary image to file");
- return Status;
- }
-
- StartAddress += PadByteSize;
- LastAddress += PadByteSize;
- }
- //
- // Proceed with next Firmware Volume updates
- //
- FileSize = _filelength (fileno (Fp));
-
- if ((FvBaseAddress + FileSize) > (FdInfo->FdBaseAddress + FdInfo->FdSize)) {
- printf (
- "\nERROR:Unable to update Firmware Device. File %s is larger than \
- available space.",
- FvFileName
- );
- if (Fp) {
- fclose (Fp);
- }
-
- return EFI_ABORTED;
- }
-
- Buffer = malloc ((UINTN) FileSize);
-
- if (Buffer == NULL) {
- printf ("Error in allocating buffer to read specific file\n");
- return EFI_OUT_OF_RESOURCES;
- }
-
- NumByteRead = fread ((VOID *) Buffer, sizeof (UINT8), (UINTN) FileSize, Fp);
-
- Status = WriteFwBinary (FdFileName, StartAddress, FileSize, Buffer);
-
- if (Buffer) {
- free ((VOID *) Buffer);
- }
-
- if (Fp) {
- fclose (Fp);
- }
-
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Error in writing the binary image to file");
- return Status;
- }
-
- StartAddress += NumByteRead;
- LastAddress += FileSize;
-
- return EFI_SUCCESS;
-}
-
-VOID
-CleanUpMemory (
- VOID
- )
-/*++
-
-Routine Description:
-
- This function cleans up any allocated buffer
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- UINTN Index;
-
- if (FdInfo) {
- free (FdInfo);
- }
-
- FvInfo = OrgFvInfoPtr;
-
- if (FvInfo) {
- for (Index = 0; Index < NumFvFiles; Index++) {
- if (*FvInfo) {
- free (*FvInfo);
- }
-
- FvInfo++;
- }
-
- FvInfo = OrgFvInfoPtr;
- free (FvInfo);
- }
-}
-
-EFI_STATUS
-GenerateFdImage (
- IN UINT64 BaseAddress,
- IN UINT64 Size,
- IN UINT8 PadByte,
- IN CHAR8 *OutFile,
- IN CHAR8 **FileList
- )
-/*++
-
-Routine Description:
-
- This function reads the input file, parses it and creates a list of tokens
- which are parsed and used to intialize the data related to the Firmware
- Volume.
-
-Arguments:
-
- BaseAddress Base Address for this Firmware Device
- Size, Total Size of the Firmware Device
- PadByte Pad byte data
- OutFile Output File Name
- FileList File List pointer to INF file names.
-
-Returns:
-
- EFI_STATUS
-
---*/
-// GC_TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_ABORTED - add return value to function comment
-// GC_TODO: EFI_SUCCESS - add return value to function comment
-{
- EFI_STATUS Status;
-
- UINTN Index;
- UINTN PadSize;
- UINTN FileSize;
- UINTN NumByte;
-
- CHAR8 **InFile;
-
- FILE *Fp;
-
- UINT8 *Buffer;
-
- //
- // If any previous Firmware Device existed,
- // make it to 0 bytes
- //
- if ((Fp = fopen (OutFile, "w")) != NULL) {
- fclose (Fp);
- }
-
- InFile = FileList;
-
- while (*InFile != NULL) {
- NumFvFiles++;
- InFile++;
- }
-
- InitializeComps ();
-
- //
- // Restore the orginal pointers
- //
- FvInfo = OrgFvInfoPtr;
- InFile = FileList;
-
- while (*InFile != NULL) {
- strcpy ((*FvInfo)->FvInfoFile, *InFile);
- Status = GetFvRelatedInfoFromInfFile (*InFile);
-
- if (Status != EFI_SUCCESS) {
- printf ("\nERROR: Error occurred in processsing INF file");
- CleanUpMemory ();
- return Status;
- }
-
- InFile++;
- FvInfo++;
- }
-
- FdInfo->FdSize = Size;
- FdInfo->FdBaseAddress = BaseAddress;
- FdInfo->PadValue = PadByte;
- FvInfo = OrgFvInfoPtr;
- strcpy (FdInfo->OutFileName, OutFile);
-
- for (Index = 0; Index < NumFvFiles; Index++) {
- Status = GenerateFvImage ((*FvInfo)->FvInfoFile);
-
- if (Status != EFI_SUCCESS) {
- CleanUpMemory ();
- return Status;
- }
-
- FvInfo++;
- }
-
- FvInfo = OrgFvInfoPtr;
-
- //
- // Sort the Firmware Volume information. Firmware Volume with lower
- // base addresses will be processed first and higher base address one
- // will be processed later.
- //
- qsort ((VOID *) FvInfo, NumFvFiles, sizeof (FVINFO *), CompareItems);
-
- LastAddress = (*FvInfo)->FvBaseAddress;
-
- for (Index = 0; Index < NumFvFiles; Index++) {
- Status = BuildFirmwareDeviceBinaryFromFwVolumes (
- (*FvInfo)->FvBaseAddress,
- (*FvInfo)->FvFile,
- FdInfo->OutFileName
- );
- if (Status != EFI_SUCCESS) {
- CleanUpMemory ();
- return Status;
- }
-
- FvInfo++;
- }
- //
- // Check if any space left after copying data from all Firmware Volumes
- // If yes, then fill those location with PadValue.
- //
- if ((FdInfo->FdBaseAddress + Size) > LastAddress) {
-
- PadSize = (UINTN) ((FdInfo->FdBaseAddress + FdInfo->FdSize) - LastAddress);
- Buffer = malloc (PadSize);
-
- if (Buffer == NULL) {
- printf ("\nERROR: allocating PadSize memory in function GenerateFdImage.\n");
- CleanUpMemory ();
- return EFI_OUT_OF_RESOURCES;
- }
-
- for (Index = 0; Index < PadSize; Index++) {
- *Buffer = FdInfo->PadValue;
- Buffer++;
- }
-
- Buffer -= PadSize;
-
- Fp = fopen (OutFile, "a+b");
-
- if (Fp == NULL) {
- printf ("\nERROR:Opening file %s", OutFile);
- CleanUpMemory ();
- return EFI_ABORTED;
- }
-
- FileSize = _filelength (fileno (Fp));
- fseek (Fp, FileSize, SEEK_SET);
- NumByte = fwrite (Buffer, sizeof (UINT8), PadSize, Fp);
-
- if (Buffer) {
- free (Buffer);
- }
-
- fclose (Fp);
-
- if (NumByte != (sizeof (UINT8) * PadSize)) {
- printf ("\nERROR: Copying data from buffer to File %s ", OutFile);
- CleanUpMemory ();
- return EFI_ABORTED;
- }
- }
- //
- // Clean up all the memory which has been allocated so far.
- //
- CleanUpMemory ();
-
- return EFI_SUCCESS;
-}
|