summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/C
diff options
context:
space:
mode:
authorShenglei Zhang <shenglei.zhang@intel.com>2018-11-30 10:30:05 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-12-06 14:32:04 +0800
commit7702ceb8afa4f94b949eca4fbbc5dc84e550e082 (patch)
treef46c6064b2081f5735926d6b245ae23b8f594f65 /BaseTools/Source/C
parent9fb5c5c4a33248764b24cb710b56d6c32ce237b4 (diff)
downloadedk2-7702ceb8afa4f94b949eca4fbbc5dc84e550e082.tar.gz
edk2-7702ceb8afa4f94b949eca4fbbc5dc84e550e082.tar.bz2
edk2-7702ceb8afa4f94b949eca4fbbc5dc84e550e082.zip
BaseTools: Remove tools only used by DuetPkg
Given that DuetPkg will be removed, tools only used by DuetPkg can also be removed after its removal operation. https://bugzilla.tianocore.org/show_bug.cgi?id=1322 v2:Remove these tools in Makefile and GNUmakefile. v4:Remove these tools in BinWrappers/PosixLike/ and UserManuals. Cc: Ruiyu Ni <ruiyu.ni@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/C')
-rw-r--r--BaseTools/Source/C/BootSectImage/GNUmakefile21
-rw-r--r--BaseTools/Source/C/BootSectImage/Makefile22
-rw-r--r--BaseTools/Source/C/BootSectImage/bootsectimage.c955
-rw-r--r--BaseTools/Source/C/BootSectImage/fat.h152
-rw-r--r--BaseTools/Source/C/BootSectImage/mbr.h58
-rw-r--r--BaseTools/Source/C/EfiLdrImage/EfiLdrImage.c319
-rw-r--r--BaseTools/Source/C/EfiLdrImage/GNUmakefile21
-rw-r--r--BaseTools/Source/C/EfiLdrImage/Makefile22
-rw-r--r--BaseTools/Source/C/GNUmakefile5
-rw-r--r--BaseTools/Source/C/GenBootSector/FatFormat.h152
-rw-r--r--BaseTools/Source/C/GenBootSector/GenBootSector.c823
-rw-r--r--BaseTools/Source/C/GenBootSector/GetDrvNumOffset.c73
-rw-r--r--BaseTools/Source/C/GenBootSector/Makefile22
-rw-r--r--BaseTools/Source/C/GenPage/GNUmakefile21
-rw-r--r--BaseTools/Source/C/GenPage/GenPage.c441
-rw-r--r--BaseTools/Source/C/GenPage/Makefile22
-rw-r--r--BaseTools/Source/C/GenPage/VirtualMemory.h122
-rw-r--r--BaseTools/Source/C/GnuGenBootSector/FatFormat.h152
-rw-r--r--BaseTools/Source/C/GnuGenBootSector/GNUmakefile21
-rw-r--r--BaseTools/Source/C/GnuGenBootSector/GnuGenBootSector.c455
-rw-r--r--BaseTools/Source/C/Makefile4
21 files changed, 0 insertions, 3883 deletions
diff --git a/BaseTools/Source/C/BootSectImage/GNUmakefile b/BaseTools/Source/C/BootSectImage/GNUmakefile
deleted file mode 100644
index f76beac265..0000000000
--- a/BaseTools/Source/C/BootSectImage/GNUmakefile
+++ /dev/null
@@ -1,21 +0,0 @@
-## @file
-# GNU/Linux makefile for 'BootSectImage' module build.
-#
-# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-MAKEROOT ?= ..
-
-APPNAME = BootSectImage
-
-LIBS = -lCommon
-
-OBJECTS = bootsectimage.o
-
-include $(MAKEROOT)/Makefiles/app.makefile
diff --git a/BaseTools/Source/C/BootSectImage/Makefile b/BaseTools/Source/C/BootSectImage/Makefile
deleted file mode 100644
index 5e27af5a87..0000000000
--- a/BaseTools/Source/C/BootSectImage/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-## @file
-# Windows makefile for 'BootSectImage' module build.
-#
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-!INCLUDE ..\Makefiles\ms.common
-
-APPNAME = BootSectImage
-
-LIBS = $(LIB_PATH)\Common.lib
-
-OBJECTS = BootSectImage.obj
-
-!INCLUDE ..\Makefiles\ms.app
-
diff --git a/BaseTools/Source/C/BootSectImage/bootsectimage.c b/BaseTools/Source/C/BootSectImage/bootsectimage.c
deleted file mode 100644
index 72cad16869..0000000000
--- a/BaseTools/Source/C/BootSectImage/bootsectimage.c
+++ /dev/null
@@ -1,955 +0,0 @@
-/** @file
-
-Abstract:
- Patch the BPB information in boot sector image file.
- Patch the MBR code in MBR image file.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#include <stdio.h>
-#include <string.h>
-#include "fat.h"
-#include "mbr.h"
-#include "EfiUtilityMsgs.h"
-#include "ParseInf.h"
-
-#define DEBUG_WARN 0x1
-#define DEBUG_ERROR 0x2
-
-//
-// Utility Name
-//
-#define UTILITY_NAME "BootSectImage"
-
-//
-// Utility version information
-//
-#define UTILITY_MAJOR_VERSION 1
-#define UTILITY_MINOR_VERSION 0
-
-void
-Version (
- void
- )
-/*++
-
-Routine Description:
-
- Displays the standard utility information to SDTOUT
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
-}
-
-void
-Usage (
- void
- )
-/*++
-
-Routine Description:
-
- GC_TODO: Add function description
-
-Arguments:
-
-
-Returns:
-
- GC_TODO: add return values
-
---*/
-{
- Version();
- printf ("Copyright (c) 1999-2016 Intel Corporation. All rights reserved.\n");
- printf ("\n The BootSectImage tool prints information or patch destination file by source\n");
- printf (" file for BIOS Parameter Block (BPB) or Master Boot Record (MBR).\n");
- printf ("\nUsage: \n\
- BootSectImage\n\
- [-f, --force force patch even if the FAT type of SrcImage and DstImage mismatch]\n\
- [-m, --mbr process MBR instead of boot sector]\n\
- [-p, --parse parse SrcImageFile]\n\
- [-o, --output DstImage]\n\
- [-g, --patch patch DstImage using data from SrcImageFile]\n\
- [-v, --verbose]\n\
- [--version]\n\
- [-q, --quiet disable all messages except fatal errors]\n\
- [-d, --debug[#]\n\
- [-h, --help]\n\
- [SrcImageFile]\n");
-}
-
-int WriteToFile (
- void *BootSector,
- char *FileName
- )
-/*++
-Routine Description:
- Write 512 bytes boot sector to file.
-
-Arguments:
- BootSector - point to a buffer containing 512 bytes boot sector to write
- FileName - file to write to
-
-Return:
- int - number of bytes wrote,
- 512 indicates write successful
- 0 indicates write failure
---*/
-{
- FILE *FileHandle;
- int result;
-
- FileHandle = fopen (LongFilePath (FileName), "r+b");
- if (FileHandle == NULL) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Open file: %s", FileName);
- return 0;
- }
- fseek (FileHandle, 0, SEEK_SET);
-
- result = fwrite (BootSector, 1, 512, FileHandle);
- if (result != 512) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Write file: %s", FileName);
- result = 0;
- }
-
- fclose (FileHandle);
- return result;
-}
-
-int ReadFromFile (
- void *BootSector,
- char *FileName
- )
-/*++
-Routine Description:
- Read first 512 bytes from file.
-
-Arguments:
- BootSector - point to a buffer receiving the first 512 bytes data from file
- FileName - file to read from
-
-Return:
- int - number of bytes read,
- 512 indicates read successful
- 0 indicates read failure
---*/
-{
- FILE *FileHandle;
- int result;
-
- FileHandle = fopen (LongFilePath (FileName), "rb");
- if (FileHandle == NULL) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E0001: Error opening file: %s", FileName);
- return 0;
- }
-
- result = fread (BootSector, 1, 512, FileHandle);
- if (result != 512) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E0004: Error reading file: %s", FileName);
- result = 0;
- }
-
- fclose (FileHandle);
- return result;
-}
-
-char *
-FatTypeToString (
- IN FAT_TYPE FatType
- )
-/*++
-Routine Description:
- Convert enum type of FatType to string
---*/
-{
- switch (FatType) {
- case FatTypeFat12:
- return "FAT12";
- case FatTypeFat16:
- return "FAT16";
- case FatTypeFat32:
- return "FAT32";
- default:
- break;
- }
- return "FAT Unknown";
-}
-
-FAT_TYPE
-GetFatType (
- IN FAT_BPB_STRUCT *FatBpb
- )
-/*++
-Routine Description:
- Determine the FAT type according to BIOS Paramater Block (BPB) data
-
-Arguments:
- FatBpb - BIOS Parameter Block (BPB) data, 512 Bytes
-
-Return:
- FatTypeUnknown - Cannot determine the FAT type
- FatTypeFat12 - FAT12
- FatTypeFat16 - FAT16
- FatTypeFat32 - FAT32
---*/
-{
- FAT_TYPE FatType;
- UINTN RootDirSectors;
- UINTN FATSz;
- UINTN TotSec;
- UINTN DataSec;
- UINTN CountOfClusters;
- CHAR8 FilSysType[9];
-
- FatType = FatTypeUnknown;
-
- //
- // Simple check
- //
- if (FatBpb->Fat12_16.Signature != FAT_BS_SIGNATURE) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - Signature Invalid - %04x, expected: %04x",
- FatBpb->Fat12_16.Signature, FAT_BS_SIGNATURE);
- return FatTypeUnknown;
- }
-
- //
- // Check according to FAT spec
- //
- if ((FatBpb->Fat12_16.BS_jmpBoot[0] != FAT_BS_JMP1) &&
- (FatBpb->Fat12_16.BS_jmpBoot[0] != FAT_BS_JMP2)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BS_jmpBoot - %02x, expected: %02x or %02x",
- FatBpb->Fat12_16.BS_jmpBoot[0], FAT_BS_JMP1, FAT_BS_JMP2);
- return FatTypeUnknown;
- }
-
- if ((FatBpb->Fat12_16.BPB_BytsPerSec != 512) &&
- (FatBpb->Fat12_16.BPB_BytsPerSec != 1024) &&
- (FatBpb->Fat12_16.BPB_BytsPerSec != 2048) &&
- (FatBpb->Fat12_16.BPB_BytsPerSec != 4096)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_BytsPerSec - %04x, expected: %04x, %04x, %04x, or %04x",
- FatBpb->Fat12_16.BPB_BytsPerSec, 512, 1024, 2048, 4096);
- return FatTypeUnknown;
- }
- if (FatBpb->Fat12_16.BPB_BytsPerSec != 512) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT - BPB_BytsPerSec - %04x, expected: %04x",
- FatBpb->Fat12_16.BPB_BytsPerSec, 512);
- }
- if ((FatBpb->Fat12_16.BPB_SecPerClus != 1) &&
- (FatBpb->Fat12_16.BPB_SecPerClus != 2) &&
- (FatBpb->Fat12_16.BPB_SecPerClus != 4) &&
- (FatBpb->Fat12_16.BPB_SecPerClus != 8) &&
- (FatBpb->Fat12_16.BPB_SecPerClus != 16) &&
- (FatBpb->Fat12_16.BPB_SecPerClus != 32) &&
- (FatBpb->Fat12_16.BPB_SecPerClus != 64) &&
- (FatBpb->Fat12_16.BPB_SecPerClus != 128)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_SecPerClus - %02x, expected: %02x, %02x, %02x, %02x, %02x, %02x, %02x, or %02x",
- FatBpb->Fat12_16.BPB_BytsPerSec, 1, 2, 4, 8, 16, 32, 64, 128);
- return FatTypeUnknown;
- }
- if (FatBpb->Fat12_16.BPB_BytsPerSec * FatBpb->Fat12_16.BPB_SecPerClus > 32 * 1024) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_BytsPerSec * BPB_SecPerClus - %08x, expected: <= %08x",
- FatBpb->Fat12_16.BPB_BytsPerSec * FatBpb->Fat12_16.BPB_SecPerClus, 32 * 1024);
- return FatTypeUnknown;
- }
- if (FatBpb->Fat12_16.BPB_RsvdSecCnt == 0) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_RsvdSecCnt - %04x, expected: Non-Zero Value",
- FatBpb->Fat12_16.BPB_RsvdSecCnt);
- return FatTypeUnknown;
- }
- if (FatBpb->Fat12_16.BPB_NumFATs != 2) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT - BPB_NumFATs - %02x, expected: %02x",
- FatBpb->Fat12_16.BPB_NumFATs, 2);
- }
- if ((FatBpb->Fat12_16.BPB_Media != 0xF0) &&
- (FatBpb->Fat12_16.BPB_Media != 0xF8) &&
- (FatBpb->Fat12_16.BPB_Media != 0xF9) &&
- (FatBpb->Fat12_16.BPB_Media != 0xFA) &&
- (FatBpb->Fat12_16.BPB_Media != 0xFB) &&
- (FatBpb->Fat12_16.BPB_Media != 0xFC) &&
- (FatBpb->Fat12_16.BPB_Media != 0xFD) &&
- (FatBpb->Fat12_16.BPB_Media != 0xFE) &&
- (FatBpb->Fat12_16.BPB_Media != 0xFF)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_Media - %02x, expected: %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, or %02x",
- FatBpb->Fat12_16.BPB_Media, 0xF0, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF);
- return FatTypeUnknown;
- }
-
- //
- // Algo in FAT spec
- //
- RootDirSectors = ((FatBpb->Fat12_16.BPB_RootEntCnt * sizeof(FAT_DIRECTORY_ENTRY)) +
- (FatBpb->Fat12_16.BPB_BytsPerSec - 1)) /
- FatBpb->Fat12_16.BPB_BytsPerSec;
-
- if (FatBpb->Fat12_16.BPB_FATSz16 != 0) {
- FATSz = FatBpb->Fat12_16.BPB_FATSz16;
- } else {
- FATSz = FatBpb->Fat32.BPB_FATSz32;
- }
- if (FATSz == 0) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_FATSz16, BPB_FATSz32 - 0, expected: Non-Zero Value");
- return FatTypeUnknown;
- }
-
- if (FatBpb->Fat12_16.BPB_TotSec16 != 0) {
- TotSec = FatBpb->Fat12_16.BPB_TotSec16;
- } else {
- TotSec = FatBpb->Fat12_16.BPB_TotSec32;
- }
- if (TotSec == 0) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_TotSec16, BPB_TotSec32 - 0, expected: Non-Zero Value");
- return FatTypeUnknown;
- }
-
- DataSec = TotSec - (
- FatBpb->Fat12_16.BPB_RsvdSecCnt +
- FatBpb->Fat12_16.BPB_NumFATs * FATSz +
- RootDirSectors
- );
-
- CountOfClusters = DataSec / FatBpb->Fat12_16.BPB_SecPerClus;
-
- if (CountOfClusters < FAT_MAX_FAT12_CLUSTER) {
- FatType = FatTypeFat12;
- } else if (CountOfClusters < FAT_MAX_FAT16_CLUSTER) {
- FatType = FatTypeFat16;
- } else {
- FatType = FatTypeFat32;
- }
- //
- // Check according to FAT spec
- //
- if (((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) &&
- (FatBpb->Fat12_16.BPB_RsvdSecCnt != 1)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT12_16 - BPB_RsvdSecCnt - %04x, expected: %04x",
- FatBpb->Fat12_16.BPB_RsvdSecCnt, 1);
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat12_16.BPB_RsvdSecCnt != 32)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_RsvdSecCnt - %04x, expected: %04x",
- FatBpb->Fat12_16.BPB_RsvdSecCnt, 32);
- }
- if ((FatType == FatTypeFat16) &&
- (FatBpb->Fat12_16.BPB_RootEntCnt != 512)) {
- printf ("WARNING: FAT16: BPB_RootEntCnt - %04x, expected - %04x\n",
- FatBpb->Fat12_16.BPB_RootEntCnt, 512);
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat12_16.BPB_RootEntCnt != 0)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_RootEntCnt - %04x, expected: %04x",
- FatBpb->Fat12_16.BPB_RootEntCnt, 0);
- return FatTypeUnknown;
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat12_16.BPB_TotSec16 != 0)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_TotSec16 - %04x, expected: %04x",
- FatBpb->Fat12_16.BPB_TotSec16, 0);
- return FatTypeUnknown;
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat12_16.BPB_FATSz16 != 0)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_FATSz16 - %04x, expected: %04x",
- FatBpb->Fat12_16.BPB_FATSz16, 0);
- return FatTypeUnknown;
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat12_16.BPB_TotSec32 == 0)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_TotSec32 - %04x, expected: Non-Zero",
- (unsigned) FatBpb->Fat12_16.BPB_TotSec32);
- return FatTypeUnknown;
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat32.BPB_FATSz32 == 0)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_FATSz32 - %08x, expected: Non-Zero",
- (unsigned) FatBpb->Fat32.BPB_FATSz32);
- return FatTypeUnknown;
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat32.BPB_FSVer != 0)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_FSVer - %08x, expected: %04x",
- FatBpb->Fat32.BPB_FSVer, 0);
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat32.BPB_RootClus != 2)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_RootClus - %08x, expected: %04x",
- (unsigned) FatBpb->Fat32.BPB_RootClus, 2);
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat32.BPB_FSInfo != 1)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_FSInfo - %08x, expected: %04x",
- FatBpb->Fat32.BPB_FSInfo, 1);
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat32.BPB_BkBootSec != 6)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_BkBootSec - %08x, expected: %04x",
- FatBpb->Fat32.BPB_BkBootSec, 6);
- }
- if ((FatType == FatTypeFat32) &&
- ((*(UINT32 *)FatBpb->Fat32.BPB_Reserved != 0) ||
- (*((UINT32 *)FatBpb->Fat32.BPB_Reserved + 1) != 0) ||
- (*((UINT32 *)FatBpb->Fat32.BPB_Reserved + 2) != 0))) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_Reserved - %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x, expected: 0",
- FatBpb->Fat32.BPB_Reserved[0],
- FatBpb->Fat32.BPB_Reserved[1],
- FatBpb->Fat32.BPB_Reserved[2],
- FatBpb->Fat32.BPB_Reserved[3],
- FatBpb->Fat32.BPB_Reserved[4],
- FatBpb->Fat32.BPB_Reserved[5],
- FatBpb->Fat32.BPB_Reserved[6],
- FatBpb->Fat32.BPB_Reserved[7],
- FatBpb->Fat32.BPB_Reserved[8],
- FatBpb->Fat32.BPB_Reserved[9],
- FatBpb->Fat32.BPB_Reserved[10],
- FatBpb->Fat32.BPB_Reserved[11]);
- return FatTypeUnknown;
- }
- if (((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) &&
- (FatBpb->Fat12_16.BS_Reserved1 != 0)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT12_16 - BS_Reserved1 - %02x, expected: 0\n",
- FatBpb->Fat12_16.BS_Reserved1);
- return FatTypeUnknown;
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat32.BS_Reserved1 != 0)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BS_Reserved1 - %02x, expected: 0\n",
- FatBpb->Fat32.BS_Reserved1);
- return FatTypeUnknown;
- }
- if (((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) &&
- (FatBpb->Fat12_16.BS_BootSig != FAT_BS_BOOTSIG)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT12_16 - BS_BootSig - %02x, expected: %02x\n",
- FatBpb->Fat12_16.BS_BootSig, FAT_BS_BOOTSIG);
- return FatTypeUnknown;
- }
- if ((FatType == FatTypeFat32) &&
- (FatBpb->Fat32.BS_BootSig != FAT_BS_BOOTSIG)) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BS_BootSig - %02x, expected: %02x\n",
- FatBpb->Fat32.BS_BootSig, FAT_BS_BOOTSIG);
- return FatTypeUnknown;
- }
-
- if ((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) {
- memcpy (FilSysType, FatBpb->Fat12_16.BS_FilSysType, 8);
- FilSysType[8] = 0;
- if ((FatType == FatTypeFat12) &&
- (strcmp (FilSysType, FAT12_FILSYSTYPE) != 0) &&
- (strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT12 - BS_FilSysType - %s, expected: %s, or %s\n",
- FilSysType, FAT12_FILSYSTYPE, FAT_FILSYSTYPE);
- }
- if ((FatType == FatTypeFat16) &&
- (strcmp (FilSysType, FAT16_FILSYSTYPE) != 0) &&
- (strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT16 - BS_FilSysType - %s, expected: %s, or %s\n",
- FilSysType, FAT16_FILSYSTYPE, FAT_FILSYSTYPE);
- }
- }
- if (FatType == FatTypeFat32) {
- memcpy (FilSysType, FatBpb->Fat32.BS_FilSysType, 8);
- FilSysType[8] = 0;
- if (strcmp (FilSysType, FAT32_FILSYSTYPE) != 0) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BS_FilSysType - %s, expected: %s\n",
- FilSysType, FAT32_FILSYSTYPE);
- }
- }
-
- //
- // pass all check, get FAT type
- //
- return FatType;
-}
-
-
-void
-ParseBootSector (
- char *FileName
- )
-{
- FAT_BPB_STRUCT FatBpb;
- FAT_TYPE FatType;
-
- if (ReadFromFile ((void *)&FatBpb, FileName) == 0) {
- return ;
- }
-
- FatType = GetFatType (&FatBpb);
- if (FatType <= FatTypeUnknown || FatType >= FatTypeMax) {
- printf ("ERROR: E3002: Unknown FAT Type!\n");
- return;
- }
-
- printf ("\nBoot Sector %s:\n", FatTypeToString (FatType));
- printf ("\n");
- printf (" Offset Title Data\n");
- printf ("==================================================================\n");
- printf (" 0 JMP instruction %02x %02x %02x\n",
- FatBpb.Fat12_16.BS_jmpBoot[0],
- FatBpb.Fat12_16.BS_jmpBoot[1],
- FatBpb.Fat12_16.BS_jmpBoot[2]);
- printf (" 3 OEM %c%c%c%c%c%c%c%c\n",
- FatBpb.Fat12_16.BS_OEMName[0],
- FatBpb.Fat12_16.BS_OEMName[1],
- FatBpb.Fat12_16.BS_OEMName[2],
- FatBpb.Fat12_16.BS_OEMName[3],
- FatBpb.Fat12_16.BS_OEMName[4],
- FatBpb.Fat12_16.BS_OEMName[5],
- FatBpb.Fat12_16.BS_OEMName[6],
- FatBpb.Fat12_16.BS_OEMName[7]);
- printf ("\n");
- printf ("BIOS Parameter Block\n");
- printf (" B Bytes per sector %04x\n", FatBpb.Fat12_16.BPB_BytsPerSec);
- printf (" D Sectors per cluster %02x\n", FatBpb.Fat12_16.BPB_SecPerClus);
- printf (" E Reserved sectors %04x\n", FatBpb.Fat12_16.BPB_RsvdSecCnt);
- printf (" 10 Number of FATs %02x\n", FatBpb.Fat12_16.BPB_NumFATs);
- printf (" 11 Root entries %04x\n", FatBpb.Fat12_16.BPB_RootEntCnt);
- printf (" 13 Sectors (under 32MB) %04x\n", FatBpb.Fat12_16.BPB_TotSec16);
- printf (" 15 Media descriptor %02x\n", FatBpb.Fat12_16.BPB_Media);
- printf (" 16 Sectors per FAT (small vol.) %04x\n", FatBpb.Fat12_16.BPB_FATSz16);
- printf (" 18 Sectors per track %04x\n", FatBpb.Fat12_16.BPB_SecPerTrk);
- printf (" 1A Heads %04x\n", FatBpb.Fat12_16.BPB_NumHeads);
- printf (" 1C Hidden sectors %08x\n", (unsigned) FatBpb.Fat12_16.BPB_HiddSec);
- printf (" 20 Sectors (over 32MB) %08x\n", (unsigned) FatBpb.Fat12_16.BPB_TotSec32);
- printf ("\n");
- if (FatType != FatTypeFat32) {
- printf (" 24 BIOS drive %02x\n", FatBpb.Fat12_16.BS_DrvNum);
- printf (" 25 (Unused) %02x\n", FatBpb.Fat12_16.BS_Reserved1);
- printf (" 26 Ext. boot signature %02x\n", FatBpb.Fat12_16.BS_BootSig);
- printf (" 27 Volume serial number %08x\n", (unsigned) FatBpb.Fat12_16.BS_VolID);
- printf (" 2B Volume lable %c%c%c%c%c%c%c%c%c%c%c\n",
- FatBpb.Fat12_16.BS_VolLab[0],
- FatBpb.Fat12_16.BS_VolLab[1],
- FatBpb.Fat12_16.BS_VolLab[2],
- FatBpb.Fat12_16.BS_VolLab[3],
- FatBpb.Fat12_16.BS_VolLab[4],
- FatBpb.Fat12_16.BS_VolLab[5],
- FatBpb.Fat12_16.BS_VolLab[6],
- FatBpb.Fat12_16.BS_VolLab[7],
- FatBpb.Fat12_16.BS_VolLab[8],
- FatBpb.Fat12_16.BS_VolLab[9],
- FatBpb.Fat12_16.BS_VolLab[10]);
- printf (" 36 File system %c%c%c%c%c%c%c%c\n",
- FatBpb.Fat12_16.BS_FilSysType[0],
- FatBpb.Fat12_16.BS_FilSysType[1],
- FatBpb.Fat12_16.BS_FilSysType[2],
- FatBpb.Fat12_16.BS_FilSysType[3],
- FatBpb.Fat12_16.BS_FilSysType[4],
- FatBpb.Fat12_16.BS_FilSysType[5],
- FatBpb.Fat12_16.BS_FilSysType[6],
- FatBpb.Fat12_16.BS_FilSysType[7]);
- printf ("\n");
- } else {
- printf ("FAT32 Section\n");
- printf (" 24 Sectors per FAT (large vol.) %08x\n", (unsigned) FatBpb.Fat32.BPB_FATSz32);
- printf (" 28 Flags %04x\n", FatBpb.Fat32.BPB_ExtFlags);
- printf (" 2A Version %04x\n", FatBpb.Fat32.BPB_FSVer);
- printf (" 2C Root dir 1st cluster %08x\n", (unsigned) FatBpb.Fat32.BPB_RootClus);
- printf (" 30 FSInfo sector %04x\n", FatBpb.Fat32.BPB_FSInfo);
- printf (" 32 Backup boot sector %04x\n", FatBpb.Fat32.BPB_BkBootSec);
- printf (" 34 (Reserved) %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
- FatBpb.Fat32.BPB_Reserved[0],
- FatBpb.Fat32.BPB_Reserved[1],
- FatBpb.Fat32.BPB_Reserved[2],
- FatBpb.Fat32.BPB_Reserved[3],
- FatBpb.Fat32.BPB_Reserved[4],
- FatBpb.Fat32.BPB_Reserved[5],
- FatBpb.Fat32.BPB_Reserved[6],
- FatBpb.Fat32.BPB_Reserved[7],
- FatBpb.Fat32.BPB_Reserved[8],
- FatBpb.Fat32.BPB_Reserved[9],
- FatBpb.Fat32.BPB_Reserved[10],
- FatBpb.Fat32.BPB_Reserved[11]);
- printf ("\n");
- printf (" 40 BIOS drive %02x\n", FatBpb.Fat32.BS_DrvNum);
- printf (" 41 (Unused) %02x\n", FatBpb.Fat32.BS_Reserved1);
- printf (" 42 Ext. boot signature %02x\n", FatBpb.Fat32.BS_BootSig);
- printf (" 43 Volume serial number %08x\n", (unsigned) FatBpb.Fat32.BS_VolID);
- printf (" 47 Volume lable %c%c%c%c%c%c%c%c%c%c%c\n",
- FatBpb.Fat32.BS_VolLab[0],
- FatBpb.Fat32.BS_VolLab[1],
- FatBpb.Fat32.BS_VolLab[2],
- FatBpb.Fat32.BS_VolLab[3],
- FatBpb.Fat32.BS_VolLab[4],
- FatBpb.Fat32.BS_VolLab[5],
- FatBpb.Fat32.BS_VolLab[6],
- FatBpb.Fat32.BS_VolLab[7],
- FatBpb.Fat32.BS_VolLab[8],
- FatBpb.Fat32.BS_VolLab[9],
- FatBpb.Fat32.BS_VolLab[10]);
- printf (" 52 File system %c%c%c%c%c%c%c%c\n",
- FatBpb.Fat32.BS_FilSysType[0],
- FatBpb.Fat32.BS_FilSysType[1],
- FatBpb.Fat32.BS_FilSysType[2],
- FatBpb.Fat32.BS_FilSysType[3],
- FatBpb.Fat32.BS_FilSysType[4],
- FatBpb.Fat32.BS_FilSysType[5],
- FatBpb.Fat32.BS_FilSysType[6],
- FatBpb.Fat32.BS_FilSysType[7]);
- printf ("\n");
- }
- printf (" 1FE Signature %04x\n", FatBpb.Fat12_16.Signature);
- printf ("\n");
-
-
- return ;
-}
-
-void
-PatchBootSector (
- char *DestFileName,
- char *SourceFileName,
- BOOLEAN ForcePatch
- )
-/*++
-Routine Description:
- Patch destination file according to the information from source file.
- Only patch BPB data but leave boot code un-touched.
-
-Arguments:
- DestFileName - Destination file to patch
- SourceFileName - Source file where patch from
---*/
-{
- FAT_BPB_STRUCT DestFatBpb;
- FAT_BPB_STRUCT SourceFatBpb;
- FAT_TYPE DestFatType;
- FAT_TYPE SourceFatType;
- CHAR8 VolLab[11];
- CHAR8 FilSysType[8];
-
- if (ReadFromFile ((void *)&DestFatBpb, DestFileName) == 0) {
- return ;
- }
- if (ReadFromFile ((void *)&SourceFatBpb, SourceFileName) == 0) {
- return ;
- }
-
- DestFatType = GetFatType (&DestFatBpb);
- SourceFatType = GetFatType (&SourceFatBpb);
-
- if (DestFatType != SourceFatType) {
- //
- // FAT type mismatch
- //
- if (ForcePatch) {
- DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s",
- FatTypeToString(SourceFatType), FatTypeToString(DestFatType));
- } else {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s",
- FatTypeToString(SourceFatType), FatTypeToString(DestFatType));
- return ;
- }
- }
-
- if (SourceFatType <= FatTypeUnknown || SourceFatType >= FatTypeMax) {
- DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3002: Unknown FAT Type!\n");
- return;
- }
-
- //
- // Copy BPB/boot data (excluding BS_jmpBoot, BS_OEMName, BootCode and Signature) from SourceFatBpb to DestFatBpb
- //
- printf ("Patching %s BPB: ", FatTypeToString (SourceFatType));
- if (SourceFatType != FatTypeFat32) {
- memcpy (
- &DestFatBpb.Fat12_16.BPB_BytsPerSec,
- &SourceFatBpb.Fat12_16.BPB_BytsPerSec,
- ((UINTN)&DestFatBpb.Fat12_16.Reserved - (UINTN)&DestFatBpb.Fat12_16.BPB_BytsPerSec)
- );
- } else {
- memcpy (
- &DestFatBpb.Fat32.BPB_BytsPerSec,
- &SourceFatBpb.Fat32.BPB_BytsPerSec,
- ((UINTN)&DestFatBpb.Fat32.Reserved - (UINTN)&DestFatBpb.Fat32.BPB_BytsPerSec)
- );
- }
-
- //
- // Set BS_VolLab and BS_FilSysType of DestFatBpb
- //
- // BS_VolLab BS_FilSysType
- // FAT12: EFI FAT12 FAT12
- // FAT16: EFI FAT16 FAT16
- // FAT32: EFI FAT32 FAT32
- //
- if (SourceFatType == FatTypeFat32) {
- memcpy (VolLab, "EFI FAT32 ", sizeof(VolLab));
- memcpy (FilSysType, FAT32_FILSYSTYPE, sizeof(FilSysType));
- } else if (SourceFatType == FatTypeFat16) {
- memcpy (VolLab, "EFI FAT16 ", sizeof(VolLab));
- memcpy (FilSysType, FAT16_FILSYSTYPE, sizeof(FilSysType));
- } else {
- memcpy (VolLab, "EFI FAT12 ", sizeof(VolLab));
- memcpy (FilSysType, FAT12_FILSYSTYPE, sizeof(FilSysType));
- }
- if (SourceFatType != FatTypeFat32) {
- memcpy (DestFatBpb.Fat12_16.BS_VolLab, VolLab, sizeof(VolLab));
- memcpy (DestFatBpb.Fat12_16.BS_FilSysType, FilSysType, sizeof(FilSysType));
- } else {
- memcpy (DestFatBpb.Fat32.BS_VolLab, VolLab, sizeof(VolLab));
- memcpy (DestFatBpb.Fat32.BS_FilSysType, FilSysType, sizeof(FilSysType));
- }
-
- //
- // Set Signature of DestFatBpb to 55AA
- //
- DestFatBpb.Fat12_16.Signature = FAT_BS_SIGNATURE;
-
- //
- // Write DestFatBpb
- //
- if (WriteToFile ((void *)&DestFatBpb, DestFileName)) {
- printf ("successful!\n");
- } else {
- printf ("failed!\n");
- }
-
- return ;
-}
-
-void
-ParseMbr (
- char *FileName
- )
-{
- MASTER_BOOT_RECORD Mbr;
-
- if (ReadFromFile ((void *)&Mbr, FileName) == 0) {
- return ;
- }
-
- printf ("\nMaster Boot Record:\n");
- printf ("\n");
- printf (" Offset Title Value\n");
- printf ("==================================================================\n");
- printf (" 0 Master bootstrap loader code (not list)\n");
- printf (" 1B8 Windows disk signature %08x\n", (unsigned) Mbr.UniqueMbrSignature);
- printf ("\n");
- printf ("Partition Table Entry #1\n");
- printf (" 1BE 80 = active partition %02x\n", Mbr.PartitionRecord[0].BootIndicator);
- printf (" 1BF Start head %02x\n", Mbr.PartitionRecord[0].StartHead);
- printf (" 1C0 Start sector %02x\n", Mbr.PartitionRecord[0].StartSector);
- printf (" 1C1 Start cylinder %02x\n", Mbr.PartitionRecord[0].StartTrack);
- printf (" 1C2 Partition type indicator %02x\n", Mbr.PartitionRecord[0].OSType);
- printf (" 1C3 End head %02x\n", Mbr.PartitionRecord[0].EndHead);
- printf (" 1C4 End sector %02x\n", Mbr.PartitionRecord[0].EndSector);
- printf (" 1C5 End cylinder %02x\n", Mbr.PartitionRecord[0].EndTrack);
- printf (" 1C6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[0].StartingLBA);
- printf (" 1CA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[0].SizeInLBA);
- printf ("\n");
- printf ("Partition Table Entry #2\n");
- printf (" 1CE 80 = active partition %02x\n", Mbr.PartitionRecord[1].BootIndicator);
- printf (" 1CF Start head %02x\n", Mbr.PartitionRecord[1].StartHead);
- printf (" 1D0 Start sector %02x\n", Mbr.PartitionRecord[1].StartSector);
- printf (" 1D1 Start cylinder %02x\n", Mbr.PartitionRecord[1].StartTrack);
- printf (" 1D2 Partition type indicator %02x\n", Mbr.PartitionRecord[1].OSType);
- printf (" 1D3 End head %02x\n", Mbr.PartitionRecord[1].EndHead);
- printf (" 1D4 End sector %02x\n", Mbr.PartitionRecord[1].EndSector);
- printf (" 1D5 End cylinder %02x\n", Mbr.PartitionRecord[1].EndTrack);
- printf (" 1D6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[1].StartingLBA);
- printf (" 1DA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[1].SizeInLBA);
- printf ("\n");
- printf ("Partition Table Entry #3\n");
- printf (" 1DE 80 = active partition %02x\n", Mbr.PartitionRecord[2].BootIndicator);
- printf (" 1DF Start head %02x\n", Mbr.PartitionRecord[2].StartHead);
- printf (" 1E0 Start sector %02x\n", Mbr.PartitionRecord[2].StartSector);
- printf (" 1E1 Start cylinder %02x\n", Mbr.PartitionRecord[2].StartTrack);
- printf (" 1E2 Partition type indicator %02x\n", Mbr.PartitionRecord[2].OSType);
- printf (" 1E3 End head %02x\n", Mbr.PartitionRecord[2].EndHead);
- printf (" 1E4 End sector %02x\n", Mbr.PartitionRecord[2].EndSector);
- printf (" 1E5 End cylinder %02x\n", Mbr.PartitionRecord[2].EndTrack);
- printf (" 1E6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[2].StartingLBA);
- printf (" 1EA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[2].SizeInLBA);
- printf ("\n");
- printf ("Partition Table Entry #4\n");
- printf (" 1EE 80 = active partition %02x\n", Mbr.PartitionRecord[3].BootIndicator);
- printf (" 1EF Start head %02x\n", Mbr.PartitionRecord[3].StartHead);
- printf (" 1F0 Start sector %02x\n", Mbr.PartitionRecord[3].StartSector);
- printf (" 1F1 Start cylinder %02x\n", Mbr.PartitionRecord[3].StartTrack);
- printf (" 1F2 Partition type indicator %02x\n", Mbr.PartitionRecord[3].OSType);
- printf (" 1F3 End head %02x\n", Mbr.PartitionRecord[3].EndHead);
- printf (" 1F4 End sector %02x\n", Mbr.PartitionRecord[3].EndSector);
- printf (" 1F5 End cylinder %02x\n", Mbr.PartitionRecord[3].EndTrack);
- printf (" 1F6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[3].StartingLBA);
- printf (" 1FA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[3].SizeInLBA);
- printf ("\n");
- printf (" 1FE Signature %04x\n", Mbr.Signature);
- printf ("\n");
-
- return ;
-}
-
-void
-PatchMbr (
- char *DestFileName,
- char *SourceFileName
- )
-{
- MASTER_BOOT_RECORD DestMbr;
- MASTER_BOOT_RECORD SourceMbr;
-
- if (ReadFromFile ((void *)&DestMbr, DestFileName) == 0) {
- return ;
- }
- if (ReadFromFile ((void *)&SourceMbr, SourceFileName) == 0) {
- return ;
- }
-
- if (SourceMbr.Signature != MBR_SIGNATURE) {
- printf ("ERROR: E3000: Invalid MBR!\n");
- return;
- }
-
- printf ("Patching MBR:\n");
- memcpy (
- &DestMbr.PartitionRecord[0],
- &SourceMbr.PartitionRecord[0],
- sizeof(DestMbr.PartitionRecord)
- );
-
- DestMbr.Signature = MBR_SIGNATURE;
-
-
- if (WriteToFile ((void *)&DestMbr, DestFileName)) {
- printf ("\tsuccessful!\n");
- }
-
- return ;
-}
-
-
-int
-main (
- int argc,
- char *argv[]
- )
-{
- char *SrcImage;
- char *DstImage;
- BOOLEAN ForcePatch; // -f
- BOOLEAN ProcessMbr; // -m
- BOOLEAN DoParse; // -p SrcImage or -g SrcImage DstImage
- BOOLEAN Verbose; // -v
- UINT64 LogLevel;
- EFI_STATUS EfiStatus;
-
- SrcImage = DstImage = NULL;
- ForcePatch = FALSE;
- ProcessMbr = FALSE;
- DoParse = TRUE;
- Verbose = FALSE;
-
- SetUtilityName ("bootsectimage");
-
- argc--; argv++;
-
- if (argc == 0) {
- Usage ();
- return -1;
- }
-
- while (argc != 0) {
- if (strcmp (*argv, "-f") == 0 || strcmp (*argv, "--force") == 0) {
- ForcePatch = TRUE;
- } else if (strcmp (*argv, "-p") == 0 || strcmp (*argv, "--parse") == 0) {
- DoParse = TRUE;
- argc--; argv++;
- if (argc < 1) {
- Usage ();
- return -1;
- }
- SrcImage = *argv;
- } else if (strcmp (*argv, "-g") == 0 || strcmp (*argv, "--patch") == 0) {
- DoParse = FALSE;
- argc--; argv++;
- if (argc < 2) {
- Usage ();
- return -1;
- }
- SrcImage = *argv;
- argc--; argv++;
- DstImage = *argv;
- } else if (strcmp (*argv, "-m") == 0 || strcmp (*argv, "--mbr") == 0) {
- ProcessMbr = TRUE;
- } else if (strcmp (*argv, "-v") == 0 || strcmp (*argv, "--verbose") == 0) {
- Verbose = TRUE;
- } else if (strcmp (*argv, "--version") == 0) {
- Version();
- return 0;
- } else if ((stricmp (*argv, "-d") == 0) || (stricmp (*argv, "--debug") == 0)) {
- argc--; argv++;
- if (argc < 1) {
- Usage ();
- return -1;
- }
- EfiStatus = AsciiStringToUint64 (*argv, FALSE, &LogLevel);
- if (EFI_ERROR (EfiStatus)) {
- Error (NULL, 0, 1003, "Invalid option value", "%s = %s", "--debug", *argv);
- return 1;
- }
- if (LogLevel > 9) {
- Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) LogLevel);
- return 1;
- }
- SetPrintLevel (LogLevel);
- DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", *argv);
- } else {
- Usage ();
- return -1;
- }
-
- argc--; argv++;
- }
-
- if (ForcePatch && DoParse) {
- printf ("ERROR: E1002: Conflicting options: -f, -p. Cannot apply force(-f) to parse(-p)!\n");
- Usage ();
- return -1;
- }
- if (ForcePatch && !DoParse && ProcessMbr) {
- printf ("ERROR: E1002: Conflicting options: -f, -g -m. Cannot apply force(-f) to processing MBR (-g -m)!\n");
- Usage ();
- return -1;
- }
-
- if (Verbose) {
- SetPrintLevel (VERBOSE_LOG_LEVEL);
- } else {
- SetPrintLevel (KEY_LOG_LEVEL);
- }
-
- if (DoParse) {
- if (ProcessMbr) {
- ParseMbr (SrcImage);
- } else {
- ParseBootSector (SrcImage);
- }
- } else {
- if (ProcessMbr) {
- PatchMbr (DstImage, SrcImage);
- } else {
- PatchBootSector (DstImage, SrcImage, ForcePatch);
- }
- }
-
- return 0;
-}
-
diff --git a/BaseTools/Source/C/BootSectImage/fat.h b/BaseTools/Source/C/BootSectImage/fat.h
deleted file mode 100644
index 33070d42cc..0000000000
--- a/BaseTools/Source/C/BootSectImage/fat.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/** @file
-
- Fat file system structure and definition.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#ifndef _FAT_BPB_H_
-#define _FAT_BPB_H_
-
-#include "CommonLib.h"
-
-#pragma pack(1)
-
-typedef struct {
- //
- // Fat common field
- //
- UINT8 BS_jmpBoot[3];
- CHAR8 BS_OEMName[8];
- UINT16 BPB_BytsPerSec;
- UINT8 BPB_SecPerClus;
- UINT16 BPB_RsvdSecCnt;
- UINT8 BPB_NumFATs;
- UINT16 BPB_RootEntCnt;
- UINT16 BPB_TotSec16;
- UINT8 BPB_Media;
- UINT16 BPB_FATSz16;
- UINT16 BPB_SecPerTrk;
- UINT16 BPB_NumHeads;
- UINT32 BPB_HiddSec;
- UINT32 BPB_TotSec32;
-
- //
- // Fat12/16 specific field
- //
- UINT8 BS_DrvNum;
- UINT8 BS_Reserved1;
- UINT8 BS_BootSig;
- UINT32 BS_VolID;
- CHAR8 BS_VolLab[11];
- CHAR8 BS_FilSysType[8];
-
- //
- // Boot Code and Data
- //
- UINT8 Reserved[448];
-
- //
- // Fat common signature - 0xAA55
- //
- UINT16 Signature;
-} FAT12_16_BPB_STRUCT;
-
-typedef struct {
- //
- // Fat common field
- //
- UINT8 BS_jmpBoot[3];
- CHAR8 BS_OEMName[8];
- UINT16 BPB_BytsPerSec;
- UINT8 BPB_SecPerClus;
- UINT16 BPB_RsvdSecCnt;
- UINT8 BPB_NumFATs;
- UINT16 BPB_RootEntCnt;
- UINT16 BPB_TotSec16;
- UINT8 BPB_Media;
- UINT16 BPB_FATSz16;
- UINT16 BPB_SecPerTrk;
- UINT16 BPB_NumHeads;
- UINT32 BPB_HiddSec;
- UINT32 BPB_TotSec32;
-
- //
- // Fat32 specific field
- //
- UINT32 BPB_FATSz32;
- UINT16 BPB_ExtFlags;
- UINT16 BPB_FSVer;
- UINT32 BPB_RootClus;
- UINT16 BPB_FSInfo;
- UINT16 BPB_BkBootSec;
- UINT8 BPB_Reserved[12];
- UINT8 BS_DrvNum;
- UINT8 BS_Reserved1;
- UINT8 BS_BootSig;
- UINT32 BS_VolID;
- CHAR8 BS_VolLab[11];
- CHAR8 BS_FilSysType[8];
-
- //
- // Boot Code and Data
- //
- UINT8 Reserved[420];
-
- //
- // Fat common signature - 0xAA55
- //
- UINT16 Signature;
-} FAT32_BPB_STRUCT;
-
-typedef union {
- FAT12_16_BPB_STRUCT Fat12_16;
- FAT32_BPB_STRUCT Fat32;
-} FAT_BPB_STRUCT;
-
-typedef enum {
- FatTypeUnknown,
- FatTypeFat12,
- FatTypeFat16,
- FatTypeFat32,
- FatTypeMax
-} FAT_TYPE;
-
-typedef struct {
- CHAR8 DIR_Name[11];
- UINT8 DIR_Attr;
- UINT8 DIR_NTRes;
- UINT8 DIR_CrtTimeTenth;
- UINT16 DIR_CrtTime;
- UINT16 DIR_CrtDate;
- UINT16 DIR_LstAccDate;
- UINT16 DIR_FstClusHI;
- UINT16 DIR_WrtTime;
- UINT16 DIR_WrtDate;
- UINT16 DIR_FstClusLO;
- UINT32 DIR_FileSize;
-} FAT_DIRECTORY_ENTRY;
-
-#pragma pack()
-
-#define FAT_MAX_FAT12_CLUSTER 0xFF5
-#define FAT_MAX_FAT16_CLUSTER 0xFFF5
-
-#define FAT_BS_SIGNATURE 0xAA55
-#define FAT_BS_BOOTSIG 0x29
-#define FAT_BS_JMP1 0xEB
-#define FAT_BS_JMP2 0xE9
-#define FAT_FILSYSTYPE "FAT "
-#define FAT12_FILSYSTYPE "FAT12 "
-#define FAT16_FILSYSTYPE "FAT16 "
-#define FAT32_FILSYSTYPE "FAT32 "
-
-#endif
diff --git a/BaseTools/Source/C/BootSectImage/mbr.h b/BaseTools/Source/C/BootSectImage/mbr.h
deleted file mode 100644
index 33e742e4a5..0000000000
--- a/BaseTools/Source/C/BootSectImage/mbr.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/** @file
-
- MBR Partition Entry and Table structure defintions.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#ifndef _MBR_H_
-#define _MBR_H_
-
-#include "CommonLib.h"
-
-#pragma pack(1)
-
-#define MAX_MBR_PARTITIONS 4
-
-//
-// MBR Partition Entry
-//
-typedef struct {
- UINT8 BootIndicator;
- UINT8 StartHead;
- UINT8 StartSector;
- UINT8 StartTrack;
- UINT8 OSType;
- UINT8 EndHead;
- UINT8 EndSector;
- UINT8 EndTrack;
- UINT32 StartingLBA;
- UINT32 SizeInLBA;
-} MBR_PARTITION_RECORD;
-
-//
-// MBR Partition table
-//
-typedef struct {
- UINT8 BootCode[440];
- UINT32 UniqueMbrSignature;
- UINT16 Unknown;
- MBR_PARTITION_RECORD PartitionRecord[MAX_MBR_PARTITIONS];
- UINT16 Signature;
-} MASTER_BOOT_RECORD;
-
-#pragma pack()
-
-#define MBR_SIGNATURE 0xAA55
-#define EXTENDED_DOS_PARTITION 0x05
-#define EXTENDED_WINDOWS_PARTITION 0x0F
-
-#endif
diff --git a/BaseTools/Source/C/EfiLdrImage/EfiLdrImage.c b/BaseTools/Source/C/EfiLdrImage/EfiLdrImage.c
deleted file mode 100644
index 1895e69619..0000000000
--- a/BaseTools/Source/C/EfiLdrImage/EfiLdrImage.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/** @file
-Creates and EFILDR image.
-This tool combines several PE Image files together using following format denoted as EBNF:
-FILE := EFILDR_HEADER
- EFILDR_IMAGE +
- <PeImageFileContent> +
-The order of EFILDR_IMAGE is same as the order of placing PeImageFileContent.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "ParseInf.h"
-#include "CommonLib.h"
-#include "EfiUtilityMsgs.h"
-
-#define MAX_PE_IMAGES 63
-#define FILE_TYPE_FIXED_LOADER 0
-#define FILE_TYPE_RELOCATABLE_PE_IMAGE 1
-
-typedef struct {
- UINT32 CheckSum;
- UINT32 Offset;
- UINT32 Length;
- UINT8 FileName[52];
-} EFILDR_IMAGE;
-
-typedef struct {
- UINT32 Signature;
- UINT32 HeaderCheckSum;
- UINT32 FileLength;
- UINT32 NumberOfImages;
-} EFILDR_HEADER;
-
-//
-// Utility Name
-//
-#define UTILITY_NAME "EfiLdrImage"
-
-//
-// Utility version information
-//
-#define UTILITY_MAJOR_VERSION 1
-#define UTILITY_MINOR_VERSION 0
-
-void
-Version (
- void
- )
-/*++
-
-Routine Description:
-
- Displays the standard utility information to SDTOUT
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
-}
-
-VOID
-Usage (
- VOID
- )
-{
- printf ("Usage: EfiLdrImage -o OutImage LoaderImage PeImage1 PeImage2 ... PeImageN\n");
- printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
- printf ("Copyright (c) 1999-2017 Intel Corporation. All rights reserved.\n");
- printf ("\n The EfiLdrImage tool is used to combine PE files into EFILDR image with Efi loader header.\n");
-}
-
-EFI_STATUS
-CountVerboseLevel (
- IN CONST CHAR8* VerboseLevelString,
- IN CONST UINT64 Length,
- OUT UINT64 *ReturnValue
-)
-{
- UINT64 i = 0;
- for (;i < Length; ++i) {
- if (VerboseLevelString[i] != 'v' && VerboseLevelString[i] != 'V') {
- return EFI_ABORTED;
- }
- ++(*ReturnValue);
- }
-
- return EFI_SUCCESS;
-}
-
-UINT64
-FCopyFile (
- FILE *in,
- FILE *out
- )
-/*++
-Routine Description:
- Write all the content of input file to output file.
-
-Arguments:
- in - input file pointer
- out - output file pointer
-
-Return:
- UINT64 : file size of input file
---*/
-{
- UINT32 filesize, offset, length;
- CHAR8 Buffer[8*1024];
-
- fseek (in, 0, SEEK_END);
- filesize = ftell(in);
-
- fseek (in, 0, SEEK_SET);
-
- offset = 0;
- while (offset < filesize) {
- length = sizeof(Buffer);
- if (filesize-offset < length) {
- length = filesize-offset;
- }
-
- fread (Buffer, length, 1, in);
- fwrite (Buffer, length, 1, out);
- offset += length;
- }
-
- return filesize;
-}
-
-
-int
-main (
- int argc,
- char *argv[]
- )
-/*++
-
-Routine Description:
-
-
-Arguments:
-
-
-Returns:
-
-
---*/
-{
- UINT64 i;
- UINT64 filesize;
- FILE *fpIn, *fpOut;
- EFILDR_HEADER EfiLdrHeader;
- EFILDR_IMAGE EfiLdrImage[MAX_PE_IMAGES];
- CHAR8* OutputFileName = NULL;
- CHAR8* InputFileNames[MAX_PE_IMAGES + 1];
- UINT8 InputFileCount = 0;
- UINT64 DebugLevel = 0;
- UINT64 VerboseLevel = 0;
- EFI_STATUS Status = EFI_SUCCESS;
-
- SetUtilityName (UTILITY_NAME);
-
- if (argc == 1) {
- printf ("Usage: EfiLdrImage -o OutImage LoaderImage PeImage1 PeImage2 ... PeImageN\n");
- return STATUS_ERROR;
- }
-
- argc --;
- argv ++;
-
- if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {
- Usage();
- return STATUS_SUCCESS;
- }
-
- if (stricmp (argv[0], "--version") == 0) {
- Version();
- return STATUS_SUCCESS;
- }
-
- while (argc > 0) {
-
- if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--output") == 0)) {
- OutputFileName = argv[1];
- if (OutputFileName == NULL) {
- Error (NULL, 0, 1003, "Invalid option value", "Output file can't be null");
- return STATUS_ERROR;
- }
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {
- argc --;
- argv ++;
- continue;
- }
-
- if ((strlen(argv[0]) >= 2 && argv[0][0] == '-' && (argv[0][1] == 'v' || argv[0][1] == 'V')) || (stricmp (argv[0], "--verbose") == 0)) {
- VerboseLevel = 1;
- if (strlen(argv[0]) > 2) {
- Status = CountVerboseLevel (&argv[0][2], strlen(argv[0]) - 2, &VerboseLevel);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 1003, "Invalid option value", "%s", argv[0]);
- return STATUS_ERROR;
- }
- }
-
- argc --;
- argv ++;
- continue;
- }
-
- if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {
- Status = AsciiStringToUint64 (argv[1], FALSE, &DebugLevel);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
- return STATUS_ERROR;
- }
- argc -= 2;
- argv += 2;
- continue;
- }
- //
- // Don't recognize the parameter, should be regarded as the input file name.
- //
- InputFileNames[InputFileCount] = argv[0];
- InputFileCount++;
- argc--;
- argv++;
- }
-
- if (InputFileCount == 0) {
- Error (NULL, 0, 1001, "Missing option", "No input file");
- return STATUS_ERROR;
- }
- //
- // Open output file for write
- //
- if (OutputFileName == NULL) {
- Error (NULL, 0, 1001, "Missing option", "No output file");
- return STATUS_ERROR;
- }
-
- fpOut = fopen (LongFilePath (OutputFileName), "w+b");
- if (!fpOut) {
- Error (NULL, 0, 0001, "Could not open output file", OutputFileName);
- return STATUS_ERROR;
- }
-
- memset (&EfiLdrHeader, 0, sizeof (EfiLdrHeader));
- memset (&EfiLdrImage, 0, sizeof (EFILDR_IMAGE) * (InputFileCount));
-
- memcpy (&EfiLdrHeader.Signature, "EFIL", 4);
- EfiLdrHeader.FileLength = sizeof(EFILDR_HEADER) + sizeof(EFILDR_IMAGE)*(InputFileCount);
-
- //
- // Skip the file header first
- //
- fseek (fpOut, EfiLdrHeader.FileLength, SEEK_SET);
-
- //
- // copy all the input files to the output file
- //
- for(i=0;i<InputFileCount;i++) {
- //
- // Copy the content of PeImage file to output file
- //
- fpIn = fopen (LongFilePath (InputFileNames[i]), "rb");
- if (!fpIn) {
- Error (NULL, 0, 0001, "Could not open input file", InputFileNames[i]);
- fclose (fpOut);
- return STATUS_ERROR;
- }
- filesize = FCopyFile (fpIn, fpOut);
- fclose(fpIn);
-
- //
- // And in the same time update the EfiLdrHeader and EfiLdrImage array
- //
- EfiLdrImage[i].Offset = EfiLdrHeader.FileLength;
- EfiLdrImage[i].Length = (UINT32) filesize;
- strncpy ((CHAR8*) EfiLdrImage[i].FileName, InputFileNames[i], sizeof (EfiLdrImage[i].FileName) - 1);
- EfiLdrHeader.FileLength += (UINT32) filesize;
- EfiLdrHeader.NumberOfImages++;
- }
-
- //
- // Write the image header to the output file finally
- //
- fseek (fpOut, 0, SEEK_SET);
- fwrite (&EfiLdrHeader, sizeof(EFILDR_HEADER) , 1, fpOut);
- fwrite (&EfiLdrImage , sizeof(EFILDR_IMAGE)*(InputFileCount), 1, fpOut);
-
- fclose (fpOut);
- printf ("Created %s\n", OutputFileName);
- return 0;
-}
-
diff --git a/BaseTools/Source/C/EfiLdrImage/GNUmakefile b/BaseTools/Source/C/EfiLdrImage/GNUmakefile
deleted file mode 100644
index f5fe49cbc1..0000000000
--- a/BaseTools/Source/C/EfiLdrImage/GNUmakefile
+++ /dev/null
@@ -1,21 +0,0 @@
-## @file
-# GNU/Linux makefile for 'EfiLdrImage' module build.
-#
-# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-MAKEROOT ?= ..
-
-APPNAME = EfiLdrImage
-
-LIBS = -lCommon
-
-OBJECTS = EfiLdrImage.o
-
-include $(MAKEROOT)/Makefiles/app.makefile
diff --git a/BaseTools/Source/C/EfiLdrImage/Makefile b/BaseTools/Source/C/EfiLdrImage/Makefile
deleted file mode 100644
index a3c9ef1f0a..0000000000
--- a/BaseTools/Source/C/EfiLdrImage/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-## @file
-# Windows makefile for 'EfiLdrImage' module build.
-#
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-!INCLUDE ..\Makefiles\ms.common
-
-APPNAME = EfiLdrImage
-
-LIBS = $(LIB_PATH)\Common.lib
-
-OBJECTS = EfiLdrImage.obj
-
-!INCLUDE ..\Makefiles\ms.app
-
diff --git a/BaseTools/Source/C/GNUmakefile b/BaseTools/Source/C/GNUmakefile
index c38de5ac73..507125eee9 100644
--- a/BaseTools/Source/C/GNUmakefile
+++ b/BaseTools/Source/C/GNUmakefile
@@ -49,18 +49,13 @@ all: makerootdir subdirs
LIBRARIES = Common
VFRAUTOGEN = VfrCompile/VfrLexer.h
-# NON_BUILDABLE_APPLICATIONS = GenBootSector BootSectImage
APPLICATIONS = \
BrotliCompress \
VfrCompile \
- GnuGenBootSector \
- BootSectImage \
- EfiLdrImage \
EfiRom \
GenFfs \
GenFv \
GenFw \
- GenPage \
GenSec \
GenCrc32 \
LzmaCompress \
diff --git a/BaseTools/Source/C/GenBootSector/FatFormat.h b/BaseTools/Source/C/GenBootSector/FatFormat.h
deleted file mode 100644
index e244f1507c..0000000000
--- a/BaseTools/Source/C/GenBootSector/FatFormat.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/** @file
-
- Fat file system structure and definition.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
---*/
-
-#ifndef _FAT_BPB_H_
-#define _FAT_BPB_H_
-
-#include "CommonLib.h"
-
-#pragma pack(1)
-
-typedef struct {
- //
- // Fat common field
- //
- UINT8 BS_jmpBoot[3];
- CHAR8 BS_OEMName[8];
- UINT16 BPB_BytsPerSec;
- UINT8 BPB_SecPerClus;
- UINT16 BPB_RsvdSecCnt;
- UINT8 BPB_NumFATs;
- UINT16 BPB_RootEntCnt;
- UINT16 BPB_TotSec16;
- UINT8 BPB_Media;
- UINT16 BPB_FATSz16;
- UINT16 BPB_SecPerTrk;
- UINT16 BPB_NumHeads;
- UINT32 BPB_HiddSec;
- UINT32 BPB_TotSec32;
-
- //
- // Fat12/16 specific field
- //
- UINT8 BS_DrvNum;
- UINT8 BS_Reserved1;
- UINT8 BS_BootSig;
- UINT32 BS_VolID;
- CHAR8 BS_VolLab[11];
- CHAR8 BS_FilSysType[8];
-
- //
- // Boot Code and Data
- //
- UINT8 Reserved[448];
-
- //
- // Fat common signature - 0xAA55
- //
- UINT16 Signature;
-} FAT12_16_BPB_STRUCT;
-
-typedef struct {
- //
- // Fat common field
- //
- UINT8 BS_jmpBoot[3];
- CHAR8 BS_OEMName[8];
- UINT16 BPB_BytsPerSec;
- UINT8 BPB_SecPerClus;
- UINT16 BPB_RsvdSecCnt;
- UINT8 BPB_NumFATs;
- UINT16 BPB_RootEntCnt;
- UINT16 BPB_TotSec16;
- UINT8 BPB_Media;
- UINT16 BPB_FATSz16;
- UINT16 BPB_SecPerTrk;
- UINT16 BPB_NumHeads;
- UINT32 BPB_HiddSec;
- UINT32 BPB_TotSec32;
-
- //
- // Fat32 specific field
- //
- UINT32 BPB_FATSz32;
- UINT16 BPB_ExtFlags;
- UINT16 BPB_FSVer;
- UINT32 BPB_RootClus;
- UINT16 BPB_FSInfo;
- UINT16 BPB_BkBootSec;
- UINT8 BPB_Reserved[12];
- UINT8 BS_DrvNum;
- UINT8 BS_Reserved1;
- UINT8 BS_BootSig;
- UINT32 BS_VolID;
- CHAR8 BS_VolLab[11];
- CHAR8 BS_FilSysType[8];
-
- //
- // Boot Code and Data
- //
- UINT8 Reserved[420];
-
- //
- // Fat common signature - 0xAA55
- //
- UINT16 Signature;
-} FAT32_BPB_STRUCT;
-
-typedef union {
- FAT12_16_BPB_STRUCT Fat12_16;
- FAT32_BPB_STRUCT Fat32;
-} FAT_BPB_STRUCT;
-
-typedef enum {
- FatTypeUnknown,
- FatTypeFat12,
- FatTypeFat16,
- FatTypeFat32,
- FatTypeMax
-} FAT_TYPE;
-
-typedef struct {
- CHAR8 DIR_Name[11];
- UINT8 DIR_Attr;
- UINT8 DIR_NTRes;
- UINT8 DIR_CrtTimeTenth;
- UINT16 DIR_CrtTime;
- UINT16 DIR_CrtDate;
- UINT16 DIR_LstAccDate;
- UINT16 DIR_FstClusHI;
- UINT16 DIR_WrtTime;
- UINT16 DIR_WrtDate;
- UINT16 DIR_FstClusLO;
- UINT32 DIR_FileSize;
-} FAT_DIRECTORY_ENTRY;
-
-#pragma pack()
-
-#define FAT_MAX_FAT12_CLUSTER 0xFF5
-#define FAT_MAX_FAT16_CLUSTER 0xFFF5
-
-#define FAT_BS_SIGNATURE 0xAA55
-#define FAT_BS_BOOTSIG 0x29
-#define FAT_BS_JMP1 0xEB
-#define FAT_BS_JMP2 0xE9
-#define FAT_FILSYSTYPE "FAT "
-#define FAT12_FILSYSTYPE "FAT12 "
-#define FAT16_FILSYSTYPE "FAT16 "
-#define FAT32_FILSYSTYPE "FAT32 "
-
-#endif
diff --git a/BaseTools/Source/C/GenBootSector/GenBootSector.c b/BaseTools/Source/C/GenBootSector/GenBootSector.c
deleted file mode 100644
index 2385ccc640..0000000000
--- a/BaseTools/Source/C/GenBootSector/GenBootSector.c
+++ /dev/null
@@ -1,823 +0,0 @@
-/** @file
-Reading/writing MBR/DBR.
- NOTE:
- If we write MBR to disk, we just update the MBR code and the partition table wouldn't be over written.
- If we process DBR, we will patch MBR to set first partition active if no active partition exists.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#include <windows.h>
-#include <stdio.h>
-#include <string.h>
-#include <Common/UefiBaseTypes.h>
-
-#include "ParseInf.h"
-#include "EfiUtilityMsgs.h"
-#include "CommonLib.h"
-
-//
-// Utility Name
-//
-#define UTILITY_NAME "GenBootSector"
-
-//
-// Utility version information
-//
-#define UTILITY_MAJOR_VERSION 0
-#define UTILITY_MINOR_VERSION 2
-
-#define MAX_DRIVE 26
-#define PARTITION_TABLE_OFFSET 0x1BE
-
-#define SIZE_OF_PARTITION_ENTRY 0x10
-
-#define PARTITION_ENTRY_STARTLBA_OFFSET 8
-
-#define PARTITION_ENTRY_NUM 4
-
-INT
-GetDrvNumOffset (
- IN VOID *BootSector
- );
-
-typedef enum {
- PatchTypeUnknown,
- PatchTypeFloppy,
- PatchTypeIde,
- PatchTypeUsb,
- PatchTypeFileImage // input and output are all file image, patching action is same as PatchTypeFloppy
-} PATCH_TYPE;
-
-typedef enum {
- PathUnknown,
- PathFile,
- PathFloppy,
- PathUsb,
- PathIde
-} PATH_TYPE;
-
-typedef enum {
- ErrorSuccess,
- ErrorFileCreate,
- ErrorFileReadWrite,
- ErrorNoMbr,
- ErrorFatType,
- ErrorPath,
-} ERROR_STATUS;
-
-CHAR *ErrorStatusDesc[] = {
- "Success",
- "Failed to create files",
- "Failed to read/write files",
- "No MBR exists",
- "Failed to detect Fat type",
- "Inavlid path"
-};
-
-typedef struct _DRIVE_TYPE_DESC {
- UINT Type;
- CHAR *Description;
-} DRIVE_TYPE_DESC;
-
-#define DRIVE_TYPE_ITEM(x) {x, #x}
-DRIVE_TYPE_DESC DriveTypeDesc[] = {
- DRIVE_TYPE_ITEM (DRIVE_UNKNOWN),
- DRIVE_TYPE_ITEM (DRIVE_NO_ROOT_DIR),
- DRIVE_TYPE_ITEM (DRIVE_REMOVABLE),
- DRIVE_TYPE_ITEM (DRIVE_FIXED),
- DRIVE_TYPE_ITEM (DRIVE_REMOTE),
- DRIVE_TYPE_ITEM (DRIVE_CDROM),
- DRIVE_TYPE_ITEM (DRIVE_RAMDISK),
- (UINT) -1, NULL
-};
-
-typedef struct _DRIVE_INFO {
- CHAR VolumeLetter;
- DRIVE_TYPE_DESC *DriveType;
- UINT DiskNumber;
-} DRIVE_INFO;
-
-typedef struct _PATH_INFO {
- CHAR *Path;
- CHAR PhysicalPath[260];
- PATH_TYPE Type;
- BOOL Input;
-} PATH_INFO;
-
-#define BOOT_SECTOR_LBA_OFFSET 0x1FA
-
-#define IsLetter(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
-
-BOOL
-GetDriveInfo (
- CHAR VolumeLetter,
- DRIVE_INFO *DriveInfo
- )
-/*++
-Routine Description:
- Get drive information including disk number and drive type,
- where disknumber is useful for reading/writing disk raw data.
- NOTE: Floppy disk doesn't have disk number but it doesn't matter because
- we can reading/writing floppy disk without disk number.
-
-Arguments:
- VolumeLetter : volume letter, e.g.: C for C:, A for A:
- DriveInfo : pointer to DRIVE_INFO structure receiving drive information.
-
-Return:
- TRUE : successful
- FALSE : failed
---*/
-{
- HANDLE VolumeHandle;
- STORAGE_DEVICE_NUMBER StorageDeviceNumber;
- DWORD BytesReturned;
- BOOL Success;
- UINT DriveType;
- UINT Index;
-
- CHAR RootPath[] = "X:\\"; // "X:\" -> for GetDriveType
- CHAR VolumeAccessPath[] = "\\\\.\\X:"; // "\\.\X:" -> to open the volume
-
- RootPath[0] = VolumeAccessPath[4] = VolumeLetter;
- DriveType = GetDriveType(RootPath);
- if (DriveType != DRIVE_REMOVABLE && DriveType != DRIVE_FIXED) {
- return FALSE;
- }
-
- DriveInfo->VolumeLetter = VolumeLetter;
- VolumeHandle = CreateFile (
- VolumeAccessPath,
- 0,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL
- );
- if (VolumeHandle == INVALID_HANDLE_VALUE) {
- fprintf (
- stderr,
- "error E0005: CreateFile failed: Volume = %s, LastError = 0x%lx\n",
- VolumeAccessPath,
- GetLastError ()
- );
- return FALSE;
- }
-
- //
- // Get Disk Number. It should fail when operating on floppy. That's ok
- // because Disk Number is only needed when operating on Hard or USB disk.
- //
- // To direct write to disk:
- // for USB and HD: use path = \\.\PHYSICALDRIVEx, where x is Disk Number
- // for floppy: use path = \\.\X:, where X can be A or B
- //
- Success = DeviceIoControl(
- VolumeHandle,
- IOCTL_STORAGE_GET_DEVICE_NUMBER,
- NULL,
- 0,
- &StorageDeviceNumber,
- sizeof(StorageDeviceNumber),
- &BytesReturned,
- NULL
- );
- //
- // DeviceIoControl should fail if Volume is floppy or network drive.
- //
- if (!Success) {
- DriveInfo->DiskNumber = (UINT) -1;
- } else if (StorageDeviceNumber.DeviceType != FILE_DEVICE_DISK) {
- //
- // Only care about the disk.
- //
- CloseHandle(VolumeHandle);
- return FALSE;
- } else{
- DriveInfo->DiskNumber = StorageDeviceNumber.DeviceNumber;
- }
- CloseHandle(VolumeHandle);
-
- //
- // Fill in the type string
- //
- DriveInfo->DriveType = NULL;
- for (Index = 0; DriveTypeDesc[Index].Description != NULL; Index ++) {
- if (DriveType == DriveTypeDesc[Index].Type) {
- DriveInfo->DriveType = &DriveTypeDesc[Index];
- break;
- }
- }
-
- if (DriveInfo->DriveType == NULL) {
- //
- // Should have a type.
- //
- fprintf (stderr, "error E3005: Fatal Error!!!\n");
- return FALSE;
- }
- return TRUE;
-}
-
-VOID
-ListDrive (
- VOID
- )
-/*++
-Routine Description:
- List every drive in current system and their information.
-
---*/
-{
- UINT Index;
- DRIVE_INFO DriveInfo;
-
- UINT Mask = GetLogicalDrives();
-
- for (Index = 0; Index < MAX_DRIVE; Index++) {
- if (((Mask >> Index) & 0x1) == 1) {
- if (GetDriveInfo ('A' + (CHAR) Index, &DriveInfo)) {
- if (Index < 2) {
- // Floppy will occupy 'A' and 'B'
- fprintf (
- stdout,
- "%c: - Type: %s\n",
- DriveInfo.VolumeLetter,
- DriveInfo.DriveType->Description
- );
- } else {
- fprintf (
- stdout,
- "%c: - DiskNum: %u, Type: %s\n",
- DriveInfo.VolumeLetter,
- (unsigned) DriveInfo.DiskNumber,
- DriveInfo.DriveType->Description
- );
- }
- }
- }
- }
-
-}
-
-INT
-GetBootSectorOffset (
- HANDLE DiskHandle,
- PATH_INFO *PathInfo
- )
-/*++
-Description:
- Get the offset of boot sector.
- For non-MBR disk, offset is just 0
- for disk with MBR, offset needs to be calculated by parsing MBR
-
- NOTE: if no one is active, we will patch MBR to select first partition as active.
-
-Arguments:
- DiskHandle : HANDLE of disk
- PathInfo : PATH_INFO structure.
- WriteToDisk : TRUE indicates writing
-
-Return:
- -1 : failed
- o.w. : Offset to boot sector
---*/
-{
- BYTE DiskPartition[0x200];
- DWORD BytesReturn;
- DWORD DbrOffset;
- DWORD Index;
- BOOL HasMbr;
-
- DbrOffset = 0;
- HasMbr = FALSE;
-
- SetFilePointer(DiskHandle, 0, NULL, FILE_BEGIN);
- if (!ReadFile (DiskHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
- return -1;
- }
-
- //
- // Check Signature, Jmp, and Boot Indicator.
- // if all pass, we assume MBR found.
- //
-
- // Check Signature: 55AA
- if ((DiskPartition[0x1FE] == 0x55) && (DiskPartition[0x1FF] == 0xAA)) {
- // Check Jmp: (EB ?? 90) or (E9 ?? ??)
- if (((DiskPartition[0] != 0xEB) || (DiskPartition[2] != 0x90)) &&
- (DiskPartition[0] != 0xE9)) {
- // Check Boot Indicator: 0x00 or 0x80
- // Boot Indicator is the first byte of Partition Entry
- HasMbr = TRUE;
- for (Index = 0; Index < PARTITION_ENTRY_NUM; ++Index) {
- if ((DiskPartition[PARTITION_TABLE_OFFSET + Index * SIZE_OF_PARTITION_ENTRY] & 0x7F) != 0) {
- HasMbr = FALSE;
- break;
- }
- }
- }
- }
-
- if (HasMbr) {
- //
- // Skip MBR
- //
- for (Index = 0; Index < PARTITION_ENTRY_NUM; Index++) {
- //
- // Found Boot Indicator.
- //
- if (DiskPartition[PARTITION_TABLE_OFFSET + (Index * SIZE_OF_PARTITION_ENTRY)] == 0x80) {
- DbrOffset = *(DWORD *)&DiskPartition[PARTITION_TABLE_OFFSET + (Index * SIZE_OF_PARTITION_ENTRY) + PARTITION_ENTRY_STARTLBA_OFFSET];
- break;
- }
- }
- //
- // If no boot indicator, we manually select 1st partition, and patch MBR.
- //
- if (Index == PARTITION_ENTRY_NUM) {
- DbrOffset = *(DWORD *)&DiskPartition[PARTITION_TABLE_OFFSET + PARTITION_ENTRY_STARTLBA_OFFSET];
- if (!PathInfo->Input && (PathInfo->Type == PathUsb)) {
- SetFilePointer(DiskHandle, 0, NULL, FILE_BEGIN);
- DiskPartition[PARTITION_TABLE_OFFSET] = 0x80;
- WriteFile (DiskHandle, DiskPartition, 0x200, &BytesReturn, NULL);
- }
- }
- }
-
- return DbrOffset;
-}
-
-/**
- * Get window file handle for input/ouput disk/file.
- *
- * @param PathInfo
- * @param ProcessMbr
- * @param FileHandle
- *
- * @return ERROR_STATUS
- */
-ERROR_STATUS
-GetFileHandle (
- PATH_INFO *PathInfo,
- BOOL ProcessMbr,
- HANDLE *FileHandle,
- DWORD *DbrOffset
- )
-{
- DWORD OpenFlag;
-
- OpenFlag = OPEN_ALWAYS;
- if (PathInfo->Input || PathInfo->Type != PathFile) {
- OpenFlag = OPEN_EXISTING;
- }
-
- *FileHandle = CreateFile(
- PathInfo->PhysicalPath,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OpenFlag,
- FILE_ATTRIBUTE_NORMAL,
- NULL
- );
- if (*FileHandle == INVALID_HANDLE_VALUE) {
- return ErrorFileCreate;
- }
-
- if ((PathInfo->Type == PathIde) || (PathInfo->Type == PathUsb)){
- *DbrOffset = GetBootSectorOffset (*FileHandle, PathInfo);
- if (!ProcessMbr) {
- //
- // 1. Process boot sector, set file pointer to the beginning of boot sector
- //
- SetFilePointer (*FileHandle, *DbrOffset * 0x200, NULL, FILE_BEGIN);
- } else if(*DbrOffset == 0) {
- //
- // If user want to process Mbr, but no Mbr exists, simply return FALSE
- //
- return ErrorNoMbr;
- } else {
- //
- // 2. Process MBR, set file pointer to 0
- //
- SetFilePointer (*FileHandle, 0, NULL, FILE_BEGIN);
- }
- }
-
- return ErrorSuccess;
-}
-
-/**
- Writing or reading boot sector or MBR according to the argument.
-
- @param InputInfo PATH_INFO instance for input path
- @param OutputInfo PATH_INFO instance for output path
- @param ProcessMbr TRUE is to process MBR, otherwise, processing boot sector
-
- @return ERROR_STATUS
- **/
-ERROR_STATUS
-ProcessBsOrMbr (
- PATH_INFO *InputInfo,
- PATH_INFO *OutputInfo,
- BOOL ProcessMbr
- )
-{
- BYTE DiskPartition[0x200] = {0};
- BYTE DiskPartitionBackup[0x200] = {0};
- DWORD BytesReturn;
- INT DrvNumOffset;
- HANDLE InputHandle = INVALID_HANDLE_VALUE;
- HANDLE OutputHandle = INVALID_HANDLE_VALUE;
- ERROR_STATUS Status;
- DWORD InputDbrOffset;
- DWORD OutputDbrOffset;
-
- //
- // Create file Handle and move file Pointer is pointed to beginning of Mbr or Dbr
- //
- Status = GetFileHandle(InputInfo, ProcessMbr, &InputHandle, &InputDbrOffset);
- if (Status != ErrorSuccess) {
- goto Done;
- }
-
- //
- // Create file Handle and move file Pointer is pointed to beginning of Mbr or Dbr
- //
- Status = GetFileHandle(OutputInfo, ProcessMbr, &OutputHandle, &OutputDbrOffset);
- if (Status != ErrorSuccess) {
- goto Done;
- }
-
- //
- // Read boot sector from source disk/file
- //
- if (!ReadFile (InputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
- Status = ErrorFileReadWrite;
- goto Done;
- }
-
- if (InputInfo->Type == PathUsb) {
- // Manually set BS_DrvNum to 0x80 as window's format.exe has a bug which will clear this field discarding USB disk's MBR.
- // offset of BS_DrvNum is 0x24 for FAT12/16
- // 0x40 for FAT32
- //
- DrvNumOffset = GetDrvNumOffset (DiskPartition);
- if (DrvNumOffset == -1) {
- Status = ErrorFatType;
- goto Done;
- }
- //
- // Some legacy BIOS require 0x80 discarding MBR.
- // Question left here: is it needed to check Mbr before set 0x80?
- //
- DiskPartition[DrvNumOffset] = ((InputDbrOffset > 0) ? 0x80 : 0);
- }
-
- if (InputInfo->Type == PathIde) {
- //
- // Patch LBAOffsetForBootSector
- //
- *(DWORD *)&DiskPartition [BOOT_SECTOR_LBA_OFFSET] = InputDbrOffset;
- }
-
- if (OutputInfo->Type != PathFile) {
- if (ProcessMbr) {
- //
- // Use original partition table
- //
- if (!ReadFile (OutputHandle, DiskPartitionBackup, 0x200, &BytesReturn, NULL)) {
- Status = ErrorFileReadWrite;
- goto Done;
- }
- memcpy (DiskPartition + 0x1BE, DiskPartitionBackup + 0x1BE, 0x40);
- SetFilePointer (OutputHandle, 0, NULL, FILE_BEGIN);
-
- }
- }
-
- //
- // Write boot sector to taget disk/file
- //
- if (!WriteFile (OutputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
- Status = ErrorFileReadWrite;
- goto Done;
- }
-
-Done:
- if (InputHandle != INVALID_HANDLE_VALUE) {
- CloseHandle (InputHandle);
- }
- if (OutputHandle != INVALID_HANDLE_VALUE) {
- CloseHandle (OutputHandle);
- }
-
- return Status;
-}
-
-void
-Version (
- void
- )
-/*++
-
-Routine Description:
-
- Displays the standard utility information to SDTOUT
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- printf ("%s Version %d.%d %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
-}
-
-VOID
-PrintUsage (
- void
- )
-{
- printf ("Usage: GenBootSector [options] --cfg-file CFG_FILE\n\n\
-Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.\n\n\
- Utility to retrieve and update the boot sector or MBR.\n\n\
-optional arguments:\n\
- -h, --help Show this help message and exit\n\
- --version Show program's version number and exit\n\
- -d [DEBUG], --debug [DEBUG]\n\
- Output DEBUG statements, where DEBUG_LEVEL is 0 (min)\n\
- - 9 (max)\n\
- -v, --verbose Print informational statements\n\
- -q, --quiet Returns the exit code, error messages will be\n\
- displayed\n\
- -s, --silent Returns only the exit code; informational and error\n\
- messages are not displayed\n\
- -l, --list List disk drives\n\
- -i INPUT_FILENAME, --input INPUT_FILENAME\n\
- Input file name\n\
- -o OUTPUT_FILENAME, --output OUTPUT_FILENAME\n\
- Output file name\n\
- -m, --mbr Also process the MBR\n\
- --sfo Reserved for future use\n");
-
-}
-
-/**
- Get path information, including physical path for windows platform.
-
- @param PathInfo Point to PATH_INFO structure.
-
- @return whether path is valid.
-**/
-ERROR_STATUS
-GetPathInfo (
- PATH_INFO *PathInfo
- )
-{
- DRIVE_INFO DriveInfo;
- CHAR VolumeLetter;
- CHAR DiskPathTemplate[] = "\\\\.\\PHYSICALDRIVE%u";
- CHAR FloppyPathTemplate[] = "\\\\.\\%c:";
- FILE *f;
-
- //
- // If path is disk path
- //
- if (IsLetter(PathInfo->Path[0]) && (PathInfo->Path[1] == ':') && (PathInfo->Path[2] == '\0')) {
- VolumeLetter = PathInfo->Path[0];
- if ((VolumeLetter == 'A') || (VolumeLetter == 'a') ||
- (VolumeLetter == 'B') || (VolumeLetter == 'b')) {
- PathInfo->Type = PathFloppy;
- sprintf (PathInfo->PhysicalPath, FloppyPathTemplate, VolumeLetter);
- return ErrorSuccess;
- }
-
- if (!GetDriveInfo(VolumeLetter, &DriveInfo)) {
- fprintf (stderr, "ERROR: GetDriveInfo - 0x%lx\n", GetLastError ());
- return ErrorPath;
- }
-
- if (!PathInfo->Input && (DriveInfo.DriveType->Type == DRIVE_FIXED)) {
- fprintf (stderr, "ERROR: Could patch own IDE disk!\n");
- return ErrorPath;
- }
-
- sprintf(PathInfo->PhysicalPath, DiskPathTemplate, DriveInfo.DiskNumber);
- if (DriveInfo.DriveType->Type == DRIVE_REMOVABLE) {
- PathInfo->Type = PathUsb;
- } else if (DriveInfo.DriveType->Type == DRIVE_FIXED) {
- PathInfo->Type = PathIde;
- } else {
- fprintf (stderr, "ERROR, Invalid disk path - %s", PathInfo->Path);
- return ErrorPath;
- }
-
- return ErrorSuccess;
- }
-
- //
- // Check the path length
- //
- if (strlen (PathInfo->Path) >= (sizeof (PathInfo->PhysicalPath) / sizeof (PathInfo->PhysicalPath[0]))) {
- fprintf (stderr, "ERROR, Path is too long for - %s", PathInfo->Path);
- return ErrorPath;
- }
-
- PathInfo->Type = PathFile;
- if (PathInfo->Input) {
- //
- // If path is file path, check whether file is valid.
- //
- f = fopen (LongFilePath (PathInfo->Path), "r");
- if (f == NULL) {
- fprintf (stderr, "error E2003: File was not provided!\n");
- return ErrorPath;
- }
- fclose (f);
- }
- PathInfo->Type = PathFile;
- strncpy(
- PathInfo->PhysicalPath,
- PathInfo->Path,
- sizeof (PathInfo->PhysicalPath) / sizeof (PathInfo->PhysicalPath[0]) - 1
- );
- PathInfo->PhysicalPath[sizeof (PathInfo->PhysicalPath) / sizeof (PathInfo->PhysicalPath[0]) - 1] = 0;
-
- return ErrorSuccess;
-}
-
-INT
-main (
- INT argc,
- CHAR *argv[]
- )
-{
- CHAR8 *AppName;
- INTN Index;
- BOOLEAN ProcessMbr;
- ERROR_STATUS Status;
- EFI_STATUS EfiStatus;
- PATH_INFO InputPathInfo = {0};
- PATH_INFO OutputPathInfo = {0};
- UINT64 LogLevel;
-
- SetUtilityName (UTILITY_NAME);
-
- AppName = *argv;
- argv ++;
- argc --;
-
- ProcessMbr = FALSE;
-
- if (argc == 0) {
- PrintUsage();
- return 0;
- }
-
- //
- // Parse command line
- //
- for (Index = 0; Index < argc; Index ++) {
- if ((stricmp (argv[Index], "-l") == 0) || (stricmp (argv[Index], "--list") == 0)) {
- ListDrive ();
- return 0;
- }
-
- if ((stricmp (argv[Index], "-m") == 0) || (stricmp (argv[Index], "--mbr") == 0)) {
- ProcessMbr = TRUE;
- continue;
- }
-
- if ((stricmp (argv[Index], "-i") == 0) || (stricmp (argv[Index], "--input") == 0)) {
- InputPathInfo.Path = argv[Index + 1];
- InputPathInfo.Input = TRUE;
- if (InputPathInfo.Path == NULL) {
- Error (NULL, 0, 1003, "Invalid option value", "Input file name can't be NULL");
- return 1;
- }
- if (InputPathInfo.Path[0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Input file is missing");
- return 1;
- }
- ++Index;
- continue;
- }
-
- if ((stricmp (argv[Index], "-o") == 0) || (stricmp (argv[Index], "--output") == 0)) {
- OutputPathInfo.Path = argv[Index + 1];
- OutputPathInfo.Input = FALSE;
- if (OutputPathInfo.Path == NULL) {
- Error (NULL, 0, 1003, "Invalid option value", "Output file name can't be NULL");
- return 1;
- }
- if (OutputPathInfo.Path[0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Output file is missing");
- return 1;
- }
- ++Index;
- continue;
- }
-
- if ((stricmp (argv[Index], "-h") == 0) || (stricmp (argv[Index], "--help") == 0)) {
- PrintUsage ();
- return 0;
- }
-
- if (stricmp (argv[Index], "--version") == 0) {
- Version ();
- return 0;
- }
-
- if ((stricmp (argv[Index], "-v") == 0) || (stricmp (argv[Index], "--verbose") == 0)) {
- continue;
- }
-
- if ((stricmp (argv[Index], "-q") == 0) || (stricmp (argv[Index], "--quiet") == 0)) {
- continue;
- }
-
- if ((stricmp (argv[Index], "-d") == 0) || (stricmp (argv[Index], "--debug") == 0)) {
- EfiStatus = AsciiStringToUint64 (argv[Index + 1], FALSE, &LogLevel);
- if (EFI_ERROR (EfiStatus)) {
- Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[Index], argv[Index + 1]);
- return 1;
- }
- if (LogLevel > 9) {
- Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) LogLevel);
- return 1;
- }
- SetPrintLevel (LogLevel);
- DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[Index + 1]);
- ++Index;
- continue;
- }
-
- //
- // Don't recognize the parameter.
- //
- Error (NULL, 0, 1000, "Unknown option", "%s", argv[Index]);
- return 1;
- }
-
- if (InputPathInfo.Path == NULL) {
- Error (NULL, 0, 1001, "Missing options", "Input file is missing");
- return 1;
- }
-
- if (OutputPathInfo.Path == NULL) {
- Error (NULL, 0, 1001, "Missing options", "Output file is missing");
- return 1;
- }
-
- if (GetPathInfo(&InputPathInfo) != ErrorSuccess) {
- Error (NULL, 0, 1003, "Invalid option value", "Input file can't be found.");
- return 1;
- }
-
- if (GetPathInfo(&OutputPathInfo) != ErrorSuccess) {
- Error (NULL, 0, 1003, "Invalid option value", "Output file can't be found.");
- return 1;
- }
-
- //
- // Process DBR (Patch or Read)
- //
- Status = ProcessBsOrMbr (&InputPathInfo, &OutputPathInfo, ProcessMbr);
-
- if (Status == ErrorSuccess) {
- fprintf (
- stdout,
- "%s %s: successful!\n",
- (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
- ProcessMbr ? "MBR" : "DBR"
- );
- return 0;
- } else {
- fprintf (
- stderr,
- "%s: %s %s: failed - %s (LastError: 0x%lx)!\n",
- (Status == ErrorNoMbr) ? "WARNING" : "ERROR",
- (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
- ProcessMbr ? "MBR" : "DBR",
- ErrorStatusDesc[Status],
- GetLastError ()
- );
- return 1;
- }
-}
diff --git a/BaseTools/Source/C/GenBootSector/GetDrvNumOffset.c b/BaseTools/Source/C/GenBootSector/GetDrvNumOffset.c
deleted file mode 100644
index ab6944ef2a..0000000000
--- a/BaseTools/Source/C/GenBootSector/GetDrvNumOffset.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/** @file
-
- Get Drv Num offset from Fat file system.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#include <stdio.h>
-#include "FatFormat.h"
-
-INTN
-GetDrvNumOffset (
- IN VOID *BootSector
- )
-{
- FAT_BPB_STRUCT *FatBpb;
- UINTN RootDirSectors;
- UINTN FATSz;
- UINTN TotSec;
- UINTN DataSec;
- UINTN CountOfClusters;
-
- FatBpb = (FAT_BPB_STRUCT *) BootSector;
-
- //
- // Check FAT type algorithm from FAT spec
- //
- RootDirSectors = ((FatBpb->Fat12_16.BPB_RootEntCnt * sizeof(FAT_DIRECTORY_ENTRY)) +
- (FatBpb->Fat12_16.BPB_BytsPerSec - 1)) / FatBpb->Fat12_16.BPB_BytsPerSec;
-
- if (FatBpb->Fat12_16.BPB_FATSz16 != 0) {
- FATSz = FatBpb->Fat12_16.BPB_FATSz16;
- } else {
- FATSz = FatBpb->Fat32.BPB_FATSz32;
- }
- if (FATSz == 0) {
- fprintf (stderr, "error E3003: FAT - BPB_FATSz16, BPB_FATSz32 - 0, expected: Non-Zero number\n");
- return -1;
- }
-
- if (FatBpb->Fat12_16.BPB_TotSec16 != 0) {
- TotSec = FatBpb->Fat12_16.BPB_TotSec16;
- } else {
- TotSec = FatBpb->Fat12_16.BPB_TotSec32;
- }
- if (TotSec == 0) {
- fprintf (stderr, "error E3003: FAT - BPB_TotSec16, BPB_TotSec32 - 0, expected: Non-Zero number\n");
- return -1;
- }
-
- DataSec = TotSec - (
- FatBpb->Fat12_16.BPB_RsvdSecCnt +
- FatBpb->Fat12_16.BPB_NumFATs * FATSz +
- RootDirSectors
- );
-
- CountOfClusters = DataSec / FatBpb->Fat12_16.BPB_SecPerClus;
-
- if (CountOfClusters < FAT_MAX_FAT16_CLUSTER) {
- return (INTN) ((UINTN) &FatBpb->Fat12_16.BS_DrvNum - (UINTN) FatBpb);
- } else {
- return (INTN) ((UINTN) &FatBpb->Fat32.BS_DrvNum - (UINTN) FatBpb);
- }
-}
-
diff --git a/BaseTools/Source/C/GenBootSector/Makefile b/BaseTools/Source/C/GenBootSector/Makefile
deleted file mode 100644
index 6ba39db166..0000000000
--- a/BaseTools/Source/C/GenBootSector/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-## @file
-# Windows makefile for 'GenBootSector' module build.
-#
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-!INCLUDE ..\Makefiles\ms.common
-
-APPNAME = GenBootSector
-
-LIBS = $(LIB_PATH)\Common.lib
-
-OBJECTS = GenBootSector.obj GetDrvNumOffset.obj
-
-!INCLUDE ..\Makefiles\ms.app
-
diff --git a/BaseTools/Source/C/GenPage/GNUmakefile b/BaseTools/Source/C/GenPage/GNUmakefile
deleted file mode 100644
index 9590042477..0000000000
--- a/BaseTools/Source/C/GenPage/GNUmakefile
+++ /dev/null
@@ -1,21 +0,0 @@
-## @file
-# GNU/Linux makefile for 'GenPage' module build.
-#
-# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-MAKEROOT ?= ..
-
-APPNAME = GenPage
-
-LIBS = -lCommon
-
-OBJECTS = GenPage.o
-
-include $(MAKEROOT)/Makefiles/app.makefile
diff --git a/BaseTools/Source/C/GenPage/GenPage.c b/BaseTools/Source/C/GenPage/GenPage.c
deleted file mode 100644
index c484b7136c..0000000000
--- a/BaseTools/Source/C/GenPage/GenPage.c
+++ /dev/null
@@ -1,441 +0,0 @@
-/** @file
- Pre-Create a 4G page table (2M pages).
- It's used in DUET x64 build needed to enter LongMode.
-
- Create 4G page table (2M pages)
-
- Linear Address
- 63 48 47 39 38 30 29 21 20 0
- +--------+-------+---------------+-----------+-----------------------------+
- PML4 Directory-Ptr Directory Offset
-
- Paging-Structures :=
- PML4
- (
- Directory-Ptr Directory {512}
- ) {4}
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "VirtualMemory.h"
-#include "EfiUtilityMsgs.h"
-#include "ParseInf.h"
-
-#define EFI_PAGE_BASE_OFFSET_IN_LDR 0x70000
-#define EFI_PAGE_BASE_ADDRESS (EFI_PAGE_BASE_OFFSET_IN_LDR + 0x20000)
-
-UINT32 gPageTableBaseAddress = EFI_PAGE_BASE_ADDRESS;
-UINT32 gPageTableOffsetInFile = EFI_PAGE_BASE_OFFSET_IN_LDR;
-
-#define EFI_MAX_ENTRY_NUM 512
-
-#define EFI_PML4_ENTRY_NUM 1
-#define EFI_PDPTE_ENTRY_NUM 4
-#define EFI_PDE_ENTRY_NUM EFI_MAX_ENTRY_NUM
-
-#define EFI_PML4_PAGE_NUM 1
-#define EFI_PDPTE_PAGE_NUM EFI_PML4_ENTRY_NUM
-#define EFI_PDE_PAGE_NUM (EFI_PML4_ENTRY_NUM * EFI_PDPTE_ENTRY_NUM)
-
-#define EFI_PAGE_NUMBER (EFI_PML4_PAGE_NUM + EFI_PDPTE_PAGE_NUM + EFI_PDE_PAGE_NUM)
-
-#define EFI_SIZE_OF_PAGE 0x1000
-#define EFI_PAGE_SIZE_2M 0x200000
-
-#define CONVERT_BIN_PAGE_ADDRESS(a) ((UINT8 *) a - PageTable + gPageTableBaseAddress)
-
-//
-// Utility Name
-//
-#define UTILITY_NAME "GenPage"
-
-//
-// Utility version information
-//
-#define UTILITY_MAJOR_VERSION 0
-#define UTILITY_MINOR_VERSION 2
-
-void
-Version (
- void
- )
-/*++
-
-Routine Description:
-
- Displays the standard utility information to SDTOUT
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- printf ("%s Version %d.%d %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
-}
-
-VOID
-Usage (
- void
- )
-{
- printf ("Usage: GenPage.exe [options] EfiLoaderImageName \n\n\
-Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.\n\n\
- Utility to generate the EfiLoader image containing a page table.\n\n\
-optional arguments:\n\
- -h, --help Show this help message and exit\n\
- --version Show program's version number and exit\n\
- -d [DEBUG], --debug [DEBUG]\n\
- Output DEBUG statements, where DEBUG_LEVEL is 0 (min)\n\
- - 9 (max)\n\
- -v, --verbose Print informational statements\n\
- -q, --quiet Returns the exit code, error messages will be\n\
- displayed\n\
- -s, --silent Returns only the exit code; informational and error\n\
- messages are not displayed\n\
- -o OUTPUT_FILENAME, --output OUTPUT_FILENAME\n\
- Output file contain both the non-page table part and\n\
- the page table\n\
- -b BASE_ADDRESS, --baseaddr BASE_ADDRESS\n\
- The page table location\n\
- -f OFFSET, --offset OFFSET\n\
- The position that the page table will appear in the\n\
- output file\n\
- --sfo Reserved for future use\n");
-
-}
-
-void *
-CreateIdentityMappingPageTables (
- void
- )
-/*++
-
-Routine Description:
- To create 4G PAE 2M pagetable
-
-Return:
- void * - buffer containing created pagetable
-
---*/
-{
- UINT64 PageAddress;
- UINT8 *PageTable;
- UINT8 *PageTablePtr;
- int PML4Index;
- int PDPTEIndex;
- int PDEIndex;
- X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *PageMapLevel4Entry;
- X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *PageDirectoryPointerEntry;
- X64_PAGE_TABLE_ENTRY_2M *PageDirectoryEntry2MB;
-
- PageTable = (void *)malloc (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE);
- if (PageTable == NULL) {
- Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
- return NULL;
- }
- memset (PageTable, 0, (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE));
- PageTablePtr = PageTable;
-
- PageAddress = 0;
-
- //
- // Page Table structure 3 level 2MB.
- //
- // Page-Map-Level-4-Table : bits 47-39
- // Page-Directory-Pointer-Table : bits 38-30
- //
- // Page Table 2MB : Page-Directory(2M) : bits 29-21
- //
- //
-
- PageMapLevel4Entry = (X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *)PageTablePtr;
-
- for (PML4Index = 0; PML4Index < EFI_PML4_ENTRY_NUM; PML4Index++, PageMapLevel4Entry++) {
- //
- // Each Page-Map-Level-4-Table Entry points to the base address of a Page-Directory-Pointer-Table Entry
- //
- PageTablePtr += EFI_SIZE_OF_PAGE;
- PageDirectoryPointerEntry = (X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *)PageTablePtr;
-
- //
- // Make a Page-Map-Level-4-Table Entry
- //
- PageMapLevel4Entry->Uint64 = (UINT64)(UINT32)(CONVERT_BIN_PAGE_ADDRESS (PageDirectoryPointerEntry));
- PageMapLevel4Entry->Bits.ReadWrite = 1;
- PageMapLevel4Entry->Bits.Present = 1;
-
- for (PDPTEIndex = 0; PDPTEIndex < EFI_PDPTE_ENTRY_NUM; PDPTEIndex++, PageDirectoryPointerEntry++) {
- //
- // Each Page-Directory-Pointer-Table Entry points to the base address of a Page-Directory Entry
- //
- PageTablePtr += EFI_SIZE_OF_PAGE;
- PageDirectoryEntry2MB = (X64_PAGE_TABLE_ENTRY_2M *)PageTablePtr;
-
- //
- // Make a Page-Directory-Pointer-Table Entry
- //
- PageDirectoryPointerEntry->Uint64 = (UINT64)(UINT32)(CONVERT_BIN_PAGE_ADDRESS (PageDirectoryEntry2MB));
- PageDirectoryPointerEntry->Bits.ReadWrite = 1;
- PageDirectoryPointerEntry->Bits.Present = 1;
-
- for (PDEIndex = 0; PDEIndex < EFI_PDE_ENTRY_NUM; PDEIndex++, PageDirectoryEntry2MB++) {
- //
- // Make a Page-Directory Entry
- //
- PageDirectoryEntry2MB->Uint64 = (UINT64)PageAddress;
- PageDirectoryEntry2MB->Bits.ReadWrite = 1;
- PageDirectoryEntry2MB->Bits.Present = 1;
- PageDirectoryEntry2MB->Bits.MustBe1 = 1;
-
- PageAddress += EFI_PAGE_SIZE_2M;
- }
- }
- }
-
- return PageTable;
-}
-
-INT32
-GenBinPage (
- void *BaseMemory,
- char *NoPageFileName,
- char *PageFileName
- )
-/*++
-
-Routine Description:
- Write the buffer containing page table to file at a specified offset.
- Here the offset is defined as EFI_PAGE_BASE_OFFSET_IN_LDR.
-
-Arguments:
- BaseMemory - buffer containing page table
- NoPageFileName - file to write page table
- PageFileName - file save to after writing
-
-return:
- 0 : successful
- -1 : failed
-
---*/
-{
- FILE *PageFile;
- FILE *NoPageFile;
- UINT8 Data;
- unsigned long FileSize;
-
- //
- // Open files
- //
- PageFile = fopen (LongFilePath (PageFileName), "w+b");
- if (PageFile == NULL) {
- Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Output File %s open failure", PageFileName);
- return -1;
- }
-
- NoPageFile = fopen (LongFilePath (NoPageFileName), "r+b");
- if (NoPageFile == NULL) {
- Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Input File %s open failure", NoPageFileName);
- fclose (PageFile);
- return -1;
- }
-
- //
- // Check size - should not be great than EFI_PAGE_BASE_OFFSET_IN_LDR
- //
- fseek (NoPageFile, 0, SEEK_END);
- FileSize = ftell (NoPageFile);
- fseek (NoPageFile, 0, SEEK_SET);
- if (FileSize > gPageTableOffsetInFile) {
- Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Input file size (0x%lx) exceeds the Page Table Offset (0x%x)", FileSize, (unsigned) gPageTableOffsetInFile);
- fclose (PageFile);
- fclose (NoPageFile);
- return -1;
- }
-
- //
- // Write data
- //
- while (fread (&Data, sizeof(UINT8), 1, NoPageFile)) {
- fwrite (&Data, sizeof(UINT8), 1, PageFile);
- }
-
- //
- // Write PageTable
- //
- fseek (PageFile, gPageTableOffsetInFile, SEEK_SET);
- fwrite (BaseMemory, (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE), 1, PageFile);
-
- //
- // Close files
- //
- fclose (PageFile);
- fclose (NoPageFile);
-
- return 0;
-}
-
-int
-main (
- int argc,
- char **argv
- )
-{
- VOID *BaseMemory;
- INTN result;
- CHAR8 *OutputFile = NULL;
- CHAR8 *InputFile = NULL;
- EFI_STATUS Status;
- UINT64 TempValue;
-
- SetUtilityName("GenPage");
-
- if (argc == 1) {
- Usage();
- return STATUS_ERROR;
- }
-
- argc --;
- argv ++;
-
- if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {
- Usage();
- return 0;
- }
-
- if (stricmp (argv[0], "--version") == 0) {
- Version();
- return 0;
- }
-
- while (argc > 0) {
- if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--output") == 0)) {
- if (argv[1] == NULL || argv[1][0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Output file is missing for -o option");
- return STATUS_ERROR;
- }
- OutputFile = argv[1];
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-b") == 0) || (stricmp (argv[0], "--baseaddr") == 0)) {
- if (argv[1] == NULL || argv[1][0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Base address is missing for -b option");
- return STATUS_ERROR;
- }
- Status = AsciiStringToUint64 (argv[1], FALSE, &TempValue);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 1003, "Invalid option value", "Base address is not valid intergrator");
- return STATUS_ERROR;
- }
- gPageTableBaseAddress = (UINT32) TempValue;
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--offset") == 0)) {
- if (argv[1] == NULL || argv[1][0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Offset is missing for -f option");
- return STATUS_ERROR;
- }
- Status = AsciiStringToUint64 (argv[1], FALSE, &TempValue);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 1003, "Invalid option value", "Offset is not valid intergrator");
- return STATUS_ERROR;
- }
- gPageTableOffsetInFile = (UINT32) TempValue;
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {
- argc --;
- argv ++;
- continue;
- }
-
- if ((stricmp (argv[0], "-v") ==0) || (stricmp (argv[0], "--verbose") == 0)) {
- argc --;
- argv ++;
- continue;
- }
-
- if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {
- if (argv[1] == NULL || argv[1][0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Debug Level is not specified.");
- return STATUS_ERROR;
- }
- Status = AsciiStringToUint64 (argv[1], FALSE, &TempValue);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 1003, "Invalid option value", "Debug Level is not valid intergrator.");
- return STATUS_ERROR;
- }
- if (TempValue > 9) {
- Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) TempValue);
- return STATUS_ERROR;
- }
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if (argv[0][0] == '-') {
- Error (NULL, 0, 1000, "Unknown option", argv[0]);
- return STATUS_ERROR;
- }
-
- //
- // Don't recognize the parameter.
- //
- InputFile = argv[0];
- argc--;
- argv++;
- }
-
- if (InputFile == NULL) {
- Error (NULL, 0, 1003, "Invalid option value", "Input file is not specified");
- return STATUS_ERROR;
- }
-
- //
- // Create X64 page table
- //
- BaseMemory = CreateIdentityMappingPageTables ();
- if (BaseMemory == NULL) {
- Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
- return STATUS_ERROR;
- }
-
- //
- // Add page table to binary file
- //
- result = GenBinPage (BaseMemory, InputFile, OutputFile);
- if (result < 0) {
- free (BaseMemory);
- return STATUS_ERROR;
- }
-
- free (BaseMemory);
- return 0;
-}
-
diff --git a/BaseTools/Source/C/GenPage/Makefile b/BaseTools/Source/C/GenPage/Makefile
deleted file mode 100644
index bc0369aadd..0000000000
--- a/BaseTools/Source/C/GenPage/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-## @file
-# Windows makefile for 'GenPage' module build.
-#
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-!INCLUDE ..\Makefiles\ms.common
-
-APPNAME = GenPage
-
-LIBS = $(LIB_PATH)\Common.lib
-
-OBJECTS = GenPage.obj
-
-!INCLUDE ..\Makefiles\ms.app
-
diff --git a/BaseTools/Source/C/GenPage/VirtualMemory.h b/BaseTools/Source/C/GenPage/VirtualMemory.h
deleted file mode 100644
index d1a6b198c4..0000000000
--- a/BaseTools/Source/C/GenPage/VirtualMemory.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/** @file
-x64 Long Mode Virtual Memory Management Definitions
-
- References:
- 1) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 1:Basic Architecture, Intel
- 2) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 2:Instruction Set Reference, Intel
- 3) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 3:System Programmer's Guide, Intel
- 4) AMD64 Architecture Programmer's Manual Volume 2: System Programming
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#ifndef _VIRTUAL_MEMORY_H_
-#define _VIRTUAL_MEMORY_H_
-
-#include "CommonLib.h"
-
-#pragma pack(1)
-
-//
-// Page-Map Level-4 Offset (PML4) and
-// Page-Directory-Pointer Offset (PDPE) entries 4K & 2MB
-//
-
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Reserved:1; // Reserved
- UINT64 MustBeZero:2; // Must Be Zero
- UINT64 Available:3; // Available for use by system software
- UINT64 PageTableBaseAddress:40; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // No Execute bit
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K;
-
-//
-// Page-Directory Offset 4K
-//
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Reserved:1; // Reserved
- UINT64 MustBeZero:1; // Must Be Zero
- UINT64 Reserved2:1; // Reserved
- UINT64 Available:3; // Available for use by system software
- UINT64 PageTableBaseAddress:40; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // No Execute bit
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_DIRECTORY_ENTRY_4K;
-
-//
-// Page Table Entry 4K
-//
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
- UINT64 PAT:1; // 0 = Ignore Page Attribute Table
- UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
- UINT64 Available:3; // Available for use by system software
- UINT64 PageTableBaseAddress:40; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_TABLE_ENTRY_4K;
-
-
-//
-// Page Table Entry 2MB
-//
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
- UINT64 MustBe1:1; // Must be 1
- UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
- UINT64 Available:3; // Available for use by system software
- UINT64 PAT:1; //
- UINT64 MustBeZero:8; // Must be zero;
- UINT64 PageTableBaseAddress:31; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_TABLE_ENTRY_2M;
-
-#pragma pack()
-
-#endif
diff --git a/BaseTools/Source/C/GnuGenBootSector/FatFormat.h b/BaseTools/Source/C/GnuGenBootSector/FatFormat.h
deleted file mode 100644
index e244f1507c..0000000000
--- a/BaseTools/Source/C/GnuGenBootSector/FatFormat.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/** @file
-
- Fat file system structure and definition.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
---*/
-
-#ifndef _FAT_BPB_H_
-#define _FAT_BPB_H_
-
-#include "CommonLib.h"
-
-#pragma pack(1)
-
-typedef struct {
- //
- // Fat common field
- //
- UINT8 BS_jmpBoot[3];
- CHAR8 BS_OEMName[8];
- UINT16 BPB_BytsPerSec;
- UINT8 BPB_SecPerClus;
- UINT16 BPB_RsvdSecCnt;
- UINT8 BPB_NumFATs;
- UINT16 BPB_RootEntCnt;
- UINT16 BPB_TotSec16;
- UINT8 BPB_Media;
- UINT16 BPB_FATSz16;
- UINT16 BPB_SecPerTrk;
- UINT16 BPB_NumHeads;
- UINT32 BPB_HiddSec;
- UINT32 BPB_TotSec32;
-
- //
- // Fat12/16 specific field
- //
- UINT8 BS_DrvNum;
- UINT8 BS_Reserved1;
- UINT8 BS_BootSig;
- UINT32 BS_VolID;
- CHAR8 BS_VolLab[11];
- CHAR8 BS_FilSysType[8];
-
- //
- // Boot Code and Data
- //
- UINT8 Reserved[448];
-
- //
- // Fat common signature - 0xAA55
- //
- UINT16 Signature;
-} FAT12_16_BPB_STRUCT;
-
-typedef struct {
- //
- // Fat common field
- //
- UINT8 BS_jmpBoot[3];
- CHAR8 BS_OEMName[8];
- UINT16 BPB_BytsPerSec;
- UINT8 BPB_SecPerClus;
- UINT16 BPB_RsvdSecCnt;
- UINT8 BPB_NumFATs;
- UINT16 BPB_RootEntCnt;
- UINT16 BPB_TotSec16;
- UINT8 BPB_Media;
- UINT16 BPB_FATSz16;
- UINT16 BPB_SecPerTrk;
- UINT16 BPB_NumHeads;
- UINT32 BPB_HiddSec;
- UINT32 BPB_TotSec32;
-
- //
- // Fat32 specific field
- //
- UINT32 BPB_FATSz32;
- UINT16 BPB_ExtFlags;
- UINT16 BPB_FSVer;
- UINT32 BPB_RootClus;
- UINT16 BPB_FSInfo;
- UINT16 BPB_BkBootSec;
- UINT8 BPB_Reserved[12];
- UINT8 BS_DrvNum;
- UINT8 BS_Reserved1;
- UINT8 BS_BootSig;
- UINT32 BS_VolID;
- CHAR8 BS_VolLab[11];
- CHAR8 BS_FilSysType[8];
-
- //
- // Boot Code and Data
- //
- UINT8 Reserved[420];
-
- //
- // Fat common signature - 0xAA55
- //
- UINT16 Signature;
-} FAT32_BPB_STRUCT;
-
-typedef union {
- FAT12_16_BPB_STRUCT Fat12_16;
- FAT32_BPB_STRUCT Fat32;
-} FAT_BPB_STRUCT;
-
-typedef enum {
- FatTypeUnknown,
- FatTypeFat12,
- FatTypeFat16,
- FatTypeFat32,
- FatTypeMax
-} FAT_TYPE;
-
-typedef struct {
- CHAR8 DIR_Name[11];
- UINT8 DIR_Attr;
- UINT8 DIR_NTRes;
- UINT8 DIR_CrtTimeTenth;
- UINT16 DIR_CrtTime;
- UINT16 DIR_CrtDate;
- UINT16 DIR_LstAccDate;
- UINT16 DIR_FstClusHI;
- UINT16 DIR_WrtTime;
- UINT16 DIR_WrtDate;
- UINT16 DIR_FstClusLO;
- UINT32 DIR_FileSize;
-} FAT_DIRECTORY_ENTRY;
-
-#pragma pack()
-
-#define FAT_MAX_FAT12_CLUSTER 0xFF5
-#define FAT_MAX_FAT16_CLUSTER 0xFFF5
-
-#define FAT_BS_SIGNATURE 0xAA55
-#define FAT_BS_BOOTSIG 0x29
-#define FAT_BS_JMP1 0xEB
-#define FAT_BS_JMP2 0xE9
-#define FAT_FILSYSTYPE "FAT "
-#define FAT12_FILSYSTYPE "FAT12 "
-#define FAT16_FILSYSTYPE "FAT16 "
-#define FAT32_FILSYSTYPE "FAT32 "
-
-#endif
diff --git a/BaseTools/Source/C/GnuGenBootSector/GNUmakefile b/BaseTools/Source/C/GnuGenBootSector/GNUmakefile
deleted file mode 100644
index 2c9d887f4a..0000000000
--- a/BaseTools/Source/C/GnuGenBootSector/GNUmakefile
+++ /dev/null
@@ -1,21 +0,0 @@
-## @file
-# GNU/Linux makefile for 'GnuGenBootSector' module build.
-#
-# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
-# 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.
-#
-MAKEROOT ?= ..
-
-APPNAME = GnuGenBootSector
-
-LIBS = -lCommon
-
-OBJECTS = GnuGenBootSector.o
-
-include $(MAKEROOT)/Makefiles/app.makefile
diff --git a/BaseTools/Source/C/GnuGenBootSector/GnuGenBootSector.c b/BaseTools/Source/C/GnuGenBootSector/GnuGenBootSector.c
deleted file mode 100644
index 6cdffcba3a..0000000000
--- a/BaseTools/Source/C/GnuGenBootSector/GnuGenBootSector.c
+++ /dev/null
@@ -1,455 +0,0 @@
-/** @file
-Reading/writing MBR/DBR.
- NOTE:
- If we write MBR to disk, we just update the MBR code and the partition table wouldn't be over written.
- If we process DBR, we will patch MBR to set first partition active if no active partition exists.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-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.
-
-**/
-
-#include "CommonLib.h"
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <Common/UefiBaseTypes.h>
-
-#include "ParseInf.h"
-#include "EfiUtilityMsgs.h"
-
-//
-// Utility Name
-//
-#define UTILITY_NAME "GnuGenBootSector"
-
-//
-// Utility version information
-//
-#define UTILITY_MAJOR_VERSION 0
-#define UTILITY_MINOR_VERSION 1
-
-#define MAX_DRIVE 26
-#define PARTITION_TABLE_OFFSET 0x1BE
-
-#define SIZE_OF_PARTITION_ENTRY 0x10
-
-#define PARTITION_ENTRY_STARTLBA_OFFSET 8
-
-#define PARTITION_ENTRY_NUM 4
-
-#define DRIVE_UNKNOWN 0
-#define DRIVE_NO_ROOT_DIR 1
-#define DRIVE_REMOVABLE 2
-#define DRIVE_FIXED 3
-#define DRIVE_REMOTE 4
-#define DRIVE_CDROM 5
-#define DRIVE_RAMDISK 6
-
-typedef struct _DRIVE_TYPE_DESC {
- UINTN Type;
- CHAR8 *Description;
-} DRIVE_TYPE_DESC;
-
-#define DRIVE_TYPE_ITEM(x) {x, #x}
-
-DRIVE_TYPE_DESC DriveTypeDesc[] = {
- DRIVE_TYPE_ITEM (DRIVE_UNKNOWN),
- DRIVE_TYPE_ITEM (DRIVE_NO_ROOT_DIR),
- DRIVE_TYPE_ITEM (DRIVE_REMOVABLE),
- DRIVE_TYPE_ITEM (DRIVE_FIXED),
- DRIVE_TYPE_ITEM (DRIVE_REMOTE),
- DRIVE_TYPE_ITEM (DRIVE_CDROM),
- DRIVE_TYPE_ITEM (DRIVE_RAMDISK),
- {(UINTN) -1, NULL}
-};
-
-typedef struct _DRIVE_INFO {
- CHAR8 VolumeLetter;
- DRIVE_TYPE_DESC *DriveType;
- UINTN DiskNumber;
-} DRIVE_INFO;
-
-typedef enum {
- PathUnknown,
- PathFile,
- PathFloppy,
- PathUsb,
- PathIde
-} PATH_TYPE;
-
-typedef struct _PATH_INFO {
- CHAR8 *Path;
- CHAR8 PhysicalPath[260];
- PATH_TYPE Type;
- BOOLEAN Input;
-} PATH_INFO;
-
-typedef enum {
- ErrorSuccess,
- ErrorFileCreate,
- ErrorFileReadWrite,
- ErrorNoMbr,
- ErrorFatType,
- ErrorPath,
-} ERROR_STATUS;
-
-CHAR8 *ErrorStatusDesc[] = {
- "Success",
- "Failed to create files",
- "Failed to read/write files",
- "No MBR exists",
- "Failed to detect Fat type",
- "Inavlid path"
-};
-
-
-//UnSupported Windows API functions.
-UINTN GetLogicalDrives(void) { return 1; }
-
-
-
-/**
- Get path information, including physical path for Linux platform.
-
- @param PathInfo Point to PATH_INFO structure.
-
- @return whether path is valid.
-**/
-ERROR_STATUS
-GetPathInfo (
- PATH_INFO *PathInfo
- )
-{
- FILE *f;
-
- if (strncmp(PathInfo->Path, "/dev/", 5) == 0) {
- //
- // Process disk path here.
- //
-
- // Process floppy disk
- if (PathInfo->Path[5] == 'f' && PathInfo->Path[6] == 'd' && PathInfo->Path[8] == '\0') {
- PathInfo->Type = PathFloppy;
- strcpy (PathInfo->PhysicalPath, PathInfo->Path);
-
- return ErrorSuccess;
- } else {
- // Other disk types is not supported yet.
- fprintf (stderr, "ERROR: It's not a floppy disk!\n");
- return ErrorPath;
- }
-
- // Try to open the device.
- f = fopen (LongFilePath (PathInfo->Path),"r");
- if (f == NULL) {
- printf ("error :open device failed!\n");
- return ErrorPath;
- }
- fclose (f);
- return ErrorSuccess;
- }
-
- // Process file path here.
- PathInfo->Type = PathFile;
- if (PathInfo->Input) {
- // If path is file path, check whether file is valid.
- printf("Path = %s\n",PathInfo->Path);
- f = fopen (LongFilePath (PathInfo->Path), "r");
- if (f == NULL) {
- fprintf (stderr, "Test error E2003: File was not provided!\n");
- return ErrorPath;
- }
- fclose (f);
- }
-
- strcpy(PathInfo->PhysicalPath, PathInfo->Path);
- return ErrorSuccess;
-
-}
-
-VOID
-ListDrive (
- VOID
- )
-{
- printf("-l or -list not supported!\n");
-}
-
-/**
- Writing or reading boot sector or MBR according to the argument.
-
- @param InputInfo PATH_INFO instance for input path
- @param OutputInfo PATH_INFO instance for output path
- @param ProcessMbr TRUE is to process MBR, otherwise, processing boot sector
-
- @return ERROR_STATUS
- **/
-ERROR_STATUS
-ProcessBsOrMbr (
- PATH_INFO *InputInfo,
- PATH_INFO *OutputInfo,
- BOOLEAN ProcessMbr
- )
-{
- CHAR8 FirstSector[0x200] = {0};
- CHAR8 FirstSectorBackup[0x200] = {0};
-
- FILE *InputFile;
- FILE *OutputFile;
-
-
- InputFile = fopen (LongFilePath (InputInfo->PhysicalPath), "r");
- if (InputFile == NULL) {
- return ErrorFileReadWrite;
- }
-
- if (0x200 != fread(FirstSector, 1, 0x200, InputFile)) {
- fclose(InputFile);
- return ErrorFileReadWrite;
- }
-
- fclose(InputFile);
-
- //Not support USB and IDE.
- if (InputInfo->Type == PathUsb) {
- printf("USB has not been supported yet!");
- return ErrorSuccess;
- }
-
- if (InputInfo->Type == PathIde) {
- printf("IDE has not been supported yet!");
- return ErrorSuccess;
- }
-
- //Process Floppy Disk
- OutputFile = fopen (LongFilePath (OutputInfo->PhysicalPath), "r+");
- if (OutputFile == NULL) {
- OutputFile = fopen (LongFilePath (OutputInfo->PhysicalPath), "w");
- if (OutputFile == NULL) {
- return ErrorFileReadWrite;
- }
- }
-
- if (OutputInfo->Type != PathFile) {
- if (ProcessMbr) {
- //
- // Use original partition table
- //
- if (0x200 != fread (FirstSectorBackup, 1, 0x200, OutputFile)) {
- fclose(OutputFile);
- return ErrorFileReadWrite;
- }
- memcpy (FirstSector + 0x1BE, FirstSectorBackup + 0x1BE, 0x40);
- }
- }
- if(0x200 != fwrite(FirstSector, 1, 0x200, OutputFile)) {
- fclose(OutputFile);
- return ErrorFileReadWrite;
- }
-
- fclose(OutputFile);
- return ErrorSuccess;
-}
-
-
-/**
-
- Displays the standard utility information to SDTOUT
-
-**/
-VOID
-Version (
- VOID
- )
-{
- printf ("%s v%d.%d %s-Utility to retrieve and update the boot sector or MBR.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
- printf ("Copyright (c) 2007-2014 Intel Corporation. All rights reserved.\n");
-}
-
-
-VOID
-PrintUsage (
- VOID
- )
-{
- Version();
- printf ("\nUsage: \n\
- GenBootSector\n\
- [-l, --list list disks]\n\
- [-i, --input Filename]\n\
- [-o, --output Filename]\n\
- [-m, --mbr process the MBR also]\n\
- [-v, --verbose]\n\
- [--version]\n\
- [-q, --quiet disable all messages except fatal errors]\n\
- [-d, --debug[#]\n\
- [-h, --help]\n");
-}
-
-int
-main (
- int argc,
- char *argv[]
- )
-{
- INTN Index;
- BOOLEAN ProcessMbr;
- ERROR_STATUS Status;
- EFI_STATUS EfiStatus;
- PATH_INFO InputPathInfo;
- PATH_INFO OutputPathInfo;
- UINT64 LogLevel;
-
- SetUtilityName (UTILITY_NAME);
-
- ZeroMem(&InputPathInfo, sizeof(PATH_INFO));
- ZeroMem(&OutputPathInfo, sizeof(PATH_INFO));
-
- argv ++;
- argc --;
-
- ProcessMbr = FALSE;
-
- if (argc == 0) {
- PrintUsage();
- return 0;
- }
-
- //
- // Parse command line
- //
- for (Index = 0; Index < argc; Index ++) {
- if ((stricmp (argv[Index], "-l") == 0) || (stricmp (argv[Index], "--list") == 0)) {
- ListDrive ();
- return 0;
- }
-
- if ((stricmp (argv[Index], "-m") == 0) || (stricmp (argv[Index], "--mbr") == 0)) {
- ProcessMbr = TRUE;
- continue;
- }
-
- if ((stricmp (argv[Index], "-i") == 0) || (stricmp (argv[Index], "--input") == 0)) {
- InputPathInfo.Path = argv[Index + 1];
- InputPathInfo.Input = TRUE;
- if (InputPathInfo.Path == NULL) {
- Error (NULL, 0, 1003, "Invalid option value", "Input file name can't be NULL");
- return 1;
- }
- if (InputPathInfo.Path[0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Input file is missing");
- return 1;
- }
- ++Index;
- continue;
- }
-
- if ((stricmp (argv[Index], "-o") == 0) || (stricmp (argv[Index], "--output") == 0)) {
- OutputPathInfo.Path = argv[Index + 1];
- OutputPathInfo.Input = FALSE;
- if (OutputPathInfo.Path == NULL) {
- Error (NULL, 0, 1003, "Invalid option value", "Output file name can't be NULL");
- return 1;
- }
- if (OutputPathInfo.Path[0] == '-') {
- Error (NULL, 0, 1003, "Invalid option value", "Output file is missing");
- return 1;
- }
- ++Index;
- continue;
- }
-
- if ((stricmp (argv[Index], "-h") == 0) || (stricmp (argv[Index], "--help") == 0)) {
- PrintUsage ();
- return 0;
- }
-
- if (stricmp (argv[Index], "--version") == 0) {
- Version ();
- return 0;
- }
-
- if ((stricmp (argv[Index], "-v") == 0) || (stricmp (argv[Index], "--verbose") == 0)) {
- continue;
- }
-
- if ((stricmp (argv[Index], "-q") == 0) || (stricmp (argv[Index], "--quiet") == 0)) {
- continue;
- }
-
- if ((stricmp (argv[Index], "-d") == 0) || (stricmp (argv[Index], "--debug") == 0)) {
- EfiStatus = AsciiStringToUint64 (argv[Index + 1], FALSE, &LogLevel);
- if (EFI_ERROR (EfiStatus)) {
- Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[Index], argv[Index + 1]);
- return 1;
- }
- if (LogLevel > 9) {
- Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) LogLevel);
- return 1;
- }
- SetPrintLevel (LogLevel);
- DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[Index + 1]);
- ++Index;
- continue;
- }
-
- //
- // Don't recognize the parameter.
- //
- Error (NULL, 0, 1000, "Unknown option", "%s", argv[Index]);
- return 1;
- }
-
- if (InputPathInfo.Path == NULL) {
- Error (NULL, 0, 1001, "Missing options", "Input file is missing");
- return 1;
- }
-
- if (OutputPathInfo.Path == NULL) {
- Error (NULL, 0, 1001, "Missing options", "Output file is missing");
- return 1;
- }
-
- if (GetPathInfo(&InputPathInfo) != ErrorSuccess) {
- Error (NULL, 0, 1003, "Invalid option value", "Input file can't be found.");
- return 1;
- }
-
- if (GetPathInfo(&OutputPathInfo) != ErrorSuccess) {
- Error (NULL, 0, 1003, "Invalid option value", "Output file can't be found.");
- return 1;
- }
-
- //
- // Process DBR (Patch or Read)
- //
- Status = ProcessBsOrMbr (&InputPathInfo, &OutputPathInfo, ProcessMbr);
-
- if (Status == ErrorSuccess) {
- fprintf (
- stdout,
- "%s %s: successful!\n",
- (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
- ProcessMbr ? "MBR" : "DBR"
- );
- return 0;
- } else {
- fprintf (
- stderr,
- "%s: %s %s: failed - %s (LastError: 0x%x)!\n",
- (Status == ErrorNoMbr) ? "WARNING" : "ERROR",
- (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
- ProcessMbr ? "MBR" : "DBR",
- ErrorStatusDesc[Status],
- errno
- );
- return 1;
- }
-}
diff --git a/BaseTools/Source/C/Makefile b/BaseTools/Source/C/Makefile
index 1f235e5202..5806dcedd9 100644
--- a/BaseTools/Source/C/Makefile
+++ b/BaseTools/Source/C/Makefile
@@ -18,20 +18,16 @@ LIBRARIES = Common
APPLICATIONS = \
VfrCompile \
BrotliCompress \
- EfiLdrImage \
EfiRom \
- GenBootSector \
GenCrc32 \
GenFfs \
GenFv \
GenFw \
- GenPage \
GenSec \
LzmaCompress \
Split \
TianoCompress \
VolInfo \
- BootSectImage \
DevicePath
all: libs apps install