summaryrefslogtreecommitdiff
path: root/Core/EM/FastBoot/FastBootDxe.c
blob: 7c158b253a8b6056b758477f0051fd8b0c7bc538 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//*************************************************************************
// $Header: /Alaska/SOURCE/Modules/PTT/FastBootDxe.c 2     4/07/11 8:20a Bibbyyeh $
//
// $Revision: 2 $
//
// $Date: 4/07/11 8:20a $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/PTT/FastBootDxe.c $
// 
// 2     4/07/11 8:20a Bibbyyeh
// [TAG]  		EIP57430
// [Category]  	New Feature
// [Description]  	PTT module is not compatible with core 4.6.5.0. Modify
// it to make build pass.
// [Files]  		FastBootDxe.c
// 
// 1     3/02/11 2:23a Bibbyyeh
// [TAG]  		EIP51391
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	In windows, use DmiEdit to change SMBIOS data, and update.
// SMBIOS will update failure in next boot.
// [RootCause]  	The reason cause this issue is, ROM will copy to ram in
// end of PEI phase. When SMBIOS Dxe driver update modified data to flash,
// the firmware volume block protocol is pointer to RAM, not flash. So it
// will cause update failure.
// [Solution]  	Before SMBIOS Dxe driver, restore the Base Address of
// Firmware Volume Block Protocol from RAM to ROM.
// [Files]         FastBoot.sdl FastBoot.mak FastBoot.cif FastBootDxe.c
// 
//
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:  FastBootDxe.c
//
//  Description:
//  Implementation of fast boot Dxe functionality
//
//<AMI_FHDR_END>
//*************************************************************************
//----------------------------------------------------------------------------
// Includes
// Statements that include other files
#include <AmiDxeLib.h>
#include <AmiCspLib.h>
#include <Protocol\FirmwareVolumeBlock.h>
#include <FFS.h>
//----------------------------------------------------------------------------
// Function Externs

//----------------------------------------------------------------------------
// Local prototypes
typedef struct {
  UINTN                       Base;
  UINTN                       Length;
} LBA_CACHE;

typedef struct {
  MEMMAP_DEVICE_PATH          MemMapDevPath;
  EFI_DEVICE_PATH_PROTOCOL    EndDevPath;
} FV_DEVICE_PATH;


typedef struct {
  UINTN                                 Signature;
  EFI_HANDLE                            Handle;
  FV_DEVICE_PATH                        DevicePath;
  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    FwVolBlockInstance;
  UINTN                                 NumBlocks;
  LBA_CACHE                             *LbaCache;
  UINT32                                FvbAttributes;
  EFI_PHYSICAL_ADDRESS                  BaseAddress;
} EFI_FW_VOL_BLOCK_DEVICE;

#define FVB_DEVICE_SIGNATURE       EFI_SIGNATURE_32('_','F','V','B')

#ifndef _CR
#define _CR(Record, TYPE, Field)  ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
#endif
#ifndef CR
#define CR(Record, TYPE, Field, Signature)  _CR (Record, TYPE, Field)
#endif

#define FVB_DEVICE_FROM_THIS(a) \
  CR(a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)


//----------------------------------------------------------------------------
// Local Variables
//----------------------------------------------------------------------------
// Function Definitions
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   FastBootDxeEntry
//
// Description: DXE Entry Point for FastBoot Driver.
//
// Input:       EFI_HANDLE          - ImageHandle
//              EFI_SYSTEM_TABLE*   - SystemTable
//
// Output:      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
FastBootDxeEntry (
  IN EFI_HANDLE             ImageHandle,
  IN EFI_SYSTEM_TABLE       *SystemTable
)
{

    EFI_GUID    EfiFirmwareVolumeBlockProtocolGuid = FW_VOLUME_BLOCK_PROTOCOL_GUID;
    EFI_STATUS              Status;
    UINTN                   NumHandles;
    UINT8                   i;

	EFI_HANDLE				*HandleBuffer;
    EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
    EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *FvBlock;


    InitAmiLib(ImageHandle, SystemTable);

    TRACE((-1,"FB:Restore the Base Address of Firmware Volume Block Protocol from RAM to ROM\n"));
// Restore the Base Address of Firmware Volume Block Protocol from RAM 
// to ROM.
    Status = pBS->LocateHandleBuffer ( ByProtocol, \
                                       &EfiFirmwareVolumeBlockProtocolGuid, \
                                       NULL, \
                                       &NumHandles, \
                                       &HandleBuffer    );
	if (EFI_ERROR(Status)) return Status;

    for (i = 0; i < NumHandles; ++i) {
        Status = pBS->HandleProtocol ( HandleBuffer[i], \
                                       &EfiFirmwareVolumeBlockProtocolGuid, \
                                       &FvBlock );
        if (EFI_ERROR(Status)) continue;
        FvbDevice = FVB_DEVICE_FROM_THIS (FvBlock);
#if PI_SPECIFICATION_VERSION < 0x00010000
        if (!(FvbDevice->FvbAttributes & EFI_FVB_MEMORY_MAPPED)) continue;
#else
        if (!(FvbDevice->FvbAttributes & EFI_FVB2_MEMORY_MAPPED)) continue;
#endif
        if (FvbDevice->NumBlocks == FV_BB_BLOCKS)
            FvbDevice->BaseAddress = FV_BB_BASE;
        else if (FvbDevice->NumBlocks == FV_MAIN_BLOCKS)    
            FvbDevice->BaseAddress = FV_MAIN_BASE;            
 
    }

    return EFI_SUCCESS;
}
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2009, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************