1) Sync EdkCompatibilityPkg with EDK 1.04. The changes includes:

1.1) Bug fixes. (For details, please check  Documents & files: Snapshot/Release Notes at https://edk.tianocore.org/servlets/ProjectDocumentList?folderID=43&expandFolder=43&folderID=6)
  1.2) Add new UEFI protocol definitions for AbsolutePointer, FormBrowser2, HiiConfigAccess, HiiConfigRouting, HiiDatabase, HiiFont, HiiImage, HiiString, SimpleTextInputEx, DPC protocol.
  1.3) Add Smbios 2.5, 2.6 supports.

  Incompatible changes hilighted:
  1) EFI_MANAGED_NETWORK_PROTOCOL_GUID changed.
  2) EFI_IP4_IPCONFIG_DATA changed.

2) Add in EdkCompatibilityPkg/EdkCompatibilityPkg.dsc to build all libraries in this package.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4624 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2008-01-24 07:29:31 +00:00
parent c7f33ca424
commit 95d675b527
87 changed files with 19753 additions and 3613 deletions

View File

@ -1,58 +0,0 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiCompNameSupport.h
Abstract:
Private data structures for the Console Splitter driver
--*/
#ifndef EFI_COMPONENT_NAME_SUPPORT_H
#define EFI_COMPONENT_NAME_SUPPORT_H
#include "Tiano.h"
#ifndef EFI_SIZE_REDUCTION_APPLIED
#define INSTALL_ALL_DRIVER_PROTOCOLS(ImageHandle, \
SystemTable, \
DriverBinding, \
DriverBindingHandle, \
ComponentName, \
DriverConfiguration, \
DriverDiagnostics) \
EfiLibInstallAllDriverProtocols ((ImageHandle), \
(SystemTable), \
(DriverBinding), \
(DriverBindingHandle), \
(ComponentName), \
(DriverConfiguration), \
(DriverDiagnostics))
#else
#define INSTALL_ALL_DRIVER_PROTOCOLS(ImageHandle, \
SystemTable, \
DriverBinding, \
DriverBindingHandle, \
ComponentName, \
DriverConfiguration, \
DriverDiagnostics) \
EfiLibInstallDriverBinding ((ImageHandle), \
(SystemTable), \
(DriverBinding), \
(DriverBindingHandle))
#endif
#endif

View File

@ -87,10 +87,15 @@ DEPEX_TYPE = EFI_SECTION_PEI_DEPEX
DEPEX_TYPE = EFI_SECTION_DXE_DEPEX
!ENDIF
!IF "$(COMPONENT_TYPE)" != "LIBRARY" && EXIST($(BUILD_DIR)\$(PROCESSOR)\CompilerStub.lib)
LIBS = $(LIBS) $(BUILD_DIR)\$(PROCESSOR)\CompilerStub.lib
!ENDIF
#
# Command flags for MAKEDEPS tool
#
DEP_FLAGS = -target $** -o $(DEP_FILE) $(INC) -ignorenotfound -q
DEP_FLAGS2 = -target $@ -o $(DEP_FILE) -cl
[=============================================================================]
#
@ -112,8 +117,15 @@ DEP_FLAGS = -target $** -o $(DEP_FILE) $(INC) -ignorenotfound -q
[=============================================================================]
[Compile.Ia32.asm,Compile.x64.asm]
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(FILE)Asm.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE)Asm.dep
!IF !EXIST($(DEP_FILE))
@ -121,10 +133,6 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
@ -140,67 +148,58 @@ $(DEST_DIR)\$(FILE).obj : $(SOURCE_FILE_NAME) $(INF_FILENAME) $(ALL_DEPS)
[=============================================================================]
[Compile.Ipf.s]
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(FILE)S.dep
!IF EXIST($(DEST_DIR)\$(FILE).pro)
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE)S.dep
!IF !EXIST($(DEP_FILE))
CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(DEST_DIR)\$(FILE).pro
$(MAKEDEPS) -f $(SOURCE_FILE_NAME) $(DEP_FLAGS)
#
# Compile the file
#
$(DEST_DIR)\$(FILE).pro : $(SOURCE_FILE_NAME) $(INF_FILENAME) $(ALL_DEPS)
$(CC) $(C_FLAGS_PRO) $(SOURCE_FILE_NAME) > $@
$(DEST_DIR)\$(FILE).obj : $(DEST_DIR)\$(FILE).pro
$(ASM) $(ASM_FLAGS) $(DEST_DIR)\$(FILE).pro
[=============================================================================]
[Compile.Ia32.c,Compile.Ipf.c,Compile.x64.c]
DEP_FILE = $(DEST_DIR)\$(FILE).dep
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE).dep
!IF !EXIST($(DEP_FILE))
CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(DEST_DIR)\$(FILE).obj
$(MAKEDEPS) -f $(SOURCE_FILE_NAME) $(DEP_FLAGS)
!ENDIF
#
# Compile the file
#
$(DEST_DIR)\$(FILE).obj : $(SOURCE_FILE_NAME) $(INF_FILENAME) $(ALL_DEPS)
$(CC) $(C_FLAGS) $(SOURCE_FILE_NAME)
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
$(CC) $(C_FLAGS_PRO) $(SOURCE_FILE_NAME) > $(DEST_DIR)\$(FILE).pro
!ELSE
-$(CC) $(C_FLAGS_PRO) $(SOURCE_FILE_NAME) /showIncludes > $(DEST_DIR)\$(FILE).pro 2> $(DEST_DIR)\$(FILE)S.cl
@$(MAKEDEPS) -f $(DEST_DIR)\$(FILE)S.cl $(DEP_FLAGS2)
!ENDIF
$(ASM) $(ASM_FLAGS) $(DEST_DIR)\$(FILE).pro
[=============================================================================]
[Compile.Ebc.c]
[Compile.Ia32.c,Compile.Ipf.c,Compile.x64.c]
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(FILE).dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE).dep
!IF !EXIST($(DEP_FILE))
@ -208,10 +207,44 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(DEST_DIR)\$(FILE).obj
$(MAKEDEPS) -f $(SOURCE_FILE_NAME) $(DEP_FLAGS)
!ENDIF
#
# Compile the file
#
$(DEST_DIR)\$(FILE).obj : $(SOURCE_FILE_NAME) $(INF_FILENAME) $(ALL_DEPS)
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
$(CC) $(C_FLAGS) $(SOURCE_FILE_NAME)
!ELSE
-$(CC) $(C_FLAGS) $(SOURCE_FILE_NAME) /showIncludes > $(DEST_DIR)\$(FILE).cl
@$(MAKEDEPS) -f $(DEST_DIR)\$(FILE).cl $(DEP_FLAGS2)
!ENDIF
[=============================================================================]
[Compile.Ebc.c]
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(FILE).dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE).dep
!IF !EXIST($(DEP_FILE))
CREATEDEPS = YES
!ENDIF
!ENDIF
#
# Update dep file for next round incremental build
#
@ -351,8 +384,32 @@ clean :
#
LIB_NAME = $(LIB_DIR)\$(BASE_NAME).lib
#
# $(DEP_TARGETS) are not needed for binary build.
#
!IF ("$(BINARY)" == "TRUE") || (("$(BINARY)" == "") && ("$(EFI_BINARY_LIBRARY)" == "YES"))
DEP_TARGETS=
CREATEDEPS=
!ENDIF
#
# Module can be built from source code or binary files.
#
!IF ((("$(BINARY)" == "TRUE") || (("$(BINARY)" == "") && ("$(EFI_BINARY_LIBRARY)" == "YES"))) \
&& EXIST($(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).lib))
$(LIB_NAME) : $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).lib
copy $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).lib $(LIB_NAME) /Y
if exist $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME)Obj.pdb \
copy $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME)Obj.pdb $(DEST_DIR)\$(BASE_NAME)Obj.pdb /Y
!ELSE
$(LIB_NAME) : $(OBJECTS) $(LIBS) $(INF_FILENAME) $(ENV_DEPS)
$(LIB) $(LIB_FLAGS) $(OBJECTS) $(LIBS) /OUT:$@
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\$(PROCESSOR) mkdir $(EFI_PLATFORM_BIN)\$(PROCESSOR)
if exist $(LIB_NAME) copy $(LIB_NAME) $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).lib /Y
if exist $(DEST_DIR)\$(BASE_NAME)Obj.pdb copy $(DEST_DIR)\$(BASE_NAME)Obj.pdb $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME)Obj.pdb /Y
!ENDIF
!ENDIF
!IF "$(CREATEDEPS)"=="YES"
all : $(DEP_TARGETS)
@ -558,10 +615,31 @@ $(TARGET_PE32) : $(TARGET_EFI)
$(GENSECTION) -I $(TARGET_EFI) -O $(TARGET_PE32) -S EFI_SECTION_PE32
#
# Run FWImage on the DLL to set it as an EFI image type.
# $(DEP_TARGETS) are not needed for binary build.
#
!IF "$(BINARY)" == "TRUE"
DEP_TARGETS=
CREATEDEPS=
!ENDIF
#
# Build module to generate *.efi file from source code or binary file.
#
!IF (("$(BINARY)" == "TRUE") && EXIST($(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi))
LOCALIZE_TARGETS=
$(TARGET_EFI) : $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi
copy $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi $(TARGET_EFI) /Y
if exist $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).pdb \
copy $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).pdb $(TARGET_PDB) /Y
!ELSE
$(TARGET_EFI) : $(TARGET_DLL) $(INF_FILENAME)
$(FWIMAGE) -t 0 $(COMPONENT_TYPE) $(TARGET_DLL) $(TARGET_EFI)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\$(PROCESSOR) mkdir $(EFI_PLATFORM_BIN)\$(PROCESSOR)
if exist $(TARGET_EFI) copy $(TARGET_EFI) $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi /Y
if exist $(TARGET_PDB) copy $(TARGET_PDB) $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).pdb /Y
!ENDIF
!ENDIF
!ENDIF
@ -621,12 +699,18 @@ DPX_SOURCE_FILE = $(DPX_SOURCE_OVERRIDE)
!IF "$(DPX_SOURCE_FILE)" != ""
!IF EXIST ($(DPX_SOURCE_FILE))
#
# Add dependency check for dxs file, because dxs file depends on PPI or
# PROTOCOL guid defintions.
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
!IF EXIST($(TARGET_DPX))
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF !EXIST($(DEP_FILE))
@ -634,17 +718,21 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(TARGET_DPX)
$(MAKEDEPS) -f $(DPX_SOURCE_FILE) $(DEP_FLAGS)
!ENDIF
$(TARGET_DPX) : $(DPX_SOURCE_FILE) $(INF_FILENAME)
$(CC) /nologo $(INC) $(VERSION_FLAGS) /EP $(DPX_SOURCE_FILE) > $*.tmp1
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) > $*.tmp1
!ELSE
-$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) /showIncludes > $*.tmp1 2> $(DEST_DIR)\$(BASE_NAME)dxs.cl
@$(MAKEDEPS) -f $(DEST_DIR)\$(BASE_NAME)dxs.cl $(DEP_FLAGS2)
!ENDIF
$(GENDEPEX) -I $*.tmp1 -O $*.tmp2
$(GENSECTION) -I $*.tmp2 -O $@ -S $(DEPEX_TYPE)
del $*.tmp1 > NUL
@ -666,8 +754,40 @@ $(TARGET_DPX) :
!IF "$(COMPONENT_TYPE)" == "COMBINED_PEIM_DRIVER"
!IF "$(DXE_DPX_SOURCE)" != ""
!IF EXIST ($(SOURCE_DIR)\$(DXE_DPX_SOURCE))
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(BASE_NAME)dxs2.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
!IF EXIST($(TARGET_DXE_DPX))
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(BASE_NAME)dxs2.dep
!IF !EXIST($(DEP_FILE))
CREATEDEPS = YES
!ENDIF
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(TARGET_DXE_DPX)
$(MAKEDEPS) -f $(SOURCE_DIR)\$(DXE_DPX_SOURCE) $(DEP_FLAGS)
!ENDIF
$(TARGET_DXE_DPX) : $(SOURCE_DIR)\$(DXE_DPX_SOURCE) $(INF_FILENAME)
$(CC) /nologo $(INC) $(VERSION_FLAGS) /EP $(SOURCE_DIR)\$(DXE_DPX_SOURCE) > $*.tmp1
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
$(CC) $(C_FLAGS_DPX) $(SOURCE_DIR)\$(DXE_DPX_SOURCE) > $*.tmp1
!ELSE
-$(CC) $(C_FLAGS_DPX) $(SOURCE_DIR)\$(DXE_DPX_SOURCE) /showIncludes > $*.tmp1 2> $(DEST_DIR)\$(BASE_NAME)dxs2.cl
@$(MAKEDEPS) -f $(DEST_DIR)\$(BASE_NAME)dxs2.cl $(DEP_FLAGS2)
!ENDIF
$(GENDEPEX) -I $*.tmp1 -O $*.tmp2
$(GENSECTION) -I $*.tmp2 -O $@ -S EFI_SECTION_DXE_DEPEX
del $*.tmp1 > NUL
@ -778,10 +898,30 @@ $(TARGET_TES) : $(TARGET_TE)
$(GENSECTION) -I $(TARGET_TE) -O $(TARGET_TES) -S EFI_SECTION_TE
#
# Run FWImage on the DLL to set it as an EFI image type.
# $(DEP_TARGETS) are not needed for binary build.
#
!IF "$(BINARY)" == "TRUE"
DEP_TARGETS=
CREATEDEPS=
!ENDIF
#
# Build module to generate *.efi file from source code or binary file.
#
!IF (("$(BINARY)" == "TRUE") && EXIST($(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi))
$(TARGET_EFI) : $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi
copy $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi $(TARGET_EFI) /Y
if exist $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).pdb \
copy $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).pdb $(TARGET_PDB) /Y
!ELSE
$(TARGET_EFI) : $(TARGET_DLL) $(INF_FILENAME)
$(FWIMAGE) $(COMPONENT_TYPE) $(TARGET_DLL) $(TARGET_EFI)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\$(PROCESSOR) mkdir $(EFI_PLATFORM_BIN)\$(PROCESSOR)
if exist $(TARGET_EFI) copy $(TARGET_EFI) $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).efi /Y
if exist $(TARGET_PDB) copy $(TARGET_PDB) $(EFI_PLATFORM_BIN)\$(PROCESSOR)\$(BASE_NAME).pdb /Y
!ENDIF
!ENDIF
#
# Run GenTEImage on the built .efi file to create our TE file.
@ -845,12 +985,18 @@ DPX_SOURCE_FILE = $(DPX_SOURCE_OVERRIDE)
!IF "$(DPX_SOURCE_FILE)" != ""
!IF EXIST ($(DPX_SOURCE_FILE))
#
# Add dependency check for dxs file, because dxs file depends on PPI or
# PROTOCOL guid defintions.
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
!IF EXIST($(TARGET_DPX))
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF !EXIST($(DEP_FILE))
@ -858,17 +1004,21 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(TARGET_DPX)
$(MAKEDEPS) -f $(DPX_SOURCE_FILE) $(DEP_FLAGS)
!ENDIF
$(TARGET_DPX) : $(DPX_SOURCE_FILE) $(INF_FILENAME)
$(CC) /nologo $(INC) $(VERSION_FLAGS) /EP $(DPX_SOURCE_FILE) > $*.tmp1
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) > $*.tmp1
!ELSE
-$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) /showIncludes > $*.tmp1 2> $(DEST_DIR)\$(BASE_NAME)dxs.cl
@$(MAKEDEPS) -f $(DEST_DIR)\$(BASE_NAME)dxs.cl $(DEP_FLAGS2)
!ENDIF
$(GENDEPEX) -I $*.tmp1 -O $*.tmp2
$(GENSECTION) -I $*.tmp2 -O $@ -S $(DEPEX_TYPE)
del $*.tmp1 > NUL
@ -1042,12 +1192,18 @@ DPX_SOURCE_FILE = $(DPX_SOURCE_OVERRIDE)
!IF "$(DPX_SOURCE_FILE)" != ""
!IF EXIST ($(DPX_SOURCE_FILE))
#
# Add dependency check for dxs file, because dxs file depends on PPI or
# PROTOCOL guid defintions.
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
!IF EXIST($(TARGET_DPX))
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF !EXIST($(DEP_FILE))
@ -1055,17 +1211,21 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(TARGET_DPX)
$(MAKEDEPS) -f $(DPX_SOURCE_FILE) $(DEP_FLAGS)
!ENDIF
$(TARGET_DPX) : $(DPX_SOURCE_FILE) $(INF_FILENAME)
$(CC) /nologo $(INC) $(VERSION_FLAGS) /EP $(DPX_SOURCE_FILE) > $*.tmp1
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) > $*.tmp1
!ELSE
-$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) /showIncludes > $*.tmp1 2> $(DEST_DIR)\$(BASE_NAME)dxs.cl
@$(MAKEDEPS) -f $(DEST_DIR)\$(BASE_NAME)dxs.cl $(DEP_FLAGS2)
!ENDIF
$(GENDEPEX) -I $*.tmp1 -O $*.tmp2
$(GENSECTION) -I $*.tmp2 -O $@ -S $(DEPEX_TYPE)
del $*.tmp1 > NUL
@ -1210,12 +1370,18 @@ DPX_SOURCE_FILE = $(DPX_SOURCE_OVERRIDE)
!IF "$(DPX_SOURCE_FILE)" != ""
!IF EXIST ($(DPX_SOURCE_FILE))
#
# Add dependency check for dxs file, because dxs file depends on PPI or
# PROTOCOL guid defintions.
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
!IF EXIST($(TARGET_DPX))
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(BASE_NAME)dxs.dep
!IF !EXIST($(DEP_FILE))
@ -1223,17 +1389,21 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
$(DEP_FILE) : $(TARGET_DPX)
$(MAKEDEPS) -f $(DPX_SOURCE_FILE) $(DEP_FLAGS)
!ENDIF
$(TARGET_DPX) : $(DPX_SOURCE_FILE) $(INF_FILENAME)
$(CC) /nologo $(INC) $(VERSION_FLAGS) /EP $(DPX_SOURCE_FILE) > $*.tmp1
!IF "$(EFI_USE_CL_FOR_DEP)" != "YES"
$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) > $*.tmp1
!ELSE
-$(CC) $(C_FLAGS_DPX) $(DPX_SOURCE_FILE) /showIncludes > $*.tmp1 2> $(DEST_DIR)\$(BASE_NAME)dxs.cl
@$(MAKEDEPS) -f $(DEST_DIR)\$(BASE_NAME)dxs.cl $(DEP_FLAGS2)
!ENDIF
$(GENDEPEX) -I $*.tmp1 -O $*.tmp2
$(GENSECTION) -I $*.tmp2 -O $@ -S $(DEPEX_TYPE)
del $*.tmp1 > NUL
@ -1348,8 +1518,15 @@ LOCALIZE = YES
[=============================================================================]
[Compile.Ia32.Vfr,Compile.Ipf.Vfr,Compile.x64.Vfr]
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(FILE)Vfr.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE)Vfr.dep
!IF !EXIST($(DEP_FILE))
@ -1357,10 +1534,6 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
@ -1425,8 +1598,15 @@ $(DEST_DIR)\$(FILE).obj : $(SOURCE_FILE_NAME) $(INF_FILENAME) $(ALL_DEPS)
[=============================================================================]
[Compile.Ia32.Ifr_Bin,Compile.Ipf.Ifr_Bin,Compile.x64.Ifr_Bin]
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(FILE)Vfr.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE)Vfr.dep
!IF !EXIST($(DEP_FILE))
@ -1434,10 +1614,6 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#
@ -1472,8 +1648,15 @@ HII_IFR_PACK_FILES = $(HII_IFR_PACK_FILES) $(DEST_DIR)\$(FILE).hpk
[=============================================================================]
[Compile.Ebc.Ifr_Bin]
#
# Add build dependency check
#
DEP_FILE = $(DEST_DIR)\$(FILE)Vfr.dep
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
!IF EXIST($(DEST_DIR)\$(FILE).obj)
DEP_TARGETS = $(DEP_TARGETS) $(DEST_DIR)\$(FILE)Vfr.dep
!IF !EXIST($(DEP_FILE))
@ -1481,10 +1664,6 @@ CREATEDEPS = YES
!ENDIF
!ENDIF
!IF EXIST($(DEP_FILE))
!INCLUDE $(DEP_FILE)
!ENDIF
#
# Update dep file for next round incremental build
#

View File

@ -275,7 +275,6 @@ IMAGE_SCRIPT =
}
}
[=============================================================================]
[Package.BS_DRIVER.Default,Package.RT_DRIVER.Default]
PACKAGE.INF
@ -359,6 +358,7 @@ IMAGE_SCRIPT =
$(SOURCE_FV)Fv.sec
}
}
[=============================================================================]
#
# Stripped package descriptions for size reduction.
@ -422,6 +422,7 @@ IMAGE_SCRIPT =
{
$(BASE_NAME).tes
}
[=============================================================================]
[Package.PE32_PEIM.DefaultStripped]
PACKAGE.INF
@ -504,7 +505,6 @@ IMAGE_SCRIPT =
}
}
[=============================================================================]
[Package.BS_DRIVER.DefaultStripped,Package.RT_DRIVER.DefaultStripped]
PACKAGE.INF
@ -522,7 +522,6 @@ IMAGE_SCRIPT =
}
}
[=============================================================================]
[Package.FvImageFile.DefaultStripped]
PACKAGE.INF
@ -556,3 +555,41 @@ IMAGE_SCRIPT =
}
[=============================================================================]
[Package.AcpiTable.Default]
PACKAGE.INF
\[.]
BASE_NAME = $(BASE_NAME)
FFS_FILEGUID = $(FILE_GUID)
FFS_FILETYPE = EFI_FV_FILETYPE_FREEFORM
FFS_ATTRIB_CHECKSUM = TRUE
IMAGE_SCRIPT =
{
Compress ($(COMPRESS_METHOD)) {
Tool (
$(OEMTOOLPATH)\GenCRC32Section
ARGS= -i $(SECTION_TARGETS)
$(DEST_DIR)\$(BASE_NAME).ui
-o $(DEST_DIR)\$(BASE_NAME).crc32
OUTPUT = $(DEST_DIR)\$(BASE_NAME).crc32
)
}
}
[=============================================================================]
[Package.AcpiTable.DefaultStripped]
PACKAGE.INF
\[.]
BASE_NAME = $(BASE_NAME)
FFS_FILEGUID = $(FILE_GUID)
FFS_FILETYPE = EFI_FV_FILETYPE_FREEFORM
FFS_ATTRIB_CHECKSUM = TRUE
IMAGE_SCRIPT =
{
Compress ($(COMPRESS_METHOD)) {
$(SECTION_TARGETS)
}
}
[=============================================================================]

View File

@ -269,7 +269,6 @@ IMAGE_SCRIPT =
$(BASE_NAME).ver \
}
[=============================================================================]
[Package.DxeIplPad.Default]
PACKAGE.INF
@ -285,7 +284,6 @@ IMAGE_SCRIPT =
$(BASE_NAME).pad \
}
[=============================================================================]
[Package.BS_DRIVER.DxeMain]
PACKAGE.INF
@ -304,7 +302,6 @@ IMAGE_SCRIPT =
}
}
[=============================================================================]
[Package.BS_DRIVER.Default,Package.RT_DRIVER.Default,Package.SAL_RT_DRIVER.Default]
PACKAGE.INF
@ -388,4 +385,27 @@ IMAGE_SCRIPT =
$(SOURCE_FV)Fv.sec
}
}
[=============================================================================]
[Package.AcpiTable.Default]
PACKAGE.INF
\[.]
BASE_NAME = $(BASE_NAME)
FFS_FILEGUID = $(FILE_GUID)
FFS_FILETYPE = EFI_FV_FILETYPE_FREEFORM
FFS_ATTRIB_CHECKSUM = TRUE
IMAGE_SCRIPT =
{
Compress ($(COMPRESS_METHOD)) {
Tool (
$(OEMTOOLPATH)\GenCRC32Section
ARGS= -i $(SECTION_TARGETS)
$(DEST_DIR)\$(BASE_NAME).ui
-o $(DEST_DIR)\$(BASE_NAME).crc32
OUTPUT = $(DEST_DIR)\$(BASE_NAME).crc32
)
}
}
[=============================================================================]

View File

@ -275,7 +275,6 @@ IMAGE_SCRIPT =
}
}
[=============================================================================]
[Package.BS_DRIVER.Default,Package.RT_DRIVER.Default,Package.SAL_RT_DRIVER.Default]
PACKAGE.INF
@ -406,6 +405,7 @@ IMAGE_SCRIPT =
{
$(BASE_NAME).tes
}
[=============================================================================]
[Package.PE32_PEIM.DefaultStripped]
PACKAGE.INF
@ -488,7 +488,6 @@ IMAGE_SCRIPT =
}
}
[=============================================================================]
[Package.BS_DRIVER.DefaultStripped,Package.RT_DRIVER.DefaultStripped,Package.SAL_RT_DRIVER.DefaultStripped]
PACKAGE.INF
@ -506,7 +505,6 @@ IMAGE_SCRIPT =
}
}
[=============================================================================]
[Package.FvImageFile.DefaultStripped]
PACKAGE.INF
@ -539,6 +537,7 @@ IMAGE_SCRIPT =
$(SOURCE_FV)Fv.sec
}
}
[=============================================================================]
[Package.SECURITY_CORE.Default|DefaultStripped]
PACKAGE.INF
@ -556,3 +555,41 @@ IMAGE_SCRIPT =
}
[=============================================================================]
[Package.AcpiTable.Default]
PACKAGE.INF
\[.]
BASE_NAME = $(BASE_NAME)
FFS_FILEGUID = $(FILE_GUID)
FFS_FILETYPE = EFI_FV_FILETYPE_FREEFORM
FFS_ATTRIB_CHECKSUM = TRUE
IMAGE_SCRIPT =
{
Compress ($(COMPRESS_METHOD)) {
Tool (
$(OEMTOOLPATH)\GenCRC32Section
ARGS= -i $(SECTION_TARGETS)
$(DEST_DIR)\$(BASE_NAME).ui
-o $(DEST_DIR)\$(BASE_NAME).crc32
OUTPUT = $(DEST_DIR)\$(BASE_NAME).crc32
)
}
}
[=============================================================================]
[Package.AcpiTable.DefaultStripped]
PACKAGE.INF
\[.]
BASE_NAME = $(BASE_NAME)
FFS_FILEGUID = $(FILE_GUID)
FFS_FILETYPE = EFI_FV_FILETYPE_FREEFORM
FFS_ATTRIB_CHECKSUM = TRUE
IMAGE_SCRIPT =
{
Compress ($(COMPRESS_METHOD)) {
$(SECTION_TARGETS)
}
}
[=============================================================================]

View File

