Update BDS boot option description string to use UNI file string in GenericBdsLib for localization.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9836 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
gikidy 2010-01-27 07:18:36 +00:00
parent 710a340911
commit 9aa7ba01aa
8 changed files with 194 additions and 184 deletions

View File

@ -13,8 +13,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "InternalBdsLib.h"
#include "String.h"
BOOLEAN mEnumBootDevice = FALSE;
EFI_HII_HANDLE gBdsLibStringPackHandle = NULL;
///
/// This GUID is used for an EFI Variable that stores the front device pathes
@ -22,6 +24,49 @@ BOOLEAN mEnumBootDevice = FALSE;
///
EFI_GUID mHdBootVariablePrivateGuid = { 0xfab7e9e1, 0x39dd, 0x4f2b, { 0x84, 0x8, 0xe2, 0xe, 0x90, 0x6c, 0xb6, 0xde } };
///
/// This GUID is used for register UNI string.
///
EFI_GUID mBdsLibStringPackGuid = { 0x3b4d9b23, 0x95ac, 0x44f6, { 0x9f, 0xcd, 0xe, 0x95, 0x94, 0x58, 0x6c, 0x72 } };
///
/// This GUID is used for Set/Get platform language into/from variable at last time enumeration to ensure the enumeration will
/// only execute once.
///
EFI_GUID mBdsLibLastLangGuid = { 0xe8c545b, 0xa2ee, 0x470d, { 0x8e, 0x26, 0xbd, 0xa1, 0xa1, 0x3c, 0xa, 0xa3 } };
/**
The constructor function register UNI strings into imageHandle.
It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The constructor successfully added string package.
@retval Other value The constructor can't add string package.
**/
EFI_STATUS
EFIAPI
GenericBdsLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
gBdsLibStringPackHandle = HiiAddPackages (
&mBdsLibStringPackGuid,
&ImageHandle,
GenericBdsLibStrings,
NULL
);
ASSERT (gBdsLibStringPackHandle != NULL);
return EFI_SUCCESS;
}
/**
@ -241,67 +286,13 @@ BdsLibBootViaBootOption (
}
DEBUG_CODE_BEGIN();
UINTN DevicePathTypeValue;
CHAR16 *HiiString;
CHAR16 *BootStringNumber;
UINTN BufferSize;
DevicePathTypeValue = BdsGetBootTypeFromDevicePath (Option->DevicePath);
//
// store number string of boot option temporary.
//
HiiString = NULL;
switch (DevicePathTypeValue) {
case BDS_EFI_ACPI_FLOPPY_BOOT:
HiiString = L"EFI Floppy";
break;
case BDS_EFI_MEDIA_CDROM_BOOT:
case BDS_EFI_MESSAGE_SATA_BOOT:
case BDS_EFI_MESSAGE_ATAPI_BOOT:
HiiString = L"EFI DVD/CDROM";
break;
case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
HiiString = L"EFI USB Device";
break;
case BDS_EFI_MESSAGE_SCSI_BOOT:
HiiString = L"EFI SCSI Device";
break;
case BDS_EFI_MESSAGE_MISC_BOOT:
HiiString = L"EFI Misc Device";
break;
case BDS_EFI_MESSAGE_MAC_BOOT:
HiiString = L"EFI Network";
break;
case BBS_DEVICE_PATH:
//
// Do nothing for legacy boot option.
//
break;
default:
DEBUG((EFI_D_INFO, "Can not find HiiString for given device path type 0x%x\n", DevicePathTypeValue));
if (Option->Description == NULL) {
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting from unknown device path\n"));
} else {
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));
}
//
// If found Hii description string then cat Hii string with original description.
//
if (HiiString != NULL) {
BootStringNumber = Option->Description;
BufferSize = StrSize(BootStringNumber);
BufferSize += StrSize(HiiString);
Option->Description = AllocateZeroPool(BufferSize);
ASSERT (Option->Description != NULL);
StrCpy (Option->Description, HiiString);
if (StrnCmp (BootStringNumber, L"0", 1) != 0) {
StrCat (Option->Description, L" ");
StrCat (Option->Description, BootStringNumber);
}
FreePool (BootStringNumber);
}
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));
DEBUG_CODE_END();
Status = gBS->LoadImage (
@ -1007,6 +998,8 @@ BdsLibEnumerateAllBootOption (
UINTN NumberFileSystemHandles;
BOOLEAN NeedDelete;
EFI_IMAGE_DOS_HEADER DosHeader;
CHAR8 *PlatLang;
CHAR8 *LastLang;
EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
@ -1015,6 +1008,8 @@ BdsLibEnumerateAllBootOption (
UsbNumber = 0;
MiscNumber = 0;
ScsiNumber = 0;
PlatLang = NULL;
LastLang = NULL;
ZeroMem (Buffer, sizeof (Buffer));
//
@ -1022,8 +1017,21 @@ BdsLibEnumerateAllBootOption (
// device from the boot order variable
//
if (mEnumBootDevice) {
Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
return Status;
LastLang = GetVariable (L"LastEnumLang", &mBdsLibLastLangGuid);
PlatLang = GetEfiGlobalVariable (L"PlatformLang");
if (LastLang == PlatLang) {
Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
return Status;
} else {
Status = gRT->SetVariable (
L"LastEnumLang",
&mBdsLibLastLangGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
sizeof (PlatLang),
PlatLang
);
ASSERT_EFI_ERROR (Status);
}
}
//
@ -1068,7 +1076,11 @@ BdsLibEnumerateAllBootOption (
switch (DevicePathType) {
case BDS_EFI_ACPI_FLOPPY_BOOT:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", FloppyNumber);
if (FloppyNumber != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)));
}
BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
FloppyNumber++;
break;
@ -1078,25 +1090,42 @@ BdsLibEnumerateAllBootOption (
//
case BDS_EFI_MESSAGE_ATAPI_BOOT:
case BDS_EFI_MESSAGE_SATA_BOOT:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", CdromNumber);
if (CdromNumber != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)));
}
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer));
BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
CdromNumber++;
break;
case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", UsbNumber);
if (UsbNumber != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)));
}
BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
UsbNumber++;
break;
case BDS_EFI_MESSAGE_SCSI_BOOT:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", ScsiNumber);
if (ScsiNumber != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)));
}
BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
ScsiNumber++;
break;
case BDS_EFI_MESSAGE_MISC_BOOT:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", MiscNumber);
if (MiscNumber != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)));
}
BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
MiscNumber++;
break;
@ -1158,7 +1187,11 @@ BdsLibEnumerateAllBootOption (
//
BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Non-Block Boot Device %d", NonBlockNumber);
if (NonBlockNumber != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)));
}
BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);
NonBlockNumber++;
}
@ -1184,7 +1217,11 @@ BdsLibEnumerateAllBootOption (
);
for (Index = 0; Index < NumOfLoadFileHandles; Index++) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", Index);
if (Index != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)), Index);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)));
}
BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);
}

View File

@ -23,6 +23,7 @@
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = GenericBdsLib|DXE_DRIVER UEFI_APPLICATION
CONSTRUCTOR = GenericBdsLibConstructor
#
# The following information is for reference only and not required by the build tools.
@ -39,6 +40,9 @@
BdsBoot.c
InternalBdsLib.h
Bmp.h
String.h
String.c
GenericBdsStrings.uni
[Sources.IPF]
Ipf/ShadowRom.c
@ -67,6 +71,7 @@
TimerLib
PcdLib
DxeServicesLib
HiiLib
[Guids]
gEfiVT100PlusGuid ## CONSUMES ## GUID (The type of terminal)

View File

@ -0,0 +1,32 @@
/** @file
String support
Copyright (c) 2010, Intel Corporation. <BR>
All rights reserved. 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 "String.h"
/**
Get string by string id from HII Interface
@param Id String ID.
@retval CHAR16 * String from ID.
@retval NULL If error occurs.
**/
CHAR16 *
BdsLibGetStringById (
IN EFI_STRING_ID Id
)
{
return HiiGetString (gBdsLibStringPackHandle, Id, NULL);
}

