From nobody Sun May 5 19:49:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+71001+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71001+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1612151678; cv=none; d=zohomail.com; s=zohoarc; b=P5frgXKpTNsyl7qFyegtzn5c+M5gLQdrm5Wg4PLL29o//xQ7RCMhgOECr+FXT3KCmy+DA/eakJUraFeJjAXexZCCFURaydMUbe0IfnJOWgZY7BprSeAJOCiyABHzsEpu1OMXKzTP1q1uvKxuoSnlON0d8te20gjdivMOTdydwaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612151678; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=3V9Ha0kKWf9ZdQ16MhgpVlIfmHp3CbIDmYqrD+u7N6A=; b=MQkxvVu0/9pgpxxpyHhgfD7JiDr1bqfkagQFQrmNTaw2t3T0PCxguTTRkZRcmm+EeBsrFEtolPGDfuP7WFAK6eI1qethJJ5al9W2HDjeDSpp3YxjRwaQxw+1RcKg5QhKDWFuHfLN/ruEW3RYs2RzNbysFJhhOscJs+CAsVt0Q18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71001+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1612151678778509.7128062358861; Sun, 31 Jan 2021 19:54:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id WmcAYY1788612xkVLNovAHcb; Sun, 31 Jan 2021 19:54:38 -0800 X-Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web10.29055.1612151677825474959 for ; Sun, 31 Jan 2021 19:54:37 -0800 X-Received: from pps.filterd (m0134422.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1113sbjN011555; Mon, 1 Feb 2021 03:54:37 GMT X-Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0b-002e3701.pphosted.com with ESMTP id 36dh76dqrh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Feb 2021 03:54:37 +0000 X-Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3425.houston.hpe.com (Postfix) with ESMTP id 67EF3A1; Mon, 1 Feb 2021 03:54:36 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id 5228748; Mon, 1 Feb 2021 03:54:35 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Dandan Bi , Eric Dong , Nickle Wang Subject: [edk2-devel] [PATCH v3] MdeModulePkg/Library: Add HiiGetStringEx to UefiHiiLib for EDK2 Redfish Date: Mon, 1 Feb 2021 11:05:42 +0800 Message-Id: <20210201030542.22997-1-abner.chang@hpe.com> X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: GOYCajnKhFAh2IR9VZIeQJx9x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1612151678; bh=0OpU95ojihoLfw2hGXp8zc3keNdzBRE1lSl5hLYk6nQ=; h=Cc:Date:From:Reply-To:Subject:To; b=TAHAhTaQHXWUIEsXc5HqbnGYBvplIYhurI41JDJNZnhKquhJSGs5IeI4XjbJr1X4IpX iKlSgo3TR+VhHR26y8O0/hobVtCezaLABoqFWZGYyG1ZaXenQdldU2me2/D9myHKeMpAV zFiwryW4kMcofdglMIDZYUEB3efNHR+xmJk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add HiiGetStringEx and leveraged by HiiGetString function to support getting string with the best language in optionally. This avoids the string in x-uefi language is misled to the language defined by "PlatformLang" or the "Supported Languages". This change is introduced to support x-uefi keyword language for configuring BIOS setting. Signed-off-by: Jiaxin Wu Signed-off-by: Siyuan Fu Signed-off-by: Fan Wang Signed-off-by: Abner Chang Cc: Dandan Bi Cc: Eric Dong Cc: Nickle Wang Reviewed-by: Dandan Bi with this is handled. --- MdeModulePkg/Include/Library/HiiLib.h | 60 ++++++++++--- MdeModulePkg/Library/UefiHiiLib/HiiString.c | 98 +++++++++++++++------ 2 files changed, 119 insertions(+), 39 deletions(-) diff --git a/MdeModulePkg/Include/Library/HiiLib.h b/MdeModulePkg/Include/L= ibrary/HiiLib.h index c475cb74a1..cd9027fefd 100644 --- a/MdeModulePkg/Include/Library/HiiLib.h +++ b/MdeModulePkg/Include/Library/HiiLib.h @@ -1,7 +1,8 @@ /** @file Public include file for the HII Library =20 -Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
+(C) Copyright 2021 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -123,16 +124,8 @@ HiiSetString ( ; =20 /** - 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 pla= tform - language is retrieved. If the string cannot be retrieved using the spec= ified - language or the current platform language, then the string is retrieved = from - the string package in the first language the string package supports. T= he - returned string is allocated using AllocatePool(). The caller is respon= sible - for freeing the allocated buffer using FreePool(). - - If HiiHandle is NULL, then ASSERT(). - If StringId is 0, then ASSERT(). + Retrieves a string from a string package in a specific language specifie= d in Language + or in the best lanaguage. See HiiGetStringEx () for the details. =20 @param[in] HiiHandle A handle that was previously registered in the HI= I Database. @param[in] StringId The identifier of the string to retrieved from th= e string @@ -152,8 +145,49 @@ HiiGetString ( IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL - ) -; + ); + +/** + Retrieves a string from a string package in a specific language or in th= e best + language at discretion of this function according to the priority of lan= guages. + TryBestLanguage is used to get the string in the best language or in the= language + specified in Language parameter. The behavior is, + If TryBestLanguage is TRUE, this function looks for the best language fo= r the string. + - If the string can not be retrieved using the specified language or th= e current + platform language, then the string is retrieved from the string packa= ge in the + first language the string package supports. + If TryBestLanguage is FALSE, Language must be specified for retrieving t= he string. + + The returned string is allocated using AllocatePool(). The caller is re= sponsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. + If TryBestLanguage is FALE and Language is NULL, then ASSERT(). + + @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. I= f this parameter + is NULL, then the current platform languag= e is used. The + format of Language must follow the languag= e format assumed + the HII Database. + @param[in] TryBestLanguage If TRUE, try to get the best matching lang= uage from all + supported languages.If FALSE, the Language= must be assigned + for the StringID. + + @retval NULL The string specified by StringId is not present in the st= ring package. + @retval Other The string was returned. + +**/ +EFI_STRING +EFIAPI +HiiGetStringEx ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL, + IN BOOLEAN TryBestLanguage + ); =20 /** Retrieves a string from a string package named by GUID, in the specified= language. diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiString.c b/MdeModulePkg/Lib= rary/UefiHiiLib/HiiString.c index 95229f8a8c..a9a11aef98 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiString.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiString.c @@ -1,7 +1,8 @@ /** @file HII Library implementation that uses DXE protocols and services. =20 - Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
+ (C) Copyright 2021 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -190,16 +191,8 @@ HiiGetPackageString ( } =20 /** - 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 pla= tform - language is retrieved. If the string can not be retrieved using the spe= cified - language or the current platform language, then the string is retrieved = from - the string package in the first language the string package supports. T= he - returned string is allocated using AllocatePool(). The caller is respon= sible - for freeing the allocated buffer using FreePool(). - - If HiiHandle is NULL, then ASSERT(). - If StringId is 0, then ASSET. + Retrieves a string from a string package in a specific language specifie= d in Language + or in the best lanaguage. See HiiGetStringEx () for the details. =20 @param[in] HiiHandle A handle that was previously registered in the HI= I Database. @param[in] StringId The identifier of the string to retrieved from th= e string @@ -220,6 +213,51 @@ HiiGetString ( IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL ) +{ + return HiiGetStringEx (HiiHandle, StringId, Language, TRUE); +} + +/** + Retrieves a string from a string package in a specific language or in th= e best + language at discretion of this function according to the priority of lan= guages. + TryBestLanguage is used to get the string in the best language or in the= language + specified in Language parameter. The behavior is, + If TryBestLanguage is TRUE, this function looks for the best language fo= r the string. + - If the string can not be retrieved using the specified language or th= e current + platform language, then the string is retrieved from the string packa= ge in the + first language the string package supports. + If TryBestLanguage is FALSE, Language must be specified for retrieving t= he string. + + The returned string is allocated using AllocatePool(). The caller is re= sponsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. + If TryBestLanguage is FALE and Language is NULL, then ASSERT(). + + @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. I= f this parameter + is NULL, then the current platform languag= e is used. The + format of Language must follow the languag= e format assumed + the HII Database. + @param[in] TryBestLanguage If TRUE, try to get the best matching lang= uage from all + supported languages.If FALSE, the Language= must be assigned + for the StringID. + + @retval NULL The string specified by StringId is not present in the st= ring package. + @retval Other The string was returned. + +**/ +EFI_STRING +EFIAPI +HiiGetStringEx ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL, + IN BOOLEAN TryBestLanguage + ) { EFI_STATUS Status; UINTN StringSize; @@ -231,7 +269,10 @@ HiiGetString ( =20 ASSERT (HiiHandle !=3D NULL); ASSERT (StringId !=3D 0); - + // + // Language must be specified if TryBestLanguage =3D FALSE. + // + ASSERT (!(TryBestLanguage =3D=3D FALSE && Language =3D=3D NULL)); // // Initialize all allocated buffers to NULL // @@ -261,21 +302,26 @@ HiiGetString ( Language =3D ""; } =20 - // - // Get the best matching language from SupportedLanguages - // - BestLanguage =3D GetBestLanguage ( - SupportedLanguages, - FALSE, // R= FC 4646 mode - Language, // H= ighest priority - PlatformLanguage !=3D NULL ? PlatformLanguage : "", //= Next highest priority - SupportedLanguages, // L= owest priority - NULL - ); - if (BestLanguage =3D=3D NULL) { - goto Error; + if (TryBestLanguage) { + // + // Get the best matching language from SupportedLanguages + // + BestLanguage =3D GetBestLanguage ( + SupportedLanguages, + FALSE, //= RFC 4646 mode + Language, //= Highest priority + PlatformLanguage !=3D NULL ? PlatformLanguage : "", = // Next highest priority + SupportedLanguages, //= Lowest priority + NULL + ); + if (BestLanguage =3D=3D NULL) { + goto Error; + } + } else { + BestLanguage =3D (CHAR8 *) Language; } =20 + // // Retrieve the size of the string in the string package for the BestLan= guage // @@ -337,7 +383,7 @@ Error: if (PlatformLanguage !=3D NULL) { FreePool (PlatformLanguage); } - if (BestLanguage !=3D NULL) { + if (TryBestLanguage && BestLanguage !=3D NULL) { FreePool (BestLanguage); } =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#71001): https://edk2.groups.io/g/devel/message/71001 Mute This Topic: https://groups.io/mt/80276844/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-