@ -37,3 +37,4 @@ $(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiHobLib\PeiHobLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiReportStatusCodeLib\PeiReportStatusCodeLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiResourcePublicationLib\PeiResourcePublicationLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiSmbusLib\PeiSmbusLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiPerformanceLib\PeiPerformanceLib.inf

View File

@ -51,4 +51,6 @@ $(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\DxeServicesTableLib\DxeServ
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\EdkDxeSalLib\EdkDxeSalLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\EdkDxeRuntimeDriverLib\EdkDxeRuntimeDriverLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\DxeSmbusLib\DxeSmbusLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiSmbusLib\PeiSmbusLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiSmbusLib\PeiSmbusLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\DxePerformanceLib\DxePerformanceLib.inf
$(EDK_PREFIX)Foundation\Library\EdkIIGlueLib\Library\PeiPerformanceLib\PeiPerformanceLib.inf

View File

@ -1,6 +1,6 @@
#/*++
#
# Copyright (c) 2004 - 2006, Intel Corporation
# Copyright (c) 2004 - 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@ -25,7 +25,6 @@ $(EDK_PREFIX)Foundation\Cpu\Pentium\CpuIA32Lib\CpuIA32Lib.inf
$(EDK_PREFIX)Foundation\Cpu\Itanium\CpuIA64Lib\CpuIA64Lib.inf
$(EDK_PREFIX)Foundation\Library\CustomizedDecompress\CustomizedDecompress.inf
$(EDK_PREFIX)Foundation\Library\CompilerStub\CompilerStubLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\Hob\HobLib.inf
#
# PEI libraries

View File

@ -25,7 +25,6 @@ $(EDK_PREFIX)Foundation\Cpu\Pentium\CpuIA32Lib\CpuIA32Lib.inf
$(EDK_PREFIX)Foundation\Cpu\Itanium\CpuIA64Lib\CpuIA64Lib.inf
$(EDK_PREFIX)Foundation\Library\CustomizedDecompress\CustomizedDecompress.inf
$(EDK_PREFIX)Foundation\Library\CompilerStub\CompilerStubLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\Hob\HobLib.inf
#
# PEI libraries
@ -42,10 +41,12 @@ $(EDK_PREFIX)Foundation\Core\Dxe\ArchProtocol\ArchProtocolLib.inf
$(EDK_PREFIX)Foundation\Efi\Protocol\EfiProtocolLib.inf
$(EDK_PREFIX)Foundation\Framework\Protocol\EdkFrameworkProtocolLib.inf
$(EDK_PREFIX)Foundation\Protocol\EdkProtocolLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\Hob\HobLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\EfiDriverLib\EfiDriverLib.inf
$(EDK_PREFIX)Foundation\Library\RuntimeDxe\EfiRuntimeLib\EfiRuntimeLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\Graphics\Graphics.inf
$(EDK_PREFIX)Foundation\Library\Dxe\EfiIfrSupportLib\EfiIfrSupportLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\UefiEfiIfrSupportLib\UefiEfiIfrSupportLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\Print\PrintLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\EfiScriptLib\EfiScriptLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\EfiUiLib\EfiUiLib.inf
@ -55,9 +56,3 @@ $(EDK_PREFIX)Foundation\Library\Dxe\EfiUiLib\EfiUiLib.inf
#
$(EDK_PREFIX)Foundation\Library\Dxe\PrintLite\PrintLib.inf
$(EDK_PREFIX)Foundation\Library\Dxe\GraphicsLite\Graphics.inf
#
# Module Libraries
#
#$(EDK_PREFIX)Sample\Platform\Generic\Dxe\GenericBds\GenericBds.inf
#$(EDK_PREFIX)Sample\Bus\Usb\UsbLib\Dxe\UsbDxeLib.inf

View File

@ -0,0 +1,138 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
MonoStatusCode.h
Abstract:
Monolithic single PEIM to provide the status code functionality.
The PEIM is a blend of libraries that correspond to the different status code
listeners that a platform installs.
--*/
#ifndef _MONO_STATUS_CODE_H_
#define _MONO_STATUS_CODE_H_
//
// Statements that include other files.
//
#include "Tiano.h"
#include "Pei.h"
#include "PeiLib.h"
#include "EfiCommonLib.h"
//
// Driver Produced DXE Protocol Prototypes
//
#include EFI_PPI_PRODUCER (StatusCode)
//
// Driver Consumed DXE Protocol Prototypes
//
#include EFI_ARCH_PROTOCOL_CONSUMER (StatusCode)
//
// Driver GUID includes
//
#include EFI_GUID_DEFINITION (StatusCode)
#include EFI_GUID_DEFINITION (StatusCodeCallerId)
#include EFI_GUID_DEFINITION (GlobalVariable)
extern EFI_GUID mStatusCodeRuntimeGuid;
//
// Platform specific function Declarations. These must be implemented in a
// subdirectory named PlatformName in a file named PlatformStatusCode.c.
// See D845GRG\PlatformStatusCode.c for an example of a simple status code
// implementation.
// See Nt32\PlatformStatusCode.c for an example of a status code implementation
// that relocates itself into memory.
//
//
// This is the driver entry point and must be defined.
//
EFI_STATUS
EFIAPI
InstallMonoStatusCode (
IN EFI_FFS_FILE_HEADER *FfsHeader,
IN EFI_PEI_SERVICES **PeiServices
)
;
//
// This is the platform function to initialize the listeners desired by the
// platform.
//
VOID
PlatformInitializeStatusCode (
IN EFI_FFS_FILE_HEADER *FfsHeader,
IN EFI_PEI_SERVICES **PeiServices
)
;
//
// This is the platform function that calls all of the listeners desired by the
// platform.
//
EFI_STATUS
EFIAPI
PlatformReportStatusCode (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN EFI_GUID * CallerId,
IN EFI_STATUS_CODE_DATA * Data OPTIONAL
)
;
//
// Platform independent function Declarations
//
//
// Initialize the status code listeners and publish the status code PPI.
//
VOID
EFIAPI
InitializeMonoStatusCode (
IN EFI_FFS_FILE_HEADER *FfsHeader,
IN EFI_PEI_SERVICES **PeiServices
)
;
//
// Convert a DXE status code call into a PEI status code call.
//
EFI_STATUS
EFIAPI
TranslateDxeStatusCodeToPeiStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN EFI_GUID * CallerId,
IN EFI_STATUS_CODE_DATA * Data OPTIONAL
)
;
//
// Publish a HOB that contains the listener to be used by DXE.
//
EFI_STATUS
EFIAPI
InitializeDxeReportStatusCode (
IN EFI_PEI_SERVICES **PeiServices
)
;
#endif

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -26,27 +26,29 @@ Abstract:
#include "BsDataHubStatusCode.h"
//
// Globals only work at BootService Time. NOT at Runtime!
// Initialize FIFO to cache records.
//
static EFI_DATA_HUB_PROTOCOL *mDataHub;
static EFI_LIST_ENTRY *mRecordHead;
static EFI_LIST_ENTRY *mRecordTail;
static INTN mRecordNum = 0;
static EFI_EVENT mLogDataHubEvent;
static EFI_LOCK mStatusCodeReportLock = EFI_INITIALIZE_LOCK_VARIABLE(EFI_TPL_HIGH_LEVEL);
static BOOLEAN mEventHandlerActive = FALSE;
STATIC EFI_LIST_ENTRY mRecordsFifo = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo);
STATIC EFI_LIST_ENTRY mRecordsBuffer = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer);
STATIC EFI_EVENT mLogDataHubEvent;
STATIC BOOLEAN mEventHandlerActive = FALSE;
//
// Cache data hub protocol.
//
STATIC EFI_DATA_HUB_PROTOCOL *mDataHubProtocol;
STATUS_CODE_RECORD_LIST *
AllocateRecordBuffer (
STATIC
DATA_HUB_STATUS_CODE_DATA_RECORD *
AcquireRecordBuffer (
VOID
)
/*++
Routine Description:
Allocate a new record list node and initialize it.
Inserting the node into the list isn't the task of this function.
Return one DATAHUB_STATUSCODE_RECORD space.
The size of free record pool would be extend, if the pool is empty.
Arguments:
@ -58,32 +60,59 @@ Returns:
--*/
{
STATUS_CODE_RECORD_LIST *DataBuffer;
DATAHUB_STATUSCODE_RECORD *Record;
EFI_TPL CurrentTpl;
EFI_LIST_ENTRY *Node;
UINT32 Index;
DataBuffer = NULL;
Record = NULL;
CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
gBS->AllocatePool (EfiBootServicesData, sizeof (STATUS_CODE_RECORD_LIST), &DataBuffer);
if (DataBuffer == NULL) {
return NULL;
if (!IsListEmpty (&mRecordsBuffer)) {
Node = GetFirstNode (&mRecordsBuffer);
RemoveEntryList (Node);
Record = _CR (Node, DATAHUB_STATUSCODE_RECORD, Node);
} else {
if (CurrentTpl > EFI_TPL_NOTIFY) {
gBS->RestoreTPL (CurrentTpl);
return NULL;
}
gBS->RestoreTPL (CurrentTpl);
gBS->AllocatePool (EfiBootServicesData, sizeof (DATAHUB_STATUSCODE_RECORD) * 16, &Record);
if (Record == NULL) {
return NULL;
}
EfiCommonLibZeroMem (Record, sizeof (DATAHUB_STATUSCODE_RECORD) * 16);
CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
for (Index = 1; Index < 16; Index++) {
InsertTailList (&mRecordsBuffer, &Record[Index].Node);
}
}
EfiCommonLibZeroMem (DataBuffer, sizeof (STATUS_CODE_RECORD_LIST));
DataBuffer->Signature = BS_DATA_HUB_STATUS_CODE_SIGNATURE;
Record->Signature = BS_DATA_HUB_STATUS_CODE_SIGNATURE;
InsertTailList (&mRecordsFifo, &Record->Node);
return DataBuffer;
gBS->RestoreTPL (CurrentTpl);
return (DATA_HUB_STATUS_CODE_DATA_RECORD *) (Record->Data);
}
STATIC
DATA_HUB_STATUS_CODE_DATA_RECORD *
AquireEmptyRecordBuffer (
RetrieveRecord (
VOID
)
/*++
Routine Description:
Acquire an empty record buffer from the record list if there's free node,
or allocate one new node and insert it to the list if the list is full and
the function isn't run in EFI_TPL_HIGH_LEVEL.
Retrieve one record from Records FIFO. The record would be removed from FIFO and
release to free record buffer.
Arguments:
@ -91,111 +120,34 @@ Arguments:
Returns:
Pointer to new record buffer. NULL if none available.
Point to record which is ready to be logged, or NULL if the FIFO of record is empty.
--*/
--*/
{
EFI_TPL OldTpl;
STATUS_CODE_RECORD_LIST *DataBuffer;
DATA_HUB_STATUS_CODE_DATA_RECORD *RecordData;
DATAHUB_STATUSCODE_RECORD *Record;
EFI_LIST_ENTRY *Node;
EFI_TPL CurrentTpl;
RecordData = NULL;
CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
DataBuffer = NULL;
if (!IsListEmpty (&mRecordsFifo)) {
Node = GetFirstNode (&mRecordsFifo);
Record = CR (Node, DATAHUB_STATUSCODE_RECORD, Node, BS_DATA_HUB_STATUS_CODE_SIGNATURE);
//
// This function must be reentrant because an event with higher priority may interrupt it
// and also report status code.
//
EfiAcquireLock (&mStatusCodeReportLock);
if (mRecordTail != mRecordHead->ForwardLink) {
if (mRecordNum != 0) {
mRecordHead = mRecordHead->ForwardLink;
}
DataBuffer = CR (mRecordHead, STATUS_CODE_RECORD_LIST, Link, BS_DATA_HUB_STATUS_CODE_SIGNATURE);
mRecordNum++;
EfiReleaseLock (&mStatusCodeReportLock);
//
// Initalize the record buffer is the responsibility of the producer,
// because the consummer is in a lock so must keep it short.
//
EfiCommonLibZeroMem (&DataBuffer->RecordBuffer[0], BYTES_PER_BUFFER);
} else if (mRecordNum < MAX_RECORD_NUM) {
//
// The condition of "mRecordNum < MAX_RECORD_NUM" is not promised,
// because mRecodeNum may be increased out of this lock.
//
EfiReleaseLock (&mStatusCodeReportLock);
//
// Can't allocate additional buffer in EFI_TPL_HIGH_LEVEL.
// Reporting too many status code in EFI_TPL_HIGH_LEVEL may cause status code lost.
//
OldTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
if (OldTpl == EFI_TPL_HIGH_LEVEL) {
return NULL;
}
gBS->RestoreTPL (OldTpl);
DataBuffer = AllocateRecordBuffer ();
if (DataBuffer == NULL) {
return NULL;
}
EfiAcquireLock (&mStatusCodeReportLock);
InsertHeadList (mRecordHead, &DataBuffer->Link);
mRecordHead = mRecordHead->ForwardLink;
mRecordNum++;
EfiReleaseLock (&mStatusCodeReportLock);
} else {
EfiReleaseLock (&mStatusCodeReportLock);
return NULL;
RemoveEntryList (&Record->Node);
InsertTailList (&mRecordsBuffer, &Record->Node);
Record->Signature = 0;
RecordData = (DATA_HUB_STATUS_CODE_DATA_RECORD *) Record->Data;
}
return (DATA_HUB_STATUS_CODE_DATA_RECORD *) DataBuffer->RecordBuffer;
gBS->RestoreTPL (CurrentTpl);
return RecordData;
}
EFI_STATUS
ReleaseRecordBuffer (
IN STATUS_CODE_RECORD_LIST *RecordBuffer
)
/*++
Routine Description:
Release a buffer in the list, remove some nodes to keep the list inital length.
Arguments:
RecordBuffer - Buffer to release
Returns:
EFI_SUCCESS - If DataRecord is valid
EFI_UNSUPPORTED - The record list has empty
--*/
{
ASSERT (RecordBuffer != NULL);
//
// The consummer needn't to be reentrient and the producer won't do any meaningful thing
// when consummer is logging records.
//
if (mRecordNum <= 0) {
return EFI_UNSUPPORTED;
} else if (mRecordNum > INITIAL_RECORD_NUM) {
mRecordTail = mRecordTail->ForwardLink;
RemoveEntryList (&RecordBuffer->Link);
mRecordNum--;
gBS->FreePool (RecordBuffer);
} else {
if (mRecordNum != 1) {
mRecordTail = mRecordTail->ForwardLink;
}
mRecordNum--;
}
return EFI_SUCCESS;
}
EFI_BOOTSERVICE
EFI_STATUS
EFIAPI
BsDataHubReportStatusCode (
@ -222,31 +174,32 @@ Returns:
--*/
{
DATA_HUB_STATUS_CODE_DATA_RECORD *DataHub;
UINT32 ErrorLevel;
VA_LIST Marker;
CHAR8 *Format;
UINTN Index;
CHAR16 FormatBuffer[BYTES_PER_RECORD];
DataHub = NULL;
DATA_HUB_STATUS_CODE_DATA_RECORD *Record;
UINT32 ErrorLevel;
VA_LIST Marker;
CHAR8 *Format;
CHAR16 FormatBuffer[BYTES_PER_RECORD];
UINTN Index;
//
// See whether in runtime phase or not.
//
if (EfiAtRuntime ()) {
//
// For now all we do is post code at runtime
//
return EFI_SUCCESS;
}
//
// If we had an error while in our event handler, then do nothing so
// that we don't get in an endless loop.
// Discard new DataHubRecord caused by DataHub->LogData()
//
if (mEventHandlerActive) {
return EFI_SUCCESS;
}
DataHub = (DATA_HUB_STATUS_CODE_DATA_RECORD *) AquireEmptyRecordBuffer ();
if (DataHub == NULL) {
Record = AcquireRecordBuffer ();
if (Record == NULL) {
//
// There are no empty record buffer in private buffers
//
@ -255,24 +208,15 @@ Returns:
//
// Construct Data Hub Extended Data
//
DataHub->CodeType = CodeType;
DataHub->Value = Value;
DataHub->Instance = Instance;
Record->CodeType = CodeType;
Record->Value = Value;
Record->Instance = Instance;
if (CallerId != NULL) {
EfiCopyMem (&DataHub->CallerId, CallerId, sizeof (EFI_GUID));
} else {
EfiZeroMem (&DataHub->CallerId, sizeof (EFI_GUID));
EfiCopyMem (&Record->CallerId, CallerId, sizeof (EFI_GUID));
}
if (Data == NULL) {
EfiZeroMem (&DataHub->Data, sizeof (EFI_STATUS_CODE_DATA));
} else {
//
// Copy generic Header
//
EfiCopyMem (&DataHub->Data, Data, sizeof (EFI_STATUS_CODE_DATA));
if (Data != NULL) {
if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
//
// Convert Ascii Format string to Unicode.
@ -287,26 +231,25 @@ Returns:
// Put processed string into the buffer
//
Index = VSPrint (
(UINT16 *) (DataHub + 1),
(CHAR16 *) (Record + 1),
BYTES_PER_RECORD - (sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD)),
FormatBuffer,
Marker
);
//
// DATA_HUB_STATUS_CODE_DATA_RECORD followed by VSPrint String Buffer
//
DataHub->Data.Size = (UINT16) (Index * sizeof (CHAR16));
EfiCopyMem (&Record->Data.Type, &gEfiStatusCodeDataTypeDebugGuid, sizeof (EFI_GUID));
Record->Data.HeaderSize = Data->HeaderSize;
Record->Data.Size = (UINT16) (Index * sizeof (CHAR16));
} else {
//
// Default behavior is to copy optional data
// Copy status code data header
//
if (Data->Size > (BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD))) {
DataHub->Data.Size = (UINT16) (BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD));
}
EfiCopyMem (&Record->Data, Data, sizeof (EFI_STATUS_CODE_DATA));
EfiCopyMem (DataHub + 1, Data + 1, DataHub->Data.Size);
if (Data->Size > BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD)) {
Record->Data.Size = (UINT16) (BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD));
}
EfiCopyMem ((VOID *) (Record + 1), Data + 1, Record->Data.Size);
}
}
@ -339,39 +282,34 @@ Returns:
--*/
{
EFI_STATUS Status;
DATA_HUB_STATUS_CODE_DATA_RECORD *DataRecord;
UINTN Size;
DATA_HUB_STATUS_CODE_DATA_RECORD *Record;
UINT32 Size;
UINT64 DataRecordClass;
EFI_LIST_ENTRY *Link;
STATUS_CODE_RECORD_LIST *BufferEntry;
//
// Set our global flag so we don't recurse if we get an error here.
// Set global flag so we don't recurse if DataHub->LogData eventually causes new DataHubRecord
//
mEventHandlerActive = TRUE;
//
// Log DataRecord in Data Hub.
// If there are multiple DataRecords, Log all of them.
// Journal records fifo to find all record entry.
//
Link = mRecordTail;
while (mRecordNum != 0) {
BufferEntry = CR (Link, STATUS_CODE_RECORD_LIST, Link, BS_DATA_HUB_STATUS_CODE_SIGNATURE);
DataRecord = (DATA_HUB_STATUS_CODE_DATA_RECORD *) (BufferEntry->RecordBuffer);
Link = Link->ForwardLink;
while (1) {
Record = RetrieveRecord ();
if (Record == NULL) {
break;
}
//
// Add in the size of the header we added.
//
Size = sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD) + DataRecord->Data.Size;
Size = sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD) + (UINT32) Record->Data.Size;
if ((DataRecord->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
DataRecordClass = EFI_DATA_RECORD_CLASS_PROGRESS_CODE;
} else if ((DataRecord->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
} else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
DataRecordClass = EFI_DATA_RECORD_CLASS_ERROR;
} else if ((DataRecord->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
} else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG;
} else {
//
@ -383,45 +321,27 @@ Returns:
EFI_DATA_RECORD_CLASS_PROGRESS_CODE;
}
if (((DataRecord->Instance & EFI_D_ERROR) != 0) &&
(((DataRecord->Instance & EFI_D_POOL) != 0) || ((DataRecord->Instance & EFI_D_PAGE) != 0))
) {
//
// If memory error, do not call LogData ().
//
ErrorPrint (L"ERROR", "Memory Error\n");
Status = EFI_OUT_OF_RESOURCES;
} else {
//
// We don't log EFI_D_POOL and EFI_D_PAGE debug info to datahub
// to avoid recursive logging due to the memory allocation in datahub
//
if (DataRecordClass != EFI_DATA_RECORD_CLASS_DEBUG ||
((DataRecord->Instance & EFI_D_POOL) == 0 && (DataRecord->Instance & EFI_D_PAGE) == 0)) {
//
// Log DataRecord in Data Hub
//
Status = mDataHub->LogData (
mDataHub,
&gEfiStatusCodeGuid,
&gEfiStatusCodeRuntimeProtocolGuid,
DataRecordClass,
DataRecord,
(UINT32) Size
);
}
}
//
// Log DataRecord in Data Hub
//
mDataHubProtocol->LogData (
mDataHubProtocol,
&gEfiStatusCodeGuid,
&gEfiStatusCodeRuntimeProtocolGuid,
DataRecordClass,
Record,
Size
);
ReleaseRecordBuffer (BufferEntry);
}
mEventHandlerActive = FALSE;
return ;
}
EFI_BOOTSERVICE
EFI_STATUS
EFIAPI
BsDataHubInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
@ -444,38 +364,14 @@ Returns:
--*/
{
EFI_STATUS Status;
STATUS_CODE_RECORD_LIST *DataBuffer;
UINTN Index1;
DataBuffer = NULL;
Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &mDataHub);
//
// Should never fail due to dependency grammer
//
Status = gBS->LocateProtocol (
&gEfiDataHubProtocolGuid,
NULL,
(VOID **) &mDataHubProtocol
);
ASSERT_EFI_ERROR (Status);
//
// Initialize a record list with length not greater than INITIAL_RECORD_NUM.
// If no buffer can be allocated, return EFI_OUT_OF_RESOURCES.
//
DataBuffer = AllocateRecordBuffer ();
if (DataBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
mRecordHead = &DataBuffer->Link;
mRecordTail = mRecordHead;
InitializeListHead (mRecordHead);
for (Index1 = 1; Index1 < INITIAL_RECORD_NUM; Index1++) {
DataBuffer = AllocateRecordBuffer ();
if (DataBuffer == NULL) {
break;
}
InsertHeadList (mRecordHead, &DataBuffer->Link);
}
//
// Create a Notify Event to log data in Data Hub
//
@ -487,5 +383,9 @@ Returns:
&mLogDataHubEvent
);
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -52,7 +52,6 @@ Abstract:
// Private data declarations
//
#define MAX_RECORD_NUM 1000
#define INITIAL_RECORD_NUM 20
#define BYTES_PER_RECORD EFI_STATUS_CODE_DATA_MAX_SIZE
#define BYTES_PER_BUFFER (BYTES_PER_RECORD * sizeof (UINT8))
@ -60,77 +59,63 @@ Abstract:
typedef struct {
UINTN Signature;
EFI_LIST_ENTRY Link;
UINT8 RecordBuffer[BYTES_PER_RECORD];
} STATUS_CODE_RECORD_LIST;
EFI_LIST_ENTRY Node;
UINT8 Data[BYTES_PER_RECORD];
} DATAHUB_STATUSCODE_RECORD;
//
// Function prototypes
//
STATUS_CODE_RECORD_LIST *
AllocateRecordBuffer (
VOID
EFI_STATUS
EFIAPI
BsDataHubInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/*++
Routine Description:
Allocate a new record list node and initialize it.
Inserting the node into the list isn't the task of this function.
Install a data hub listener.
Arguments:
None
(Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
Returns:
A pointer to the new allocated node or NULL if non available
--*/
DATA_HUB_STATUS_CODE_DATA_RECORD *
AquireEmptyRecordBuffer (
VOID
);
/*++
Routine Description:
Acquire an empty record buffer from the record list if there's free node,
or allocate one new node and insert it to the list if the list is full and
the function isn't run in EFI_TPL_HIGH_LEVEL.
Arguments:
None
Returns:
Pointer to new record buffer. NULL if none available.
EFI_SUCCESS - Logging Hub protocol installed
Other - No protocol installed, unload driver.
--*/
EFI_STATUS
ReleaseRecordBuffer (
IN STATUS_CODE_RECORD_LIST *RecordBuffer
EFIAPI
BsDataHubReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN EFI_GUID * CallerId,
IN EFI_STATUS_CODE_DATA * Data OPTIONAL
);
/*++
Routine Description:
Release a buffer in the list, remove some nodes to keep the list inital length.
Boot service report status code listener. This function logs the status code
into the data hub.
Arguments:
RecordBuffer - Buffer to release
Same as gRT->ReportStatusCode (See Tiano Runtime Specification)
Returns:
EFI_SUCCESS - If DataRecord is valid
EFI_UNSUPPORTED - The record list has empty
None
--*/
void
VOID
EFIAPI
LogDataHubEventHandler (
IN EFI_EVENT Event,

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -2095,6 +2095,7 @@ Returns:
#endif
VOID
EFIAPI
BsSerialInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
@ -2189,6 +2190,9 @@ Returns:
} while ((Data & LSR_TXRDY) == 0);
IoWrite8 (gComBase, Character);
#ifdef SERIAL_OUTPUT_STALL
EfiStall (SERIAL_OUTPUT_STALL);
#endif
}
VOID

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -31,6 +31,7 @@ Abstract:
// Initialization function
//
VOID
EFIAPI
BsDataHubInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
@ -41,6 +42,7 @@ BsDataHubInitializeStatusCode (
// Status code reporting function
//
EFI_STATUS
EFIAPI
BsDataHubReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -31,6 +31,7 @@ Abstract:
// Initialization function
//
VOID
EFIAPI
BsSerialInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
@ -41,6 +42,7 @@ BsSerialInitializeStatusCode (
// Status code reporting function
//
EFI_STATUS
EFIAPI
BsSerialReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -31,6 +31,7 @@ Abstract:
// Initialization function
//
VOID
EFIAPI
RtMemoryInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
@ -41,6 +42,7 @@ RtMemoryInitializeStatusCode (
// Status code reporting function
//
EFI_STATUS
EFIAPI
RtMemoryReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
@ -55,7 +57,7 @@ RtMemoryReportStatusCode (
//
typedef
EFI_STATUS
(*PLATFORM_REPORT_STATUS_CODE) (
(EFIAPI *PLATFORM_REPORT_STATUS_CODE) (
IN EFI_STATUS_CODE_TYPE Type,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
@ -64,6 +66,7 @@ EFI_STATUS
);
VOID
EFIAPI
PlaybackStatusCodes (
IN PLATFORM_REPORT_STATUS_CODE ReportStatusCode
)

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -32,6 +32,7 @@ Abstract:
// Initialization function
//
VOID
EFIAPI
RtPlatformInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
@ -42,6 +43,7 @@ RtPlatformInitializeStatusCode (
// Status code reporting function
//
EFI_STATUS
EFIAPI
RtPlatformReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -31,6 +31,7 @@ Abstract:
// Status code reporting function
//
EFI_STATUS
EFIAPI
RtPort80ReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,

View File

@ -0,0 +1,53 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EdkNt32PpiLib.inf
Abstract:
Component description file for the Edk Nt32 PPI library.
--*/
[defines]
BASE_NAME= EdkNt32PpiLib
COMPONENT_TYPE= LIBRARY
[includes.common]
$(EDK_SOURCE)\Sample\Platform\Nt32
$(EDK_SOURCE)\Foundation\Efi
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Include\Pei
$(EDK_SOURCE)\Foundation\Library\Pei\Include
$(EDK_SOURCE)\Foundation\Core\Dxe
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Framework
[nmake.common]
C_STD_INCLUDE=
[sources.common]
NtAutoscan\NtAutoscan.h
NtAutoscan\NtAutoscan.c
NtFwh\NtFwh.h
NtFwh\NtFwh.c
NtLoadAsDll\NtLoadAsDll.h
NtLoadAsDll\NtLoadAsDll.c
NtPeiLoadFile\NtPeiLoadFile.h
NtPeiLoadFile\NtPeiLoadFile.c
NtThunk\NtThunk.h
NtThunk\NtThunk.c

View File

@ -0,0 +1,29 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtAutoscan.c
Abstract:
Abstraction for the NT Load Image PPI GUID as defined in Tiano
--*/
#include "Tiano.h"
#include "PeiBind.h"
#include "PeiApi.h"
#include EFI_PPI_DEFINITION (NtAutoScan)
EFI_GUID gPeiNtAutoScanPpiGuid = PEI_NT_AUTOSCAN_PPI_GUID;
EFI_GUID_STRING(&gPeiNtAutoScanPpiGuid, "NtAutoScan", "NT PEI AUTOSCAN PPI");

View File

@ -0,0 +1,67 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtAutoscan.h
Abstract:
Nt Autoscan PPI
--*/
#ifndef _NT_PEI_AUTOSCAN_H_
#define _NT_PEI_AUTOSCAN_H_
#include "Tiano.h"
#include "PeiHob.h"
#define PEI_NT_AUTOSCAN_PPI_GUID \
{ \
0xdce384d, 0x7c, 0x4ba5, 0x94, 0xbd, 0xf, 0x6e, 0xb6, 0x4d, 0x2a, 0xa9 \
}
typedef
EFI_STATUS
(EFIAPI *PEI_NT_AUTOSCAN) (
IN UINTN Index,
OUT EFI_PHYSICAL_ADDRESS * MemoryBase,
OUT UINT64 *MemorySize
);
/*++
Routine Description:
This service is called from Index == 0 until it returns EFI_UNSUPPORTED.
It allows discontiguous memory regions to be supported by the emulator.
It uses gSystemMemory[] and gSystemMemoryCount that were created by
parsing the Windows environment variable EFI_MEMORY_SIZE.
The size comes from the varaible and the address comes from the call to
WinNtOpenFile.
Arguments:
Index - Which memory region to use
MemoryBase - Return Base address of memory region
MemorySize - Return size in bytes of the memory region
Returns:
EFI_SUCCESS - If memory region was mapped
EFI_UNSUPPORTED - If Index is not supported
--*/
typedef struct {
PEI_NT_AUTOSCAN NtAutoScan;
} PEI_NT_AUTOSCAN_PPI;
extern EFI_GUID gPeiNtAutoScanPpiGuid;
#endif

View File

@ -0,0 +1,29 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtFwh.c
Abstract:
NT FWH Information PPI GUID as defined in Tiano
--*/
#include "Tiano.h"
#include "PeiBind.h"
#include "PeiApi.h"
#include EFI_PPI_DEFINITION (NtFwh)
EFI_GUID gNtFwhPpiGuid = NT_FWH_PPI_GUID;
EFI_GUID_STRING(&gNtFwhPpiGuid, "NtFwh", "NT PEI FWH INFO PPI");

View File

@ -0,0 +1,63 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtFwh.h
Abstract:
WinNt FWH PPI as defined in Tiano
--*/
#ifndef _NT_PEI_FWH_H_
#define _NT_PEI_FWH_H_
#include "Tiano.h"
#include "PeiHob.h"
#define NT_FWH_PPI_GUID \
{ \
0x4e76928f, 0x50ad, 0x4334, 0xb0, 0x6b, 0xa8, 0x42, 0x13, 0x10, 0x8a, 0x57 \
}
typedef
EFI_STATUS
(EFIAPI *NT_FWH_INFORMATION) (
IN UINTN Index,
IN OUT EFI_PHYSICAL_ADDRESS * FdBase,
IN OUT UINT64 *FdSize
);
/*++
Routine Description:
Return the FD Size and base address. Since the FD is loaded from a
file into Windows memory only the SEC will know it's address.
Arguments:
Index - Which FD, starts at zero.
FdSize - Size of the FD in bytes
FdBase - Start address of the FD. Assume it points to an FV Header
Returns:
EFI_SUCCESS - Return the Base address and size of the FV
EFI_UNSUPPORTED - Index does nto map to an FD in the system
--*/
typedef struct {
NT_FWH_INFORMATION NtFwh;
} NT_FWH_PPI;
extern EFI_GUID gNtFwhPpiGuid;
#endif

View File

@ -0,0 +1,28 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtLoadAsDll.c
Abstract:
DXE Initial Program Load PPI GUID as defined in Tiano
--*/
#include "Tiano.h"
#include "Pei.h"
#include EFI_PPI_DEFINITION (NtLoadAsDll)
EFI_GUID gEfiNtLoadAsDllPpiGuid = EFI_NT_LOAD_AS_DLL_PPI_GUID;
EFI_GUID_STRING(&gEfiNtLoadAsDllPpiGuid, "NtLoadAsDll", "NT LOAD AS DLL PPI");

View File

@ -0,0 +1,84 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtLoadAsDll.h
Abstract:
Nt service Ppi that is used to load PE32s in the NT emulation environment.
--*/
#ifndef _NT_LOAD_AS_DLL_H_
#define _NT_LOAD_AS_DLL_H_
#include "Tiano.h"
#define EFI_NT_LOAD_AS_DLL_PPI_GUID \
{ \
0xccc53f6b, 0xa03a, 0x4ed8, 0x83, 0x9a, 0x3, 0xd9, 0x9c, 0x2, 0xb4, 0xe3 \
}
typedef
EFI_STATUS
(EFIAPI *EFI_NT_LOAD_AS_DLL) (
IN CHAR8 *PdbFileName,
IN VOID **ImageEntryPoint,
OUT VOID **ModHandle
);
/*++
Routine Description:
Loads the .DLL file is present when a PE/COFF file is loaded. This provides source level
debugging for drivers that have cooresponding .DLL files on the local system.
Arguments:
PdbFileName - The name of the .PDB file. This was found from the PE/COFF
file's debug directory entry.
ImageEntryPoint - A pointer to the DLL entry point of the .DLL file was loaded.
Returns:
EFI_SUCCESS - The .DLL file was loaded, and the DLL entry point is returned in ImageEntryPoint
EFI_NOT_FOUND - The .DLL file could not be found
EFI_UNSUPPORTED - The .DLL file was loaded, but the entry point to the .DLL file could not
determined.
--*/
typedef
EFI_STATUS
(EFIAPI *EFI_NT_FREE_LIBRARY) (
IN VOID *ModHandle
);
/*++
Routine Description:
Free resources allocated by Entry (). ModHandle was returned by
Entry ().
Arguments:
MohHandle - Handle of the resources to free to undo the work.
Returns:
EFI_SUCCESS -
--*/
typedef struct {
EFI_NT_LOAD_AS_DLL Entry;
EFI_NT_FREE_LIBRARY FreeLibrary;
} EFI_NT_LOAD_AS_DLL_PPI;
extern EFI_GUID gEfiNtLoadAsDllPpiGuid;
#endif

View File

@ -0,0 +1,29 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtPeiLoadFile.c
Abstract:
Abstraction for the NT Load Image PPI GUID as defined in Tiano
--*/
#include "Tiano.h"
#include "PeiBind.h"
#include "PeiApi.h"
#include EFI_PPI_DEFINITION (NtPeiLoadFile)
EFI_GUID gNtPeiLoadFileGuid = NT_PEI_LOAD_FILE_GUID;
EFI_GUID_STRING(&gNtPeiLoadFileGuid, "NtPeiLoadFile", "NT PEI LOAD FILE PPI");

View File

@ -0,0 +1,66 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtPeiLoadFile.h
Abstract:
WinNt Load File PPI.
When the PEI core is done it calls the DXE IPL via PPI
--*/
#ifndef _NT_PEI_LOAD_FILE_H_
#define _NT_PEI_LOAD_FILE_H_
#include "Tiano.h"
#include "PeiHob.h"
#define NT_PEI_LOAD_FILE_GUID \
{ \
0xfd0c65eb, 0x405, 0x4cd2, 0x8a, 0xee, 0xf4, 0x0, 0xef, 0x13, 0xba, 0xc2 \
}
typedef
EFI_STATUS
(EFIAPI *NT_PEI_LOAD_FILE) (
VOID *Pe32Data,
EFI_PHYSICAL_ADDRESS *ImageAddress,
UINT64 *ImageSize,
EFI_PHYSICAL_ADDRESS *EntryPoint
);
/*++
Routine Description:
Loads and relocates a PE/COFF image into memory.
Arguments:
Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
ImageAddress - The base address of the relocated PE/COFF image
ImageSize - The size of the relocated PE/COFF image
EntryPoint - The entry point of the relocated PE/COFF image
Returns:
EFI_SUCCESS - The file was loaded and relocated
EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
--*/
typedef struct {
NT_PEI_LOAD_FILE PeiLoadFileService;
} NT_PEI_LOAD_FILE_PPI;
extern EFI_GUID gNtPeiLoadFileGuid;
#endif

View File

@ -0,0 +1,29 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtThunk.c
Abstract:
Abstraction for the NT Thunk PPI
--*/
#include "Tiano.h"
#include "PeiBind.h"
#include "PeiApi.h"
#include EFI_PPI_DEFINITION (NtThunk)
EFI_GUID gPeiNtThunkPpiGuid = PEI_NT_THUNK_GUID;
EFI_GUID_STRING(&gPeiNtThunkPpiGuid, "NtThunk", "NT PEI WINNT THUNK PPI");

View File

@ -0,0 +1,59 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
NtThunk.h
Abstract:
WinNt Thunk interface PPI
--*/
#ifndef _NT_PEI_WIN_NT_THUNK_H_
#define _NT_PEI_WIN_NT_THUNK_H_
#include "Tiano.h"
#include "PeiHob.h"
#define PEI_NT_THUNK_GUID \
{ \
0x98c281e5, 0xf906, 0x43dd, 0xa9, 0x2b, 0xb0, 0x3, 0xbf, 0x27, 0x65, 0xda \
}
typedef
EFI_STATUS
(EFIAPI *PEI_NT_THUNK_INTERFACE) (
IN OUT UINT64 *InterfaceSize,
IN OUT EFI_PHYSICAL_ADDRESS * InterfaceBase
);
/*++
Routine Description:
Export of EFI_WIN_NT_THUNK_PROTOCOL from the Windows SEC.
Arguments:
InterfaceSize - sizeof (EFI_WIN_NT_THUNK_PROTOCOL);
InterfaceBase - Address of the EFI_WIN_NT_THUNK_PROTOCOL
Returns:
EFI_SUCCESS - Data returned
--*/
typedef struct {
PEI_NT_THUNK_INTERFACE NtThunk;
} PEI_NT_THUNK_PPI;
extern EFI_GUID gPeiNtThunkPpiGuid;
#endif

View File

@ -1,881 +0,0 @@
/*++
Copyright 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
bootsectimage.c
Abstract:
Patch the BPB information in boot sector image file.
Patch the MBR code in MBR image file.
--*/
#include <windows.h>
#include <stdio.h>
#include "fat.h"
#include "mbr.h"
#include "EfiUtilityMsgs.h"
#define DEBUG_WARN 0x1
#define DEBUG_ERROR 0x2
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 (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 (FileName, "rb");
if (FileHandle == NULL) {
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Open file: %s", FileName);
return 0;
}
result = fread (BootSector, 1, 512, FileHandle);
if (result != 512) {
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Read 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, "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, "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, "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, "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, "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, "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, "FAT: BPB_RsvdSecCnt - %04x, expected - Non-Zero",
FatBpb->Fat12_16.BPB_RsvdSecCnt);
return FatTypeUnknown;
}
if (FatBpb->Fat12_16.BPB_NumFATs != 2) {
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "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, "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, "FAT: BPB_FATSz16, BPB_FATSz32 - 0, expected - Non-Zero");
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, "FAT: BPB_TotSec16, BPB_TotSec32 - 0, expected - Non-Zero");
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, "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, "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, "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, "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, "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, "FAT32: BPB_TotSec32 - %04x, expected - Non-Zero",
FatBpb->Fat12_16.BPB_TotSec32);
return FatTypeUnknown;
}
if ((FatType == FatTypeFat32) &&
(FatBpb->Fat32.BPB_FATSz32 == 0)) {
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "FAT32: BPB_FATSz32 - %08x, expected - Non-Zero",
FatBpb->Fat32.BPB_FATSz32);
return FatTypeUnknown;
}
if ((FatType == FatTypeFat32) &&
(FatBpb->Fat32.BPB_FSVer != 0)) {
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "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, "FAT32: BPB_RootClus - %08x, expected - %04x",
FatBpb->Fat32.BPB_RootClus, 2);
}
if ((FatType == FatTypeFat32) &&
(FatBpb->Fat32.BPB_FSInfo != 1)) {
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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: 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", FatBpb.Fat12_16.BPB_HiddSec);
printf (" 20 Sectors (over 32MB) %08x\n", 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", 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", 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", 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", 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,
BOOL 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, "FAT type mismatch: Dest - %s, Source - %s",
FatTypeToString(DestFatType), FatTypeToString(SourceFatType));
} else {
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "FAT type mismatch: Dest - %s, Source - %s",
FatTypeToString(DestFatType), FatTypeToString(SourceFatType));
return ;
}
}
if (SourceFatType <= FatTypeUnknown || SourceFatType >= FatTypeMax) {
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "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 ("successfully!\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", 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", Mbr.PartitionRecord[0].StartingLBA);
printf (" 1CA Sectors in partition %08x\n", 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", Mbr.PartitionRecord[1].StartingLBA);
printf (" 1DA Sectors in partition %08x\n", 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", Mbr.PartitionRecord[2].StartingLBA);
printf (" 1EA Sectors in partition %08x\n", 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", Mbr.PartitionRecord[3].StartingLBA);
printf (" 1FA Sectors in partition %08x\n", 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: 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 ("\tsuccessfully!\n");
}
return ;
}
void
PrintUsage (
void
)
{
printf (
"Usage:\n"
"bootsectimage [-m] [-v] -p SrcImage\n"
"bootsectimage [-m] [-v] [-f] -g SrcImage DstImage\n"
"where\n"
" -p: parse SrcImage\n"
" -g: get info from SrcImage, and patch to DstImage\n"
" -f: force patch even FAT type of SrcImage and DstImage mismatch\n"
" -m: process MBR instead of boot sector\n"
" -v: verbose\n"
);
}
int
main (
int argc,
char *argv[]
)
{
char *SrcImage;
char *DstImage;
BOOL ForcePatch; // -f
BOOL ProcessMbr; // -m
BOOL DoParse; // -p SrcImage or -g SrcImage DstImage
BOOL Verbose; // -v
SrcImage = DstImage = NULL;
ForcePatch = FALSE;
ProcessMbr = FALSE;
DoParse = TRUE;
Verbose = FALSE;
SetUtilityName ("bootsectimage");
argc--; argv++;
if (argc == 0) {
PrintUsage ();
return -1;
}
while (argc != 0) {
if (strcmp (*argv, "-f") == 0) {
ForcePatch = TRUE;
} else if (strcmp (*argv, "-p") == 0) {
DoParse = TRUE;
argc--; argv++;
if (argc < 1) {
PrintUsage ();
return -1;
}
SrcImage = *argv;
} else if (strcmp (*argv, "-g") == 0) {
DoParse = FALSE;
argc--; argv++;
if (argc < 2) {
PrintUsage ();
return -1;
}
SrcImage = *argv;
argc--; argv++;
DstImage = *argv;
} else if (strcmp (*argv, "-m") == 0) {
ProcessMbr = TRUE;
} else if (strcmp (*argv, "-v") == 0) {
Verbose = TRUE;
} else {
PrintUsage ();
return -1;
}
argc--; argv++;
}
if (ForcePatch && DoParse) {
printf ("Cannot apply force(-f) to parse(-p)!\n");
PrintUsage ();
return -1;
}
if (ForcePatch && !DoParse && ProcessMbr) {
printf ("Cannot apply force(-f) to processing MBR (-g -m)!\n");
PrintUsage ();
return -1;
}
if (Verbose) {
SetDebugMsgMask (DEBUG_WARN | DEBUG_ERROR);
} else {
SetDebugMsgMask (0);
}
if (DoParse) {
if (ProcessMbr) {
ParseMbr (SrcImage);
} else {
ParseBootSector (SrcImage);
}
} else {
if (ProcessMbr) {
PatchMbr (DstImage, SrcImage);
} else {
PatchBootSector (DstImage, SrcImage, ForcePatch);
}
}
return 0;
}

View File

@ -1,158 +0,0 @@
/*++
Copyright 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
fat.h
Abstract:
Revision History
--*/
#ifndef _FAT_BPB_H_
#define _FAT_BPB_H_
#include "Tiano.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

View File

@ -1,64 +0,0 @@
/*++
Copyright 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
mbr.h
Abstract:
Revision History
--*/
#ifndef _MBR_H_
#define _MBR_H_
#include "Tiano.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

View File

@ -390,6 +390,91 @@ Returns:
return EFI_SUCCESS;
}
EFI_STATUS
SearchSectionByType (
IN EFI_FILE_SECTION_POINTER FirstSection,
IN UINT8 *SearchEnd,
IN EFI_SECTION_TYPE SectionType,
IN OUT UINTN *StartIndex,
IN UINTN Instance,
OUT EFI_FILE_SECTION_POINTER *Section
)
/*++
Routine Description:
Helper function to search a sequence of sections from the section pointed
by FirstSection to SearchEnd for the Instance-th section of type SectionType.
The current counter is saved in StartIndex and when the section is found, it's
saved in Section. GUID-defined sections, if special processing is not required,
are searched recursively in a depth-first manner.
Arguments:
FirstSection The first section to start searching from.
SearchEnd The end address to stop search.
SectionType The type of section to search.
StartIndex The current counter is saved.
Instance The requested n-th section number.
Section The found section returned.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_NOT_FOUND The section is not found.
--*/
{
EFI_FILE_SECTION_POINTER CurrentSection;
EFI_FILE_SECTION_POINTER InnerSection;
EFI_STATUS Status;
UINTN SectionSize;
CurrentSection = FirstSection;
while ((UINTN) CurrentSection.CommonHeader < (UINTN) SearchEnd) {
if (CurrentSection.CommonHeader->Type == SectionType) {
(*StartIndex)++;
}
if (*StartIndex == Instance) {
*Section = CurrentSection;
return EFI_SUCCESS;
}
//
// If the requesting section is not GUID-defined and
// we find a GUID-defined section that doesn't need
// special processing, go ahead to search the requesting
// section inside the GUID-defined section.
//
if (SectionType != EFI_SECTION_GUID_DEFINED &&
CurrentSection.CommonHeader->Type == EFI_SECTION_GUID_DEFINED &&
!(CurrentSection.GuidDefinedSection->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED)) {
InnerSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *)
((UINTN) CurrentSection.CommonHeader + CurrentSection.GuidDefinedSection->DataOffset);
SectionSize = CurrentSection.CommonHeader->Size[0] +
(CurrentSection.CommonHeader->Size[1] << 8) +
(CurrentSection.CommonHeader->Size[2] << 16);
Status = SearchSectionByType (
InnerSection,
(UINT8 *) ((UINTN) CurrentSection.CommonHeader + SectionSize),
SectionType,
StartIndex,
Instance,
Section
);
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
}
}
//
// Find next section (including compensating for alignment issues.
//
CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetLength (CurrentSection.CommonHeader->Size) + 0x03) & (-1 << 2));
}
return EFI_NOT_FOUND;
}
EFI_STATUS
GetSectionByType (
IN EFI_FFS_FILE_HEADER *File,
@ -403,7 +488,8 @@ Routine Description:
Find a section in a file by type and instance. An instance of 1 is the first
instance. The function will return NULL if a matching section cannot be found.
The function will not handle encapsulating sections.
GUID-defined sections, if special processing is not needed, are handled in a
depth-first manner.
Arguments:
@ -448,28 +534,24 @@ Returns:
//
CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) File + sizeof (EFI_FFS_FILE_HEADER));
//
// Loop as long as we have a valid file
//
while ((UINTN) CurrentSection.CommonHeader < (UINTN) File + GetLength (File->Size)) {
if (CurrentSection.CommonHeader->Type == SectionType) {
SectionCount++;
}
Status = SearchSectionByType (
CurrentSection,
(UINT8 *) ((UINTN) File + GetLength (File->Size)),
SectionType,
&SectionCount,
Instance,
Section
);
if (SectionCount == Instance) {
*Section = CurrentSection;
return EFI_SUCCESS;
}
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
} else {
//
// Find next section (including compensating for alignment issues.
// Section not found
//
CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetLength (CurrentSection.CommonHeader->Size) + 0x03) & (-1 << 2));
(*Section).Code16Section = NULL;
return EFI_NOT_FOUND;
}
//
// Section not found
//
(*Section).Code16Section = NULL;
return EFI_NOT_FOUND;
}
//
// will not parse compressed sections

