2 Implementation for EFI_HII_STRING_PROTOCOL.
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "HiiDatabase.h"
20 CHAR16 mLanguageWindow
[16] = {
21 0x0000, 0x0080, 0x0100, 0x0300,
22 0x2000, 0x2080, 0x2100, 0x3000,
23 0x0080, 0x00C0, 0x0400, 0x0600,
24 0x0900, 0x3040, 0x30A0, 0xFF00
29 This function checks whether a global font info is referred by local
30 font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create
31 a HII_FONT_INFO to refer it locally.
33 This is a internal function.
36 @param Private Hii database private structure.
37 @param StringPackage HII string package instance.
38 @param FontId Font identifer, which must be unique within the string package.
39 @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to
40 the same EFI_FONT_INFO is permitted. Otherwise it
42 @param GlobalFontInfo Input a global font info which specify a
44 @param LocalFontInfo Output a local font info which refers to a
47 @retval TRUE Already referred before calling this function.
48 @retval FALSE Not referred before calling this function.
52 ReferFontInfoLocally (
53 IN HII_DATABASE_PRIVATE_DATA
*Private
,
54 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
56 IN BOOLEAN DuplicateEnable
,
57 IN HII_GLOBAL_FONT_INFO
*GlobalFontInfo
,
58 OUT HII_FONT_INFO
**LocalFontInfo
61 HII_FONT_INFO
*LocalFont
;
64 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& GlobalFontInfo
!= NULL
&& LocalFontInfo
!= NULL
);
66 if (!DuplicateEnable
) {
67 for (Link
= StringPackage
->FontInfoList
.ForwardLink
;
68 Link
!= &StringPackage
->FontInfoList
;
69 Link
= Link
->ForwardLink
71 LocalFont
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
72 if (LocalFont
->GlobalEntry
== &GlobalFontInfo
->Entry
) {
74 // Already referred by local font info list, return directly.
76 *LocalFontInfo
= LocalFont
;
81 // FontId identifies EFI_FONT_INFO in local string package uniquely.
82 // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies
83 // EFI_FONT_INFO uniquely in whole hii database.
85 LocalFont
= (HII_FONT_INFO
*) AllocateZeroPool (sizeof (HII_FONT_INFO
));
86 ASSERT (LocalFont
!= NULL
);
88 LocalFont
->Signature
= HII_FONT_INFO_SIGNATURE
;
89 LocalFont
->FontId
= FontId
;
90 LocalFont
->GlobalEntry
= &GlobalFontInfo
->Entry
;
91 InsertTailList (&StringPackage
->FontInfoList
, &LocalFont
->Entry
);
93 *LocalFontInfo
= LocalFont
;
99 Convert Ascii string text to unicode string test.
101 This is a internal function.
104 @param StringDest Buffer to store the string text. If it is NULL,
105 only the size will be returned.
106 @param StringSrc Points to current null-terminated string.
107 @param BufferSize Length of the buffer.
109 @retval EFI_SUCCESS The string text was outputted successfully.
110 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
111 text. BufferSize is updated to the required buffer
116 ConvertToUnicodeText (
117 OUT EFI_STRING StringDest
,
119 IN OUT UINTN
*BufferSize
125 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
127 StringSize
= AsciiStrSize (StringSrc
) * 2;
128 if (*BufferSize
< StringSize
|| StringDest
== NULL
) {
129 *BufferSize
= StringSize
;
130 return EFI_BUFFER_TOO_SMALL
;
133 for (Index
= 0; Index
< AsciiStrLen (StringSrc
); Index
++) {
134 StringDest
[Index
] = (CHAR16
) StringSrc
[Index
];
137 StringDest
[Index
] = 0;
143 Calculate the size of StringSrc and output it. If StringDest is not NULL,
144 copy string text from src to dest.
146 This is a internal function.
148 @param StringDest Buffer to store the string text. If it is NULL,
149 only the size will be returned.
150 @param StringSrc Points to current null-terminated string.
151 @param BufferSize Length of the buffer.
153 @retval EFI_SUCCESS The string text was outputted successfully.
154 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
155 text. BufferSize is updated to the required buffer
160 GetUnicodeStringTextOrSize (
161 OUT EFI_STRING StringDest
, OPTIONAL
163 IN OUT UINTN
*BufferSize
169 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
171 StringSize
= sizeof (CHAR16
);
172 StringPtr
= StringSrc
;
173 while (ReadUnaligned16 ((UINT16
*) StringPtr
) != 0) {
174 StringSize
+= sizeof (CHAR16
);
175 StringPtr
+= sizeof (CHAR16
);
178 if (*BufferSize
< StringSize
) {
179 *BufferSize
= StringSize
;
180 return EFI_BUFFER_TOO_SMALL
;
182 if (StringDest
!= NULL
) {
183 CopyMem (StringDest
, StringSrc
, StringSize
);
186 *BufferSize
= StringSize
;
192 Copy string font info to a buffer.
194 This is a internal function.
196 @param StringPackage Hii string package instance.
197 @param FontId Font identifier which is unique in a string
199 @param StringFontInfo Buffer to record the output font info. It's
200 caller's responsibility to free this buffer.
202 @retval EFI_SUCCESS The string font is outputted successfully.
203 @retval EFI_NOT_FOUND The specified font id does not exist.
208 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
210 OUT EFI_FONT_INFO
**StringFontInfo
214 HII_FONT_INFO
*FontInfo
;
215 HII_GLOBAL_FONT_INFO
*GlobalFont
;
217 ASSERT (StringFontInfo
!= NULL
&& StringPackage
!= NULL
);
219 for (Link
= StringPackage
->FontInfoList
.ForwardLink
; Link
!= &StringPackage
->FontInfoList
; Link
= Link
->ForwardLink
) {
220 FontInfo
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
221 if (FontInfo
->FontId
== FontId
) {
222 GlobalFont
= CR (FontInfo
->GlobalEntry
, HII_GLOBAL_FONT_INFO
, Entry
, HII_GLOBAL_FONT_INFO_SIGNATURE
);
223 *StringFontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (GlobalFont
->FontInfoSize
);
224 if (*StringFontInfo
== NULL
) {
225 return EFI_OUT_OF_RESOURCES
;
227 CopyMem (*StringFontInfo
, GlobalFont
->FontInfo
, GlobalFont
->FontInfoSize
);
232 return EFI_NOT_FOUND
;
237 Parse all string blocks to find a String block specified by StringId.
238 If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks
239 within this string package and backup its information. If LastStringId is
240 specified, the string id of last string block will also be output.
241 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_STRING).
243 @param Private Hii database private structure.
244 @param StringPackage Hii string package instance.
245 @param StringId The string's id, which is unique within
247 @param BlockType Output the block type of found string block.
248 @param StringBlockAddr Output the block address of found string block.
249 @param StringTextOffset Offset, relative to the found block address, of
250 the string text information.
251 @param LastStringId Output the last string id when StringId = 0 or StringId = -1.
252 @param StartStringId The first id in the skip block which StringId in the block.
254 @retval EFI_SUCCESS The string text and font is retrieved
256 @retval EFI_NOT_FOUND The specified text or font info can not be found
258 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
264 IN HII_DATABASE_PRIVATE_DATA
*Private
,
265 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
266 IN EFI_STRING_ID StringId
,
267 OUT UINT8
*BlockType
, OPTIONAL
268 OUT UINT8
**StringBlockAddr
, OPTIONAL
269 OUT UINTN
*StringTextOffset
, OPTIONAL
270 OUT EFI_STRING_ID
*LastStringId
, OPTIONAL
271 OUT EFI_STRING_ID
*StartStringId OPTIONAL
275 EFI_STRING_ID CurrentStringId
;
278 UINT8
*StringTextPtr
;
280 HII_FONT_INFO
*LocalFont
;
281 EFI_FONT_INFO
*FontInfo
;
282 HII_GLOBAL_FONT_INFO
*GlobalFont
;
286 EFI_HII_FONT_STYLE FontStyle
;
289 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
295 ASSERT (StringPackage
!= NULL
);
296 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
301 if (StringId
!= (EFI_STRING_ID
) (-1) && StringId
!= 0) {
302 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
303 if (StringId
> StringPackage
->MaxStringId
) {
304 return EFI_NOT_FOUND
;
307 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
308 if (StringId
== 0 && LastStringId
!= NULL
) {
309 *LastStringId
= StringPackage
->MaxStringId
;
314 ZeroMem (&Zero
, sizeof (CHAR16
));
317 // Parse the string blocks to get the string text and font.
319 BlockHdr
= StringPackage
->StringBlock
;
322 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
324 case EFI_HII_SIBT_STRING_SCSU
:
325 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
326 StringTextPtr
= BlockHdr
+ Offset
;
327 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
331 case EFI_HII_SIBT_STRING_SCSU_FONT
:
332 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
333 StringTextPtr
= BlockHdr
+ Offset
;
334 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
338 case EFI_HII_SIBT_STRINGS_SCSU
:
339 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
340 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
341 BlockSize
+= StringTextPtr
- BlockHdr
;
343 for (Index
= 0; Index
< StringCount
; Index
++) {
344 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
345 if (CurrentStringId
== StringId
) {
346 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
347 *BlockType
= *BlockHdr
;
348 *StringBlockAddr
= BlockHdr
;
349 *StringTextOffset
= StringTextPtr
- BlockHdr
;
352 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
357 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
360 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
363 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
364 BlockSize
+= StringTextPtr
- BlockHdr
;
366 for (Index
= 0; Index
< StringCount
; Index
++) {
367 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
368 if (CurrentStringId
== StringId
) {
369 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
370 *BlockType
= *BlockHdr
;
371 *StringBlockAddr
= BlockHdr
;
372 *StringTextOffset
= StringTextPtr
- BlockHdr
;
375 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
380 case EFI_HII_SIBT_STRING_UCS2
:
381 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
382 StringTextPtr
= BlockHdr
+ Offset
;
384 // Use StringSize to store the size of the specified string, including the NULL
387 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
388 BlockSize
+= Offset
+ StringSize
;
392 case EFI_HII_SIBT_STRING_UCS2_FONT
:
393 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
394 StringTextPtr
= BlockHdr
+ Offset
;
396 // Use StrSize to store the size of the specified string, including the NULL
399 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
400 BlockSize
+= Offset
+ StringSize
;
404 case EFI_HII_SIBT_STRINGS_UCS2
:
405 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
406 StringTextPtr
= BlockHdr
+ Offset
;
408 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
409 for (Index
= 0; Index
< StringCount
; Index
++) {
410 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
411 BlockSize
+= StringSize
;
412 if (CurrentStringId
== StringId
) {
413 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
414 *BlockType
= *BlockHdr
;
415 *StringBlockAddr
= BlockHdr
;
416 *StringTextOffset
= StringTextPtr
- BlockHdr
;
419 StringTextPtr
= StringTextPtr
+ StringSize
;
424 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
425 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
426 StringTextPtr
= BlockHdr
+ Offset
;
430 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
433 for (Index
= 0; Index
< StringCount
; Index
++) {
434 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
435 BlockSize
+= StringSize
;
436 if (CurrentStringId
== StringId
) {
437 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
438 *BlockType
= *BlockHdr
;
439 *StringBlockAddr
= BlockHdr
;
440 *StringTextOffset
= StringTextPtr
- BlockHdr
;
443 StringTextPtr
= StringTextPtr
+ StringSize
;
448 case EFI_HII_SIBT_DUPLICATE
:
449 if (CurrentStringId
== StringId
) {
451 // Incoming StringId is an id of a duplicate string block.
452 // Update the StringId to be the previous string block.
453 // Go back to the header of string block to search.
457 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
),
458 sizeof (EFI_STRING_ID
)
460 ASSERT (StringId
!= CurrentStringId
);
464 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
469 case EFI_HII_SIBT_SKIP1
:
470 SkipCount
= (UINT16
) (*(UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
471 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
472 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
475 case EFI_HII_SIBT_SKIP2
:
476 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
477 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
478 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
481 case EFI_HII_SIBT_EXT1
:
484 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
487 BlockSize
+= Length8
;
490 case EFI_HII_SIBT_EXT2
:
491 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
492 if (Ext2
.BlockType2
== EFI_HII_SIBT_FONT
&& StringId
== (EFI_STRING_ID
) (-1)) {
494 // Find the relationship between global font info and the font info of
495 // this EFI_HII_SIBT_FONT block then backup its information in local package.
497 BlockHdr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
498 CopyMem (&FontId
, BlockHdr
, sizeof (UINT8
));
500 CopyMem (&FontSize
, BlockHdr
, sizeof (UINT16
));
501 BlockHdr
+= sizeof (UINT16
);
502 CopyMem (&FontStyle
, BlockHdr
, sizeof (EFI_HII_FONT_STYLE
));
503 BlockHdr
+= sizeof (EFI_HII_FONT_STYLE
);
504 GetUnicodeStringTextOrSize (NULL
, BlockHdr
, &StringSize
);
506 FontInfoSize
= sizeof (EFI_FONT_INFO
) - sizeof (CHAR16
) + StringSize
;
507 FontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (FontInfoSize
);
508 if (FontInfo
== NULL
) {
509 return EFI_OUT_OF_RESOURCES
;
511 FontInfo
->FontStyle
= FontStyle
;
512 FontInfo
->FontSize
= FontSize
;
513 CopyMem (FontInfo
->FontName
, BlockHdr
, StringSize
);
516 // If find the corresponding global font info, save the relationship.
517 // Otherwise ignore this EFI_HII_SIBT_FONT block.
519 if (IsFontInfoExisted (Private
, FontInfo
, NULL
, NULL
, &GlobalFont
)) {
520 ReferFontInfoLocally (Private
, StringPackage
, FontId
, TRUE
, GlobalFont
, &LocalFont
);
524 // Since string package tool set FontId initially to 0 and increases it
525 // progressively by one, StringPackage->FondId always represents an unique
526 // and available FontId.
528 StringPackage
->FontId
++;
533 BlockSize
+= Ext2
.Length
;
537 case EFI_HII_SIBT_EXT4
:
540 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
544 BlockSize
+= Length32
;
551 if (StringId
> 0 && StringId
!= (EFI_STRING_ID
)(-1)) {
552 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
553 *BlockType
= *BlockHdr
;
554 *StringBlockAddr
= BlockHdr
;
555 *StringTextOffset
= Offset
;
557 if (StringId
== CurrentStringId
- 1) {
559 // if only one skip item, return EFI_NOT_FOUND.
561 if(*BlockType
== EFI_HII_SIBT_SKIP2
|| *BlockType
== EFI_HII_SIBT_SKIP1
) {
562 return EFI_NOT_FOUND
;
568 if (StringId
< CurrentStringId
- 1) {
569 return EFI_NOT_FOUND
;
572 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
573 if (StartStringId
!= NULL
) {
574 *StartStringId
= CurrentStringId
;
579 // Get last string ID
581 if (StringId
== (EFI_STRING_ID
) (-1) && LastStringId
!= NULL
) {
582 *LastStringId
= (EFI_STRING_ID
) (CurrentStringId
- 1);
586 return EFI_NOT_FOUND
;
591 Parse all string blocks to get a string specified by StringId.
593 This is a internal function.
595 @param Private Hii database private structure.
596 @param StringPackage Hii string package instance.
597 @param StringId The string's id, which is unique within
599 @param String Points to retrieved null-terminated string.
600 @param StringSize On entry, points to the size of the buffer pointed
601 to by String, in bytes. On return, points to the
602 length of the string, in bytes.
603 @param StringFontInfo If not NULL, allocate a buffer to record the
604 output font info. It's caller's responsibility to
607 @retval EFI_SUCCESS The string text and font is retrieved
609 @retval EFI_NOT_FOUND The specified text or font info can not be found
611 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
617 IN HII_DATABASE_PRIVATE_DATA
*Private
,
618 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
619 IN EFI_STRING_ID StringId
,
620 OUT EFI_STRING String
,
621 IN OUT UINTN
*StringSize
, OPTIONAL
622 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
625 UINT8
*StringTextPtr
;
627 UINT8
*StringBlockAddr
;
628 UINTN StringTextOffset
;
632 ASSERT (StringPackage
!= NULL
);
633 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
636 // Find the specified string block
638 Status
= FindStringBlock (
648 if (EFI_ERROR (Status
)) {
652 if (StringSize
== NULL
) {
654 // String text buffer is not requested
660 // Get the string text.
662 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
664 case EFI_HII_SIBT_STRING_SCSU
:
665 case EFI_HII_SIBT_STRING_SCSU_FONT
:
666 case EFI_HII_SIBT_STRINGS_SCSU
:
667 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
668 Status
= ConvertToUnicodeText (String
, (CHAR8
*) StringTextPtr
, StringSize
);
670 case EFI_HII_SIBT_STRING_UCS2
:
671 case EFI_HII_SIBT_STRING_UCS2_FONT
:
672 case EFI_HII_SIBT_STRINGS_UCS2
:
673 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
674 Status
= GetUnicodeStringTextOrSize (String
, StringTextPtr
, StringSize
);
677 return EFI_NOT_FOUND
;
679 if (EFI_ERROR (Status
)) {
684 // Get the string font. The FontId 0 is the default font for those string blocks which
685 // do not specify a font identifier. If default font is not specified, return NULL.
687 if (StringFontInfo
!= NULL
) {
689 case EFI_HII_SIBT_STRING_SCSU_FONT
:
690 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
691 case EFI_HII_SIBT_STRING_UCS2_FONT
:
692 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
693 FontId
= *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
698 Status
= GetStringFontInfo (StringPackage
, FontId
, StringFontInfo
);
699 if (Status
== EFI_NOT_FOUND
) {
700 *StringFontInfo
= NULL
;
708 If GetStringBlock find the StringId's string is not saved in the exist string block,
709 this function will create the UCS2 string block to save the string; also split the
710 skip block into two or one skip block.
712 This is a internal function.
714 @param StringPackage Hii string package instance.
715 @param StartStringId The first id in the skip block which StringId in the block.
716 @param StringId The string's id, which is unique within
718 @param BlockType Output the block type of found string block.
719 @param StringBlockAddr Output the block address of found string block.
720 @param FontBlock whether this string block has font info.
722 @retval EFI_SUCCESS The string font is outputted successfully.
723 @retval EFI_OUT_OF_RESOURCES NO resource for the memory to save the new string block.
727 InsertLackStringBlock (
728 IN OUT HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
729 IN EFI_STRING_ID StartStringId
,
730 IN EFI_STRING_ID StringId
,
731 IN OUT UINT8
*BlockType
,
732 IN OUT UINT8
**StringBlockAddr
,
742 UINT32 NewUCSBlockLen
;
743 UINT8
*OldStringAddr
;
748 OldStringAddr
= *StringBlockAddr
;
750 ASSERT (*BlockType
== EFI_HII_SIBT_SKIP1
|| *BlockType
== EFI_HII_SIBT_SKIP2
);
752 // Old skip block size.
754 if (*BlockType
== EFI_HII_SIBT_SKIP1
) {
755 SkipLen
= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
756 IdCount
= *(UINT8
*)(OldStringAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
758 SkipLen
= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
759 IdCount
= *(UINT16
*)(OldStringAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
763 // New create UCS or UCS2 block size.
766 NewUCSBlockLen
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
);
768 NewUCSBlockLen
= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
771 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
773 if (StartStringId
== StringId
) {
775 // New block + [Skip block]
778 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
;
780 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
- SkipLen
;
782 } else if (StartStringId
+ IdCount
- 1 == StringId
){
784 // Skip block + New block
786 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
;
787 FrontSkipNum
= StringId
- StartStringId
;
790 // Skip block + New block + [Skip block]
792 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
+ SkipLen
;
793 FrontSkipNum
= StringId
- StartStringId
;
796 StringBlock
= (UINT8
*) AllocateZeroPool (NewBlockSize
);
797 if (StringBlock
== NULL
) {
798 return EFI_OUT_OF_RESOURCES
;
802 // Copy old block in front of skip block.
804 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldStringAddr
- StringPackage
->StringBlock
);
805 BlockPtr
= StringBlock
+ (OldStringAddr
- StringPackage
->StringBlock
);
807 if (FrontSkipNum
> 0) {
808 *BlockPtr
= *BlockType
;
809 if (*BlockType
== EFI_HII_SIBT_SKIP1
) {
810 *(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT8
) FrontSkipNum
;
812 *(UINT16
*)(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT16
) FrontSkipNum
;
818 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
820 *StringBlockAddr
= BlockPtr
;
822 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
824 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
826 BlockPtr
+= NewUCSBlockLen
;
828 if (IdCount
> FrontSkipNum
+ 1) {
829 *BlockPtr
= *BlockType
;
830 if (*BlockType
== EFI_HII_SIBT_SKIP1
) {
831 *(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT8
) (IdCount
- FrontSkipNum
- 1);
833 *(UINT16
*)(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT16
) (IdCount
- FrontSkipNum
- 1);
839 // Append a EFI_HII_SIBT_END block to the end.
841 CopyMem (BlockPtr
, OldStringAddr
+ SkipLen
, OldBlockSize
- (OldStringAddr
- StringPackage
->StringBlock
) - SkipLen
);
844 *BlockType
= EFI_HII_SIBT_STRING_UCS2_FONT
;
846 *BlockType
= EFI_HII_SIBT_STRING_UCS2
;
848 FreePool (StringPackage
->StringBlock
);
849 StringPackage
->StringBlock
= StringBlock
;
850 StringPackage
->StringPkgHdr
->Header
.Length
+= NewBlockSize
- OldBlockSize
;
856 Parse all string blocks to set a String specified by StringId.
858 This is a internal function.
860 @param Private HII database driver private structure.
861 @param StringPackage HII string package instance.
862 @param StringId The string's id, which is unique within
864 @param String Points to the new null-terminated string.
865 @param StringFontInfo Points to the input font info.
867 @retval EFI_SUCCESS The string was updated successfully.
868 @retval EFI_NOT_FOUND The string specified by StringId is not in the
870 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
871 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
873 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
879 IN HII_DATABASE_PRIVATE_DATA
*Private
,
880 IN OUT HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
881 IN EFI_STRING_ID StringId
,
882 IN EFI_STRING String
,
883 IN EFI_FONT_INFO
*StringFontInfo OPTIONAL
886 UINT8
*StringTextPtr
;
888 UINT8
*StringBlockAddr
;
889 UINTN StringTextOffset
;
895 HII_FONT_INFO
*LocalFont
;
896 HII_GLOBAL_FONT_INFO
*GlobalFont
;
898 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
901 EFI_STRING_ID StartStringId
;
905 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& String
!= NULL
);
906 ASSERT (Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
908 // Find the specified string block
910 Status
= FindStringBlock (
920 if (EFI_ERROR (Status
) && (BlockType
== EFI_HII_SIBT_SKIP1
|| BlockType
== EFI_HII_SIBT_SKIP2
)) {
921 Status
= InsertLackStringBlock(StringPackage
,
926 (BOOLEAN
)(StringFontInfo
!= NULL
)
928 if (EFI_ERROR (Status
)) {
931 if (StringFontInfo
!= NULL
) {
932 StringTextOffset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
934 StringTextOffset
= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
);
943 // The input StringFontInfo should exist in current database if specified.
945 if (StringFontInfo
!= NULL
) {
946 if (!IsFontInfoExisted (Private
, StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
947 return EFI_INVALID_PARAMETER
;
949 Referred
= ReferFontInfoLocally (
952 StringPackage
->FontId
,
958 StringPackage
->FontId
++;
962 // Update the FontId of the specified string block to input font info.
965 case EFI_HII_SIBT_STRING_SCSU_FONT
:
966 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
967 case EFI_HII_SIBT_STRING_UCS2_FONT
:
968 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
969 *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
)) = LocalFont
->FontId
;
973 // When modify the font info of these blocks, the block type should be updated
974 // to contain font info thus the whole structure should be revised.
975 // It is recommended to use tool to modify the block type not in the code.
977 return EFI_UNSUPPORTED
;
981 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
984 // Set the string text and font.
986 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
988 case EFI_HII_SIBT_STRING_SCSU
:
989 case EFI_HII_SIBT_STRING_SCSU_FONT
:
990 case EFI_HII_SIBT_STRINGS_SCSU
:
991 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
992 BlockSize
= OldBlockSize
+ StrLen (String
);
993 BlockSize
-= AsciiStrSize ((CHAR8
*) StringTextPtr
);
994 Block
= AllocateZeroPool (BlockSize
);
996 return EFI_OUT_OF_RESOURCES
;
999 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
1000 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
1002 while (*String
!= 0) {
1003 *BlockPtr
++ = (CHAR8
) *String
++;
1008 TmpSize
= OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - AsciiStrSize ((CHAR8
*) StringTextPtr
);
1011 StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
),
1015 FreePool (StringPackage
->StringBlock
);
1016 StringPackage
->StringBlock
= Block
;
1017 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
1020 case EFI_HII_SIBT_STRING_UCS2
:
1021 case EFI_HII_SIBT_STRING_UCS2_FONT
:
1022 case EFI_HII_SIBT_STRINGS_UCS2
:
1023 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
1025 // Use StrSize to store the size of the specified string, including the NULL
1028 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
1030 BlockSize
= OldBlockSize
+ StrSize (String
) - StringSize
;
1031 Block
= AllocateZeroPool (BlockSize
);
1032 if (Block
== NULL
) {
1033 return EFI_OUT_OF_RESOURCES
;
1036 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
1037 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
1039 CopyMem (BlockPtr
, String
, StrSize (String
));
1040 BlockPtr
+= StrSize (String
);
1044 StringTextPtr
+ StringSize
,
1045 OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - StringSize
1048 FreePool (StringPackage
->StringBlock
);
1049 StringPackage
->StringBlock
= Block
;
1050 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
1054 return EFI_NOT_FOUND
;
1058 // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming
1059 // StringFontInfo does not exist in current string package.
1061 // This new block does not impact on the value of StringId.
1064 if (StringFontInfo
== NULL
|| Referred
) {
1068 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1069 BlockSize
= OldBlockSize
+ sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
) +
1070 StrSize (GlobalFont
->FontInfo
->FontName
);
1072 Block
= AllocateZeroPool (BlockSize
);
1073 if (Block
== NULL
) {
1074 return EFI_OUT_OF_RESOURCES
;
1078 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1079 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1080 Ext2
.Length
= (UINT16
) (BlockSize
- OldBlockSize
);
1081 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1082 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1084 *BlockPtr
= LocalFont
->FontId
;
1086 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontSize
, sizeof (UINT16
));
1087 BlockPtr
+= sizeof (UINT16
);
1088 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontStyle
, sizeof (UINT32
));
1089 BlockPtr
+= sizeof (UINT32
);
1092 GlobalFont
->FontInfo
->FontName
,
1093 StrSize (GlobalFont
->FontInfo
->FontName
)
1095 BlockPtr
+= StrSize (GlobalFont
->FontInfo
->FontName
);
1097 CopyMem (BlockPtr
, StringPackage
->StringBlock
, OldBlockSize
);
1099 FreePool (StringPackage
->StringBlock
);
1100 StringPackage
->StringBlock
= Block
;
1101 StringPackage
->StringPkgHdr
->Header
.Length
+= Ext2
.Length
;
1109 This function adds the string String to the group of strings owned by PackageList, with the
1110 specified font information StringFontInfo and returns a new string id.
1111 The new string identifier is guaranteed to be unique within the package list.
1112 That new string identifier is reserved for all languages in the package list.
1115 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1116 @param PackageList Handle of the package list where this string will
1118 @param StringId On return, contains the new strings id, which is
1119 unique within PackageList.
1120 @param Language Points to the language for the new string.
1121 @param LanguageName Points to the printable language name to associate
1122 with the passed in Language field.If LanguageName
1123 is not NULL and the string package header's
1124 LanguageName associated with a given Language is
1125 not zero, the LanguageName being passed in will
1127 @param String Points to the new null-terminated string.
1128 @param StringFontInfo Points to the new string's font information or
1129 NULL if the string should have the default system
1130 font, size and style.
1132 @retval EFI_SUCCESS The new string was added successfully.
1133 @retval EFI_NOT_FOUND The specified PackageList could not be found in
1135 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
1136 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is
1138 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1145 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1146 IN EFI_HII_HANDLE PackageList
,
1147 OUT EFI_STRING_ID
*StringId
,
1148 IN CONST CHAR8
*Language
,
1149 IN CONST CHAR16
*LanguageName
, OPTIONAL
1150 IN CONST EFI_STRING String
,
1151 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1156 HII_DATABASE_PRIVATE_DATA
*Private
;
1157 HII_DATABASE_RECORD
*DatabaseRecord
;
1158 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1159 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1162 UINT32 OldBlockSize
;
1165 UINT32 Ucs2BlockSize
;
1166 UINT32 FontBlockSize
;
1167 UINT32 Ucs2FontBlockSize
;
1168 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
1169 HII_FONT_INFO
*LocalFont
;
1170 HII_GLOBAL_FONT_INFO
*GlobalFont
;
1171 EFI_STRING_ID NewStringId
;
1172 EFI_STRING_ID NextStringId
;
1173 EFI_STRING_ID Index
;
1174 HII_STRING_PACKAGE_INSTANCE
*MatchStringPackage
;
1175 BOOLEAN NewStringPackageCreated
;
1178 if (This
== NULL
|| String
== NULL
|| StringId
== NULL
|| Language
== NULL
|| PackageList
== NULL
) {
1179 return EFI_INVALID_PARAMETER
;
1182 if (!IsHiiHandleValid (PackageList
)) {
1183 return EFI_NOT_FOUND
;
1186 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1190 // If StringFontInfo specify a paritcular font, it should exist in current database.
1192 if (StringFontInfo
!= NULL
) {
1193 if (!IsFontInfoExisted (Private
, (EFI_FONT_INFO
*) StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
1194 return EFI_INVALID_PARAMETER
;
1199 // Get the matching package list.
1201 PackageListNode
= NULL
;
1202 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1203 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1204 if (DatabaseRecord
->Handle
== PackageList
) {
1205 PackageListNode
= DatabaseRecord
->PackageList
;
1209 if (PackageListNode
== NULL
) {
1210 return EFI_NOT_FOUND
;
1213 EfiAcquireLock (&mHiiDatabaseLock
);
1215 Status
= EFI_SUCCESS
;
1216 NewStringPackageCreated
= FALSE
;
1219 StringPackage
= NULL
;
1220 MatchStringPackage
= NULL
;
1221 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1222 Link
!= &PackageListNode
->StringPkgHdr
;
1223 Link
= Link
->ForwardLink
1225 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1227 // Create a string block and corresponding font block if exists, then append them
1228 // to the end of the string package.
1230 Status
= FindStringBlock (
1240 if (EFI_ERROR (Status
)) {
1244 // Make sure that new StringId is same in all String Packages for the different language.
1246 if (NewStringId
!= 0 && NewStringId
!= NextStringId
) {
1248 Status
= EFI_INVALID_PARAMETER
;
1251 NewStringId
= NextStringId
;
1253 // Get the matched string package with language.
1255 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1256 MatchStringPackage
= StringPackage
;
1258 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1260 // Create a blank EFI_HII_SIBT_STRING_UCS2_BLOCK to reserve new string ID.
1262 Ucs2BlockSize
= (UINT32
) sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1264 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1265 if (StringBlock
== NULL
) {
1266 Status
= EFI_OUT_OF_RESOURCES
;
1270 // Copy original string blocks, except the EFI_HII_SIBT_END.
1272 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1274 // Create a blank EFI_HII_SIBT_STRING_UCS2 block
1276 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1277 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1278 BlockPtr
+= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1281 // Append a EFI_HII_SIBT_END block to the end.
1283 *BlockPtr
= EFI_HII_SIBT_END
;
1284 FreePool (StringPackage
->StringBlock
);
1285 StringPackage
->StringBlock
= StringBlock
;
1286 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1287 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1290 if (NewStringId
== 0) {
1292 // No string package is found.
1293 // Create new string package. StringId 1 is reserved for Language Name string.
1300 *StringId
= (EFI_STRING_ID
) (NewStringId
+ 1);
1303 if (MatchStringPackage
!= NULL
) {
1304 StringPackage
= MatchStringPackage
;
1307 // LanguageName is required to create a new string package.
1309 if (LanguageName
== NULL
) {
1310 Status
= EFI_INVALID_PARAMETER
;
1314 StringPackage
= AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE
));
1315 if (StringPackage
== NULL
) {
1316 Status
= EFI_OUT_OF_RESOURCES
;
1320 StringPackage
->Signature
= HII_STRING_PACKAGE_SIGNATURE
;
1321 StringPackage
->MaxStringId
= *StringId
;
1322 StringPackage
->FontId
= 0;
1323 InitializeListHead (&StringPackage
->FontInfoList
);
1326 // Fill in the string package header
1328 HeaderSize
= (UINT32
) (AsciiStrSize ((CHAR8
*) Language
) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR
));
1329 StringPackage
->StringPkgHdr
= AllocateZeroPool (HeaderSize
);
1330 if (StringPackage
->StringPkgHdr
== NULL
) {
1331 FreePool (StringPackage
);
1332 Status
= EFI_OUT_OF_RESOURCES
;
1335 StringPackage
->StringPkgHdr
->Header
.Type
= EFI_HII_PACKAGE_STRINGS
;
1336 StringPackage
->StringPkgHdr
->HdrSize
= HeaderSize
;
1337 StringPackage
->StringPkgHdr
->StringInfoOffset
= HeaderSize
;
1338 CopyMem (StringPackage
->StringPkgHdr
->LanguageWindow
, mLanguageWindow
, 16 * sizeof (CHAR16
));
1339 StringPackage
->StringPkgHdr
->LanguageName
= 1;
1340 AsciiStrCpyS (StringPackage
->StringPkgHdr
->Language
, (HeaderSize
- OFFSET_OF(EFI_HII_STRING_PACKAGE_HDR
,Language
)) / sizeof (CHAR8
), (CHAR8
*) Language
);
1343 // Calculate the length of the string blocks, including string block to record
1344 // printable language full name and EFI_HII_SIBT_END_BLOCK.
1346 Ucs2BlockSize
= (UINT32
) (StrSize ((CHAR16
*) LanguageName
) +
1347 (*StringId
- 1) * sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
));
1349 BlockSize
= Ucs2BlockSize
+ sizeof (EFI_HII_SIBT_END_BLOCK
);
1350 StringPackage
->StringBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
1351 if (StringPackage
->StringBlock
== NULL
) {
1352 FreePool (StringPackage
->StringPkgHdr
);
1353 FreePool (StringPackage
);
1354 Status
= EFI_OUT_OF_RESOURCES
;
1359 // Insert the string block of printable language full name
1361 BlockPtr
= StringPackage
->StringBlock
;
1362 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1363 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1364 CopyMem (BlockPtr
, (EFI_STRING
) LanguageName
, StrSize ((EFI_STRING
) LanguageName
));
1365 BlockPtr
+= StrSize ((EFI_STRING
) LanguageName
);
1366 for (Index
= 2; Index
<= *StringId
- 1; Index
++) {
1367 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1368 BlockPtr
+= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1371 // Insert the end block
1373 *BlockPtr
= EFI_HII_SIBT_END
;
1376 // Append this string package node to string package array in this package list.
1378 StringPackage
->StringPkgHdr
->Header
.Length
= HeaderSize
+ BlockSize
;
1379 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
;
1380 InsertTailList (&PackageListNode
->StringPkgHdr
, &StringPackage
->StringEntry
);
1381 NewStringPackageCreated
= TRUE
;
1384 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1386 if (StringFontInfo
== NULL
) {
1388 // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.
1390 Ucs2BlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
)
1393 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1394 if (StringBlock
== NULL
) {
1395 Status
= EFI_OUT_OF_RESOURCES
;
1399 // Copy original string blocks, except the EFI_HII_SIBT_END.
1401 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1403 // Create a EFI_HII_SIBT_STRING_UCS2 block
1405 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1406 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1407 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1408 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1409 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1412 // Append a EFI_HII_SIBT_END block to the end.
1414 *BlockPtr
= EFI_HII_SIBT_END
;
1415 FreePool (StringPackage
->StringBlock
);
1416 StringPackage
->StringBlock
= StringBlock
;
1417 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1418 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1422 // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK
1423 // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block
1424 // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING
1425 // _UCS2_FONT block.
1427 Ucs2FontBlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) -
1429 if (ReferFontInfoLocally (Private
, StringPackage
, StringPackage
->FontId
, FALSE
, GlobalFont
, &LocalFont
)) {
1431 // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.
1433 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2FontBlockSize
);
1434 if (StringBlock
== NULL
) {
1435 Status
= EFI_OUT_OF_RESOURCES
;
1439 // Copy original string blocks, except the EFI_HII_SIBT_END.
1441 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1443 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1445 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1446 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1447 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1448 *BlockPtr
= LocalFont
->FontId
;
1450 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1451 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1454 // Append a EFI_HII_SIBT_END block to the end.
1456 *BlockPtr
= EFI_HII_SIBT_END
;
1457 FreePool (StringPackage
->StringBlock
);
1458 StringPackage
->StringBlock
= StringBlock
;
1459 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2FontBlockSize
;
1460 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2FontBlockSize
;
1464 // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so
1465 // create a EFI_HII_SIBT_FONT block to record the font info, then generate
1466 // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.
1468 FontBlockSize
= (UINT32
) (StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
) +
1469 sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
));
1470 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ FontBlockSize
+ Ucs2FontBlockSize
);
1471 if (StringBlock
== NULL
) {
1472 Status
= EFI_OUT_OF_RESOURCES
;
1476 // Copy original string blocks, except the EFI_HII_SIBT_END.
1478 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1481 // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string
1482 // package instance for future reference.
1484 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1486 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1487 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1488 Ext2
.Length
= (UINT16
) FontBlockSize
;
1489 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1490 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1492 *BlockPtr
= LocalFont
->FontId
;
1494 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontSize
, sizeof (UINT16
));
1495 BlockPtr
+= sizeof (UINT16
);
1496 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontStyle
, sizeof (EFI_HII_FONT_STYLE
));
1497 BlockPtr
+= sizeof (EFI_HII_FONT_STYLE
);
1500 &((EFI_FONT_INFO
*) StringFontInfo
)->FontName
,
1501 StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
)
1503 BlockPtr
+= StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
);
1505 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1507 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1508 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1509 *BlockPtr
= LocalFont
->FontId
;
1511 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1512 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1515 // Append a EFI_HII_SIBT_END block to the end.
1517 *BlockPtr
= EFI_HII_SIBT_END
;
1518 FreePool (StringPackage
->StringBlock
);
1519 StringPackage
->StringBlock
= StringBlock
;
1520 StringPackage
->StringPkgHdr
->Header
.Length
+= FontBlockSize
+ Ucs2FontBlockSize
;
1521 PackageListNode
->PackageListHdr
.PackageLength
+= FontBlockSize
+ Ucs2FontBlockSize
;
1524 // Increase the FontId to make it unique since we already add
1525 // a EFI_HII_SIBT_FONT block to this string package.
1527 StringPackage
->FontId
++;
1532 if (!EFI_ERROR (Status
) && NewStringPackageCreated
) {
1534 // Trigger any registered notification function for new string package
1536 Status
= InvokeRegisteredFunction (
1538 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
1539 (VOID
*) StringPackage
,
1540 EFI_HII_PACKAGE_STRINGS
,
1545 if (!EFI_ERROR (Status
)) {
1547 // Update MaxString Id to new StringId
1549 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1550 Link
!= &PackageListNode
->StringPkgHdr
;
1551 Link
= Link
->ForwardLink
1553 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1554 StringPackage
->MaxStringId
= *StringId
;
1556 } else if (NewStringPackageCreated
) {
1558 // Free the allocated new string Package when new string can't be added.
1560 RemoveEntryList (&StringPackage
->StringEntry
);
1561 FreePool (StringPackage
->StringBlock
);
1562 FreePool (StringPackage
->StringPkgHdr
);
1563 FreePool (StringPackage
);
1566 // The contents of HiiDataBase may updated,need to check.
1569 // Check whether need to get the contents of HiiDataBase.
1570 // Only after ReadyToBoot to do the export.
1572 if (gExportAfterReadyToBoot
) {
1573 if (!EFI_ERROR (Status
)) {
1574 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
1578 EfiReleaseLock (&mHiiDatabaseLock
);
1585 This function retrieves the string specified by StringId which is associated
1586 with the specified PackageList in the language Language and copies it into
1587 the buffer specified by String.
1589 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1590 @param Language Points to the language for the retrieved string.
1591 @param PackageList The package list in the HII database to search for
1592 the specified string.
1593 @param StringId The string's id, which is unique within
1595 @param String Points to the new null-terminated string.
1596 @param StringSize On entry, points to the size of the buffer pointed
1597 to by String, in bytes. On return, points to the
1598 length of the string, in bytes.
1599 @param StringFontInfo If not NULL, points to the string's font
1600 information. It's caller's responsibility to free
1603 @retval EFI_SUCCESS The string was returned successfully.
1604 @retval EFI_NOT_FOUND The string specified by StringId is not available.
1605 @retval EFI_NOT_FOUND The string specified by StringId is available but
1606 not in the specified language.
1607 The specified PackageList is not in the database.
1608 @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but
1609 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
1611 @retval EFI_INVALID_PARAMETER The Language or StringSize was NULL.
1612 @retval EFI_INVALID_PARAMETER The value referenced by StringSize was not zero and String was NULL.
1613 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
1620 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1621 IN CONST CHAR8
*Language
,
1622 IN EFI_HII_HANDLE PackageList
,
1623 IN EFI_STRING_ID StringId
,
1624 OUT EFI_STRING String
,
1625 IN OUT UINTN
*StringSize
,
1626 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
1631 HII_DATABASE_PRIVATE_DATA
*Private
;
1632 HII_DATABASE_RECORD
*DatabaseRecord
;
1633 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1634 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1636 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || StringSize
== NULL
|| PackageList
== NULL
) {
1637 return EFI_INVALID_PARAMETER
;
1640 if (String
== NULL
&& *StringSize
!= 0) {
1641 return EFI_INVALID_PARAMETER
;
1644 if (!IsHiiHandleValid (PackageList
)) {
1645 return EFI_NOT_FOUND
;
1648 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1649 PackageListNode
= NULL
;
1651 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1652 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1653 if (DatabaseRecord
->Handle
== PackageList
) {
1654 PackageListNode
= DatabaseRecord
->PackageList
;
1659 if (PackageListNode
!= NULL
) {
1661 // First search: to match the StringId in the specified language.
1663 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1664 Link
!= &PackageListNode
->StringPkgHdr
;
1665 Link
= Link
->ForwardLink
1667 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1668 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1669 Status
= GetStringWorker (Private
, StringPackage
, StringId
, String
, StringSize
, StringFontInfo
);
1670 if (Status
!= EFI_NOT_FOUND
) {
1676 // Second search: to match the StringId in other available languages if exist.
1678 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1679 Link
!= &PackageListNode
->StringPkgHdr
;
1680 Link
= Link
->ForwardLink
1682 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1683 Status
= GetStringWorker (Private
, StringPackage
, StringId
, NULL
, NULL
, NULL
);
1684 if (!EFI_ERROR (Status
)) {
1685 return EFI_INVALID_LANGUAGE
;
1690 return EFI_NOT_FOUND
;
1696 This function updates the string specified by StringId in the specified PackageList to the text
1697 specified by String and, optionally, the font information specified by StringFontInfo.
1699 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1700 @param PackageList The package list containing the strings.
1701 @param StringId The string's id, which is unique within
1703 @param Language Points to the language for the updated string.
1704 @param String Points to the new null-terminated string.
1705 @param StringFontInfo Points to the string's font information or NULL if
1706 the string font information is not changed.
1708 @retval EFI_SUCCESS The string was updated successfully.
1709 @retval EFI_NOT_FOUND The string specified by StringId is not in the
1711 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
1712 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1714 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
1721 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1722 IN EFI_HII_HANDLE PackageList
,
1723 IN EFI_STRING_ID StringId
,
1724 IN CONST CHAR8
*Language
,
1725 IN CONST EFI_STRING String
,
1726 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1731 HII_DATABASE_PRIVATE_DATA
*Private
;
1732 HII_DATABASE_RECORD
*DatabaseRecord
;
1733 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1734 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1735 UINT32 OldPackageLen
;
1737 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || String
== NULL
|| PackageList
== NULL
) {
1738 return EFI_INVALID_PARAMETER
;
1741 if (!IsHiiHandleValid (PackageList
)) {
1742 return EFI_NOT_FOUND
;
1745 EfiAcquireLock (&mHiiDatabaseLock
);
1747 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1748 PackageListNode
= NULL
;
1750 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1751 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1752 if (DatabaseRecord
->Handle
== PackageList
) {
1753 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1757 if (PackageListNode
!= NULL
) {
1758 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1759 Link
!= &PackageListNode
->StringPkgHdr
;
1760 Link
= Link
->ForwardLink
1762 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1763 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1764 OldPackageLen
= StringPackage
->StringPkgHdr
->Header
.Length
;
1765 Status
= SetStringWorker (
1769 (EFI_STRING
) String
,
1770 (EFI_FONT_INFO
*) StringFontInfo
1772 if (EFI_ERROR (Status
)) {
1773 EfiReleaseLock (&mHiiDatabaseLock
);
1776 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
- OldPackageLen
;
1778 // Check whether need to get the contents of HiiDataBase.
1779 // Only after ReadyToBoot to do the export.
1781 if (gExportAfterReadyToBoot
) {
1782 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
1784 EfiReleaseLock (&mHiiDatabaseLock
);
1790 EfiReleaseLock (&mHiiDatabaseLock
);
1791 return EFI_NOT_FOUND
;
1797 This function returns the list of supported languages, in the format specified
1798 in Appendix M of UEFI 2.1 spec.
1800 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1801 @param PackageList The package list to examine.
1802 @param Languages Points to the buffer to hold the returned
1803 null-terminated ASCII string.
1804 @param LanguagesSize On entry, points to the size of the buffer pointed
1805 to by Languages, in bytes. On return, points to
1806 the length of Languages, in bytes.
1808 @retval EFI_SUCCESS The languages were returned successfully.
1809 @retval EFI_INVALID_PARAMETER The LanguagesSize was NULL.
1810 @retval EFI_INVALID_PARAMETER The value referenced by LanguagesSize is not zero and Languages is NULL.
1811 @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of
1812 supported languages. LanguageSize is updated to
1813 contain the required size.
1814 @retval EFI_NOT_FOUND Could not find string package in specified
1821 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1822 IN EFI_HII_HANDLE PackageList
,
1823 IN OUT CHAR8
*Languages
,
1824 IN OUT UINTN
*LanguagesSize
1828 HII_DATABASE_PRIVATE_DATA
*Private
;
1829 HII_DATABASE_RECORD
*DatabaseRecord
;
1830 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1831 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1834 if (This
== NULL
|| LanguagesSize
== NULL
|| PackageList
== NULL
) {
1835 return EFI_INVALID_PARAMETER
;
1837 if (*LanguagesSize
!= 0 && Languages
== NULL
) {
1838 return EFI_INVALID_PARAMETER
;
1840 if (!IsHiiHandleValid (PackageList
)) {
1841 return EFI_NOT_FOUND
;
1844 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1846 PackageListNode
= NULL
;
1847 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1848 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1849 if (DatabaseRecord
->Handle
== PackageList
) {
1850 PackageListNode
= DatabaseRecord
->PackageList
;
1854 if (PackageListNode
== NULL
) {
1855 return EFI_NOT_FOUND
;
1859 // Search the languages in the specified packagelist.
1862 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1863 Link
!= &PackageListNode
->StringPkgHdr
;
1864 Link
= Link
->ForwardLink
1866 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1867 ResultSize
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1868 if (ResultSize
<= *LanguagesSize
) {
1869 AsciiStrCpyS (Languages
, *LanguagesSize
/ sizeof (CHAR8
), StringPackage
->StringPkgHdr
->Language
);
1870 Languages
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1871 *(Languages
- 1) = L
';';
1874 if (ResultSize
== 0) {
1875 return EFI_NOT_FOUND
;
1878 if (*LanguagesSize
< ResultSize
) {
1879 *LanguagesSize
= ResultSize
;
1880 return EFI_BUFFER_TOO_SMALL
;
1883 *(Languages
- 1) = 0;
1889 Each string package has associated with it a single primary language and zero
1890 or more secondary languages. This routine returns the secondary languages
1891 associated with a package list.
1893 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1894 @param PackageList The package list to examine.
1895 @param PrimaryLanguage Points to the null-terminated ASCII string that specifies
1896 the primary language. Languages are specified in the
1897 format specified in Appendix M of the UEFI 2.0 specification.
1898 @param SecondaryLanguages Points to the buffer to hold the returned null-terminated
1899 ASCII string that describes the list of
1900 secondary languages for the specified
1901 PrimaryLanguage. If there are no secondary
1902 languages, the function returns successfully, but
1903 this is set to NULL.
1904 @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed
1905 to by SecondaryLanguages, in bytes. On return,
1906 points to the length of SecondaryLanguages in bytes.
1908 @retval EFI_SUCCESS Secondary languages were correctly returned.
1909 @retval EFI_INVALID_PARAMETER PrimaryLanguage or SecondaryLanguagesSize was NULL.
1910 @retval EFI_INVALID_PARAMETER The value referenced by SecondaryLanguagesSize is not
1911 zero and SecondaryLanguages is NULL.
1912 @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is
1913 too small to hold the returned information.
1914 SecondaryLanguageSize is updated to hold the size of
1915 the buffer required.
1916 @retval EFI_INVALID_LANGUAGE The language specified by PrimaryLanguage is not
1917 present in the specified package list.
1918 @retval EFI_NOT_FOUND The specified PackageList is not in the Database.
1923 HiiGetSecondaryLanguages (
1924 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1925 IN EFI_HII_HANDLE PackageList
,
1926 IN CONST CHAR8
*PrimaryLanguage
,
1927 IN OUT CHAR8
*SecondaryLanguages
,
1928 IN OUT UINTN
*SecondaryLanguagesSize
1933 HII_DATABASE_PRIVATE_DATA
*Private
;
1934 HII_DATABASE_RECORD
*DatabaseRecord
;
1935 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1936 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1940 if (This
== NULL
|| PackageList
== NULL
|| PrimaryLanguage
== NULL
|| SecondaryLanguagesSize
== NULL
) {
1941 return EFI_INVALID_PARAMETER
;
1943 if (SecondaryLanguages
== NULL
&& *SecondaryLanguagesSize
!= 0) {
1944 return EFI_INVALID_PARAMETER
;
1946 if (!IsHiiHandleValid (PackageList
)) {
1947 return EFI_NOT_FOUND
;
1950 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1952 PackageListNode
= NULL
;
1953 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1954 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1955 if (DatabaseRecord
->Handle
== PackageList
) {
1956 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1960 if (PackageListNode
== NULL
) {
1961 return EFI_NOT_FOUND
;
1966 for (Link1
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1967 Link1
!= &PackageListNode
->StringPkgHdr
;
1968 Link1
= Link1
->ForwardLink
1970 StringPackage
= CR (Link1
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1971 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) PrimaryLanguage
)) {
1972 Languages
= StringPackage
->StringPkgHdr
->Language
;
1974 // Language is a series of ';' terminated strings, first one is primary
1975 // language and following with other secondary languages or NULL if no
1976 // secondary languages any more.
1978 Languages
= AsciiStrStr (Languages
, ";");
1979 if (Languages
== NULL
) {
1984 ResultSize
= AsciiStrSize (Languages
);
1985 if (ResultSize
<= *SecondaryLanguagesSize
) {
1986 AsciiStrCpyS (SecondaryLanguages
, *SecondaryLanguagesSize
/ sizeof (CHAR8
), Languages
);
1988 *SecondaryLanguagesSize
= ResultSize
;
1989 return EFI_BUFFER_TOO_SMALL
;
1996 return EFI_INVALID_LANGUAGE
;
2000 Converts the ascii character of the string from uppercase to lowercase.
2001 This is a internal function.
2003 @param ConfigString String to be converted
2009 IN CHAR8
*ConfigString
2012 ASSERT (ConfigString
!= NULL
);
2015 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
2017 for (; *ConfigString
!= '\0'; ConfigString
++) {
2018 if ( *ConfigString
>= 'A' && *ConfigString
<= 'Z') {
2019 *ConfigString
= (CHAR8
) (*ConfigString
- 'A' + 'a');
2025 Compare whether two names of languages are identical.
2027 @param Language1 Name of language 1 from StringPackage
2028 @param Language2 Name of language 2 to be compared with language 1.
2031 @retval FALSE not same
2035 HiiCompareLanguage (
2036 IN CHAR8
*Language1
,
2046 // Convert to lower to compare.
2048 StrLen
= AsciiStrSize (Language1
);
2049 Lan1
= AllocateZeroPool (StrLen
);
2050 ASSERT (Lan1
!= NULL
);
2051 AsciiStrCpyS(Lan1
, StrLen
/ sizeof (CHAR8
), Language1
);
2052 AsciiHiiToLower (Lan1
);
2054 StrLen
= AsciiStrSize (Language2
);
2055 Lan2
= AllocateZeroPool (StrLen
);
2056 ASSERT (Lan2
!= NULL
);
2057 AsciiStrCpyS(Lan2
, StrLen
/ sizeof (CHAR8
), Language2
);
2058 AsciiHiiToLower (Lan2
);
2061 // Compare the Primary Language in Language1 to Language2
2063 for (Index
= 0; Lan1
[Index
] != 0 && Lan1
[Index
] != ';'; Index
++) {
2064 if (Lan1
[Index
] != Lan2
[Index
]) {
2066 // Return FALSE if any characters are different.
2078 // Only return TRUE if Language2[Index] is a Null-terminator which means
2079 // the Primary Language in Language1 is the same length as Language2. If
2080 // Language2[Index] is not a Null-terminator, then Language2 is longer than
2081 // the Primary Language in Language1, and FALSE must be returned.
2083 return (BOOLEAN
) (Language2
[Index
] == 0);