UEFI 基础教程 (十三) - VFR,HFR 简单使用

一、 修改UEFI UiApp源代码

  1. 修改 FrontPageStrings.uni 与 FrontPageVfr.Vfr
    添加字符串资源到 MdeModulePkg/Application/UiApp/FrontPageStrings.uni
//Add CSDN UI resources
#string STR_CSDN_BANNER_LEFT           #language en-US  "Csdn Bannder Left"
#string STR_CSDN_BANNER_RIGHT          #language en-US  "Csdn Bannder Right"

#string STR_CSDN_STRING                #language en-US  "CsdnText"
                                       #language fr-FR  "CsdnText"
#string STR_CSDN_STRING_HELP           #language en-US  "CsdnText the current setting."
                                       #language fr-FR  "CsdnText the current setting."

#string STR_CSDN_RADIO_STRING          #language en-US  "CsdnRdioBtn"
                                       #language fr-FR  "CsdnRdioBtn"
#string STR_CSDN_RADIO_STRING_HELP     #language en-US  "CsdnRadio the current setting."
                                       #language fr-FR  "CsdnRadio the current setting."

#string STR_CSDN_STRING_RADIO_1        #language en-US  "Csdn Radio Button No 1"
#string STR_CSDN_STRING_RADIO_2        #language en-US  "Csdn Radio Button No 2"
#string STR_CSDN_STRING_RADIO_3        #language en-US  "Csdn Radio Button No 3"
#string STR_CSDN_STRING_RADIO_4        #language en-US  "Csdn Radio Button No 4"
#string STR_CSDN_STRING_RADIO_5        #language en-US  "Csdn Radio Button No 5"
#string STR_CSDN_STRING_RADIO_6        #language en-US  "Csdn Radio Button No 6"
#string STR_CSDN_STRING_RADIO_7        #language en-US  "Csdn Radio Button No 7"

修改 FrontPageVfr.Vfr的Lable
MdeModulePkg/Application/UiApp/FrontPageVfr.Vfr

    banner
      title = STRING_TOKEN(STR_CSDN_BANNER_LEFT),
      line  4,
      align left;

    banner
      title = STRING_TOKEN(STR_CSDN_BANNER_RIGHT),
      line  4,
      align right;
  1. 修改 FrontPageCustomizedUi.c 与 FrontPageCustomizedUiSupport.c
    添加 Oneof(RadioButton) 菜单
    MdeModulePkg/Application/UiApp/FrontPageCustomizedUi.c
/**
  Customize menus in the page.

  @param[in]  HiiHandle             The HII Handle of the form to update.
  @param[in]  StartOpCodeHandle     The context used to insert opcode.
  @param[in]  CustomizePageType     The page type need to be customized.

**/
VOID
UiCustomizeFrontPage (
  IN EFI_HII_HANDLE  HiiHandle,
  IN VOID            *StartOpCodeHandle
  )
{
  //
  // Create "Select CSDN" menu with Oneof opcode.
  //
  UiCreateCsdnRadioMenu(HiiHandle, StartOpCodeHandle);

  ...

  //
  // Create csdn menu.
  //
  UiCreateCsdnMenu(HiiHandle, StartOpCodeHandle);
}

MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c

// 定义 CallBack 
EFI_STATUS
CsdnRadioChangeHandler (
  IN  EFI_IFR_TYPE_VALUE                     *Value
  )
{
  EFI_STATUS                    Status;

  CHAR8  *CsdnText = "Csdn Radio Button No 1";
  DEBUG((EFI_D_INFO,"[csdn] CsdnRadioChangeHandler value=%x\n",Value->u8));

  Status = gRT->SetVariable (
                    L"CSDNRadioButtonText",
                    &gEfiIfrFrontPageGuid,
                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
                    22,
                    CsdnText
                    );
  if (EFI_ERROR (Status)) {
    DEBUG((EFI_D_INFO,"[csdn] CsdnRadioChangeHandler status=%r\n",Status));
    return EFI_DEVICE_ERROR;
  }
  return EFI_SUCCESS;
}

//触发 CallBack 
BOOLEAN
UiSupportLibCallbackHandler (
  IN  EFI_HII_HANDLE                         HiiHandle,
  IN  EFI_BROWSER_ACTION                     Action,
  IN  EFI_QUESTION_ID                        QuestionId,
  IN  UINT8                                  Type,
  IN  EFI_IFR_TYPE_VALUE                     *Value,
  OUT EFI_BROWSER_ACTION_REQUEST             *ActionRequest,
  OUT EFI_STATUS                             *Status
  ){
 ...
 switch (QuestionId) {
    case FRONT_PAGE_KEY_CONTINUE:
      //
      // This is the continue - clear the screen and return an error to get out of FrontPage loop
      //
      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
      break;
   ...
    
    //CallBack 触发入口
    case FRONT_PAGE_KEY_CSDN_RADIIO:
      *Status = CsdnRadioChangeHandler(Value);
      break;

    default:
      break;
    }

  }

二、 编译生成EFI文件

运行edksetup.bat && build -a X64 -p OvmfPkg\OvmfPkgX64.dsc -D DEBUG_ON_SERIAL_PORT -t VS2013x86编译整个OvmfPkg Package

三、 运行 UEFI

执行setup-qemu-x64.bat | findstr csdn

UEFI 基础教程 (十三) - VFR,HFR 简单使用_第1张图片
UEFI 基础教程 (十三) - VFR,HFR 简单使用_第2张图片

四、 小结

在UEFI平台可以通过修改 VFR/HFR等相关文件来配置SETUP界面, 其中
UNI文件用来存放资源, C文件用作driver 用来动态更新配置值。

你可能感兴趣的:(15_固件开发)