From 9aa7ba01aa6d3526f99a145415a91798b00d339a Mon Sep 17 00:00:00 2001 From: gikidy Date: Wed, 27 Jan 2010 07:18:36 +0000 Subject: 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 --- .../Library/GenericBdsLib/BdsBoot.c | 173 +++++++++++++-------- .../Library/GenericBdsLib/GenericBdsLib.inf | 5 + .../Library/GenericBdsLib/GenericBdsStrings.uni | Bin 0 -> 3530 bytes .../Library/GenericBdsLib/String.c | 32 ++++ .../Library/GenericBdsLib/String.h | 48 ++++++ 5 files changed, 190 insertions(+), 68 deletions(-) create mode 100644 IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni create mode 100644 IntelFrameworkModulePkg/Library/GenericBdsLib/String.c create mode 100644 IntelFrameworkModulePkg/Library/GenericBdsLib/String.h (limited to 'IntelFrameworkModulePkg/Library/GenericBdsLib') diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c index e9e3435abd..40984adb3a 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c @@ -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 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); + 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)); } - - 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); } diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf b/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf index c5ba83c4a0..3b81f80b76 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf @@ -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) diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni b/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni new file mode 100644 index 0000000000..aab1a7876f Binary files /dev/null and b/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni differ diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c new file mode 100644 index 0000000000..bbbbf3ae54 --- /dev/null +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c @@ -0,0 +1,32 @@ +/** @file + String support + +Copyright (c) 2010, Intel Corporation.
+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); +} diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h b/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h new file mode 100644 index 0000000000..1b09206121 --- /dev/null +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h @@ -0,0 +1,48 @@ +/** @file + String support + +Copyright (c) 2010, Intel Corporation.
+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 +#include +#include +#include +#include + +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_ -- cgit v1.2.3