summaryrefslogtreecommitdiff
path: root/Core/EM/OFBD/MEUD/MEUD.c
blob: 1d1cb68efa365129f9084685cf8124232c251b27 (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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2009, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/OFBD Intel ME Update/MEUD.c 28    5/14/14 1:54a Tristinchou $
//
// $Revision: 28 $
//
// $Date: 5/14/14 1:54a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/OFBD Intel ME Update/MEUD.c $
// 
// 28    5/14/14 1:54a Tristinchou
// [TAG]  		EIP167375
// [Category]  	Improvement
// [Description]  	Remove the variables' RT attribute
// 
// 27    5/16/13 4:05a Klzhan
// [TAG]  		EIPNone
// [Category]  	Improvement
// [Description]  	Fix system hangs when BIOS is not on the top of ROM
// 
// 26    5/16/13 1:54a Klzhan
// [TAG]  		EIPNone
// [Category]  	Improvement
// [Description]  	Remove Flash Device Enable/Disable.
// Report BIOS information to AFU.
// 
// 25    3/08/12 5:32a Klzhan
// Report error when CSP_ReportMEInfo return error.
// 
// 24    8/30/11 4:24a Klzhan
// Remove Un-use code.
// 
// 23    8/15/11 5:06a Klzhan
// Fix can't update Ignition FW.
// 
// 22    8/05/11 6:44a Klzhan
// [TAG]  		EIP63481
// [Category]  	Improvement
// [Description]  	AFU support commands for each regions update.
// 
// 21    7/15/11 4:54a Klzhan
// Remove un used comment.
// 
// 20    7/15/11 4:52a Klzhan
// [TAG]  		EIP60754
// [Category]  	Spec Update
// [Severity]  	Important
// [Description]  	Support Direct FW Update.
// 
// 19    6/14/11 3:42a Klzhan
// Support SPS spec to 1.1.
// 
// 18    5/31/11 5:01a Klzhan
// [TAG]  		EIP60991
// [Category]  	New Feature
// [Description]  	Read whole Flash image.
// 
// 17    5/09/11 3:55a Klzhan
// Remove Debug include.
// 
// 16    5/09/11 3:24a Klzhan
// Add Setup Item in Advanced Page to select regions to update.
// 
// 15    4/22/11 5:53a Klzhan
// Fix Build Error.
// 
// 14    4/22/11 4:36a Klzhan
// Add error handler when restore MAC.
// 
// 13    4/22/11 4:15a Klzhan
// Resotre MAC address when update GBE.
// 
// 12    4/22/11 2:30a Klzhan
// Remove the code related to ME AUTO UPDATE.
// Add OFBD version control for update ME though OFBD.
// 
// 11    2/10/11 5:52a Klzhan
// [TAG]  		EIP52968
// [Category]  	New Feature
// [Description]  	Update ME through OFBD not SMIFlash.
// [Files]  		MEUD.sdl
// MEUD.h
// MEUD.c
// 
// 10    1/12/11 10:34p Klzhan
// Fix build error when ME_AUTO_UPDATE is disabled.
// 
// 9     12/27/10 4:42a Klzhan
// Improvement : ME auto update.
// 
// 8     11/16/10 4:38a Klzhan
// Correct behavior of ME update.
// 
// 7     11/16/10 1:44a Klzhan
// Fill all parameters in MEUDStructPtr.
// 
// 6     11/11/10 4:46a Klzhan
// Correct error check when report MEInfo.
// 
// 5     6/10/10 11:25p Klzhan
// BugFix : FIx Compiler Error when ME_Ignition_FW_MSG_SUPPORT is
// disabled.
// 
// 4     6/10/10 4:21a Klzhan
// Improvement : Correct "ME_IGNITION_FW_MSG_SUPPORT" behavior.
// 
// 3     11/18/09 5:07a Klzhan
// Improvement : Restore FlashCapacity after program for AFUWin.
// 
// 2     10/13/09 3:33a Klzhan
// Updated for Aptio Source Enhancement.
// 
// 1     9/30/09 11:15p Lawrencechang
// Move Intel ME update module part to an independent SS path.
// 
// 5     8/31/09 9:04a Klzhan
// Update Procedure name to support Capella.
// 
// 4     7/10/09 4:19a Klzhan
// Improvement: Command /ME support flash entire image when Ignition FW.
// 
// 3     7/03/09 5:04a Klzhan
// Bug fix: Update ME Ignition FW fail.
// Severity: Critical
// Symptom: System will write wrong address when Ignition update.
// Root Cause: Coding Error
// Improvement: Add a token for showing ME Ignition status message
// 
// 2     7/02/09 8:25a Klzhan
// 
// 1     4/13/09 5:47a Lawrencechang
// Initial check-in.
// 
// 1     3/25/05 5:37p Markw
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name:	MEUD.c
//
// Description:
//
//<AMI_FHDR_END>
//**********************************************************************
#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include "MEUD.h"
#include "Flash.h"
#include "..\OFBD.h"
#include <Protocol\smiflash.h>
#include <Protocol\SmmSwDispatch.h>
#include <Protocol\SmmBase2.h>
#include "Setup.h"

EFI_SMI_FLASH_PROTOCOL *mSmiFlash;
UINT32 FlashCapacity;
// Skip Area, Now there are only 5 regions(FD, ME, GBE, PDR and BIOS)

UINT8     MacAddr[6];

VOID MEUDSMIHandler (
    IN    EFI_HANDLE    DispatchHandle,
    IN    EFI_SMM_SW_DISPATCH_CONTEXT    *DispatchContext
);

// SMM Nvram Control Protocol Definitions
typedef
EFI_STATUS (*SHOW_BOOT_TIME_VARIABLES)(BOOLEAN Show);

typedef struct{
    SHOW_BOOT_TIME_VARIABLES ShowBootTimeVariables;
}AMI_NVRAM_CONTROL_PROTOCOL;

AMI_NVRAM_CONTROL_PROTOCOL *gNvramControl = NULL;

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	LocateNvramControlSmmProtocol
//
// Description:	Locate NvramControlProtocol
//
// Input:
//      VOID
//
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
AMI_NVRAM_CONTROL_PROTOCOL*
LocateNvramControlSmmProtocol()
{
    EFI_STATUS Status;
    static EFI_GUID AmiNvramControlProtocolGuid = { 0xf7ca7568, 0x5a09, 0x4d2c, { 0x8a, 0x9b, 0x75, 0x84, 0x68, 0x59, 0x2a, 0xe2 } };
    EFI_GUID EfiSmmBase2ProtocolGuid = EFI_SMM_BASE2_PROTOCOL_GUID;
    EFI_SMM_BASE2_PROTOCOL  *SmmBase2 = NULL;
    EFI_SMM_SYSTEM_TABLE2   *Smst2 = NULL;
    EFI_CONFIGURATION_TABLE *Table = NULL;
    UINTN                   Count = 0;

    Status = pBS->LocateProtocol( &EfiSmmBase2ProtocolGuid, NULL, &SmmBase2 );
    if( !EFI_ERROR(Status) )
    {
        Status = SmmBase2->GetSmstLocation( SmmBase2, &Smst2 );
        if( EFI_ERROR(Status) || Smst2 == NULL )
            return NULL;
    }

    Table = Smst2->SmmConfigurationTable;
    Count = Smst2->NumberOfTableEntries;

    for( ; Count ; --Count, ++Table )
    {
        if( guidcmp( &Table->VendorGuid, &AmiNvramControlProtocolGuid ) == 0 ) 
            return Table->VendorTable;
    }

    return NULL;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	MEUDCallback
//
// Description:	Locate SmiFlash protocol callback
//
// Input:
//      IN EFI_EVENT    Event
//      IN VOID         *Context
//
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID MEUDCallback(
    IN EFI_EVENT Event,
    IN VOID *Context
)
{
    EFI_GUID       gEfiSmiFlashProtocolGuid = EFI_SMI_FLASH_GUID;

    pBS->LocateProtocol (&gEfiSmiFlashProtocolGuid, NULL, &mSmiFlash);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	MEUDInSmm
//
// Description:	OFBD ME Firmware Update InSmm Function
//
// Input:
//      VOID
//
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID MEUDInSmm(VOID)
{
    EFI_STATUS     Status;
    EFI_GUID       gEfiSmiFlashProtocolGuid = EFI_SMI_FLASH_GUID;
    EFI_GUID       gMEUDErrorGuid = MEUD_ERROR_GUID;
    UINT8          FW_Usage = 0, MeResetFlag;
    UINT32         VariableAttr;
    UINTN          VariableSize;
    FlashCapacity = GetFlashCapacity();

    Status = pBS->LocateProtocol (&gEfiSmiFlashProtocolGuid, NULL, &mSmiFlash);
    if (EFI_ERROR(Status)){
        EFI_EVENT   SmiFlashCallbackEvt;
        VOID        *MEUDReg;
        RegisterProtocolCallback(
             &gEfiSmiFlashProtocolGuid, MEUDCallback,
             NULL,&SmiFlashCallbackEvt, &MEUDReg
        );
    }

    gNvramControl = LocateNvramControlSmmProtocol();

    CSP_MEUDInSmm();
    VariableSize = sizeof(UINT8);
    Status = pRS->GetVariable( L"MEUpdateResetFlag", &gMEUDErrorGuid,
                               &VariableAttr, &VariableSize, &MeResetFlag);


    if((!EFI_ERROR(Status)) && (MeResetFlag == 1))
    {
        UINT32  TempReg;

        // Reset ME
        IoWrite32(0xCF8, 0x8000F8AC);
        TempReg = IoRead32(0xCFC);

        if(!(TempReg & BIT20))
        {
            IoWrite32(0xCF8, 0x8000F8AC);
            IoWrite32(0xCFC, TempReg | BIT20);
        }
 
        // Clear Flag
        VariableSize = 0;
        pRS->SetVariable( L"MEUpdateResetFlag", &gMEUDErrorGuid,
                            VariableAttr,
                            VariableSize, &MeResetFlag);

        pRS->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
    }


    // If HFS is NULL, return.
#if ME_IGNITION_FW_MSG_SUPPORT
    if(GetHFS() == 0)
        return;

    FW_Usage = (GetHFS() >> 24);
    if(((GetHFS() >> 16) & 0x0F) == 1)
    // Set A variable as Flag or Link many lib to AMITSE.
        pRS->SetVariable( L"ShowMEUDFailMSG", &gMEUDErrorGuid,
	EFI_VARIABLE_BOOTSERVICE_ACCESS,
            sizeof(UINT8), &FW_Usage);
#endif
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	MEUDEntry
//
// Description:	OFBD ME Firmware Update Entry point
//
// Input:
//      IN VOID             *Buffer
//      IN OUT UINT8        *pOFBDDataHandled
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID MEUDEntry (
    IN VOID             *Buffer,
    IN OUT UINT8        *pOFBDDataHandled )
{

    OFBD_HDR       *pOFBDHdr;
    OFBD_EXT_HDR   *pOFBDExtHdr;
    VOID           *pOFBDTblEnd;
    OFBD_TC_55_MEUD_STRUCT *MEUDStructPtr;
    EFI_STATUS     Status = EFI_SUCCESS;
    UINT32         Buffer1, Buffer2;
    OFBD_TC_55_ME_INFO_STRUCT  *MEInfoStructPtr;
    OFBD_TC_55_ME_PROCESS_STRUCT  *MEProcessStructPtr;
#ifdef CSP_SPSUD_SUPPORT
#if CSP_SPSUD_SUPPORT
    UINT8          Timer = 0;
    UINT8          MeResetFlag = 0;
    EFI_GUID       gMEUDErrorGuid = MEUD_ERROR_GUID;
#endif
#endif
#if (OFBD_VERSION >= 0x0210)
    UINT32         Length, Offset;
    BOOLEAN        FlashStatus = TRUE;
    UINT8          *Address;
    UINT32         Size;
    UINT8*         Data;
#endif
    if (*pOFBDDataHandled == 0)
    {
        pOFBDHdr = (OFBD_HDR *)Buffer;
        pOFBDExtHdr = (OFBD_EXT_HDR *)((UINT8 *)Buffer + \
                      (pOFBDHdr->OFBD_HDR_SIZE));
        MEUDStructPtr = (OFBD_TC_55_MEUD_STRUCT *)((UINT8 *)pOFBDExtHdr + \
                        sizeof(OFBD_EXT_HDR));
        MEInfoStructPtr = (OFBD_TC_55_ME_INFO_STRUCT*)MEUDStructPtr;
        MEProcessStructPtr = (OFBD_TC_55_ME_PROCESS_STRUCT*)MEUDStructPtr;

        pOFBDTblEnd = (VOID *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_Size));

        if (pOFBDHdr->OFBD_FS & OFBD_FS_MEUD)
        {
            //Check Type Code ID
            if (pOFBDExtHdr->TypeCodeID == OFBD_EXT_TC_MEUD)
            {
                switch (MEUDStructPtr->bSubFunction)
                {
                case 0 :

                    Status = CSP_ReportMEInfo(0 , \
                            &(MEUDStructPtr->dMERuntimeBase), \
                            &(MEUDStructPtr->dMERuntimeLength));

                    MEUDStructPtr->dMEBiosRegionBase = \
                                                 FlashCapacity - FLASH_SIZE;
                    MEUDStructPtr->dMEBiosRegionLength = (UINT32)FLASH_SIZE;

                    if ((FlashCapacity == 0) || EFI_ERROR(Status))
                    {
                        // Fail , Return
                        *pOFBDDataHandled = 0xFE;
                        return;
                    }
                    *pOFBDDataHandled = 0xFF;
                    MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    return;
                case 3 :
                    Status = CSP_ReportMEInfo(3, \
                            &(MEUDStructPtr->dMERuntimeBase), \
                            &(MEUDStructPtr->dMERuntimeLength));

                    MEUDStructPtr->dMEBiosRegionBase = \
                                                 FlashCapacity - FLASH_SIZE;
                    MEUDStructPtr->dMEBiosRegionLength = (UINT32)FLASH_SIZE;

                    // If FlashCapacity == 0, Not support ME Update
                    if (FlashCapacity == 0)
                    {
                        // Fail , Return
                        *pOFBDDataHandled = 0xFE;
                        return;
                    }

                    *pOFBDDataHandled = 0xFF;
                    MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    return;
                case 1 :
                    // Send this again to check is this suppoet.
                    Status = CSP_ReportMEInfo(0, \
                            &Buffer1, \
                            &Buffer2);

                    if (!EFI_ERROR(Status))
                        Status = HMRFPO_ENABLE_MSG();

                    if (EFI_ERROR(Status))
                    {
                        // Fail , Return
                        *pOFBDDataHandled = 0xFE;
                        return;
                    }
                    MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    *pOFBDDataHandled = 0xFF;
                    mSmiFlash->FlashCapacity = FlashCapacity;
                    return;
                case 4 :
                    // Send this again to check is this suppoet.
                    Status = CSP_ReportMEInfo(3, \
                            &Buffer1, \
                            &Buffer2);
                    if (EFI_ERROR(Status))
                    {
                        // Fail , Return
                        *pOFBDDataHandled = 0xFE;
                        return;
                    }
                    MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    *pOFBDDataHandled = 0xFF;
                    mSmiFlash->FlashCapacity = FlashCapacity;
#if (OFBD_VERSION >= 0x0210)
                    // Get GBE Region for Restore MAC address
                    Status = GetRegionOffset(3, &Offset, &Length);

                    // Before Erase, Get mac address
                    if(Length)
                    {
#if (OFBD_VERSION >= 0x0220)
                        DoNotConvert = TRUE;
#endif
                        Address = (UINT8*)FLASH_BASE_ADDRESS(Offset);
                        FlashRead(Address, MacAddr, 6);
#if (OFBD_VERSION >= 0x0220)
                        DoNotConvert = FALSE;
#endif
                    }
#endif
                    return;
                case 2 :
                    Status = HMRFPO_LOCK_MSG();
                    if (EFI_ERROR(Status))
                    {
                        // Fail , Return
                        *pOFBDDataHandled = 0xFE;
                        return;
                    }
                case 5 :
                    mSmiFlash->FlashCapacity = FLASH_SIZE;
#if defined (CSP_SPSUD_SUPPORT) && (CSP_SPSUD_SUPPORT == 1)
/*
                    do{
                        Status = HMRFPO_LOCK_MSG();
                        if(!EFI_ERROR(Status))
                            break;
                        Timer ++;
                    }while(Timer < 3);
*/
                    //reset ME.
                    MeResetFlag = 1;

                    if( gNvramControl )
                        gNvramControl->ShowBootTimeVariables( TRUE );
                    Status = pRS->SetVariable(
                                    L"MEUpdateResetFlag",
                                    &gMEUDErrorGuid,
                                    EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                    EFI_VARIABLE_NON_VOLATILE,
                                    sizeof(UINT8),
                                    &MeResetFlag );
                    if( gNvramControl )
                        gNvramControl->ShowBootTimeVariables( FALSE );
                    if (EFI_ERROR(Status))
                    {
                        // Fail , Return
                        *pOFBDDataHandled = 0xFE;
                        return;
                    }
#endif
                    MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    *pOFBDDataHandled = 0xFF;
                    return;

                default :
                    *pOFBDDataHandled = 0xFE;
                    break;
// =============== OFBD Version 2.1 and AFU version 2.37 or newer ===============
#if (OFBD_VERSION >= 0x0210)
                // earse
                case 6 :

                    Size = MEUDStructPtr->ddBlockSize;

                    Address = (UINT8*)FLASH_BASE_ADDRESS(MEUDStructPtr->ddBlockAddr);



                    for (; FlashStatus && Size > 0; Address += 0x1000, Size -= 0x1000)
                    {
                         FlashBlockWriteEnable(Address);
                         FlashStatus = FlashEraseBlock(Address);
                         FlashBlockWriteDisable(Address);
                     }

                     if(FlashStatus)
                     {
                         *pOFBDDataHandled = 0xFF;
                         MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                     }
                    break;
                // program
                case 7 :
                    Size = MEUDStructPtr->ddBlockSize;
                    Data = (UINT8*)pOFBDHdr;
                    Status = CSP_ReportMEInfo(3, \
                                &Buffer1,
                                &Buffer2);
                    (UINTN)Address = FLASH_BASE_ADDRESS(MEUDStructPtr->ddBlockAddr);
                    Status = GetRegionOffset(3, &Offset, &Length);

                    (UINTN)Data += MEUDStructPtr->ddFlashBufOffset;
                    // Restore MAC Address
                    if((MEUDStructPtr->ddBlockAddr == Offset) && (Length != 0))
                        MemCpy(Data,MacAddr,6);

                    FlashDeviceWriteEnable();

                    FlashBlockWriteEnable(Address);
                    FlashStatus = FlashProgram(Address, Data, Size);
                    FlashBlockWriteDisable(Address);

                    FlashDeviceWriteDisable();
                    if(FlashStatus)
                    {
                        *pOFBDDataHandled = 0xFF;
                        MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    }
                    break;

                // Read
                case 8 :
                    (UINTN)Address = FLASH_BASE_ADDRESS(MEUDStructPtr->ddBlockAddr);
                    Data = (UINT8*)pOFBDHdr;
                    (UINTN)Data += MEUDStructPtr->ddFlashBufOffset;

                    FlashRead(Address, Data, MEUDStructPtr->ddBlockSize);
                    *pOFBDDataHandled = 0xFF;
                    MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    break;

                case 9 :
                    // Get Info
                    {
                        UINT16    TotalBlocks = 0;

                        // Get FD
                        Status = GetRegionOffset(0 ,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].StartAddress, 
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].BlockSize);

                        // Fill FD Info
                        if(!EFI_ERROR(Status))
                        {
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Command,"FDR",4);
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Description,
                                   "Flash Flash-Descriptor Region",64);
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Type = FDT_BLK;
                            // Status = 1 means Protect
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Status = 0;
                            TotalBlocks += 1;
                        }
                        // Get GBE
                        Status = GetRegionOffset(3 ,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].StartAddress,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].BlockSize);

                        // Fill GBE Info
                        if(!EFI_ERROR(Status))
                        {
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Command,"GBER",4);
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Description,
                                   "Flash GBE Region",64);
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Type = GBE_BLK;
                            // Status = 1 means Protect
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Status = 0;
                            TotalBlocks += 1;
                        }

                        // Get PDR
                        Status = GetRegionOffset(4 ,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].StartAddress,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].BlockSize);

                        // Fill PDR Info
                        if(!EFI_ERROR(Status))
                        {
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Command,"PDR",4);
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Description,
                                   "Flash PDR Region",64);
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Type = PDR_BLK;
                            // Status = 1 means Protect
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Status = 0;
                            TotalBlocks += 1;
                        }

                        // Get ME
                        Status = GetRegionOffset(2 ,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].StartAddress,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].BlockSize);

                        // Fill ME Info
                        if(!EFI_ERROR(Status))
                        {
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Command,"MER",4);
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Description,
                                   "Flash Entire ME Region",64);
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Type = ME_BLK;
                            // Status = 1 means Protect
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Status = 0;
                            TotalBlocks += 1;
                        }

                        // Get BIOS
                        Status = GetRegionOffset(1 ,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].StartAddress,
                            &MEInfoStructPtr->BlockInfo[TotalBlocks].BlockSize);

                        // Fill BIOS Info
                        if(!EFI_ERROR(Status))
                        {
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Command,"MER",4);
                            MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Description,
                                   "Flash Entire ME Region",64);
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Type = BIOS_BLK;
                            // Status = 1 means Protect
                            MEInfoStructPtr->BlockInfo[TotalBlocks].Status = 0;
                            TotalBlocks += 1;
                        }