View File

@ -0,0 +1,48 @@
/** @file
String support
Copyright (c) 2010, Intel Corporation. <BR>
All rights reserved. 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.
**/
#ifndef _STRING_H_
#define _STRING_H_
#include <Library/HiiLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
extern EFI_HII_HANDLE gBdsLibStringPackHandle;
//
// This is the VFR compiler generated header file which defines the
// string identifiers.
//
extern UINT8 GenericBdsLibStrings[];
/**
Get string by string id from HII Interface
@param Id String ID.
@retval CHAR16 * String from ID.
@retval NULL If error occurs.
**/
CHAR16 *
BdsLibGetStringById (
IN EFI_STRING_ID Id
);
#endif // _STRING_H_

View File

@ -876,8 +876,6 @@ BOpt_GetBootOptions (
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
UINTN MenuCount;
UINT8 *Ptr;
UINTN DevicePathType;
CHAR16 *HiiString;
MenuCount = 0;
BootOrderListSize = 0;
@ -1015,56 +1013,10 @@ BOpt_GetBootOptions (
LoadOptionPtr += sizeof (UINT16);
StringSize = StrSize((UINT16*)LoadOptionPtr);
//
// Get Hii description string according to device path type
//
HiiString = NULL;
DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);
switch (DevicePathType) {
case BDS_EFI_ACPI_FLOPPY_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY));
break;
case BDS_EFI_MESSAGE_SATA_BOOT:
case BDS_EFI_MESSAGE_ATAPI_BOOT:
case BDS_EFI_MEDIA_CDROM_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_DVD));
break;
case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_USB));
break;
case BDS_EFI_MESSAGE_SCSI_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI));
break;
case BDS_EFI_MESSAGE_MISC_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC));
break;
case BDS_EFI_MESSAGE_MAC_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK));
break;
case BBS_DEVICE_PATH:
//
// Do nothing for legacy boot option.
//
break;
default:
DEBUG((EFI_D_INFO, "Can not find HiiString for given device path type 0x%x\n", DevicePathType));
}
if (HiiString != NULL) {
NewLoadContext->Description = AllocateZeroPool(StringSize + StrSize(HiiString));
ASSERT (NewLoadContext->Description != NULL);
StrCpy (NewLoadContext->Description, HiiString);
if (StrnCmp ((UINT16*)LoadOptionPtr, L"0", 1) != 0) {
StrCat (NewLoadContext->Description, L" ");
StrCat (NewLoadContext->Description, (UINT16*)LoadOptionPtr);
}
FreePool (HiiString);
} else {
NewLoadContext->Description = AllocateZeroPool (StrSize((UINT16*)LoadOptionPtr));
ASSERT (NewLoadContext->Description != NULL);
StrCpy (NewLoadContext->Description, (UINT16*)LoadOptionPtr);
}
NewLoadContext->Description = AllocateZeroPool (StrSize((UINT16*)LoadOptionPtr));
ASSERT (NewLoadContext->Description != NULL);
StrCpy (NewLoadContext->Description, (UINT16*)LoadOptionPtr);
ASSERT (NewLoadContext->Description != NULL);
NewMenuEntry->DisplayString = NewLoadContext->Description;

