summaryrefslogtreecommitdiff
path: root/Core/EM/OFBD/OEMCMD/OEMCMD.c
blob: c7613e3547d313618f97d9b28e77aa88e3899e2d (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (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/OEMCMD/OEMCMD.c 4     4/12/11 10:28p Terrylin $
//
// $Revision: 4 $
//
// $Date: 4/12/11 10:28p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/OFBD/OEMCMD/OEMCMD.c $
// 
// 4     4/12/11 10:28p Terrylin
// Fix sample code is wrong problem.
// 
// 3     3/16/11 10:36p Terrylin
// [TAG]  		EIP51285
// [Category]  	Improvement
// [Description]  	Fill the description for user more clearly.
// [Files]  		OEMCMD.mak
// OEMCMD.h
// OEMCMD.c
// 
// 2     1/26/11 3:52a Terrylin
// [Category]  	Improvement
// [Description]  	Add /CMD: command description and its sample code.
// 
// 1     5/06/10 2:23a Lawrencechang
// Initial check-in.
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name:	OEMCMD.c
//
// Description: 
//By OEMCMD module, OEM engineers define customized commands to extend AFU functions. AFU sends OEM defined commands
// to BIOS if user issued /oemcmd:<command>. Then BIOS reacts by these customized commands.
//
//<AMI_FHDR_END>
//**********************************************************************
#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include "OEMCMD.h"
#include "..\OFBD.h"

//#define CONVERT_TO_STRING(a) #a
#define STR(a) CONVERT_TO_STRING(a)

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	OFBDOEMCMDHandle
//
// Description:	OFBD OEM CMD Handle
//
// Input:
//      IN OUT OFBD_HDR *pOFBDHdr
// Output:
//      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
OFBDOEMCMDHandle( 
    IN OUT OFBD_HDR *pOFBDHdr)
{
    EFI_STATUS Status = EFI_SUCCESS;

#if OEM_CMD_CHECKING_SAMPLE_TEST

	UINT8 *pOFBDTblEnd;
	UINT8 *pCMDBufferStr;
	UINT32 ddCMDLength = 0;
	char *DisOemBFStr = "Sample Message: OEM CMD Before Flash Run is OK !!";
	char *DisOemAFStr = "Sample Message: OEM CMD After Flash Run is OK !!";
	char *DisOemBEStr = "Sample Message: OEM CMD Before End Run is OK !!";
	char *DisOemSFStr = "Sample Message: OEM CMD Start to Flash Run is OK !!";
	
	OFBD_TC_57_OEM_CMD_STRUCT *OCStructPtr;   
	
	pOFBDTblEnd = (UINT8 *)((UINT8 *)pOFBDHdr + (pOFBDHdr->OFBD_Size));
	OCStructPtr = (OFBD_TC_57_OEM_CMD_STRUCT *)((UINT8 *)pOFBDHdr + pOFBDHdr->OFBD_HDR_SIZE + sizeof(OFBD_EXT_HDR)); 
	
	//
	// OEM add start here >>>+
	//
	
	//--------------------------------------------------------------------------------------
	//
	// OEM Notice : 
	//
	// case 1:
	// 		OCStructPtr->ddCMD is parse by AFU, according "/OEMCMD:x" to given Hex value.
	//
	// case 2:
	// 		OCStructPtr->ddCMD is "/CMD:{xxx}" command string offset.
	// 		OCStructPtr->ddReserve is command string length.
	//
	//--------------------------------------------------------------------------------------

	// IoWrite32(0x1080, OCStructPtr->ddCMD); //debug
	
	//------------------------------------------------------------------------------------------
	// Case 1
	//------------------------------------------------------------------------------------------
	
	// 01. Before Flash
	if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_BF) {	 
		//--------------------------------------------------------------------------------------
		//
		// OEM Command sample definition:
		//
		//--------------------------------------------------------------------------------------
		// Bit 0  : Restart
		// Bit 1  : Shutdown
		// Bit 2  : Wait
		// ...
		// Bit 5 : No Check AC adapter
		// Bit 6 : OEM function 01
		// Bit 7 : OEM function 02
		// ...
		// 
		// 01. /OEMCMD:1	, OCStructPtr->ddCMD = 0x1  (Hex). ("Restart")
		// 02. /OEMCMD:5	, OCStructPtr->ddCMD = 0x5  (Hex). ("Restart" + "Wait")
		// 03. /OEMCMD:11	, OCStructPtr->ddCMD = 0x11 (Hex). ("No Check AC adapter" + "Restart")
		// 04. /OEMCMD:A2	, OCStructPtr->ddCMD = 0xA2 (Hex). ("OEM function 02" + "No Check AC adapter" + "Shutdown")
		// 05. /OEMCMD:123	, OCStructPtr->ddCMD = 0x123(Hex). ...
		// 06. /OEMCMD:AABB	, OCStructPtr->ddCMD = 0xAABB(Hex). ...
		//--------------------------------------------------------------------------------------
		
		//
		// OCStructPtr->ddCMD
		// 
		
		// Check Bit 0
		if (OCStructPtr->ddCMD & 0x1) {
			// Restart code
		}
		
		// Check Bit 1
		if (OCStructPtr->ddCMD >> 1 & 0x1) {
			// Shutdown code
		}
		
		// Check Bit 2
		if (OCStructPtr->ddCMD >> 2 & 0x1) {
			// Wait code
		}
		
		// Check Bit 5
		if (OCStructPtr->ddCMD >> 5 & 0x1) {
			// No Check AC adapter code
		}
		
		// Check Bit 7
		if (OCStructPtr->ddCMD >> 7 & 0x1) {
			// OEM function 02 code
		}
		
		// << debug >>	
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemBFStr);
	    
	    
	// 02. After Flash
	} else if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_AF) {
		
		// 
		// Display OEM String Usage +>>>
		// 
		
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemAFStr);
	    
	    //
	    // Display OEM String Usage <<<+
	    //
	    
	// 03. Before End
	} else if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_BE) {
	
		// OEM add ...
		
		// << debug >>
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemBEStr);
	    
	} else if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_SF) {
                // << debug >>	
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemSFStr);
	    
    }
			   
	//------------------------------------------------------------------------------------------
	// Case 2
	//------------------------------------------------------------------------------------------
	// 05. Before Flash
	if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_BUF) {	 
		//--------------------------------------------------------------------------------------
		//
		// OEM Command sample definition:
		//
		//--------------------------------------------------------------------------------------
		// 
		// 01. /CMD:{123}	    , OCStructPtr->ddCMD = 0x400(Hex), OCStructPtr->ddReserve = 3 (Bytes)
		// 02. /CMD:{Reset}	    , OCStructPtr->ddCMD = 0x400(Hex), OCStructPtr->ddReserve = 5 (Bytes)
		// 03. /CMD:{NoVer}     , OCStructPtr->ddCMD = 0x400(Hex), OCStructPtr->ddReserve = 5 (Bytes)
		// 04. /CMD:{NoAC}	    , OCStructPtr->ddCMD = 0x400(Hex), OCStructPtr->ddReserve = 4 (Bytes)
		// 05. /CMD:{Battery}	, OCStructPtr->ddCMD = 0x400(Hex), OCStructPtr->ddReserve = 7 (Bytes)
		// 06. /CMD:{NoAc Battery NoVer}	, OCStructPtr->ddCMD = 0x400(Hex), OCStructPtr->ddReserve = 18 (Bytes)
		//--------------------------------------------------------------------------------------
		
		//
		// Get Command String Offset
		// 
		
		pCMDBufferStr = (UINT8 *)((UINT8 *)pOFBDHdr + (OCStructPtr->ddCMD));
		
		
		//
		// Get Command String Length
		//
		
		ddCMDLength = OCStructPtr->ddReserve;
		
		// << debug >>	
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemBFStr);
	    
	    
	// 06. After Flash
	} else if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_BUF_AF) {
		
		// 
		// Display OEM String Usage +>>>
		// 
		
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemAFStr);
	    
	    //
	    // Display OEM String Usage <<<+
	    //
	    
	// 07. Before End
	} else if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_BUF_BE) {
	
		// OEM add ...
		
		// << debug >>
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemBEStr);
	    
	} else if (OCStructPtr->dwFlaSts == OFBD_TC_OEM_CMD_BUF_SF) {
                // << debug >>	
		// set oem string flag for AFU to know
	    pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
	    // copy the oem string ptr for AFU
	    Strcpy((char *)pOFBDTblEnd, DisOemSFStr);
	    
    }
    
	//
	// OEM add start here <<<+
	//
		
	// Setting Return Status is '1' for AFU to know OFBD has supported OEM CMD module.
	OCStructPtr->dwRetSts = 1;

#endif

    return(Status);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	OEMCMDEntry
//
// Description:	OFBD OEM CMD CHECKING Entry Point
//
// Input:
//      IN VOID             *Buffer
//      IN OUT UINT8        *pOFBDDataHandled
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID OEMCMDEntry (
    IN VOID             *Buffer,
    IN OUT UINT8        *pOFBDDataHandled )
{
	OFBD_HDR *pOFBDHdr;
	OFBD_EXT_HDR *pOFBDExtHdr; 
	VOID *pOFBDTblEnd;
	OFBD_TC_57_OEM_CMD_STRUCT *OCStructPtr;    

	if(*pOFBDDataHandled == 0)
	{
		pOFBDHdr = (OFBD_HDR *)Buffer;
		pOFBDExtHdr = (OFBD_EXT_HDR *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_HDR_SIZE));
		OCStructPtr = (OFBD_TC_57_OEM_CMD_STRUCT *)((UINT8 *)pOFBDExtHdr + sizeof(OFBD_EXT_HDR)); 
		pOFBDTblEnd = (VOID *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_Size));    
		
		if(pOFBDHdr->OFBD_FS & OFBD_FS_OEM_CMD)
		{   
			//Check Type Code ID
			if(pOFBDExtHdr->TypeCodeID == OFBD_EXT_TC_OEM_CMD)
			{  
				if(OFBDOEMCMDHandle(pOFBDHdr) == EFI_SUCCESS)
				{
					//OEM CMD CHECKING 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                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************