From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Jaben
Subject: [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance
Date: Fri, 26 Jan 2018 17:07:38 +0800 [thread overview]
Message-ID: <20180126090739.14188-2-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20180126090739.14188-1-ruiyu.ni@intel.com>
Original code locates the first UnicodeCollation instance in
DXE Core protocol database.
It's not correct considering multiple UnicodeCollation instances
exist in system.
The patch changes logic to find the one that matches the current
system language.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com.
---
.../UefiShellCommandLib/UefiShellCommandLib.c | 76 ++++++++++++++++++----
.../UefiShellCommandLib/UefiShellCommandLib.h | 3 +-
2 files changed, 67 insertions(+), 12 deletions(-)
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
index c7984f11b2..0df252b420 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
@@ -1,7 +1,7 @@
/** @file
Provides interface to shell internal functions for shell commands.
- Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
@@ -72,14 +72,70 @@ CommandInit(
VOID
)
{
- EFI_STATUS Status;
+ UINTN NumHandles;
+ EFI_HANDLE *Handles;
+ EFI_UNICODE_COLLATION_PROTOCOL *Uc;
+ CHAR8 *BestLanguage;
+ UINTN Index;
+ EFI_STATUS Status;
+ CHAR8 *PlatformLang;
+
+ GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);
+ if (PlatformLang == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
if (gUnicodeCollation == NULL) {
- Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);
- if (EFI_ERROR(Status)) {
- return (EFI_DEVICE_ERROR);
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiUnicodeCollation2ProtocolGuid,
+ NULL,
+ &NumHandles,
+ &Handles
+ );
+ if (EFI_ERROR (Status)) {
+ NumHandles = 0;
+ Handles = NULL;
}
+ for (Index = 0; Index < NumHandles; Index++) {
+ //
+ // Open Unicode Collation Protocol
+ //
+ Status = gBS->OpenProtocol (
+ Handles[Index],
+ &gEfiUnicodeCollation2ProtocolGuid,
+ (VOID **) &Uc,
+ gImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+
+ //
+ // Find the best matching matching language from the supported languages
+ // of Unicode Collation2 protocol.
+ //
+ BestLanguage = GetBestLanguage (
+ Uc->SupportedLanguages,
+ FALSE,
+ PlatformLang,
+ NULL
+ );
+ if (BestLanguage != NULL) {
+ FreePool (BestLanguage);
+ gUnicodeCollation = Uc;
+ break;
+ }
+ }
+ if (Handles != NULL) {
+ FreePool (Handles);
+ }
+ FreePool (PlatformLang);
}
- return (EFI_SUCCESS);
+
+ return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;
}
/**
@@ -112,11 +168,9 @@ ShellCommandLibConstructor (
mProfileListSize = 0;
mProfileList = NULL;
- if (gUnicodeCollation == NULL) {
- Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);
- if (EFI_ERROR(Status)) {
- return (EFI_DEVICE_ERROR);
- }
+ Status = CommandInit ();
+ if (EFI_ERROR (Status)) {
+ return EFI_DEVICE_ERROR;
}
return (RETURN_SUCCESS);
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
index b998656b4e..bcfde60c26 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
@@ -1,7 +1,7 @@
/** @file
Provides interface to shell internal functions for shell commands.
- Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -19,6 +19,7 @@
#include <Uefi.h>
#include <Guid/FileInfo.h>
+#include <Guid/GlobalVariable.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/LoadedImage.h>
--
2.15.1.windows.2
next prev parent reply other threads:[~2018-01-26 9:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-26 9:07 [PATCH 0/2] User UnicodeCollation in StrinCmp Ruiyu Ni
2018-01-26 9:07 ` Ruiyu Ni [this message]
2018-01-26 9:07 ` [PATCH 2/2] ShellPkg/Level2Command: Use " Ruiyu Ni
-- strict thread matches above, loose matches on Subject: below --
2018-01-26 9:51 [PATCH 0/2] User " Ruiyu Ni
2018-01-26 9:51 ` [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance Ruiyu Ni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180126090739.14188-2-ruiyu.ni@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox