diff options
author | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
---|---|---|
committer | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
commit | b7c51c9cf4864df6aabb99a1ae843becd577237c (patch) | |
tree | eebe9b0d0ca03062955223097e57da84dd618b9a /Core/EM/OFBD/SecureFlash | |
download | zprj-master.tar.xz |
Diffstat (limited to 'Core/EM/OFBD/SecureFlash')
-rw-r--r-- | Core/EM/OFBD/SecureFlash/SecureFlash.c | 343 | ||||
-rw-r--r-- | Core/EM/OFBD/SecureFlash/SecureFlash.chm | bin | 0 -> 29136 bytes | |||
-rw-r--r-- | Core/EM/OFBD/SecureFlash/SecureFlash.cif | 12 | ||||
-rw-r--r-- | Core/EM/OFBD/SecureFlash/SecureFlash.h | 68 | ||||
-rw-r--r-- | Core/EM/OFBD/SecureFlash/SecureFlash.mak | 76 | ||||
-rw-r--r-- | Core/EM/OFBD/SecureFlash/SecureFlash.sdl | 51 |
6 files changed, 550 insertions, 0 deletions
diff --git a/Core/EM/OFBD/SecureFlash/SecureFlash.c b/Core/EM/OFBD/SecureFlash/SecureFlash.c new file mode 100644 index 0000000..f787d33 --- /dev/null +++ b/Core/EM/OFBD/SecureFlash/SecureFlash.c @@ -0,0 +1,343 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/OFBD Secure Flash/SecureFlash.c 7 1/17/12 10:24p Lawrencechang $ +// +// $Revision: 7 $ +// +// $Date: 1/17/12 10:24p $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/OFBD Secure Flash/SecureFlash.c $ +// +// 7 1/17/12 10:24p Lawrencechang +// Remove unnecessary header file. +// +// 6 1/04/12 7:14a Lawrencechang +// Remove runtime flash codes, which will be done by SMIFlash protocol. +// +// 5 12/21/11 8:17a Lawrencechang +// 1. Check if SMIFlash module exists or enables before install SMIFlash +// protocol. +// 2. Add WriteBlockEx() for SMIFlash protocol compatibility. +// WriteBlockEx() will be only used in SMIFlash protocol but no exposed to +// flash ROM interface. +// +// 4 10/29/11 5:26a Lawrencechang +// Modified for adding SMIFlash protocol compatibility. +// +// 3 10/28/11 4:28a Lawrencechang +// Add GetFlashInfo() for compatibility with SMIFlash protocol. Only works +// with 4.6.3.2_OFBD.1.0.2. +// +// 2 10/18/11 3:11a Lawrencechang +// Force LoadFirmwareImage(), GetFlashUpdatePolicy() and +// SetFlashUpdateMethod() to return correct error code. +// +// 1 9/16/11 4:25a Lawrencechang +// Initial check-in. +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: SecureFlash.c +// +// Description: This file provides OFBD Secure Flash function. +// +//<AMI_FHDR_END> +//********************************************************************** +#include <EFI.h> +#include <Token.h> +#include <AmiDxeLib.h> +#include <Protocol/SecSmiFlash.h> +#include <Protocol/FlashProtocol.h> + +#include <OFBD.h> +#include <SecureFlash.h> + +// GUIDs of consumed protocols +static EFI_GUID gEfiSmiFlashProtocolGuid = EFI_SMI_FLASH_GUID; +static EFI_GUID gEfiSecSmiFlashProtocolGuid = EFI_SEC_SMI_FLASH_GUID; + +// Consumed protocols +EFI_SEC_SMI_FLASH_PROTOCOL *SecSmiFlash = NULL; +FLASH_PROTOCOL *Flash = NULL; + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: LoadFirmwareImage +// +// Description: Transfer ROM image from AFU's buffer to Secure Flash Module +// through EFI_SEC_SMI_FLASH_PROTOCOL. +// +// Input: +// IN VOID *Data The data is a memory buffer. Its content is FUNC_BLOCK +// defined in SmiFlash.h. The member function +// LOAD_FLASH_IMAGE in EFI_SEC_SMI_FLASH_PROTOCOL only +// accepts this type of parameter. +// +// Output: +// EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS LoadFirmwareImage ( + VOID *Data +) +{ + EFI_STATUS Status; + + if (NULL == SecSmiFlash) return EFI_UNSUPPORTED; + + Status = SecSmiFlash->LoadFwImage((FUNC_BLOCK *)Data); + + ((FUNC_BLOCK *)Data)->ErrorCode = (EFI_ERROR(Status) ? 1 : 0); + + return Status; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: GetFlashUpdatePolicy +// +// Description: Get Flash Update Policy from Secure Flash module. +// +// Input: +// IN VOID *Data The data is a memory buffer. Its content is +// FLASH_POLICY_INFO_BLOCK defined in SecSmiFlash.h. +// +// Output: +// EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS GetFlashUpdatePolicy ( + VOID *Data +) +{ + EFI_STATUS Status; + FLASH_POLICY_INFO_BLOCK *pFlashPolicy = (FLASH_POLICY_INFO_BLOCK *)Data; + + if (NULL == SecSmiFlash) return EFI_UNSUPPORTED; + + Status = SecSmiFlash->GetFlUpdPolicy(pFlashPolicy); + + pFlashPolicy->ErrorCode = (EFI_ERROR(Status) ? 1 : 0); + + return Status; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: SetFlashUpdateMethod +// +// Description: Set Flash Update Policy to Secure Flash module. +// +// Input: +// IN VOID *Data The data is a memory buffer. Its content is +// FUNC_FLASH_SESSION_BLOCK defined in SecSmiFlash.h. +// +// Output: +// EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS SetFlashUpdateMethod ( + VOID *Data +) +{ + EFI_STATUS Status; + FUNC_FLASH_SESSION_BLOCK *pFlashSessionBlock = (FUNC_FLASH_SESSION_BLOCK *)Data; + + if (NULL == SecSmiFlash) return EFI_UNSUPPORTED; + + Status = SecSmiFlash->SetFlUpdMethod(pFlashSessionBlock); + + pFlashSessionBlock->ErrorCode = (EFI_ERROR(Status) ? 1 : 0); + + return Status; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: SecureFlashProtocolCallback +// +// Description: Locate SecSmiFlash protocol callback +// +// Input: +// IN EFI_EVENT Event +// IN VOID *Context +// +// Output: +// VOID +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID SecureFlashProtocolCallback ( + IN EFI_EVENT Event, + IN VOID *Context +) +{ + pBS->LocateProtocol(&gEfiSecSmiFlashProtocolGuid, NULL, &SecSmiFlash); + pBS->CloseEvent(Event); +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: SmmFlashProtocolCallback +// +// Description: Locate Flash protocol callback +// +// Input: +// IN EFI_EVENT Event +// IN VOID *Context +// +// Output: +// VOID +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID SmmFlashProtocolCallback ( + IN EFI_EVENT Event, + IN VOID *Context +) +{ + pBS->LocateProtocol(&gFlashSmmProtocolGuid, NULL, &Flash); + pBS->CloseEvent(Event); +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------- +// Procedure: ASFUInSmm +// +// Description: This function installs the ASFU Protocol. +// +// Input: +// VOID +// +// Output: +// VOID +// +//---------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID ASFUInSmm ( + VOID +) +{ + EFI_STATUS Status; + EFI_HANDLE DummyHandle = NULL; + + Status = pBS->LocateProtocol(&gEfiSecSmiFlashProtocolGuid, NULL, &SecSmiFlash); + if (EFI_ERROR(Status)) { + EFI_EVENT SecFlashCallbackEvt; + VOID *Reg; + RegisterProtocolCallback( + &gEfiSecSmiFlashProtocolGuid, + SecureFlashProtocolCallback, + NULL, + &SecFlashCallbackEvt, + &Reg); + } + + Status = pBS->LocateProtocol(&gFlashSmmProtocolGuid, NULL, &Flash); + if (EFI_ERROR(Status)) { + EFI_EVENT SmmFlashCallbackEvt; + VOID *Reg; + RegisterProtocolCallback( + &gFlashSmmProtocolGuid, + SmmFlashProtocolCallback, + NULL, + &SmmFlashCallbackEvt, + &Reg); + } + + return; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: ASFUEntry +// +// Description: OFBD Secure Flash Update Entry point +// +// Input: +// IN VOID *Buffer +// IN OUT UINT8 *pOFBDDataHandled +// +// Output: +// VOID +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID ASFUEntry ( + IN VOID *Buffer, + IN OUT UINT8 *pOFBDDataHandled +) +{ + OFBD_HDR *pOFBDHdr; + OFBD_EXT_HDR *pOFBDExtHdr; + VOID *pOFBDTblEnd; + OFBD_TC_70_SFU_STRUCT *ASFUStructPtr; + EFI_STATUS Status = EFI_SUCCESS; + + if (*pOFBDDataHandled == 0) { + pOFBDHdr = (OFBD_HDR *)Buffer; + pOFBDExtHdr = (OFBD_EXT_HDR *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_HDR_SIZE)); + ASFUStructPtr = (OFBD_TC_70_SFU_STRUCT *)((UINT8 *)pOFBDExtHdr + sizeof(OFBD_EXT_HDR)); + pOFBDTblEnd = (VOID *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_Size)); + + if (pOFBDHdr->OFBD_FS & OFBD_FS_SFU) { + //Check Type Code ID + if (pOFBDExtHdr->TypeCodeID == OFBD_EXT_TC_SFU) { + switch (ASFUStructPtr->Command) { + case OFBD_TC_SFU_LOAD_FIRMWARE_IMAGE : + Status = LoadFirmwareImage(pOFBDTblEnd); + break; + case OFBD_TC_SFU_GET_FLASH_UPDATE_POLICY : + Status = GetFlashUpdatePolicy(pOFBDTblEnd); + break; + case OFBD_TC_SFU_SET_FLASH_UPDATE_METHOD : + Status = SetFlashUpdateMethod(pOFBDTblEnd); + break; + default : + Status = EFI_UNSUPPORTED; + break; + } + if (EFI_ERROR(Status)) { + *pOFBDDataHandled = 0xFE; + ASFUStructPtr->Status = OFBD_TC_SFU_NOT_SUPPORTED; + } else { + *pOFBDDataHandled = 0xFF; + ASFUStructPtr->Status = OFBD_TC_SFU_OK; + } + } + } + } +} + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/Core/EM/OFBD/SecureFlash/SecureFlash.chm b/Core/EM/OFBD/SecureFlash/SecureFlash.chm Binary files differnew file mode 100644 index 0000000..1d3bd8d --- /dev/null +++ b/Core/EM/OFBD/SecureFlash/SecureFlash.chm diff --git a/Core/EM/OFBD/SecureFlash/SecureFlash.cif b/Core/EM/OFBD/SecureFlash/SecureFlash.cif new file mode 100644 index 0000000..feed7f2 --- /dev/null +++ b/Core/EM/OFBD/SecureFlash/SecureFlash.cif @@ -0,0 +1,12 @@ +<component> + name = "On Flash Block Description (APTIO) - Secure Flash" + category = eModule + LocalRoot = "Core\EM\OFBD\SecureFlash\" + RefName = "OFBD_SECURE_FLASH" +[files] +"SecureFlash.sdl" +"SecureFlash.mak" +"SecureFlash.h" +"SecureFlash.c" +"SecureFlash.chm" +<endComponent> diff --git a/Core/EM/OFBD/SecureFlash/SecureFlash.h b/Core/EM/OFBD/SecureFlash/SecureFlash.h new file mode 100644 index 0000000..99b251e --- /dev/null +++ b/Core/EM/OFBD/SecureFlash/SecureFlash.h @@ -0,0 +1,68 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/OFBD Secure Flash/SecureFlash.h 3 1/04/12 7:12a Lawrencechang $ +// +// $Revision: 3 $ +// +// $Date: 1/04/12 7:12a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/OFBD Secure Flash/SecureFlash.h $ +// +// 3 1/04/12 7:12a Lawrencechang +// Remove SMIFlash related codes. +// +// 2 10/29/11 5:29a Lawrencechang +// Modified for adding SMIFlash protocol compatibility. +// +// 1 9/16/11 4:25a Lawrencechang +// Initial check-in. +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: SecureFlash.h +// +// Description: Header file for OFBD Secure Flash module. +// +//<AMI_FHDR_END> +//********************************************************************** +#ifndef _EFI_ASFU_H_ +#define _EFI_ASFU_H_ +#ifdef __cplusplus +extern "C" { +#endif + +/****** DO NOT WRITE BELOW THIS LINE *******/ +#ifdef __cplusplus +} +#endif +#endif + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/Core/EM/OFBD/SecureFlash/SecureFlash.mak b/Core/EM/OFBD/SecureFlash/SecureFlash.mak new file mode 100644 index 0000000..337cf61 --- /dev/null +++ b/Core/EM/OFBD/SecureFlash/SecureFlash.mak @@ -0,0 +1,76 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/SOURCE/Modules/OFBD Secure Flash/SecureFlash.mak 4 1/04/12 7:11a Lawrencechang $ +# +# $Revision: 4 $ +# +# $Date: 1/04/12 7:11a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/OFBD Secure Flash/SecureFlash.mak $ +# +# 4 1/04/12 7:11a Lawrencechang +# Remove SMIFlash related make rules. +# +# 3 10/29/11 5:30a Lawrencechang +# Modified for adding SMIFlash protocol compatibility. +# +# 2 10/03/11 2:36a Lawrencechang +# Modify path of SecSMIFlashHook.obj to adapt the latest version +# SecureFlashPkg. +# +# 1 9/16/11 4:25a Lawrencechang +# Initial check-in. +# +#************************************************************************* +#<AMI_FHDR_START> +# +# Name: SecureFlash.mak +# +# Description: Make file for OFBD Secure Flash module. +# +#<AMI_FHDR_END> +#************************************************************************* + +$(OFBD_SECUREFLASH_LIB) : $(BUILD_DIR)\SecureFlash.mak OFBD_SECUREFLASH_BIN + +OFBD_SECFLASH_EXT_INCLUDES = \ + /I $(OFBD_DIR)\ + /I $(OFBD_SECURE_FLASH_DIR) + +$(BUILD_DIR)\SecureFlash.mak : $(OFBD_SECURE_FLASH_DIR)\$(@B).cif + $(CIF2MAK) $(OFBD_SECURE_FLASH_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +OFBD_SECUREFLASH_BIN : $(AMIDXELIB) $(FLASHLIB) $(OFBD_EXT_OBJS) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\SecureFlash.mak all\ + "MY_INCLUDES=$(OFBD_SECFLASH_EXT_INCLUDES)"\ + NAME=SecureFlash TYPE=LIBRARY LIBRARY_NAME=$(OFBD_SECUREFLASH_LIB) + +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/Core/EM/OFBD/SecureFlash/SecureFlash.sdl b/Core/EM/OFBD/SecureFlash/SecureFlash.sdl new file mode 100644 index 0000000..da1b3c5 --- /dev/null +++ b/Core/EM/OFBD/SecureFlash/SecureFlash.sdl @@ -0,0 +1,51 @@ +TOKEN + Name = SECURE_FLASH_SUPPORT + Value = "1" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes + Help = "Main switch to enable Security Flash in Project" + Token = "SecSMIFlash_SUPPORT" "=" "1" +End + +TOKEN + Name = "OFBD_SECUREFLASH_LIB" + Value = "$(BUILD_DIR)\OfbdSecureFlash.lib" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "[OFBD Security Update]" + Help = "See detail description in each token's help box." + TokenType = Expression + Lock = Yes +End + +PATH + Name = "OFBD_SECURE_FLASH_DIR" +End + +MODULE + Help = "Includes SecureFlash.mak to Project" + File = "SecureFlash.mak" +End + +ELINK + Name = "$(OFBD_SECUREFLASH_LIB)" + Parent = "OFBDLISTLIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "ASFUEntry," + Parent = "OFBDPartsList" + InvokeOrder = AfterParent +End + +ELINK + Name = "ASFUInSmm," + Parent = "OFBDInSmmFuncList" + InvokeOrder = AfterParent +End |