View File

@ -100,7 +100,7 @@ all: $(TARGET_LIB)
"$(EDK_TOOLS_OUTPUT)\PeCoffLoaderEx.obj": "$(EDK_SOURCE)\Foundation\Library\Pei\PeiLib\$(PROCESSOR)\PeCoffLoaderEx.c"
$(CC) $(C_FLAGS) "$(EDK_SOURCE)\Foundation\Library\Pei\PeiLib\$(PROCESSOR)\PeCoffLoaderEx.c" /Fo"$(EDK_TOOLS_OUTPUT)\PeCoffLoaderEx.obj"
"$(EDK_TOOLS_OUTPUT)\FvLib.obj": "$(TARGET_SOURCE_DIR)\FvLib.c" "$(TARGET_SOURCE_DIR)\FvLib.h" $(EDK_SOURCE)\Sample\Include\Efi2WinNt.h $(EDK_SOURCE)\Foundation\Framework\Include\EfiFirmwareFileSystem.h "$(EDK_SOURCE)\Foundation\Framework\Include\EfiFirmwareVolumeHeader.h"
"$(EDK_TOOLS_OUTPUT)\FvLib.obj": "$(TARGET_SOURCE_DIR)\FvLib.c" "$(TARGET_SOURCE_DIR)\FvLib.h" $(EDK_SOURCE)\Foundation\Framework\Include\EfiFirmwareFileSystem.h "$(EDK_SOURCE)\Foundation\Framework\Include\EfiFirmwareVolumeHeader.h"
$(CC) $(C_FLAGS) "$(TARGET_SOURCE_DIR)\FvLib.c" /Fo"$(EDK_TOOLS_OUTPUT)\FvLib.obj"
"$(EDK_TOOLS_OUTPUT)\EfiUtilityMsgs.obj": "$(TARGET_SOURCE_DIR)\EfiUtilityMsgs.c" "$(TARGET_SOURCE_DIR)\EfiUtilityMsgs.h"
@ -125,11 +125,13 @@ $(TARGET_LIB): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).lib
!ELSE
$(TARGET_LIB): $(OBJECTS)
$(LIB_EXE) $(LIB_FLAGS) $(OBJECTS) /OUT:$(TARGET_LIB)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_LIB) copy $(TARGET_LIB) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).lib /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Obj.pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Obj.pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME)Obj.pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\ParseInf.* del /q $(EDK_TOOLS_OUTPUT)\ParseInf.* > NUL

View File

@ -71,11 +71,13 @@ $(TARGET_LIB): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).lib
!ELSE
$(TARGET_LIB): $(OBJECTS)
$(LIB_EXE) $(LIB_FLAGS) $(OBJECTS) /OUT:$(TARGET_LIB)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_LIB) copy $(TARGET_LIB) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).lib /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Obj.pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Obj.pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME)Obj.pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\CustomizedCompress.* del /q $(EDK_TOOLS_OUTPUT)\CustomizedCompress.* > NUL

View File

