====== UEFI AMI BIOS 研究 ====== ===== AMI Utility ===== ==== MMTOOL ==== * Module Management Tool - Manage the Firmware file modules (Modules, Option ROM, CPU microcode Patch, ROM holes) that are contained in the Aptio firmware image. - The MMTOOL Module Management Utility offers the following features: * Insert * Replace * Delete * Displays ==== AMIBCP ==== * AMI BIOS Configuration Program * Provides easy customization of some Aptio features in a ROM file without using source code - BIOS setup options – Change default values, hide questions - BIOS strings – Displayed at boot or in BIOS setup - PCI IRQ Routing Table - APTIO DMI Tables – Change static data - Boot Order Grouping - BIOS Features ==== ChangeLOGO ==== * AMI ChangeLogo Tool allows you to replace the logo inside the APTIO Firmware file or Capsule file with a new one * The Change Logo Tool supports the following image formats outlined below - BMP files - JPEG files - GIF files - PCX files - PNG files ==== AMISLP ==== * AMISLP (AMI System Lock Preinstallation) - Used by OEMs to pre-activate Microsoft Windows - Display OEM IDs - Amislp /D ROMfilename ==== AMISDE ==== * Provides an easy way to extract setup questions and its related information from the given APTIO ROM Image. ==== AMISCE ==== ==== DMIEdit ==== * Desktop Management Interface Edit. * Read or write data associated with SMBIOS tables. * The following SMBIOS tables could be modified by DMIEdit: - Bios Information (Type 0) - System (Type 1) - Base Board (Type 2) - Chassis (Type 3) - Processor Information(Type 4) - OEM String (Type 11) - System Configuration Options (Type 12) - Portable Battery (Type 22) - System Power Supply (Type 39) ==== AFU ==== * AMI Firmware Update - Update system - Main BIOS - Boot Block - NVRAM - Embedded Controller - Intel ME - OEM Activation file (OA 3.0 for Window8) * AFU Secure Flash - Security OFBD - Capsule - Recovery ==== AMIUCP ==== * Utility Configuration Program * Customize AMIBIOS ROM Utility’s capabilities for specific product or user. This is an utility to configure default settings/behaviors of certain compatible utilities * This utility offers following features: - Display Utility Identification Information - Insert - Delete - Extract - Replace - Insert ROM image - Exchange ROM image - Insert Default Command String - Exchange Default Command String - Edit OEM Version - Change Command Default Status ===== 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. ==== SetupItemCallbacks elink Prototype define ==== 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 ==== Setup instruction ==== * Grayoutif 的作用是设定某一个 item 跟随另一个 item 的变化而被设置为灰色无法修改。 * Suppressif 的作用是设定某一个 item 跟随另一个 item 的变化而被自动隐藏 。 ==== HotKey Class Hook ==== - CheckForKeyHook * 在POST過程中,會有很多地方都加入此HOOK,如果插入在此HOOK則很多地方都會檢查並執行。 - OemKey1Hook - OemKey2Hook - OemKey3Hook - OemKey4Hook * 一般給OEM使用,如RECOVERY,按了按鍵,則做對應動作。 ==== OemKey1-4 Token ==== - SETUP_OEM_KEY1_ENABLE - SETUP_OEM_KEY1_UNICODE * 使用方式像 F1, F2, F3 ...等HOTKEY - SETUP_OEM_KEY1_SCAN * 使用方式像 A, B, C ...等HOTKEY - SETUP_OEM_KEY1_SHIFT * 檢查是否有按下 CTRL/SHIFT/ALT/Windows Modifier Key - SETUP_OEM_KEY1_TOGGLE * 檢查是否有按下 CAPS LOCK/ NUMBER LOCK ==== 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