summaryrefslogtreecommitdiff
path: root/Core/EM/OFBD/OEMROMHOLE/OEMROMHOLE.c
blob: a129d72da3047b6b07652cd36b90d64c89503b68 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (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/OEMROMHOLE/OEMROMHOLE.c 3     3/16/11 10:33p Terrylin $
//
// $Revision: 3 $
//
// $Date: 3/16/11 10:33p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/OFBD/OEMROMHOLE/OEMROMHOLE.c $
// 
// 3     3/16/11 10:33p Terrylin
// [TAG]  		EIP51285
// [Category]  	Improvement
// [Description]  	Fill the description for user more clearly.
// [Files]  		OEMROMHOLE.mak
// OEMROMHOLE.c
// OEMROMHOLE.h
// 
// 2     1/11/10 4:00a Lawrencechang
// Solve compiling warning about type casting from UINTN to UINT16.
// 
// 1     12/16/09 12:51a Lawrencechang
// Initial check-in.
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name:    OEMROMHOLE.c
//
// Description: 
// Unlike the same name module in CORE8. Due to AFUAPTIO has ability to identify ROM hole location and size in ROM
// file. This function is only used to provide AFU the messages to show on screen if user tries to flash sesitive data
// in ROM hole.
//
//<AMI_FHDR_END>
//**********************************************************************
#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include "OEMROMHOLE.h"
#include "..\OFBD.h"

static UINT16 dwOFBDTblEndOffset = 0;

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   OFBDOemStrHandle
//
// Description: OFBD OEM STRING Handle
// 
// This routine will output the OEM String message to the flash utility.
//
// Input:
//      IN OUT  OFBD_HDR    *pOFBDHdr
//      IN      char        *OEMSTR
//      IN      EFI_GUID    *ROMHOLEGUID
//      IN      BOOLEAN     IsAppend
// Output:
//      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
OFBDOemStrHandle(
    IN OUT OFBD_HDR *pOFBDHdr,
    IN char *OEMSTR,
    IN EFI_GUID * ROMHOLEGUID,
    IN BOOLEAN IsAppend)
{
    EFI_STATUS Status = EFI_SUCCESS;
    OFBD_TC_50_RH_STRUCT *RomHoleStructPtr;
    UINT8 *pOFBDTblEnd;
    
    RomHoleStructPtr = (OFBD_TC_50_RH_STRUCT *)((UINT8 *)pOFBDHdr + pOFBDHdr->OFBD_HDR_SIZE + sizeof(OFBD_EXT_HDR)); 
    pOFBDTblEnd = (UINT8 *)((UINT8 *)pOFBDHdr + (pOFBDHdr->OFBD_Size));
    
    if (MemCmp(&(RomHoleStructPtr->HoleGuid), ROMHOLEGUID, sizeof(EFI_GUID)) == 0)
    {
        if (IsAppend == 0 && dwOFBDTblEndOffset > 0) {
            Strcpy((char *)pOFBDTblEnd+dwOFBDTblEndOffset, "\n");
            dwOFBDTblEndOffset += (UINT16)Strlen("\n");
            Strcpy((char *)pOFBDTblEnd+dwOFBDTblEndOffset, OEMSTR);
        }else
            Strcpy((char *)pOFBDTblEnd+dwOFBDTblEndOffset, OEMSTR);
        dwOFBDTblEndOffset += (UINT16)Strlen(OEMSTR);
        pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
    }

    return(Status);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   OFBDRomHoleCheckHandle
//
// Description: OFBD Rom Hole Check Handle
//
// Input:
//      IN OUT OFBD_HDR *pOFBDHdr
// Output:
//      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
OFBDRomHoleCheckHandle(
    IN OUT OFBD_HDR *pOFBDHdr)
{
    EFI_STATUS Status = EFI_SUCCESS;
    
    //
    // About OEM RomHole Message, PLEASE FOLLOW BELOW 3 Steps TO DO. +>>> <OEM_STR>
    //
#if OEM_ROM_HOLE_SAMPLE_TEST

    OFBD_TC_50_RH_STRUCT *RHPtr;  
//
//  Step 1: Add your RomHole OEM string message for AFU to display
//
    char *DisOemStr0Protect = "RomHole 0 is Protected!";
    char *DisOemStr0Program = "RomHole 0 is Programming!";
    char *DisOemStr1Protect = "RomHole 1 is Protected!";
    char *DisOemStr1Program = "RomHole 1 is Programming!";
    char *DisOemStrNewLine = "After next line ";
    char *DisOemStrAppend  = "& Test!";
//
//  Step 2: Add your RomHole GUID definition here for AFU to compare
//
//  For example :
//                EFI_GUID gEfiRomHoleX = OEM_ROM_HOLE_X_GUID;    // Specific Rom Hole X Guid
//
//  Notice: X range should be 0~7. ( Max of 8 RomHole support )
//
    EFI_GUID gEfiRomHole0 = OEM_ROM_HOLE_0_GUID;    // Specific Rom Hole 0 Guid
    EFI_GUID gEfiRomHole1 = OEM_ROM_HOLE_1_GUID;    // Specific Rom Hole 1 Guid

    // --------------------------------------------------------------------------------------------------
    // DO NOT MODIFY +>>>>
    // --------------------------------------------------------------------------------------------------
    RHPtr = (OFBD_TC_50_RH_STRUCT *)((UINT8 *)pOFBDHdr + pOFBDHdr->OFBD_HDR_SIZE + sizeof(OFBD_EXT_HDR));    
    dwOFBDTblEndOffset = 0;
    // --------------------------------------------------------------------------------------------------
    // DO NOT MODIFY <<<<+
    // --------------------------------------------------------------------------------------------------

//
//  Step 3: Define your RomHole message to the corresponding AFU commands.
//    
//  Notice: OFBD_TC_CFG_XXX reference from OFBD.H file (Type Code 51 Return Status)
//
    //
    // Sample 1: AFU issued the /Hole command to update the specific Rom Hole
    //
    if (RHPtr->ddExtCmd == OFBD_TC_CFG_ROMHOLE)
    {
        //  Display the OEM message
        OFBDOemStrHandle(pOFBDHdr, DisOemStr0Program, &gEfiRomHole0, 0);
        OFBDOemStrHandle(pOFBDHdr, DisOemStr1Program, &gEfiRomHole1, 0);
    }
    //
    // Sample 2: AFU issued the /P or /B command to update the FV_MAIN or FV_BB region (default the Rom Hole is been protected.)
    //
    if (RHPtr->ddExtCmd == OFBD_TC_CFG_P || RHPtr->ddExtCmd == OFBD_TC_CFG_B)
    {
        //  Display the OEM message
        OFBDOemStrHandle(pOFBDHdr, DisOemStr0Protect, &gEfiRomHole0, 0);
        OFBDOemStrHandle(pOFBDHdr, DisOemStr1Protect, &gEfiRomHole1, 0);
        OFBDOemStrHandle(pOFBDHdr, DisOemStrNewLine, &gEfiRomHole0, 0);
        OFBDOemStrHandle(pOFBDHdr, DisOemStrAppend, &gEfiRomHole0, 1);
    }
    
#endif // #if OEM_ROM_HOLE_SAMPLE_TEST
    // About OEM RomHole Message, PLEASE FOLLOW ABOVE 3 Steps TO DO. <<<+ <OEM_STR>
    
    return(Status);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   OEMROMHOLEEntry
//
// Description: OFBD OEM ROM HOLE Entry Point
//
// Input:
//      IN VOID             *Buffer
//      IN OUT UINT8        *pOFBDDataHandled
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID OEMROMHOLEEntry (
    IN VOID             *Buffer,
    IN OUT UINT8        *pOFBDDataHandled )
{
    OFBD_HDR *pOFBDHdr;
    OFBD_EXT_HDR *pOFBDExtHdr; 

    if(*pOFBDDataHandled == 0)
    {
        pOFBDHdr = (OFBD_HDR *)Buffer;
        pOFBDExtHdr = (OFBD_EXT_HDR *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_HDR_SIZE));
        
        if(pOFBDHdr->OFBD_FS & OFBD_FS_ROMH)
        {   
            //Check Type Code ID
            if(pOFBDExtHdr->TypeCodeID == OFBD_EXT_TC_ROMHOLE)
            {                  
                if(OFBDRomHoleCheckHandle(pOFBDHdr) == EFI_SUCCESS)
                {
                    //OEM ROM HOLE Data Handled.
                    *pOFBDDataHandled = 0xFF;      
                    return;
                }
            } 
            //Error occured
            *pOFBDDataHandled = 0xFE;          
            return;
        }  
    }

    return;
}

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