@ -79,11 +79,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\EfiCompressMain.obj $(TARGET_EXE_LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\EfiCompressMain.obj $(TARGET_EXE_LIBS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Main.* del /q $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Main.* > NUL

View File

@ -41,11 +41,11 @@ Abstract:
//
// END include differences
//
#include "Pci22.h" // for option ROM header structures
#include "Pci.h" // for option ROM header structures
//
// Version of this utility
//
#define UTILITY_VERSION "v2.5"
#define UTILITY_VERSION "v2.6"
//
// Define some status return values
@ -137,6 +137,15 @@ static STRING_LOOKUP mSubsystemTypes[] = {
0,
NULL
};
static char* mCodeTypeStr[] = {
"PCAT Image",
"Open Firmware Image",
"HP PA RISC Image",
"EFI Image",
"Undefined"
};
//
// Function prototypes
//
@ -353,6 +362,45 @@ BailOut:
return Status;
}
UINT8
CheckSum (
UINT8 *Buffer,
UINT32 DataSize,
UINT32 PaddingSize
)
/*++
Routine Description:
Calculate checksum from DataSize of Buffer.
Arguments:
Buffer - pointer to data buffer
DataSize - size of data buffer in bytes
Return:
UINT8 - checksum
--*/
{
UINT8 Checksum = 0;
while (DataSize-- != 0) {
Checksum = Checksum + Buffer[DataSize];
}
while (PaddingSize-- != 0) {
Checksum = Checksum + 0xff;
}
return Checksum;
}
char *
GetCodeTypeStr (
UINT8 CodeType
)
{
if (CodeType >= sizeof (mCodeTypeStr) / sizeof (*mCodeTypeStr)) {
CodeType = sizeof (mCodeTypeStr) / sizeof (*mCodeTypeStr) - 1;
}
return mCodeTypeStr[CodeType];
}
static
int
@ -382,11 +430,12 @@ Returns:
FILE *InFptr;
UINT32 TotalSize;
UINT32 FileSize;
UINT32 DataSize;
UINT32 PaddingSize;
UINT8 *Buffer;
UINT32 Status;
PCI_EXPANSION_ROM_HEADER *RomHdr;
PCI_DATA_STRUCTURE *PciDs;
UINT32 Index;
UINT8 ByteCheckSum;
Status = STATUS_SUCCESS;
@ -421,34 +470,14 @@ Returns:
Status = STATUS_ERROR;
goto BailOut;
}
//
// Total size must be an even multiple of 512 bytes, and can't exceed
// the option ROM image size.
//
TotalSize = FileSize;
if (TotalSize & 0x1FF) {
TotalSize = (TotalSize + 0x200) &~0x1ff;
}
if (TotalSize > MAX_OPTION_ROM_SIZE) {
fprintf (
stdout,
"ERROR: Option ROM image %s size exceeds limit 0x%X bytes\n",
InFile->FileName,
MAX_OPTION_ROM_SIZE
);
Status = STATUS_ERROR;
goto BailOut;
}
//
// Return the size to the caller so they can keep track of the running total.
//
*Size = TotalSize;
RomHdr = (PCI_EXPANSION_ROM_HEADER *) Buffer;
PciDs = (PCI_DATA_STRUCTURE *) (Buffer + RomHdr->PcirOffset);
//
// Crude check to make sure it's a legitimate ROM image
//
RomHdr = (PCI_EXPANSION_ROM_HEADER *) Buffer;
if (RomHdr->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
fprintf (stdout, "ERROR: ROM image file has invalid ROM signature\n");
Status = STATUS_ERROR;
@ -464,47 +493,76 @@ Returns:
goto BailOut;
}
PciDs = (PCI_DATA_STRUCTURE *) (Buffer + RomHdr->PcirOffset);
if (PciDs->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {
fprintf (stdout, "ERROR: PCI data structure has invalid signature\n");
Status = STATUS_ERROR;
goto BailOut;
}
if ((UINT32) (PciDs->ImageLength * 512) == FileSize) {
//
// ImageLength reflects the actual file size correctly.
//
DataSize = FileSize - 1;
PaddingSize = 0;
TotalSize = FileSize;
} else {
//
// ImageLength doesn't reflect the actual file size,
// 1). add additional 512 bytes if actual file size is multiple of 512
// 2). add additional X (X <= 512) bytes so that the result size is multiple of 512
//
fprintf (stdout, "WARNING: ImageLength in PCI data structure != Actual File Size\n"
" --> add additional padding bytes\n"
" --> adjust ImageLength\n"
);
TotalSize = (FileSize + 0x200) & ~0x1ff;
DataSize = FileSize;
PaddingSize = TotalSize - DataSize - 1;
PciDs->ImageLength = (UINT16) (TotalSize / 512);
}
//
// Check size
//
if (TotalSize > MAX_OPTION_ROM_SIZE) {
fprintf (
stdout,
"ERROR: Option ROM image %s size exceeds limit 0x%X bytes\n",
InFile->FileName,
MAX_OPTION_ROM_SIZE
);
Status = STATUS_ERROR;
goto BailOut;
}
//
// Return the size to the caller so they can keep track of the running total.
//
*Size = TotalSize;
//
// If this is the last image, then set the LAST bit unless requested not
// to via the command-line -l argument. Otherwise, make sure you clear it.
//
if ((InFile->Next == NULL) && (mOptions.NoLast == 0)) {
PciDs->Indicator = INDICATOR_LAST;
PciDs->Indicator |= INDICATOR_LAST;
} else {
PciDs->Indicator = 0;
PciDs->Indicator &= ~INDICATOR_LAST;
}
ByteCheckSum = 0;
for (Index = 0; Index < FileSize - 1; Index++) {
ByteCheckSum = (UINT8) (ByteCheckSum + Buffer[Index]);
}
ByteCheckSum = -CheckSum (Buffer, DataSize, PaddingSize);
Buffer[FileSize - 1] = (UINT8) ((~ByteCheckSum) + 1);
fprintf (stdout, "CheckSUm = %02x\n", (UINT32) Buffer[FileSize - 1]);
//
// Now copy the input file contents out to the output file
//
if (fwrite (Buffer, FileSize, 1, OutFptr) != 1) {
if (fwrite (Buffer, DataSize, 1, OutFptr) != 1) {
fprintf (stdout, "ERROR: Failed to write all file bytes to output file\n");
Status = STATUS_ERROR;
goto BailOut;
}
TotalSize -= FileSize;
//
// Pad the rest of the image to make it a multiple of 512 bytes
//
while (TotalSize > 0) {
while (PaddingSize-- != 0) {
putc (~0, OutFptr);
TotalSize--;
}
putc (ByteCheckSum, OutFptr);
BailOut:
if (InFptr != NULL) {
@ -665,9 +723,8 @@ Returns:
//
// Total size must be an even multiple of 512 bytes
//
if (TotalSize & 0x1FF) {
TotalSize = (TotalSize + 0x200) &~0x1ff;
}
TotalSize = (TotalSize + 0x1ff) & ~0x1ff;
//
// Check size
//
@ -729,7 +786,7 @@ Returns:
// to via the command-line -l argument.
//
if ((InFile->Next == NULL) && (mOptions.NoLast == 0)) {
PciDs.Indicator = INDICATOR_LAST;
PciDs.Indicator |= INDICATOR_LAST;
}
//
// Write the ROM header to the output file
@ -1068,7 +1125,7 @@ Returns:
//
// Specify binary files with -b
//
FileFlags = (FileFlags &~FILE_FLAG_EFI) | FILE_FLAG_BINARY;
FileFlags = (FileFlags & ~FILE_FLAG_EFI) | FILE_FLAG_BINARY;
} else if ((_stricmp (Argv[0], "-e") == 0) || (_stricmp (Argv[0], "-ec") == 0)) {
//
// Specify EFI files with -e. Specify EFI-compressed with -ec.
@ -1280,7 +1337,7 @@ Returns:
" the following FileName",
" -dump - to dump the headers of an existing option ROM image",
"",
"Example usage: EfiRom -v 0xABCD -d 0x1234 -b File1.bin File2.bin -e File1.efi File2.efi ",
"Example usage: EfiRom -v 0xABCD -d 0x1234 -b File1.bin File2.bin -e File1.efi File2.efi",
"",
NULL
};
@ -1315,8 +1372,9 @@ Returns:
FILE *InFptr;
UINT32 ImageStart;
UINT32 ImageCount;
UINT16 DeviceId;
EFI_PCI_EXPANSION_ROM_HEADER EfiRomHdr;
PCI_DATA_STRUCTURE PciDs;
PCI_3_0_DATA_STRUCTURE PciDs;
//
// Open the input file
@ -1382,41 +1440,35 @@ Returns:
);
fprintf (stdout, " Vendor ID 0x%04X\n", PciDs.VendorId);
fprintf (stdout, " Device ID 0x%04X\n", PciDs.DeviceId);
fprintf (stdout, " Structure Length 0x%04X\n", PciDs.Length);
fprintf (stdout, " PCI Revision 0x%02X\n", PciDs.Revision);
fprintf (
stdout,
" Class Code 0x%06X\n",
(UINT32) (PciDs.ClassCode[0] | (PciDs.ClassCode[1] << 8) | (PciDs.ClassCode[2] << 16))
);
fprintf (stdout, " Image size 0x%X\n", PciDs.ImageLength * 512);
fprintf (stdout, " Code revision: 0x%04X\n", PciDs.CodeRevision);
fprintf (stdout, " Code revision 0x%04X\n", PciDs.CodeRevision);
fprintf (stdout, " Indicator 0x%02X", (UINT32) PciDs.Indicator);
//
// Print the indicator, used to flag the last image
//
if (PciDs.Indicator == INDICATOR_LAST) {
if ((PciDs.Indicator & INDICATOR_LAST) == INDICATOR_LAST) {
fprintf (stdout, " (last image)\n");
} else {
fprintf (stdout, "\n");
}
//
// Print the code type. If EFI code, then we can provide more info.
//
fprintf (stdout, " Code type 0x%02X", (UINT32) PciDs.CodeType);
fprintf (stdout, " Code type 0x%02X (%s)\n", (UINT32) PciDs.CodeType, GetCodeTypeStr (PciDs.CodeType));
if (PciDs.CodeType == PCI_CODE_TYPE_EFI_IMAGE) {
fprintf (stdout, " (EFI image)\n");
//
// Re-read the header as an EFI ROM header, then dump more info
//
fprintf (stdout, " EFI ROM header contents\n");
if (fseek (InFptr, ImageStart, SEEK_SET)) {
fprintf (stdout, "ERROR: Failed to re-seek to ROM header structure\n");
goto BailOut;
}
if (fread (&EfiRomHdr, sizeof (EfiRomHdr), 1, InFptr) != 1) {
fprintf (stdout, "ERROR: Failed to read EFI PCI ROM header from file\n");
goto BailOut;
}
memcpy (&EfiRomHdr, &PciRomHdr, sizeof (EfiRomHdr));
//
// Now dump more info
//
@ -1450,22 +1502,45 @@ Returns:
(UINT32) EfiRomHdr.EfiImageHeaderOffset,
(UINT32) (EfiRomHdr.EfiImageHeaderOffset + ImageStart)
);
} else {
//
// Not an EFI image
//
fprintf (stdout, "\n");
}
//
// If code type is EFI image, then dump it as well?
// Dump additional information for PCI 3.0 OpROM
//
// if (PciDs.CodeType == PCI_CODE_TYPE_EFI_IMAGE) {
// }
if (PciDs.Revision >= 3) {
fprintf (stdout, " Extended for PCI 3.0\n");
if (PciDs.DeviceListOffset != 0) {
if (fseek (InFptr, ImageStart + PciRomHdr.PcirOffset + PciDs.DeviceListOffset, SEEK_SET)) {
fprintf (stdout, "ERROR: Failed to seek to supported Device List\n");
goto BailOut;
}
fprintf (stdout, " Device ID List ");
while (TRUE) {
if (fread (&DeviceId, sizeof (DeviceId), 1, InFptr) != 1) {
fprintf (stdout, "ERROR: Failed to read supported DeviceId from DeviceId List\n");
goto BailOut;
}
if (DeviceId == 0) {
break;
}
fprintf (stdout, "0x%04X ", DeviceId);
}
fprintf (stdout, "\n");
}
fprintf (stdout, " Max Runtime Image Length 0x%08X\n", PciDs.MaxRuntimeImageLength * 512);
if (PciDs.Length == sizeof (PCI_3_0_DATA_STRUCTURE)) {
fprintf (stdout, " Config Utility Header 0x%04X\n", PciDs.ConfigUtilityCodeHeaderOffset);
fprintf (stdout, " DMTF CLP Entry Point 0x%04X\n", PciDs.DMTFCLPEntryPointOffset);
} else {
fprintf (stdout, "WARNING: Oprom declars 3.0 revision with wrong structure length 0x%04X\n", PciDs.Length);
}
}
//
// If last image, then we're done
//
if (PciDs.Indicator == INDICATOR_LAST) {
if ((PciDs.Indicator & INDICATOR_LAST) == INDICATOR_LAST) {
goto BailOut;
}
//
@ -1543,3 +1618,4 @@ Returns:
return "unknown";
}

View File

@ -75,11 +75,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(OBJECTS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -1,188 +0,0 @@
/*++
Copyright 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
efildrimage.c
Abstract:
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.
Revision History
--*/
#include <windows.h>
#include <stdio.h>
#include "Tiano.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;
VOID
Usage (
VOID
)
{
printf ("Usage: EfiLdrImage OutImage LoaderImage PeImage1 PeImage2 ... PeImageN");
exit (1);
}
ULONG
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:
ULONG : file size of input file
--*/
{
ULONG filesize, offset, length;
UCHAR 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:
--*/
{
ULONG i;
ULONG filesize;
FILE *fpIn, *fpOut;
EFILDR_HEADER EfiLdrHeader;
EFILDR_IMAGE EfiLdrImage[MAX_PE_IMAGES];
if (argc < 4) {
Usage();
}
//
// Open output file for write
//
fpOut = fopen(argv[1], "w+b");
if (!fpOut) {
printf ("efildrimage: Could not open output file %s\n", argv[1]);
exit(1);
}
memset (&EfiLdrHeader, 0, sizeof (EfiLdrHeader));
memset (&EfiLdrImage, 0, sizeof (EFILDR_IMAGE) * (argc - 2));
memcpy (&EfiLdrHeader.Signature, "EFIL", 4);
EfiLdrHeader.FileLength = sizeof(EFILDR_HEADER) + sizeof(EFILDR_IMAGE)*(argc-2);
//
// Skip the file header first
//
fseek (fpOut, EfiLdrHeader.FileLength, SEEK_SET);
//
// copy all the input files to the output file
//
for(i=2;i<(ULONG)argc;i++) {
//
// Copy the content of PeImage file to output file
//
fpIn = fopen (argv[i], "rb");
if (!fpIn) {
printf ("efildrimage: Could not open input file %s\n", argv[i-2]);
exit(1);
}
filesize = FCopyFile (fpIn, fpOut);
fclose(fpIn);
//
// And in the same time update the EfiLdrHeader and EfiLdrImage array
//
EfiLdrImage[i-2].Offset = EfiLdrHeader.FileLength;
EfiLdrImage[i-2].Length = filesize;
strncpy (EfiLdrImage[i-2].FileName, argv[i], sizeof (EfiLdrImage[i-2].FileName) - 1);
EfiLdrHeader.FileLength += 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)*(argc-2), 1, fpOut);
fclose (fpOut);
printf ("Created %s\n", argv[1]);
return 0;
}

View File

@ -76,11 +76,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -66,11 +66,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(OBJECTS) $(LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Lib.* del /q $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME)Lib.* > NUL

View File

@ -1,58 +0,0 @@
#include "fat.h"
#include <stdio.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: FAT: BPB_FATSz16, BPB_FATSz32 - 0, expected - Non-Zero\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: FAT: BPB_TotSec16, BPB_TotSec32 - 0, expected - Non-Zero\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);
}
}

View File

@ -1,158 +0,0 @@
/*++
Copyright 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
fat.h
Abstract:
Revision History
--*/
#ifndef _FAT_BPB_H_
#define _FAT_BPB_H_
#include "Tiano.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

View File

@ -1,652 +0,0 @@
/*++
Copyright 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
genbootsector.c
Abstract:
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.
--*/
#include <windows.h>
#include <stdio.h>
#include <string.h>
#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,
} PATCH_TYPE;
typedef enum {
ErrorSuccess,
ErrorFileCreate,
ErrorFileReadWrite,
ErrorNoMbr,
ErrorFatType
} ERROR_STATUS;
CHAR *ErrorStatusDesc[] = {
"Success",
"Failed to create files",
"Failed to read/write files",
"No MBR exists",
"Failed to detect Fat type"
};
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;
#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: CreateFile failed: Volume = %s, LastError = 0x%x\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.
//
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: fetal 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: %d, Type: %s\n",
DriveInfo.VolumeLetter,
DriveInfo.DiskNumber,
DriveInfo.DriveType->Description
);
}
}
}
}
}
INT
GetBootSectorOffset (
HANDLE DiskHandle,
BOOL WriteToDisk,
PATCH_TYPE PatchType
)
/*++
Description:
Get the offset of boot sector.
For non-MBR disk, offset is just 0
for disk with MBR, offset needs to be caculated by parsing MBR
NOTE: if no one is active, we will patch MBR to select first partition as active.
Arguments:
DiskHandle : HANDLE of disk
WriteToDisk : TRUE indicates writing
PatchType : PatchTypeFloppy, PatchTypeIde, PatchTypeUsb
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 (WriteToDisk && (PatchType == PatchTypeUsb)) {
SetFilePointer(DiskHandle, 0, NULL, FILE_BEGIN);
DiskPartition[PARTITION_TABLE_OFFSET] = 0x80;
WriteFile (DiskHandle, DiskPartition, 0x200, &BytesReturn, NULL);
}
}
}
return DbrOffset;
}
ERROR_STATUS
ProcessBsOrMbr (
CHAR *DiskName,
CHAR *FileName,
BOOL WriteToDisk,
PATCH_TYPE PatchType,
BOOL ProcessMbr
)
/*++
Routine Description:
Writing or reading boot sector or MBR according to the argument.
Arguments:
DiskName : Win32 API recognized string name of disk
FileName : file name
WriteToDisk : TRUE is to write content of file to disk, otherwise, reading content of disk to file
PatchType : PatchTypeFloppy, PatchTypeIde, PatchTypeUsb
ProcessMbr : TRUE is to process MBR, otherwise, processing boot sector
Return:
ErrorSuccess
ErrorFileCreate
ErrorFileReadWrite
ErrorNoMbr
ErrorFatType
--*/
{
BYTE DiskPartition[0x200];
BYTE DiskPartitionBackup[0x200];
HANDLE DiskHandle;
HANDLE FileHandle;
DWORD BytesReturn;
DWORD DbrOffset;
INT DrvNumOffset;
DiskHandle = CreateFile (
DiskName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (DiskHandle == INVALID_HANDLE_VALUE) {
return ErrorFileCreate;
}
FileHandle = CreateFile (
FileName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (FileHandle == INVALID_HANDLE_VALUE) {
return ErrorFileCreate;
}
DbrOffset = 0;
//
// Skip potential MBR for Ide & USB disk
//
if ((PatchType == PatchTypeIde) || (PatchType == PatchTypeUsb)) {
//
// Even user just wants to process MBR, we get offset of boot sector here to validate the disk
// if disk have MBR, DbrOffset should be greater than 0
//
DbrOffset = GetBootSectorOffset (DiskHandle, WriteToDisk, PatchType);
if (!ProcessMbr) {
//
// 1. Process boot sector, set file pointer to the beginning of boot sector
//
SetFilePointer (DiskHandle, 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 (DiskHandle, 0, NULL, FILE_BEGIN);
}
}
//
// [File Pointer is pointed to beginning of Mbr or Dbr]
//
if (WriteToDisk) {
//
// Write
//
if (!ReadFile (FileHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
return ErrorFileReadWrite;
}
if (ProcessMbr) {
//
// Use original partition table
//
if (!ReadFile (DiskHandle, DiskPartitionBackup, 0x200, &BytesReturn, NULL)) {
return ErrorFileReadWrite;
}
memcpy (DiskPartition + 0x1BE, DiskPartitionBackup + 0x1BE, 0x40);
SetFilePointer (DiskHandle, 0, NULL, FILE_BEGIN);
}
if (!WriteFile (DiskHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
return ErrorFileReadWrite;
}
} else {
//
// Read
//
if (!ReadFile (DiskHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
return ErrorFileReadWrite;
}
if (PatchType == PatchTypeUsb) {
// 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) {
return ErrorFatType;
}
//
// Some legacy BIOS require 0x80 discarding MBR.
// Question left here: is it needed to check Mbr before set 0x80?
//
DiskPartition[DrvNumOffset] = ((DbrOffset > 0) ? 0x80 : 0);
}
if (PatchType == PatchTypeIde) {
//
// Patch LBAOffsetForBootSector
//
*(DWORD *)&DiskPartition [BOOT_SECTOR_LBA_OFFSET] = DbrOffset;
}
if (!WriteFile (FileHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
return ErrorFileReadWrite;
}
}
CloseHandle (FileHandle);
CloseHandle (DiskHandle);
return ErrorSuccess;
}
VOID
PrintUsage (
CHAR* AppName
)
{
fprintf (
stdout,
"Usage: %s [OPTIONS]...\n"
"Copy file content from/to bootsector.\n"
"\n"
" -l list disks\n"
" -if=FILE specified an input, can be files or disks\n"
" -of=FILE specified an output, can be files or disks\n"
" -mbr process MBR also\n"
" -h print this message\n"
"\n"
"FILE providing a volume plus a colon (X:), indicates a disk\n"
"FILE providing other format, indicates a file\n",
AppName
);
}
INT
main (
INT argc,
CHAR *argv[]
)
{
CHAR *AppName;
INT Index;
BOOL ProcessMbr;
CHAR VolumeLetter;
CHAR *FilePath;
BOOL WriteToDisk;
DRIVE_INFO DriveInfo;
PATCH_TYPE PatchType;
ERROR_STATUS Status;
CHAR FloppyPathTemplate[] = "\\\\.\\%c:";
CHAR DiskPathTemplate[] = "\\\\.\\PHYSICALDRIVE%u";
CHAR DiskPath[MAX_PATH];
AppName = *argv;
argv ++;
argc --;
ProcessMbr = FALSE;
WriteToDisk = TRUE;
FilePath = NULL;
VolumeLetter = 0;
//
// Parse command line
//
for (Index = 0; Index < argc; Index ++) {
if (_stricmp (argv[Index], "-l") == 0) {
ListDrive ();
return 0;
}
else if (_stricmp (argv[Index], "-mbr") == 0) {
ProcessMbr = TRUE;
}
else if ((_strnicmp (argv[Index], "-if=", 4) == 0) ||
(_strnicmp (argv[Index], "-of=", 4) == 0)
) {
if (argv[Index][6] == '\0' && argv[Index][5] == ':' && IsLetter (argv[Index][4])) {
VolumeLetter = argv[Index][4];
if (_strnicmp (argv[Index], "-if=", 4) == 0) {
WriteToDisk = FALSE;
}
}
else {
FilePath = &argv[Index][4];
}
}
else {
PrintUsage (AppName);
return 1;
}
}
//
// Check parameter
//
if (VolumeLetter == 0) {
fprintf (stderr, "ERROR: Volume isn't provided!\n");
PrintUsage (AppName);
return 1;
}
if (FilePath == NULL) {
fprintf (stderr, "ERROR: File isn't pvovided!\n");
PrintUsage (AppName);
return 1;
}
PatchType = PatchTypeUnknown;
if ((VolumeLetter == 'A') || (VolumeLetter == 'a') ||
(VolumeLetter == 'B') || (VolumeLetter == 'b')
) {
//
// Floppy
//
sprintf (DiskPath, FloppyPathTemplate, VolumeLetter);
PatchType = PatchTypeFloppy;
}
else {
//
// Hard/USB disk
//
if (!GetDriveInfo (VolumeLetter, &DriveInfo)) {
fprintf (stderr, "ERROR: GetDriveInfo - 0x%x\n", GetLastError ());
return 1;
}
//
// Shouldn't patch my own hard disk, but can read it.
// very safe then:)
//
if (DriveInfo.DriveType->Type == DRIVE_FIXED && WriteToDisk) {
fprintf (stderr, "ERROR: Write to local harddisk - permission denied!\n");
return 1;
}
sprintf (DiskPath, DiskPathTemplate, DriveInfo.DiskNumber);
if (DriveInfo.DriveType->Type == DRIVE_REMOVABLE) {
PatchType = PatchTypeUsb;
}
else if (DriveInfo.DriveType->Type == DRIVE_FIXED) {
PatchType = PatchTypeIde;
}
}
if (PatchType == PatchTypeUnknown) {
fprintf (stderr, "ERROR: PatchType unknown!\n");
return 1;
}
//
// Process DBR (Patch or Read)
//
Status = ProcessBsOrMbr (DiskPath, FilePath, WriteToDisk, PatchType, ProcessMbr);
if (Status == ErrorSuccess) {
fprintf (
stdout,
"%s %s: successfully!\n",
WriteToDisk ? "Write" : "Read",
ProcessMbr ? "MBR" : "DBR"
);
return 0;
} else {
fprintf (
stderr,
"%s: %s %s: failed - %s (LastError: 0x%x)!\n",
(Status == ErrorNoMbr) ? "WARNING" : "ERROR",
WriteToDisk ? "Write" : "Read",
ProcessMbr ? "MBR" : "DBR",
ErrorStatusDesc[Status],
GetLastError ()
);
return 1;
}
}

View File

@ -1,99 +0,0 @@
#/*++
#
# Copyright (c) 2006 - 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# Makefile
#
# Abstract:
#
# makefile for building the GenBootsector utility.
#
#--*/
#
# Make sure environmental variable EDK_SOURCE is set
#
!IFNDEF EDK_SOURCE
!ERROR EDK_SOURCE environmental variable not set
!ENDIF
#
# Do this if you want to compile from this directory
#
!IFNDEF TOOLCHAIN
TOOLCHAIN = TOOLCHAIN_MSVC
!ENDIF
!INCLUDE $(BUILD_DIR)\PlatformTools.env
#
# Define some macros we use here. Should get rid of them someday and
# get rid of the extra level of indirection.
#
COMMON_SOURCE = $(EDK_TOOLS_COMMON)
#
# Common information
#
INC=$(INC)
#
# Target specific information
#
TARGET_NAME=GenBootsector
TARGET_SOURCE_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
TARGET_EXE = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).exe
TARGET_EXE_SOURCE = "$(TARGET_SOURCE_DIR)\GenBootsector.c"
TARGET_EXE_INCLUDE =
#
# Build targets
#
all: $(TARGET_EXE)
#
# Build EXE
#
$(EDK_TOOLS_OUTPUT)\GetDrvNumOffset.obj: $(TARGET_SOURCE_DIR)\GenBootsector.c $(TARGET_SOURCE_DIR)\fat.h
$(CC) $(C_FLAGS) $(INC) $(TARGET_SOURCE_DIR)\GetDrvNumOffset.c /Fo$(EDK_TOOLS_OUTPUT)\GetDrvNumOffset.obj
$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj: $(TARGET_EXE_SOURCE) $(TARGET_EXE_INCLUDE)
$(CC) $(C_FLAGS) $(INC) $(TARGET_EXE_SOURCE) /Fo$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
#
# Add Binary Build description for this tool.
#
!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
$(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe $(TARGET_EXE) /Y
if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(EDK_TOOLS_OUTPUT)\GetDrvNumOffset.obj
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) user32.lib advapi32.lib /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(EDK_TOOLS_OUTPUT)\GetDrvNumOffset.obj
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\GetDrvNumOffset.* del $(EDK_TOOLS_OUTPUT)\GetDrvNumOffset.* > NUL
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -75,11 +75,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_EXE_LIBS) $(TARGET_DLL)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_LIB) $(TARGET_EXE_LIBS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -841,12 +841,12 @@ Returns:
//
// Output the calling arguments
//
printf ("\n\n");
for (Index = 0; Index < argc; Index++) {
printf ("%s ", argv[Index]);
}
printf ("\n\n");
//printf ("\n\n");
//for (Index = 0; Index < argc; Index++) {
// printf ("%s ", argv[Index]);
//}
//
//printf ("\n\n");
if (argc < 5) {
printf ("Not enough arguments\n");

View File

@ -80,11 +80,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_LIB)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_LIB)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
#
# Build LIB

View File

@ -24,6 +24,7 @@ Abstract:
#include "EfiFirmwareFileSystem.h"
#include "EfiFirmwareVolumeHeader.h"
#include "EfiImageFormat.h"
#include "EfiImage.h"
#include "ParseInf.h"
#include "Compress.h"
#include "EfiCustomizedCompress.h"
@ -82,6 +83,39 @@ PrintUsage (
void
);
static
void
AddMacro (
UINT8 *MacroString
);
static
UINT8 *
GetMacroValue (
UINT8 *MacroName
);
static
void
FreeMacros (
);
static
STATUS
ReplaceMacros (
UINT8 *InputFile,
UINT8 *OutputFile
);
//
// Linked list to keep track of all macros
//
typedef struct _MACRO {
struct _MACRO *Next;
UINT8 *Name;
UINT8 *Value;
} MACRO;
//
// Keep globals in this structure
//
@ -90,10 +124,13 @@ static struct {
UINT8 PrimaryPackagePath[_MAX_PATH];
UINT8 OverridePackagePath[_MAX_PATH];
BOOLEAN Verbose;
MACRO *MacroList;
} mGlobals;
static EFI_GUID mZeroGuid = { 0 };
static UINT8 MinFfsDataAlignOverride = 0;
static
void
StripQuotes (
@ -151,8 +188,9 @@ Returns:
--*/
{
printf ("Usage:\n");
printf (UTILITY_NAME " -b \"build directory\" -p1 \"package1.inf\" -p2 \"package2.inf\" -v\n");
printf (" -b \"build directory\":\n ");
printf (UTILITY_NAME " -b \"build directory\" -p1 \"package1.inf\" -p2 \"package2.inf\"\n");
printf (" -d \"name=value\" -v\n");
printf (" -b \"build directory\":\n");
printf (" specifies the full path to the component build directory.\n");
printf (" -p1 \"P1_path\":\n");
printf (" specifies fully qualified file name to the primary package file.\n");
@ -161,6 +199,10 @@ Returns:
printf (" -p2 \"P2_path\":\n");
printf (" specifies fully qualified file name to the override package file.\n");
printf (" This file will normally exist in the build tip. Optional.\n");
printf (" -d \"name=value\":\n");
printf (" add a macro definition for package file. Optional.\n");
printf (" -v :\n");
printf (" verbose. Optional.\n");
}
static
@ -756,54 +798,6 @@ Returns:
return ;
}
static
INT32
ProcessEnvironmentVariable (
IN CHAR8 *Buffer,
OUT CHAR8 *NewBuffer
)
/*++
Routine Description:
Converts environment variables to values
Arguments:
Buffer - Buffer containing Environment Variable String
NewBuffer - Buffer containing value of environment variable
Returns:
Number of characters from Buffer used
--*/
{
INT32 Index;
INT32 Index2;
CHAR8 VariableBuffer[_MAX_PATH];
Index = 2;
Index2 = 0;
while (Buffer[Index] != ')') {
VariableBuffer[Index - 2] = Buffer[Index++];
}
VariableBuffer[Index - 2] = 0;
Index++;
if (getenv (VariableBuffer) != NULL) {
strcpy (NewBuffer, getenv (VariableBuffer));
} else {
printf ("Environment variable %s not found!\n", VariableBuffer);
}
return Index;
}
static
void
SplitAttributesField (
@ -880,7 +874,6 @@ GetToolArguments (
UINT32 Index2;
UINT32 z;
CHAR8 *CharBuffer;
INT32 Index;
INT32 ReturnValue;
EFI_STATUS Status;
@ -982,17 +975,7 @@ GetToolArguments (
ToolArgumentsArray[argc] = CharBuffer;
if (Buffer[0] == '$') {
Index = ProcessEnvironmentVariable (&Buffer[0], ToolArgumentsArray[argc]);
//
// if there is string after the environment variable, cat it.
//
if ((UINT32) Index < strlen (Buffer)) {
strcat (ToolArgumentsArray[argc], &Buffer[Index]);
}
} else {
strcpy (ToolArgumentsArray[argc], Buffer);
}
strcpy (ToolArgumentsArray[argc], Buffer);
argc += 1;
ToolArgumentsArray[argc] = NULL;
@ -1010,17 +993,7 @@ GetToolArguments (
ZeroMem (InputFileName, sizeof (_MAX_PATH));
if (Buffer[0] == '$') {
Index = ProcessEnvironmentVariable (&Buffer[0], InputFileName);
//
// if there is string after the environment variable, cat it.
//
if ((UINT32) Index < strlen (Buffer)) {
strcat (InputFileName, &Buffer[Index]);
}
} else {
strcpy (InputFileName, Buffer);
}
strcpy (InputFileName, Buffer);
InputFlag = FALSE;
continue;
@ -1037,17 +1010,7 @@ GetToolArguments (
ZeroMem (OutputFileName, sizeof (_MAX_PATH));
if (Buffer[0] == '$') {
Index = ProcessEnvironmentVariable (&Buffer[0], OutputFileName);
//
// if there is string after the environment variable, cat it.
//
if ((UINT32) Index < strlen (Buffer)) {
strcat (OutputFileName, &Buffer[Index]);
}
} else {
strcpy (OutputFileName, Buffer);
}
strcpy (OutputFileName, Buffer);
OutputFlag = FALSE;
continue;
@ -1139,10 +1102,12 @@ Returns:
{
EFI_STATUS Status;
UINT32 Size;
UINT32 OldSize;
UINT32 Adjust;
UINT16 TeStrippedSize;
CHAR8 Buffer[_MAX_PATH];
CHAR8 Type[_MAX_PATH];
CHAR8 FileName[_MAX_PATH];
CHAR8 NewBuffer[_MAX_PATH];
INT32 Index3;
INT32 Index2;
UINT32 ReturnValue;
@ -1157,7 +1122,6 @@ Returns:
FILE *InputFile;
UINT8 Temp;
int returnint;
INT32 Index;
UINT32 LineNumber;
BOOLEAN IsError;
EFI_GUID SignGuid;
@ -1200,11 +1164,7 @@ Returns:
}
StripParens (Buffer);
if (Buffer[0] == '$') {
ProcessEnvironmentVariable (&Buffer[0], Type);
} else {
strcpy (Type, Buffer);
}
strcpy (Type, Buffer);
//
// build buffer
//
@ -1275,19 +1235,7 @@ Returns:
}
StripParens (Buffer);
if (Buffer[0] == '$') {
Index = ProcessEnvironmentVariable (&Buffer[0], ToolName);
//
// if there is string after the environment variable, cat it.
//
if ((UINT32) Index < strlen (Buffer)) {
strcat (ToolName, &Buffer[Index]);
}
} else {
strcpy (ToolName, Buffer);
}
strcpy (ToolName, Buffer);
ToolArgumentsArray[0] = ToolName;
//
@ -1397,13 +1345,8 @@ Returns:
if (!isalpha (Buffer[0]) || (Buffer[1] != ':')) {
sprintf (FileName, "%s\\", BuildDirectory);
}
while (Buffer[Index3] != '\n') {
if (Buffer[Index3] == '$') {
Index3 += ProcessEnvironmentVariable (&Buffer[Index3], NewBuffer);
strcat (FileName, NewBuffer);
}
if (Buffer[Index3] == 0) {
break;
} else {
@ -1420,6 +1363,7 @@ Returns:
goto Done;
}
OldSize = Size;
fread (&ByteBuffer, sizeof (UINT8), 1, InFile);
while (!feof (InFile)) {
FileBuffer[Size++] = ByteBuffer;
@ -1429,6 +1373,29 @@ Returns:
fclose (InFile);
InFile = NULL;
//
// Adjust the TE Section for IPF so that the function entries are 16-byte aligned.
//
if (Size - OldSize >= sizeof (EFI_COMMON_SECTION_HEADER) + sizeof (EFI_TE_IMAGE_HEADER) &&
((EFI_COMMON_SECTION_HEADER *) &FileBuffer[OldSize])->Type == EFI_SECTION_TE &&
((EFI_TE_IMAGE_HEADER *) &FileBuffer[OldSize + 4])->Machine == EFI_IMAGE_MACHINE_IA64) {
TeStrippedSize = ((EFI_TE_IMAGE_HEADER *) &FileBuffer[OldSize + 4])->StrippedSize;
Adjust = TeStrippedSize - (OldSize + sizeof (EFI_COMMON_SECTION_HEADER) + sizeof (EFI_TE_IMAGE_HEADER));
Adjust &= 15;
if (Adjust > 0) {
memmove (&FileBuffer[OldSize + Adjust], &FileBuffer[OldSize], Size - OldSize);
//
// Pad with RAW Section type
//
*(UINT32 *)&FileBuffer[OldSize] = 0x19000000 | Adjust;
Size += Adjust;
//
// Make sure the Data alignment in FFS header is no less than 1 (16-byte aligned)
//
MinFfsDataAlignOverride = 1;
}
}
//
// Make sure section ends on a DWORD boundary
//
@ -2252,6 +2219,9 @@ here:
memset (&FileHeader, 0, sizeof (EFI_FFS_FILE_HEADER));
memcpy (&FileHeader.Name, &FfsGuid, sizeof (EFI_GUID));
FileHeader.Type = StringToType (FileType);
if (((FfsAttrib & FFS_ATTRIB_DATA_ALIGNMENT) >> 3) < MinFfsDataAlignOverride) {
FfsAttrib = (FfsAttrib & ~FFS_ATTRIB_DATA_ALIGNMENT) | (MinFfsDataAlignOverride << 3);
}
FileHeader.Attributes = FfsAttrib;
//
// Now FileSize includes the EFI_FFS_FILE_HEADER
@ -2396,6 +2366,9 @@ here:
memset (&FileHeader, 0, sizeof (EFI_FFS_FILE_HEADER));
memcpy (&FileHeader.Name, &FfsGuid, sizeof (EFI_GUID));
FileHeader.Type = StringToType (FileType);
if (((FfsAttrib & FFS_ATTRIB_DATA_ALIGNMENT) >> 3) < MinFfsDataAlignOverride) {
FfsAttrib = (FfsAttrib & ~FFS_ATTRIB_DATA_ALIGNMENT) | (MinFfsDataAlignOverride << 3);
}
FileHeader.Attributes = FfsAttrib;
//
// From this point on FileSize includes the size of the EFI_FFS_FILE_HEADER
@ -2540,6 +2513,7 @@ Returns:
//
SetUtilityName (UTILITY_NAME);
Status = ProcessCommandLineArgs (argc, argv);
FreeMacros ();
if (Status != STATUS_SUCCESS) {
return Status;
}
@ -2577,6 +2551,11 @@ Returns:
--*/
{
STATUS Status;
UINT8 *OriginalPrimaryPackagePath;
UINT8 *OriginalOverridePackagePath;
UINT8 *PackageName;
//
// If no args, then print usage instructions and return an error
//
@ -2584,7 +2563,9 @@ Returns:
PrintUsage ();
return STATUS_ERROR;
}
OriginalPrimaryPackagePath = NULL;
OriginalOverridePackagePath = NULL;
memset (&mGlobals, 0, sizeof (mGlobals));
Argc--;
Argv++;
@ -2617,12 +2598,12 @@ Returns:
return STATUS_ERROR;
}
if (mGlobals.PrimaryPackagePath[0]) {
if (OriginalPrimaryPackagePath) {
Error (NULL, 0, 0, Argv[0], "option can only be specified once");
return STATUS_ERROR;
}
strcpy (mGlobals.PrimaryPackagePath, Argv[1]);
OriginalPrimaryPackagePath = Argv[1];
Argc--;
Argv++;
} else if (_strcmpi (Argv[0], "-p2") == 0) {
@ -2635,12 +2616,12 @@ Returns:
return STATUS_ERROR;
}
if (mGlobals.OverridePackagePath[0]) {
if (OriginalOverridePackagePath) {
Error (NULL, 0, 0, Argv[0], "option can only be specified once");
return STATUS_ERROR;
}
strcpy (mGlobals.OverridePackagePath, Argv[1]);
OriginalOverridePackagePath = Argv[1];
Argc--;
Argv++;
} else if (_strcmpi (Argv[0], "-v") == 0) {
@ -2648,6 +2629,19 @@ Returns:
// OPTION: -v verbose
//
mGlobals.Verbose = TRUE;
} else if (_strcmpi (Argv[0], "-d") == 0) {
//
// OPTION: -d name=value
// Make sure there is another argument, then add it to our macro list.
//
if (Argc < 2) {
Error (NULL, 0, 0, Argv[0], "option requires the macro definition");
return STATUS_ERROR;
}
AddMacro (Argv[1]);
Argc--;
Argv++;
} else if (_strcmpi (Argv[0], "-h") == 0) {
//
// OPTION: -h help
@ -2669,13 +2663,324 @@ Returns:
Argv++;
Argc--;
}
//
// Must have at least specified the build directory
//
if (!mGlobals.BuildDirectory[0]) {
Error (NULL, 0, 0, "must specify build directory", NULL);
return STATUS_ERROR;
}
//
// Must have at least specified the package file name
//
if (mGlobals.PrimaryPackagePath[0] == 0) {
if (OriginalPrimaryPackagePath == NULL) {
Error (NULL, 0, 0, "must specify primary package file", NULL);
return STATUS_ERROR;
}
PackageName = OriginalPrimaryPackagePath + strlen (OriginalPrimaryPackagePath);
while ((*PackageName != '\\') && (*PackageName != '/') &&
(PackageName != OriginalPrimaryPackagePath)) {
PackageName--;
}
//
// Skip the '\' or '/'
//
if (PackageName != OriginalPrimaryPackagePath) {
PackageName++;
}
sprintf (mGlobals.PrimaryPackagePath, "%s\\%s.new", mGlobals.BuildDirectory, PackageName);
Status = ReplaceMacros (OriginalPrimaryPackagePath, mGlobals.PrimaryPackagePath);
if (Status == STATUS_WARNING) {
//
// No macro replacement, use the previous package file
//
strcpy (mGlobals.PrimaryPackagePath, OriginalPrimaryPackagePath);
} else if (Status != STATUS_SUCCESS) {
return Status;
}
if (OriginalOverridePackagePath != NULL) {
PackageName = OriginalOverridePackagePath + strlen (OriginalOverridePackagePath);
while ((*PackageName != '\\') && (*PackageName != '/') &&
(PackageName != OriginalOverridePackagePath)) {
PackageName--;
}
//
// Skip the '\' or '/'
//
if (PackageName != OriginalOverridePackagePath) {
PackageName++;
}
sprintf (mGlobals.OverridePackagePath, "%s\\%s.new", mGlobals.BuildDirectory, PackageName);
Status = ReplaceMacros (OriginalOverridePackagePath, mGlobals.OverridePackagePath);
if (Status == STATUS_WARNING) {
//
// No macro replacement, use the previous package file
//
strcpy (mGlobals.OverridePackagePath, OriginalOverridePackagePath);
} else if (Status != STATUS_SUCCESS) {
return Status;
}
}
return STATUS_SUCCESS;
}
static
void
AddMacro (
UINT8 *MacroString
)
/*++
Routine Description:
Add or override a macro definition.
Arguments:
MacroString - macro definition string: name=value
Returns:
None
--*/
{
MACRO *Macro;
MACRO *NewMacro;
UINT8 *Value;
//
// Seperate macro name and value by '\0'
//
for (Value = MacroString; *Value && (*Value != '='); Value++);
if (*Value == '=') {
*Value = '\0';
Value ++;
}
//
// We now have a macro name and value.
// Look for an existing macro and overwrite it.
//
Macro = mGlobals.MacroList;
while (Macro) {
if (_strcmpi (MacroString, Macro->Name) == 0) {
Macro->Value = Value;
return;
}
Macro = Macro->Next;
}
//
// Does not exist, create a new one
//
NewMacro = (MACRO *) malloc (sizeof (MACRO));
memset ((UINT8 *) NewMacro, 0, sizeof (MACRO));
NewMacro->Name = MacroString;
NewMacro->Value = Value;
//
// Add it to the head of the list.
//
NewMacro->Next = mGlobals.MacroList;
mGlobals.MacroList = NewMacro;
return;
}
static
UINT8 *
GetMacroValue (
UINT8 *MacroName
)
/*++
Routine Description:
Look up a macro.
Arguments:
MacroName - The name of macro
Returns:
Pointer to the value of the macro if found
NULL if the macro is not found
--*/
{
MACRO *Macro;
UINT8 *Value;
//
// Scan for macro
//
Macro = mGlobals.MacroList;
while (Macro) {
if (_strcmpi (MacroName, Macro->Name) == 0) {
return Macro->Value;
}
Macro = Macro->Next;
}
//
// Try environment variable
//
Value = getenv (MacroName);
if (Value == NULL) {
printf ("Environment variable %s not found!\n", MacroName);
}
return Value;
}
static
void
FreeMacros (
)
/*++
Routine Description:
Free the macro list.
Arguments:
None
Returns:
None
--*/
{
MACRO *Macro;
MACRO *NextMacro;
Macro = mGlobals.MacroList;
while (Macro) {
NextMacro = Macro->Next;
free (Macro);
Macro = NextMacro;
}
mGlobals.MacroList = NULL;
return;
}
static
STATUS
ReplaceMacros (
UINT8 *InputFile,
UINT8 *OutputFile
)
/*++
Routine Description:
Replace all the macros in InputFile to create the OutputFile.
Arguments:
InputFile - Input package file for macro replacement
OutputFile - Output package file after macro replacement
Returns:
STATUS_SUCCESS - Output package file is created successfully after the macro replacement.
STATUS_WARNING - Output package file is not created because of no macro replacement.
STATUS_ERROR - Some error occurred during execution.
--*/
{
FILE *Fptr;
UINT8 *SaveStart;
UINT8 *FromPtr;
UINT8 *ToPtr;
UINT8 *Value;
UINT8 *FileBuffer;
UINTN FileSize;
//
// Get the file size, and then read the entire thing into memory.
// Allocate extra space for a terminator character.
//
if ((Fptr = fopen (InputFile, "r")) == NULL) {
Error (NULL, 0, 0, InputFile, "can't open input file");
return STATUS_ERROR;
}
fseek (Fptr, 0, SEEK_END);
FileSize = ftell (Fptr);
fseek (Fptr, 0, SEEK_SET);
FileBuffer = malloc (FileSize + 1);
if (FileBuffer == NULL) {
fclose (Fptr);
Error (NULL, 0, 0, InputFile, "file buffer memory allocation failure");
return STATUS_ERROR;
}
fread (FileBuffer, FileSize, 1, Fptr);
FileBuffer[FileSize] = '\0';
fclose (Fptr);
//
// Walk the entire file, replacing $(MACRO_NAME).
//
Fptr = NULL;
FromPtr = FileBuffer;
SaveStart = FromPtr;
while (*FromPtr) {
if ((*FromPtr == '$') && (*(FromPtr + 1) == '(')) {
FromPtr += 2;
for (ToPtr = FromPtr; *ToPtr && (*ToPtr != ')'); ToPtr++);
if (*ToPtr) {
//
// Find an $(MACRO_NAME), replace it
//
*ToPtr = '\0';
Value = GetMacroValue (FromPtr);
*(FromPtr-2)= '\0';
if (Fptr == NULL) {
if ((Fptr = fopen (OutputFile, "w")) == NULL) {
free (FileBuffer);
Error (NULL, 0, 0, OutputFile, "can't open output file");
return STATUS_ERROR;
}
}
if (Value != NULL) {
fprintf (Fptr, "%s%s", SaveStart, Value);
} else {
fprintf (Fptr, "%s", SaveStart);
}
//
// Continue macro replacement for the remaining string line
//
FromPtr = ToPtr+1;
SaveStart = FromPtr;
continue;
} else {
break;
}
} else {
FromPtr++;
}
}
if (Fptr != NULL) {
fprintf (Fptr, "%s", SaveStart);
}
free (FileBuffer);
if (Fptr != NULL) {
fclose (Fptr);
return STATUS_SUCCESS;
} else {
return STATUS_WARNING;
}
}

View File

@ -78,11 +78,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(LIBS) $(TARGET_EXE_LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj \
$(TARGET_LIB) $(TARGET_EXE_LIBS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -26,7 +26,7 @@ Abstract:
//
// Include files
//
#include "Efi2WinNT.h"
#include <windows.h>
#include "ParseInf.h"
//

View File

@ -88,11 +88,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_EXE_LIBS) $(TARGET_LIB)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_LIB) $(TARGET_EXE_LIBS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
#
# Build LIB

View File

@ -1,127 +0,0 @@
/*++
Copyright 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
VirtualMemory.h
Abstract:
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
--*/
#ifndef _VIRTUAL_MEMORY_H_
#define _VIRTUAL_MEMORY_H_
#include "Tiano.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

View File

@ -1,344 +0,0 @@
/*++
Copyright 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenPage.c
Abstract:
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}
--*/
#include <stdio.h>
#include <stdlib.h>
#include "VirtualMemory.h"
void
memset (void *, char, long);
unsigned int
xtoi (char *);
#define EFI_PAGE_BASE_OFFSET_IN_LDR 0x70000
#define EFI_PAGE_BASE_ADDRESS (EFI_PAGE_BASE_OFFSET_IN_LDR + 0x20000)
unsigned int gPageTableBaseAddress = EFI_PAGE_BASE_ADDRESS;
unsigned int 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)
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);
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;
}
int
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 (PageFileName, "w+b");
if (PageFile == NULL) {
fprintf (stderr, "GenBinPage: Could not open file %s\n", PageFileName);
return -1;
}
NoPageFile = fopen (NoPageFileName, "r+b");
if (NoPageFile == NULL) {
fprintf (stderr, "GenBinPage: Could not open file %s\n", 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) {
fprintf (stderr, "GenBinPage: file size too large - 0x%x\n", FileSize);
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;
int result;
//
// Check parameter
//
if ((argc != 3) && (argc != 5)) {
printf ("Usage: GenPage.exe NoPageFile PageFile [<PageTableBaseAddrss> <PageTableOffsetInFile>]\n");
return 1;
}
//
// Get PageTable parameter, if have
//
if (argc == 5) {
gPageTableBaseAddress = xtoi (argv[3]);
gPageTableOffsetInFile = xtoi (argv[4]);
}
//
// Create X64 page table
//
BaseMemory = CreateIdentityMappingPageTables ();
//
// Add page table to binary file
//
result = GenBinPage (BaseMemory, argv[1], argv[2]);
if (result < 0) {
return 1;
}
return 0;
}
unsigned int
xtoi (
char *str
)
/*++
Routine Description:
Convert hex string to uint
Arguments:
Str - The string
Returns:
--*/
{
unsigned int u;
char c;
unsigned int m;
if (str == NULL) {
return 0;
}
m = (unsigned int) -1 >> 4;
//
// skip preceeding white space
//
while (*str && *str == ' ') {
str += 1;
}
//
// skip preceeding zeros
//
while (*str && *str == '0') {
str += 1;
}
//
// skip preceeding white space
//
if (*str && (*str == 'x' || *str == 'X')) {
str += 1;
}
//
// convert hex digits
//
u = 0;
c = *(str++);
while (c) {
if (c >= 'a' && c <= 'f') {
c -= 'a' - 'A';
}
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
if (u > m) {
return (unsigned int) -1;
}
u = u << 4 | c - (c >= 'A' ? 'A' - 10 : '0');
} else {
break;
}
c = *(str++);
}
return u;
}

View File

@ -72,11 +72,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(LIBS) $(TARGET_EXE_LIBS)
$(LINK) /DEBUG $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_EXE_LIBS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -0,0 +1,929 @@
/*++
Copyright (c) 1999 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenTEImage.c
Abstract:
Utility program to shrink a PE32 image down by replacing
the DOS, PE, and optional headers with a minimal header.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Tiano.h"
#include "TianoCommon.h"
#include "EfiImage.h" // for PE32 structure definitions
#include "EfiUtilityMsgs.h"
//
// Version of this utility
//
#define UTILITY_NAME "GenTEImage"
#define UTILITY_VERSION "v0.11"
//
// Define the max length of a filename
//
#define MAX_PATH 256
#define DEFAULT_OUTPUT_EXTENSION ".te"
//
// Use this to track our command-line options and globals
//
struct {
INT8 OutFileName[MAX_PATH];
INT8 InFileName[MAX_PATH];
INT8 Verbose;
INT8 Dump;
} mOptions;
//
// Use these to convert from machine type value to a named type
//
typedef struct {
UINT16 Value;
INT8 *Name;
} STRING_LOOKUP;
static STRING_LOOKUP mMachineTypes[] = {
EFI_IMAGE_MACHINE_IA32,
"IA32",
EFI_IMAGE_MACHINE_IA64,
"IA64",
EFI_IMAGE_MACHINE_X64,
"X64",
EFI_IMAGE_MACHINE_EBC,
"EBC",
0,
NULL
};
static STRING_LOOKUP mSubsystemTypes[] = {
EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION,
"EFI application",
EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER,
"EFI boot service driver",
EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER,
"EFI runtime driver",
0,
NULL
};
//
// Function prototypes
//
static
void
Usage (
VOID
);
static
STATUS
ParseCommandLine (
int Argc,
char *Argv[]
);
static
STATUS
CheckPE32File (
INT8 *FileName,
FILE *Fptr,
UINT16 *MachineType,
UINT16 *SubSystem
);
static
STATUS
ProcessFile (
INT8 *InFileName,
INT8 *OutFileName
);
static
void
DumpImage (
INT8 *FileName
);
static
INT8 *
GetMachineTypeStr (
UINT16 MachineType
);
static
INT8 *
GetSubsystemTypeStr (
UINT16 SubsystemType
);
int
main (
int Argc,
char *Argv[]
)
/*++
Routine Description:
Arguments:
Argc - standard C main() argument count
Argv - standard C main() argument list
Returns:
0 success
non-zero otherwise
--*/
// GC_TODO: ] - add argument and description to function comment
{
INT8 *Ext;
UINT32 Status;
SetUtilityName (UTILITY_NAME);
//
// Parse the command line arguments
//
if (ParseCommandLine (Argc, Argv)) {
return STATUS_ERROR;
}
//
// If dumping an image, then do that and quit
//
if (mOptions.Dump) {
DumpImage (mOptions.InFileName);
goto Finish;
}
//
// Determine the output filename. Either what they specified on
// the command line, or the first input filename with a different extension.
//
if (!mOptions.OutFileName[0]) {
strcpy (mOptions.OutFileName, mOptions.InFileName);
//
// Find the last . on the line and replace the filename extension with
// the default
//
for (Ext = mOptions.OutFileName + strlen (mOptions.OutFileName) - 1;
(Ext >= mOptions.OutFileName) && (*Ext != '.') && (*Ext != '\\');
Ext--
)
;
//
// If dot here, then insert extension here, otherwise append
//
if (*Ext != '.') {
Ext = mOptions.OutFileName + strlen (mOptions.OutFileName);
}
strcpy (Ext, DEFAULT_OUTPUT_EXTENSION);
}
//
// Make sure we don't have the same filename for input and output files
//
if (_stricmp (mOptions.OutFileName, mOptions.InFileName) == 0) {
Error (NULL, 0, 0, mOptions.OutFileName, "input and output file names must be different");
goto Finish;
}
//
// Process the file
//
ProcessFile (mOptions.InFileName, mOptions.OutFileName);
Finish:
Status = GetUtilityStatus ();
return Status;
}
static
STATUS
ProcessFile (
INT8 *InFileName,
INT8 *OutFileName
)
/*++
Routine Description:
Process a PE32 EFI file.
Arguments:
InFileName - the file name pointer to the input file
OutFileName - the file name pointer to the output file
Returns:
STATUS_SUCCESS - the process has been finished successfully
STATUS_ERROR - error occured during the processing
--*/
{
STATUS Status;
FILE *InFptr;
FILE *OutFptr;
UINT16 MachineType;
UINT16 SubSystem;
EFI_TE_IMAGE_HEADER TEImageHeader;
UINT32 PESigOffset;
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader32;
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader64;
UINT32 BytesStripped;
UINT32 FileSize;
UINT8 *Buffer;
long SaveFilePosition;
InFptr = NULL;
OutFptr = NULL;
Buffer = NULL;
Status = STATUS_ERROR;
//
// Try to open the input file
//
if ((InFptr = fopen (InFileName, "rb")) == NULL) {
Error (NULL, 0, 0, InFileName, "failed to open input file for reading");
return STATUS_ERROR;
}
//
// Double-check the file to make sure it's what we expect it to be
//
if (CheckPE32File (InFileName, InFptr, &MachineType, &SubSystem) != STATUS_SUCCESS) {
goto Finish;
}
//
// Initialize our new header
//
memset (&TEImageHeader, 0, sizeof (EFI_TE_IMAGE_HEADER));
//
// Seek to the end to get the file size
//
fseek (InFptr, 0, SEEK_END);
FileSize = ftell (InFptr);
fseek (InFptr, 0, SEEK_SET);
//
// Per the PE/COFF specification, at offset 0x3C in the file is a 32-bit
// offset (from the start of the file) to the PE signature, which always
// follows the MSDOS stub. The PE signature is immediately followed by the
// COFF file header.
//
//
if (fseek (InFptr, 0x3C, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to PE signature in file", NULL);
goto Finish;
}
if (fread (&PESigOffset, sizeof (PESigOffset), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read PE signature offset from file");
goto Finish;
}
if (fseek (InFptr, PESigOffset + 4, SEEK_SET) != 0) {
Error (NULL, 0, 0, InFileName, "failed to seek to PE signature");
goto Finish;
}
//
// We should now be at the COFF file header. Read it in and verify it's
// of an image type we support.
//
if (fread (&FileHeader, sizeof (EFI_IMAGE_FILE_HEADER), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read file header from image");
goto Finish;
}
if ((FileHeader.Machine != EFI_IMAGE_MACHINE_IA32) &&
(FileHeader.Machine != EFI_IMAGE_MACHINE_X64) &&
(FileHeader.Machine != EFI_IMAGE_MACHINE_IA64)) {
Error (NULL, 0, 0, InFileName, "image is of an unsupported machine type 0x%X", (UINT32) FileHeader.Machine);
goto Finish;
}
//
// Calculate the total number of bytes we're going to strip off. The '4' is for the
// PE signature PE\0\0. Then sanity check the size.
//
BytesStripped = PESigOffset + 4 + sizeof (EFI_IMAGE_FILE_HEADER) + FileHeader.SizeOfOptionalHeader;
if (BytesStripped >= FileSize) {
Error (NULL, 0, 0, InFileName, "attempt to strip more bytes than the total file size");
goto Finish;
}
if (BytesStripped &~0xFFFF) {
Error (NULL, 0, 0, InFileName, "attempt to strip more than 64K bytes", NULL);
goto Finish;
}
TEImageHeader.StrippedSize = (UINT16) BytesStripped;
//
// Read in the optional header. Assume PE32, and if not, then re-read as PE32+
//
SaveFilePosition = ftell (InFptr);
if (fread (&OptionalHeader32, sizeof (EFI_IMAGE_OPTIONAL_HEADER32), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read optional header from input file");
goto Finish;
}
if (OptionalHeader32.SectionAlignment != OptionalHeader32.FileAlignment) {
Error (NULL, 0, 0, InFileName, "Section alignment is not same to file alignment.");
goto Finish;
}
if (OptionalHeader32.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Fill in our new header with required data directory entries
//
TEImageHeader.AddressOfEntryPoint = OptionalHeader32.AddressOfEntryPoint;
//
// - BytesStripped + sizeof (EFI_TE_IMAGE_HEADER);
//
// We're going to pack the subsystem into 1 byte. Make sure it fits
//
if (OptionalHeader32.Subsystem &~0xFF) {
Error (
NULL,
0,
0,
InFileName,
NULL,
"image subsystem 0x%X cannot be packed into 1 byte",
(UINT32) OptionalHeader32.Subsystem
);
goto Finish;
}
TEImageHeader.Subsystem = (UINT8) OptionalHeader32.Subsystem;
TEImageHeader.BaseOfCode = OptionalHeader32.BaseOfCode;
TEImageHeader.ImageBase = (UINT64) (OptionalHeader32.ImageBase);
if (OptionalHeader32.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
}
if (OptionalHeader32.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = OptionalHeader32.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
}
} else if (OptionalHeader32.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
//
// Rewind and re-read the optional header
//
fseek (InFptr, SaveFilePosition, SEEK_SET);
if (fread (&OptionalHeader64, sizeof (EFI_IMAGE_OPTIONAL_HEADER64), 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to re-read optional header from input file");
goto Finish;
}
TEImageHeader.AddressOfEntryPoint = OptionalHeader64.AddressOfEntryPoint;
//
// - BytesStripped + sizeof (EFI_TE_IMAGE_HEADER);
//
// We're going to pack the subsystem into 1 byte. Make sure it fits
//
if (OptionalHeader64.Subsystem &~0xFF) {
Error (
NULL,
0,
0,
InFileName,
NULL,
"image subsystem 0x%X cannot be packed into 1 byte",
(UINT32) OptionalHeader64.Subsystem
);
goto Finish;
}
TEImageHeader.Subsystem = (UINT8) OptionalHeader64.Subsystem;
TEImageHeader.BaseOfCode = OptionalHeader64.BaseOfCode;
TEImageHeader.ImageBase = (UINT64) (OptionalHeader64.ImageBase);
if (OptionalHeader64.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
}
if (OptionalHeader64.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = OptionalHeader64.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
}
} else {
Error (
NULL,
0,
0,
InFileName,
"unsupported magic number 0x%X found in optional header",
(UINT32) OptionalHeader32.Magic
);
goto Finish;
}
//
// Fill in the remainder of our new image header
//
TEImageHeader.Signature = EFI_TE_IMAGE_HEADER_SIGNATURE;
TEImageHeader.Machine = FileHeader.Machine;
//
// We're going to pack the number of sections into a single byte. Make sure it fits.
//
if (FileHeader.NumberOfSections &~0xFF) {
Error (
NULL,
0,
0,
InFileName,
NULL,
"image's number of sections 0x%X cannot be packed into 1 byte",
(UINT32) FileHeader.NumberOfSections
);
goto Finish;
}
TEImageHeader.NumberOfSections = (UINT8) FileHeader.NumberOfSections;
//
// Now open our output file
//
if ((OutFptr = fopen (OutFileName, "wb")) == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
goto Finish;
}
//
// Write the TE header
//
if (fwrite (&TEImageHeader, sizeof (EFI_TE_IMAGE_HEADER), 1, OutFptr) != 1) {
Error (NULL, 0, 0, "failed to write image header to output file", NULL);
goto Finish;
}
//
// Position into the input file, read the part we're not stripping, and
// write it out.
//
fseek (InFptr, BytesStripped, SEEK_SET);
Buffer = (UINT8 *) malloc (FileSize - BytesStripped);
if (Buffer == NULL) {
Error (NULL, 0, 0, "application error", "failed to allocate memory");
goto Finish;
}
if (fread (Buffer, FileSize - BytesStripped, 1, InFptr) != 1) {
Error (NULL, 0, 0, InFileName, "failed to read remaining contents of input file");
goto Finish;
}
if (fwrite (Buffer, FileSize - BytesStripped, 1, OutFptr) != 1) {
Error (NULL, 0, 0, OutFileName, "failed to write all bytes to output file");
goto Finish;
}
Status = STATUS_SUCCESS;
Finish:
if (InFptr != NULL) {
fclose (InFptr);
}
//
// Close the output file. If there was an error, delete the output file so
// that a subsequent build will rebuild it.
//
if (OutFptr != NULL) {
fclose (OutFptr);
if (GetUtilityStatus () == STATUS_ERROR) {
remove (OutFileName);
}
}
//
// Free up our buffer
//
if (Buffer != NULL) {
free (Buffer);
}
return Status;
}
static
STATUS
CheckPE32File (
INT8 *FileName,
FILE *Fptr,
UINT16 *MachineType,
UINT16 *SubSystem
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
FileName - GC_TODO: add argument description
Fptr - GC_TODO: add argument description
MachineType - GC_TODO: add argument description
SubSystem - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
/*++
Routine Description:
Given a file pointer to a supposed PE32 image file, verify that it is indeed a
PE32 image file, and then return the machine type in the supplied pointer.
Arguments:
Fptr File pointer to the already-opened PE32 file
MachineType Location to stuff the machine type of the PE32 file. This is needed
because the image may be Itanium-based, IA32, or EBC.
Returns:
0 success
non-zero otherwise
--*/
EFI_IMAGE_DOS_HEADER DosHeader;
EFI_IMAGE_FILE_HEADER FileHdr;
EFI_IMAGE_OPTIONAL_HEADER OptionalHdr;
UINT32 PESig;
STATUS Status;
Status = STATUS_ERROR;
//
// Position to the start of the file
//
fseek (Fptr, 0, SEEK_SET);
//
// Read the DOS header
//
if (fread (&DosHeader, sizeof (DosHeader), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read the DOS stub from the input file");
goto Finish;
}
//
// Check the magic number (0x5A4D)
//
if (DosHeader.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Error (NULL, 0, 0, FileName, "input file does not appear to be a PE32 image (magic number)");
goto Finish;
}
//
// Position into the file and check the PE signature
//
fseek (Fptr, (long) DosHeader.e_lfanew, SEEK_SET);
if (fread (&PESig, sizeof (PESig), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read PE signature bytes");
goto Finish;
}
//
// Check the PE signature in the header "PE\0\0"
//
if (PESig != EFI_IMAGE_NT_SIGNATURE) {
Error (NULL, 0, 0, FileName, "file does not appear to be a PE32 image (signature)");
goto Finish;
}
//
// Read the file header
//
if (fread (&FileHdr, sizeof (FileHdr), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read PE file header from input file");
goto Finish;
}
//
// Read the optional header so we can get the subsystem
//
if (fread (&OptionalHdr, sizeof (OptionalHdr), 1, Fptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read COFF optional header from input file");
goto Finish;
}
*SubSystem = OptionalHdr.Subsystem;
if (mOptions.Verbose) {
fprintf (stdout, " Got subsystem = 0x%X from image\n", (int) *SubSystem);
}
//
// Good to go
//
Status = STATUS_SUCCESS;
Finish:
fseek (Fptr, 0, SEEK_SET);
return Status;
}
static
int
ParseCommandLine (
int Argc,
char *Argv[]
)
/*++
Routine Description:
Given the Argc/Argv program arguments, and a pointer to an options structure,
parse the command-line options and check their validity.
Arguments:
Argc - standard C main() argument count
Argv - standard C main() argument list
Returns:
STATUS_SUCCESS success
non-zero otherwise
--*/
// GC_TODO: ] - add argument and description to function comment
{
//
// Clear out the options
//
memset ((char *) &mOptions, 0, sizeof (mOptions));
//
// Skip over the program name
//
Argc--;
Argv++;
//
// If no arguments, assume they want usage info
//
if (Argc == 0) {
Usage ();
return STATUS_ERROR;
}
//
// Process until no more arguments
//
while ((Argc > 0) && ((Argv[0][0] == '-') || (Argv[0][0] == '/'))) {
//
// To simplify string comparisons, replace slashes with dashes
//
Argv[0][0] = '-';
if (_stricmp (Argv[0], "-o") == 0) {
//
// Output filename specified with -o
// Make sure there's another parameter
//
if (Argc > 1) {
strcpy (mOptions.OutFileName, Argv[1]);
} else {
Error (NULL, 0, 0, Argv[0], "missing output file name with option");
Usage ();
return STATUS_ERROR;
}
Argv++;
Argc--;
} else if ((_stricmp (Argv[0], "-h") == 0) || (strcmp (Argv[0], "-?") == 0)) {
//
// Help option
//
Usage ();
return STATUS_ERROR;
} else if (_stricmp (Argv[0], "-v") == 0) {
//
// -v for verbose
//
mOptions.Verbose = 1;
} else if (_stricmp (Argv[0], "-dump") == 0) {
//
// -dump for dumping an image
//
mOptions.Dump = 1;
} else {
Error (NULL, 0, 0, Argv[0], "unrecognized option");
Usage ();
return STATUS_ERROR;
}
//
// Next argument
//
Argv++;
Argc--;
}
//
// Better be one more arg for input file name
//
if (Argc == 0) {
Error (NULL, 0, 0, "input file name required", NULL);
Usage ();
return STATUS_ERROR;
}
if (Argc != 1) {
Error (NULL, 0, 0, Argv[1], "extra arguments on command line");
return STATUS_ERROR;
}
strcpy (mOptions.InFileName, Argv[0]);
return STATUS_SUCCESS;
}
static
void
Usage (
VOID
)
/*++
Routine Description:
Print usage information for this utility.
Arguments:
None.
Returns:
Nothing.
--*/
{
int Index;
static const char *Msg[] = {
UTILITY_NAME " version "UTILITY_VERSION " - TE image utility",
" Generate a TE image from an EFI PE32 image",
" Usage: "UTILITY_NAME " {-v} {-dump} {-h|-?} {-o OutFileName} InFileName",
" [-e|-b] [FileName(s)]",
" where:",
" -v - for verbose output",
" -dump - to dump the input file to a text file",
" -h -? - for this help information",
" -o OutFileName - to write output to OutFileName rather than InFileName"DEFAULT_OUTPUT_EXTENSION,
" InFileName - name of the input PE32 file",
"",
NULL
};
for (Index = 0; Msg[Index] != NULL; Index++) {
fprintf (stdout, "%s\n", Msg[Index]);
}
}
static
VOID
DumpImage (
INT8 *FileName
)
/*++
Routine Description:
Dump a specified image information
Arguments:
FileName - File name pointer to the image to dump
Returns:
Nothing.
--*/
{
FILE *InFptr;
EFI_TE_IMAGE_HEADER TEImageHeader;
INT8 *NamePtr;
//
// Open the input file
//
InFptr = NULL;
if ((InFptr = fopen (FileName, "rb")) == NULL) {
Error (NULL, 0, 0, FileName, "failed to open input file for reading");
return ;
}
if (fread (&TEImageHeader, sizeof (EFI_TE_IMAGE_HEADER), 1, InFptr) != 1) {
Error (NULL, 0, 0, FileName, "failed to read image header from input file");
goto Finish;
}
if (TEImageHeader.Signature != EFI_TE_IMAGE_HEADER_SIGNATURE) {
Error (NULL, 0, 0, FileName, "Image does not appear to be a TE image (bad signature)");
goto Finish;
}
//
// Dump the header
//
fprintf (stdout, "Header (%d bytes):\n", sizeof (EFI_TE_IMAGE_HEADER));
fprintf (stdout, " Signature: 0x%04X (TE)\n", (UINT32) TEImageHeader.Signature);
NamePtr = GetMachineTypeStr (TEImageHeader.Machine);
fprintf (stdout, " Machine: 0x%04X (%s)\n", (UINT32) TEImageHeader.Machine, NamePtr);
NamePtr = GetSubsystemTypeStr (TEImageHeader.Subsystem);
fprintf (stdout, " Subsystem: 0x%02X (%s)\n", (UINT32) TEImageHeader.Subsystem, NamePtr);
fprintf (stdout, " Number of sections 0x%02X\n", (UINT32) TEImageHeader.NumberOfSections);
fprintf (stdout, " Stripped size: 0x%04X\n", (UINT32) TEImageHeader.StrippedSize);
fprintf (stdout, " Entry point: 0x%08X\n", TEImageHeader.AddressOfEntryPoint);
fprintf (stdout, " Base of code: 0x%08X\n", TEImageHeader.BaseOfCode);
fprintf (stdout, " Data directories:\n");
fprintf (
stdout,
" %8X [%8X] RVA [size] of Base Relocation Directory\n",
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress,
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size
);
fprintf (
stdout,
" %8X [%8X] RVA [size] of Debug Directory\n",
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress,
TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].Size
);
Finish:
if (InFptr != NULL) {
fclose (InFptr);
}
}
static
INT8 *
GetMachineTypeStr (
UINT16 MachineType
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
MachineType - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
int Index;
for (Index = 0; mMachineTypes[Index].Name != NULL; Index++) {
if (mMachineTypes[Index].Value == MachineType) {
return mMachineTypes[Index].Name;
}
}
return "unknown";
}
static
INT8 *
GetSubsystemTypeStr (
UINT16 SubsystemType
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
SubsystemType - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
int Index;
for (Index = 0; mSubsystemTypes[Index].Name != NULL; Index++) {
if (mSubsystemTypes[Index].Value == SubsystemType) {
return mSubsystemTypes[Index].Name;
}
}
return "unknown";
}

View File

@ -1,6 +1,6 @@
#/*++
#
# Copyright (c) 2006 - 2007, Intel Corporation
#
# Copyright (c) 2002 - 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@ -9,15 +9,15 @@
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# Makefile
#
# Module Name:
#
# makefile
#
# Abstract:
#
# makefile for building the GenPage utility.
#
#--*/
#
# makefile for building the GenTEImage utility.
#
#--*/
#
# Make sure environmental variable EDK_SOURCE is set
@ -27,37 +27,19 @@
!ENDIF
#
# Do this if you want to compile from this directory
# Define the toolchain which is used to set build options and toolchain paths
#
!IFNDEF TOOLCHAIN
TOOLCHAIN = TOOLCHAIN_MSVC
!ENDIF
!INCLUDE $(BUILD_DIR)\PlatformTools.env
#
# Define some macros we use here. Should get rid of them someday and
# get rid of the extra level of indirection.
#
COMMON_SOURCE = $(EDK_TOOLS_COMMON)
#
# Common information
#
INC=$(INC)
#
# Target specific information
#
TARGET_NAME=GenPage
TARGET_SOURCE_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
TARGET_EXE = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).exe
TARGET_EXE_SOURCE = "$(TARGET_SOURCE_DIR)\GenPage.c"
TARGET_EXE_INCLUDE = "$(TARGET_SOURCE_DIR)\VirtualMemory.h"
TARGET_NAME = GenTEImage
TARGET_SRC_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
TARGET_EXE = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).exe
#
# Build targets
@ -65,15 +47,22 @@ TARGET_EXE_INCLUDE = "$(TARGET_SOURCE_DIR)\VirtualMemory.h"
all: $(TARGET_EXE)
OBJECTS = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
LIBS = $(EDK_TOOLS_OUTPUT)\Common.lib
INC_DEPS = $(EDK_SOURCE)\Foundation\Efi\Include\EfiImage.h
#
# Build EXE
# Build the EXE by compiling the source files, then linking the resultant
# object files together.
#
$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj: $(TARGET_EXE_SOURCE) $(TARGET_EXE_INCLUDE)
$(CC) $(C_FLAGS) $(INC) $(TARGET_EXE_SOURCE) /Fo$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj : $(TARGET_SRC_DIR)\$(TARGET_NAME).c $(INC_DEPS)
$(CC) $(C_FLAGS) $(TARGET_SRC_DIR)\$(TARGET_NAME).c /Fo$@
#
# Add Binary Build description for this tool.
# Add Binary Build description for this tools.
#
!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
@ -82,14 +71,15 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
$(TARGET_EXE) : $(OBJECTS) $(LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -85,11 +85,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -101,6 +101,12 @@ typedef struct _SYMBOL {
INT8 *Value;
} SYMBOL;
typedef enum {
SearchCurrentDir,
SearchIncludePaths,
SearchAllPaths,
} FILE_SEARCH_TYPE;
//
// Here's all our globals. We need a linked list of include paths, a linked
// list of source files, a linked list of subdirectories (appended to each
@ -108,6 +114,7 @@ typedef struct _SYMBOL {
//
static struct {
STRING_LIST *IncludePaths; // all include paths to search
STRING_LIST *ParentPaths; // all parent paths to search
STRING_LIST *SourceFiles; // all source files to parse
STRING_LIST *SubDirs; // appended to each include path when searching
SYMBOL *SymbolTable; // for replacement strings
@ -120,25 +127,37 @@ static struct {
BOOLEAN NoDupes; // to not list duplicate dependency files (for timing purposes)
BOOLEAN UseSumDeps; // use summary dependency files if found
BOOLEAN IsAsm; // The SourceFiles are assembler files
BOOLEAN IsCl; // The SourceFiles are the output of cl with /showIncludes
INT8 TargetFileName[MAX_PATH]; // target object filename
INT8 SumDepsPath[MAX_PATH]; // path to summary files
INT8 TmpFileName[MAX_PATH]; // temp file name for output file
INT8 *OutFileName; // -o option
} mGlobals;
static
STATUS
ProcessFile (
INT8 *TargetFileName,
INT8 *FileName,
UINT32 NestDepth,
STRING_LIST *ProcessedFiles,
FILE_SEARCH_TYPE FileSearchType
);
static
STATUS
ProcessClOutput (
INT8 *TargetFileName,
INT8 *FileName,
UINT32 NestDepth,
STRING_LIST *ProcessedFiles
);
static
FILE *
FindFile (
INT8 *FileName,
UINT32 FileNameLen
INT8 *FileName,
UINT32 FileNameLen,
FILE_SEARCH_TYPE FileSearchType
);
static
@ -258,7 +277,12 @@ Returns:
strcpy (TargetFileName, mGlobals.TargetFileName);
}
Status = ProcessFile (TargetFileName, File->Str, START_NEST_DEPTH, &ProcessedFiles);
if (mGlobals.IsCl) {
Status = ProcessClOutput (TargetFileName, File->Str, &ProcessedFiles);
} else {
Status = ProcessFile (TargetFileName, File->Str, START_NEST_DEPTH,
&ProcessedFiles, SearchCurrentDir);
}
if (Status != STATUS_SUCCESS) {
goto Finish;
}
@ -282,7 +306,7 @@ Finish:
ProcessedFiles.Next = TempList;
}
//
// Close our output file
// Close our temp output file
//
if ((mGlobals.OutFptr != stdout) && (mGlobals.OutFptr != NULL)) {
fclose (mGlobals.OutFptr);
@ -291,12 +315,22 @@ Finish:
if (mGlobals.NeverFail) {
return STATUS_SUCCESS;
}
//
// If any errors, then delete our output so that it will get created
// again on a rebuild.
//
if ((GetUtilityStatus () == STATUS_ERROR) && (mGlobals.OutFileName != NULL)) {
remove (mGlobals.OutFileName);
if (mGlobals.OutFileName != NULL) {
if (GetUtilityStatus () == STATUS_ERROR) {
//
// If any errors, then delete our temp output
// Also try to delete target file to improve the incremental build
//
remove (mGlobals.TmpFileName);
remove (TargetFileName);
} else {
//
// Otherwise, rename temp file to output file
//
remove (mGlobals.OutFileName);
rename (mGlobals.TmpFileName, mGlobals.OutFileName);
}
}
return GetUtilityStatus ();
@ -305,10 +339,11 @@ Finish:
static
STATUS
ProcessFile (
INT8 *TargetFileName,
INT8 *FileName,
UINT32 NestDepth,
STRING_LIST *ProcessedFiles
INT8 *TargetFileName,
INT8 *FileName,
UINT32 NestDepth,
STRING_LIST *ProcessedFiles,
FILE_SEARCH_TYPE FileSearchType
)
/*++
@ -322,6 +357,7 @@ Arguments:
FileName - name of the file to process
NestDepth - how deep we're nested in includes
ProcessedFiles - list of processed files.
FileSearchType - search type for FileName
Returns:
@ -342,6 +378,7 @@ Returns:
UINT32 Index;
UINT32 LineNum;
STRING_LIST *ListPtr;
STRING_LIST ParentPath;
Status = STATUS_SUCCESS;
Fptr = NULL;
@ -380,37 +417,6 @@ Returns:
return STATUS_SUCCESS;
}
}
//
// If we're not doing duplicates, and we've already seen this filename,
// then return
//
if (mGlobals.NoDupes) {
for (ListPtr = ProcessedFiles->Next; ListPtr != NULL; ListPtr = ListPtr->Next) {
if (_stricmp (FileName, ListPtr->Str) == 0) {
break;
}
}
//
// If we found a match, we're done. If we didn't, create a new element
// and add it to the list.
//
if (ListPtr != NULL) {
//
// Print a message if verbose mode
//
if (mGlobals.Verbose) {
DebugMsg (NULL, 0, 0, FileName, "duplicate include -- not processed again");
}
return STATUS_SUCCESS;
}
ListPtr = malloc (sizeof (STRING_LIST));
ListPtr->Str = malloc (strlen (FileName) + 1);
strcpy (ListPtr->Str, FileName);
ListPtr->Next = ProcessedFiles->Next;
ProcessedFiles->Next = ListPtr;
}
//
// Make sure we didn't exceed our maximum nesting depth
@ -424,14 +430,20 @@ Returns:
// if we have to.
//
strcpy (FileNameCopy, FileName);
//
// Try to open the file locally
//
if ((Fptr = fopen (FileNameCopy, "r")) == NULL) {
if (FileSearchType == SearchCurrentDir) {
//
// Try to open the source file locally
//
if ((Fptr = fopen (FileNameCopy, "r")) == NULL) {
Error (NULL, 0, 0, FileNameCopy, "could not open source file");
return STATUS_ERROR;
}
} else {
//
// Try to find it among the paths.
//
Fptr = FindFile (FileNameCopy, sizeof (FileNameCopy));
Fptr = FindFile (FileNameCopy, sizeof (FileNameCopy), FileSearchType);
if (Fptr == NULL) {
//
// If this is not the top-level file, and the command-line argument
@ -457,11 +469,58 @@ Returns:
}
}
}
//
// If we're not doing duplicates, and we've already seen this filename,
// then return
//
if (mGlobals.NoDupes) {
for (ListPtr = ProcessedFiles->Next; ListPtr != NULL; ListPtr = ListPtr->Next) {
if (_stricmp (FileNameCopy, ListPtr->Str) == 0) {
break;
}
}
//
// If we found a match, we're done. If we didn't, create a new element
// and add it to the list.
//
if (ListPtr != NULL) {
//
// Print a message if verbose mode
//
if (mGlobals.Verbose) {
DebugMsg (NULL, 0, 0, FileNameCopy, "duplicate include -- not processed again");
}
fclose (Fptr);
return STATUS_SUCCESS;
}
ListPtr = malloc (sizeof (STRING_LIST));
ListPtr->Str = malloc (strlen (FileNameCopy) + 1);
strcpy (ListPtr->Str, FileNameCopy);
ListPtr->Next = ProcessedFiles->Next;
ProcessedFiles->Next = ListPtr;
}
//
// Print the dependency, with string substitution
//
PrintDependency (TargetFileName, FileNameCopy);
//
// Get the file path and push to ParentPaths
//
Cptr = FileNameCopy + strlen (FileNameCopy) - 1;
for (; (Cptr > FileNameCopy) && (*Cptr != '\\') && (*Cptr != '/'); Cptr--);
if ((*Cptr == '\\') || (*Cptr == '/')) {
*(Cptr + 1) = 0;
} else {
strcpy (FileNameCopy, ".\\");
}
ParentPath.Next = mGlobals.ParentPaths;
ParentPath.Str = FileNameCopy;
mGlobals.ParentPaths = &ParentPath;
//
// Now read in lines and find all #include lines. Allow them to indent, and
// to put spaces between the # and include.
@ -523,7 +582,8 @@ Returns:
// Null terminate the filename and try to process it.
//
*EndPtr = 0;
Status = ProcessFile (TargetFileName, Cptr, NestDepth + 1, ProcessedFiles);
Status = ProcessFile (TargetFileName, Cptr, NestDepth + 1,
ProcessedFiles, SearchAllPaths);
} else {
//
// Handle special #include MACRO_NAME(file)
@ -579,7 +639,8 @@ Returns:
//
// Process immediately, then break out of the outside FOR loop.
//
Status = ProcessFile (TargetFileName, MacroIncludeFileName, NestDepth + 1, ProcessedFiles);
Status = ProcessFile (TargetFileName, MacroIncludeFileName, NestDepth + 1,
ProcessedFiles, SearchAllPaths);
break;
}
}
@ -615,12 +676,20 @@ Returns:
//
// If we're processing it, do it
//
if ((EndChar != '>') || (!mGlobals.NoSystem)) {
if (EndChar != '>') {
//
// Null terminate the filename and try to process it.
//
*EndPtr = 0;
Status = ProcessFile (TargetFileName, Cptr, NestDepth + 1, ProcessedFiles);
Status = ProcessFile (TargetFileName, Cptr, NestDepth + 1,
ProcessedFiles, SearchAllPaths);
} else if (!mGlobals.NoSystem) {
//
// Null terminate the filename and try to process it.
//
*EndPtr = 0;
Status = ProcessFile (TargetFileName, Cptr, NestDepth + 1,
ProcessedFiles, SearchIncludePaths);
}
} else {
Warning (FileNameCopy, LineNum, 0, "malformed include", "missing closing %c", EndChar);
@ -631,6 +700,10 @@ Returns:
}
}
}
//
// Pop the file path from ParentPaths
//
mGlobals.ParentPaths = ParentPath.Next;
Finish:
//
@ -643,6 +716,120 @@ Finish:
return Status;
}
static
STATUS
ProcessClOutput (
INT8 *TargetFileName,
INT8 *FileName,
STRING_LIST *ProcessedFiles
)
/*++
Routine Description:
Given a source file name, open the file and parse all "Note: including file: xxx.h" lines.
Arguments:
TargetFileName - name of the usually .obj target
FileName - name of the file to process
ProcessedFiles - list of processed files.
Returns:
standard status.
--*/
{
FILE *Fptr;
INT8 Line[MAX_LINE_LEN];
INT8 IncludeFileName[MAX_LINE_LEN];
STRING_LIST *ListPtr;
BOOLEAN ClError;
INT32 Ret;
INT8 Char;
if ((Fptr = fopen (FileName, "r")) == NULL) {
Error (NULL, 0, 0, FileName, "could not open file for reading");
return STATUS_ERROR;
}
if (fgets (Line, sizeof (Line), Fptr) != NULL) {
//
// First line is the source file name, print it
//
printf ("%s", Line);
} else {
//
// No output from cl
//
fclose (Fptr);
Error (NULL, 0, 0, NULL, "incorrect cl tool path may be used ");
return STATUS_ERROR;
}
ClError = FALSE;
while (fgets (Line, sizeof (Line), Fptr) != NULL) {
Ret = sscanf (Line, "Note: including file: %s %c", IncludeFileName, &Char);
if (Ret == 2) {
//
// There is space in include file name. It's VS header file. Ignore it.
//
continue;
} else if ( Ret != 1) {
//
// Cl error info, print it
// the tool will return error code to stop the nmake
//
ClError = TRUE;
printf ("%s", Line);
continue;
}
//
// If we're not doing duplicates, and we've already seen this filename,
// then continue
//
if (mGlobals.NoDupes) {
for (ListPtr = ProcessedFiles->Next; ListPtr != NULL; ListPtr = ListPtr->Next) {
if (_stricmp (IncludeFileName, ListPtr->Str) == 0) {
break;
}
}
//
// If we found a match, we're done. If we didn't, create a new element
// and add it to the list.
//
if (ListPtr != NULL) {
//
// Print a message if verbose mode
//
if (mGlobals.Verbose) {
DebugMsg (NULL, 0, 0, IncludeFileName, "duplicate include -- not processed again");
}
continue;
}
ListPtr = malloc (sizeof (STRING_LIST));
ListPtr->Str = malloc (strlen (IncludeFileName) + 1);
strcpy (ListPtr->Str, IncludeFileName);
ListPtr->Next = ProcessedFiles->Next;
ProcessedFiles->Next = ListPtr;
}
PrintDependency (TargetFileName, IncludeFileName);
}
fclose (Fptr);
if (ClError) {
Error (NULL, 0, 0, NULL, "cl error");
return STATUS_ERROR;
} else {
return STATUS_SUCCESS;
}
}
static
void
PrintDependency (
@ -754,8 +941,9 @@ ReplaceSymbols (
static
FILE *
FindFile (
INT8 *FileName,
UINT32 FileNameLen
INT8 *FileName,
UINT32 FileNameLen,
FILE_SEARCH_TYPE FileSearchType
)
{
FILE *Fptr;
@ -766,6 +954,49 @@ FindFile (
//
// Traverse the list of paths and try to find the file
//
if (FileSearchType == SearchAllPaths) {
List = mGlobals.ParentPaths;
while (List != NULL) {
//
// Put the path and filename together
//
if (strlen (List->Str) + strlen (FileName) + 1 > sizeof (FullFileName)) {
Error (
__FILE__,
__LINE__,
0,
"application error",
"cannot concatenate '%s' + '%s'",
List->Str,
FileName
);
return NULL;
}
//
// Append the filename to this include path and try to open the file.
//
strcpy (FullFileName, List->Str);
strcat (FullFileName, FileName);
if ((Fptr = fopen (FullFileName, "r")) != NULL) {
//
// Return the file name
//
if (FileNameLen <= strlen (FullFileName)) {
Error (__FILE__, __LINE__, 0, "application error", "internal path name of insufficient length");
//
// fprintf (stdout, "File length > %d: %s\n", FileNameLen, FullFileName);
//
return NULL;
}
strcpy (FileName, FullFileName);
return Fptr;
}
List = List->Next;
}
}
List = mGlobals.IncludePaths;
while (List != NULL) {
//
@ -846,7 +1077,7 @@ ProcessArgs (
STRING_LIST *LastIncludePath;
STRING_LIST *LastSourceFile;
SYMBOL *Symbol;
int Index;
//
// Clear our globals
//
@ -957,50 +1188,7 @@ ProcessArgs (
Usage ();
return STATUS_ERROR;
}
//
// The C compiler first looks for #include files in the directory where
// the source file came from. Add the file's source directory to the
// list of include paths.
//
NewList = malloc (sizeof (STRING_LIST));
if (NewList == NULL) {
Error (__FILE__, __LINE__, 0, "memory allocation failure", NULL);
return STATUS_ERROR;
}
NewList->Next = NULL;
NewList->Str = malloc (strlen (Argv[1]) + 3);
if (NewList->Str == NULL) {
free (NewList);
Error (__FILE__, __LINE__, 0, "memory allocation failure", NULL);
return STATUS_ERROR;
}
strcpy (NewList->Str, Argv[1]);
//
// Back up in the source file name to the last backslash and terminate after it.
//
for (Index = strlen (NewList->Str) - 1; (Index > 0) && (NewList->Str[Index] != '\\'); Index--)
;
if (Index < 0) {
strcpy (NewList->Str, ".\\");
} else {
NewList->Str[Index + 1] = 0;
}
//
// Add it to the end of the our list of include paths
//
if (mGlobals.IncludePaths == NULL) {
mGlobals.IncludePaths = NewList;
} else {
LastIncludePath->Next = NewList;
}
if (mGlobals.Verbose) {
fprintf (stdout, "Adding include path: %s\n", NewList->Str);
}
LastIncludePath = NewList;
Argc--;
Argv++;
} else if (_stricmp (Argv[0], "-s") == 0) {
@ -1145,15 +1333,20 @@ ProcessArgs (
// check for one more arg
//
if (Argc > 1) {
mGlobals.OutFileName = Argv[1];
//
// Try to open the file
// Use temp file for output
// This can avoid overwriting previous existed dep file when error
// ocurred in this tool
//
if ((mGlobals.OutFptr = fopen (Argv[1], "w")) == NULL) {
Error (NULL, 0, 0, Argv[1], "could not open file for writing");
sprintf (mGlobals.TmpFileName, "%s2", mGlobals.OutFileName);
//
// Try to open the temp file
//
if ((mGlobals.OutFptr = fopen (mGlobals.TmpFileName, "w")) == NULL) {
Error (NULL, 0, 0, mGlobals.TmpFileName, "could not open file for writing");
return STATUS_ERROR;
}
mGlobals.OutFileName = Argv[1];
} else {
Error (NULL, 0, 0, Argv[0], "option requires output file name");
Usage ();
@ -1171,7 +1364,17 @@ ProcessArgs (
} else if (_stricmp (Argv[0], "-ignorenotfound") == 0) {
mGlobals.IgnoreNotFound = TRUE;
} else if (_stricmp (Argv[0], "-asm") == 0) {
if (mGlobals.IsCl) {
Error (NULL, 0, 0, Argv[0], "option conflict with -cl");
return STATUS_ERROR;
}
mGlobals.IsAsm = TRUE;
} else if (_stricmp (Argv[0], "-cl") == 0) {
if (mGlobals.IsAsm) {
Error (NULL, 0, 0, Argv[0], "option conflict with -asm");
return STATUS_ERROR;
}
mGlobals.IsCl = TRUE;
} else if ((_stricmp (Argv[0], "-h") == 0) || (strcmp (Argv[0], "-?") == 0)) {
Usage ();
return STATUS_ERROR;
@ -1306,7 +1509,8 @@ Returns:
// " -nodupes keep track of include files, don't rescan duplicates",
//
" -usesumdeps path use summary dependency files in 'path' directory.",
" -asm The SourceFile is assembler file",
" -asm The SourceFiles are assembler files",
" -cl The SourceFiles are the output of cl with /showIncludes",
"",
NULL
};

View File

@ -62,8 +62,10 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS) $(LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF

View File

@ -17,13 +17,6 @@
#
#--*/
#
# Everything depends on EDK_SOURCE. Make sure it's defined
#
!IFNDEF EDK_SOURCE
!ERROR EDK_SOURCE environmental variable not set
!ENDIF
#
# Define our toolchain before we include the master settings file
#
@ -42,25 +35,26 @@ MAKEFILES = $(EDK_TOOLS_SOURCE)\Common\Makefile \
$(EDK_TOOLS_SOURCE)\GenDepex\Makefile \
$(EDK_TOOLS_SOURCE)\GenFfsFile\Makefile \
$(EDK_TOOLS_SOURCE)\GenFvImage\Makefile \
$(EDK_TOOLS_SOURCE)\GenTEImage\makefile \
$(EDK_TOOLS_SOURCE)\FwImage\Makefile \
$(EDK_TOOLS_SOURCE)\ProcessDsc\makefile \
$(EDK_TOOLS_SOURCE)\GuidChk\makefile \
$(EDK_TOOLS_SOURCE)\MakeDeps\makefile \
$(EDK_TOOLS_SOURCE)\SetStamp\makefile \
!IF "$(EFI_SPECIFICATION_VERSION)" >= "0x0002000A"
$(EDK_TOOLS_SOURCE)\UefiVfrCompile\makefile \
$(EDK_TOOLS_SOURCE)\UefiStrGather\makefile \
!ELSE
$(EDK_TOOLS_SOURCE)\VfrCompile\makefile \
$(EDK_TOOLS_SOURCE)\StrGather\makefile \
$(EDK_TOOLS_SOURCE)\BootsectImage\Makefile \
$(EDK_TOOLS_SOURCE)\GenBootsector\Makefile \
$(EDK_TOOLS_SOURCE)\GenPage\Makefile \
!ENDIF
$(EDK_TOOLS_SOURCE)\SplitFile\Makefile \
$(EDK_TOOLS_SOURCE)\Strip\Makefile \
$(EDK_TOOLS_SOURCE)\EfiCompress\Makefile \
$(EDK_TOOLS_SOURCE)\EfildrImage\Makefile \
$(EDK_TOOLS_SOURCE)\EfiRom\Makefile \
$(EDK_TOOLS_SOURCE)\GenAprioriFile\Makefile \
$(EDK_TOOLS_SOURCE)\ModifyInf\Makefile
#
# Define default all target which calls all our makefiles. The special
# bang (!) tells nmake to do the command for each out-of-date dependent.

View File

@ -72,11 +72,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -89,11 +89,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS) $(LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -554,6 +554,12 @@ AddModuleName (
INT8 *InfName
);
static
void
ReplaceSlash (
INT8 *Path
);
/*****************************************************************************/
int
main (
@ -1032,10 +1038,11 @@ Returns:
// added local symbols
//
ExpandSymbols (ArgLine, Line, sizeof (Line), EXPANDMODE_NO_UNDEFS);
//
// If we have "c:\path\filename"
//
ReplaceSlash (Line);
if (IsAbsolutePath (Line)) {
ComponentFilePathAbsolute = 1;
} else if (Line[0] == '.') {
@ -1054,7 +1061,7 @@ Returns:
//
strcpy (ComponentFilePath, Line);
Cptr = ComponentFilePath + strlen (ComponentFilePath) - 1;
while ((*Cptr != '\\') && (*Cptr != '/') && (Cptr != ComponentFilePath)) {
while ((*Cptr != '\\') && (Cptr != ComponentFilePath)) {
Cptr--;
}
//
@ -1239,7 +1246,8 @@ Returns:
// They may have defined DEST_DIR on the component INF line, so it's already
// been defined, If that's the case, then don't set it to the path of this file.
//
if (GetSymbolValue (DEST_DIR) == NULL) {
TempCptr = GetSymbolValue (DEST_DIR);
if (TempCptr == NULL) {
if (ComponentFilePathAbsolute == 0) {
//
// The destination path is $(BUILD_DIR)\$(PROCESSOR)\component_path
@ -1264,6 +1272,8 @@ Returns:
);
}
AddSymbol (DEST_DIR, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILEPATH);
} else {
ReplaceSlash (TempCptr);
}
//
@ -1818,6 +1828,7 @@ Returns:
//
OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);
if (OverridePath != NULL) {
ReplaceSlash (OverridePath);
fprintf (MakeFptr, "INC = $(INC) -I %s\n", OverridePath);
fprintf (MakeFptr, "INC = $(INC) -I %s\\%s \n", OverridePath, Processor);
}
@ -1881,6 +1892,7 @@ ProcessIncludesSectionSingle (
// Don't process blank lines
//
if (*Cptr) {
ReplaceSlash (Cptr);
//
// Strip off trailing slash
//
@ -2150,6 +2162,7 @@ ProcessSourceFilesSection (
//
ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);
AddFileSymbols (FileName);
ReplaceSlash (FileName);
//
// Set the SOURCE_FILE_NAME symbol. What we have now is the name of
// the file, relative to the location of the INF file. So prepend
@ -2197,6 +2210,7 @@ ProcessSourceFilesSection (
OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);
}
if (OverridePath != NULL) {
ReplaceSlash (OverridePath);
//
// See if the file exists. If it does, reset the SOURCE_FILE_NAME symbol.
//
@ -2490,6 +2504,7 @@ ProcessObjectsSingle (
//
if (!IsIncludeFile (Cptr)) {
ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);
ReplaceSlash (FileName);
Cptr2 = BuiltFileExtension (FileName);
if (Cptr2 != NULL) {
SetFileExtension (FileName, Cptr2);
@ -2731,8 +2746,10 @@ ProcessIncludeFilesSingle (
//
ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);
AddFileSymbols (FileName);
ReplaceSlash (FileName);
if (IsIncludeFile (FileName)) {
if ((OverridePath != NULL) && (!IsAbsolutePath (FileName))) {
ReplaceSlash (OverridePath);
strcpy (TempFileName, OverridePath);
strcat (TempFileName, "\\");
strcat (TempFileName, FileName);
@ -2743,7 +2760,7 @@ ProcessIncludeFilesSingle (
// to the beginning of the list of include paths.
//
for (Cptr = TempFileName + strlen (TempFileName) - 1;
(Cptr >= TempFileName) && (*Cptr != '\\') && (*Cptr != '/');
(Cptr >= TempFileName) && (*Cptr != '\\');
Cptr--
)
;
@ -2848,9 +2865,9 @@ GetFileParts (
FP->Extension[0] = 0;
}
//
// Now back up and get the base name (include the preceding '\' or '/')
// Now back up and get the base name (include the preceding '\')
//
for (; (Cptr > FileNamePtr) && (*Cptr != '\\') && (*Cptr != '/'); Cptr--)
for (; (Cptr > FileNamePtr) && (*Cptr != '\\'); Cptr--)
;
FP->BaseName = (char *) malloc (strlen (Cptr) + 1);
strcpy (FP->BaseName, Cptr);
@ -3329,7 +3346,7 @@ MakeFilePath (
}
for (;;) {
for (; *Cptr && (*Cptr != '/') && (*Cptr != '\\'); Cptr++)
for (; *Cptr && (*Cptr != '\\'); Cptr++)
;
if (*Cptr) {
SavedChar = *Cptr;
@ -4204,6 +4221,7 @@ Returns:
FreeCwd = 1;
AddSymbol (BUILD_DIR, Cptr, SYM_OVERWRITE | SYM_GLOBAL | SYM_FILEPATH);
} else {
ReplaceSlash (Cptr);
FreeCwd = 0;
}
@ -4359,6 +4377,7 @@ GetEfiSource (
//
EfiSource = GetSymbolValue (EFI_SOURCE);
if ( EfiSource != NULL) {
ReplaceSlash (EfiSource);
if (EfiSource[strlen (EfiSource) - 1] == '\\') {
EfiSource[strlen (EfiSource) - 1] = 0;
}
@ -4370,6 +4389,7 @@ GetEfiSource (
//
EfiSource = getenv (EFI_SOURCE);
if (EfiSource != NULL) {
ReplaceSlash (EfiSource);
if (EfiSource[strlen (EfiSource) - 1] == '\\') {
EfiSource[strlen (EfiSource) - 1] = 0;
}
@ -4724,3 +4744,26 @@ Returns:
return 0;
}
static
void
ReplaceSlash (
INT8 *Path
)
/*++
Routine Description:
Replace '/' with '\\'
Returns:
--*/
{
while (*Path) {
if (*Path == '/') {
*Path = '\\';
}
Path++;
}
}

View File

@ -78,11 +78,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).*

View File

@ -84,11 +84,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -79,11 +79,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS) $(LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:

View File

@ -1,5 +1,5 @@
#/*++
#
#
# Copyright (c) 2006 - 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -8,16 +8,14 @@
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# Makefile
#
#
# Module Name: makefile
#
# Abstract:
#
# makefile for building the EfildrImage utility.
#
#--*/
#
# This file is used to build the Strip utility.
#
#--*/
#
# Make sure environmental variable EDK_SOURCE is set
@ -51,15 +49,14 @@ INC=$(INC)
# Target specific information
#
TARGET_NAME=EfildrImage
TARGET_NAME=Strip
TARGET_SOURCE_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
TARGET_EXE = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).exe
TARGET_EXE_SOURCE = "$(TARGET_SOURCE_DIR)\EfildrImage.c"
TARGET_EXE_SOURCE = "$(TARGET_SOURCE_DIR)\Strip.c"
TARGET_EXE_INCLUDE =
#
# Build targets
#
@ -74,7 +71,7 @@ $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj: $(TARGET_EXE_SOURCE) $(TARGET_EXE_INCLUD
$(CC) $(C_FLAGS) $(INC) $(TARGET_EXE_SOURCE) /Fo$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
#
# Add Binary Build description for this tool.
# Add Binary Build description for this tools.
#
!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
@ -83,14 +80,15 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_EXE_LIBS) $(TARGET_DLL)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(TARGET_LIB) $(TARGET_EXE_LIBS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -0,0 +1,104 @@
/*++
Copyright 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Strip.c
Abstract:
Quick Exe2Bin equivalent.
--*/
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <malloc.h>
int
main (
int argc,
char *argv[]
)
/*++
Routine Description:
Converts executable files to binary files.
Arguments:
argc - Number of command line arguments
argv[] - Array of pointers to the command line arguments
Returns:
Zero - Function completed successfully.
Non-zero - Function exited with errors.
--*/
{
FILE *InFile;
FILE *OutFile;
int Index;
int FileSize;
char *Buffer;
char *Ptrx;
if (argc < 3) {
printf ("Need more args, such as file name to convert and output name\n");
return -1;
}
InFile = fopen (argv[1], "rb");
OutFile = fopen (argv[2], "wb");
if (!InFile) {
printf ("no file, exit\n");
return -1;
}
if (OutFile == NULL) {
printf ("Unable to open output file.\n");
return -1;
}
fseek (InFile, 0, SEEK_END);
FileSize = ftell (InFile);
if (FileSize < 0x200) {
printf ("%d is not a legal size, exit\n", FileSize);
return -1;
}
fseek (InFile, 0, SEEK_SET);
Buffer = malloc (FileSize);
if (Buffer == NULL) {
printf ("Error: Out of resources.\n");
return -1;
}
fread (Buffer, 1, FileSize, InFile);
Ptrx = Buffer + 0x200;
Index = FileSize - 0x200;
fwrite (Ptrx, Index, 1, OutFile);
fclose (InFile);
fclose (OutFile);
free (Buffer);
return 0;
}

View File

@ -1,6 +1,6 @@
#/*++
#
# Copyright (c) 2006 - 2007, Intel Corporation
# Copyright (c) 2004 - 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@ -15,7 +15,7 @@
#
# Abstract:
#
# makefile for building the BootsectImage utility.
# makefile for building the StrGather utility.
#
#--*/
@ -35,31 +35,12 @@ TOOLCHAIN = TOOLCHAIN_MSVC
!INCLUDE $(BUILD_DIR)\PlatformTools.env
#
# Define some macros we use here. Should get rid of them someday and
# get rid of the extra level of indirection.
#
COMMON_SOURCE = $(EDK_TOOLS_COMMON)
#
# Common information
#
INC=$(INC)
#
# Target specific information
#
TARGET_NAME=BootsectImage
TARGET_SOURCE_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
TARGET_EXE = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).exe
TARGET_EXE_SOURCE = "$(TARGET_SOURCE_DIR)\BootsectImage.c"
TARGET_EXE_INCLUDE = "$(TARGET_SOURCE_DIR)\fat.h" \
"$(TARGET_SOURCE_DIR)\mbr.h" \
TARGET_NAME = StrGather
TARGET_SRC_DIR = $(EDK_TOOLS_SOURCE)\Uefi$(TARGET_NAME)
TARGET_EXE = $(EDK_TOOLS_OUTPUT)\StrGather.exe
#
# Build targets
@ -67,15 +48,39 @@ TARGET_EXE_INCLUDE = "$(TARGET_SOURCE_DIR)\fat.h" \
all: $(TARGET_EXE)
#
# Build EXE
#
$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj: $(TARGET_EXE_SOURCE) $(TARGET_EXE_INCLUDE)
$(CC) $(C_FLAGS) $(INC) $(TARGET_EXE_SOURCE) /Fo$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
LIBS = "$(EDK_TOOLS_OUTPUT)\Common.lib"
OBJECTS = $(EDK_TOOLS_OUTPUT)\StrGather.obj \
$(EDK_TOOLS_OUTPUT)\StringDB.obj
INC_PATHS = -I $(TARGET_SRC_DIR) \
-I $(EDK_SOURCE)\Foundation\Include\Ia32 \
-I $(EDK_SOURCE)\Foundation\Efi\Include \
-I $(EDK_SOURCE)\Foundation\Framework\Include \
-I $(EDK_SOURCE)\Foundation\Include\IndustryStandard \
-I $(EDK_SOURCE)\Foundation\ \
-I $(EDK_SOURCE)\Foundation\Core\Dxe \
-I $(EDK_SOURCE)\Foundation\Efi \
-I $(EDK_SOURCE)\Foundation\Framework \
-I $(EDK_TOOLS_SOURCE)\Common \
-I $(EDK_SOURCE)\Foundation\Include
INC_DEPS = $(TARGET_SRC_DIR)\StrGather.h $(TARGET_SRC_DIR)\StringDB.h
C_FLAGS = $(C_FLAGS) /W4
#
# Add Binary Build description for this tool.
# Compile each source file
#
$(EDK_TOOLS_OUTPUT)\StrGather.obj : $(TARGET_SRC_DIR)\StrGather.c $(INC_DEPS)
$(CC) $(C_FLAGS) $(INC_PATHS) $(TARGET_SRC_DIR)\StrGather.c /Fo$@
$(EDK_TOOLS_OUTPUT)\StringDB.obj : $(TARGET_SRC_DIR)\StringDB.c $(INC_DEPS)
$(CC) $(C_FLAGS) $(INC_PATHS) $(TARGET_SRC_DIR)\StringDB.c /Fo$@
#
# Add Binary Build description for this tools.
#
!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
@ -84,14 +89,15 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
!ELSE
$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj $(EDK_TOOLS_OUTPUT)\Common.lib
$(LINK) $(MSVS_LINK_LIBPATHS) $(EDK_TOOLS_OUTPUT)\Common.lib $(L_FLAGS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
$(TARGET_EXE) : $(OBJECTS) $(LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,87 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
StrGather.h
Abstract:
Common defines and prototypes for StrGather.
--*/
#ifndef _STR_GATHER_H_
#define _STR_GATHER_H_
#define MALLOC(size) malloc (size)
#define FREE(ptr) do { if ((ptr) != NULL) { free (ptr); } } while (0)
#define PROGRAM_NAME "StrGather"
typedef CHAR16 WCHAR;
#define UNICODE_TO_ASCII(w) (INT8) ((w) & 0xFF)
#define ASCII_TO_UNICODE(a) (WCHAR) ((UINT8) (a))
#define UNICODE_HASH L'#'
#define UNICODE_BACKSLASH L'\\'
#define UNICODE_SLASH L'/'
#define UNICODE_EQUAL_SIGN L'='
#define UNICODE_PLUS_SIGN L'+'
#define UNICODE_FILE_START 0xFEFF
#define UNICODE_CR 0x000D
#define UNICODE_LF 0x000A
#define UNICODE_NULL 0x0000
#define UNICODE_SPACE L' '
#define UNICODE_SLASH L'/'
#define UNICODE_DOUBLE_QUOTE L'"'
#define UNICODE_OPEN_PAREN L'('
#define UNICODE_CLOSE_PAREN L')'
#define UNICODE_Z L'Z'
#define UNICODE_z L'z'
#define UNICODE_A L'A'
#define UNICODE_a L'a'
#define UNICODE_F L'F'
#define UNICODE_f L'f'
#define UNICODE_UNDERSCORE L'_'
#define UNICODE_MINUS L'-'
#define UNICODE_0 L'0'
#define UNICODE_9 L'9'
#define UNICODE_TAB L'\t'
#define UNICODE_NBR_STRING L"\\nbr"
#define UNICODE_BR_STRING L"\\br"
#define UNICODE_WIDE_STRING L"\\wide"
#define UNICODE_NARROW_STRING L"\\narrow"
//
// This is the length of a valid string identifier
//
#define LANGUAGE_IDENTIFIER_NAME_LEN 128
typedef struct _TEXT_STRING_LIST {
struct _TEXT_STRING_LIST *Next;
UINT8 *Str;
} TEXT_STRING_LIST;
typedef struct _WCHAR_STRING_LIST {
struct _WCHAR_STRING_LIST *Next;
WCHAR *Str;
} WCHAR_STRING_LIST;
typedef struct _WCHAR_MATCHING_STRING_LIST {
struct _WCHAR_MATCHING_STRING_LIST *Next;
WCHAR *Str1;
WCHAR *Str2;
} WCHAR_MATCHING_STRING_LIST;
#endif // #ifndef _STR_GATHER_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,254 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
StringDB.h
Abstract:
Common defines and prototypes for string database management
--*/
#ifndef _STRING_DB_H_
#define _STRING_DB_H_
#define LANGUAGE_NAME_STRING_NAME L"$LANGUAGE_NAME"
#define PRINTABLE_LANGUAGE_NAME_STRING_NAME L"$PRINTABLE_LANGUAGE_NAME"
typedef CHAR16 WCHAR;
#define NARROW_CHAR 0xFFF0
#define WIDE_CHAR 0xFFF1
#define NON_BREAKING_CHAR 0xFFF2
#define GLYPH_WIDTH 8
#define GLYPH_HEIGHT 19
#define STRING_DB_KEY (('S' << 24) | ('D' << 16) | ('B' << 8) | 'K')
//
// Version supported by this tool
//
#define STRING_DB_VERSION 0x00010000
#define STRING_DB_MAJOR_VERSION_MASK 0xFFFF0000
#define STRING_DB_MINOR_VERSION_MASK 0x0000FFFF
#define DEFINE_STR L"// #define"
#define EFI_STRING_ID_BEGIN 0x01
//
// This is the header that gets written to the top of the
// output binary database file.
//
typedef struct {
UINT32 Key;
UINT32 HeaderSize;
UINT32 Version;
UINT32 NumStringIdenfiers;
UINT32 StringIdentifiersSize;
UINT32 NumLanguages;
} STRING_DB_HEADER;
//
// When we write out data to the database, we have a UINT16 identifier, which
// indicates what follows, followed by the data. Here's the structure.
//
typedef struct {
UINT16 DataType;
UINT16 Reserved;
} DB_DATA_ITEM_HEADER;
#define DB_DATA_TYPE_INVALID 0x0000
#define DB_DATA_TYPE_STRING_IDENTIFIER 0x0001
#define DB_DATA_TYPE_LANGUAGE_DEFINITION 0x0002
#define DB_DATA_TYPE_STRING_DEFINITION 0x0003
#define DB_DATA_TYPE_LAST DB_DATA_TYPE_STRING_DEFINITION
//
// We have to keep track of a list of languages, each of which has its own
// list of strings. Define a structure to keep track of all languages and
// their list of strings.
//
typedef struct _STRING_LIST {
struct _STRING_LIST *Next;
UINT32 Size; // number of bytes in string, including null terminator
WCHAR *LanguageName;
WCHAR *StringName; // for example STR_ID_TEXT1
WCHAR *Scope; //
WCHAR *Str; // the actual string
UINT16 Flags; // properties of this string (used, undefined)
} STRING_LIST;
typedef struct _LANGUAGE_LIST {
struct _LANGUAGE_LIST *Next;
WCHAR *LanguageName;
WCHAR *PrintableLanguageName;
WCHAR *SecondaryLanguageList;
STRING_LIST *String;
STRING_LIST *LastString;
} LANGUAGE_LIST;
//
// We also keep track of all the string identifier names, which we assign unique
// values to. Create a structure to keep track of them all.
//
typedef struct _STRING_IDENTIFIER {
struct _STRING_IDENTIFIER *Next;
UINT32 Index; // only need 16 bits, but makes it easier with UINT32
WCHAR *StringName;
UINT16 Flags; // if someone referenced it via STRING_TOKEN()
} STRING_IDENTIFIER;
//
// Keep our globals in this structure to be as modular as possible.
//
typedef struct {
FILE *StringDBFptr;
LANGUAGE_LIST *LanguageList;
LANGUAGE_LIST *LastLanguageList;
LANGUAGE_LIST *CurrentLanguage; // keep track of the last language they used
STRING_IDENTIFIER *StringIdentifier;
STRING_IDENTIFIER *LastStringIdentifier;
UINT8 *StringDBFileName;
UINT32 NumStringIdentifiers;
UINT32 NumStringIdentifiersReferenced;
STRING_IDENTIFIER *CurrentStringIdentifier; // keep track of the last string identifier they added
WCHAR *CurrentScope;
} STRING_DB_DATA;
typedef struct _SPkgBlkBuffer {
UINT32 mBlkSize;
VOID *mBlkBuffer;
struct _SPkgBlkBuffer *mNext;
} SPkgBlkBuffer;
void
StringDBConstructor (
void
)
;
void
StringDBDestructor (
void
)
;
STATUS
StringDBAddString (
WCHAR *LanguageName,
WCHAR *StringIdentifier,
WCHAR *Scope,
WCHAR *String,
BOOLEAN Format,
UINT16 Flags
)
;
STATUS
StringDBSetScope (
WCHAR *Scope
)
;
#define STRING_FLAGS_REFERENCED 0x0001 // if referenced somewhere
#define STRING_FLAGS_UNDEFINED 0x0002 // if we added it for padding purposes
#define STRING_FLAGS_INDEX_ASSIGNED 0x0004 // so don't change the index value
#define STRING_ID_INVALID 0xFFFF
#define STRING_ID_LANGUAGE_NAME 0x0000
#define STRING_ID_PRINTABLE_LANGUAGE_NAME 0x0001
STATUS
StringDBAddStringIdentifier (
WCHAR *StringIdentifier,
UINT16 *NewId,
UINT16 Flags
)
;
STATUS
StringDBReadDatabase (
INT8 *DBFileName,
BOOLEAN IgnoreIfNotExist,
BOOLEAN Verbose
)
;
STATUS
StringDBWriteDatabase (
INT8 *DBFileName,
BOOLEAN Verbose
)
;
STATUS
StringDBDumpDatabase (
INT8 *DBFileName,
INT8 *OutputFileName,
BOOLEAN Verbose
)
;
STATUS
StringDBAddLanguage (
WCHAR *LanguageName,
WCHAR *PrintableLanguageName,
WCHAR *SecondaryLanguageList
)
;
STATUS
StringDBAddSecondaryLanguage (
WCHAR *LanguageName,
WCHAR *SecondaryLanguageList
)
;
STATUS
StringDBDumpCStrings (
INT8 *BaseName,
INT8 *FileName
)
;
STATUS
StringDBDumpStringDefines (
INT8 *FileName,
INT8 *BaseName
)
;
STATUS
StringDBSetCurrentLanguage (
WCHAR *LanguageName
)
;
STATUS
StringDBSetStringReferenced (
INT8 *StringIdentifierName,
BOOLEAN IgnoreNotFound
)
;
void
StringDBFormatString (
WCHAR *String
)
;
LANGUAGE_LIST *
StringDBFindLanguageList (
WCHAR *LanguageName
)
;
#endif // #ifndef _STRING_DB_H_

View File

@ -0,0 +1,53 @@
/*++
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiVfr.h
Abstract:
Defines and prototypes for the UEFI VFR compiler internal use.
--*/
#ifndef _EFIVFR_H_
#define _EFIVFR_H_
#include "Tiano.h"
#include "TianoHii.h"
#define MAX_PATH 255
#define MAX_LINE_LEN 4096
#define EFI_IFR_MAX_LENGTH 0xFF
#define EFI_VARSTORE_ID_INVALID 0
#define EFI_VAROFFSET_INVALID 0xFFFF
#define EFI_VARSTORE_ID_START 0x20
#define EFI_STRING_ID_INVALID 0x0
#define EFI_IMAGE_ID_INVALID 0xFFFF
typedef enum {
QUESTION_NORMAL,
QUESTION_DATE,
QUESTION_TIME,
} EFI_QUESION_TYPE;
typedef enum {
EQUAL,
LESS_EQUAL,
LESS_THAN,
GREATER_THAN,
GREATER_EQUAL
} EFI_COMPARE_TYPE;
#endif

View File

@ -0,0 +1,594 @@
#include "stdio.h"
#include "string.h"
#include "process.h"
#include "VfrCompiler.h"
VOID
CVfrCompiler::SET_RUN_STATUS (
IN COMPILER_RUN_STATUS Status
)
{
mRunStatus = Status;
}
BOOLEAN
CVfrCompiler::IS_RUN_STATUS (
IN COMPILER_RUN_STATUS Status
)
{
return mRunStatus == Status;
}
VOID
CVfrCompiler::OptionInitialization (
IN INT32 Argc,
IN INT8 **Argv
)
{
INT32 Index;
mOptions.VfrFileName[0] = '\0';
mOptions.RecordListFile[0] = '\0';
mOptions.CreateRecordListFile = FALSE;
mOptions.CreateIfrPkgFile = FALSE;
mOptions.PkgOutputFileName[0] = '\0';
mOptions.COutputFileName[0] = '\0';
mOptions.OutputDirectory[0] = '\0';
mOptions.PreprocessorOutputFileName[0] = '\0';
mOptions.VfrBaseFileName[0] = '\0';
mOptions.IncludePaths = NULL;
mOptions.CPreprocessorOptions = NULL;
for (Index = 1; (Index < Argc) && (Argv[Index][0] == '-'); Index++) {
if ((_stricmp(Argv[Index], "-?") == 0) || (_stricmp(Argv[Index], "-h") == 0)) {
Usage ();
SET_RUN_STATUS (STATUS_DEAD);
return;
} else if (_stricmp(Argv[Index], "-l") == 0) {
mOptions.CreateRecordListFile = TRUE;
gCIfrRecordInfoDB.TurnOn ();
} else if (_stricmp(Argv[Index], "-i") == 0) {
Index++;
if ((Index >= Argc) || (Argv[Index][0] == '-')) {
printf ("%s -i - missing path argument\n", PROGRAM_NAME);
goto Fail;
}
AppendIncludePath(Argv[Index]);
} else if (_stricmp(Argv[Index], "-od") == 0) {
Index++;
if ((Index >= Argc) || (Argv[Index][0] == '-')) {
printf ("%s -od - missing output directory name\n", PROGRAM_NAME);
goto Fail;
}
strcpy (mOptions.OutputDirectory, Argv[Index]);
} else if (_stricmp(Argv[Index], "-ibin") == 0) {
mOptions.CreateIfrPkgFile = TRUE;
} else if (_stricmp(Argv[Index], "-nostrings") == 0) {
} else if (_stricmp(Argv[Index], "-ppflag") == 0) {
Index++;
if ((Index >= Argc) || (Argv[Index][0] == '-')) {
printf ("%s -od - missing C-preprocessor argument\n", PROGRAM_NAME);
goto Fail;
}
AppendCPreprocessorOptions (Argv[Index]);
} else {
printf ("%s unrecognized option %s\n", PROGRAM_NAME, Argv[Index]);
Usage ();
goto Fail;
}
}
if (Index != Argc - 1) {
printf ("%s must specify VFR file name", PROGRAM_NAME);
Usage ();
goto Fail;
} else {
strcpy (mOptions.VfrFileName, Argv[Index]);
}
if (SetBaseFileName() != 0) {
goto Fail;
}
if (SetPkgOutputFileName () != 0) {
goto Fail;
}
if (SetCOutputFileName() != 0) {
goto Fail;
}
if (SetPreprocessorOutputFileName () != 0) {
goto Fail;
}
if (SetRecordListFileName () != 0) {
goto Fail;
}
return;
Fail:
SET_RUN_STATUS (STATUS_FAILED);
mOptions.VfrFileName[0] = '\0';
mOptions.RecordListFile[0] = '\0';
mOptions.CreateRecordListFile = FALSE;
mOptions.CreateIfrPkgFile = FALSE;
mOptions.PkgOutputFileName[0] = '\0';
mOptions.COutputFileName[0] = '\0';
mOptions.OutputDirectory[0] = '\0';
mOptions.PreprocessorOutputFileName[0] = '\0';
mOptions.VfrBaseFileName[0] = '\0';
if (mOptions.IncludePaths != NULL) {
delete mOptions.IncludePaths;
mOptions.IncludePaths = NULL;
}
if (mOptions.CPreprocessorOptions != NULL) {
delete mOptions.CPreprocessorOptions;
mOptions.CPreprocessorOptions = NULL;
}
}
VOID
CVfrCompiler::AppendIncludePath (
IN INT8 *PathStr
)
{
UINT32 Len = 0;
INT8 *IncludePaths = NULL;
Len = strlen (" -I ") + strlen (PathStr) + 1;
if (mOptions.IncludePaths != NULL) {
Len += strlen (mOptions.IncludePaths);
}
IncludePaths = new INT8[Len];
if (IncludePaths == NULL) {
printf ("%s memory allocation failure\n", PROGRAM_NAME);
return;
}
IncludePaths[0] = '\0';
if (mOptions.IncludePaths != NULL) {
strcat (IncludePaths, mOptions.IncludePaths);
}
strcat (IncludePaths, " -I ");
strcat (IncludePaths, PathStr);
if (mOptions.IncludePaths != NULL) {
delete mOptions.IncludePaths;
}
mOptions.IncludePaths = IncludePaths;
}
VOID
CVfrCompiler::AppendCPreprocessorOptions (
IN INT8 *Options
)
{
UINT32 Len = 0;
INT8 *Opt = NULL;
Len = strlen (Options) + strlen (" ") + 1;
if (mOptions.CPreprocessorOptions != NULL) {
Len += strlen (mOptions.CPreprocessorOptions);
}
Opt = new INT8[Len];
if (Opt == NULL) {
printf ("%s memory allocation failure\n", PROGRAM_NAME);
return;
}
Opt[0] = 0;
if (mOptions.CPreprocessorOptions != NULL) {
strcat (Opt, mOptions.CPreprocessorOptions);
}
strcat (Opt, " ");
strcat (Opt, Options);
if (mOptions.CPreprocessorOptions != NULL) {
delete mOptions.CPreprocessorOptions;
}
mOptions.CPreprocessorOptions = Opt;
}
INT8
CVfrCompiler::SetBaseFileName (
VOID
)
{
INT8 *pFileName, *pPath, *pExt;
if (mOptions.VfrFileName[0] == '\0') {
return -1;
}
pFileName = mOptions.VfrFileName;
while ((pPath = strchr (pFileName, '\\')) != NULL) {
pFileName = pPath + 1;
}
if (pFileName == NULL) {
return -1;
}
if ((pExt = strchr (pFileName, '.')) == NULL) {
return -1;
}
strncpy (mOptions.VfrBaseFileName, pFileName, pExt - pFileName);
mOptions.VfrBaseFileName[pExt - pFileName] = '\0';
return 0;
}
INT8
CVfrCompiler::SetPkgOutputFileName (
VOID
)
{
if (mOptions.VfrBaseFileName[0] == '\0') {
return -1;
}
strcpy (mOptions.PkgOutputFileName, mOptions.OutputDirectory);
strcat (mOptions.PkgOutputFileName, mOptions.VfrBaseFileName);
strcat (mOptions.PkgOutputFileName, VFR_PACKAGE_FILENAME_EXTENSION);
return 0;
}
INT8
CVfrCompiler::SetCOutputFileName (
VOID
)
{
if (mOptions.VfrBaseFileName[0] == '\0') {
return -1;
}
strcpy (mOptions.COutputFileName, mOptions.OutputDirectory);
strcat (mOptions.COutputFileName, mOptions.VfrBaseFileName);
strcat (mOptions.COutputFileName, ".c");
return 0;
}
INT8
CVfrCompiler::SetPreprocessorOutputFileName (
VOID
)
{
if (mOptions.VfrBaseFileName[0] == '\0') {
return -1;
}
strcpy (mOptions.PreprocessorOutputFileName, mOptions.OutputDirectory);
strcat (mOptions.PreprocessorOutputFileName, mOptions.VfrBaseFileName);
strcat (mOptions.PreprocessorOutputFileName, VFR_PREPROCESS_FILENAME_EXTENSION);
return 0;
}
INT8
CVfrCompiler::SetRecordListFileName (
VOID
)
{
if (mOptions.VfrBaseFileName[0] == '\0') {
return -1;
}
strcpy (mOptions.RecordListFile, mOptions.OutputDirectory);
strcat (mOptions.RecordListFile, mOptions.VfrBaseFileName);
strcat (mOptions.RecordListFile, VFR_RECORDLIST_FILENAME_EXTENSION);
return 0;
}
CVfrCompiler::CVfrCompiler (
IN INT32 Argc,
IN INT8 **Argv
)
{
mPreProcessCmd = PREPROCESSOR_COMMAND;
mPreProcessOpt = PREPROCESSOR_OPTIONS;
OptionInitialization(Argc, Argv);
if ((IS_RUN_STATUS(STATUS_FAILED)) || (IS_RUN_STATUS(STATUS_DEAD))) {
return;
}
SET_RUN_STATUS(STATUS_INITIALIZED);
}
CVfrCompiler::~CVfrCompiler (
VOID
)
{
if (mOptions.IncludePaths != NULL) {
delete mOptions.IncludePaths;
mOptions.IncludePaths = NULL;
}
if (mOptions.CPreprocessorOptions != NULL) {
delete mOptions.CPreprocessorOptions;
mOptions.CPreprocessorOptions = NULL;
}
SET_RUN_STATUS(STATUS_DEAD);
}
VOID
CVfrCompiler::Usage (
VOID
)
{
UINT32 Index;
CONST INT8 *Help[] = {
" ",
"VfrCompile version " VFR_COMPILER_VERSION,
" ",
" Usage: VfrCompile {options} [VfrFile]",
" ",
" where options include:",
" -? or -h prints this help",
" -l create an output IFR listing file",
" -i IncPath add IncPath to the search path for VFR included files",
" -od OutputDir deposit all output files to directory OutputDir (default=cwd)",
" -ibin create an IFR HII pack file"
" -ppflag C-preprocessor argument",
" where parameters include:",
" VfrFile name of the input VFR script file",
" ",
NULL
};
for (Index = 0; Help[Index] != NULL; Index++) {
fprintf (stdout, "%s\n", Help[Index]);
}
}
VOID
CVfrCompiler::PreProcess (
VOID
)
{
FILE *pVfrFile = NULL;
UINT32 CmdLen = 0;
INT8 *PreProcessCmd = NULL;
if (!IS_RUN_STATUS(STATUS_INITIALIZED)) {
goto Fail;
}
if ((pVfrFile = fopen (mOptions.VfrFileName, "r")) == NULL) {
printf ("%s could not open input VFR file - %s\n", PROGRAM_NAME, mOptions.VfrFileName);
goto Fail;
}
fclose (pVfrFile);
CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) +
strlen (mOptions.VfrFileName) + strlen (mOptions.PreprocessorOutputFileName);
if (mOptions.CPreprocessorOptions != NULL) {
CmdLen += strlen (mOptions.CPreprocessorOptions);
}
if (mOptions.IncludePaths != NULL) {
CmdLen += strlen (mOptions.IncludePaths);
}
PreProcessCmd = new INT8[CmdLen + 10];
if (PreProcessCmd == NULL) {
printf ("%s could not allocate memory\n", PROGRAM_NAME);
goto Fail;
}
strcpy (PreProcessCmd, mPreProcessCmd), strcat (PreProcessCmd, " ");
strcat (PreProcessCmd, mPreProcessOpt), strcat (PreProcessCmd, " ");
if (mOptions.IncludePaths != NULL) {
strcat (PreProcessCmd, mOptions.IncludePaths), strcat (PreProcessCmd, " ");
}
if (mOptions.CPreprocessorOptions != NULL) {
strcat (PreProcessCmd, mOptions.CPreprocessorOptions), strcat (PreProcessCmd, " ");
}
strcat (PreProcessCmd, mOptions.VfrFileName), strcat (PreProcessCmd, " > ");
strcat (PreProcessCmd, mOptions.PreprocessorOutputFileName);
if (system (PreProcessCmd) != 0) {
printf ("%s failed to spawn C preprocessor on VFR file \n\t - %s\n", PROGRAM_NAME, PreProcessCmd);
goto Fail;
}
delete PreProcessCmd;
SET_RUN_STATUS (STATUS_PREPROCESSED);
return;
Fail:
if (!IS_RUN_STATUS(STATUS_DEAD)) {
SET_RUN_STATUS (STATUS_FAILED);
}
delete PreProcessCmd;
}
extern UINT8 VfrParserStart (IN FILE *);
VOID
CVfrCompiler::Compile (
VOID
)
{
FILE *VfrFile = NULL;
if (!IS_RUN_STATUS(STATUS_PREPROCESSED)) {
goto Fail;
}
if ((VfrFile = fopen (mOptions.PreprocessorOutputFileName, "r")) == NULL) {
printf ("%s failed to open input VFR preprocessor output file - %s\n", PROGRAM_NAME, mOptions.PreprocessorOutputFileName);
goto Fail;
}
if (VfrParserStart (VfrFile) != 0) {
goto Fail;
}
fclose (VfrFile);
if (gCFormPkg.HavePendingUnassigned () == TRUE) {
gCFormPkg.PendingAssignPrintAll ();
goto Fail;
}
SET_RUN_STATUS (STATUS_COMPILEED);
return;
Fail:
if (!IS_RUN_STATUS(STATUS_DEAD)) {
printf ("%s compile error!\n", PROGRAM_NAME);
SET_RUN_STATUS (STATUS_FAILED);
}
if (VfrFile != NULL) {
fclose (VfrFile);
}
}
VOID
CVfrCompiler::GenBinary (
VOID
)
{
FILE *pFile = NULL;
if (!IS_RUN_STATUS(STATUS_COMPILEED)) {
goto Fail;
}
if (mOptions.CreateIfrPkgFile == TRUE) {
if ((pFile = fopen (mOptions.PkgOutputFileName, "wb")) == NULL) {
printf ("can not open PkgFileName\n", mOptions.PkgOutputFileName);
goto Fail;
}
if (gCFormPkg.BuildPkg (pFile) != VFR_RETURN_SUCCESS) {
fclose (pFile);
goto Fail;
}
fclose (pFile);
}
SET_RUN_STATUS (STATUS_GENBINARY);
return;
Fail:
if (!IS_RUN_STATUS(STATUS_DEAD)) {
SET_RUN_STATUS (STATUS_FAILED);
}
}
static const char *gSourceFileHeader[] = {
"//",
"// DO NOT EDIT -- auto-generated file",
"//",
"// This file is generated by the vfrcompiler utility",
"//",
NULL
};
VOID
CVfrCompiler::GenCFile (
VOID
)
{
FILE *pFile;
UINT32 Index;
if (!IS_RUN_STATUS(STATUS_GENBINARY)) {
goto Fail;
}
if ((pFile = fopen (mOptions.COutputFileName, "w")) == NULL) {
printf ("failed to open output C file - %s\n", mOptions.COutputFileName);
goto Fail;
}
for (Index = 0; gSourceFileHeader[Index] != NULL; Index++) {
fprintf (pFile, "%s\n", gSourceFileHeader[Index]);
}
gCVfrBufferConfig.OutputCFile (pFile, mOptions.VfrBaseFileName);
if (gCFormPkg.GenCFile (mOptions.VfrBaseFileName, pFile) != VFR_RETURN_SUCCESS) {
fclose (pFile);
goto Fail;
}
fclose (pFile);
SET_RUN_STATUS (STATUS_FINISHED);
return;
Fail:
if (!IS_RUN_STATUS(STATUS_DEAD)) {
SET_RUN_STATUS (STATUS_FAILED);
}
}
VOID
CVfrCompiler::GenRecordListFile (
VOID
)
{
FILE *pInFile = NULL;
FILE *pOutFile = NULL;
INT8 LineBuf[MAX_LINE_LEN];
UINT32 LineNo;
if (mOptions.CreateRecordListFile == TRUE) {
if ((mOptions.PreprocessorOutputFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {
return;
}
if ((pInFile = fopen (mOptions.PreprocessorOutputFileName, "r")) == NULL) {
printf ("%s failed to open input VFR preprocessor output file - %s\n", PROGRAM_NAME, mOptions.PreprocessorOutputFileName);
return;
}
if ((pOutFile = fopen (mOptions.RecordListFile, "w")) == NULL) {
printf ("%s failed to open record list file for writing - %s\n", PROGRAM_NAME, mOptions.RecordListFile);
goto Err1;
}
fprintf (pOutFile, "//\n// VFR compiler version " VFR_COMPILER_VERSION "\n//\n");
LineNo = 0;
while (!feof (pInFile)) {
if (fgets (LineBuf, MAX_LINE_LEN, pInFile) != NULL) {
fprintf (pOutFile, "%s", LineBuf);
LineNo++;
gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, LineNo);
}
}
fclose (pOutFile);
fclose (pInFile);
}
return;
Err1:
fclose (pInFile);
}
INT32
main (
IN INT32 Argc,
IN INT8 **Argv
)
{
COMPILER_RUN_STATUS Status;
CVfrCompiler Compiler(Argc, Argv);
Compiler.PreProcess();
Compiler.Compile();
Compiler.GenBinary();
Compiler.GenCFile();
Compiler.GenRecordListFile ();
Status = Compiler.RunStatus ();
if ((Status == STATUS_DEAD) || (Status == STATUS_FAILED)) {
return 2;
}
return 0;
}

View File

@ -0,0 +1,90 @@
#ifndef _VFRCOMPILER_H_
#define _VFRCOMPILER_H_
#include "Tiano.h"
#include "EfiTypes.h"
#include "EfiVfr.h"
#include "VfrFormPkg.h"
#include "VfrUtilityLib.h"
#define PROGRAM_NAME "VfrCompile"
#define VFR_COMPILER_VERSION "UEFI 2.1"
//
// This is how we invoke the C preprocessor on the VFR source file
// to resolve #defines, #includes, etc. To make C source files
// shareable between VFR and drivers, define VFRCOMPILE so that
// #ifdefs can be used in shared .h files.
//
#define PREPROCESSOR_COMMAND "cl "
#define PREPROCESSOR_OPTIONS "/nologo /E /TC /DVFRCOMPILE "
//
// Specify the filename extensions for the files we generate.
//
#define VFR_PREPROCESS_FILENAME_EXTENSION ".i"
#define VFR_PACKAGE_FILENAME_EXTENSION ".hpk"
#define VFR_RECORDLIST_FILENAME_EXTENSION ".lst"
typedef struct {
INT8 VfrFileName[MAX_PATH];
INT8 RecordListFile[MAX_PATH];
INT8 PkgOutputFileName[MAX_PATH];
INT8 COutputFileName[MAX_PATH];
bool CreateRecordListFile;
bool CreateIfrPkgFile;
INT8 OutputDirectory[MAX_PATH];
INT8 PreprocessorOutputFileName[MAX_PATH];
INT8 VfrBaseFileName[MAX_PATH]; // name of input VFR file with no path or extension
INT8 *IncludePaths;
INT8 *CPreprocessorOptions;
} OPTIONS;
typedef enum {
STATUS_INITIALIZED = 1,
STATUS_PREPROCESSED,
STATUS_COMPILEED,
STATUS_GENBINARY,
STATUS_FINISHED,
STATUS_FAILED,
STATUS_DEAD,
} COMPILER_RUN_STATUS;
class CVfrCompiler {
private:
COMPILER_RUN_STATUS mRunStatus;
OPTIONS mOptions;
INT8 *mPreProcessCmd;
INT8 *mPreProcessOpt;
VOID OptionInitialization (IN INT32 , IN INT8 **);
VOID AppendIncludePath (IN INT8 *);
VOID AppendCPreprocessorOptions (IN INT8 *);
INT8 SetBaseFileName (VOID);
INT8 SetPkgOutputFileName (VOID);
INT8 SetCOutputFileName(VOID);
INT8 SetPreprocessorOutputFileName (VOID);
INT8 SetRecordListFileName (VOID);
VOID SET_RUN_STATUS (IN COMPILER_RUN_STATUS);
BOOLEAN IS_RUN_STATUS (IN COMPILER_RUN_STATUS);
public:
COMPILER_RUN_STATUS RunStatus (VOID) {
return mRunStatus;
}
public:
CVfrCompiler (IN INT32 , IN INT8 **);
~CVfrCompiler ();
VOID Usage (VOID);
VOID PreProcess (VOID);
VOID Compile (VOID);
VOID GenBinary (VOID);
VOID GenCFile (VOID);
VOID GenRecordListFile (VOID);
};
#endif

View File

@ -0,0 +1,197 @@
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "VfrError.h"
static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE [] = {
{ VFR_RETURN_SUCCESS, NULL },
{ VFR_RETURN_ERROR_SKIPED, NULL },
{ VFR_RETURN_FATAL_ERROR, "fatal error!!" },
{ VFR_RETURN_MISMATCHED, "unexpected token" },
{ VFR_RETURN_INVALID_PARAMETER, "Invalid parameter" },
{ VFR_RETURN_OUT_FOR_RESOURCES, "system out of memory" },
{ VFR_RETURN_UNSUPPORTED, "unsupported" },
{ VFR_RETURN_REDEFINED, "already defined" },
{ VFR_RETURN_FORMID_REDEFINED, "form id already defined" },
{ VFR_RETURN_QUESTIONID_REDEFINED, "question id already defined" },
{ VFR_RETURN_VARSTOREID_REDEFINED, "varstore id already defined" },
{ VFR_RETURN_UNDEFINED, "undefined" },
{ VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION, "some variable has not defined by a question"},
{ VFR_RETURN_GET_EFIVARSTORE_ERROR, "get efi varstore error"},
{ VFR_RETURN_EFIVARSTORE_USE_ERROR, "can not use the efi varstore like this" },
{ VFR_RETURN_EFIVARSTORE_SIZE_ERROR, "unsupport efi varstore size should be <= 8 bytes" },
{ VFR_RETURN_GET_NVVARSTORE_ERROR, "get name value varstore error" },
{ VFR_RETURN_QVAR_REUSE, "variable reused by more than one question" },
{ VFR_RETURN_FLAGS_UNSUPPORTED, "flags unsupported" },
{ VFR_RETURN_ERROR_ARRARY_NUM, "array number error" },
{ VFR_RETURN_DATA_STRING_ERROR, "data field string error or not support"},
{ VFR_RETURN_CODEUNDEFINED, "Undefined Error Code" }
};
CVfrErrorHandle::CVfrErrorHandle (
VOID
)
{
mScopeRecordListHead = NULL;
mScopeRecordListTail = NULL;
mVfrErrorHandleTable = VFR_ERROR_HANDLE_TABLE;
}
CVfrErrorHandle::~CVfrErrorHandle (
VOID
)
{
SVfrFileScopeRecord *pNode = NULL;
while (mScopeRecordListHead != NULL) {
pNode = mScopeRecordListHead;
mScopeRecordListHead = mScopeRecordListHead->mNext;
delete pNode;
}
mScopeRecordListHead = NULL;
mScopeRecordListTail = NULL;
mVfrErrorHandleTable = NULL;
}
SVfrFileScopeRecord::SVfrFileScopeRecord (
IN INT8 *Record,
IN UINT32 LineNum
)
{
UINT32 Index;
INT8 *FileName = NULL;
INT8 *Str = NULL;
mWholeScopeLine = LineNum;
mNext = NULL;
Str = strchr (Record, ' ');
mScopeLineStart = atoi (++Str);
Str = strchr (Str, '\"');
FileName = ++Str;
while((Str = strstr (FileName, "\\\\")) != NULL) {
FileName = Str + 2;
}
if ((mFileName = new INT8[strlen(FileName)]) != NULL) {
for (Index = 0; FileName[Index] != '\"'; Index++) {
mFileName[Index] = FileName[Index];
}
mFileName[Index] = '\0';
}
return;
}
SVfrFileScopeRecord::~SVfrFileScopeRecord (
VOID
)
{
if (mFileName != NULL) {
delete mFileName;
}
}
VOID
CVfrErrorHandle::ParseFileScopeRecord (
IN INT8 *Record,
IN UINT32 WholeScopeLine
)
{
INT8 *FullPathName = NULL;
SVfrFileScopeRecord *pNode = NULL;
if (Record == NULL) {
return;
}
if ((pNode = new SVfrFileScopeRecord(Record, WholeScopeLine)) == NULL) {
return;
}
if (mScopeRecordListHead == NULL) {
mScopeRecordListTail = mScopeRecordListHead = pNode;
} else {
mScopeRecordListTail->mNext = pNode;
mScopeRecordListTail = pNode;
}
}
VOID
CVfrErrorHandle::GetFileNameLineNum (
IN UINT32 LineNum,
OUT INT8 **FileName,
OUT UINT32 *FileLine
)
{
SVfrFileScopeRecord *pNode = NULL;
if ((FileName == NULL) || (FileLine == NULL)) {
return;
}
*FileName = NULL;
*FileLine = 0xFFFFFFFF;
for (pNode = mScopeRecordListHead; pNode->mNext != NULL; pNode = pNode->mNext) {
if ((LineNum > pNode->mWholeScopeLine) && (pNode->mNext->mWholeScopeLine > LineNum)) {
*FileName = pNode->mFileName;
*FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;
return ;
}
}
*FileName = pNode->mFileName;
*FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;
}
VOID
CVfrErrorHandle::PrintError (
IN UINT32 LineNum,
IN INT8 *TokName,
IN INT8 *ErrorMsg
)
{
INT8 *FileName = NULL;
UINT32 FileLine;
GetFileNameLineNum (LineNum, &FileName, &FileLine);
printf ("%s line %d: error %s %s\n", FileName, FileLine, TokName, ErrorMsg);
}
UINT8
CVfrErrorHandle::HandleError (
IN EFI_VFR_RETURN_CODE ErrorCode,
IN UINT32 LineNum,
IN INT8 *TokName
)
{
UINT32 Index;
INT8 *FileName = NULL;
UINT32 FileLine;
INT8 *ErrorMsg = NULL;
if (mVfrErrorHandleTable == NULL) {
return 1;
}
for (Index = 0; mVfrErrorHandleTable[Index].mErrorCode != VFR_RETURN_CODEUNDEFINED; Index++) {
if (ErrorCode == mVfrErrorHandleTable[Index].mErrorCode) {
ErrorMsg = mVfrErrorHandleTable[Index].mErrorMsg;
break;
}
}
if (ErrorMsg != NULL) {
GetFileNameLineNum (LineNum, &FileName, &FileLine);
printf ("%s line %d: error %s %s\n", FileName, FileLine, TokName, ErrorMsg);
return 1;
} else {
return 0;
}
}
CVfrErrorHandle gCVfrErrorHandle;

View File

@ -0,0 +1,67 @@
#ifndef _VFRERROR_H_
#define _VFRERROR_H_
#include "Tiano.h"
#include "EfiTypes.h"
typedef enum {
VFR_RETURN_SUCCESS = 0,
VFR_RETURN_ERROR_SKIPED,
VFR_RETURN_FATAL_ERROR,
VFR_RETURN_MISMATCHED,
VFR_RETURN_INVALID_PARAMETER,
VFR_RETURN_OUT_FOR_RESOURCES,
VFR_RETURN_UNSUPPORTED,
VFR_RETURN_REDEFINED,
VFR_RETURN_FORMID_REDEFINED,
VFR_RETURN_QUESTIONID_REDEFINED,
VFR_RETURN_VARSTOREID_REDEFINED,
VFR_RETURN_UNDEFINED,
VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION,
VFR_RETURN_GET_EFIVARSTORE_ERROR,
VFR_RETURN_EFIVARSTORE_USE_ERROR,
VFR_RETURN_EFIVARSTORE_SIZE_ERROR,
VFR_RETURN_GET_NVVARSTORE_ERROR,
VFR_RETURN_QVAR_REUSE,
VFR_RETURN_FLAGS_UNSUPPORTED,
VFR_RETURN_ERROR_ARRARY_NUM,
VFR_RETURN_DATA_STRING_ERROR,
VFR_RETURN_CODEUNDEFINED
} EFI_VFR_RETURN_CODE;
typedef struct _SVFR_ERROR_HANDLE {
EFI_VFR_RETURN_CODE mErrorCode;
INT8 *mErrorMsg;
} SVFR_ERROR_HANDLE;
struct SVfrFileScopeRecord {
INT8 *mFileName;
UINT32 mWholeScopeLine;
UINT32 mScopeLineStart;
SVfrFileScopeRecord *mNext;
SVfrFileScopeRecord (IN INT8 *, IN UINT32);
~SVfrFileScopeRecord();
};
class CVfrErrorHandle {
private:
SVFR_ERROR_HANDLE *mVfrErrorHandleTable;
SVfrFileScopeRecord *mScopeRecordListHead;
SVfrFileScopeRecord *mScopeRecordListTail;
public:
CVfrErrorHandle (VOID);
~CVfrErrorHandle (VOID);
VOID ParseFileScopeRecord (IN INT8 *, IN UINT32);
VOID GetFileNameLineNum (IN UINT32, OUT INT8 **, OUT UINT32 *);
UINT8 HandleError (IN EFI_VFR_RETURN_CODE, IN UINT32 LineNum = 0, IN INT8 *TokName = "\0");
VOID PrintError (IN UINT32 LineNum = 0, IN INT8 *TokName = "\0", IN INT8 *ErrorMsg = "\0");
};
#define CHECK_ERROR_RETURN(f, v) do { EFI_VFR_RETURN_CODE r; if ((r = (f)) != (v)) { return r; } } while (0)
extern CVfrErrorHandle gCVfrErrorHandle;
#endif

View File

@ -0,0 +1,830 @@
#include "stdio.h"
#include "VfrFormPkg.h"
/*
* The definition of CFormPkg's member function
*/
SPendingAssign::SPendingAssign (
IN INT8 *Key,
IN VOID *Addr,
IN UINT32 Len,
IN UINT32 LineNo
)
{
if (Key != NULL) {
mKey = new INT8[strlen (Key) + 1];
if (mKey != NULL) {
strcpy (mKey, Key);
}
} else {
mKey = NULL;
}
mAddr = Addr;
mLen = Len;
mFlag = PENDING;
mLineNo = LineNo;
mNext = NULL;
}
SPendingAssign::~SPendingAssign (
VOID
)
{
if (mKey != NULL) {
delete mKey;
}
mAddr = NULL;
mLen = 0;
mLineNo = 0;
mNext = NULL;
}
VOID
SPendingAssign::SetAddrAndLen (
IN VOID *Addr,
IN UINT32 LineNo
)
{
mAddr = Addr;
mLineNo = LineNo;
}
VOID
SPendingAssign::AssignValue (
IN VOID *Addr,
IN UINT32 Len
)
{
memcpy (mAddr, Addr, (mLen < Len ? mLen : Len));
mFlag = ASSIGNED;
}
INT8 *
SPendingAssign::GetKey (
VOID
)
{
return mKey;
}
CFormPkg::CFormPkg (
IN UINT32 BufferSize = 4096
)
{
CHAR8 *BufferStart;
CHAR8 *BufferEnd;
SBufferNode *Node;
mPkgLength = 0;
mBufferNodeQueueHead = NULL;
mCurrBufferNode = NULL;
Node = new SBufferNode;
if (Node == NULL) {
return ;
}
BufferStart = new CHAR8[BufferSize];
if (BufferStart == NULL) {
return;
}
BufferEnd = BufferStart + BufferSize;
memset (BufferStart, 0, BufferSize);
Node->mBufferStart = BufferStart;
Node->mBufferEnd = BufferEnd;
Node->mBufferFree = BufferStart;
Node->mNext = NULL;
mBufferSize = BufferSize;
mBufferNodeQueueHead = Node;
mBufferNodeQueueTail = Node;
mCurrBufferNode = Node;
}
CFormPkg::~CFormPkg ()
{
SBufferNode *pBNode;
SPendingAssign *pPNode;
while (mBufferNodeQueueHead != NULL) {
pBNode = mBufferNodeQueueHead;
mBufferNodeQueueHead = mBufferNodeQueueHead->mNext;
if (pBNode->mBufferStart != NULL) {
delete pBNode->mBufferStart;
delete pBNode;
}
}
mBufferNodeQueueTail = NULL;
mCurrBufferNode = NULL;
while (PendingAssignList != NULL) {
pPNode = PendingAssignList;
PendingAssignList = PendingAssignList->mNext;
delete pPNode;
}
PendingAssignList = NULL;
}
CHAR8 *
CFormPkg::IfrBinBufferGet (
IN UINT32 Len
)
{
CHAR8 *BinBuffer = NULL;
if ((Len == 0) || (Len > mBufferSize)) {
return NULL;
}
if ((mCurrBufferNode->mBufferFree + Len) <= mCurrBufferNode->mBufferEnd) {
BinBuffer = mCurrBufferNode->mBufferFree;
mCurrBufferNode->mBufferFree += Len;
} else {
SBufferNode *Node;
Node = new SBufferNode;
if (Node == NULL) {
return NULL;
}
Node->mBufferStart = new CHAR8[mBufferSize];
if (Node->mBufferStart == NULL) {
delete Node;
return NULL;
} else {
memset (Node->mBufferStart, 0, mBufferSize);
Node->mBufferEnd = Node->mBufferStart + mBufferSize;
Node->mBufferFree = Node->mBufferStart;
Node->mNext = NULL;
}
if (mBufferNodeQueueTail == NULL) {
mBufferNodeQueueHead = mBufferNodeQueueTail = Node;
} else {
mBufferNodeQueueTail->mNext = Node;
mBufferNodeQueueTail = Node;
}
mCurrBufferNode = Node;
//
// Now try again.
//
BinBuffer = mCurrBufferNode->mBufferFree;
mCurrBufferNode->mBufferFree += Len;
}
mPkgLength += Len;
return BinBuffer;
}
inline
UINT32
CFormPkg::GetPkgLength (
VOID
)
{
return mPkgLength;
}
VOID
CFormPkg::Open (
VOID
)
{
mReadBufferNode = mBufferNodeQueueHead;
mReadBufferOffset = 0;
}
VOID
CFormPkg::Close (
VOID
)
{
mReadBufferNode = NULL;
mReadBufferOffset = 0;
}
UINT32
CFormPkg::Read (
IN CHAR8 *Buffer,
IN UINT32 Size
)
{
UINT32 Index;
if ((Size == 0) || (Buffer == NULL)) {
return 0;
}
if (mReadBufferNode == NULL) {
return 0;
}
for (Index = 0; Index < Size; Index++) {
if ((mReadBufferNode->mBufferStart + mReadBufferOffset) < mReadBufferNode->mBufferFree) {
Buffer[Index] = mReadBufferNode->mBufferStart[mReadBufferOffset++];
} else {
if ((mReadBufferNode = mReadBufferNode->mNext) == NULL) {
return Index;
} else {
mReadBufferOffset = 0;
Buffer[Index] = mReadBufferNode->mBufferStart[mReadBufferOffset++];
}
}
}
return Size;
}
EFI_VFR_RETURN_CODE
CFormPkg::BuildPkgHdr (
OUT EFI_HII_PACKAGE_HEADER **PkgHdr
)
{
if (PkgHdr == NULL) {
return VFR_RETURN_FATAL_ERROR;
}
if (((*PkgHdr) = new EFI_HII_PACKAGE_HEADER) == NULL) {
return VFR_RETURN_OUT_FOR_RESOURCES;
}
(*PkgHdr)->Type = EFI_HII_PACKAGE_FORM;
(*PkgHdr)->Length = mPkgLength + sizeof (EFI_HII_PACKAGE_HEADER);
return VFR_RETURN_SUCCESS;
}
EFI_VFR_RETURN_CODE
CFormPkg::BuildPkg (
IN FILE *Output
)
{
EFI_VFR_RETURN_CODE Ret;
CHAR8 Buffer[1024];
UINT32 Size;
EFI_HII_PACKAGE_HEADER *PkgHdr;
if (Output == NULL) {
return VFR_RETURN_FATAL_ERROR;
}
if ((Ret = BuildPkgHdr(&PkgHdr)) != VFR_RETURN_SUCCESS) {
return Ret;
}
fwrite (PkgHdr, sizeof (EFI_HII_PACKAGE_HEADER), 1, Output);
delete PkgHdr;
Open ();
while ((Size = Read (Buffer, 1024)) != 0) {
fwrite (Buffer, Size, 1, Output);
}
Close ();
return VFR_RETURN_SUCCESS;
}
VOID
CFormPkg::_WRITE_PKG_LINE (
IN FILE *pFile,
IN UINT32 LineBytes,
IN INT8 *LineHeader,
IN INT8 *BlkBuf,
IN UINT32 BlkSize
)
{
UINT32 Index;
if ((pFile == NULL) || (LineHeader == NULL) || (BlkBuf == NULL)) {
return;
}
for (Index = 0; Index < BlkSize; Index++) {
if ((Index % LineBytes) == 0) {
fprintf (pFile, "\n%s", LineHeader);
}
fprintf (pFile, "0x%02X, ", (UINT8)BlkBuf[Index]);
}
}
VOID
CFormPkg::_WRITE_PKG_END (
IN FILE *pFile,
IN UINT32 LineBytes,
IN INT8 *LineHeader,
IN INT8 *BlkBuf,
IN UINT32 BlkSize
)
{
UINT32 Index;
if ((BlkSize == 0) || (pFile == NULL) || (LineHeader == NULL) || (BlkBuf == NULL)) {
return;
}
for (Index = 0; Index < BlkSize - 1; Index++) {
if ((Index % LineBytes) == 0) {
fprintf (pFile, "\n%s", LineHeader);
}
fprintf (pFile, "0x%02X, ", (UINT8)BlkBuf[Index]);
}
if ((Index % LineBytes) == 0) {
fprintf (pFile, "\n%s", LineHeader);
}
fprintf (pFile, "0x%02X\n", (UINT8)BlkBuf[Index]);
}
#define BYTES_PRE_LINE 0x10
EFI_VFR_RETURN_CODE
CFormPkg::GenCFile (
IN INT8 *BaseName,
IN FILE *pFile
)
{
EFI_VFR_RETURN_CODE Ret;
INT8 Buffer[BYTES_PRE_LINE * 8];
EFI_HII_PACKAGE_HEADER *PkgHdr;
UINT32 PkgLength = 0;
UINT32 ReadSize = 0;
if ((BaseName == NULL) || (pFile == NULL)) {
return VFR_RETURN_FATAL_ERROR;
}
fprintf (pFile, "\nunsigned char %sBin[] = {\n", BaseName);
if ((Ret = BuildPkgHdr(&PkgHdr)) != VFR_RETURN_SUCCESS) {
return Ret;
}
fprintf (pFile, " // ARRAY LENGTH\n");
PkgLength = PkgHdr->Length + sizeof (UINT32);
_WRITE_PKG_LINE(pFile, BYTES_PRE_LINE, " ", (INT8 *)&PkgLength, sizeof (UINT32));
fprintf (pFile, "\n\n // PACKAGE HEADER\n");
_WRITE_PKG_LINE(pFile, BYTES_PRE_LINE, " ", (INT8 *)PkgHdr, sizeof (EFI_HII_PACKAGE_HEADER));
PkgLength = sizeof (EFI_HII_PACKAGE_HEADER);
fprintf (pFile, "\n\n // PACKAGE DATA\n");
Open ();
while ((ReadSize = Read ((CHAR8 *)Buffer, BYTES_PRE_LINE * 8)) != 0) {
PkgLength += ReadSize;
if (PkgLength < PkgHdr->Length) {
_WRITE_PKG_LINE (pFile, BYTES_PRE_LINE, " ", Buffer, ReadSize);
} else {
_WRITE_PKG_END (pFile, BYTES_PRE_LINE, " ", Buffer, ReadSize);
}
}
Close ();
delete PkgHdr;
fprintf (pFile, "\n};\n");
return VFR_RETURN_SUCCESS;
}
EFI_VFR_RETURN_CODE
CFormPkg::AssignPending (
IN INT8 *Key,
IN VOID *ValAddr,
IN UINT32 ValLen,
IN UINT32 LineNo
)
{
SPendingAssign *pNew;
pNew = new SPendingAssign (Key, ValAddr, ValLen, LineNo);
if (pNew == NULL) {
return VFR_RETURN_OUT_FOR_RESOURCES;
}
pNew->mNext = PendingAssignList;
PendingAssignList = pNew;
return VFR_RETURN_SUCCESS;
}
VOID
CFormPkg::DoPendingAssign (
IN INT8 *Key,
IN VOID *ValAddr,
IN UINT32 ValLen
)
{
SPendingAssign *pNode;
if ((Key == NULL) || (ValAddr == NULL)) {
return;
}
for (pNode = PendingAssignList; pNode != NULL; pNode = pNode->mNext) {
if (strcmp (pNode->mKey, Key) == 0) {
pNode->AssignValue (ValAddr, ValLen);
}
}
}
bool
CFormPkg::HavePendingUnassigned (
VOID
)
{
SPendingAssign *pNode;
for (pNode = PendingAssignList; pNode != NULL; pNode = pNode->mNext) {
if (pNode->mFlag == PENDING) {
return TRUE;
}
}
return FALSE;
}
VOID
CFormPkg::PendingAssignPrintAll (
VOID
)
{
SPendingAssign *pNode;
for (pNode = PendingAssignList; pNode != NULL; pNode = pNode->mNext) {
if (pNode->mFlag == PENDING) {
gCVfrErrorHandle.PrintError (pNode->mLineNo, pNode->mKey, "can not assign value because not defined");
}
}
}
CFormPkg gCFormPkg;
SIfrRecord::SIfrRecord (
VOID
)
{
mIfrBinBuf = NULL;
mBinBufLen = 0;
mLineNo = 0xFFFFFFFF;
mOffset = 0xFFFFFFFF;
mNext = NULL;
}
SIfrRecord::~SIfrRecord (
VOID
)
{
if (mIfrBinBuf != NULL) {
delete mIfrBinBuf;
mIfrBinBuf = NULL;
}
mLineNo = 0xFFFFFFFF;
mOffset = 0xFFFFFFFF;
mBinBufLen = 0;
mNext = NULL;
}
CIfrRecordInfoDB::CIfrRecordInfoDB (
VOID
)
{
mSwitch = FALSE;
mRecordCount = EFI_IFR_RECORDINFO_IDX_START;
mIfrRecordListHead = NULL;
mIfrRecordListTail = NULL;
}
CIfrRecordInfoDB::~CIfrRecordInfoDB (
VOID
)
{
SIfrRecord *pNode;
while (mIfrRecordListHead != NULL) {
pNode = mIfrRecordListHead;
mIfrRecordListHead = mIfrRecordListHead->mNext;
delete pNode;
}
}
SIfrRecord *
CIfrRecordInfoDB::GetRecordInfoFromIdx (
IN UINT32 RecordIdx
)
{
UINT32 Idx;
SIfrRecord *pNode = NULL;
if (RecordIdx == EFI_IFR_RECORDINFO_IDX_INVALUD) {
return NULL;
}
for (Idx = (EFI_IFR_RECORDINFO_IDX_START + 1), pNode = mIfrRecordListHead;
(Idx != RecordIdx) && (pNode != NULL);
Idx++, pNode = pNode->mNext)
;
return pNode;
}
UINT32
CIfrRecordInfoDB::IfrRecordRegister (
IN UINT32 LineNo,
IN CHAR8 *IfrBinBuf,
IN UINT8 BinBufLen,
IN UINT32 Offset
)
{
SIfrRecord *pNew;
if (mSwitch == FALSE) {
return EFI_IFR_RECORDINFO_IDX_INVALUD;
}
if ((pNew = new SIfrRecord) == NULL) {
return EFI_IFR_RECORDINFO_IDX_INVALUD;
}
if (mIfrRecordListHead == NULL) {
mIfrRecordListHead = pNew;
mIfrRecordListTail = pNew;
} else {
mIfrRecordListTail->mNext = pNew;
mIfrRecordListTail = pNew;
}
mRecordCount++;
return mRecordCount;
}
VOID
CIfrRecordInfoDB::IfrRecordInfoUpdate (
IN UINT32 RecordIdx,
IN UINT32 LineNo,
IN CHAR8 *BinBuf,
IN UINT8 BinBufLen,
IN UINT32 Offset
)
{
SIfrRecord *pNode;
if ((pNode = GetRecordInfoFromIdx (RecordIdx)) == NULL) {
return;
}
pNode->mLineNo = LineNo;
pNode->mOffset = Offset;
pNode->mBinBufLen = BinBufLen;
if (BinBuf != NULL) {
if (pNode->mIfrBinBuf != NULL) {
delete pNode->mIfrBinBuf;
}
pNode->mIfrBinBuf = new CHAR8[BinBufLen];
if (pNode->mIfrBinBuf != NULL) {
memcpy (pNode->mIfrBinBuf, BinBuf, BinBufLen);
}
}
}
VOID
CIfrRecordInfoDB::IfrRecordOutput (
IN FILE *File,
IN UINT32 LineNo
)
{
SIfrRecord *pNode;
UINT8 Index;
if (mSwitch == FALSE) {
return;
}
if (File == NULL) {
return;
}
for (pNode = mIfrRecordListHead; pNode != NULL; pNode = pNode->mNext) {
if (pNode->mLineNo == LineNo) {
fprintf (File, ">%08X: ", pNode->mOffset);
if (pNode->mIfrBinBuf != NULL) {
for (Index = 0; Index < pNode->mBinBufLen; Index++) {
fprintf (File, "%02X ", pNode->mIfrBinBuf[Index]);
}
}
fprintf (File, "\n");
}
}
}
CIfrRecordInfoDB gCIfrRecordInfoDB;
VOID
CIfrObj::_EMIT_PENDING_OBJ (
VOID
)
{
CHAR8 *ObjBinBuf = NULL;
ObjBinBuf = gCFormPkg.IfrBinBufferGet (mObjBinLen);
if (ObjBinBuf != NULL) {
memcpy (ObjBinBuf, mObjBinBuf, mObjBinLen);
}
if (mObjBinBuf != NULL) {
delete mObjBinBuf;
}
}
/*
* The definition of CIfrObj's member function
*/
static struct {
UINT8 mSize;
UINT8 mScope;
} gOpcodeSizesScopeTable[] = {
{ 0, 0 }, // EFI_IFR_INVALID - 0x00
{ sizeof (EFI_IFR_FORM), 1 }, // EFI_IFR_FORM_OP
{ sizeof (EFI_IFR_SUBTITLE), 1 }, // EFI_IFR_SUBTITLE_OP
{ sizeof (EFI_IFR_TEXT), 0 }, // EFI_IFR_TEXT_OP
{ sizeof (EFI_IFR_IMAGE), 0 }, // EFI_IFR_IMAGE_OP
{ sizeof (EFI_IFR_ONE_OF), 1 }, // EFI_IFR_ONE_OF_OP - 0x05
{ sizeof (EFI_IFR_CHECKBOX), 1}, // EFI_IFR_CHECKBOX_OP
{ sizeof (EFI_IFR_NUMERIC), 1 }, // EFI_IFR_NUMERIC_OP
{ sizeof (EFI_IFR_PASSWORD), 1 }, // EFI_IFR_PASSWORD_OP
{ sizeof (EFI_IFR_ONE_OF_OPTION), 0 }, // EFI_IFR_ONE_OF_OPTION_OP
{ sizeof (EFI_IFR_SUPPRESS_IF), 1 }, // EFI_IFR_SUPPRESS_IF - 0x0A
{ sizeof (EFI_IFR_LOCKED), 0 }, // EFI_IFR_LOCKED_OP
{ sizeof (EFI_IFR_ACTION), 1 }, // EFI_IFR_ACTION_OP
{ sizeof (EFI_IFR_RESET_BUTTON), 1 }, // EFI_IFR_RESET_BUTTON_OP
{ sizeof (EFI_IFR_FORM_SET), 1 }, // EFI_IFR_FORM_SET_OP -0xE
{ sizeof (EFI_IFR_REF), 0 }, // EFI_IFR_REF_OP
{ sizeof (EFI_IFR_NO_SUBMIT_IF), 1}, // EFI_IFR_NO_SUBMIT_IF_OP -0x10
{ sizeof (EFI_IFR_INCONSISTENT_IF), 1 }, // EFI_IFR_INCONSISTENT_IF_OP
{ sizeof (EFI_IFR_EQ_ID_VAL), 0 }, // EFI_IFR_EQ_ID_VAL_OP
{ sizeof (EFI_IFR_EQ_ID_ID), 0 }, // EFI_IFR_EQ_ID_ID_OP
{ sizeof (EFI_IFR_EQ_ID_LIST), 0 }, // EFI_IFR_EQ_ID_LIST_OP - 0x14
{ sizeof (EFI_IFR_AND), 0 }, // EFI_IFR_AND_OP
{ sizeof (EFI_IFR_OR), 0 }, // EFI_IFR_OR_OP
{ sizeof (EFI_IFR_NOT), 0 }, // EFI_IFR_NOT_OP
{ sizeof (EFI_IFR_RULE), 1 }, // EFI_IFR_RULE_OP
{ sizeof (EFI_IFR_GRAY_OUT_IF), 1 }, // EFI_IFR_GRAYOUT_IF_OP - 0x19
{ sizeof (EFI_IFR_DATE), 1 }, // EFI_IFR_DATE_OP
{ sizeof (EFI_IFR_TIME), 1 }, // EFI_IFR_TIME_OP
{ sizeof (EFI_IFR_STRING), 1 }, // EFI_IFR_STRING_OP
{ sizeof (EFI_IFR_REFRESH), 1 }, // EFI_IFR_REFRESH_OP
{ sizeof (EFI_IFR_DISABLE_IF), 1 }, // EFI_IFR_DISABLE_IF_OP - 0x1E
{ 0, 0 }, // 0x1F
{ sizeof (EFI_IFR_TO_LOWER), 0 }, // EFI_IFR_TO_LOWER_OP - 0x20
{ sizeof (EFI_IFR_TO_UPPER), 0 }, // EFI_IFR_TO_UPPER_OP - 0x21
{ 0, 0 }, // 0x22
{ sizeof (EFI_IFR_ORDERED_LIST), 1 }, // EFI_IFR_ORDERED_LIST_OP - 0x23
{ sizeof (EFI_IFR_VARSTORE), 0 }, // EFI_IFR_VARSTORE_OP
{ sizeof (EFI_IFR_VARSTORE_NAME_VALUE), 0 }, // EFI_IFR_VARSTORE_NAME_VALUE_OP
{ sizeof (EFI_IFR_VARSTORE_EFI), 0 }, // EFI_IFR_VARSTORE_EFI_OP
{ sizeof (EFI_IFR_VARSTORE_DEVICE), 1 }, // EFI_IFR_VARSTORE_DEVICE_OP
{ sizeof (EFI_IFR_VERSION), 0 }, // EFI_IFR_VERSION_OP - 0x28
{ sizeof (EFI_IFR_END), 0 }, // EFI_IFR_END_OP
{ sizeof (EFI_IFR_MATCH), 1 }, // EFI_IFR_MATCH_OP - 0x2A
{ 0, 0 }, { 0, 0} , { 0, 0} , { 0, 0} , // 0x2B ~ 0x2E
{ sizeof (EFI_IFR_EQUAL), 0 }, // EFI_IFR_EQUAL_OP - 0x2F
{ sizeof (EFI_IFR_NOT_EQUAL), 0 }, // EFI_IFR_NOT_EQUAL_OP
{ sizeof (EFI_IFR_GREATER_THAN), 0 }, // EFI_IFR_GREATER_THAN_OP
{ sizeof (EFI_IFR_GREATER_EQUAL), 0 }, // EFI_IFR_GREATER_EQUAL_OP
{ sizeof (EFI_IFR_LESS_THAN), 0 }, // EFI_IFR_LESS_THAN_OP
{ sizeof (EFI_IFR_LESS_EQUAL), 0 }, // EFI_IFR_LESS_EQUAL_OP - 0x34
{ sizeof (EFI_IFR_BITWISE_AND), 0 }, // EFI_IFR_BITWISE_AND_OP
{ sizeof (EFI_IFR_BITWISE_OR), 0 }, // EFI_IFR_BITWISE_OR_OP
{ sizeof (EFI_IFR_BITWISE_NOT), 0 }, // EFI_IFR_BITWISE_NOT_OP
{ sizeof (EFI_IFR_SHIFT_LEFT), 0 }, // EFI_IFR_SHIFT_LEFT_OP
{ sizeof (EFI_IFR_SHIFT_RIGHT), 0 }, // EFI_IFR_SHIFT_RIGHT_OP
{ sizeof (EFI_IFR_ADD), 0 }, // EFI_IFR_ADD_OP - 0x3A
{ sizeof (EFI_IFR_SUBTRACT), 0 }, // EFI_IFR_SUBTRACT_OP
{ sizeof (EFI_IFR_MULTIPLY), 0 }, // EFI_IFR_MULTIPLY_OP
{ sizeof (EFI_IFR_DIVIDE), 0 }, // EFI_IFR_DIVIDE_OP
{ sizeof (EFI_IFR_MODULO), 0 }, // EFI_IFR_MODULO_OP - 0x3E
{ sizeof (EFI_IFR_RULE_REF), 0 }, // EFI_IFR_RULE_REF_OP
{ sizeof (EFI_IFR_QUESTION_REF1), 0 }, // EFI_IFR_QUESTION_REF1_OP
{ sizeof (EFI_IFR_QUESTION_REF2), 0 }, // EFI_IFR_QUESTION_REF2_OP - 0x41
{ sizeof (EFI_IFR_UINT8), 0}, // EFI_IFR_UINT8
{ sizeof (EFI_IFR_UINT16), 0}, // EFI_IFR_UINT16
{ sizeof (EFI_IFR_UINT32), 0}, // EFI_IFR_UINT32
{ sizeof (EFI_IFR_UINT64), 0}, // EFI_IFR_UTNT64
{ sizeof (EFI_IFR_TRUE), 0 }, // EFI_IFR_TRUE_OP - 0x46
{ sizeof (EFI_IFR_FALSE), 0 }, // EFI_IFR_FALSE_OP
{ sizeof (EFI_IFR_TO_UINT), 0 }, // EFI_IFR_TO_UINT_OP
{ sizeof (EFI_IFR_TO_STRING), 0 }, // EFI_IFR_TO_STRING_OP
{ sizeof (EFI_IFR_TO_BOOLEAN), 0 }, // EFI_IFR_TO_BOOLEAN_OP
{ sizeof (EFI_IFR_MID), 0 }, // EFI_IFR_MID_OP
{ sizeof (EFI_IFR_FIND), 0 }, // EFI_IFR_FIND_OP
{ sizeof (EFI_IFR_TOKEN), 0 }, // EFI_IFR_TOKEN_OP
{ sizeof (EFI_IFR_STRING_REF1), 0 }, // EFI_IFR_STRING_REF1_OP - 0x4E
{ sizeof (EFI_IFR_STRING_REF2), 0 }, // EFI_IFR_STRING_REF2_OP
{ sizeof (EFI_IFR_CONDITIONAL), 0 }, // EFI_IFR_CONDITIONAL_OP
{ sizeof (EFI_IFR_QUESTION_REF3), 0 }, // EFI_IFR_QUESTION_REF3_OP
{ sizeof (EFI_IFR_ZERO), 0 }, // EFI_IFR_ZERO_OP
{ sizeof (EFI_IFR_ONE), 0 }, // EFI_IFR_ONE_OP
{ sizeof (EFI_IFR_ONES), 0 }, // EFI_IFR_ONES_OP
{ sizeof (EFI_IFR_UNDEFINED), 0 }, // EFI_IFR_UNDEFINED_OP
{ sizeof (EFI_IFR_LENGTH), 0 }, // EFI_IFR_LENGTH_OP
{ sizeof (EFI_IFR_DUP), 0 }, // EFI_IFR_DUP_OP - 0x57
{ sizeof (EFI_IFR_THIS), 0 }, // EFI_IFR_THIS_OP
{ sizeof (EFI_IFR_SPAN), 0 }, // EFI_IFR_SPAN_OP
{ sizeof (EFI_IFR_VALUE), 1 }, // EFI_IFR_VALUE_OP
{ sizeof (EFI_IFR_DEFAULT), 0 }, // EFI_IFR_DEFAULT_OP
{ sizeof (EFI_IFR_DEFAULTSTORE), 0 }, // EFI_IFR_DEFAULTSTORE_OP - 0x5C
{ 0, 0}, // 0x5D
{ sizeof (EFI_IFR_CATENATE), 0 }, // EFI_IFR_CATENATE_OP
{ sizeof (EFI_IFR_GUID), 0 }, // EFI_IFR_GUID_OP
};
#ifdef CIFROBJ_DEUBG
static struct {
INT8 *mIfrName;
} gIfrObjPrintDebugTable[] = {
"EFI_IFR_INVALID", "EFI_IFR_FORM", "EFI_IFR_SUBTITLE", "EFI_IFR_TEXT", "EFI_IFR_IMAGE", "EFI_IFR_ONE_OF",
"EFI_IFR_CHECKBOX", "EFI_IFR_NUMERIC", "EFI_IFR_PASSWORD", "EFI_IFR_ONE_OF_OPTION", "EFI_IFR_SUPPRESS_IF", "EFI_IFR_LOCKED",
"EFI_IFR_ACTION", "EFI_IFR_RESET_BUTTON", "EFI_IFR_FORM_SET", "EFI_IFR_REF", "EFI_IFR_NO_SUBMIT_IF", "EFI_IFR_INCONSISTENT_IF",
"EFI_IFR_EQ_ID_VAL", "EFI_IFR_EQ_ID_ID", "EFI_IFR_EQ_ID_LIST", "EFI_IFR_AND", "EFI_IFR_OR", "EFI_IFR_NOT",
"EFI_IFR_RULE", "EFI_IFR_GRAY_OUT_IF", "EFI_IFR_DATE", "EFI_IFR_TIME", "EFI_IFR_STRING", "EFI_IFR_REFRESH",
"EFI_IFR_DISABLE_IF", "EFI_IFR_INVALID", "EFI_IFR_TO_LOWER", "EFI_IFR_TO_UPPER", "EFI_IFR_INVALID", "EFI_IFR_ORDERED_LIST",
"EFI_IFR_VARSTORE", "EFI_IFR_VARSTORE_NAME_VALUE", "EFI_IFR_VARSTORE_EFI", "EFI_IFR_VARSTORE_DEVICE", "EFI_IFR_VERSION", "EFI_IFR_END",
"EFI_IFR_MATCH", "EFI_IFR_INVALID", "EFI_IFR_INVALID", "EFI_IFR_INVALID", "EFI_IFR_INVALID", "EFI_IFR_EQUAL",
"EFI_IFR_NOT_EQUAL", "EFI_IFR_GREATER_THAN", "EFI_IFR_GREATER_EQUAL", "EFI_IFR_LESS_THAN", "EFI_IFR_LESS_EQUAL", "EFI_IFR_BITWISE_AND",
"EFI_IFR_BITWISE_OR", "EFI_IFR_BITWISE_NOT", "EFI_IFR_SHIFT_LEFT", "EFI_IFR_SHIFT_RIGHT", "EFI_IFR_ADD", "EFI_IFR_SUBTRACT",
"EFI_IFR_MULTIPLY", "EFI_IFR_DIVIDE", "EFI_IFR_MODULO", "EFI_IFR_RULE_REF", "EFI_IFR_QUESTION_REF1", "EFI_IFR_QUESTION_REF2",
"EFI_IFR_UINT8", "EFI_IFR_UINT16", "EFI_IFR_UINT32", "EFI_IFR_UINT64", "EFI_IFR_TRUE", "EFI_IFR_FALSE",
"EFI_IFR_TO_UINT", "EFI_IFR_TO_STRING", "EFI_IFR_TO_BOOLEAN", "EFI_IFR_MID", "EFI_IFR_FIND", "EFI_IFR_TOKEN",
"EFI_IFR_STRING_REF1","EFI_IFR_STRING_REF2", "EFI_IFR_CONDITIONAL", "EFI_IFR_QUESTION_REF3", "EFI_IFR_ZERO", "EFI_IFR_ONE",
"EFI_IFR_ONES", "EFI_IFR_UNDEFINED", "EFI_IFR_LENGTH", "EFI_IFR_DUP", "EFI_IFR_THIS", "EFI_IFR_SPAN",
"EFI_IFR_VALUE", "EFI_IFR_DEFAULT", "EFI_IFR_DEFAULTSTORE", "EFI_IFR_INVALID", "EFI_IFR_CATENATE", "EFI_IFR_GUID",
};
VOID
CIFROBJ_DEBUG_PRINT (
IN UINT8 OpCode
)
{
printf ("======Create IFR [%s]\n", gIfrObjPrintDebugTable[OpCode].mIfrName);
}
#else
#define CIFROBJ_DEBUG_PRINT(OpCode)
#endif
bool gCreateOp = TRUE;
CIfrObj::CIfrObj (
IN UINT8 OpCode,
OUT CHAR8 **IfrObj,
IN UINT8 ObjBinLen,
IN BOOLEAN DelayEmit
)
{
mDelayEmit = DelayEmit;
mPkgOffset = gCFormPkg.GetPkgLength ();
mObjBinLen = (ObjBinLen == 0) ? gOpcodeSizesScopeTable[OpCode].mSize : ObjBinLen;
mObjBinBuf = ((DelayEmit == FALSE) && (gCreateOp == TRUE)) ? gCFormPkg.IfrBinBufferGet (mObjBinLen) : new CHAR8[EFI_IFR_MAX_LENGTH];
mRecordIdx = (gCreateOp == TRUE) ? gCIfrRecordInfoDB.IfrRecordRegister (0xFFFFFFFF, mObjBinBuf, mObjBinLen, mPkgOffset) : EFI_IFR_RECORDINFO_IDX_INVALUD;
if (IfrObj != NULL) {
*IfrObj = mObjBinBuf;
}
CIFROBJ_DEBUG_PRINT (OpCode);
}
CIfrObj::~CIfrObj (
VOID
)
{
if ((mDelayEmit == TRUE) && ((gCreateOp == TRUE))) {
_EMIT_PENDING_OBJ ();
}
gCIfrRecordInfoDB.IfrRecordInfoUpdate (mRecordIdx, mLineNo, mObjBinBuf, mObjBinLen, mPkgOffset);
}
/*
* The definition of CIfrObj's member function
*/
UINT8 gScopeCount = 0;
CIfrOpHeader::CIfrOpHeader (
IN UINT8 OpCode,
IN VOID *StartAddr,
IN UINT8 Length
) : mHeader ((EFI_IFR_OP_HEADER *)StartAddr)
{
mHeader->OpCode = OpCode;
mHeader->Length = (Length == 0) ? gOpcodeSizesScopeTable[OpCode].mSize : Length;
mHeader->Scope = (gOpcodeSizesScopeTable[OpCode].mScope + gScopeCount > 0) ? 1 : 0;
}
CIfrOpHeader::CIfrOpHeader (
IN CIfrOpHeader &OpHdr
)
{
mHeader = OpHdr.mHeader;
}
UINT32 CIfrForm::FormIdBitMap[EFI_FREE_FORM_ID_BITMAP_SIZE] = {0, };

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,341 @@
#ifndef _VFRUTILITYLIB_H_
#define _VFRUTILITYLIB_H_
#include "Tiano.h"
#include "string.h"
#include "EfiTypes.h"
#include "EfiVfr.h"
#include "VfrError.h"
#define MAX_NAME_LEN 64
#define DEFAULT_ALIGN 1
#define DEFAULT_PACK_ALIGN 0xFFFFFFFF
#define DEFAULT_NAME_TABLE_ITEMS 1024
#define EFI_BITS_SHIFT_PER_UINT32 0x5
#define EFI_BITS_PER_UINT32 (1 << EFI_BITS_SHIFT_PER_UINT32)
#define BUFFER_SAFE_FREE(Buf) do { if ((Buf) != NULL) { delete (Buf); } } while (0);
class CVfrBinaryOutput {
public:
virtual VOID WriteLine (IN FILE *, IN UINT32, IN INT8 *, IN INT8 *, IN UINT32);
virtual VOID WriteEnd (IN FILE *, IN UINT32, IN INT8 *, IN INT8 *, IN UINT32);
};
UINT32
_STR2U32 (
IN INT8 *Str
);
struct SConfigInfo {
UINT16 mOffset;
UINT16 mWidth;
UINT8 *mValue;
SConfigInfo *mNext;
SConfigInfo (IN UINT8, IN UINT16, IN UINT32, IN EFI_IFR_TYPE_VALUE);
~SConfigInfo (VOID);
};
struct SConfigItem {
INT8 *mId;
INT8 *mInfo;
SConfigInfo *mInfoStrList;
SConfigItem *mNext;
public:
SConfigItem (IN INT8 *, IN INT8 *);
SConfigItem (IN INT8 *, IN INT8 *, IN UINT8, IN UINT16, IN UINT16, IN EFI_IFR_TYPE_VALUE);
virtual ~SConfigItem ();
};
class CVfrBufferConfig {
private:
SConfigItem *mItemListHead;
SConfigItem *mItemListTail;
SConfigItem *mItemListPos;
public:
CVfrBufferConfig (VOID);
virtual ~CVfrBufferConfig (VOID);
virtual UINT8 Register (IN INT8 *, IN INT8 *Info = NULL);
virtual VOID Open (VOID);
virtual BOOLEAN Eof(VOID);
virtual UINT8 Select (IN INT8 *, IN INT8 *Info = NULL);
virtual UINT8 Write (IN CONST CHAR8, IN INT8 *, IN INT8 *, IN UINT8, IN UINT16, IN UINT32, IN EFI_IFR_TYPE_VALUE);
#if 0
virtual UINT8 Read (OUT INT8 **, OUT INT8 **, OUT INT8 **, OUT INT8 **, OUT INT8 **);
#endif
virtual VOID Close (VOID);
virtual VOID OutputCFile (IN FILE *, IN INT8 *);
};
extern CVfrBufferConfig gCVfrBufferConfig;
#define ALIGN_STUFF(Size, Align) ((Align) - (Size) % (Align))
#define INVALID_ARRAY_INDEX 0xFFFFFFFF
struct SVfrDataType;
struct SVfrDataField {
INT8 mFieldName[MAX_NAME_LEN];
SVfrDataType *mFieldType;
UINT32 mOffset;
UINT32 mArrayNum;
SVfrDataField *mNext;
};
struct SVfrDataType {
INT8 mTypeName[MAX_NAME_LEN];
UINT8 mType;
UINT32 mAlign;
UINT32 mTotalSize;
SVfrDataField *mMembers;
SVfrDataType *mNext;
};
class CVfrVarDataTypeDB {
private:
SVfrDataType *mDataTypeList;
UINT32 mPackAlign;
SVfrDataType *mNewDataType;
SVfrDataType *mCurrDataType;
SVfrDataField *mCurrDataField;
VOID InternalTypesListInit (VOID);
VOID RegisterNewType (IN SVfrDataType *);
EFI_VFR_RETURN_CODE ExtractStructTypeName (IN INT8 *&, OUT INT8 *);
EFI_VFR_RETURN_CODE ExtractFieldNameAndArrary (IN INT8 *&, OUT INT8 *, OUT UINT32 &);
EFI_VFR_RETURN_CODE GetTypeField (IN INT8 *, IN SVfrDataType *, IN SVfrDataField *&);
EFI_VFR_RETURN_CODE GetFieldOffset (IN SVfrDataField *, IN UINT32, OUT UINT32 &);
UINT8 GetFieldWidth (IN SVfrDataField *);
UINT32 GetFieldSize (IN SVfrDataField *, IN UINT32);
public:
CVfrVarDataTypeDB (VOID);
~CVfrVarDataTypeDB (VOID);
EFI_VFR_RETURN_CODE Pack (IN UINT32);
VOID UnPack (VOID);
VOID DeclareDataTypeBegin (VOID);
EFI_VFR_RETURN_CODE SetNewTypeName (IN INT8 *);
EFI_VFR_RETURN_CODE DataTypeAddField (IN INT8 *, IN INT8 *, IN UINT32);
VOID DeclareDataTypeEnd (VOID);
EFI_VFR_RETURN_CODE GetDataType (IN INT8 *, OUT SVfrDataType **);
EFI_VFR_RETURN_CODE GetDataTypeSize (IN INT8 *, OUT UINT32 *);
EFI_VFR_RETURN_CODE GetDataFieldInfo (IN INT8 *, OUT UINT16 &, OUT UINT8 &, OUT UINT32 &);
EFI_VFR_RETURN_CODE GetUserDefinedTypeNameList (OUT INT8 ***, OUT UINT32 *);
BOOLEAN IsTypeNameDefined (IN INT8 *);
#ifdef CVFR_VARDATATYPEDB_DEBUG
VOID ParserDB ();
#endif
};
typedef enum {
EFI_VFR_VARSTORE_INVALID,
EFI_VFR_VARSTORE_BUFFER,
EFI_VFR_VARSTORE_EFI,
EFI_VFR_VARSTORE_NAME
} EFI_VFR_VARSTORE_TYPE;
struct SVfrVarStorageNode {
EFI_GUID mGuid;
INT8 *mVarStoreName;
EFI_VARSTORE_ID mVarStoreId;
struct SVfrVarStorageNode *mNext;
EFI_VFR_VARSTORE_TYPE mVarStoreType;
union {
// EFI Variable
struct {
EFI_STRING_ID mEfiVarName;
UINT32 mEfiVarSize;
} mEfiVar;
// Buffer Storage
SVfrDataType *mDataType;
// NameValue Storage
struct {
EFI_STRING_ID *mNameTable;
UINT32 mTableSize;
} mNameSpace;
} mStorageInfo;
public:
SVfrVarStorageNode (IN EFI_GUID *, IN INT8 *, IN EFI_VARSTORE_ID, IN EFI_STRING_ID, IN UINT32);
SVfrVarStorageNode (IN EFI_GUID *, IN INT8 *, IN EFI_VARSTORE_ID, IN SVfrDataType *);
SVfrVarStorageNode (IN INT8 *, IN EFI_VARSTORE_ID);
~SVfrVarStorageNode (VOID);
};
struct EFI_VARSTORE_INFO {
EFI_VARSTORE_ID mVarStoreId;
union {
EFI_STRING_ID mVarName;
UINT16 mVarOffset;
} mInfo;
UINT8 mVarType;
UINT32 mVarTotalSize;
EFI_VARSTORE_INFO (VOID);
EFI_VARSTORE_INFO (IN EFI_VARSTORE_INFO &);
BOOLEAN operator == (IN EFI_VARSTORE_INFO *);
};
#define EFI_VARSTORE_ID_MAX 0xFFFF
#define EFI_FREE_VARSTORE_ID_BITMAP_SIZE ((EFI_VARSTORE_ID_MAX + 1) / EFI_BITS_PER_UINT32)
class CVfrDataStorage {
private:
UINT32 mFreeVarStoreIdBitMap[EFI_FREE_VARSTORE_ID_BITMAP_SIZE];
struct SVfrVarStorageNode *mBufferVarStoreList;
struct SVfrVarStorageNode *mEfiVarStoreList;
struct SVfrVarStorageNode *mNameVarStoreList;
struct SVfrVarStorageNode *mCurrVarStorageNode;
struct SVfrVarStorageNode *mNewVarStorageNode;
private:
EFI_VARSTORE_ID GetFreeVarStoreId (VOID);
BOOLEAN ChekVarStoreIdFree (IN EFI_VARSTORE_ID);
VOID MarkVarStoreIdUsed (IN EFI_VARSTORE_ID);
VOID MarkVarStoreIdUnused (IN EFI_VARSTORE_ID);
public:
CVfrDataStorage ();
~CVfrDataStorage ();
EFI_VFR_RETURN_CODE DeclareNameVarStoreBegin (INT8 *);
EFI_VFR_RETURN_CODE NameTableAddItem (EFI_STRING_ID);
EFI_VFR_RETURN_CODE DeclareNameVarStoreEnd (EFI_GUID *);
EFI_VFR_RETURN_CODE DeclareEfiVarStore (IN INT8 *, IN EFI_GUID *, IN EFI_STRING_ID, IN UINT32);
EFI_VFR_RETURN_CODE DeclareBufferVarStore (IN INT8 *, IN EFI_GUID *, IN CVfrVarDataTypeDB *, IN INT8 *, IN EFI_VARSTORE_ID);
EFI_VFR_RETURN_CODE GetVarStoreId (IN INT8 *, OUT EFI_VARSTORE_ID *);
EFI_VFR_RETURN_CODE GetVarStoreType (IN INT8 *, OUT EFI_VFR_VARSTORE_TYPE &);
EFI_VFR_RETURN_CODE GetVarStoreName (IN EFI_VARSTORE_ID, OUT INT8 **);
EFI_VFR_RETURN_CODE GetBufferVarStoreDataTypeName (IN INT8 *, OUT INT8 **);
EFI_VFR_RETURN_CODE GetEfiVarStoreInfo (IN EFI_VARSTORE_INFO *);
EFI_VFR_RETURN_CODE GetNameVarStoreInfo (IN EFI_VARSTORE_INFO *, IN UINT32);
EFI_VFR_RETURN_CODE BufferVarStoreRequestElementAdd (IN INT8 *, IN EFI_VARSTORE_INFO &);
};
#define EFI_QUESTION_ID_MAX 0xFFFF
#define EFI_FREE_QUESTION_ID_BITMAP_SIZE ((EFI_QUESTION_ID_MAX + 1) / EFI_BITS_PER_UINT32)
#define EFI_QUESTION_ID_INVALID 0x0
#define DATE_YEAR_BITMASK 0x0000FFFF
#define DATE_MONTH_BITMASK 0x00FF0000
#define DATE_DAY_BITMASK 0xFF000000
#define TIME_HOUR_BITMASK 0x000000FF
#define TIME_MINUTE_BITMASK 0x0000FF00
#define TIME_SECOND_BITMASK 0x00FF0000
struct SVfrQuestionNode {
INT8 *mName;
INT8 *mVarIdStr;
EFI_QUESTION_ID mQuestionId;
UINT32 mBitMask;
SVfrQuestionNode *mNext;
SVfrQuestionNode (IN INT8 *, IN INT8 *, IN UINT32 BitMask = 0);
~SVfrQuestionNode ();
};
class CVfrQuestionDB {
private:
SVfrQuestionNode *mQuestionList;
UINT32 mFreeQIdBitMap[EFI_FREE_QUESTION_ID_BITMAP_SIZE];
private:
EFI_QUESTION_ID GetFreeQuestionId (VOID);
BOOLEAN ChekQuestionIdFree (IN EFI_QUESTION_ID);
VOID MarkQuestionIdUsed (IN EFI_QUESTION_ID);
VOID MarkQuestionIdUnused (IN EFI_QUESTION_ID);
public:
CVfrQuestionDB ();
~CVfrQuestionDB();
EFI_VFR_RETURN_CODE RegisterQuestion (IN INT8 *, IN INT8 *, IN OUT EFI_QUESTION_ID &);
VOID RegisterOldDateQuestion (IN INT8 *, IN INT8 *, IN INT8 *, IN OUT EFI_QUESTION_ID &);
VOID RegisterNewDateQuestion (IN INT8 *, IN INT8 *, IN OUT EFI_QUESTION_ID &);
VOID RegisterOldTimeQuestion (IN INT8 *, IN INT8 *, IN INT8 *, IN OUT EFI_QUESTION_ID &);
VOID RegisterNewTimeQuestion (IN INT8 *, IN INT8 *, IN OUT EFI_QUESTION_ID &);
EFI_VFR_RETURN_CODE UpdateQuestionId (IN EFI_QUESTION_ID, IN EFI_QUESTION_ID);
VOID GetQuestionId (IN INT8 *, IN INT8 *, OUT EFI_QUESTION_ID &, OUT UINT32 &);
EFI_VFR_RETURN_CODE FindQuestion (IN EFI_QUESTION_ID);
EFI_VFR_RETURN_CODE FindQuestion (IN INT8 *);
};
struct SVfrDefaultStoreNode {
EFI_IFR_DEFAULTSTORE *mObjBinAddr;
INT8 *mRefName;
EFI_STRING_ID mDefaultStoreNameId;
UINT16 mDefaultId;
SVfrDefaultStoreNode *mNext;
SVfrDefaultStoreNode (IN EFI_IFR_DEFAULTSTORE *, IN INT8 *, IN EFI_STRING_ID, IN UINT16);
~SVfrDefaultStoreNode();
};
class CVfrDefaultStore {
private:
SVfrDefaultStoreNode *mDefaultStoreList;
public:
CVfrDefaultStore ();
~CVfrDefaultStore ();
EFI_VFR_RETURN_CODE RegisterDefaultStore (IN CHAR8 *, IN INT8 *, IN EFI_STRING_ID, IN UINT16);
EFI_VFR_RETURN_CODE ReRegisterDefaultStoreById (IN UINT16, IN INT8 *, IN EFI_STRING_ID);
BOOLEAN DefaultIdRegistered (IN UINT16);
EFI_VFR_RETURN_CODE GetDefaultId (IN INT8 *, OUT UINT16 *);
EFI_VFR_RETURN_CODE BufferVarStoreAltConfigAdd (IN EFI_VARSTORE_ID, IN EFI_VARSTORE_INFO &, IN INT8 *, IN UINT8, IN EFI_IFR_TYPE_VALUE);
};
#define EFI_RULE_ID_START 0x01
#define EFI_RULE_ID_INVALID 0x00
struct SVfrRuleNode {
UINT8 mRuleId;
INT8 *mRuleName;
SVfrRuleNode *mNext;
SVfrRuleNode(IN INT8 *, IN UINT8);
~SVfrRuleNode();
};
class CVfrRulesDB {
private:
SVfrRuleNode *mRuleList;
UINT8 mFreeRuleId;
public:
CVfrRulesDB ();
~CVfrRulesDB();
VOID RegisterRule (IN INT8 *);
UINT8 GetRuleId (IN INT8 *);
};
#define MIN(v1, v2) (((v1) < (v2)) ? (v1) : (v2))
#define MAX(v1, v2) (((v1) > (v2)) ? (v1) : (v2))
#endif

View File

@ -0,0 +1,149 @@
#/*++
#
# Copyright (c) 2004 - 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# makefile
#
# Abstract:
#
# Makefile for building the EFI VFR compiler
#
#--*/
!IFNDEF EDK_SOURCE
!ERROR EDK_SOURCE environmental variable not set
!ENDIF
!IFNDEF TOOLCHAIN
TOOLCHAIN = TOOLCHAIN_MSVC
!ENDIF
!INCLUDE $(BUILD_DIR)\PlatformTools.env
.SUFFIXES :
TARGET_NAME = VfrCompile
ETO = $(EDK_TOOLS_OUTPUT)
SRC = $(EDK_TOOLS_SOURCE)\Uefi$(TARGET_NAME)
TARGET_EXE = $(ETO)\$(TARGET_NAME).exe
INC = -I $(SRC) \
-I $(EDK_SOURCE)\Foundation\Include\Ia32 \
-I $(EDK_SOURCE)\Foundation\Efi\Include \
-I $(EDK_SOURCE)\Foundation\Framework\Include \
-I $(EDK_SOURCE)\Foundation\Include\IndustryStandard \
-I $(EDK_SOURCE)\Foundation\ \
-I $(EDK_SOURCE)\Foundation\Core\Dxe \
-I $(EDK_SOURCE)\Foundation\Efi \
-I $(EDK_SOURCE)\Foundation\Framework \
-I $(EDK_TOOLS_SOURCE)\Common \
-I $(EDK_SOURCE)\Foundation\Include
ANTLR_FLAGS = -CC -e3 -ck 3 -k 2
DLG_FLAGS = -C2 -i -CC
LINK_FLAGS_PCCTS = /DEBUG /PDB:$*.pdb
C_FLAGS_PCCTS = -I. -I$(ANTLR_H) /WX /Od /EHsc /Zi /Fd$(ETO)\$(TARGET_NAME)Obj /D _CRT_SECURE_NO_DEPRECATE $(VERSION_FLAGS) /D PCCTS_USE_NAMESPACE_STD #/D CVFR_VARDATATYPEDB_DEBUG /D CIFROBJ_DEUBG /D VFREXP_DEBUG
VFR_GRAMMER_FILE = $(SRC)\VfrSyntax.g
VFR_ANTLR_SPAWN = $(ETO)\VfrSyntax.cpp \
$(ETO)\EfiVfrParser.cpp \
$(ETO)\EfiVfrParser.h \
$(ETO)\VfrParser.dlg \
$(ETO)\VfrTokens.h
VFR_DLG_SPAWN = $(ETO)\VfrLexer.cpp \
$(ETO)\VfrLexer.h
ANTLR_H = $(PCCTS_DIR)\h
HEADER_FILES = $(SRC)\VfrFormPkg.h \
$(SRC)\EfiVfr.h \
$(SRC)\VfrCompiler.h \
$(SRC)\VfrError.h \
$(SRC)\VfrUtilityLib.h
OBJECTS = $(ETO)\AParser.obj \
$(ETO)\DLexerBase.obj \
$(ETO)\ATokenBuffer.obj \
$(ETO)\VfrSyntax.obj \
$(ETO)\EfiVfrParser.obj \
$(ETO)\VfrLexer.obj \
$(ETO)\VfrFormPkg.obj \
$(ETO)\VfrError.obj \
$(ETO)\VfrUtilityLib.obj \
$(ETO)\VfrCompiler.obj
all : $(TARGET_EXE)
$(VFR_ANTLR_SPAWN) : $(VFR_GRAMMER_FILE)
$(ANTLR) $(ANTLR_FLAGS) -fl VfrParser.dlg -ft VfrTokens.h -o $(ETO) $(VFR_GRAMMER_FILE)
$(VFR_DLG_SPAWN) : $(ETO)\VfrParser.dlg
$(DLG) $(DLG_FLAGS) -cl VfrLexer -o $(ETO) $(ETO)\VfrParser.dlg
$(ETO)\VfrSyntax.obj : $(ETO)\VfrSyntax.cpp $(VFR_DLG_SPAWN)
$(CC) -c $(C_FLAGS_PCCTS) /Fo$@ $(INC) $(ETO)\VfrSyntax.cpp
$(ETO)\EfiVfrParser.obj : $(ETO)\EfiVfrParser.cpp $(ETO)\EfiVfrParser.h $(VFR_DLG_SPAWN)
$(CC) -c $(C_FLAGS_PCCTS) /Fo$@ $(INC) $(ETO)\EfiVfrParser.cpp
$(ETO)\AParser.obj : $(ANTLR_H)\AParser.cpp
$(CC) -c $(C_FLAGS_PCCTS) /Fo$@ $(ANTLR_H)\AParser.cpp
$(ETO)\ATokenBuffer.obj : $(ANTLR_H)\ATokenBuffer.cpp
$(CC) -c $(C_FLAGS_PCCTS) /Fo$@ $(ANTLR_H)\ATokenBuffer.cpp
$(ETO)\DLexerBase.obj : $(ANTLR_H)\DLexerBase.cpp
$(CC) -c $(C_FLAGS_PCCTS) /Fo$@ $(ANTLR_H)\DLexerBase.cpp
$(ETO)\VfrLexer.obj : $(ETO)\VfrLexer.cpp $(VFR_DLG_SPAWN)
$(CC) -c $(C_FLAGS_PCCTS) /Fo$@ $(INC) $(ETO)\VfrLexer.cpp
$(ETO)\VfrFormPkg.obj : $(SRC)\VfrFormPkg.cpp $(HEADER_FILES)
$(CC) -c $(C_FLAGS_PCCTS) $(INC) /Fo$@ $(SRC)\VfrFormPkg.cpp
$(ETO)\VfrError.obj : $(SRC)\VfrError.cpp $(HEADER_FILES)
$(CC) -c $(C_FLAGS_PCCTS) $(INC) /Fo$@ $(SRC)\VfrError.cpp
$(ETO)\VfrUtilityLib.obj : $(SRC)\VfrUtilityLib.cpp $(HEADER_FILES)
$(CC) -c $(C_FLAGS_PCCTS) $(INC) /Fo$@ $(SRC)\VfrUtilityLib.cpp
$(ETO)\VfrCompiler.obj : $(SRC)\VfrCompiler.cpp $(HEADER_FILES)
$(CC) -c $(C_FLAGS_PCCTS) $(INC) /Fo$@ $(SRC)\VfrCompiler.cpp
#
# Add Binary Build description for this tools.
#
!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
$(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe $(TARGET_EXE) /Y
if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
!ELSE
$(TARGET_EXE) : $(OBJECTS) $(HEADER_FILES)
$(LINK) $(MSVS_LINK_LIBPATHS) $(LINK_FLAGS_PCCTS) /OUT:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:

View File

@ -82,11 +82,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean:
@if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL

View File

@ -162,11 +162,13 @@ $(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
!ELSE
$(TARGET_EXE) : $(OBJECTS) $(LIBS)
$(LINK) $(MSVS_LINK_LIBPATHS) $(LIBS) /DEBUG /OUT:$(TARGET_EXE) $(LINK_FLAGS_PCCTS) $(OBJECTS) /PDB:$*.pdb
!IF ("$(EFI_BINARY_BUILD)" == "YES")
if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
!ENDIF
!ENDIF
clean: