5.UEFI Platform Initialization Distribution Packaging Specification 当前最新版本 UEFI Platform Initialization Distribution Packaging Specification Version 1.1
/** @file
Logo DXE Driver, install Edkii Platform Logo protocol.
Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/ShellCEntryLib.h>
#include <Protocol/HiiDatabase.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/HiiImageEx.h>
#include <Protocol/PlatformLogo.h>
#include <Protocol/HiiPackageList.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
{ \
0x9042a9de, 0x23dc, 0x4a38, {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } \
}
static EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
//DO NOT REMOVE IMAGE_TOKEN (IMG_LOGO)
/**
Entrypoint of this module.
This function is the entrypoint of this module. It installs the Edkii
Platform Logo protocol.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
**/
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
EFI_HII_IMAGE_PACKAGE_HDR *ImageHeader;
EFI_HII_IMAGE_BLOCK *ImageBlocktType;
EFI_HII_IIBT_IMAGE_24BIT_BASE *ImageData;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
UINT16 i,j;
UINT8* RGB32;
//Step1. Get Package List Header Address
//
// Retrieve HII package list from ImageHandle
//
Status = gBS->OpenProtocol (
ImageHandle,
&gEfiHiiPackageListProtocolGuid,
(VOID **) &PackageListHeader,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
Print(L"HII Image Package with logo not found in PE/COFF resource section\n");
return Status;
}
Print(L"PackageList :\n GUID=[%g] Length=[%X]\n",
PackageListHeader->PackageListGuid,
PackageListHeader->PackageLength);
//Step2. Parser HII Image
ImageHeader=(EFI_HII_IMAGE_PACKAGE_HDR*)(PackageListHeader+1);
Print(L"Image Header:\n Length=[%d] Type=[%d]\n",ImageHeader->Header.Length,ImageHeader->Header.Type);
Print(L"ImageOffset %d PalOffset %d\n",ImageHeader->ImageInfoOffset,ImageHeader->PaletteInfoOffset);
ImageBlocktType=(EFI_HII_IMAGE_BLOCK *)(ImageHeader+1);
Print(L"ImageBlockType %x\n",*ImageBlocktType);
ImageData=(EFI_HII_IIBT_IMAGE_24BIT_BASE *)(ImageBlocktType+1);
Print(L"ImageData:\n Width=[%d] Heigth=[%d]\n",ImageData->Width,ImageData->Height);
Status = gBS->LocateProtocol(&GraphicsOutputProtocolGuid, NULL, (VOID **) &GraphicsOutput);
if (EFI_ERROR(Status)) {
Print(L"Loading Graphics_Output_Protocol error!\n");
return EFI_SUCCESS;
}
//Step3. Get BMP Image
RGB32 = (UINT8*)AllocatePool(ImageData->Width * ImageData->Height *4);
for (j=0;j<ImageData->Height;j++) {
for (i=0;i<ImageData->Width;i++) {
RGB32[(j*ImageData->Width+i)*4] = ImageData->Bitmap[(j*ImageData->Width+i)].b;//Blue
RGB32[(j*ImageData->Width+i)*4+1]= ImageData->Bitmap[(j*ImageData->Width+i)].g; //Green
RGB32[(j*ImageData->Width+i)*4+2]= ImageData->Bitmap[(j*ImageData->Width+i)].r; //Red
RGB32[(j*ImageData->Width+i)*4+3]= 0;
}
}
//Step4. Show the Image
GraphicsOutput->Blt(
GraphicsOutput,
(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) RGB32,
EfiBltBufferToVideo,
0, 0,
200, 0,
ImageData->Width, ImageData->Height, 0);
FreePool(RGB32);
return Status;
}
HIIImageTest.idf #image IMG_LOGO TestImage.bmp
#image IMG_LOGO TestImage.bmp
HIIImageTest.inf
## @file
# The default logo bitmap picture shown on setup screen.
#
# Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = hit
MODULE_UNI_FILE = LogoDxe.uni
FILE_GUID = F74D20EE-37E7-48FC-97F7-9B1047749C69
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiMain
#
# This flag specifies whether HII resource section is generated into PE image.
#
UEFI_HII_RESOURCE_SECTION = TRUE
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#
[Sources]
TestImage.bmp
HIIImageTest.c
HIIImageTest.idf
[Packages]
MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
StdLib/StdLib.dec
ShellPkg/ShellPkg.dec
[LibraryClasses]
DebugLib
UefiApplicationEntryPoint
PrintLib
UefiLib
[Protocols]
gEfiHiiPackageListProtocolGuid ## PRODUCES CONSUMES
很多时候,为了分析研究现象,我们需要收集一些信息,比如:当前Windows版本,BIOS 版本或者 ME 版本等等。 Intel SSU 就是为此设计的。这个工具介绍如下:
Intel® System Support Utility. Intel® System Support Utility (Intel® SSU) is a standalone utility that performs a detailed scan and report of your computer system information and devices. Intel SSU produces an output file that can be saved, viewed, and shared by the user.
这里,实验的目标就是在不修改 RamDiskDxe.efi 的情况下,当语言选择为法语时,修改 Ram Disk 的名称。 首先研究一下 Setup 的选项,经过研究发现在\MdeModulePkg\Library\UefiHiiLib\HiiString.c中有一个HiiGetString的函数。从注释可以看出,这个函数负责返回 Hii Package中的字符串,因此,我们在其中添加代码,当发现语言设置为法语时,并且取得 Ram Disk 相关的String后,用我们定义的 String 替换掉正常的返回值从而实现“翻译”的动作。
/**
Retrieves a string from a string package in a specific language. If the language
is not specified, then a string from a string package in the current platform
language is retrieved. If the string can not be retrieved using the specified
language or the current platform language, then the string is retrieved from
the string package in the first language the string package supports. The
returned string is allocated using AllocatePool(). The caller is responsible
for freeing the allocated buffer using FreePool().
If HiiHandle is NULL, then ASSERT().
If StringId is 0, then ASSET.
@param[in] HiiHandle A handle that was previously registered in the HII Database.
@param[in] StringId The identifier of the string to retrieved from the string
package associated with HiiHandle.
@param[in] Language The language of the string to retrieve. If this parameter
is NULL, then the current platform language is used. The
format of Language must follow the language format assumed
the HII Database.
@retval NULL The string specified by StringId is not present in the string package.
@retval Other The string was returned.
**/
EFI_STRING
EFIAPI
HiiGetString (
IN EFI_HII_HANDLE HiiHandle,
IN EFI_STRING_ID StringId,
IN CONST CHAR8 *Language OPTIONAL
)
最终代码如下:
//
// Return the Null-terminated Unicode string
//
//LABZ_Start
if (String!=NULL) {
DEBUG((DEBUG_INFO, "Get [%s]\n",String));
if (StrCmp(String,L"Choisir la Langue")==0) { //这里判断一下语言是否已经选择为法语
DEBUG((DEBUG_INFO, "Let's speek French\n"));
FrenchX=TRUE; //做一个标记
}
//只有在切换为法语以及发现需要替换的字符串时再下手
if ((FrenchX)&&(StrCmp(String,L"RAM Disk Configuration")==0)) {
DEBUG((DEBUG_INFO, "Replace item string\n"));
//"RAM Disk Configuration"
//"Jia zhuang fayu "
StrCpy(String,L"Jia zhuang fayu ");
}
}
//LABZ_End