summaryrefslogtreecommitdiff
path: root/Core/CPU/MicrocodeUpdate/FwhFvb.c
blob: 94502728b60db88fc3f5200752232de9daf02707 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1987-2013, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//****************************************************************************
// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/CPU Core/MicrocodeUpdate/FwhFvb.c 1     2/07/12 3:59a Davidhsieh $
//
// $Revision: 1 $
//
// $Date: 2/07/12 3:59a $
//
//****************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/CPU Core/MicrocodeUpdate/FwhFvb.c $
// 
// 1     2/07/12 3:59a Davidhsieh
// 
//****************************************************************************

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		FwhFvb.c
//
// Description:	
//  This file contains code for flash update used by the MicrocodeUpdate module.
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#include <Efi.h>
#include "Flash.h"
#include "Token.h"


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	FwhFvbErase
//
// Description:	This function erases a block of NVRAM.
//
// Input:	    Address - Address of the block to erase
//
// Output:		Return Status based on errors that occurred while erasing.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS FwhErase(
    IN UINTN      Address,
    IN UINTN      NumberOfBytes
)
{
    UINTN FlashBlockStart = BLOCK(Address);
    UINTN FlashBlockEnd = BLOCK(Address + NumberOfBytes - 1);
    UINTN FlashBlock;
    BOOLEAN bStatus;

    FlashDeviceWriteEnable();

    for (FlashBlock = FlashBlockStart; FlashBlock <= FlashBlockEnd; FlashBlock += FLASH_BLOCK_SIZE) {
        FlashBlockWriteEnable((UINT8*)FlashBlock);
		bStatus = FlashEraseBlock((UINT8*)FlashBlock);
        FlashBlockWriteDisable((UINT8*)FlashBlock);
        if (!bStatus) break;
    }

    FlashDeviceWriteDisable();

    return bStatus ? EFI_SUCCESS : EFI_DEVICE_ERROR;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	FwhWrite
//
// Description:	This function writes a block of NVRAM.
//
// Input:	    Address       - Address of the block to write.
//              Buffer        - Pointer to a buffer containing data to write.
//              NumberOfBytes - The number of bytes to write
//
// Output:		Return Status based on errors that occurred while writing.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS FwhWrite(
    IN UINT8      *Buffer, 
    IN UINTN      Address, 
    IN UINTN      NumberOfBytes
)
{
    BOOLEAN  bStatus;
    UINTN FlashBlockStart = BLOCK(Address);
    UINTN FlashBlockEnd = BLOCK(Address + NumberOfBytes - 1);
    UINTN FlashBlock;

    FlashDeviceWriteEnable();

    for (FlashBlock = FlashBlockStart; FlashBlock <= FlashBlockEnd; FlashBlock += FLASH_BLOCK_SIZE) {
        FlashBlockWriteEnable((UINT8*)FlashBlock);
    }


    bStatus = FlashProgram((UINT8*)Address, Buffer, (UINT32)NumberOfBytes);


    for (FlashBlock = FlashBlockStart; FlashBlock <= FlashBlockEnd; FlashBlock += FLASH_BLOCK_SIZE) {
        FlashBlockWriteDisable((UINT8*)FlashBlock);
    }

    FlashDeviceWriteDisable();

    return bStatus ? EFI_SUCCESS : EFI_DEVICE_ERROR;
}

//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1987-2013, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************