@@ -1371,6 +1371,149 @@ GetSupportedLanguages (
13711371 return SupportedLanguages ;
13721372}
13731373
1374+ /**
1375+ This function create a new string in String Package or updates an existing
1376+ string in a String Package. If StringId is 0, then a new string is added to
1377+ a String Package. If StringId is not zero, then a string in String Package is
1378+ updated. If SupportedLanguages is NULL, then the string is added or updated
1379+ for all the languages that the String Package supports. If SupportedLanguages
1380+ is not NULL, then the string is added or updated for the set of languages
1381+ specified by SupportedLanguages.
1382+
1383+ If HiiHandle is NULL, then ASSERT().
1384+ If String is NULL, then ASSERT().
1385+
1386+ @param[in] HiiHandle A handle that was previously registered in the
1387+ HII Database.
1388+ @param[in] StringId If zero, then a new string is created in the
1389+ String Package associated with HiiHandle. If
1390+ non-zero, then the string specified by StringId
1391+ is updated in the String Package associated
1392+ with HiiHandle.
1393+ @param[in] String A pointer to the Null-terminated Unicode string
1394+ to add or update in the String Package associated
1395+ with HiiHandle.
1396+ @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of
1397+ language codes. If this parameter is NULL, then
1398+ String is added or updated in the String Package
1399+ associated with HiiHandle for all the languages
1400+ that the String Package supports. If this
1401+ parameter is not NULL, then then String is added
1402+ or updated in the String Package associated with
1403+ HiiHandle for the set oflanguages specified by
1404+ SupportedLanguages. The format of
1405+ SupportedLanguages must follow the language
1406+ format assumed the HII Database.
1407+
1408+ @retval 0 The string could not be added or updated in the String Package.
1409+ @retval Other The EFI_STRING_ID of the newly added or updated string.
1410+
1411+ **/
1412+ EFI_STRING_ID
1413+ InternalHiiSetString (
1414+ IN EFI_HII_HANDLE HiiHandle ,
1415+ IN EFI_STRING_ID StringId OPTIONAL ,
1416+ IN CONST EFI_STRING String ,
1417+ IN CONST CHAR8 * SupportedLanguages OPTIONAL
1418+ )
1419+ {
1420+ EFI_STATUS Status ;
1421+ CHAR8 * AllocatedLanguages ;
1422+ CHAR8 * Supported ;
1423+ CHAR8 * Language ;
1424+
1425+ ASSERT (HiiHandle != NULL );
1426+
1427+ if (SupportedLanguages == NULL ) {
1428+ //
1429+ // Retrieve the languages that the package specified by HiiHandle supports
1430+ //
1431+ AllocatedLanguages = GetSupportedLanguages (HiiHandle );
1432+ } else {
1433+ //
1434+ // Allocate a copy of the SupportLanguages string that passed in
1435+ //
1436+ AllocatedLanguages = AllocateCopyPool (AsciiStrSize (SupportedLanguages ), SupportedLanguages );
1437+ }
1438+
1439+ //
1440+ // If there are not enough resources for the supported languages string, then return a StringId of 0
1441+ //
1442+ if (AllocatedLanguages == NULL ) {
1443+ return (EFI_STRING_ID )(0 );
1444+ }
1445+
1446+ Status = EFI_INVALID_PARAMETER ;
1447+ //
1448+ // Loop through each language that the string supports
1449+ //
1450+ for (Supported = AllocatedLanguages ; * Supported != '\0' ; ) {
1451+ //
1452+ // Cache a pointer to the beginning of the current language in the list of languages
1453+ //
1454+ Language = Supported ;
1455+
1456+ //
1457+ // Search for the next language separator and replace it with a Null-terminator
1458+ //
1459+ for ( ; * Supported != 0 && * Supported != ';' ; Supported ++ ) {
1460+ }
1461+
1462+ if (* Supported != 0 ) {
1463+ * (Supported ++ ) = '\0' ;
1464+ }
1465+
1466+ if ((SupportedLanguages == NULL ) && (AsciiStrnCmp (Language , UEFI_CONFIG_LANG , AsciiStrLen (UEFI_CONFIG_LANG )) == 0 )) {
1467+ //
1468+ // Skip string package used for keyword protocol.
1469+ //
1470+ continue ;
1471+ }
1472+
1473+ //
1474+ // If StringId is 0, then call NewString(). Otherwise, call SetString()
1475+ //
1476+ if (StringId == (EFI_STRING_ID )(0 )) {
1477+ Status = mPrivate .HiiString .NewString (
1478+ & mPrivate .HiiString ,
1479+ HiiHandle ,
1480+ & StringId ,
1481+ Language ,
1482+ NULL ,
1483+ String ,
1484+ NULL
1485+ );
1486+ } else {
1487+ Status = mPrivate .HiiString .SetString (
1488+ & mPrivate .HiiString ,
1489+ HiiHandle ,
1490+ StringId ,
1491+ Language ,
1492+ String ,
1493+ NULL
1494+ );
1495+ }
1496+
1497+ //
1498+ // If there was an error, then break out of the loop and return a StringId of 0
1499+ //
1500+ if (EFI_ERROR (Status )) {
1501+ break ;
1502+ }
1503+ }
1504+
1505+ //
1506+ // Free the buffer of supported languages
1507+ //
1508+ FreePool (AllocatedLanguages );
1509+
1510+ if (EFI_ERROR (Status )) {
1511+ return (EFI_STRING_ID )(0 );
1512+ } else {
1513+ return StringId ;
1514+ }
1515+ }
1516+
13741517/**
13751518 Retrieves a string from a string package.
13761519
@@ -2202,6 +2345,7 @@ ParseIfrData (
22022345 BOOLEAN SmallestIdFromFlag ;
22032346 BOOLEAN FromOtherDefaultOpcode ;
22042347 BOOLEAN QuestionReferBitField ;
2348+ UINT16 * StringData ;
22052349
22062350 Status = EFI_SUCCESS ;
22072351 BlockData = NULL ;
@@ -2215,6 +2359,7 @@ ParseIfrData (
22152359 FromOtherDefaultOpcode = FALSE;
22162360 QuestionReferBitField = FALSE;
22172361 IfrEfiVarStoreTmp = NULL ;
2362+ StringData = NULL ;
22182363
22192364 //
22202365 // Go through the form package to parse OpCode one by one.
@@ -2871,6 +3016,34 @@ ParseIfrData (
28713016 goto Done ;
28723017 }
28733018
3019+ //
3020+ // Set default value base on the DefaultId list get from IFR data.
3021+ //
3022+ NvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer );
3023+ for (LinkData = DefaultIdArray -> Entry .ForwardLink ; LinkData != & DefaultIdArray -> Entry ; LinkData = LinkData -> ForwardLink ) {
3024+ DefaultDataPtr = BASE_CR (LinkData , IFR_DEFAULT_DATA , Entry );
3025+ DefaultData .DefaultId = DefaultDataPtr -> DefaultId ;
3026+ if (NvDefaultStoreSize > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER )) {
3027+ StringData = AllocateZeroPool (VarWidth * 2 );
3028+ if (StringData == NULL ) {
3029+ Status = EFI_OUT_OF_RESOURCES ;
3030+ goto Done ;
3031+ }
3032+
3033+ if (IfrEfiVarStoreTmp == NULL ) {
3034+ Status = EFI_OUT_OF_RESOURCES ;
3035+ goto Done ;
3036+ }
3037+
3038+ FindQuestionDefaultSetting (DefaultData .DefaultId , IfrEfiVarStoreTmp , & (IfrString -> Question ), (VOID * )StringData , VarWidth , QuestionReferBitField );
3039+ if ((DefaultData .Value .string != 0 ) && (StringData != NULL )) {
3040+ DefaultData .Value .string = InternalHiiSetString (HiiHandle , 0 , StringData , NULL );
3041+ InsertDefaultValue (BlockData , & DefaultData );
3042+ FreePool (StringData );
3043+ }
3044+ }
3045+ }
3046+
28743047 break ;
28753048
28763049 case EFI_IFR_PASSWORD_OP :
0 commit comments