View File

@ -201,10 +201,6 @@ CallBootManager (
VOID *EndOpCodeHandle;
EFI_IFR_GUID_LABEL *StartLabel;
EFI_IFR_GUID_LABEL *EndLabel;
CHAR16 *HiiString;
CHAR16 *BootStringNumber;
UINTN DevicePathType;
UINTN BufferSize;
gOption = NULL;
InitializeListHead (&BdsBootOptionList);
@ -267,66 +263,6 @@ CallBootManager (
continue;
}
//
// Replace description string with UNI file string.
//
BootStringNumber = NULL;
DevicePathType = BdsGetBootTypeFromDevicePath (Option->DevicePath);
//
// store number string of boot option temporary.
//
HiiString = NULL;
switch (DevicePathType) {
case BDS_EFI_ACPI_FLOPPY_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY));
break;
case BDS_EFI_MEDIA_CDROM_BOOT:
case BDS_EFI_MESSAGE_SATA_BOOT:
case BDS_EFI_MESSAGE_ATAPI_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_DVD));
break;
case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_USB));
break;
case BDS_EFI_MESSAGE_SCSI_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI));
break;
case BDS_EFI_MESSAGE_MISC_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC));
break;
case BDS_EFI_MESSAGE_MAC_BOOT:
HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK));
break;
case BBS_DEVICE_PATH:
//
// Do nothing for legacy boot option.
//
break;
default:
DEBUG((EFI_D_INFO, "Can not find HiiString for given device path type 0x%x\n", DevicePathType));
}
//
// If found Hii description string then cat Hii string with original description.
//
if (HiiString != NULL) {
BootStringNumber = Option->Description;
BufferSize = StrSize(BootStringNumber);
BufferSize += StrSize(HiiString);
Option->Description = AllocateZeroPool(BufferSize);
ASSERT (Option->Description != NULL);
StrCpy (Option->Description, HiiString);
if (StrnCmp (BootStringNumber, L"0", 1) != 0) {
StrCat (Option->Description, L" ");
StrCat (Option->Description, BootStringNumber);
}
FreePool (HiiString);
FreePool (BootStringNumber);
}
ASSERT (Option->Description != NULL);
Token = HiiSetString (HiiHandle, 0, Option->Description, NULL);