使用者工具

網站工具


uefi_ami_bios

這是本文件的舊版!


UEFI AMI BIOS 研究

Setup

VFR flag

  • DEFAULT: Set default option.
  • MANUFACTURING: Manufacturing mode default value.
  • INTERACTIVE: Item can use callback function.
  • RESET_REQUIRED: Reset system when you change and save this item.

Setup token Explain

  • LOGO_FILE_NAME: Set full screen mode logo file.
  • DEFAULT_QUIET_BOOT : Set Default value of the Quiet Boot option.
  • SUPPORT_ZERO_BOOT_TIMEOUT : Enables or disables possibility to set boot timeout to 0.
  • DEFAULT_BOOT_TIMEOUT : Number of seconds that the firmware will wait before initiating.
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

  • EFI_BROWSER_ACTION_CHANGING

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

  • EFI_BROWSER_ACTION_CHANGED

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

  • EFI_BROWSER_ACTION_FORM_OPEN

When entry to Setup menu and will trigger this action.

  • EFI_BROWSER_ACTION_FORM_CLOSE

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

  • LoadedUserDefaultsHook
  • SavedConfigChangesHook
  • LoadedConfigDefaultsHook
  • PreSystemResetHookHook

HotKey Class Hook

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

OemKey1-4 Token

  • SETUP_OEM_KEY1_ENABLE
  • SETUP_OEM_KEY1_UNICODE
  • SETUP_OEM_KEY1_SCAN
  • SETUP_OEM_KEY1_SHIFT
  • SETUP_OEM_KEY1_TOGGLE

OemKey Shift and Toggle state

Shift state

  • #define EFI_SHIFT_STATE_VALID 0x80000000
  • #define EFI_RIGHT_SHIFT_PRESSED 0x00000001
  • #define EFI_LEFT_SHIFT_PRESSED 0x00000002
  • #define EFI_RIGHT_CONTROL_PRESSED 0x00000004
  • #define EFI_LEFT_CONTROL_PRESSED 0x00000008
  • #define EFI_RIGHT_ALT_PRESSED 0x00000010
  • #define EFI_LEFT_ALT_PRESSED 0x00000020
  • #define EFI_RIGHT_LOGO_PRESSED 0x00000040
  • #define EFI_LEFT_LOGO_PRESSED 0x00000080
  • #define EFI_MENU_KEY_PRESSED 0x00000100
  • #define EFI_SYS_REQ_PRESSED 0x00000200

Toggle state

  • #define EFI_TOGGLE_STATE_VALID 0x80
  • #define EFI_KEY_STATE_EXPOSED 0x40
  • #define EFI_SCROLL_LOCK_ACTIVE 0x01
  • #define EFI_NUM_LOCK_ACTIVE 0x02
  • #define EFI_CAPS_LOCK_ACTIVE 0x04

EFI Scan codes

  • #define SCAN_F11 0x0015
  • #define SCAN_F12 0x0016
  • #define SCAN_PAUSE 0x0048
  • #define SCAN_F13 0x0068
  • #define SCAN_F14 0x0069
  • #define SCAN_F15 0x006A
  • #define SCAN_F16 0x006B
  • #define SCAN_F17 0x006C
  • #define SCAN_F18 0x006D
  • #define SCAN_F19 0x006E
  • #define SCAN_F20 0x006F
  • #define SCAN_F21 0x0070
  • #define SCAN_F22 0x0071
  • #define SCAN_F23 0x0072
  • #define SCAN_F24 0x0073
  • #define SCAN_MUTE 0x007F
  • #define SCAN_VOLUME_UP 0x0080
  • #define SCAN_VOLUME_DOWN 0x0081
  • #define SCAN_BRIGHTNESS_UP 0x0100
  • #define SCAN_BRIGHTNESS_DOWN 0x0101
  • #define SCAN_SUSPEND 0x0102
  • #define SCAN_HIBERNATE 0x0103
  • #define SCAN_TOGGLE_DISPLAY 0x0104
  • #define SCAN_RECOVERY 0x0105
  • #define SCAN_EJECT 0x0106
uefi_ami_bios.1715062134.txt.gz · 上一次變更: 2024/05/07 14:08 由 don