diff options
author | lhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-05-19 02:38:56 +0000 |
---|---|---|
committer | lhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-05-19 02:38:56 +0000 |
commit | d25c4bf080b9820d15b7c329cf42775010dbcc56 (patch) | |
tree | fddbcf8d4a8d5a7730f9dc5a44b09efba8d50e33 /Tools/Source/TianoTools/SecFixup | |
parent | 291a871a27d0bbcebede5b62a5e23d03f20a54fc (diff) | |
download | edk2-platforms-d25c4bf080b9820d15b7c329cf42775010dbcc56.tar.xz |
Adding Additional Tools that are needed for Platform Image creation.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@198 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Tools/Source/TianoTools/SecFixup')
-rw-r--r-- | Tools/Source/TianoTools/SecFixup/Makefile | 57 | ||||
-rw-r--r-- | Tools/Source/TianoTools/SecFixup/SecFixup.c | 362 | ||||
-rw-r--r-- | Tools/Source/TianoTools/SecFixup/SecFixup.h | 146 |
3 files changed, 565 insertions, 0 deletions
diff --git a/Tools/Source/TianoTools/SecFixup/Makefile b/Tools/Source/TianoTools/SecFixup/Makefile new file mode 100644 index 0000000000..6ae2ebd31a --- /dev/null +++ b/Tools/Source/TianoTools/SecFixup/Makefile @@ -0,0 +1,57 @@ +#/*++
+#
+# Copyright (c) 2001 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: makefile
+#
+# Abstract:
+#
+# This file is used to build the EFI utility.
+#
+#--*/
+
+#
+# Do this if you want to compile from this directory
+#
+!IFNDEF TOOLCHAIN
+TOOLCHAIN = TOOLCHAIN_MSVC
+!ENDIF
+
+!INCLUDE PlatformTools.env
+
+#
+# Target specific information
+#
+
+TARGET_NAME = SecFixup
+TARGET_SOURCE_DIR = $(TIANO_TOOLS_SOURCE)\$(TARGET_NAME)
+TARGET_EXE = $(TIANO_TOOLS_OUTPUT)\$(TARGET_NAME).exe
+TARGET_EXE_SOURCE = $(TARGET_SOURCE_DIR)\$(TARGET_NAME).c
+
+#
+# Build targets
+#
+
+all: $(TARGET_EXE)
+
+OBJECTS = $(TIANO_TOOLS_OUTPUT)\$(TARGET_NAME).obj
+
+#
+# Build EXE
+#
+
+$(OBJECTS) : $(TARGET_EXE_SOURCE) $(INC_DEPS)
+ $(CC) $(C_FLAGS) $(TARGET_EXE_SOURCE) /Fo$@
+
+$(TARGET_EXE): $(OBJECTS)
+ $(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(OBJECTS) $(LIBS) /out:$(TARGET_EXE)
+
+clean:
+ @if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL
diff --git a/Tools/Source/TianoTools/SecFixup/SecFixup.c b/Tools/Source/TianoTools/SecFixup/SecFixup.c new file mode 100644 index 0000000000..a8e707fd16 --- /dev/null +++ b/Tools/Source/TianoTools/SecFixup/SecFixup.c @@ -0,0 +1,362 @@ +/*++
+
+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:
+
+ SecFixup.c
+
+Abstract:
+
+ This utility is part of build process for IA32 SEC FFS file.
+
+ It fixup the reset vector data. The reset vector data binary file
+ will be wrapped as a RAW section and be located immediately after
+ the PE/TE section.
+
+ The SEC EXE file can be either PE or TE file.
+
+--*/
+
+#include <stdio.h>
+
+#include "EfiCommon.h"
+#include "EfiImage.h"
+#include "EfiImageFormat.h"
+#include "EfiUtilityMsgs.c"
+
+#include "SecFixup.h"
+
+VOID
+PrintUtilityInfo (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ Displays the standard utility information to SDTOUT
+
+Arguments:
+
+ None
+
+Returns:
+
+ None
+
+--*/
+{
+ printf (
+ "%s - Tiano IA32 SEC Fixup 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 SecExeFile ResetVectorDataFile OutputFile\n", UTILITY_NAME);
+ printf (" Where:\n");
+ printf ("\tSecExeFile - Name of the IA32 SEC EXE file.\n");
+ printf ("\tResetVectorDataFile - Name of the reset vector data binary file.\n");
+ printf ("\tOutputFileName - Name of the output file.\n\n");
+}
+
+STATUS
+main (
+ IN INTN argc,
+ IN CHAR8 **argv
+ )
+/*++
+
+Routine Description:
+
+ Main function.
+
+Arguments:
+
+ argc - Number of command line parameters.
+ argv - Array of pointers to parameter strings.
+
+Returns:
+ STATUS_SUCCESS - Utility exits successfully.
+ STATUS_ERROR - Some error occurred during execution.
+
+--*/
+{
+ FILE *FpIn;
+
+ FILE *FpOut;
+ UINT32 AddressOfEntryPoint;
+ INT32 DestRel;
+ STATUS Status;
+ UINT32 SecFileSize;
+
+ 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 STATUS_ERROR;
+ }
+ //
+ // Open the SEC exe file
+ //
+ if ((FpIn = fopen (argv[1], "rb")) == NULL) {
+ Error (NULL, 0, 0, "Unable to open file", argv[1]);
+ return STATUS_ERROR;
+ }
+ //
+ // Get the entry point of the EXE file
+ //
+ Status = GetEntryPoint (FpIn, &AddressOfEntryPoint);
+ if (Status != STATUS_SUCCESS) {
+ fclose (FpIn);
+ return STATUS_ERROR;
+ }
+ //
+ // Get the SEC file size
+ //
+ fseek (FpIn, 0, SEEK_END);
+ SecFileSize = ftell (FpIn);
+
+ //
+ // Close the SEC file
+ //
+ fclose (FpIn);
+
+ //
+ // Open the reset vector data file
+ //
+ if ((FpIn = fopen (argv[2], "rb")) == NULL) {
+ Error (NULL, 0, 0, "Unable to open file", argv[2]);
+ return STATUS_ERROR;
+ }
+ //
+ // Open the output file
+ //
+ if ((FpOut = fopen (argv[3], "w+b")) == NULL) {
+ Error (NULL, 0, 0, "Unable to open file", argv[3]);
+ fclose (FpIn);
+ return STATUS_ERROR;
+ }
+ //
+ // Copy the input file to the output file
+ //
+ if (CopyFile (FpIn, FpOut) != STATUS_SUCCESS) {
+ fclose (FpIn);
+ fclose (FpOut);
+ return STATUS_ERROR;
+ }
+ //
+ // Close the reset vector data file
+ //
+ fclose (FpIn);
+
+ //
+ // Fix the destination relative in the jmp instruction
+ // in the reset vector data structure
+ //
+ fseek (FpOut, -DEST_REL_OFFSET, SEEK_END);
+ DestRel = AddressOfEntryPoint - (SecFileSize + sizeof (EFI_COMMON_SECTION_HEADER) + (UINT32) (ftell (FpOut)) + 2);
+ if (DestRel <= -65536) {
+ Error (NULL, 0, 0, "The SEC EXE file size is too big", NULL);
+ fclose (FpOut);
+ return STATUS_ERROR;
+ }
+
+ if (fwrite (&DestRel, sizeof (UINT16), 1, FpOut) != 1) {
+ Error (NULL, 0, 0, "Failed to write to the output file", NULL);
+ fclose (FpOut);
+ return STATUS_ERROR;
+ }
+ //
+ // Close the output file
+ //
+ fclose (FpOut);
+
+ return STATUS_SUCCESS;
+}
+
+STATUS
+GetEntryPoint (
+ IN FILE *ExeFile,
+ OUT UINT32 *EntryPoint
+ )
+/*++
+
+Routine Description:
+
+ Get the address of the entry point of a PE/TE file.
+
+Arguments:
+
+ PeFile - File pointer to the specified PE/TE file.
+ EntryPoint - Buffer for the address of the entry point to be returned.
+
+Returns:
+ STATUS_SUCCESS - Function completed successfully.
+ STATUS_ERROR - Error occured.
+
+--*/
+// GC_TODO: ExeFile - add argument and description to function comment
+{
+ EFI_IMAGE_DOS_HEADER DosHeader;
+ EFI_IMAGE_NT_HEADERS32 NtHeader;
+ EFI_TE_IMAGE_HEADER TeHeader;
+
+ //
+ // Check if it is a TE file
+ //
+ fseek (ExeFile, 0, SEEK_SET);
+ //
+ // Attempt to read the TE header
+ //
+ if (fread (&TeHeader, sizeof (TeHeader), 1, ExeFile) == 1) {
+ if (TeHeader.Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
+ if (TeHeader.Machine != EFI_IMAGE_MACHINE_IA32) {
+ Error (NULL, 0, 0, "The SEC file is PE but is not PE32 for IA32", NULL);
+ return STATUS_ERROR;
+ }
+
+ *EntryPoint = TeHeader.AddressOfEntryPoint + sizeof (EFI_TE_IMAGE_HEADER) - TeHeader.StrippedSize;
+ return STATUS_SUCCESS;
+ }
+ }
+ //
+ // Check if it is a PE file
+ //
+ fseek (ExeFile, 0, SEEK_SET);
+ //
+ // Attempt to read the DOS header
+ //
+ if (fread (&DosHeader, sizeof (DosHeader), 1, ExeFile) != 1) {
+ goto InvalidFile;
+ }
+ //
+ // Check the magic number
+ //
+ if (DosHeader.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
+ goto InvalidFile;
+ }
+ //
+ // Position into the file and read the NT PE header
+ //
+ fseek (ExeFile, (long) DosHeader.e_lfanew, SEEK_SET);
+ if (fread (&NtHeader, sizeof (NtHeader), 1, ExeFile) != 1) {
+ goto InvalidFile;
+ }
+ //
+ // Check the PE signature in the header
+ //
+ if (NtHeader.Signature != EFI_IMAGE_NT_SIGNATURE) {
+ goto InvalidFile;
+ }
+ //
+ // Make sure the PE file is PE32 for IA32
+ //
+ if (NtHeader.FileHeader.Machine != EFI_IMAGE_MACHINE_IA32 ||
+ NtHeader.OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
+ ) {
+ Error (NULL, 0, 0, "The SEC file is PE but is not PE32 for IA32", NULL);
+ return STATUS_ERROR;
+ }
+ //
+ // Get the entry point from the optional header
+ //
+ *EntryPoint = NtHeader.OptionalHeader.AddressOfEntryPoint;
+ return STATUS_SUCCESS;
+
+InvalidFile:
+ Error (NULL, 0, 0, "The SEC file is neither PE nor TE file", NULL);
+ return STATUS_ERROR;
+}
+
+STATUS
+CopyFile (
+ FILE *FpIn,
+ FILE *FpOut
+ )
+/*++
+
+Routine Description:
+
+ Copy file.
+
+Arguments:
+
+ FpIn - File pointer to the source file.
+ FpOut - File pointer to the destination file.
+
+Returns:
+ STATUS_SUCCESS - Function completed successfully.
+ STATUS_ERROR - Error occured.
+
+--*/
+{
+ INTN FileSize;
+
+ INTN Offset;
+
+ INTN Length;
+ UINT8 Buffer[BUF_SIZE];
+
+ fseek (FpIn, 0, SEEK_END);
+ FileSize = ftell (FpIn);
+
+ fseek (FpIn, 0, SEEK_SET);
+ fseek (FpOut, 0, SEEK_SET);
+
+ Offset = 0;
+ while (Offset < FileSize) {
+ Length = sizeof (Buffer);
+ if (FileSize - Offset < Length) {
+ Length = FileSize - Offset;
+ }
+
+ if (fread (Buffer, Length, 1, FpIn) != 1 || fwrite (Buffer, Length, 1, FpOut) != 1) {
+ Error (NULL, 0, 0, "Copy file error", NULL);
+ return STATUS_ERROR;
+ }
+
+ Offset += Length;
+ }
+
+ return STATUS_SUCCESS;
+}
diff --git a/Tools/Source/TianoTools/SecFixup/SecFixup.h b/Tools/Source/TianoTools/SecFixup/SecFixup.h new file mode 100644 index 0000000000..5571dc34a2 --- /dev/null +++ b/Tools/Source/TianoTools/SecFixup/SecFixup.h @@ -0,0 +1,146 @@ +/*++
+
+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:
+
+ SecFixup.h
+
+Abstract:
+
+ Definitions for the SecFixup utility.
+
+--*/
+
+#ifndef _SEC_FIXUP_H
+#define _SEC_FIXUP_H
+
+//
+// Utility Name
+//
+#define UTILITY_NAME "SecFixup"
+
+//
+// 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 4
+
+#define DEST_REL_OFFSET 13
+#define BUF_SIZE (8 * 1024)
+
+//
+// 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
+
+--*/
+;
+
+//
+// The function that gets the entry point of a PE/TE file.
+//
+STATUS
+GetEntryPoint (
+ IN FILE *ExeFile,
+ OUT UINT32 *EntryPoint
+ )
+/*++
+
+Routine Description:
+
+ GC_TODO: Add function description
+
+Arguments:
+
+ ExeFile - GC_TODO: add argument description
+ EntryPoint - GC_TODO: add argument description
+
+Returns:
+
+ GC_TODO: add return values
+
+--*/
+;
+
+//
+// The function that copies a file.
+//
+STATUS
+CopyFile (
+ FILE *FpIn,
+ FILE *FpOut
+ )
+/*++
+
+Routine Description:
+
+ GC_TODO: Add function description
+
+Arguments:
+
+ FpIn - GC_TODO: add argument description
+ FpOut - GC_TODO: add argument description
+
+Returns:
+
+ GC_TODO: add return values
+
+--*/
+;
+
+#endif
|