目錄表

UEFI AMI BIOS 研究

AMI Utility

MMTOOL

AMIBCP

AMISLP

AMISDE

AMISCE

DMIEdit

AFU

AMIUCP

Setup

VFR flag

Setup token Explain

typedef struct{ 
      UINT16 Class; 
      UINT16 SubClass; 
      UINT16 Key; 
      SETUP_ITEM_CALLBACK_HANDLER *UpdateItem; 
  } SETUP_ITEM_CALLBACK; 
  
Ex.
ELINK 
 Name = "ITEM_CALLBACK(ADVANCED_FORM_SET_CLASS, 0, DPTF_SADEVICE_KEY, PlatformSetupCallback)," 
 Parent = "SetupItemCallbacks" 
 InvokeOrder = AfterParent 
End 
  

SetupItem Callbacks action explain

When modify value will trigger this action. Always get modify previous value when get browser data.

When modify value will trigger this action. Always get modify value when get browser data.

When entry to Setup menu and will trigger this action.

When leave to Setup menu will trigger this action.

Callback Function Prototype define

typedef EFI_STATUS (SETUP_ITEM_CALLBACK_HANDLER)( 
    EFI_HII_HANDLE HiiHandle, UINT16 Class, UINT16 SubClass, UINT16 Key) 

Hii Get/Set Setup data buffer

讀取和寫入目前記憶體中的設定值, 並不會影響到 Flash part,除非做了 save 動作。
第一次進 SETUP 時,會將所有資料寫到 MEMORY buffer。

HiiLibGetBrowserData(&Size, &FlashUpdateControl, &guidReFlash, L"Setup"); 
HiiLibSetBrowserData(Size, &FlashUpdateControl, &guidReFlash, L"Setup"); 

SetupItem Callbacks Create

1. Proclaim “INTERACTIVE” and “questionid”  in Setup Item 
oneof varid  = SETUP_DATA.EnableDptf, 
 questionid = AUTO_ID(DPTF_ENABLE_KEY), 
 prompt = STRING_TOKEN(STR_ENABLE_DPTF_PROMPT), 
 help = STRING_TOKEN(STR_ENABLE_DPTF_HELP), 
 option text = STRING_TOKEN(STR_DISABLED), value = 0, flags = DEFAULT | MANUFACTURING | RESET_REQUIRED | INTERACTIVE; 
 option text = STRING_TOKEN(STR_ENABLED), value = 1, flags = RESET_REQUIRED | INTERACTIVE; 
endoneof; 

****** 記得要加入 INTERACTIVE ******


2.Create Callback Function  

3.Add SetupItemCallbacks ELINK 
ELINK 
 Name = "ITEM_CALLBACK(ADVANCED_FORM_SET_CLASS,0,DPTF_SADEVICE_KEY,PlatformSetupCallback)," 
 Parent = "SetupItemCallbacks" 
 InvokeOrder = AfterParent 
End 

Callback Function Example

Ex1: 

EFI_STATUS PushButtonResetSetupCallbackFunction(
    EFI_HII_HANDLE HiiHandle, 
    UINT16 Class, 
    UINT16 SubClass, 
    UINT16 Key )
{
    EFI_STATUS Status = EFI_SUCCESS;
    AMI_PUSH_BUTTON_RESET_PROTOCOL *AmiPushButtonResetProtocol = NULL;
    CALLBACK_PARAMETERS *Callback = NULL;

    TRACE((TRACE_ALWAYS, "PushButtonReset: Callback function invoked.\n"));
    
    Callback = GetCallbackParameters();
    if(Callback==NULL) {
        Status=EFI_INVALID_PARAMETER;
        return Status;
    }
    
    if(Callback->Action != EFI_BROWSER_ACTION_CHANGING) {
        Status=EFI_INVALID_PARAMETER;
        return Status;
    }
    
    if(Key == PUSH_BUTTON_RESET_TRIGGER_KEY) {
        TRACE((TRACE_ALWAYS, "PushButtonReset: Try to call the loader\n"));
        Status = pBS->LocateProtocol (&gAmiPushButtonResetProtocolGuid,
                                      NULL,
                                      &AmiPushButtonResetProtocol) ;
        if(EFI_ERROR(Status)) {
            TRACE((TRACE_ALWAYS, "Error in locate protocol %r\n",Status));
            return Status;
        }
        
        Status = AmiPushButtonResetProtocol->InvokeLoader();
        if(EFI_ERROR(Status))
            TRACE((TRACE_ALWAYS, "Error in invoke loader\n"));
            return Status;
    }
    return Status;
}