#if defined (CSP_SPSUD_SUPPORT) && (CSP_SPSUD_SUPPORT == 1)
                        //
                        // Fill SPS Partition Info
                        //

                        // OPR1
                        MEInfoStructPtr->BlockInfo[TotalBlocks].StartAddress = OPR1_START;
                        MEInfoStructPtr->BlockInfo[TotalBlocks].BlockSize = OPR1_LENGTH;
                            // OPR2
                        if(OPR2_LENGTH != 0)
                            MEInfoStructPtr->BlockInfo[TotalBlocks].BlockSize += OPR2_LENGTH;

                        MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Command,"OPR",4);
                        MemCpy(MEInfoStructPtr->BlockInfo[TotalBlocks].Description,
                               "Flash Operation Region of SPS",64);

                        MEInfoStructPtr->BlockInfo[TotalBlocks].Type = ME_OPR_BLK;
                        // Status = 1 means Protect
                        MEInfoStructPtr->BlockInfo[TotalBlocks].Status = 0;
                        TotalBlocks += 1;
#endif
                        MEInfoStructPtr->TotalBlocks = TotalBlocks;
                        *pOFBDDataHandled = 0xFF;
                        MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;

                    }
                    break;
                case 10 :
                    // ME Process Handle
                    // In CSP_MEUD.c
                    MEProcessHandler(&MEProcessStructPtr);
                    *pOFBDDataHandled = 0xFF;
                    MEUDStructPtr->bReturnStatus =  OFBD_TC_MEUD_OK;
                    break;
#endif //#if (OFBD_VERSION >= 0x0210)
                }// End of Switch
            }

        }

    }
    return;
}

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