Ex2 :

EFI_STATUS JumplessMeTemporarityDisabledTrigger(
    EFI_HII_HANDLE HiiHandle, 
    UINT16 Class, 
    UINT16 SubClass, 
    UINT16 Key )
{   
    EFI_STATUS Status = EFI_SUCCESS;
    UINT8 Value;
    CALLBACK_PARAMETERS *Callback = NULL;

    TRACE((TRACE_ALWAYS, "JumplessMeTemporarityDisabledTrigger: Callback function invoked.\n"));
    
    Callback = GetCallbackParameters();
    if(Callback==NULL) {
        Status=EFI_INVALID_PARAMETER;
        return Status;
    }
    
    if(Callback->Action != EFI_BROWSER_ACTION_CHANGING) {
        Status=EFI_INVALID_PARAMETER;
        return Status;
    }
    
    if(Key == JPLS_ME_TEMPDIS_TRIGGER_KEY) {
        IoWrite8(0x4E, 0x87);
        IoWrite8(0x4E, 0x87);

        IoWrite8(0x4E, 0x27);
        Value = IoRead8(0x4F);
        Value = Value & 0xF2 | 0x00;
        IoWrite8(0x4F, Value);

        IoWrite8(0x4E, 0x2C);
        Value = IoRead8(0x4F);
        Value = Value & 0xEF | 0x10;
        IoWrite8(0x4F, Value);

        IoWrite8(0x4E, 0x07);
        Value = IoRead8(0x4F);
        Value = Value & 0x00 | 0x06;
        IoWrite8(0x4F, Value);

        IoWrite8(0x4E, 0xF0);
        Value = IoRead8(0x4F);
        Value = Value & 0xEF | 0x10;
        IoWrite8(0x4F, Value);

        IoWrite8(0x4E, 0xF1);
        Value = IoRead8(0x4F);
        Value = Value & 0xEF | 0x00;
        IoWrite8(0x4F, Value);

        IoWrite8(0x4E, 0xF3);
        Value = IoRead8(0x4F);
        Value = Value & 0xEF | 0x10;
        IoWrite8(0x4F, Value);

        IoWrite8(0x4E, 0xAA);

        IoWrite8(0xCF9, 0x0E);
    }
    return Status;
}

Setup Class Hook

Setup instruction

HotKey Class Hook

  1. CheckForKeyHook
    • 在POST過程中,會有很多地方都加入此HOOK,如果插入在此HOOK則很多地方都會檢查並執行。
  2. OemKey1Hook
  3. OemKey2Hook
  4. OemKey3Hook
  5. OemKey4Hook
    • 一般給OEM使用,如RECOVERY,按了按鍵,則做對應動作。

OemKey1-4 Token

  1. SETUP_OEM_KEY1_ENABLE
  2. SETUP_OEM_KEY1_UNICODE
    • 使用方式像 F1, F2, F3 …等HOTKEY
  3. SETUP_OEM_KEY1_SCAN
    • 使用方式像 A, B, C …等HOTKEY
  4. SETUP_OEM_KEY1_SHIFT
    • 檢查是否有按下 CTRL/SHIFT/ALT/Windows Modifier Key
  5. SETUP_OEM_KEY1_TOGGLE
    • 檢查是否有按下 CAPS LOCK/ NUMBER LOCK

OemKey Shift and Toggle state

Shift state

Toggle state

EFI Scan codes